1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 # include <liblustre.h>
29 #include <obd_support.h>
30 #include <lustre_import.h>
31 #include <lustre_net.h>
33 #include <lustre_lib.h>
34 #include <lustre/lustre_idl.h>
35 #include <lprocfs_status.h>
37 #if defined(__linux__)
38 #include <linux/obd_class.h>
39 #elif defined(__APPLE__)
40 #include <darwin/obd_class.h>
41 #elif defined(__WINNT__)
42 #include <winnt/obd_class.h>
44 #error Unsupported operating system.
47 /* OBD Device Declarations */
48 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
49 extern spinlock_t obd_dev_lock;
51 /* OBD Operations Declarations */
52 extern struct obd_device *class_conn2obd(struct lustre_handle *);
53 extern struct obd_device *class_exp2obd(struct obd_export *);
55 struct lu_device_type;
58 struct obd_export *class_conn2export(struct lustre_handle *);
59 int class_register_type(struct obd_ops *, struct md_ops *,
60 struct lprocfs_vars *, const char *nm,
61 struct lu_device_type *ldt);
62 int class_unregister_type(const char *nm);
64 struct obd_device *class_newdev(const char *type_name, const char *name);
65 void class_release_dev(struct obd_device *obd);
67 int class_name2dev(const char *name);
68 struct obd_device *class_name2obd(const char *name);
69 int class_uuid2dev(struct obd_uuid *uuid);
70 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
71 void class_obd_list(void);
72 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
73 const char * typ_name,
74 struct obd_uuid *grp_uuid);
75 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
76 struct obd_uuid *grp_uuid);
77 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
79 struct obd_device * class_num2obd(int num);
81 int oig_init(struct obd_io_group **oig);
82 int oig_add_one(struct obd_io_group *oig, struct oig_callback_context *occ);
83 void oig_complete_one(struct obd_io_group *oig,
84 struct oig_callback_context *occ, int rc);
85 void oig_release(struct obd_io_group *oig);
86 int oig_wait(struct obd_io_group *oig);
88 char *obd_export_nid2str(struct obd_export *exp);
90 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
91 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
94 int class_process_config(struct lustre_cfg *lcfg);
95 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
96 struct lustre_cfg *lcfg, void *data);
97 int class_attach(struct lustre_cfg *lcfg);
98 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
99 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
100 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
101 struct obd_device *class_incref(struct obd_device *obd);
102 void class_decref(struct obd_device *obd);
106 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
108 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
110 memset(lvars, 0, sizeof(*lvars));
114 #define CFG_F_START 0x01 /* Set when we start updating from a log */
115 #define CFG_F_MARKER 0x02 /* We are within a maker */
116 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
117 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
118 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
120 /* Passed as data param to class_config_parse_llog */
121 struct config_llog_instance {
123 struct super_block *cfg_sb;
124 struct obd_uuid cfg_uuid;
125 int cfg_last_idx; /* for partial llog processing */
128 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
129 struct config_llog_instance *cfg);
130 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
131 struct config_llog_instance *cfg);
133 /* list of active configuration logs */
134 struct config_llog_data {
136 struct ldlm_res_id cld_resid;
137 struct config_llog_instance cld_cfg;
138 struct list_head cld_list_chain;
139 atomic_t cld_refcount;
140 struct obd_export *cld_mgcexp;
141 unsigned int cld_stopping:1, /* we were told to stop watching */
142 cld_lostlock:1; /* lock not requeued */
145 struct lustre_profile {
146 struct list_head lp_list;
152 struct lustre_profile *class_get_profile(const char * prof);
153 void class_del_profile(const char *prof);
154 void class_del_profiles(void);
156 #define class_export_rpc_get(exp) \
158 atomic_inc(&(exp)->exp_rpc_count); \
159 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
160 (exp), atomic_read(&(exp)->exp_rpc_count)); \
161 class_export_get(exp); \
164 #define class_export_rpc_put(exp) \
166 atomic_dec(&(exp)->exp_rpc_count); \
167 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
168 (exp), atomic_read(&(exp)->exp_rpc_count)); \
169 class_export_put(exp); \
173 #define class_export_get(exp) \
175 struct obd_export *exp_ = exp; \
176 atomic_inc(&exp_->exp_refcount); \
177 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
178 atomic_read(&exp_->exp_refcount)); \
182 #define class_export_put(exp) \
184 LASSERT((exp) != NULL); \
185 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
186 atomic_read(&(exp)->exp_refcount) - 1); \
187 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
188 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
189 __class_export_put(exp); \
192 void __class_export_put(struct obd_export *);
193 struct obd_export *class_new_export(struct obd_device *obddev,
194 struct obd_uuid *cluuid);
195 void class_unlink_export(struct obd_export *exp);
197 struct obd_import *class_import_get(struct obd_import *);
198 void class_import_put(struct obd_import *);
199 struct obd_import *class_new_import(struct obd_device *obd);
200 void class_destroy_import(struct obd_import *exp);
202 struct obd_type *class_search_type(const char *name);
203 struct obd_type *class_get_type(const char *name);
204 void class_put_type(struct obd_type *type);
205 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
206 struct obd_uuid *cluuid);
207 int class_disconnect(struct obd_export *exp);
208 void class_fail_export(struct obd_export *exp);
209 void class_disconnect_exports(struct obd_device *obddev);
210 int class_disconnect_stale_exports(struct obd_device *,
211 int (*test_export)(struct obd_export *));
212 int class_manual_cleanup(struct obd_device *obd);
214 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
215 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
216 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
217 unsigned int ia_valid);
218 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
219 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
220 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
223 #define OBT(dev) (dev)->obd_type
224 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
225 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
226 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
228 /* Ensure obd_setup: used for cleanup which must be called
229 while obd is stopping */
230 #define OBD_CHECK_DEV(obd) \
233 CERROR("NULL device\n"); \
238 /* ensure obd_setup and !obd_stopping */
239 #define OBD_CHECK_DEV_ACTIVE(obd) \
241 OBD_CHECK_DEV(obd); \
242 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
243 CERROR("Device %d not setup\n", \
251 #define OBD_COUNTER_OFFSET(op) \
252 ((offsetof(struct obd_ops, o_ ## op) - \
253 offsetof(struct obd_ops, o_iocontrol)) \
254 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
256 #define OBD_COUNTER_INCREMENT(obdx, op) \
257 if ((obdx)->obd_stats != NULL) { \
258 unsigned int coffset; \
259 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
260 OBD_COUNTER_OFFSET(op); \
261 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
262 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
265 #define EXP_COUNTER_INCREMENT(export, op) \
266 if ((export)->exp_obd->obd_stats != NULL) { \
267 unsigned int coffset; \
268 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
269 OBD_COUNTER_OFFSET(op); \
270 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
271 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
272 if ((export)->exp_ops_stats != NULL) \
273 lprocfs_counter_incr( \
274 (export)->exp_ops_stats, coffset); \
277 #define MD_COUNTER_OFFSET(op) \
278 ((offsetof(struct md_ops, m_ ## op) - \
279 offsetof(struct md_ops, m_getstatus)) \
280 / sizeof(((struct md_ops *)(0))->m_getstatus))
282 #define MD_COUNTER_INCREMENT(obdx, op) \
283 if ((obd)->md_stats != NULL) { \
284 unsigned int coffset; \
285 coffset = (unsigned int)((obdx)->md_cntr_base) + \
286 MD_COUNTER_OFFSET(op); \
287 LASSERT(coffset < (obdx)->md_stats->ls_num); \
288 lprocfs_counter_incr((obdx)->md_stats, coffset); \
291 #define EXP_MD_COUNTER_INCREMENT(export, op) \
292 if ((export)->exp_obd->obd_stats != NULL) { \
293 unsigned int coffset; \
294 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
295 MD_COUNTER_OFFSET(op); \
296 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
297 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
298 if ((export)->exp_md_stats != NULL) \
299 lprocfs_counter_incr( \
300 (export)->exp_md_stats, coffset); \
304 #define OBD_COUNTER_OFFSET(op)
305 #define OBD_COUNTER_INCREMENT(obd, op)
306 #define EXP_COUNTER_INCREMENT(exp, op)
307 #define MD_COUNTER_INCREMENT(obd, op)
308 #define EXP_MD_COUNTER_INCREMENT(exp, op)
311 #define OBD_CHECK_MD_OP(obd, op, err) \
313 if (!OBT(obd) || !MDP((obd), op)) { \
315 CERROR("md_" #op ": dev %s/%d no operation\n", \
316 obd->obd_name, obd->obd_minor); \
321 #define EXP_CHECK_MD_OP(exp, op) \
323 if ((exp) == NULL) { \
324 CERROR("obd_" #op ": NULL export\n"); \
327 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
328 CERROR("obd_" #op ": cleaned up obd\n"); \
329 RETURN(-EOPNOTSUPP); \
331 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
332 CERROR("obd_" #op ": dev %s/%d no operation\n", \
333 (exp)->exp_obd->obd_name, \
334 (exp)->exp_obd->obd_minor); \
335 RETURN(-EOPNOTSUPP); \
340 #define OBD_CHECK_DT_OP(obd, op, err) \
342 if (!OBT(obd) || !OBP((obd), op)) { \
344 CERROR("obd_" #op ": dev %d no operation\n", \
350 #define EXP_CHECK_DT_OP(exp, op) \
352 if ((exp) == NULL) { \
353 CERROR("obd_" #op ": NULL export\n"); \
356 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
357 CERROR("obd_" #op ": cleaned up obd\n"); \
358 RETURN(-EOPNOTSUPP); \
360 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
361 CERROR("obd_" #op ": dev %d no operation\n", \
362 (exp)->exp_obd->obd_minor); \
363 RETURN(-EOPNOTSUPP); \
367 #define CTXT_CHECK_OP(ctxt, op, err) \
369 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
371 CERROR("lop_" #op ": dev %d no operation\n", \
372 ctxt->loc_obd->obd_minor); \
377 static inline int class_devno_max(void)
379 return MAX_OBD_DEVICES;
382 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
383 void *key, __u32 *vallen, void *val)
388 EXP_CHECK_DT_OP(exp, get_info);
389 EXP_COUNTER_INCREMENT(exp, get_info);
391 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
395 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
396 void *key, obd_count vallen, void *val,
397 struct ptlrpc_request_set *set)
402 EXP_CHECK_DT_OP(exp, set_info_async);
403 EXP_COUNTER_INCREMENT(exp, set_info_async);
405 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
411 #define DECLARE_LU_VARS(ldt, d) \
412 struct lu_device_type *ldt; \
415 #define DECLARE_LU_VARS(ldt, d) \
416 extern void __placeholder_to_put_a_semicolon(void)
418 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
421 DECLARE_LU_VARS(ldt, d);
425 ldt = obd->obd_type->typ_lu;
429 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
431 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
443 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
444 OBD_COUNTER_INCREMENT(obd, setup);
445 rc = OBP(obd, setup)(obd, cfg);
450 static inline int obd_precleanup(struct obd_device *obd,
451 enum obd_cleanup_stage cleanup_stage)
454 DECLARE_LU_VARS(ldt, d);
459 ldt = obd->obd_type->typ_lu;
463 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
466 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
468 ldt->ldt_ops->ldto_device_fini(&env, d);
477 OBD_CHECK_DT_OP(obd, precleanup, 0);
478 rc = OBP(obd, precleanup)(obd, cleanup_stage);
481 OBD_COUNTER_INCREMENT(obd, precleanup);
485 static inline int obd_cleanup(struct obd_device *obd)
488 DECLARE_LU_VARS(ldt, d);
494 ldt = obd->obd_type->typ_lu;
500 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
502 ldt->ldt_ops->ldto_device_free(&env, d);
504 obd->obd_lu_dev = NULL;
509 OBD_CHECK_DT_OP(obd, cleanup, 0);
510 rc = OBP(obd, cleanup)(obd);
512 OBD_COUNTER_INCREMENT(obd, cleanup);
517 obd_process_config(struct obd_device *obd, int datalen, void *data)
520 DECLARE_LU_VARS(ldt, d);
526 ldt = obd->obd_type->typ_lu;
528 if (ldt != NULL && d != NULL) {
531 rc = lu_env_init(&env, NULL, ldt->ldt_ctx_tags);
533 rc = d->ld_ops->ldo_process_config(&env, d, data);
539 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
540 rc = OBP(obd, process_config)(obd, datalen, data);
542 OBD_COUNTER_INCREMENT(obd, process_config);
547 /* Pack an in-memory MD struct for storage on disk.
548 * Returns +ve size of packed MD (0 for free), or -ve error.
550 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
551 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
552 * If @*disk_tgt == NULL, it will be allocated
554 static inline int obd_packmd(struct obd_export *exp,
555 struct lov_mds_md **disk_tgt,
556 struct lov_stripe_md *mem_src)
561 EXP_CHECK_DT_OP(exp, packmd);
562 EXP_COUNTER_INCREMENT(exp, packmd);
564 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
568 static inline int obd_size_diskmd(struct obd_export *exp,
569 struct lov_stripe_md *mem_src)
571 return obd_packmd(exp, NULL, mem_src);
574 /* helper functions */
575 static inline int obd_alloc_diskmd(struct obd_export *exp,
576 struct lov_mds_md **disk_tgt)
579 LASSERT(*disk_tgt == NULL);
580 return obd_packmd(exp, disk_tgt, NULL);
583 static inline int obd_free_diskmd(struct obd_export *exp,
584 struct lov_mds_md **disk_tgt)
588 return obd_packmd(exp, disk_tgt, NULL);
591 /* Unpack an MD struct from disk to in-memory format.
592 * Returns +ve size of unpacked MD (0 for free), or -ve error.
594 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
595 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
596 * If @*mem_tgt == NULL, it will be allocated
598 static inline int obd_unpackmd(struct obd_export *exp,
599 struct lov_stripe_md **mem_tgt,
600 struct lov_mds_md *disk_src,
606 EXP_CHECK_DT_OP(exp, unpackmd);
607 EXP_COUNTER_INCREMENT(exp, unpackmd);
609 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
613 /* helper functions */
614 static inline int obd_alloc_memmd(struct obd_export *exp,
615 struct lov_stripe_md **mem_tgt)
618 LASSERT(*mem_tgt == NULL);
619 return obd_unpackmd(exp, mem_tgt, NULL, 0);
622 static inline int obd_free_memmd(struct obd_export *exp,
623 struct lov_stripe_md **mem_tgt)
627 return obd_unpackmd(exp, mem_tgt, NULL, 0);
630 static inline int obd_checkmd(struct obd_export *exp,
631 struct obd_export *md_exp,
632 struct lov_stripe_md *mem_tgt)
637 EXP_CHECK_DT_OP(exp, checkmd);
638 EXP_COUNTER_INCREMENT(exp, checkmd);
640 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
644 static inline int obd_precreate(struct obd_export *exp)
649 EXP_CHECK_DT_OP(exp, precreate);
650 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
652 rc = OBP(exp->exp_obd, precreate)(exp);
656 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
657 struct lov_stripe_md **ea,
658 struct obd_trans_info *oti)
663 EXP_CHECK_DT_OP(exp, create);
664 EXP_COUNTER_INCREMENT(exp, create);
666 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
670 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
671 struct lov_stripe_md *ea,
672 struct obd_trans_info *oti,
673 struct obd_export *md_exp)
678 EXP_CHECK_DT_OP(exp, destroy);
679 EXP_COUNTER_INCREMENT(exp, destroy);
681 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
685 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
690 EXP_CHECK_DT_OP(exp, getattr);
691 EXP_COUNTER_INCREMENT(exp, getattr);
693 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
697 static inline int obd_getattr_async(struct obd_export *exp,
698 struct obd_info *oinfo,
699 struct ptlrpc_request_set *set)
704 EXP_CHECK_DT_OP(exp, getattr_async);
705 EXP_COUNTER_INCREMENT(exp, getattr_async);
707 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
711 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
712 struct obd_trans_info *oti)
717 EXP_CHECK_DT_OP(exp, setattr);
718 EXP_COUNTER_INCREMENT(exp, setattr);
720 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
724 /* This performs all the requests set init/wait/destroy actions. */
725 static inline int obd_setattr_rqset(struct obd_export *exp,
726 struct obd_info *oinfo,
727 struct obd_trans_info *oti)
729 struct ptlrpc_request_set *set = NULL;
733 EXP_CHECK_DT_OP(exp, setattr_async);
734 EXP_COUNTER_INCREMENT(exp, setattr_async);
736 set = ptlrpc_prep_set();
740 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
742 rc = ptlrpc_set_wait(set);
743 ptlrpc_set_destroy(set);
747 /* This adds all the requests into @set if @set != NULL, otherwise
748 all requests are sent asynchronously without waiting for response. */
749 static inline int obd_setattr_async(struct obd_export *exp,
750 struct obd_info *oinfo,
751 struct obd_trans_info *oti,
752 struct ptlrpc_request_set *set)
757 EXP_CHECK_DT_OP(exp, setattr_async);
758 EXP_COUNTER_INCREMENT(exp, setattr_async);
760 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
764 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
767 struct obd_device *obd = imp->imp_obd;
771 OBD_CHECK_DEV_ACTIVE(obd);
772 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
773 OBD_COUNTER_INCREMENT(obd, add_conn);
775 rc = OBP(obd, add_conn)(imp, uuid, priority);
779 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
781 struct obd_device *obd = imp->imp_obd;
785 OBD_CHECK_DEV_ACTIVE(obd);
786 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
787 OBD_COUNTER_INCREMENT(obd, del_conn);
789 rc = OBP(obd, del_conn)(imp, uuid);
793 static inline int obd_connect(const struct lu_env *env,
794 struct lustre_handle *conn,struct obd_device *obd,
795 struct obd_uuid *cluuid,
796 struct obd_connect_data *d)
800 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
805 OBD_CHECK_DEV_ACTIVE(obd);
806 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
807 OBD_COUNTER_INCREMENT(obd, connect);
809 rc = OBP(obd, connect)(env, conn, obd, cluuid, d);
810 /* check that only subset is granted */
811 LASSERT(ergo(d != NULL,
812 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
816 static inline int obd_reconnect(const struct lu_env *env,
817 struct obd_export *exp,
818 struct obd_device *obd,
819 struct obd_uuid *cluuid,
820 struct obd_connect_data *d)
824 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
830 OBD_CHECK_DEV_ACTIVE(obd);
831 OBD_CHECK_DT_OP(obd, reconnect, 0);
832 OBD_COUNTER_INCREMENT(obd, reconnect);
834 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d);
835 /* check that only subset is granted */
836 LASSERT(ergo(d != NULL,
837 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
841 static inline int obd_disconnect(struct obd_export *exp)
846 EXP_CHECK_DT_OP(exp, disconnect);
847 EXP_COUNTER_INCREMENT(exp, disconnect);
849 rc = OBP(exp->exp_obd, disconnect)(exp);
853 static inline int obd_fid_init(struct obd_export *exp)
858 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
859 EXP_COUNTER_INCREMENT(exp, fid_init);
861 rc = OBP(exp->exp_obd, fid_init)(exp);
865 static inline int obd_fid_fini(struct obd_export *exp)
870 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
871 EXP_COUNTER_INCREMENT(exp, fid_fini);
873 rc = OBP(exp->exp_obd, fid_fini)(exp);
877 static inline int obd_fid_alloc(struct obd_export *exp,
879 struct md_op_data *op_data)
884 EXP_CHECK_DT_OP(exp, fid_alloc);
885 EXP_COUNTER_INCREMENT(exp, fid_alloc);
887 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
891 static inline int obd_fid_delete(struct obd_export *exp,
892 const struct lu_fid *fid)
897 EXP_CHECK_DT_OP(exp, fid_delete);
898 EXP_COUNTER_INCREMENT(exp, fid_delete);
900 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
904 static inline int obd_ping(struct obd_export *exp)
909 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
910 EXP_COUNTER_INCREMENT(exp, ping);
912 rc = OBP(exp->exp_obd, ping)(exp);
916 static inline int obd_init_export(struct obd_export *exp)
921 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
922 OBP((exp)->exp_obd, init_export))
923 rc = OBP(exp->exp_obd, init_export)(exp);
927 static inline int obd_destroy_export(struct obd_export *exp)
930 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
931 OBP((exp)->exp_obd, destroy_export))
932 OBP(exp->exp_obd, destroy_export)(exp);
936 static inline int obd_extent_calc(struct obd_export *exp,
937 struct lov_stripe_md *md,
938 int cmd, obd_off *offset)
942 EXP_CHECK_DT_OP(exp, extent_calc);
943 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
947 static inline struct dentry *
948 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
950 LASSERT(exp->exp_obd);
952 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
957 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
959 LASSERT(exp->exp_obd);
960 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
962 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
963 dentry, exp->exp_obd);
969 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
972 /* @max_age is the oldest time in jiffies that we accept using a cached data.
973 * If the cache is older than @max_age we will get a new value from the
974 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
975 static inline int obd_statfs_async(struct obd_device *obd,
976 struct obd_info *oinfo,
978 struct ptlrpc_request_set *rqset)
986 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
987 OBD_COUNTER_INCREMENT(obd, statfs);
989 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
990 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
991 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
992 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
994 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
995 " objects "LPU64"/"LPU64"\n",
996 obd->obd_name, &obd->obd_osfs,
997 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
998 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
999 spin_lock(&obd->obd_osfs_lock);
1000 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1001 spin_unlock(&obd->obd_osfs_lock);
1002 if (oinfo->oi_cb_up)
1003 oinfo->oi_cb_up(oinfo, 0);
1008 static inline int obd_statfs_rqset(struct obd_device *obd,
1009 struct obd_statfs *osfs, __u64 max_age,
1012 struct ptlrpc_request_set *set = NULL;
1013 struct obd_info oinfo = { { { 0 } } };
1017 set = ptlrpc_prep_set();
1021 oinfo.oi_osfs = osfs;
1022 oinfo.oi_flags = flags;
1023 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1025 rc = ptlrpc_set_wait(set);
1026 ptlrpc_set_destroy(set);
1030 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1031 * If the cache is older than @max_age we will get a new value from the
1032 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1033 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1034 __u64 max_age, __u32 flags)
1042 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1043 OBD_COUNTER_INCREMENT(obd, statfs);
1045 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1046 obd->obd_osfs_age, max_age);
1047 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1048 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1050 spin_lock(&obd->obd_osfs_lock);
1051 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1052 obd->obd_osfs_age = cfs_time_current_64();
1053 spin_unlock(&obd->obd_osfs_lock);
1056 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1057 " objects "LPU64"/"LPU64"\n",
1058 obd->obd_name, &obd->obd_osfs,
1059 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1060 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1061 spin_lock(&obd->obd_osfs_lock);
1062 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1063 spin_unlock(&obd->obd_osfs_lock);
1068 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1069 struct lov_stripe_md *ea, obd_size start,
1070 obd_size end, void *capa)
1075 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1076 EXP_COUNTER_INCREMENT(exp, sync);
1078 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1082 static inline int obd_punch_rqset(struct obd_export *exp,
1083 struct obd_info *oinfo,
1084 struct obd_trans_info *oti)
1086 struct ptlrpc_request_set *set = NULL;
1090 EXP_CHECK_DT_OP(exp, punch);
1091 EXP_COUNTER_INCREMENT(exp, punch);
1093 set = ptlrpc_prep_set();
1097 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1099 rc = ptlrpc_set_wait(set);
1100 ptlrpc_set_destroy(set);
1104 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1105 struct obd_trans_info *oti,
1106 struct ptlrpc_request_set *rqset)
1111 EXP_CHECK_DT_OP(exp, punch);
1112 EXP_COUNTER_INCREMENT(exp, punch);
1114 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1118 static inline int obd_brw(int cmd, struct obd_export *exp,
1119 struct obd_info *oinfo, obd_count oa_bufs,
1120 struct brw_page *pg, struct obd_trans_info *oti)
1125 EXP_CHECK_DT_OP(exp, brw);
1126 EXP_COUNTER_INCREMENT(exp, brw);
1128 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1129 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1130 "or OBD_BRW_CHECK\n");
1134 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1138 static inline int obd_brw_async(int cmd, struct obd_export *exp,
1139 struct obd_info *oinfo, obd_count oa_bufs,
1140 struct brw_page *pg, struct obd_trans_info *oti,
1141 struct ptlrpc_request_set *set)
1146 EXP_CHECK_DT_OP(exp, brw_async);
1147 EXP_COUNTER_INCREMENT(exp, brw_async);
1149 if (!(cmd & OBD_BRW_RWMASK)) {
1150 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
1154 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oinfo, oa_bufs, pg,oti,set);
1158 static inline int obd_brw_rqset(int cmd, struct obd_export *exp,
1159 struct obdo *oa, struct lov_stripe_md *lsm,
1160 obd_count oa_bufs, struct brw_page *pg,
1161 struct obd_trans_info *oti,
1162 struct obd_capa *ocapa)
1164 struct ptlrpc_request_set *set = NULL;
1165 struct obd_info oinfo = { { { 0 } } };
1169 set = ptlrpc_prep_set();
1175 oinfo.oi_capa = ocapa;
1176 rc = obd_brw_async(cmd, exp, &oinfo, oa_bufs, pg, oti, set);
1178 rc = ptlrpc_set_wait(set);
1180 CERROR("error from callback: rc = %d\n", rc);
1182 CDEBUG(rc == -ENOSPC ? D_INODE : D_ERROR,
1183 "error from obd_brw_async: rc = %d\n", rc);
1185 ptlrpc_set_destroy(set);
1189 static inline int obd_prep_async_page(struct obd_export *exp,
1190 struct lov_stripe_md *lsm,
1191 struct lov_oinfo *loi,
1192 cfs_page_t *page, obd_off offset,
1193 struct obd_async_page_ops *ops,
1194 void *data, void **res)
1199 EXP_CHECK_DT_OP(exp, prep_async_page);
1200 EXP_COUNTER_INCREMENT(exp, prep_async_page);
1202 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
1207 static inline int obd_queue_async_io(struct obd_export *exp,
1208 struct lov_stripe_md *lsm,
1209 struct lov_oinfo *loi, void *cookie,
1210 int cmd, obd_off off, int count,
1211 obd_flag brw_flags, obd_flag async_flags)
1216 EXP_CHECK_DT_OP(exp, queue_async_io);
1217 EXP_COUNTER_INCREMENT(exp, queue_async_io);
1218 LASSERT(cmd & OBD_BRW_RWMASK);
1220 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
1221 count, brw_flags, async_flags);
1225 static inline int obd_set_async_flags(struct obd_export *exp,
1226 struct lov_stripe_md *lsm,
1227 struct lov_oinfo *loi, void *cookie,
1228 obd_flag async_flags)
1233 EXP_CHECK_DT_OP(exp, set_async_flags);
1234 EXP_COUNTER_INCREMENT(exp, set_async_flags);
1236 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
1241 static inline int obd_queue_group_io(struct obd_export *exp,
1242 struct lov_stripe_md *lsm,
1243 struct lov_oinfo *loi,
1244 struct obd_io_group *oig,
1245 void *cookie, int cmd, obd_off off,
1246 int count, obd_flag brw_flags,
1247 obd_flag async_flags)
1252 EXP_CHECK_DT_OP(exp, queue_group_io);
1253 EXP_COUNTER_INCREMENT(exp, queue_group_io);
1254 LASSERT(cmd & OBD_BRW_RWMASK);
1256 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
1257 cmd, off, count, brw_flags,
1262 static inline int obd_trigger_group_io(struct obd_export *exp,
1263 struct lov_stripe_md *lsm,
1264 struct lov_oinfo *loi,
1265 struct obd_io_group *oig)
1270 EXP_CHECK_DT_OP(exp, trigger_group_io);
1271 EXP_COUNTER_INCREMENT(exp, trigger_group_io);
1273 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
1277 static inline int obd_teardown_async_page(struct obd_export *exp,
1278 struct lov_stripe_md *lsm,
1279 struct lov_oinfo *loi, void *cookie)
1284 EXP_CHECK_DT_OP(exp, teardown_async_page);
1285 EXP_COUNTER_INCREMENT(exp, teardown_async_page);
1287 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
1291 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1292 int objcount, struct obd_ioobj *obj,
1293 int niocount, struct niobuf_remote *remote,
1294 struct niobuf_local *local,
1295 struct obd_trans_info *oti,
1296 struct lustre_capa *capa)
1301 EXP_CHECK_DT_OP(exp, preprw);
1302 EXP_COUNTER_INCREMENT(exp, preprw);
1304 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
1305 remote, local, oti, capa);
1309 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1310 int objcount, struct obd_ioobj *obj,
1311 int niocount, struct niobuf_local *local,
1312 struct obd_trans_info *oti, int rc)
1316 EXP_CHECK_DT_OP(exp, commitrw);
1317 EXP_COUNTER_INCREMENT(exp, commitrw);
1319 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1324 static inline int obd_merge_lvb(struct obd_export *exp,
1325 struct lov_stripe_md *lsm,
1326 struct ost_lvb *lvb, int kms_only)
1331 EXP_CHECK_DT_OP(exp, merge_lvb);
1332 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1334 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1338 static inline int obd_adjust_kms(struct obd_export *exp,
1339 struct lov_stripe_md *lsm, obd_off size,
1345 EXP_CHECK_DT_OP(exp, adjust_kms);
1346 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1348 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1352 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1353 int len, void *karg, void *uarg)
1358 EXP_CHECK_DT_OP(exp, iocontrol);
1359 EXP_COUNTER_INCREMENT(exp, iocontrol);
1361 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1365 static inline int obd_enqueue_rqset(struct obd_export *exp,
1366 struct obd_info *oinfo,
1367 struct ldlm_enqueue_info *einfo)
1369 struct ptlrpc_request_set *set = NULL;
1373 EXP_CHECK_DT_OP(exp, enqueue);
1374 EXP_COUNTER_INCREMENT(exp, enqueue);
1376 set = ptlrpc_prep_set();
1380 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1382 rc = ptlrpc_set_wait(set);
1383 ptlrpc_set_destroy(set);
1387 static inline int obd_enqueue(struct obd_export *exp,
1388 struct obd_info *oinfo,
1389 struct ldlm_enqueue_info *einfo,
1390 struct ptlrpc_request_set *set)
1395 EXP_CHECK_DT_OP(exp, enqueue);
1396 EXP_COUNTER_INCREMENT(exp, enqueue);
1398 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1402 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1403 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1404 int *flags, void *data, struct lustre_handle *lockh)
1409 EXP_CHECK_DT_OP(exp, match);
1410 EXP_COUNTER_INCREMENT(exp, match);
1412 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1417 static inline int obd_change_cbdata(struct obd_export *exp,
1418 struct lov_stripe_md *lsm,
1419 ldlm_iterator_t it, void *data)
1424 EXP_CHECK_DT_OP(exp, change_cbdata);
1425 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1427 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1431 static inline int obd_cancel(struct obd_export *exp,
1432 struct lov_stripe_md *ea, __u32 mode,
1433 struct lustre_handle *lockh)
1438 EXP_CHECK_DT_OP(exp, cancel);
1439 EXP_COUNTER_INCREMENT(exp, cancel);
1441 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1445 static inline int obd_cancel_unused(struct obd_export *exp,
1446 struct lov_stripe_md *ea,
1447 int flags, void *opaque)
1452 EXP_CHECK_DT_OP(exp, cancel_unused);
1453 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1455 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1459 static inline int obd_join_lru(struct obd_export *exp,
1460 struct lov_stripe_md *ea, int join)
1465 EXP_CHECK_DT_OP(exp, join_lru);
1466 EXP_COUNTER_INCREMENT(exp, join_lru);
1468 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1472 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1473 struct obd_capa *oc, struct obd_client_handle *handle,
1479 EXP_CHECK_DT_OP(exp, pin);
1480 EXP_COUNTER_INCREMENT(exp, pin);
1482 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1486 static inline int obd_unpin(struct obd_export *exp,
1487 struct obd_client_handle *handle, int flag)
1492 EXP_CHECK_DT_OP(exp, unpin);
1493 EXP_COUNTER_INCREMENT(exp, unpin);
1495 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1500 static inline void obd_import_event(struct obd_device *obd,
1501 struct obd_import *imp,
1502 enum obd_import_event event)
1506 CERROR("NULL device\n");
1510 if (obd->obd_set_up && OBP(obd, import_event)) {
1511 OBD_COUNTER_INCREMENT(obd, import_event);
1512 OBP(obd, import_event)(obd, imp, event);
1517 static inline int obd_llog_connect(struct obd_export *exp,
1518 struct llogd_conn_body *body)
1523 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1524 EXP_COUNTER_INCREMENT(exp, llog_connect);
1526 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1531 static inline int obd_notify(struct obd_device *obd,
1532 struct obd_device *watched,
1533 enum obd_notify_event ev,
1540 /* the check for async_recov is a complete hack - I'm hereby
1541 overloading the meaning to also mean "this was called from
1542 mds_postsetup". I know that my mds is able to handle notifies
1543 by this point, and it needs to get them to execute mds_postrecov. */
1544 if (!obd->obd_set_up && !obd->obd_async_recov) {
1545 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1549 if (!OBP(obd, notify)) {
1550 CERROR("obd %s has no notify handler\n", obd->obd_name);
1554 OBD_COUNTER_INCREMENT(obd, notify);
1555 rc = OBP(obd, notify)(obd, watched, ev, data);
1559 static inline int obd_notify_observer(struct obd_device *observer,
1560 struct obd_device *observed,
1561 enum obd_notify_event ev,
1567 struct obd_notify_upcall *onu;
1569 if (observer->obd_observer)
1570 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1574 * Also, call non-obd listener, if any
1576 onu = &observer->obd_upcall;
1577 if (onu->onu_upcall != NULL)
1578 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1582 return rc1 ? rc1 : rc2;
1585 static inline int obd_quotacheck(struct obd_export *exp,
1586 struct obd_quotactl *oqctl)
1591 EXP_CHECK_DT_OP(exp, quotacheck);
1592 EXP_COUNTER_INCREMENT(exp, quotacheck);
1594 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1598 static inline int obd_quotactl(struct obd_export *exp,
1599 struct obd_quotactl *oqctl)
1604 EXP_CHECK_DT_OP(exp, quotactl);
1605 EXP_COUNTER_INCREMENT(exp, quotactl);
1607 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1611 static inline int obd_health_check(struct obd_device *obd)
1613 /* returns: 0 on healthy
1614 * >0 on unhealthy + reason code/flag
1615 * however the only suppored reason == 1 right now
1616 * We'll need to define some better reasons
1617 * or flags in the future.
1623 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1624 if (obd == NULL || !OBT(obd)) {
1625 CERROR("cleaned up obd\n");
1626 RETURN(-EOPNOTSUPP);
1628 if (!obd->obd_set_up || obd->obd_stopping)
1630 if (!OBP(obd, health_check))
1633 rc = OBP(obd, health_check)(obd);
1637 static inline int obd_register_observer(struct obd_device *obd,
1638 struct obd_device *observer)
1642 if (obd->obd_observer && observer)
1644 obd->obd_observer = observer;
1648 /* metadata helpers */
1649 static inline int md_getstatus(struct obd_export *exp,
1650 struct lu_fid *fid, struct obd_capa **pc)
1655 EXP_CHECK_MD_OP(exp, getstatus);
1656 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1657 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1661 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1662 struct obd_capa *oc, obd_valid valid, int ea_size,
1663 struct ptlrpc_request **request)
1667 EXP_CHECK_MD_OP(exp, getattr);
1668 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1669 rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1674 static inline int md_change_cbdata(struct obd_export *exp,
1675 const struct lu_fid *fid,
1676 ldlm_iterator_t it, void *data)
1680 EXP_CHECK_MD_OP(exp, change_cbdata);
1681 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1682 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1686 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1687 struct md_open_data *mod,
1688 struct ptlrpc_request **request)
1692 EXP_CHECK_MD_OP(exp, close);
1693 EXP_MD_COUNTER_INCREMENT(exp, close);
1694 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1698 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1699 const void *data, int datalen, int mode, __u32 uid,
1700 __u32 gid, __u32 cap_effective, __u64 rdev,
1701 struct ptlrpc_request **request)
1705 EXP_CHECK_MD_OP(exp, create);
1706 EXP_MD_COUNTER_INCREMENT(exp, create);
1707 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1708 uid, gid, cap_effective, rdev, request);
1712 static inline int md_done_writing(struct obd_export *exp,
1713 struct md_op_data *op_data,
1714 struct md_open_data *mod)
1718 EXP_CHECK_MD_OP(exp, done_writing);
1719 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1720 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1724 static inline int md_enqueue(struct obd_export *exp,
1725 struct ldlm_enqueue_info *einfo,
1726 struct lookup_intent *it,
1727 struct md_op_data *op_data,
1728 struct lustre_handle *lockh,
1729 void *lmm, int lmmsize,
1730 int extra_lock_flags)
1734 EXP_CHECK_MD_OP(exp, enqueue);
1735 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1736 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1737 lmm, lmmsize, extra_lock_flags);
1741 static inline int md_getattr_name(struct obd_export *exp,
1742 const struct lu_fid *fid, struct obd_capa *oc,
1743 const char *name, int namelen,
1744 obd_valid valid, int ea_size, __u32 suppgid,
1745 struct ptlrpc_request **request)
1749 EXP_CHECK_MD_OP(exp, getattr_name);
1750 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1751 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1752 valid, ea_size, suppgid, request);
1756 static inline int md_intent_lock(struct obd_export *exp,
1757 struct md_op_data *op_data, void *lmm,
1758 int lmmsize, struct lookup_intent *it,
1759 int flags, struct ptlrpc_request **reqp,
1760 ldlm_blocking_callback cb_blocking,
1761 int extra_lock_flags)
1765 EXP_CHECK_MD_OP(exp, intent_lock);
1766 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1767 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1768 it, flags, reqp, cb_blocking,
1773 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1774 struct ptlrpc_request **request)
1778 EXP_CHECK_MD_OP(exp, link);
1779 EXP_MD_COUNTER_INCREMENT(exp, link);
1780 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1784 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1785 const char *old, int oldlen, const char *new,
1786 int newlen, struct ptlrpc_request **request)
1790 EXP_CHECK_MD_OP(exp, rename);
1791 EXP_MD_COUNTER_INCREMENT(exp, rename);
1792 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1797 static inline int md_is_subdir(struct obd_export *exp,
1798 const struct lu_fid *pfid,
1799 const struct lu_fid *cfid,
1800 struct ptlrpc_request **request)
1804 EXP_CHECK_MD_OP(exp, is_subdir);
1805 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1806 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1810 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1811 void *ea, int ealen, void *ea2, int ea2len,
1812 struct ptlrpc_request **request,
1813 struct md_open_data **mod)
1817 EXP_CHECK_MD_OP(exp, setattr);
1818 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1819 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1820 ea2, ea2len, request, mod);
1824 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1825 struct obd_capa *oc, struct ptlrpc_request **request)
1829 EXP_CHECK_MD_OP(exp, sync);
1830 EXP_MD_COUNTER_INCREMENT(exp, sync);
1831 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1835 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1836 struct obd_capa *oc, __u64 offset,
1838 struct ptlrpc_request **request)
1842 EXP_CHECK_MD_OP(exp, readpage);
1843 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1844 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1848 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1849 struct ptlrpc_request **request)
1853 EXP_CHECK_MD_OP(exp, unlink);
1854 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1855 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1859 static inline int md_get_lustre_md(struct obd_export *exp,
1860 struct ptlrpc_request *req,
1861 struct obd_export *dt_exp,
1862 struct obd_export *md_exp,
1863 struct lustre_md *md)
1866 EXP_CHECK_MD_OP(exp, get_lustre_md);
1867 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1868 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1871 static inline int md_free_lustre_md(struct obd_export *exp,
1872 struct lustre_md *md)
1875 EXP_CHECK_MD_OP(exp, free_lustre_md);
1876 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1877 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1880 static inline int md_setxattr(struct obd_export *exp,
1881 const struct lu_fid *fid, struct obd_capa *oc,
1882 obd_valid valid, const char *name,
1883 const char *input, int input_size,
1884 int output_size, int flags, __u32 suppgid,
1885 struct ptlrpc_request **request)
1888 EXP_CHECK_MD_OP(exp, setxattr);
1889 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1890 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1891 input_size, output_size, flags,
1895 static inline int md_getxattr(struct obd_export *exp,
1896 const struct lu_fid *fid, struct obd_capa *oc,
1897 obd_valid valid, const char *name,
1898 const char *input, int input_size,
1899 int output_size, int flags,
1900 struct ptlrpc_request **request)
1903 EXP_CHECK_MD_OP(exp, getxattr);
1904 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1905 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1906 input_size, output_size, flags,
1910 static inline int md_set_open_replay_data(struct obd_export *exp,
1911 struct obd_client_handle *och,
1912 struct ptlrpc_request *open_req)
1915 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1916 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1917 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1920 static inline int md_clear_open_replay_data(struct obd_export *exp,
1921 struct obd_client_handle *och)
1924 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1925 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1926 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1929 static inline int md_set_lock_data(struct obd_export *exp,
1930 __u64 *lockh, void *data)
1933 EXP_CHECK_MD_OP(exp, set_lock_data);
1934 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1935 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1938 static inline int md_cancel_unused(struct obd_export *exp,
1939 const struct lu_fid *fid,
1940 ldlm_policy_data_t *policy,
1941 ldlm_mode_t mode, int flags, void *opaque)
1946 EXP_CHECK_MD_OP(exp, cancel_unused);
1947 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1949 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1954 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
1955 const struct lu_fid *fid,
1957 ldlm_policy_data_t *policy,
1959 struct lustre_handle *lockh)
1962 EXP_CHECK_MD_OP(exp, lock_match);
1963 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1964 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1965 policy, mode, lockh));
1968 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1969 int def_asize, int cookiesize)
1972 EXP_CHECK_MD_OP(exp, init_ea_size);
1973 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1974 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1978 static inline int md_get_remote_perm(struct obd_export *exp,
1979 const struct lu_fid *fid,
1980 struct obd_capa *oc, __u32 suppgid,
1981 struct ptlrpc_request **request)
1984 EXP_CHECK_MD_OP(exp, get_remote_perm);
1985 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1986 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1990 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1995 EXP_CHECK_MD_OP(exp, renew_capa);
1996 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1997 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2001 /* OBD Metadata Support */
2003 extern int obd_init_caches(void);
2004 extern void obd_cleanup_caches(void);
2006 /* support routines */
2007 extern cfs_mem_cache_t *obdo_cachep;
2009 #define OBDO_ALLOC(ptr) \
2011 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
2014 #define OBDO_FREE(ptr) \
2016 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2020 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2022 /* something here */
2025 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2027 /* something here */
2030 /* I'm as embarrassed about this as you are.
2032 * <shaver> // XXX do not look into _superhack with remaining eye
2033 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2034 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2037 extern void obd_sysctl_init (void);
2038 extern void obd_sysctl_clean (void);
2041 typedef __u8 class_uuid_t[16];
2042 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2045 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2046 int class_add_uuid(const char *uuid, __u64 nid);
2047 int class_del_uuid (const char *uuid);
2048 void class_init_uuidlist(void);
2049 void class_exit_uuidlist(void);
2052 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2053 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2056 void ll_generate_random_uuid(class_uuid_t uuid_out);
2058 #endif /* __LINUX_OBD_CLASS_H */