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_find_client_notype(struct obd_uuid *tgt_uuid,
90 struct obd_uuid *grp_uuid);
91 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
93 struct obd_device * class_num2obd(int num);
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);
106 int class_process_config(struct lustre_cfg *lcfg);
107 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
108 struct lustre_cfg *lcfg, void *data);
109 int class_attach(struct lustre_cfg *lcfg);
110 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
111 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
112 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
113 struct obd_device *class_incref(struct obd_device *obd,
114 const char *scope, const void *source);
115 void class_decref(struct obd_device *obd,
116 const char *scope, const void *source);
120 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
122 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
124 memset(lvars, 0, sizeof(*lvars));
128 #define CFG_F_START 0x01 /* Set when we start updating from a log */
129 #define CFG_F_MARKER 0x02 /* We are within a maker */
130 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
131 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
132 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
134 /* Passed as data param to class_config_parse_llog */
135 struct config_llog_instance {
137 struct super_block *cfg_sb;
138 struct obd_uuid cfg_uuid;
139 int cfg_last_idx; /* for partial llog processing */
142 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
143 struct config_llog_instance *cfg);
144 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
145 struct config_llog_instance *cfg);
147 /* list of active configuration logs */
148 struct config_llog_data {
150 struct ldlm_res_id cld_resid;
151 struct config_llog_instance cld_cfg;
152 struct list_head cld_list_chain;
153 atomic_t cld_refcount;
154 struct obd_export *cld_mgcexp;
155 unsigned int cld_stopping:1, /* we were told to stop watching */
156 cld_lostlock:1; /* lock not requeued */
159 struct lustre_profile {
160 struct list_head lp_list;
166 struct lustre_profile *class_get_profile(const char * prof);
167 void class_del_profile(const char *prof);
168 void class_del_profiles(void);
170 #define class_export_rpc_get(exp) \
172 atomic_inc(&(exp)->exp_rpc_count); \
173 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
174 (exp), atomic_read(&(exp)->exp_rpc_count)); \
175 class_export_get(exp); \
178 #define class_export_rpc_put(exp) \
180 atomic_dec(&(exp)->exp_rpc_count); \
181 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
182 (exp), atomic_read(&(exp)->exp_rpc_count)); \
183 class_export_put(exp); \
187 struct obd_export *class_export_get(struct obd_export *exp);
188 void class_export_put(struct obd_export *exp);
189 struct obd_export *class_new_export(struct obd_device *obddev,
190 struct obd_uuid *cluuid);
191 void class_unlink_export(struct obd_export *exp);
193 struct obd_import *class_import_get(struct obd_import *);
194 void class_import_put(struct obd_import *);
195 struct obd_import *class_new_import(struct obd_device *obd);
196 void class_destroy_import(struct obd_import *exp);
198 struct obd_type *class_search_type(const char *name);
199 struct obd_type *class_get_type(const char *name);
200 void class_put_type(struct obd_type *type);
201 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
202 struct obd_uuid *cluuid);
203 int class_disconnect(struct obd_export *exp);
204 void class_fail_export(struct obd_export *exp);
205 void class_disconnect_exports(struct obd_device *obddev);
206 int class_disconnect_stale_exports(struct obd_device *,
207 int (*test_export)(struct obd_export *));
208 int class_manual_cleanup(struct obd_device *obd);
210 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
211 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
212 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
213 unsigned int ia_valid);
214 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
215 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
216 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
219 #define OBT(dev) (dev)->obd_type
220 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
221 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
222 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
224 /* Ensure obd_setup: used for cleanup which must be called
225 while obd is stopping */
226 #define OBD_CHECK_DEV(obd) \
229 CERROR("NULL device\n"); \
234 /* ensure obd_setup and !obd_stopping */
235 #define OBD_CHECK_DEV_ACTIVE(obd) \
237 OBD_CHECK_DEV(obd); \
238 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
239 CERROR("Device %d not setup\n", \
247 #define OBD_COUNTER_OFFSET(op) \
248 ((offsetof(struct obd_ops, o_ ## op) - \
249 offsetof(struct obd_ops, o_iocontrol)) \
250 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
252 #define OBD_COUNTER_INCREMENT(obdx, op) \
253 if ((obdx)->obd_stats != NULL) { \
254 unsigned int coffset; \
255 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
256 OBD_COUNTER_OFFSET(op); \
257 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
258 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
261 #define EXP_COUNTER_INCREMENT(export, op) \
262 if ((export)->exp_obd->obd_stats != NULL) { \
263 unsigned int coffset; \
264 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
265 OBD_COUNTER_OFFSET(op); \
266 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
267 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
268 if ((export)->exp_nid_stats != NULL && \
269 (export)->exp_nid_stats->nid_stats != NULL) \
270 lprocfs_counter_incr( \
271 (export)->exp_nid_stats->nid_stats, coffset);\
274 #define MD_COUNTER_OFFSET(op) \
275 ((offsetof(struct md_ops, m_ ## op) - \
276 offsetof(struct md_ops, m_getstatus)) \
277 / sizeof(((struct md_ops *)(0))->m_getstatus))
279 #define MD_COUNTER_INCREMENT(obdx, op) \
280 if ((obd)->md_stats != NULL) { \
281 unsigned int coffset; \
282 coffset = (unsigned int)((obdx)->md_cntr_base) + \
283 MD_COUNTER_OFFSET(op); \
284 LASSERT(coffset < (obdx)->md_stats->ls_num); \
285 lprocfs_counter_incr((obdx)->md_stats, coffset); \
288 #define EXP_MD_COUNTER_INCREMENT(export, op) \
289 if ((export)->exp_obd->obd_stats != NULL) { \
290 unsigned int coffset; \
291 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
292 MD_COUNTER_OFFSET(op); \
293 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
294 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
295 if ((export)->exp_md_stats != NULL) \
296 lprocfs_counter_incr( \
297 (export)->exp_md_stats, coffset); \
301 #define OBD_COUNTER_OFFSET(op)
302 #define OBD_COUNTER_INCREMENT(obd, op)
303 #define EXP_COUNTER_INCREMENT(exp, op)
304 #define MD_COUNTER_INCREMENT(obd, op)
305 #define EXP_MD_COUNTER_INCREMENT(exp, op)
308 #define OBD_CHECK_MD_OP(obd, op, err) \
310 if (!OBT(obd) || !MDP((obd), op)) { \
312 CERROR("md_" #op ": dev %s/%d no operation\n", \
313 obd->obd_name, obd->obd_minor); \
318 #define EXP_CHECK_MD_OP(exp, op) \
320 if ((exp) == NULL) { \
321 CERROR("obd_" #op ": NULL export\n"); \
324 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
325 CERROR("obd_" #op ": cleaned up obd\n"); \
326 RETURN(-EOPNOTSUPP); \
328 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
329 CERROR("obd_" #op ": dev %s/%d no operation\n", \
330 (exp)->exp_obd->obd_name, \
331 (exp)->exp_obd->obd_minor); \
332 RETURN(-EOPNOTSUPP); \
337 #define OBD_CHECK_DT_OP(obd, op, err) \
339 if (!OBT(obd) || !OBP((obd), op)) { \
341 CERROR("obd_" #op ": dev %d no operation\n", \
347 #define EXP_CHECK_DT_OP(exp, op) \
349 if ((exp) == NULL) { \
350 CERROR("obd_" #op ": NULL export\n"); \
353 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
354 CERROR("obd_" #op ": cleaned up obd\n"); \
355 RETURN(-EOPNOTSUPP); \
357 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
358 CERROR("obd_" #op ": dev %d no operation\n", \
359 (exp)->exp_obd->obd_minor); \
360 RETURN(-EOPNOTSUPP); \
364 #define CTXT_CHECK_OP(ctxt, op, err) \
366 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
368 CERROR("lop_" #op ": dev %d no operation\n", \
369 ctxt->loc_obd->obd_minor); \
374 static inline int class_devno_max(void)
376 return MAX_OBD_DEVICES;
379 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
380 void *key, __u32 *vallen, void *val,
381 struct lov_stripe_md *lsm)
386 EXP_CHECK_DT_OP(exp, get_info);
387 EXP_COUNTER_INCREMENT(exp, get_info);
389 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
393 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
394 void *key, obd_count vallen, void *val,
395 struct ptlrpc_request_set *set)
400 EXP_CHECK_DT_OP(exp, set_info_async);
401 EXP_COUNTER_INCREMENT(exp, set_info_async);
403 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
409 * obd-lu integration.
411 * Functionality is being moved into new lu_device-based layering, but some
412 * pieces of configuration process are still based on obd devices.
414 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
415 * subsume ->o_setup() methods of obd devices they replace. The same for
416 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
417 * result, obd_setup() and obd_process_config() branch and call one XOR
420 * Yet neither lu_device_type_operations::ldto_device_fini() nor
421 * lu_device_type_operations::ldto_device_free() fully implement the
422 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
423 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
426 #define DECLARE_LU_VARS(ldt, d) \
427 struct lu_device_type *ldt; \
430 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
433 DECLARE_LU_VARS(ldt, d);
436 ldt = obd->obd_type->typ_lu;
440 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
442 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
452 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
453 OBD_COUNTER_INCREMENT(obd, setup);
454 rc = OBP(obd, setup)(obd, cfg);
459 static inline int obd_precleanup(struct obd_device *obd,
460 enum obd_cleanup_stage cleanup_stage)
463 DECLARE_LU_VARS(ldt, d);
467 ldt = obd->obd_type->typ_lu;
469 if (ldt != NULL && d != NULL) {
470 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
473 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
475 ldt->ldt_ops->ldto_device_fini(&env, d);
480 OBD_CHECK_DT_OP(obd, precleanup, 0);
481 OBD_COUNTER_INCREMENT(obd, precleanup);
483 rc = OBP(obd, precleanup)(obd, cleanup_stage);
487 static inline int obd_cleanup(struct obd_device *obd)
490 DECLARE_LU_VARS(ldt, d);
495 ldt = obd->obd_type->typ_lu;
497 if (ldt != NULL && d != NULL) {
500 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
502 ldt->ldt_ops->ldto_device_free(&env, d);
504 obd->obd_lu_dev = NULL;
507 OBD_CHECK_DT_OP(obd, cleanup, 0);
508 OBD_COUNTER_INCREMENT(obd, cleanup);
510 rc = OBP(obd, cleanup)(obd);
515 obd_process_config(struct obd_device *obd, int datalen, void *data)
518 DECLARE_LU_VARS(ldt, d);
523 ldt = obd->obd_type->typ_lu;
525 if (ldt != NULL && d != NULL) {
528 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
530 rc = d->ld_ops->ldo_process_config(&env, d, data);
534 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
535 rc = OBP(obd, process_config)(obd, datalen, data);
537 OBD_COUNTER_INCREMENT(obd, process_config);
542 /* Pack an in-memory MD struct for storage on disk.
543 * Returns +ve size of packed MD (0 for free), or -ve error.
545 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
546 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
547 * If @*disk_tgt == NULL, it will be allocated
549 static inline int obd_packmd(struct obd_export *exp,
550 struct lov_mds_md **disk_tgt,
551 struct lov_stripe_md *mem_src)
556 EXP_CHECK_DT_OP(exp, packmd);
557 EXP_COUNTER_INCREMENT(exp, packmd);
559 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
563 static inline int obd_size_diskmd(struct obd_export *exp,
564 struct lov_stripe_md *mem_src)
566 return obd_packmd(exp, NULL, mem_src);
569 /* helper functions */
570 static inline int obd_alloc_diskmd(struct obd_export *exp,
571 struct lov_mds_md **disk_tgt)
574 LASSERT(*disk_tgt == NULL);
575 return obd_packmd(exp, disk_tgt, NULL);
578 static inline int obd_free_diskmd(struct obd_export *exp,
579 struct lov_mds_md **disk_tgt)
583 return obd_packmd(exp, disk_tgt, NULL);
586 /* Unpack an MD struct from disk to in-memory format.
587 * Returns +ve size of unpacked MD (0 for free), or -ve error.
589 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
590 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
591 * If @*mem_tgt == NULL, it will be allocated
593 static inline int obd_unpackmd(struct obd_export *exp,
594 struct lov_stripe_md **mem_tgt,
595 struct lov_mds_md *disk_src,
601 EXP_CHECK_DT_OP(exp, unpackmd);
602 EXP_COUNTER_INCREMENT(exp, unpackmd);
604 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
608 /* helper functions */
609 static inline int obd_alloc_memmd(struct obd_export *exp,
610 struct lov_stripe_md **mem_tgt)
613 LASSERT(*mem_tgt == NULL);
614 return obd_unpackmd(exp, mem_tgt, NULL, 0);
617 static inline int obd_free_memmd(struct obd_export *exp,
618 struct lov_stripe_md **mem_tgt)
624 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
629 static inline int obd_checkmd(struct obd_export *exp,
630 struct obd_export *md_exp,
631 struct lov_stripe_md *mem_tgt)
636 EXP_CHECK_DT_OP(exp, checkmd);
637 EXP_COUNTER_INCREMENT(exp, checkmd);
639 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
643 static inline int obd_precreate(struct obd_export *exp)
648 EXP_CHECK_DT_OP(exp, precreate);
649 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
651 rc = OBP(exp->exp_obd, precreate)(exp);
655 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
656 struct lov_stripe_md **ea,
657 struct obd_trans_info *oti)
662 EXP_CHECK_DT_OP(exp, create);
663 EXP_COUNTER_INCREMENT(exp, create);
665 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
669 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
670 struct lov_stripe_md *ea,
671 struct obd_trans_info *oti,
672 struct obd_export *md_exp)
677 EXP_CHECK_DT_OP(exp, destroy);
678 EXP_COUNTER_INCREMENT(exp, destroy);
680 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
684 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
689 EXP_CHECK_DT_OP(exp, getattr);
690 EXP_COUNTER_INCREMENT(exp, getattr);
692 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
696 static inline int obd_getattr_async(struct obd_export *exp,
697 struct obd_info *oinfo,
698 struct ptlrpc_request_set *set)
703 EXP_CHECK_DT_OP(exp, getattr_async);
704 EXP_COUNTER_INCREMENT(exp, getattr_async);
706 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
710 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
711 struct obd_trans_info *oti)
716 EXP_CHECK_DT_OP(exp, setattr);
717 EXP_COUNTER_INCREMENT(exp, setattr);
719 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
723 /* This performs all the requests set init/wait/destroy actions. */
724 static inline int obd_setattr_rqset(struct obd_export *exp,
725 struct obd_info *oinfo,
726 struct obd_trans_info *oti)
728 struct ptlrpc_request_set *set = NULL;
732 EXP_CHECK_DT_OP(exp, setattr_async);
733 EXP_COUNTER_INCREMENT(exp, setattr_async);
735 set = ptlrpc_prep_set();
739 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
741 rc = ptlrpc_set_wait(set);
742 ptlrpc_set_destroy(set);
746 /* This adds all the requests into @set if @set != NULL, otherwise
747 all requests are sent asynchronously without waiting for response. */
748 static inline int obd_setattr_async(struct obd_export *exp,
749 struct obd_info *oinfo,
750 struct obd_trans_info *oti,
751 struct ptlrpc_request_set *set)
756 EXP_CHECK_DT_OP(exp, setattr_async);
757 EXP_COUNTER_INCREMENT(exp, setattr_async);
759 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
763 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
766 struct obd_device *obd = imp->imp_obd;
770 OBD_CHECK_DEV_ACTIVE(obd);
771 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
772 OBD_COUNTER_INCREMENT(obd, add_conn);
774 rc = OBP(obd, add_conn)(imp, uuid, priority);
778 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
780 struct obd_device *obd = imp->imp_obd;
784 OBD_CHECK_DEV_ACTIVE(obd);
785 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
786 OBD_COUNTER_INCREMENT(obd, del_conn);
788 rc = OBP(obd, del_conn)(imp, uuid);
792 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
794 struct obd_uuid *uuid;
797 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
798 EXP_COUNTER_INCREMENT(exp, get_uuid);
800 uuid = OBP(exp->exp_obd, get_uuid)(exp);
804 static inline int obd_connect(const struct lu_env *env,
805 struct lustre_handle *conn,struct obd_device *obd,
806 struct obd_uuid *cluuid,
807 struct obd_connect_data *d,
811 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
815 OBD_CHECK_DEV_ACTIVE(obd);
816 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
817 OBD_COUNTER_INCREMENT(obd, connect);
819 rc = OBP(obd, connect)(env, conn, obd, cluuid, d, localdata);
820 /* check that only subset is granted */
821 LASSERT(ergo(d != NULL,
822 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
826 static inline int obd_reconnect(const struct lu_env *env,
827 struct obd_export *exp,
828 struct obd_device *obd,
829 struct obd_uuid *cluuid,
830 struct obd_connect_data *d,
834 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
839 OBD_CHECK_DEV_ACTIVE(obd);
840 OBD_CHECK_DT_OP(obd, reconnect, 0);
841 OBD_COUNTER_INCREMENT(obd, reconnect);
843 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
844 /* check that only subset is granted */
845 LASSERT(ergo(d != NULL,
846 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
850 static inline int obd_disconnect(struct obd_export *exp)
855 EXP_CHECK_DT_OP(exp, disconnect);
856 EXP_COUNTER_INCREMENT(exp, disconnect);
858 rc = OBP(exp->exp_obd, disconnect)(exp);
862 static inline int obd_fid_init(struct obd_export *exp)
867 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
868 EXP_COUNTER_INCREMENT(exp, fid_init);
870 rc = OBP(exp->exp_obd, fid_init)(exp);
874 static inline int obd_fid_fini(struct obd_export *exp)
879 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
880 EXP_COUNTER_INCREMENT(exp, fid_fini);
882 rc = OBP(exp->exp_obd, fid_fini)(exp);
886 static inline int obd_fid_alloc(struct obd_export *exp,
888 struct md_op_data *op_data)
893 EXP_CHECK_DT_OP(exp, fid_alloc);
894 EXP_COUNTER_INCREMENT(exp, fid_alloc);
896 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
900 static inline int obd_fid_delete(struct obd_export *exp,
901 const struct lu_fid *fid)
906 EXP_CHECK_DT_OP(exp, fid_delete);
907 EXP_COUNTER_INCREMENT(exp, fid_delete);
909 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
913 static inline int obd_ping(struct obd_export *exp)
918 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
919 EXP_COUNTER_INCREMENT(exp, ping);
921 rc = OBP(exp->exp_obd, ping)(exp);
925 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
930 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
931 OBD_COUNTER_INCREMENT(obd, pool_new);
933 rc = OBP(obd, pool_new)(obd, poolname);
937 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
942 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
943 OBD_COUNTER_INCREMENT(obd, pool_del);
945 rc = OBP(obd, pool_del)(obd, poolname);
949 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
954 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
955 OBD_COUNTER_INCREMENT(obd, pool_add);
957 rc = OBP(obd, pool_add)(obd, poolname, ostname);
961 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
966 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
967 OBD_COUNTER_INCREMENT(obd, pool_rem);
969 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
973 static inline int obd_init_export(struct obd_export *exp)
978 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
979 OBP((exp)->exp_obd, init_export))
980 rc = OBP(exp->exp_obd, init_export)(exp);
984 static inline int obd_destroy_export(struct obd_export *exp)
987 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
988 OBP((exp)->exp_obd, destroy_export))
989 OBP(exp->exp_obd, destroy_export)(exp);
993 static inline int obd_extent_calc(struct obd_export *exp,
994 struct lov_stripe_md *md,
995 int cmd, obd_off *offset)
999 EXP_CHECK_DT_OP(exp, extent_calc);
1000 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1004 static inline struct dentry *
1005 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1007 LASSERT(exp->exp_obd);
1009 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1014 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1016 LASSERT(exp->exp_obd);
1017 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1019 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1020 dentry, exp->exp_obd);
1026 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
1029 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1030 * If the cache is older than @max_age we will get a new value from the
1031 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1032 static inline int obd_statfs_async(struct obd_device *obd,
1033 struct obd_info *oinfo,
1035 struct ptlrpc_request_set *rqset)
1043 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1044 OBD_COUNTER_INCREMENT(obd, statfs);
1046 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1047 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1048 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1049 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1051 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1052 " objects "LPU64"/"LPU64"\n",
1053 obd->obd_name, &obd->obd_osfs,
1054 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1055 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1056 spin_lock(&obd->obd_osfs_lock);
1057 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1058 spin_unlock(&obd->obd_osfs_lock);
1059 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1060 if (oinfo->oi_cb_up)
1061 oinfo->oi_cb_up(oinfo, 0);
1066 static inline int obd_statfs_rqset(struct obd_device *obd,
1067 struct obd_statfs *osfs, __u64 max_age,
1070 struct ptlrpc_request_set *set = NULL;
1071 struct obd_info oinfo = { { { 0 } } };
1075 set = ptlrpc_prep_set();
1079 oinfo.oi_osfs = osfs;
1080 oinfo.oi_flags = flags;
1081 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1083 rc = ptlrpc_set_wait(set);
1084 ptlrpc_set_destroy(set);
1088 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1089 * If the cache is older than @max_age we will get a new value from the
1090 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1091 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1092 __u64 max_age, __u32 flags)
1100 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1101 OBD_COUNTER_INCREMENT(obd, statfs);
1103 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1104 obd->obd_osfs_age, max_age);
1105 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1106 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1108 spin_lock(&obd->obd_osfs_lock);
1109 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1110 obd->obd_osfs_age = cfs_time_current_64();
1111 spin_unlock(&obd->obd_osfs_lock);
1114 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1115 " objects "LPU64"/"LPU64"\n",
1116 obd->obd_name, &obd->obd_osfs,
1117 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1118 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1119 spin_lock(&obd->obd_osfs_lock);
1120 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1121 spin_unlock(&obd->obd_osfs_lock);
1126 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1127 struct lov_stripe_md *ea, obd_size start,
1128 obd_size end, void *capa)
1133 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1134 EXP_COUNTER_INCREMENT(exp, sync);
1136 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1140 static inline int obd_punch_rqset(struct obd_export *exp,
1141 struct obd_info *oinfo,
1142 struct obd_trans_info *oti)
1144 struct ptlrpc_request_set *set = NULL;
1148 EXP_CHECK_DT_OP(exp, punch);
1149 EXP_COUNTER_INCREMENT(exp, punch);
1151 set = ptlrpc_prep_set();
1155 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1157 rc = ptlrpc_set_wait(set);
1158 ptlrpc_set_destroy(set);
1162 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1163 struct obd_trans_info *oti,
1164 struct ptlrpc_request_set *rqset)
1169 EXP_CHECK_DT_OP(exp, punch);
1170 EXP_COUNTER_INCREMENT(exp, punch);
1172 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1176 static inline int obd_brw(int cmd, struct obd_export *exp,
1177 struct obd_info *oinfo, obd_count oa_bufs,
1178 struct brw_page *pg, struct obd_trans_info *oti)
1183 EXP_CHECK_DT_OP(exp, brw);
1184 EXP_COUNTER_INCREMENT(exp, brw);
1186 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1187 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1188 "or OBD_BRW_CHECK\n");
1192 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1196 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1197 int objcount, struct obd_ioobj *obj,
1198 struct niobuf_remote *remote, int *pages,
1199 struct niobuf_local *local,
1200 struct obd_trans_info *oti,
1201 struct lustre_capa *capa)
1206 EXP_CHECK_DT_OP(exp, preprw);
1207 EXP_COUNTER_INCREMENT(exp, preprw);
1209 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1210 pages, local, oti, capa);
1214 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1215 int objcount, struct obd_ioobj *obj,
1216 struct niobuf_remote *rnb, int pages,
1217 struct niobuf_local *local,
1218 struct obd_trans_info *oti, int rc)
1222 EXP_CHECK_DT_OP(exp, commitrw);
1223 EXP_COUNTER_INCREMENT(exp, commitrw);
1225 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1226 rnb, pages, local, oti, rc);
1230 static inline int obd_merge_lvb(struct obd_export *exp,
1231 struct lov_stripe_md *lsm,
1232 struct ost_lvb *lvb, int kms_only)
1237 EXP_CHECK_DT_OP(exp, merge_lvb);
1238 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1240 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1244 static inline int obd_adjust_kms(struct obd_export *exp,
1245 struct lov_stripe_md *lsm, obd_off size,
1251 EXP_CHECK_DT_OP(exp, adjust_kms);
1252 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1254 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1258 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1259 int len, void *karg, void *uarg)
1264 EXP_CHECK_DT_OP(exp, iocontrol);
1265 EXP_COUNTER_INCREMENT(exp, iocontrol);
1267 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1271 static inline int obd_enqueue_rqset(struct obd_export *exp,
1272 struct obd_info *oinfo,
1273 struct ldlm_enqueue_info *einfo)
1275 struct ptlrpc_request_set *set = NULL;
1279 EXP_CHECK_DT_OP(exp, enqueue);
1280 EXP_COUNTER_INCREMENT(exp, enqueue);
1282 set = ptlrpc_prep_set();
1286 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1288 rc = ptlrpc_set_wait(set);
1289 ptlrpc_set_destroy(set);
1293 static inline int obd_enqueue(struct obd_export *exp,
1294 struct obd_info *oinfo,
1295 struct ldlm_enqueue_info *einfo,
1296 struct ptlrpc_request_set *set)
1301 EXP_CHECK_DT_OP(exp, enqueue);
1302 EXP_COUNTER_INCREMENT(exp, enqueue);
1304 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1308 static inline int obd_change_cbdata(struct obd_export *exp,
1309 struct lov_stripe_md *lsm,
1310 ldlm_iterator_t it, void *data)
1315 EXP_CHECK_DT_OP(exp, change_cbdata);
1316 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1318 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1322 static inline int obd_cancel(struct obd_export *exp,
1323 struct lov_stripe_md *ea, __u32 mode,
1324 struct lustre_handle *lockh)
1329 EXP_CHECK_DT_OP(exp, cancel);
1330 EXP_COUNTER_INCREMENT(exp, cancel);
1332 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1336 static inline int obd_cancel_unused(struct obd_export *exp,
1337 struct lov_stripe_md *ea,
1338 int flags, void *opaque)
1343 EXP_CHECK_DT_OP(exp, cancel_unused);
1344 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1346 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1350 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1351 struct obd_capa *oc, struct obd_client_handle *handle,
1357 EXP_CHECK_DT_OP(exp, pin);
1358 EXP_COUNTER_INCREMENT(exp, pin);
1360 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1364 static inline int obd_unpin(struct obd_export *exp,
1365 struct obd_client_handle *handle, int flag)
1370 EXP_CHECK_DT_OP(exp, unpin);
1371 EXP_COUNTER_INCREMENT(exp, unpin);
1373 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1378 static inline void obd_import_event(struct obd_device *obd,
1379 struct obd_import *imp,
1380 enum obd_import_event event)
1384 CERROR("NULL device\n");
1388 if (obd->obd_set_up && OBP(obd, import_event)) {
1389 OBD_COUNTER_INCREMENT(obd, import_event);
1390 OBP(obd, import_event)(obd, imp, event);
1395 static inline int obd_llog_connect(struct obd_export *exp,
1396 struct llogd_conn_body *body)
1401 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1402 EXP_COUNTER_INCREMENT(exp, llog_connect);
1404 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1409 static inline int obd_notify(struct obd_device *obd,
1410 struct obd_device *watched,
1411 enum obd_notify_event ev,
1418 /* the check for async_recov is a complete hack - I'm hereby
1419 overloading the meaning to also mean "this was called from
1420 mds_postsetup". I know that my mds is able to handle notifies
1421 by this point, and it needs to get them to execute mds_postrecov. */
1422 if (!obd->obd_set_up && !obd->obd_async_recov) {
1423 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1427 if (!OBP(obd, notify)) {
1428 CERROR("obd %s has no notify handler\n", obd->obd_name);
1432 OBD_COUNTER_INCREMENT(obd, notify);
1433 rc = OBP(obd, notify)(obd, watched, ev, data);
1437 static inline int obd_notify_observer(struct obd_device *observer,
1438 struct obd_device *observed,
1439 enum obd_notify_event ev,
1445 struct obd_notify_upcall *onu;
1447 if (observer->obd_observer)
1448 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1452 * Also, call non-obd listener, if any
1454 onu = &observer->obd_upcall;
1455 if (onu->onu_upcall != NULL)
1456 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1460 return rc1 ? rc1 : rc2;
1463 static inline int obd_quotacheck(struct obd_export *exp,
1464 struct obd_quotactl *oqctl)
1469 EXP_CHECK_DT_OP(exp, quotacheck);
1470 EXP_COUNTER_INCREMENT(exp, quotacheck);
1472 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1476 static inline int obd_quotactl(struct obd_export *exp,
1477 struct obd_quotactl *oqctl)
1482 EXP_CHECK_DT_OP(exp, quotactl);
1483 EXP_COUNTER_INCREMENT(exp, quotactl);
1485 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1489 static inline int obd_health_check(struct obd_device *obd)
1491 /* returns: 0 on healthy
1492 * >0 on unhealthy + reason code/flag
1493 * however the only suppored reason == 1 right now
1494 * We'll need to define some better reasons
1495 * or flags in the future.
1501 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1502 if (obd == NULL || !OBT(obd)) {
1503 CERROR("cleaned up obd\n");
1504 RETURN(-EOPNOTSUPP);
1506 if (!obd->obd_set_up || obd->obd_stopping)
1508 if (!OBP(obd, health_check))
1511 rc = OBP(obd, health_check)(obd);
1515 static inline int obd_register_observer(struct obd_device *obd,
1516 struct obd_device *observer)
1520 if (obd->obd_observer && observer)
1522 obd->obd_observer = observer;
1527 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1528 obd_page_removal_cb_t cb,
1529 obd_pin_extent_cb pin_cb)
1534 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1535 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1537 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1541 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1542 obd_page_removal_cb_t cb)
1547 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1548 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1550 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1554 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1555 obd_lock_cancel_cb cb)
1560 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1561 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1563 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1567 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1568 obd_lock_cancel_cb cb)
1573 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1574 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1576 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1581 /* metadata helpers */
1582 static inline int md_getstatus(struct obd_export *exp,
1583 struct lu_fid *fid, struct obd_capa **pc)
1588 EXP_CHECK_MD_OP(exp, getstatus);
1589 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1590 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1594 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1595 struct obd_capa *oc, obd_valid valid, int ea_size,
1596 struct ptlrpc_request **request)
1600 EXP_CHECK_MD_OP(exp, getattr);
1601 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1602 rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1607 static inline int md_change_cbdata(struct obd_export *exp,
1608 const struct lu_fid *fid,
1609 ldlm_iterator_t it, void *data)
1613 EXP_CHECK_MD_OP(exp, change_cbdata);
1614 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1615 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1619 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1620 struct md_open_data *mod,
1621 struct ptlrpc_request **request)
1625 EXP_CHECK_MD_OP(exp, close);
1626 EXP_MD_COUNTER_INCREMENT(exp, close);
1627 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1631 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1632 const void *data, int datalen, int mode, __u32 uid,
1633 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1634 struct ptlrpc_request **request)
1638 EXP_CHECK_MD_OP(exp, create);
1639 EXP_MD_COUNTER_INCREMENT(exp, create);
1640 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1641 uid, gid, cap_effective, rdev, request);
1645 static inline int md_done_writing(struct obd_export *exp,
1646 struct md_op_data *op_data,
1647 struct md_open_data *mod)
1651 EXP_CHECK_MD_OP(exp, done_writing);
1652 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1653 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1657 static inline int md_enqueue(struct obd_export *exp,
1658 struct ldlm_enqueue_info *einfo,
1659 struct lookup_intent *it,
1660 struct md_op_data *op_data,
1661 struct lustre_handle *lockh,
1662 void *lmm, int lmmsize,
1663 struct ptlrpc_request **req,
1664 int extra_lock_flags)
1668 EXP_CHECK_MD_OP(exp, enqueue);
1669 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1670 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1671 lmm, lmmsize, req, extra_lock_flags);
1675 static inline int md_getattr_name(struct obd_export *exp,
1676 const struct lu_fid *fid, struct obd_capa *oc,
1677 const char *name, int namelen,
1678 obd_valid valid, int ea_size, __u32 suppgid,
1679 struct ptlrpc_request **request)
1683 EXP_CHECK_MD_OP(exp, getattr_name);
1684 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1685 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1686 valid, ea_size, suppgid, request);
1690 static inline int md_intent_lock(struct obd_export *exp,
1691 struct md_op_data *op_data, void *lmm,
1692 int lmmsize, struct lookup_intent *it,
1693 int flags, struct ptlrpc_request **reqp,
1694 ldlm_blocking_callback cb_blocking,
1695 int extra_lock_flags)
1699 EXP_CHECK_MD_OP(exp, intent_lock);
1700 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1701 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1702 it, flags, reqp, cb_blocking,
1707 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1708 struct ptlrpc_request **request)
1712 EXP_CHECK_MD_OP(exp, link);
1713 EXP_MD_COUNTER_INCREMENT(exp, link);
1714 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1718 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1719 const char *old, int oldlen, const char *new,
1720 int newlen, struct ptlrpc_request **request)
1724 EXP_CHECK_MD_OP(exp, rename);
1725 EXP_MD_COUNTER_INCREMENT(exp, rename);
1726 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1731 static inline int md_is_subdir(struct obd_export *exp,
1732 const struct lu_fid *pfid,
1733 const struct lu_fid *cfid,
1734 struct ptlrpc_request **request)
1738 EXP_CHECK_MD_OP(exp, is_subdir);
1739 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1740 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1744 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1745 void *ea, int ealen, void *ea2, int ea2len,
1746 struct ptlrpc_request **request,
1747 struct md_open_data **mod)
1751 EXP_CHECK_MD_OP(exp, setattr);
1752 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1753 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1754 ea2, ea2len, request, mod);
1758 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1759 struct obd_capa *oc, struct ptlrpc_request **request)
1763 EXP_CHECK_MD_OP(exp, sync);
1764 EXP_MD_COUNTER_INCREMENT(exp, sync);
1765 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1769 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1770 struct obd_capa *oc, __u64 offset,
1772 struct ptlrpc_request **request)
1776 EXP_CHECK_MD_OP(exp, readpage);
1777 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1778 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1782 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1783 struct ptlrpc_request **request)
1787 EXP_CHECK_MD_OP(exp, unlink);
1788 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1789 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1793 static inline int md_get_lustre_md(struct obd_export *exp,
1794 struct ptlrpc_request *req,
1795 struct obd_export *dt_exp,
1796 struct obd_export *md_exp,
1797 struct lustre_md *md)
1800 EXP_CHECK_MD_OP(exp, get_lustre_md);
1801 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1802 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1805 static inline int md_free_lustre_md(struct obd_export *exp,
1806 struct lustre_md *md)
1809 EXP_CHECK_MD_OP(exp, free_lustre_md);
1810 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1811 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1814 static inline int md_setxattr(struct obd_export *exp,
1815 const struct lu_fid *fid, struct obd_capa *oc,
1816 obd_valid valid, const char *name,
1817 const char *input, int input_size,
1818 int output_size, int flags, __u32 suppgid,
1819 struct ptlrpc_request **request)
1822 EXP_CHECK_MD_OP(exp, setxattr);
1823 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1824 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1825 input_size, output_size, flags,
1829 static inline int md_getxattr(struct obd_export *exp,
1830 const struct lu_fid *fid, struct obd_capa *oc,
1831 obd_valid valid, const char *name,
1832 const char *input, int input_size,
1833 int output_size, int flags,
1834 struct ptlrpc_request **request)
1837 EXP_CHECK_MD_OP(exp, getxattr);
1838 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1839 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1840 input_size, output_size, flags,
1844 static inline int md_set_open_replay_data(struct obd_export *exp,
1845 struct obd_client_handle *och,
1846 struct ptlrpc_request *open_req)
1849 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1850 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1851 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1854 static inline int md_clear_open_replay_data(struct obd_export *exp,
1855 struct obd_client_handle *och)
1858 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1859 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1860 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1863 static inline int md_set_lock_data(struct obd_export *exp,
1864 __u64 *lockh, void *data)
1867 EXP_CHECK_MD_OP(exp, set_lock_data);
1868 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1869 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1872 static inline int md_cancel_unused(struct obd_export *exp,
1873 const struct lu_fid *fid,
1874 ldlm_policy_data_t *policy,
1875 ldlm_mode_t mode, int flags, void *opaque)
1880 EXP_CHECK_MD_OP(exp, cancel_unused);
1881 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1883 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1888 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
1889 const struct lu_fid *fid,
1891 ldlm_policy_data_t *policy,
1893 struct lustre_handle *lockh)
1896 EXP_CHECK_MD_OP(exp, lock_match);
1897 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1898 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1899 policy, mode, lockh));
1902 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1903 int def_asize, int cookiesize)
1906 EXP_CHECK_MD_OP(exp, init_ea_size);
1907 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1908 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1912 static inline int md_get_remote_perm(struct obd_export *exp,
1913 const struct lu_fid *fid,
1914 struct obd_capa *oc, __u32 suppgid,
1915 struct ptlrpc_request **request)
1918 EXP_CHECK_MD_OP(exp, get_remote_perm);
1919 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1920 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1924 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1929 EXP_CHECK_MD_OP(exp, renew_capa);
1930 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1931 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1935 static inline int md_intent_getattr_async(struct obd_export *exp,
1936 struct md_enqueue_info *minfo,
1937 struct ldlm_enqueue_info *einfo)
1941 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1942 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1943 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
1947 static inline int md_revalidate_lock(struct obd_export *exp,
1948 struct lookup_intent *it,
1953 EXP_CHECK_MD_OP(exp, revalidate_lock);
1954 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1955 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
1960 /* OBD Metadata Support */
1962 extern int obd_init_caches(void);
1963 extern void obd_cleanup_caches(void);
1965 /* support routines */
1966 extern cfs_mem_cache_t *obdo_cachep;
1968 #define OBDO_ALLOC(ptr) \
1970 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
1973 #define OBDO_FREE(ptr) \
1975 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1979 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
1981 /* something here */
1984 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
1986 /* something here */
1989 /* I'm as embarrassed about this as you are.
1991 * <shaver> // XXX do not look into _superhack with remaining eye
1992 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1993 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1996 extern void obd_sysctl_init (void);
1997 extern void obd_sysctl_clean (void);
2000 typedef __u8 class_uuid_t[16];
2001 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2004 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2005 int class_add_uuid(const char *uuid, __u64 nid);
2006 int class_del_uuid (const char *uuid);
2007 void class_init_uuidlist(void);
2008 void class_exit_uuidlist(void);
2011 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2012 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2015 void ll_generate_random_uuid(class_uuid_t uuid_out);
2017 #endif /* __LINUX_OBD_CLASS_H */