1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
40 # include <liblustre.h>
43 #include <obd_support.h>
44 #include <lustre_import.h>
45 #include <lustre_net.h>
47 #include <lustre_lib.h>
48 #include <lustre/lustre_idl.h>
49 #include <lprocfs_status.h>
51 #if defined(__linux__)
52 #include <linux/obd_class.h>
53 #elif defined(__APPLE__)
54 #include <darwin/obd_class.h>
55 #elif defined(__WINNT__)
56 #include <winnt/obd_class.h>
58 #error Unsupported operating system.
61 /* OBD Device Declarations */
62 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
63 extern spinlock_t obd_dev_lock;
65 /* OBD Operations Declarations */
66 extern struct obd_device *class_conn2obd(struct lustre_handle *);
67 extern struct obd_device *class_exp2obd(struct obd_export *);
69 struct lu_device_type;
72 struct obd_export *class_conn2export(struct lustre_handle *);
73 int class_register_type(struct obd_ops *, struct md_ops *,
74 struct lprocfs_vars *, const char *nm,
75 struct lu_device_type *ldt);
76 int class_unregister_type(const char *nm);
78 struct obd_device *class_newdev(const char *type_name, const char *name);
79 void class_release_dev(struct obd_device *obd);
81 int class_name2dev(const char *name);
82 struct obd_device *class_name2obd(const char *name);
83 int class_uuid2dev(struct obd_uuid *uuid);
84 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
85 void class_obd_list(void);
86 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
87 const char * typ_name,
88 struct obd_uuid *grp_uuid);
89 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
91 struct obd_device * class_num2obd(int num);
93 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
95 char *obd_export_nid2str(struct obd_export *exp);
97 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
98 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
100 int obd_zombie_impexp_init(void);
101 void obd_zombie_impexp_stop(void);
102 void obd_zombie_impexp_cull(void);
103 void obd_zombie_barrier(void);
104 void obd_exports_barrier(struct obd_device *obd);
107 int class_process_config(struct lustre_cfg *lcfg);
108 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
109 struct lustre_cfg *lcfg, void *data);
110 int class_attach(struct lustre_cfg *lcfg);
111 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
112 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
113 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
114 struct obd_device *class_incref(struct obd_device *obd,
115 const char *scope, const void *source);
116 void class_decref(struct obd_device *obd,
117 const char *scope, const void *source);
118 void dump_exports(struct obd_device *obd, int locks);
122 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
124 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
126 memset(lvars, 0, sizeof(*lvars));
130 #define CFG_F_START 0x01 /* Set when we start updating from a log */
131 #define CFG_F_MARKER 0x02 /* We are within a maker */
132 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
133 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
134 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
136 /* Passed as data param to class_config_parse_llog */
137 struct config_llog_instance {
140 struct super_block *cfg_sb;
141 struct obd_uuid cfg_uuid;
142 int cfg_last_idx; /* for partial llog processing */
145 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
146 struct config_llog_instance *cfg);
147 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
148 struct config_llog_instance *cfg);
150 /* list of active configuration logs */
151 struct config_llog_data {
153 struct ldlm_res_id cld_resid;
154 struct config_llog_instance cld_cfg;
155 struct list_head cld_list_chain;
156 atomic_t cld_refcount;
157 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
158 struct obd_export *cld_mgcexp;
159 unsigned int cld_stopping:1, /* we were told to stop watching */
160 cld_lostlock:1, /* lock not requeued */
164 struct lustre_profile {
165 struct list_head lp_list;
171 struct lustre_profile *class_get_profile(const char * prof);
172 void class_del_profile(const char *prof);
173 void class_del_profiles(void);
175 #if LUSTRE_TRACKS_LOCK_EXP_REFS
177 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
178 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
179 extern void (*class_export_dump_hook)(struct obd_export *);
183 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
184 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
188 #define class_export_rpc_get(exp) \
190 atomic_inc(&(exp)->exp_rpc_count); \
191 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
192 (exp), atomic_read(&(exp)->exp_rpc_count)); \
193 class_export_get(exp); \
196 #define class_export_rpc_put(exp) \
198 LASSERT(atomic_read(&exp->exp_rpc_count) > 0); \
199 atomic_dec(&(exp)->exp_rpc_count); \
200 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
201 (exp), atomic_read(&(exp)->exp_rpc_count)); \
202 class_export_put(exp); \
205 #define class_export_lock_get(exp, lock) \
207 atomic_inc(&(exp)->exp_locks_count); \
208 __class_export_add_lock_ref(exp, lock); \
209 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
210 (exp), atomic_read(&(exp)->exp_locks_count)); \
211 class_export_get(exp); \
214 #define class_export_lock_put(exp, lock) \
216 LASSERT(atomic_read(&exp->exp_locks_count) > 0); \
217 atomic_dec(&(exp)->exp_locks_count); \
218 __class_export_del_lock_ref(exp, lock); \
219 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
220 (exp), atomic_read(&(exp)->exp_locks_count)); \
221 class_export_put(exp); \
224 #define class_export_cb_get(exp) \
226 atomic_inc(&(exp)->exp_cb_count); \
227 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
228 (exp), atomic_read(&(exp)->exp_cb_count)); \
229 class_export_get(exp); \
232 #define class_export_cb_put(exp) \
234 LASSERT(atomic_read(&exp->exp_cb_count) > 0); \
235 atomic_dec(&(exp)->exp_cb_count); \
236 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
237 (exp), atomic_read(&(exp)->exp_cb_count)); \
238 class_export_put(exp); \
242 struct obd_export *class_export_get(struct obd_export *exp);
243 void class_export_put(struct obd_export *exp);
244 struct obd_export *class_new_export(struct obd_device *obddev,
245 struct obd_uuid *cluuid);
246 void class_unlink_export(struct obd_export *exp);
248 struct obd_import *class_import_get(struct obd_import *);
249 void class_import_put(struct obd_import *);
250 struct obd_import *class_new_import(struct obd_device *obd);
251 void class_destroy_import(struct obd_import *exp);
253 struct obd_type *class_search_type(const char *name);
254 struct obd_type *class_get_type(const char *name);
255 void class_put_type(struct obd_type *type);
256 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
257 struct obd_uuid *cluuid);
258 int class_disconnect(struct obd_export *exp);
259 void class_fail_export(struct obd_export *exp);
260 int class_connected_export(struct obd_export *exp);
261 void class_disconnect_exports(struct obd_device *obddev);
262 int class_manual_cleanup(struct obd_device *obd);
263 void class_disconnect_stale_exports(struct obd_device *,
264 int (*test_export)(struct obd_export *));
265 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
267 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
268 (obd->obd_force ? OBD_OPT_FORCE : 0) |
269 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
273 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
274 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
275 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
276 unsigned int ia_valid);
277 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
278 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
279 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
282 #define OBT(dev) (dev)->obd_type
283 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
284 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
285 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
287 /* Ensure obd_setup: used for cleanup which must be called
288 while obd is stopping */
289 #define OBD_CHECK_DEV(obd) \
292 CERROR("NULL device\n"); \
297 /* ensure obd_setup and !obd_stopping */
298 #define OBD_CHECK_DEV_ACTIVE(obd) \
300 OBD_CHECK_DEV(obd); \
301 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
302 CERROR("Device %d not setup\n", \
310 #define OBD_COUNTER_OFFSET(op) \
311 ((offsetof(struct obd_ops, o_ ## op) - \
312 offsetof(struct obd_ops, o_iocontrol)) \
313 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
315 #define OBD_COUNTER_INCREMENT(obdx, op) \
316 if ((obdx)->obd_stats != NULL) { \
317 unsigned int coffset; \
318 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
319 OBD_COUNTER_OFFSET(op); \
320 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
321 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
324 #define EXP_COUNTER_INCREMENT(export, op) \
325 if ((export)->exp_obd->obd_stats != NULL) { \
326 unsigned int coffset; \
327 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
328 OBD_COUNTER_OFFSET(op); \
329 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
330 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
331 if ((export)->exp_nid_stats != NULL && \
332 (export)->exp_nid_stats->nid_stats != NULL) \
333 lprocfs_counter_incr( \
334 (export)->exp_nid_stats->nid_stats, coffset);\
337 #define MD_COUNTER_OFFSET(op) \
338 ((offsetof(struct md_ops, m_ ## op) - \
339 offsetof(struct md_ops, m_getstatus)) \
340 / sizeof(((struct md_ops *)(0))->m_getstatus))
342 #define MD_COUNTER_INCREMENT(obdx, op) \
343 if ((obd)->md_stats != NULL) { \
344 unsigned int coffset; \
345 coffset = (unsigned int)((obdx)->md_cntr_base) + \
346 MD_COUNTER_OFFSET(op); \
347 LASSERT(coffset < (obdx)->md_stats->ls_num); \
348 lprocfs_counter_incr((obdx)->md_stats, coffset); \
351 #define EXP_MD_COUNTER_INCREMENT(export, op) \
352 if ((export)->exp_obd->obd_stats != NULL) { \
353 unsigned int coffset; \
354 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
355 MD_COUNTER_OFFSET(op); \
356 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
357 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
358 if ((export)->exp_md_stats != NULL) \
359 lprocfs_counter_incr( \
360 (export)->exp_md_stats, coffset); \
364 #define OBD_COUNTER_OFFSET(op)
365 #define OBD_COUNTER_INCREMENT(obd, op)
366 #define EXP_COUNTER_INCREMENT(exp, op)
367 #define MD_COUNTER_INCREMENT(obd, op)
368 #define EXP_MD_COUNTER_INCREMENT(exp, op)
371 #define OBD_CHECK_MD_OP(obd, op, err) \
373 if (!OBT(obd) || !MDP((obd), op)) { \
375 CERROR("md_" #op ": dev %s/%d no operation\n", \
376 obd->obd_name, obd->obd_minor); \
381 #define EXP_CHECK_MD_OP(exp, op) \
383 if ((exp) == NULL) { \
384 CERROR("obd_" #op ": NULL export\n"); \
387 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
388 CERROR("obd_" #op ": cleaned up obd\n"); \
389 RETURN(-EOPNOTSUPP); \
391 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
392 CERROR("obd_" #op ": dev %s/%d no operation\n", \
393 (exp)->exp_obd->obd_name, \
394 (exp)->exp_obd->obd_minor); \
395 RETURN(-EOPNOTSUPP); \
400 #define OBD_CHECK_DT_OP(obd, op, err) \
402 if (!OBT(obd) || !OBP((obd), op)) { \
404 CERROR("obd_" #op ": dev %d no operation\n", \
410 #define EXP_CHECK_DT_OP(exp, op) \
412 if ((exp) == NULL) { \
413 CERROR("obd_" #op ": NULL export\n"); \
416 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
417 CERROR("obd_" #op ": cleaned up obd\n"); \
418 RETURN(-EOPNOTSUPP); \
420 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
421 CERROR("obd_" #op ": dev %d no operation\n", \
422 (exp)->exp_obd->obd_minor); \
423 RETURN(-EOPNOTSUPP); \
427 #define CTXT_CHECK_OP(ctxt, op, err) \
429 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
431 CERROR("lop_" #op ": dev %d no operation\n", \
432 ctxt->loc_obd->obd_minor); \
437 static inline int class_devno_max(void)
439 return MAX_OBD_DEVICES;
442 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
443 void *key, __u32 *vallen, void *val,
444 struct lov_stripe_md *lsm)
449 EXP_CHECK_DT_OP(exp, get_info);
450 EXP_COUNTER_INCREMENT(exp, get_info);
452 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
456 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
457 void *key, obd_count vallen, void *val,
458 struct ptlrpc_request_set *set)
463 EXP_CHECK_DT_OP(exp, set_info_async);
464 EXP_COUNTER_INCREMENT(exp, set_info_async);
466 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
472 * obd-lu integration.
474 * Functionality is being moved into new lu_device-based layering, but some
475 * pieces of configuration process are still based on obd devices.
477 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
478 * subsume ->o_setup() methods of obd devices they replace. The same for
479 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
480 * result, obd_setup() and obd_process_config() branch and call one XOR
483 * Yet neither lu_device_type_operations::ldto_device_fini() nor
484 * lu_device_type_operations::ldto_device_free() fully implement the
485 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
486 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
489 #define DECLARE_LU_VARS(ldt, d) \
490 struct lu_device_type *ldt; \
493 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
496 DECLARE_LU_VARS(ldt, d);
499 ldt = obd->obd_type->typ_lu;
501 struct lu_context session_ctx;
503 lu_context_init(&session_ctx, LCT_SESSION);
504 session_ctx.lc_thread = NULL;
505 lu_context_enter(&session_ctx);
507 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
509 env.le_ses = &session_ctx;
510 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
519 lu_context_exit(&session_ctx);
520 lu_context_fini(&session_ctx);
523 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
524 OBD_COUNTER_INCREMENT(obd, setup);
525 rc = OBP(obd, setup)(obd, cfg);
530 static inline int obd_precleanup(struct obd_device *obd,
531 enum obd_cleanup_stage cleanup_stage)
534 DECLARE_LU_VARS(ldt, d);
538 ldt = obd->obd_type->typ_lu;
540 if (ldt != NULL && d != NULL) {
541 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
544 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
546 ldt->ldt_ops->ldto_device_fini(&env, d);
551 OBD_CHECK_DT_OP(obd, precleanup, 0);
552 OBD_COUNTER_INCREMENT(obd, precleanup);
554 rc = OBP(obd, precleanup)(obd, cleanup_stage);
558 static inline int obd_cleanup(struct obd_device *obd)
561 DECLARE_LU_VARS(ldt, d);
566 ldt = obd->obd_type->typ_lu;
568 if (ldt != NULL && d != NULL) {
571 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
573 ldt->ldt_ops->ldto_device_free(&env, d);
575 obd->obd_lu_dev = NULL;
578 OBD_CHECK_DT_OP(obd, cleanup, 0);
579 OBD_COUNTER_INCREMENT(obd, cleanup);
581 rc = OBP(obd, cleanup)(obd);
586 obd_process_config(struct obd_device *obd, int datalen, void *data)
589 DECLARE_LU_VARS(ldt, d);
594 obd->obd_process_conf = 1;
595 ldt = obd->obd_type->typ_lu;
597 if (ldt != NULL && d != NULL) {
600 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
602 rc = d->ld_ops->ldo_process_config(&env, d, data);
606 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
607 rc = OBP(obd, process_config)(obd, datalen, data);
609 OBD_COUNTER_INCREMENT(obd, process_config);
610 obd->obd_process_conf = 0;
615 /* Pack an in-memory MD struct for storage on disk.
616 * Returns +ve size of packed MD (0 for free), or -ve error.
618 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
619 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
620 * If @*disk_tgt == NULL, it will be allocated
622 static inline int obd_packmd(struct obd_export *exp,
623 struct lov_mds_md **disk_tgt,
624 struct lov_stripe_md *mem_src)
629 EXP_CHECK_DT_OP(exp, packmd);
630 EXP_COUNTER_INCREMENT(exp, packmd);
632 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
636 static inline int obd_size_diskmd(struct obd_export *exp,
637 struct lov_stripe_md *mem_src)
639 return obd_packmd(exp, NULL, mem_src);
642 /* helper functions */
643 static inline int obd_alloc_diskmd(struct obd_export *exp,
644 struct lov_mds_md **disk_tgt)
647 LASSERT(*disk_tgt == NULL);
648 return obd_packmd(exp, disk_tgt, NULL);
651 static inline int obd_free_diskmd(struct obd_export *exp,
652 struct lov_mds_md **disk_tgt)
656 return obd_packmd(exp, disk_tgt, NULL);
659 /* Unpack an MD struct from disk to in-memory format.
660 * Returns +ve size of unpacked MD (0 for free), or -ve error.
662 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
663 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
664 * If @*mem_tgt == NULL, it will be allocated
666 static inline int obd_unpackmd(struct obd_export *exp,
667 struct lov_stripe_md **mem_tgt,
668 struct lov_mds_md *disk_src,
674 EXP_CHECK_DT_OP(exp, unpackmd);
675 EXP_COUNTER_INCREMENT(exp, unpackmd);
677 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
681 /* helper functions */
682 static inline int obd_alloc_memmd(struct obd_export *exp,
683 struct lov_stripe_md **mem_tgt)
686 LASSERT(*mem_tgt == NULL);
687 return obd_unpackmd(exp, mem_tgt, NULL, 0);
690 static inline int obd_free_memmd(struct obd_export *exp,
691 struct lov_stripe_md **mem_tgt)
697 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
702 static inline int obd_precreate(struct obd_export *exp)
707 EXP_CHECK_DT_OP(exp, precreate);
708 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
710 rc = OBP(exp->exp_obd, precreate)(exp);
714 static inline int obd_create_async(struct obd_export *exp,
715 struct obd_info *oinfo,
716 struct lov_stripe_md **ea,
717 struct obd_trans_info *oti)
722 EXP_CHECK_DT_OP(exp, create_async);
723 EXP_COUNTER_INCREMENT(exp, create_async);
725 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
729 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
730 struct lov_stripe_md **ea,
731 struct obd_trans_info *oti)
736 EXP_CHECK_DT_OP(exp, create);
737 EXP_COUNTER_INCREMENT(exp, create);
739 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
743 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
744 struct lov_stripe_md *ea,
745 struct obd_trans_info *oti,
746 struct obd_export *md_exp, void *capa)
751 EXP_CHECK_DT_OP(exp, destroy);
752 EXP_COUNTER_INCREMENT(exp, destroy);
754 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
758 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
763 EXP_CHECK_DT_OP(exp, getattr);
764 EXP_COUNTER_INCREMENT(exp, getattr);
766 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
770 static inline int obd_getattr_async(struct obd_export *exp,
771 struct obd_info *oinfo,
772 struct ptlrpc_request_set *set)
777 EXP_CHECK_DT_OP(exp, getattr_async);
778 EXP_COUNTER_INCREMENT(exp, getattr_async);
780 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
784 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
785 struct obd_trans_info *oti)
790 EXP_CHECK_DT_OP(exp, setattr);
791 EXP_COUNTER_INCREMENT(exp, setattr);
793 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
797 /* This performs all the requests set init/wait/destroy actions. */
798 static inline int obd_setattr_rqset(struct obd_export *exp,
799 struct obd_info *oinfo,
800 struct obd_trans_info *oti)
802 struct ptlrpc_request_set *set = NULL;
806 EXP_CHECK_DT_OP(exp, setattr_async);
807 EXP_COUNTER_INCREMENT(exp, setattr_async);
809 set = ptlrpc_prep_set();
813 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
815 rc = ptlrpc_set_wait(set);
816 ptlrpc_set_destroy(set);
820 /* This adds all the requests into @set if @set != NULL, otherwise
821 all requests are sent asynchronously without waiting for response. */
822 static inline int obd_setattr_async(struct obd_export *exp,
823 struct obd_info *oinfo,
824 struct obd_trans_info *oti,
825 struct ptlrpc_request_set *set)
830 EXP_CHECK_DT_OP(exp, setattr_async);
831 EXP_COUNTER_INCREMENT(exp, setattr_async);
833 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
837 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
840 struct obd_device *obd = imp->imp_obd;
844 OBD_CHECK_DEV_ACTIVE(obd);
845 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
846 OBD_COUNTER_INCREMENT(obd, add_conn);
848 rc = OBP(obd, add_conn)(imp, uuid, priority);
852 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
854 struct obd_device *obd = imp->imp_obd;
858 OBD_CHECK_DEV_ACTIVE(obd);
859 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
860 OBD_COUNTER_INCREMENT(obd, del_conn);
862 rc = OBP(obd, del_conn)(imp, uuid);
866 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
868 struct obd_uuid *uuid;
871 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
872 EXP_COUNTER_INCREMENT(exp, get_uuid);
874 uuid = OBP(exp->exp_obd, get_uuid)(exp);
878 static inline int obd_connect(const struct lu_env *env,
879 struct obd_export **exp,struct obd_device *obd,
880 struct obd_uuid *cluuid,
881 struct obd_connect_data *d,
885 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
889 OBD_CHECK_DEV_ACTIVE(obd);
890 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
891 OBD_COUNTER_INCREMENT(obd, connect);
893 rc = OBP(obd, connect)(env, exp, obd, cluuid, d, localdata);
894 /* check that only subset is granted */
895 LASSERT(ergo(d != NULL,
896 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
900 static inline int obd_reconnect(const struct lu_env *env,
901 struct obd_export *exp,
902 struct obd_device *obd,
903 struct obd_uuid *cluuid,
904 struct obd_connect_data *d,
908 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
913 OBD_CHECK_DEV_ACTIVE(obd);
914 OBD_CHECK_DT_OP(obd, reconnect, 0);
915 OBD_COUNTER_INCREMENT(obd, reconnect);
917 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
918 /* check that only subset is granted */
919 LASSERT(ergo(d != NULL,
920 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
924 static inline int obd_disconnect(struct obd_export *exp)
929 EXP_CHECK_DT_OP(exp, disconnect);
930 EXP_COUNTER_INCREMENT(exp, disconnect);
932 rc = OBP(exp->exp_obd, disconnect)(exp);
936 static inline int obd_fid_init(struct obd_export *exp)
941 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
942 EXP_COUNTER_INCREMENT(exp, fid_init);
944 rc = OBP(exp->exp_obd, fid_init)(exp);
948 static inline int obd_fid_fini(struct obd_export *exp)
953 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
954 EXP_COUNTER_INCREMENT(exp, fid_fini);
956 rc = OBP(exp->exp_obd, fid_fini)(exp);
960 static inline int obd_fid_alloc(struct obd_export *exp,
962 struct md_op_data *op_data)
967 EXP_CHECK_DT_OP(exp, fid_alloc);
968 EXP_COUNTER_INCREMENT(exp, fid_alloc);
970 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
974 static inline int obd_fid_delete(struct obd_export *exp,
975 const struct lu_fid *fid)
980 EXP_CHECK_DT_OP(exp, fid_delete);
981 EXP_COUNTER_INCREMENT(exp, fid_delete);
983 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
987 static inline int obd_ping(struct obd_export *exp)
992 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
993 EXP_COUNTER_INCREMENT(exp, ping);
995 rc = OBP(exp->exp_obd, ping)(exp);
999 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1004 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1005 OBD_COUNTER_INCREMENT(obd, pool_new);
1007 rc = OBP(obd, pool_new)(obd, poolname);
1011 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1016 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1017 OBD_COUNTER_INCREMENT(obd, pool_del);
1019 rc = OBP(obd, pool_del)(obd, poolname);
1023 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1028 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1029 OBD_COUNTER_INCREMENT(obd, pool_add);
1031 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1035 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1040 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1041 OBD_COUNTER_INCREMENT(obd, pool_rem);
1043 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1047 static inline void obd_getref(struct obd_device *obd)
1050 if (OBT(obd) && OBP(obd, getref)) {
1051 OBD_COUNTER_INCREMENT(obd, getref);
1052 OBP(obd, getref)(obd);
1057 static inline void obd_putref(struct obd_device *obd)
1060 if (OBT(obd) && OBP(obd, putref)) {
1061 OBD_COUNTER_INCREMENT(obd, putref);
1062 OBP(obd, putref)(obd);
1067 static inline int obd_init_export(struct obd_export *exp)
1072 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1073 OBP((exp)->exp_obd, init_export))
1074 rc = OBP(exp->exp_obd, init_export)(exp);
1078 static inline int obd_destroy_export(struct obd_export *exp)
1081 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1082 OBP((exp)->exp_obd, destroy_export))
1083 OBP(exp->exp_obd, destroy_export)(exp);
1087 static inline int obd_extent_calc(struct obd_export *exp,
1088 struct lov_stripe_md *md,
1089 int cmd, obd_off *offset)
1093 EXP_CHECK_DT_OP(exp, extent_calc);
1094 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1098 static inline struct dentry *
1099 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1101 LASSERT(exp->exp_obd);
1103 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1108 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1110 LASSERT(exp->exp_obd);
1111 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1113 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1114 dentry, exp->exp_obd);
1120 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
1123 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1124 * If the cache is older than @max_age we will get a new value from the
1125 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1126 static inline int obd_statfs_async(struct obd_device *obd,
1127 struct obd_info *oinfo,
1129 struct ptlrpc_request_set *rqset)
1137 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1138 OBD_COUNTER_INCREMENT(obd, statfs);
1140 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1141 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1142 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1143 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1145 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1146 " objects "LPU64"/"LPU64"\n",
1147 obd->obd_name, &obd->obd_osfs,
1148 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1149 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1150 spin_lock(&obd->obd_osfs_lock);
1151 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1152 spin_unlock(&obd->obd_osfs_lock);
1153 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1154 if (oinfo->oi_cb_up)
1155 oinfo->oi_cb_up(oinfo, 0);
1160 static inline int obd_statfs_rqset(struct obd_device *obd,
1161 struct obd_statfs *osfs, __u64 max_age,
1164 struct ptlrpc_request_set *set = NULL;
1165 struct obd_info oinfo = { { { 0 } } };
1169 set = ptlrpc_prep_set();
1173 oinfo.oi_osfs = osfs;
1174 oinfo.oi_flags = flags;
1175 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1177 rc = ptlrpc_set_wait(set);
1178 ptlrpc_set_destroy(set);
1182 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1183 * If the cache is older than @max_age we will get a new value from the
1184 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1185 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1186 __u64 max_age, __u32 flags)
1194 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1195 OBD_COUNTER_INCREMENT(obd, statfs);
1197 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1198 obd->obd_osfs_age, max_age);
1199 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1200 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1202 spin_lock(&obd->obd_osfs_lock);
1203 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1204 obd->obd_osfs_age = cfs_time_current_64();
1205 spin_unlock(&obd->obd_osfs_lock);
1208 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1209 " objects "LPU64"/"LPU64"\n",
1210 obd->obd_name, &obd->obd_osfs,
1211 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1212 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1213 spin_lock(&obd->obd_osfs_lock);
1214 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1215 spin_unlock(&obd->obd_osfs_lock);
1220 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1221 struct lov_stripe_md *ea, obd_size start,
1222 obd_size end, void *capa)
1227 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1228 EXP_COUNTER_INCREMENT(exp, sync);
1230 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1234 static inline int obd_punch_rqset(struct obd_export *exp,
1235 struct obd_info *oinfo,
1236 struct obd_trans_info *oti)
1238 struct ptlrpc_request_set *set = NULL;
1242 EXP_CHECK_DT_OP(exp, punch);
1243 EXP_COUNTER_INCREMENT(exp, punch);
1245 set = ptlrpc_prep_set();
1249 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1251 rc = ptlrpc_set_wait(set);
1252 ptlrpc_set_destroy(set);
1256 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1257 struct obd_trans_info *oti,
1258 struct ptlrpc_request_set *rqset)
1263 EXP_CHECK_DT_OP(exp, punch);
1264 EXP_COUNTER_INCREMENT(exp, punch);
1266 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1270 static inline int obd_brw(int cmd, struct obd_export *exp,
1271 struct obd_info *oinfo, obd_count oa_bufs,
1272 struct brw_page *pg, struct obd_trans_info *oti)
1277 EXP_CHECK_DT_OP(exp, brw);
1278 EXP_COUNTER_INCREMENT(exp, brw);
1280 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1281 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1282 "or OBD_BRW_CHECK\n");
1286 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1290 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1291 int objcount, struct obd_ioobj *obj,
1292 struct niobuf_remote *remote, int *pages,
1293 struct niobuf_local *local,
1294 struct obd_trans_info *oti,
1295 struct lustre_capa *capa)
1300 EXP_CHECK_DT_OP(exp, preprw);
1301 EXP_COUNTER_INCREMENT(exp, preprw);
1303 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1304 pages, local, oti, capa);
1308 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1309 int objcount, struct obd_ioobj *obj,
1310 struct niobuf_remote *rnb, int pages,
1311 struct niobuf_local *local,
1312 struct obd_trans_info *oti, int rc)
1316 EXP_CHECK_DT_OP(exp, commitrw);
1317 EXP_COUNTER_INCREMENT(exp, commitrw);
1319 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1320 rnb, pages, local, oti, rc);
1324 static inline int obd_merge_lvb(struct obd_export *exp,
1325 struct lov_stripe_md *lsm,
1326 struct ost_lvb *lvb, int kms_only)
1331 EXP_CHECK_DT_OP(exp, merge_lvb);
1332 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1334 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1338 static inline int obd_adjust_kms(struct obd_export *exp,
1339 struct lov_stripe_md *lsm, obd_off size,
1345 EXP_CHECK_DT_OP(exp, adjust_kms);
1346 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1348 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1352 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1353 int len, void *karg, void *uarg)
1358 EXP_CHECK_DT_OP(exp, iocontrol);
1359 EXP_COUNTER_INCREMENT(exp, iocontrol);
1361 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1365 static inline int obd_enqueue_rqset(struct obd_export *exp,
1366 struct obd_info *oinfo,
1367 struct ldlm_enqueue_info *einfo)
1369 struct ptlrpc_request_set *set = NULL;
1373 EXP_CHECK_DT_OP(exp, enqueue);
1374 EXP_COUNTER_INCREMENT(exp, enqueue);
1376 set = ptlrpc_prep_set();
1380 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1382 rc = ptlrpc_set_wait(set);
1383 ptlrpc_set_destroy(set);
1387 static inline int obd_enqueue(struct obd_export *exp,
1388 struct obd_info *oinfo,
1389 struct ldlm_enqueue_info *einfo,
1390 struct ptlrpc_request_set *set)
1395 EXP_CHECK_DT_OP(exp, enqueue);
1396 EXP_COUNTER_INCREMENT(exp, enqueue);
1398 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1402 static inline int obd_change_cbdata(struct obd_export *exp,
1403 struct lov_stripe_md *lsm,
1404 ldlm_iterator_t it, void *data)
1409 EXP_CHECK_DT_OP(exp, change_cbdata);
1410 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1412 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1416 static inline int obd_cancel(struct obd_export *exp,
1417 struct lov_stripe_md *ea, __u32 mode,
1418 struct lustre_handle *lockh)
1423 EXP_CHECK_DT_OP(exp, cancel);
1424 EXP_COUNTER_INCREMENT(exp, cancel);
1426 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1430 static inline int obd_cancel_unused(struct obd_export *exp,
1431 struct lov_stripe_md *ea,
1432 int flags, void *opaque)
1437 EXP_CHECK_DT_OP(exp, cancel_unused);
1438 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1440 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1444 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1445 struct obd_capa *oc, struct obd_client_handle *handle,
1451 EXP_CHECK_DT_OP(exp, pin);
1452 EXP_COUNTER_INCREMENT(exp, pin);
1454 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1458 static inline int obd_unpin(struct obd_export *exp,
1459 struct obd_client_handle *handle, int flag)
1464 EXP_CHECK_DT_OP(exp, unpin);
1465 EXP_COUNTER_INCREMENT(exp, unpin);
1467 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1472 static inline void obd_import_event(struct obd_device *obd,
1473 struct obd_import *imp,
1474 enum obd_import_event event)
1478 CERROR("NULL device\n");
1482 if (obd->obd_set_up && OBP(obd, import_event)) {
1483 OBD_COUNTER_INCREMENT(obd, import_event);
1484 OBP(obd, import_event)(obd, imp, event);
1489 static inline int obd_llog_connect(struct obd_export *exp,
1490 struct llogd_conn_body *body)
1495 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1496 EXP_COUNTER_INCREMENT(exp, llog_connect);
1498 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1503 static inline int obd_notify(struct obd_device *obd,
1504 struct obd_device *watched,
1505 enum obd_notify_event ev,
1512 /* the check for async_recov is a complete hack - I'm hereby
1513 overloading the meaning to also mean "this was called from
1514 mds_postsetup". I know that my mds is able to handle notifies
1515 by this point, and it needs to get them to execute mds_postrecov. */
1516 if (!obd->obd_set_up && !obd->obd_async_recov) {
1517 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1521 if (!OBP(obd, notify)) {
1522 CERROR("obd %s has no notify handler\n", obd->obd_name);
1526 OBD_COUNTER_INCREMENT(obd, notify);
1527 rc = OBP(obd, notify)(obd, watched, ev, data);
1531 static inline int obd_notify_observer(struct obd_device *observer,
1532 struct obd_device *observed,
1533 enum obd_notify_event ev,
1539 struct obd_notify_upcall *onu;
1541 if (observer->obd_observer)
1542 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1546 * Also, call non-obd listener, if any
1548 onu = &observer->obd_upcall;
1549 if (onu->onu_upcall != NULL)
1550 rc2 = onu->onu_upcall(observer, observed, ev,
1551 onu->onu_owner, NULL);
1555 return rc1 ? rc1 : rc2;
1558 static inline int obd_quotacheck(struct obd_export *exp,
1559 struct obd_quotactl *oqctl)
1564 EXP_CHECK_DT_OP(exp, quotacheck);
1565 EXP_COUNTER_INCREMENT(exp, quotacheck);
1567 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1571 static inline int obd_quotactl(struct obd_export *exp,
1572 struct obd_quotactl *oqctl)
1577 EXP_CHECK_DT_OP(exp, quotactl);
1578 EXP_COUNTER_INCREMENT(exp, quotactl);
1580 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1584 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1585 struct quota_adjust_qunit *oqaq,
1586 struct lustre_quota_ctxt *qctxt)
1588 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1589 struct timeval work_start;
1590 struct timeval work_end;
1596 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1598 do_gettimeofday(&work_start);
1600 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1601 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1603 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt);
1605 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1607 do_gettimeofday(&work_end);
1608 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1609 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1616 static inline int obd_health_check(struct obd_device *obd)
1618 /* returns: 0 on healthy
1619 * >0 on unhealthy + reason code/flag
1620 * however the only suppored reason == 1 right now
1621 * We'll need to define some better reasons
1622 * or flags in the future.
1628 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1629 if (obd == NULL || !OBT(obd)) {
1630 CERROR("cleaned up obd\n");
1631 RETURN(-EOPNOTSUPP);
1633 if (!obd->obd_set_up || obd->obd_stopping)
1635 if (!OBP(obd, health_check))
1638 rc = OBP(obd, health_check)(obd);
1642 static inline int obd_register_observer(struct obd_device *obd,
1643 struct obd_device *observer)
1647 down_write(&obd->obd_observer_link_sem);
1648 if (obd->obd_observer && observer) {
1649 up_write(&obd->obd_observer_link_sem);
1652 obd->obd_observer = observer;
1653 up_write(&obd->obd_observer_link_sem);
1657 static inline int obd_pin_observer(struct obd_device *obd,
1658 struct obd_device **observer)
1661 down_read(&obd->obd_observer_link_sem);
1662 if (!obd->obd_observer) {
1664 up_read(&obd->obd_observer_link_sem);
1667 *observer = obd->obd_observer;
1671 static inline int obd_unpin_observer(struct obd_device *obd)
1674 up_read(&obd->obd_observer_link_sem);
1679 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1680 obd_page_removal_cb_t cb,
1681 obd_pin_extent_cb pin_cb)
1686 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1687 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1689 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1693 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1694 obd_page_removal_cb_t cb)
1699 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1700 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1702 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1706 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1707 obd_lock_cancel_cb cb)
1712 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1713 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1715 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1719 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1720 obd_lock_cancel_cb cb)
1725 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1726 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1728 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1733 /* metadata helpers */
1734 static inline int md_getstatus(struct obd_export *exp,
1735 struct lu_fid *fid, struct obd_capa **pc)
1740 EXP_CHECK_MD_OP(exp, getstatus);
1741 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1742 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1746 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1747 struct obd_capa *oc, obd_valid valid, int ea_size,
1748 struct ptlrpc_request **request)
1752 EXP_CHECK_MD_OP(exp, getattr);
1753 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1754 rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1759 static inline int md_change_cbdata(struct obd_export *exp,
1760 const struct lu_fid *fid,
1761 ldlm_iterator_t it, void *data)
1765 EXP_CHECK_MD_OP(exp, change_cbdata);
1766 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1767 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1771 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1772 struct md_open_data *mod,
1773 struct ptlrpc_request **request)
1777 EXP_CHECK_MD_OP(exp, close);
1778 EXP_MD_COUNTER_INCREMENT(exp, close);
1779 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1783 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1784 const void *data, int datalen, int mode, __u32 uid,
1785 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1786 struct ptlrpc_request **request)
1790 EXP_CHECK_MD_OP(exp, create);
1791 EXP_MD_COUNTER_INCREMENT(exp, create);
1792 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1793 uid, gid, cap_effective, rdev, request);
1797 static inline int md_done_writing(struct obd_export *exp,
1798 struct md_op_data *op_data,
1799 struct md_open_data *mod)
1803 EXP_CHECK_MD_OP(exp, done_writing);
1804 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1805 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1809 static inline int md_enqueue(struct obd_export *exp,
1810 struct ldlm_enqueue_info *einfo,
1811 struct lookup_intent *it,
1812 struct md_op_data *op_data,
1813 struct lustre_handle *lockh,
1814 void *lmm, int lmmsize,
1815 struct ptlrpc_request **req,
1816 int extra_lock_flags)
1820 EXP_CHECK_MD_OP(exp, enqueue);
1821 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1822 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1823 lmm, lmmsize, req, extra_lock_flags);
1827 static inline int md_getattr_name(struct obd_export *exp,
1828 const struct lu_fid *fid, struct obd_capa *oc,
1829 const char *name, int namelen,
1830 obd_valid valid, int ea_size, __u32 suppgid,
1831 struct ptlrpc_request **request)
1835 EXP_CHECK_MD_OP(exp, getattr_name);
1836 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1837 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1838 valid, ea_size, suppgid, request);
1842 static inline int md_intent_lock(struct obd_export *exp,
1843 struct md_op_data *op_data, void *lmm,
1844 int lmmsize, struct lookup_intent *it,
1845 int flags, struct ptlrpc_request **reqp,
1846 ldlm_blocking_callback cb_blocking,
1847 int extra_lock_flags)
1851 EXP_CHECK_MD_OP(exp, intent_lock);
1852 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1853 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1854 it, flags, reqp, cb_blocking,
1859 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1860 struct ptlrpc_request **request)
1864 EXP_CHECK_MD_OP(exp, link);
1865 EXP_MD_COUNTER_INCREMENT(exp, link);
1866 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1870 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1871 const char *old, int oldlen, const char *new,
1872 int newlen, struct ptlrpc_request **request)
1876 EXP_CHECK_MD_OP(exp, rename);
1877 EXP_MD_COUNTER_INCREMENT(exp, rename);
1878 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1883 static inline int md_is_subdir(struct obd_export *exp,
1884 const struct lu_fid *pfid,
1885 const struct lu_fid *cfid,
1886 struct ptlrpc_request **request)
1890 EXP_CHECK_MD_OP(exp, is_subdir);
1891 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1892 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1896 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1897 void *ea, int ealen, void *ea2, int ea2len,
1898 struct ptlrpc_request **request,
1899 struct md_open_data **mod)
1903 EXP_CHECK_MD_OP(exp, setattr);
1904 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1905 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1906 ea2, ea2len, request, mod);
1910 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1911 struct obd_capa *oc, struct ptlrpc_request **request)
1915 EXP_CHECK_MD_OP(exp, sync);
1916 EXP_MD_COUNTER_INCREMENT(exp, sync);
1917 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1921 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1922 struct obd_capa *oc, __u64 offset,
1924 struct ptlrpc_request **request)
1928 EXP_CHECK_MD_OP(exp, readpage);
1929 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1930 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1934 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1935 struct ptlrpc_request **request)
1939 EXP_CHECK_MD_OP(exp, unlink);
1940 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1941 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1945 static inline int md_get_lustre_md(struct obd_export *exp,
1946 struct ptlrpc_request *req,
1947 struct obd_export *dt_exp,
1948 struct obd_export *md_exp,
1949 struct lustre_md *md)
1952 EXP_CHECK_MD_OP(exp, get_lustre_md);
1953 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1954 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1957 static inline int md_free_lustre_md(struct obd_export *exp,
1958 struct lustre_md *md)
1961 EXP_CHECK_MD_OP(exp, free_lustre_md);
1962 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1963 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1966 static inline int md_setxattr(struct obd_export *exp,
1967 const struct lu_fid *fid, struct obd_capa *oc,
1968 obd_valid valid, const char *name,
1969 const char *input, int input_size,
1970 int output_size, int flags, __u32 suppgid,
1971 struct ptlrpc_request **request)
1974 EXP_CHECK_MD_OP(exp, setxattr);
1975 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1976 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1977 input_size, output_size, flags,
1981 static inline int md_getxattr(struct obd_export *exp,
1982 const struct lu_fid *fid, struct obd_capa *oc,
1983 obd_valid valid, const char *name,
1984 const char *input, int input_size,
1985 int output_size, int flags,
1986 struct ptlrpc_request **request)
1989 EXP_CHECK_MD_OP(exp, getxattr);
1990 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1991 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1992 input_size, output_size, flags,
1996 static inline int md_set_open_replay_data(struct obd_export *exp,
1997 struct obd_client_handle *och,
1998 struct ptlrpc_request *open_req)
2001 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2002 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2003 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2006 static inline int md_clear_open_replay_data(struct obd_export *exp,
2007 struct obd_client_handle *och)
2010 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2011 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2012 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2015 static inline int md_set_lock_data(struct obd_export *exp,
2016 __u64 *lockh, void *data, __u32 *bits)
2019 EXP_CHECK_MD_OP(exp, set_lock_data);
2020 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2021 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2024 static inline int md_cancel_unused(struct obd_export *exp,
2025 const struct lu_fid *fid,
2026 ldlm_policy_data_t *policy,
2027 ldlm_mode_t mode, int flags, void *opaque)
2032 EXP_CHECK_MD_OP(exp, cancel_unused);
2033 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2035 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2040 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2041 const struct lu_fid *fid,
2043 ldlm_policy_data_t *policy,
2045 struct lustre_handle *lockh)
2048 EXP_CHECK_MD_OP(exp, lock_match);
2049 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2050 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2051 policy, mode, lockh));
2054 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2055 int def_asize, int cookiesize)
2058 EXP_CHECK_MD_OP(exp, init_ea_size);
2059 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2060 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2064 static inline int md_get_remote_perm(struct obd_export *exp,
2065 const struct lu_fid *fid,
2066 struct obd_capa *oc, __u32 suppgid,
2067 struct ptlrpc_request **request)
2070 EXP_CHECK_MD_OP(exp, get_remote_perm);
2071 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2072 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2076 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2081 EXP_CHECK_MD_OP(exp, renew_capa);
2082 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2083 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2087 static inline int md_unpack_capa(struct obd_export *exp,
2088 struct ptlrpc_request *req,
2089 const struct req_msg_field *field,
2090 struct obd_capa **oc)
2094 EXP_CHECK_MD_OP(exp, unpack_capa);
2095 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2096 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2100 static inline int md_intent_getattr_async(struct obd_export *exp,
2101 struct md_enqueue_info *minfo,
2102 struct ldlm_enqueue_info *einfo)
2106 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2107 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2108 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2112 static inline int md_revalidate_lock(struct obd_export *exp,
2113 struct lookup_intent *it,
2118 EXP_CHECK_MD_OP(exp, revalidate_lock);
2119 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2120 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2125 /* OBD Metadata Support */
2127 extern int obd_init_caches(void);
2128 extern void obd_cleanup_caches(void);
2130 /* support routines */
2131 extern cfs_mem_cache_t *obdo_cachep;
2133 #define OBDO_ALLOC(ptr) \
2135 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
2138 #define OBDO_FREE(ptr) \
2140 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2144 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2146 /* something here */
2149 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2151 /* something here */
2154 /* I'm as embarrassed about this as you are.
2156 * <shaver> // XXX do not look into _superhack with remaining eye
2157 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2158 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2161 extern void obd_sysctl_init (void);
2162 extern void obd_sysctl_clean (void);
2165 typedef __u8 class_uuid_t[16];
2166 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2169 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2170 int class_add_uuid(const char *uuid, __u64 nid);
2171 int class_del_uuid (const char *uuid);
2172 void class_init_uuidlist(void);
2173 void class_exit_uuidlist(void);
2176 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2177 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2180 void ll_generate_random_uuid(class_uuid_t uuid_out);
2182 #endif /* __LINUX_OBD_CLASS_H */