4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, Whamcloud, Inc.
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 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
62 * and resends for avoid deadlocks */
63 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
65 #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd
66 * instead of a specific set. This
67 * means that we cannot rely on the set
68 * interpret routine to be called.
69 * lov_statfs_fini() must thus be called
70 * by the request interpret routine */
72 #define OBD_FL_PUNCH 0x00000001 /* To indicate it is punch operation */
74 /* OBD Device Declarations */
75 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
76 extern rwlock_t obd_dev_lock;
78 /* OBD Operations Declarations */
79 extern struct obd_device *class_conn2obd(struct lustre_handle *);
80 extern struct obd_device *class_exp2obd(struct obd_export *);
81 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
82 extern int lustre_get_jobid(char *jobid);
84 struct lu_device_type;
87 struct obd_export *class_conn2export(struct lustre_handle *);
88 int class_register_type(struct obd_ops *, struct md_ops *,
89 struct lprocfs_vars *, const char *nm,
90 struct lu_device_type *ldt);
91 int class_unregister_type(const char *nm);
93 struct obd_device *class_newdev(const char *type_name, const char *name);
94 void class_release_dev(struct obd_device *obd);
96 int class_name2dev(const char *name);
97 struct obd_device *class_name2obd(const char *name);
98 int class_uuid2dev(struct obd_uuid *uuid);
99 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
100 void class_obd_list(void);
101 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
102 const char * typ_name,
103 struct obd_uuid *grp_uuid);
104 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
106 struct obd_device * class_num2obd(int num);
108 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
110 char *obd_export_nid2str(struct obd_export *exp);
112 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
113 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
114 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
116 int obd_zombie_impexp_init(void);
117 void obd_zombie_impexp_stop(void);
118 void obd_zombie_impexp_cull(void);
119 void obd_zombie_barrier(void);
120 void obd_exports_barrier(struct obd_device *obd);
121 int kuc_len(int payload_len);
122 struct kuc_hdr * kuc_ptr(void *p);
123 int kuc_ispayload(void *p);
124 void *kuc_alloc(int payload_len, int transport, int type);
125 void kuc_free(void *p, int payload_len);
129 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
130 struct llog_rec_hdr *, void *);
132 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
133 const char *new_name);
134 int class_process_config(struct lustre_cfg *lcfg);
135 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
136 struct lustre_cfg *lcfg, void *data);
137 int class_attach(struct lustre_cfg *lcfg);
138 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
139 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
140 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
141 struct obd_device *class_incref(struct obd_device *obd,
142 const char *scope, const void *source);
143 void class_decref(struct obd_device *obd,
144 const char *scope, const void *source);
145 void dump_exports(struct obd_device *obd, int locks);
146 int class_config_llog_handler(const struct lu_env *env,
147 struct llog_handle *handle,
148 struct llog_rec_hdr *rec, void *data);
149 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
150 int class_add_uuid(const char *uuid, __u64 nid);
154 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
156 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
158 memset(lvars, 0, sizeof(*lvars));
162 #define CFG_F_START 0x01 /* Set when we start updating from a log */
163 #define CFG_F_MARKER 0x02 /* We are within a maker */
164 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
165 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
166 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
168 /* Passed as data param to class_config_parse_llog */
169 struct config_llog_instance {
172 struct super_block *cfg_sb;
173 struct obd_uuid cfg_uuid;
174 llog_cb_t cfg_callback;
175 int cfg_last_idx; /* for partial llog processing */
178 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
179 char *name, struct config_llog_instance *cfg);
180 int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
181 char *name, struct config_llog_instance *cfg);
185 CONFIG_T_SPTLRPC = 1,
186 CONFIG_T_RECOVER = 2,
190 /* list of active configuration logs */
191 struct config_llog_data {
192 struct ldlm_res_id cld_resid;
193 struct config_llog_instance cld_cfg;
194 cfs_list_t cld_list_chain;
195 cfs_atomic_t cld_refcount;
196 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
197 struct config_llog_data *cld_recover; /* imperative recover log */
198 struct obd_export *cld_mgcexp;
199 struct mutex cld_lock;
201 unsigned int cld_stopping:1, /* we were told to stop
203 cld_lostlock:1; /* lock not requeued */
207 struct lustre_profile {
214 struct lustre_profile *class_get_profile(const char * prof);
215 void class_del_profile(const char *prof);
216 void class_del_profiles(void);
218 #if LUSTRE_TRACKS_LOCK_EXP_REFS
220 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
221 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
222 extern void (*class_export_dump_hook)(struct obd_export *);
226 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
227 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
231 #define class_export_rpc_get(exp) \
233 cfs_atomic_inc(&(exp)->exp_rpc_count); \
234 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
235 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
236 class_export_get(exp); \
239 #define class_export_rpc_put(exp) \
241 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
242 cfs_atomic_dec(&(exp)->exp_rpc_count); \
243 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
244 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
245 class_export_put(exp); \
248 #define class_export_lock_get(exp, lock) \
250 cfs_atomic_inc(&(exp)->exp_locks_count); \
251 __class_export_add_lock_ref(exp, lock); \
252 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
253 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
254 class_export_get(exp); \
257 #define class_export_lock_put(exp, lock) \
259 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
260 cfs_atomic_dec(&(exp)->exp_locks_count); \
261 __class_export_del_lock_ref(exp, lock); \
262 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
263 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
264 class_export_put(exp); \
267 #define class_export_cb_get(exp) \
269 cfs_atomic_inc(&(exp)->exp_cb_count); \
270 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
271 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
272 class_export_get(exp); \
275 #define class_export_cb_put(exp) \
277 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
278 cfs_atomic_dec(&(exp)->exp_cb_count); \
279 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
280 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
281 class_export_put(exp); \
285 struct obd_export *class_export_get(struct obd_export *exp);
286 void class_export_put(struct obd_export *exp);
287 struct obd_export *class_new_export(struct obd_device *obddev,
288 struct obd_uuid *cluuid);
289 void class_unlink_export(struct obd_export *exp);
291 struct obd_import *class_import_get(struct obd_import *);
292 void class_import_put(struct obd_import *);
293 struct obd_import *class_new_import(struct obd_device *obd);
294 void class_destroy_import(struct obd_import *exp);
296 struct obd_type *class_search_type(const char *name);
297 struct obd_type *class_get_type(const char *name);
298 void class_put_type(struct obd_type *type);
299 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
300 struct obd_uuid *cluuid);
301 int class_disconnect(struct obd_export *exp);
302 void class_fail_export(struct obd_export *exp);
303 int class_connected_export(struct obd_export *exp);
304 void class_disconnect_exports(struct obd_device *obddev);
305 int class_manual_cleanup(struct obd_device *obd);
306 void class_disconnect_stale_exports(struct obd_device *,
307 int (*test_export)(struct obd_export *));
308 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
310 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
311 (obd->obd_force ? OBD_OPT_FORCE : 0) |
312 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
316 #ifdef HAVE_SERVER_SUPPORT
317 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
319 LASSERT(exp->exp_obd);
320 return exp->exp_obd->u.obt.obt_lut;
323 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
325 LASSERT(obd->u.obt.obt_lut);
326 return &obd->u.obt.obt_lut->lut_lsd;
330 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
331 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
332 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
333 unsigned int ia_valid);
334 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
335 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
336 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
339 #define OBT(dev) (dev)->obd_type
340 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
341 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
342 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
344 /* Ensure obd_setup: used for cleanup which must be called
345 while obd is stopping */
346 #define OBD_CHECK_DEV(obd) \
349 CERROR("NULL device\n"); \
354 /* ensure obd_setup and !obd_stopping */
355 #define OBD_CHECK_DEV_ACTIVE(obd) \
357 OBD_CHECK_DEV(obd); \
358 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
359 CERROR("Device %d not setup\n", \
367 #define OBD_COUNTER_OFFSET(op) \
368 ((offsetof(struct obd_ops, o_ ## op) - \
369 offsetof(struct obd_ops, o_iocontrol)) \
370 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
372 #define OBD_COUNTER_INCREMENT(obdx, op) \
373 if ((obdx)->obd_stats != NULL) { \
374 unsigned int coffset; \
375 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
376 OBD_COUNTER_OFFSET(op); \
377 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
378 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
381 #define EXP_COUNTER_INCREMENT(export, op) \
382 if ((export)->exp_obd->obd_stats != NULL) { \
383 unsigned int coffset; \
384 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
385 OBD_COUNTER_OFFSET(op); \
386 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
387 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
388 if ((export)->exp_nid_stats != NULL && \
389 (export)->exp_nid_stats->nid_stats != NULL) \
390 lprocfs_counter_incr( \
391 (export)->exp_nid_stats->nid_stats, coffset);\
394 #define MD_COUNTER_OFFSET(op) \
395 ((offsetof(struct md_ops, m_ ## op) - \
396 offsetof(struct md_ops, m_getstatus)) \
397 / sizeof(((struct md_ops *)(0))->m_getstatus))
399 #define MD_COUNTER_INCREMENT(obdx, op) \
400 if ((obd)->md_stats != NULL) { \
401 unsigned int coffset; \
402 coffset = (unsigned int)((obdx)->md_cntr_base) + \
403 MD_COUNTER_OFFSET(op); \
404 LASSERT(coffset < (obdx)->md_stats->ls_num); \
405 lprocfs_counter_incr((obdx)->md_stats, coffset); \
408 #define EXP_MD_COUNTER_INCREMENT(export, op) \
409 if ((export)->exp_obd->obd_stats != NULL) { \
410 unsigned int coffset; \
411 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
412 MD_COUNTER_OFFSET(op); \
413 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
414 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
415 if ((export)->exp_md_stats != NULL) \
416 lprocfs_counter_incr( \
417 (export)->exp_md_stats, coffset); \
421 #define OBD_COUNTER_OFFSET(op)
422 #define OBD_COUNTER_INCREMENT(obd, op)
423 #define EXP_COUNTER_INCREMENT(exp, op)
424 #define MD_COUNTER_INCREMENT(obd, op)
425 #define EXP_MD_COUNTER_INCREMENT(exp, op)
428 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
430 /* Always add in ldlm_stats */
431 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
432 ,LPROCFS_STATS_FLAG_NOPERCPU);
433 if (tmp->nid_ldlm_stats == NULL)
436 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
438 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
439 tmp->nid_ldlm_stats);
442 #define OBD_CHECK_MD_OP(obd, op, err) \
444 if (!OBT(obd) || !MDP((obd), op)) { \
446 CERROR("md_" #op ": dev %s/%d no operation\n", \
447 obd->obd_name, obd->obd_minor); \
452 #define EXP_CHECK_MD_OP(exp, op) \
454 if ((exp) == NULL) { \
455 CERROR("obd_" #op ": NULL export\n"); \
458 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
459 CERROR("obd_" #op ": cleaned up obd\n"); \
460 RETURN(-EOPNOTSUPP); \
462 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
463 CERROR("obd_" #op ": dev %s/%d no operation\n", \
464 (exp)->exp_obd->obd_name, \
465 (exp)->exp_obd->obd_minor); \
466 RETURN(-EOPNOTSUPP); \
471 #define OBD_CHECK_DT_OP(obd, op, err) \
473 if (!OBT(obd) || !OBP((obd), op)) { \
475 CERROR("obd_" #op ": dev %d no operation\n", \
481 #define EXP_CHECK_DT_OP(exp, op) \
483 if ((exp) == NULL) { \
484 CERROR("obd_" #op ": NULL export\n"); \
487 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
488 CERROR("obd_" #op ": cleaned up obd\n"); \
489 RETURN(-EOPNOTSUPP); \
491 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
492 CERROR("obd_" #op ": dev %d no operation\n", \
493 (exp)->exp_obd->obd_minor); \
494 RETURN(-EOPNOTSUPP); \
498 #define CTXT_CHECK_OP(ctxt, op, err) \
500 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
502 CERROR("lop_" #op ": dev %d no operation\n", \
503 ctxt->loc_obd->obd_minor); \
508 static inline int class_devno_max(void)
510 return MAX_OBD_DEVICES;
513 static inline int obd_get_info(const struct lu_env *env,
514 struct obd_export *exp, __u32 keylen,
515 void *key, __u32 *vallen, void *val,
516 struct lov_stripe_md *lsm)
521 EXP_CHECK_DT_OP(exp, get_info);
522 EXP_COUNTER_INCREMENT(exp, get_info);
524 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val,
529 static inline int obd_set_info_async(const struct lu_env *env,
530 struct obd_export *exp, obd_count keylen,
531 void *key, obd_count vallen, void *val,
532 struct ptlrpc_request_set *set)
537 EXP_CHECK_DT_OP(exp, set_info_async);
538 EXP_COUNTER_INCREMENT(exp, set_info_async);
540 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
546 * obd-lu integration.
548 * Functionality is being moved into new lu_device-based layering, but some
549 * pieces of configuration process are still based on obd devices.
551 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
552 * subsume ->o_setup() methods of obd devices they replace. The same for
553 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
554 * result, obd_setup() and obd_process_config() branch and call one XOR
557 * Yet neither lu_device_type_operations::ldto_device_fini() nor
558 * lu_device_type_operations::ldto_device_free() fully implement the
559 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
560 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
563 #define DECLARE_LU_VARS(ldt, d) \
564 struct lu_device_type *ldt; \
567 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
570 DECLARE_LU_VARS(ldt, d);
573 ldt = obd->obd_type->typ_lu;
575 struct lu_context session_ctx;
577 lu_context_init(&session_ctx, LCT_SESSION);
578 session_ctx.lc_thread = NULL;
579 lu_context_enter(&session_ctx);
581 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
583 env.le_ses = &session_ctx;
584 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
593 lu_context_exit(&session_ctx);
594 lu_context_fini(&session_ctx);
597 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
598 OBD_COUNTER_INCREMENT(obd, setup);
599 rc = OBP(obd, setup)(obd, cfg);
604 static inline int obd_precleanup(struct obd_device *obd,
605 enum obd_cleanup_stage cleanup_stage)
608 DECLARE_LU_VARS(ldt, d);
612 ldt = obd->obd_type->typ_lu;
614 if (ldt != NULL && d != NULL) {
615 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
618 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
620 ldt->ldt_ops->ldto_device_fini(&env, d);
625 OBD_CHECK_DT_OP(obd, precleanup, 0);
626 OBD_COUNTER_INCREMENT(obd, precleanup);
628 rc = OBP(obd, precleanup)(obd, cleanup_stage);
632 static inline int obd_cleanup(struct obd_device *obd)
635 DECLARE_LU_VARS(ldt, d);
640 ldt = obd->obd_type->typ_lu;
642 if (ldt != NULL && d != NULL) {
645 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
647 ldt->ldt_ops->ldto_device_free(&env, d);
649 obd->obd_lu_dev = NULL;
652 OBD_CHECK_DT_OP(obd, cleanup, 0);
653 OBD_COUNTER_INCREMENT(obd, cleanup);
655 rc = OBP(obd, cleanup)(obd);
659 static inline void obd_cleanup_client_import(struct obd_device *obd)
663 /* If we set up but never connected, the
664 client import will not have been cleaned. */
665 down_write(&obd->u.cli.cl_sem);
666 if (obd->u.cli.cl_import) {
667 struct obd_import *imp;
668 imp = obd->u.cli.cl_import;
669 CDEBUG(D_CONFIG, "%s: client import never connected\n",
671 ptlrpc_invalidate_import(imp);
672 if (imp->imp_rq_pool) {
673 ptlrpc_free_rq_pool(imp->imp_rq_pool);
674 imp->imp_rq_pool = NULL;
676 client_destroy_import(imp);
677 obd->u.cli.cl_import = NULL;
679 up_write(&obd->u.cli.cl_sem);
685 obd_process_config(struct obd_device *obd, int datalen, void *data)
688 DECLARE_LU_VARS(ldt, d);
693 obd->obd_process_conf = 1;
694 ldt = obd->obd_type->typ_lu;
696 if (ldt != NULL && d != NULL) {
699 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
701 rc = d->ld_ops->ldo_process_config(&env, d, data);
705 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
706 rc = OBP(obd, process_config)(obd, datalen, data);
708 OBD_COUNTER_INCREMENT(obd, process_config);
709 obd->obd_process_conf = 0;
714 /* Pack an in-memory MD struct for storage on disk.
715 * Returns +ve size of packed MD (0 for free), or -ve error.
717 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
718 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
719 * If @*disk_tgt == NULL, it will be allocated
721 static inline int obd_packmd(struct obd_export *exp,
722 struct lov_mds_md **disk_tgt,
723 struct lov_stripe_md *mem_src)
728 EXP_CHECK_DT_OP(exp, packmd);
729 EXP_COUNTER_INCREMENT(exp, packmd);
731 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
735 static inline int obd_size_diskmd(struct obd_export *exp,
736 struct lov_stripe_md *mem_src)
738 return obd_packmd(exp, NULL, mem_src);
741 /* helper functions */
742 static inline int obd_alloc_diskmd(struct obd_export *exp,
743 struct lov_mds_md **disk_tgt)
746 LASSERT(*disk_tgt == NULL);
747 return obd_packmd(exp, disk_tgt, NULL);
750 static inline int obd_free_diskmd(struct obd_export *exp,
751 struct lov_mds_md **disk_tgt)
755 return obd_packmd(exp, disk_tgt, NULL);
758 /* Unpack an MD struct from disk to in-memory format.
759 * Returns +ve size of unpacked MD (0 for free), or -ve error.
761 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
762 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
763 * If @*mem_tgt == NULL, it will be allocated
765 static inline int obd_unpackmd(struct obd_export *exp,
766 struct lov_stripe_md **mem_tgt,
767 struct lov_mds_md *disk_src,
773 EXP_CHECK_DT_OP(exp, unpackmd);
774 EXP_COUNTER_INCREMENT(exp, unpackmd);
776 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
780 /* helper functions */
781 static inline int obd_alloc_memmd(struct obd_export *exp,
782 struct lov_stripe_md **mem_tgt)
785 LASSERT(*mem_tgt == NULL);
786 return obd_unpackmd(exp, mem_tgt, NULL, 0);
789 static inline int obd_free_memmd(struct obd_export *exp,
790 struct lov_stripe_md **mem_tgt)
796 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
801 static inline int obd_precreate(struct obd_export *exp)
806 EXP_CHECK_DT_OP(exp, precreate);
807 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
809 rc = OBP(exp->exp_obd, precreate)(exp);
813 static inline int obd_create_async(struct obd_export *exp,
814 struct obd_info *oinfo,
815 struct lov_stripe_md **ea,
816 struct obd_trans_info *oti)
821 EXP_CHECK_DT_OP(exp, create_async);
822 EXP_COUNTER_INCREMENT(exp, create_async);
824 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
828 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
829 struct obdo *obdo, struct lov_stripe_md **ea,
830 struct obd_trans_info *oti)
835 EXP_CHECK_DT_OP(exp, create);
836 EXP_COUNTER_INCREMENT(exp, create);
838 rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti);
842 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
843 struct obdo *obdo, struct lov_stripe_md *ea,
844 struct obd_trans_info *oti,
845 struct obd_export *md_exp, void *capa)
850 EXP_CHECK_DT_OP(exp, destroy);
851 EXP_COUNTER_INCREMENT(exp, destroy);
853 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp, capa);
857 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
858 struct obd_info *oinfo)
863 EXP_CHECK_DT_OP(exp, getattr);
864 EXP_COUNTER_INCREMENT(exp, getattr);
866 rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo);
870 static inline int obd_getattr_async(struct obd_export *exp,
871 struct obd_info *oinfo,
872 struct ptlrpc_request_set *set)
877 EXP_CHECK_DT_OP(exp, getattr_async);
878 EXP_COUNTER_INCREMENT(exp, getattr_async);
880 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
884 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
885 struct obd_info *oinfo,
886 struct obd_trans_info *oti)
891 EXP_CHECK_DT_OP(exp, setattr);
892 EXP_COUNTER_INCREMENT(exp, setattr);
894 rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
898 /* This performs all the requests set init/wait/destroy actions. */
899 static inline int obd_setattr_rqset(struct obd_export *exp,
900 struct obd_info *oinfo,
901 struct obd_trans_info *oti)
903 struct ptlrpc_request_set *set = NULL;
907 EXP_CHECK_DT_OP(exp, setattr_async);
908 EXP_COUNTER_INCREMENT(exp, setattr_async);
910 set = ptlrpc_prep_set();
914 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
916 rc = ptlrpc_set_wait(set);
917 ptlrpc_set_destroy(set);
921 /* This adds all the requests into @set if @set != NULL, otherwise
922 all requests are sent asynchronously without waiting for response. */
923 static inline int obd_setattr_async(struct obd_export *exp,
924 struct obd_info *oinfo,
925 struct obd_trans_info *oti,
926 struct ptlrpc_request_set *set)
931 EXP_CHECK_DT_OP(exp, setattr_async);
932 EXP_COUNTER_INCREMENT(exp, setattr_async);
934 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
938 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
941 struct obd_device *obd = imp->imp_obd;
945 OBD_CHECK_DEV_ACTIVE(obd);
946 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
947 OBD_COUNTER_INCREMENT(obd, add_conn);
949 rc = OBP(obd, add_conn)(imp, uuid, priority);
953 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
955 struct obd_device *obd = imp->imp_obd;
959 OBD_CHECK_DEV_ACTIVE(obd);
960 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
961 OBD_COUNTER_INCREMENT(obd, del_conn);
963 rc = OBP(obd, del_conn)(imp, uuid);
967 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
969 struct obd_uuid *uuid;
972 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
973 EXP_COUNTER_INCREMENT(exp, get_uuid);
975 uuid = OBP(exp->exp_obd, get_uuid)(exp);
979 /** Create a new /a exp on device /a obd for the uuid /a cluuid
980 * @param exp New export handle
981 * @param d Connect data, supported flags are set, flags also understood
982 * by obd are returned.
984 static inline int obd_connect(const struct lu_env *env,
985 struct obd_export **exp,struct obd_device *obd,
986 struct obd_uuid *cluuid,
987 struct obd_connect_data *data,
991 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
995 OBD_CHECK_DEV_ACTIVE(obd);
996 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
997 OBD_COUNTER_INCREMENT(obd, connect);
999 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
1000 /* check that only subset is granted */
1001 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
1002 data->ocd_connect_flags));
1006 static inline int obd_reconnect(const struct lu_env *env,
1007 struct obd_export *exp,
1008 struct obd_device *obd,
1009 struct obd_uuid *cluuid,
1010 struct obd_connect_data *d,
1014 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
1019 OBD_CHECK_DEV_ACTIVE(obd);
1020 OBD_CHECK_DT_OP(obd, reconnect, 0);
1021 OBD_COUNTER_INCREMENT(obd, reconnect);
1023 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
1024 /* check that only subset is granted */
1025 LASSERT(ergo(d != NULL,
1026 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
1030 static inline int obd_disconnect(struct obd_export *exp)
1035 EXP_CHECK_DT_OP(exp, disconnect);
1036 EXP_COUNTER_INCREMENT(exp, disconnect);
1038 rc = OBP(exp->exp_obd, disconnect)(exp);
1042 static inline int obd_fid_init(struct obd_export *exp)
1047 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
1048 EXP_COUNTER_INCREMENT(exp, fid_init);
1050 rc = OBP(exp->exp_obd, fid_init)(exp);
1054 static inline int obd_fid_fini(struct obd_export *exp)
1059 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
1060 EXP_COUNTER_INCREMENT(exp, fid_fini);
1062 rc = OBP(exp->exp_obd, fid_fini)(exp);
1066 static inline int obd_fid_alloc(struct obd_export *exp,
1068 struct md_op_data *op_data)
1073 EXP_CHECK_DT_OP(exp, fid_alloc);
1074 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1076 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1080 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
1085 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1086 EXP_COUNTER_INCREMENT(exp, ping);
1088 rc = OBP(exp->exp_obd, ping)(env, exp);
1092 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1097 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1098 OBD_COUNTER_INCREMENT(obd, pool_new);
1100 rc = OBP(obd, pool_new)(obd, poolname);
1104 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1109 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1110 OBD_COUNTER_INCREMENT(obd, pool_del);
1112 rc = OBP(obd, pool_del)(obd, poolname);
1116 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1121 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1122 OBD_COUNTER_INCREMENT(obd, pool_add);
1124 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1128 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1133 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1134 OBD_COUNTER_INCREMENT(obd, pool_rem);
1136 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1140 static inline void obd_getref(struct obd_device *obd)
1143 if (OBT(obd) && OBP(obd, getref)) {
1144 OBD_COUNTER_INCREMENT(obd, getref);
1145 OBP(obd, getref)(obd);
1150 static inline void obd_putref(struct obd_device *obd)
1153 if (OBT(obd) && OBP(obd, putref)) {
1154 OBD_COUNTER_INCREMENT(obd, putref);
1155 OBP(obd, putref)(obd);
1160 static inline int obd_init_export(struct obd_export *exp)
1165 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1166 OBP((exp)->exp_obd, init_export))
1167 rc = OBP(exp->exp_obd, init_export)(exp);
1171 static inline int obd_destroy_export(struct obd_export *exp)
1174 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1175 OBP((exp)->exp_obd, destroy_export))
1176 OBP(exp->exp_obd, destroy_export)(exp);
1180 static inline int obd_extent_calc(struct obd_export *exp,
1181 struct lov_stripe_md *md,
1182 int cmd, obd_off *offset)
1186 EXP_CHECK_DT_OP(exp, extent_calc);
1187 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1191 static inline struct dentry *
1192 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1194 LASSERT(exp->exp_obd);
1196 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1201 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1203 LASSERT(exp->exp_obd);
1204 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1206 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1207 dentry, exp->exp_obd);
1212 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1213 * If the cache is older than @max_age we will get a new value from the
1214 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1215 static inline int obd_statfs_async(struct obd_export *exp,
1216 struct obd_info *oinfo,
1218 struct ptlrpc_request_set *rqset)
1221 struct obd_device *obd;
1224 if (exp == NULL || exp->exp_obd == NULL)
1228 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1229 OBD_COUNTER_INCREMENT(obd, statfs);
1231 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1232 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1233 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1234 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1236 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1237 " objects "LPU64"/"LPU64"\n",
1238 obd->obd_name, &obd->obd_osfs,
1239 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1240 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1241 spin_lock(&obd->obd_osfs_lock);
1242 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1243 spin_unlock(&obd->obd_osfs_lock);
1244 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1245 if (oinfo->oi_cb_up)
1246 oinfo->oi_cb_up(oinfo, 0);
1251 static inline int obd_statfs_rqset(struct obd_export *exp,
1252 struct obd_statfs *osfs, __u64 max_age,
1255 struct ptlrpc_request_set *set = NULL;
1256 struct obd_info oinfo = { { { 0 } } };
1260 set = ptlrpc_prep_set();
1264 oinfo.oi_osfs = osfs;
1265 oinfo.oi_flags = flags;
1266 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1268 rc = ptlrpc_set_wait(set);
1269 ptlrpc_set_destroy(set);
1273 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1274 * If the cache is older than @max_age we will get a new value from the
1275 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1276 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1277 struct obd_statfs *osfs, __u64 max_age,
1281 struct obd_device *obd = exp->exp_obd;
1287 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1288 OBD_COUNTER_INCREMENT(obd, statfs);
1290 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1291 obd->obd_osfs_age, max_age);
1292 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1293 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1295 spin_lock(&obd->obd_osfs_lock);
1296 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1297 obd->obd_osfs_age = cfs_time_current_64();
1298 spin_unlock(&obd->obd_osfs_lock);
1301 CDEBUG(D_SUPER, "%s: use %p cache blocks "LPU64"/"LPU64
1302 " objects "LPU64"/"LPU64"\n",
1303 obd->obd_name, &obd->obd_osfs,
1304 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1305 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1306 spin_lock(&obd->obd_osfs_lock);
1307 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1308 spin_unlock(&obd->obd_osfs_lock);
1313 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
1314 obd_size start, obd_size end)
1316 struct ptlrpc_request_set *set = NULL;
1320 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1321 EXP_COUNTER_INCREMENT(exp, sync);
1323 set = ptlrpc_prep_set();
1327 rc = OBP(exp->exp_obd, sync)(NULL, exp, oinfo, start, end, set);
1329 rc = ptlrpc_set_wait(set);
1330 ptlrpc_set_destroy(set);
1334 static inline int obd_sync(const struct lu_env *env, struct obd_export *exp,
1335 struct obd_info *oinfo, obd_size start, obd_size end,
1336 struct ptlrpc_request_set *set)
1341 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1342 EXP_COUNTER_INCREMENT(exp, sync);
1344 rc = OBP(exp->exp_obd, sync)(env, exp, oinfo, start, end, set);
1348 static inline int obd_punch_rqset(struct obd_export *exp,
1349 struct obd_info *oinfo,
1350 struct obd_trans_info *oti)
1352 struct ptlrpc_request_set *set = NULL;
1356 EXP_CHECK_DT_OP(exp, punch);
1357 EXP_COUNTER_INCREMENT(exp, punch);
1359 set = ptlrpc_prep_set();
1363 rc = OBP(exp->exp_obd, punch)(NULL, exp, oinfo, oti, set);
1365 rc = ptlrpc_set_wait(set);
1366 ptlrpc_set_destroy(set);
1370 static inline int obd_punch(const struct lu_env *env, struct obd_export *exp,
1371 struct obd_info *oinfo, struct obd_trans_info *oti,
1372 struct ptlrpc_request_set *rqset)
1377 EXP_CHECK_DT_OP(exp, punch);
1378 EXP_COUNTER_INCREMENT(exp, punch);
1380 rc = OBP(exp->exp_obd, punch)(env, exp, oinfo, oti, rqset);
1384 static inline int obd_brw(int cmd, struct obd_export *exp,
1385 struct obd_info *oinfo, obd_count oa_bufs,
1386 struct brw_page *pg, struct obd_trans_info *oti)
1391 EXP_CHECK_DT_OP(exp, brw);
1392 EXP_COUNTER_INCREMENT(exp, brw);
1394 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1395 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1396 "or OBD_BRW_CHECK\n");
1400 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1404 static inline int obd_preprw(const struct lu_env *env, int cmd,
1405 struct obd_export *exp, struct obdo *oa,
1406 int objcount, struct obd_ioobj *obj,
1407 struct niobuf_remote *remote, int *pages,
1408 struct niobuf_local *local,
1409 struct obd_trans_info *oti,
1410 struct lustre_capa *capa)
1415 EXP_CHECK_DT_OP(exp, preprw);
1416 EXP_COUNTER_INCREMENT(exp, preprw);
1418 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1419 pages, local, oti, capa);
1423 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1424 struct obd_export *exp, struct obdo *oa,
1425 int objcount, struct obd_ioobj *obj,
1426 struct niobuf_remote *rnb, int pages,
1427 struct niobuf_local *local,
1428 struct obd_trans_info *oti, int rc)
1432 EXP_CHECK_DT_OP(exp, commitrw);
1433 EXP_COUNTER_INCREMENT(exp, commitrw);
1435 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1436 rnb, pages, local, oti, rc);
1440 static inline int obd_merge_lvb(struct obd_export *exp,
1441 struct lov_stripe_md *lsm,
1442 struct ost_lvb *lvb, int kms_only)
1447 EXP_CHECK_DT_OP(exp, merge_lvb);
1448 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1450 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1454 static inline int obd_adjust_kms(struct obd_export *exp,
1455 struct lov_stripe_md *lsm, obd_off size,
1461 EXP_CHECK_DT_OP(exp, adjust_kms);
1462 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1464 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1468 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1469 int len, void *karg, void *uarg)
1474 EXP_CHECK_DT_OP(exp, iocontrol);
1475 EXP_COUNTER_INCREMENT(exp, iocontrol);
1477 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1481 static inline int obd_enqueue_rqset(struct obd_export *exp,
1482 struct obd_info *oinfo,
1483 struct ldlm_enqueue_info *einfo)
1485 struct ptlrpc_request_set *set = NULL;
1489 EXP_CHECK_DT_OP(exp, enqueue);
1490 EXP_COUNTER_INCREMENT(exp, enqueue);
1492 set = ptlrpc_prep_set();
1496 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1498 rc = ptlrpc_set_wait(set);
1499 ptlrpc_set_destroy(set);
1503 static inline int obd_enqueue(struct obd_export *exp,
1504 struct obd_info *oinfo,
1505 struct ldlm_enqueue_info *einfo,
1506 struct ptlrpc_request_set *set)
1511 EXP_CHECK_DT_OP(exp, enqueue);
1512 EXP_COUNTER_INCREMENT(exp, enqueue);
1514 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1518 static inline int obd_change_cbdata(struct obd_export *exp,
1519 struct lov_stripe_md *lsm,
1520 ldlm_iterator_t it, void *data)
1525 EXP_CHECK_DT_OP(exp, change_cbdata);
1526 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1528 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1532 static inline int obd_find_cbdata(struct obd_export *exp,
1533 struct lov_stripe_md *lsm,
1534 ldlm_iterator_t it, void *data)
1539 EXP_CHECK_DT_OP(exp, find_cbdata);
1540 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1542 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1546 static inline int obd_cancel(struct obd_export *exp,
1547 struct lov_stripe_md *ea, __u32 mode,
1548 struct lustre_handle *lockh)
1553 EXP_CHECK_DT_OP(exp, cancel);
1554 EXP_COUNTER_INCREMENT(exp, cancel);
1556 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1560 static inline int obd_cancel_unused(struct obd_export *exp,
1561 struct lov_stripe_md *ea,
1562 ldlm_cancel_flags_t flags,
1568 EXP_CHECK_DT_OP(exp, cancel_unused);
1569 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1571 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1575 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1576 struct obd_capa *oc, struct obd_client_handle *handle,
1582 EXP_CHECK_DT_OP(exp, pin);
1583 EXP_COUNTER_INCREMENT(exp, pin);
1585 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1589 static inline int obd_unpin(struct obd_export *exp,
1590 struct obd_client_handle *handle, int flag)
1595 EXP_CHECK_DT_OP(exp, unpin);
1596 EXP_COUNTER_INCREMENT(exp, unpin);
1598 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1603 static inline void obd_import_event(struct obd_device *obd,
1604 struct obd_import *imp,
1605 enum obd_import_event event)
1609 CERROR("NULL device\n");
1613 if (obd->obd_set_up && OBP(obd, import_event)) {
1614 OBD_COUNTER_INCREMENT(obd, import_event);
1615 OBP(obd, import_event)(obd, imp, event);
1620 static inline int obd_llog_connect(struct obd_export *exp,
1621 struct llogd_conn_body *body)
1626 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1627 EXP_COUNTER_INCREMENT(exp, llog_connect);
1629 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1634 static inline int obd_notify(struct obd_device *obd,
1635 struct obd_device *watched,
1636 enum obd_notify_event ev,
1643 /* the check for async_recov is a complete hack - I'm hereby
1644 overloading the meaning to also mean "this was called from
1645 mds_postsetup". I know that my mds is able to handle notifies
1646 by this point, and it needs to get them to execute mds_postrecov. */
1647 if (!obd->obd_set_up && !obd->obd_async_recov) {
1648 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1652 if (!OBP(obd, notify)) {
1653 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1657 OBD_COUNTER_INCREMENT(obd, notify);
1658 rc = OBP(obd, notify)(obd, watched, ev, data);
1662 static inline int obd_notify_observer(struct obd_device *observer,
1663 struct obd_device *observed,
1664 enum obd_notify_event ev,
1670 struct obd_notify_upcall *onu;
1672 if (observer->obd_observer)
1673 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1677 * Also, call non-obd listener, if any
1679 onu = &observer->obd_upcall;
1680 if (onu->onu_upcall != NULL)
1681 rc2 = onu->onu_upcall(observer, observed, ev,
1682 onu->onu_owner, NULL);
1686 return rc1 ? rc1 : rc2;
1689 static inline int obd_quotacheck(struct obd_export *exp,
1690 struct obd_quotactl *oqctl)
1695 EXP_CHECK_DT_OP(exp, quotacheck);
1696 EXP_COUNTER_INCREMENT(exp, quotacheck);
1698 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1702 static inline int obd_quotactl(struct obd_export *exp,
1703 struct obd_quotactl *oqctl)
1708 EXP_CHECK_DT_OP(exp, quotactl);
1709 EXP_COUNTER_INCREMENT(exp, quotactl);
1711 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1715 static inline int obd_health_check(const struct lu_env *env,
1716 struct obd_device *obd)
1718 /* returns: 0 on healthy
1719 * >0 on unhealthy + reason code/flag
1720 * however the only suppored reason == 1 right now
1721 * We'll need to define some better reasons
1722 * or flags in the future.
1728 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1729 if (obd == NULL || !OBT(obd)) {
1730 CERROR("cleaned up obd\n");
1731 RETURN(-EOPNOTSUPP);
1733 if (!obd->obd_set_up || obd->obd_stopping)
1735 if (!OBP(obd, health_check))
1738 rc = OBP(obd, health_check)(env, obd);
1742 static inline int obd_register_observer(struct obd_device *obd,
1743 struct obd_device *observer)
1747 down_write(&obd->obd_observer_link_sem);
1748 if (obd->obd_observer && observer) {
1749 up_write(&obd->obd_observer_link_sem);
1752 obd->obd_observer = observer;
1753 up_write(&obd->obd_observer_link_sem);
1757 static inline int obd_pin_observer(struct obd_device *obd,
1758 struct obd_device **observer)
1761 down_read(&obd->obd_observer_link_sem);
1762 if (!obd->obd_observer) {
1764 up_read(&obd->obd_observer_link_sem);
1767 *observer = obd->obd_observer;
1771 static inline int obd_unpin_observer(struct obd_device *obd)
1774 up_read(&obd->obd_observer_link_sem);
1779 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1780 obd_page_removal_cb_t cb,
1781 obd_pin_extent_cb pin_cb)
1786 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1787 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1789 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1793 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1794 obd_page_removal_cb_t cb)
1799 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1800 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1802 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1806 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1807 obd_lock_cancel_cb cb)
1812 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1813 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1815 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1819 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1820 obd_lock_cancel_cb cb)
1825 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1826 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1828 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1833 /* metadata helpers */
1834 static inline int md_getstatus(struct obd_export *exp,
1835 struct lu_fid *fid, struct obd_capa **pc)
1840 EXP_CHECK_MD_OP(exp, getstatus);
1841 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1842 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1846 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1847 struct ptlrpc_request **request)
1851 EXP_CHECK_MD_OP(exp, getattr);
1852 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1853 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1857 static inline int md_change_cbdata(struct obd_export *exp,
1858 const struct lu_fid *fid,
1859 ldlm_iterator_t it, void *data)
1863 EXP_CHECK_MD_OP(exp, change_cbdata);
1864 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1865 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1869 static inline int md_find_cbdata(struct obd_export *exp,
1870 const struct lu_fid *fid,
1871 ldlm_iterator_t it, void *data)
1875 EXP_CHECK_MD_OP(exp, find_cbdata);
1876 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1877 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1881 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1882 struct md_open_data *mod,
1883 struct ptlrpc_request **request)
1887 EXP_CHECK_MD_OP(exp, close);
1888 EXP_MD_COUNTER_INCREMENT(exp, close);
1889 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1893 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1894 const void *data, int datalen, int mode, __u32 uid,
1895 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1896 struct ptlrpc_request **request)
1900 EXP_CHECK_MD_OP(exp, create);
1901 EXP_MD_COUNTER_INCREMENT(exp, create);
1902 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1903 uid, gid, cap_effective, rdev, request);
1907 static inline int md_done_writing(struct obd_export *exp,
1908 struct md_op_data *op_data,
1909 struct md_open_data *mod)
1913 EXP_CHECK_MD_OP(exp, done_writing);
1914 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1915 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1919 static inline int md_enqueue(struct obd_export *exp,
1920 struct ldlm_enqueue_info *einfo,
1921 struct lookup_intent *it,
1922 struct md_op_data *op_data,
1923 struct lustre_handle *lockh,
1924 void *lmm, int lmmsize,
1925 struct ptlrpc_request **req,
1926 int extra_lock_flags)
1930 EXP_CHECK_MD_OP(exp, enqueue);
1931 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1932 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1933 lmm, lmmsize, req, extra_lock_flags);
1937 static inline int md_getattr_name(struct obd_export *exp,
1938 struct md_op_data *op_data,
1939 struct ptlrpc_request **request)
1943 EXP_CHECK_MD_OP(exp, getattr_name);
1944 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1945 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1949 static inline int md_intent_lock(struct obd_export *exp,
1950 struct md_op_data *op_data, void *lmm,
1951 int lmmsize, struct lookup_intent *it,
1952 int lookup_flags, struct ptlrpc_request **reqp,
1953 ldlm_blocking_callback cb_blocking,
1954 __u64 extra_lock_flags)
1958 EXP_CHECK_MD_OP(exp, intent_lock);
1959 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1960 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1961 it, lookup_flags, reqp, cb_blocking,
1966 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1967 struct ptlrpc_request **request)
1971 EXP_CHECK_MD_OP(exp, link);
1972 EXP_MD_COUNTER_INCREMENT(exp, link);
1973 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1977 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1978 const char *old, int oldlen, const char *new,
1979 int newlen, struct ptlrpc_request **request)
1983 EXP_CHECK_MD_OP(exp, rename);
1984 EXP_MD_COUNTER_INCREMENT(exp, rename);
1985 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1990 static inline int md_is_subdir(struct obd_export *exp,
1991 const struct lu_fid *pfid,
1992 const struct lu_fid *cfid,
1993 struct ptlrpc_request **request)
1997 EXP_CHECK_MD_OP(exp, is_subdir);
1998 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1999 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
2003 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
2004 void *ea, int ealen, void *ea2, int ea2len,
2005 struct ptlrpc_request **request,
2006 struct md_open_data **mod)
2010 EXP_CHECK_MD_OP(exp, setattr);
2011 EXP_MD_COUNTER_INCREMENT(exp, setattr);
2012 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
2013 ea2, ea2len, request, mod);
2017 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
2018 struct obd_capa *oc, struct ptlrpc_request **request)
2022 EXP_CHECK_MD_OP(exp, sync);
2023 EXP_MD_COUNTER_INCREMENT(exp, sync);
2024 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
2028 static inline int md_readpage(struct obd_export *exp, struct md_op_data *opdata,
2029 struct page **pages,
2030 struct ptlrpc_request **request)
2034 EXP_CHECK_MD_OP(exp, readpage);
2035 EXP_MD_COUNTER_INCREMENT(exp, readpage);
2036 rc = MDP(exp->exp_obd, readpage)(exp, opdata, pages, request);
2040 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
2041 struct ptlrpc_request **request)
2045 EXP_CHECK_MD_OP(exp, unlink);
2046 EXP_MD_COUNTER_INCREMENT(exp, unlink);
2047 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
2051 static inline int md_get_lustre_md(struct obd_export *exp,
2052 struct ptlrpc_request *req,
2053 struct obd_export *dt_exp,
2054 struct obd_export *md_exp,
2055 struct lustre_md *md)
2058 EXP_CHECK_MD_OP(exp, get_lustre_md);
2059 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
2060 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
2063 static inline int md_free_lustre_md(struct obd_export *exp,
2064 struct lustre_md *md)
2067 EXP_CHECK_MD_OP(exp, free_lustre_md);
2068 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2069 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2072 static inline int md_setxattr(struct obd_export *exp,
2073 const struct lu_fid *fid, struct obd_capa *oc,
2074 obd_valid valid, const char *name,
2075 const char *input, int input_size,
2076 int output_size, int flags, __u32 suppgid,
2077 struct ptlrpc_request **request)
2080 EXP_CHECK_MD_OP(exp, setxattr);
2081 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2082 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2083 input_size, output_size, flags,
2087 static inline int md_getxattr(struct obd_export *exp,
2088 const struct lu_fid *fid, struct obd_capa *oc,
2089 obd_valid valid, const char *name,
2090 const char *input, int input_size,
2091 int output_size, int flags,
2092 struct ptlrpc_request **request)
2095 EXP_CHECK_MD_OP(exp, getxattr);
2096 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2097 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2098 input_size, output_size, flags,
2102 static inline int md_set_open_replay_data(struct obd_export *exp,
2103 struct obd_client_handle *och,
2104 struct ptlrpc_request *open_req)
2107 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2108 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2109 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2112 static inline int md_clear_open_replay_data(struct obd_export *exp,
2113 struct obd_client_handle *och)
2116 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2117 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2118 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2121 static inline int md_set_lock_data(struct obd_export *exp,
2122 __u64 *lockh, void *data, __u64 *bits)
2125 EXP_CHECK_MD_OP(exp, set_lock_data);
2126 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2127 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2130 static inline int md_cancel_unused(struct obd_export *exp,
2131 const struct lu_fid *fid,
2132 ldlm_policy_data_t *policy,
2134 ldlm_cancel_flags_t flags,
2140 EXP_CHECK_MD_OP(exp, cancel_unused);
2141 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2143 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2148 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
2149 const struct lu_fid *fid,
2151 ldlm_policy_data_t *policy,
2153 struct lustre_handle *lockh)
2156 EXP_CHECK_MD_OP(exp, lock_match);
2157 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2158 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2159 policy, mode, lockh));
2162 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2163 int def_asize, int cookiesize)
2166 EXP_CHECK_MD_OP(exp, init_ea_size);
2167 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2168 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2172 static inline int md_get_remote_perm(struct obd_export *exp,
2173 const struct lu_fid *fid,
2174 struct obd_capa *oc, __u32 suppgid,
2175 struct ptlrpc_request **request)
2178 EXP_CHECK_MD_OP(exp, get_remote_perm);
2179 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2180 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2184 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2189 EXP_CHECK_MD_OP(exp, renew_capa);
2190 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2191 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2195 static inline int md_unpack_capa(struct obd_export *exp,
2196 struct ptlrpc_request *req,
2197 const struct req_msg_field *field,
2198 struct obd_capa **oc)
2202 EXP_CHECK_MD_OP(exp, unpack_capa);
2203 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2204 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2208 static inline int md_intent_getattr_async(struct obd_export *exp,
2209 struct md_enqueue_info *minfo,
2210 struct ldlm_enqueue_info *einfo)
2214 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2215 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2216 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2220 static inline int md_revalidate_lock(struct obd_export *exp,
2221 struct lookup_intent *it,
2222 struct lu_fid *fid, __u64 *bits)
2226 EXP_CHECK_MD_OP(exp, revalidate_lock);
2227 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2228 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
2233 /* OBD Metadata Support */
2235 extern int obd_init_caches(void);
2236 extern void obd_cleanup_caches(void);
2238 /* support routines */
2239 extern cfs_mem_cache_t *obdo_cachep;
2241 #define OBDO_ALLOC(ptr) \
2243 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, CFS_ALLOC_IO); \
2246 #define OBDO_FREE(ptr) \
2248 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2252 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2254 /* something here */
2257 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2259 /* something here */
2262 typedef int (*register_osp_cb)(void *data);
2264 struct osp_register_item {
2265 struct obd_export **ori_exp;
2266 register_osp_cb ori_cb_func;
2268 cfs_list_t ori_list;
2269 char ori_name[MTI_NAME_MAXLEN];
2272 /* I'm as embarrassed about this as you are.
2274 * <shaver> // XXX do not look into _superhack with remaining eye
2275 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2276 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2279 int server_name2fsname(char *svname, char *fsname, char **endptr);
2280 int lustre_register_osp_item(char *ospname, struct obd_export **exp,
2281 register_osp_cb cb_func, void *cb_data);
2282 void lustre_deregister_osp_item(struct obd_export **exp);
2283 int tgt_name2ospname(char *ost_name, char *osp_name);
2286 extern void obd_sysctl_init (void);
2287 extern void obd_sysctl_clean (void);
2290 typedef __u8 class_uuid_t[16];
2291 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2294 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2295 int class_add_uuid(const char *uuid, __u64 nid);
2296 int class_del_uuid (const char *uuid);
2297 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
2298 void class_init_uuidlist(void);
2299 void class_exit_uuidlist(void);
2302 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2303 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2306 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2308 #endif /* __LINUX_OBD_CLASS_H */