1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
40 # include <liblustre.h>
43 #include <obd_support.h>
44 #include <lustre_import.h>
45 #include <lustre_net.h>
47 #include <lustre_lib.h>
48 #include <lustre/lustre_idl.h>
49 #include <lprocfs_status.h>
51 #if defined(__linux__)
52 #include <linux/obd_class.h>
53 #elif defined(__APPLE__)
54 #include <darwin/obd_class.h>
55 #elif defined(__WINNT__)
56 #include <winnt/obd_class.h>
58 #error Unsupported operating system.
61 /* OBD Device Declarations */
62 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
63 extern spinlock_t obd_dev_lock;
65 /* OBD Operations Declarations */
66 extern struct obd_device *class_conn2obd(struct lustre_handle *);
67 extern struct obd_device *class_exp2obd(struct obd_export *);
69 struct lu_device_type;
72 struct obd_export *class_conn2export(struct lustre_handle *);
73 int class_register_type(struct obd_ops *, struct md_ops *,
74 struct lprocfs_vars *, const char *nm,
75 struct lu_device_type *ldt);
76 int class_unregister_type(const char *nm);
78 struct obd_device *class_newdev(const char *type_name, const char *name);
79 void class_release_dev(struct obd_device *obd);
81 int class_name2dev(const char *name);
82 struct obd_device *class_name2obd(const char *name);
83 int class_uuid2dev(struct obd_uuid *uuid);
84 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
85 void class_obd_list(void);
86 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
87 const char * typ_name,
88 struct obd_uuid *grp_uuid);
89 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
91 struct obd_device * class_num2obd(int num);
93 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
95 char *obd_export_nid2str(struct obd_export *exp);
97 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
98 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
100 int obd_zombie_impexp_init(void);
101 void obd_zombie_impexp_stop(void);
102 void obd_zombie_impexp_cull(void);
103 void obd_zombie_barrier(void);
104 void obd_exports_barrier(struct obd_device *obd);
107 int class_process_config(struct lustre_cfg *lcfg);
108 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
109 struct lustre_cfg *lcfg, void *data);
110 int class_attach(struct lustre_cfg *lcfg);
111 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
112 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
113 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
114 struct obd_device *class_incref(struct obd_device *obd,
115 const char *scope, const void *source);
116 void class_decref(struct obd_device *obd,
117 const char *scope, const void *source);
118 void dump_exports(struct obd_device *obd);
122 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
124 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
126 memset(lvars, 0, sizeof(*lvars));
130 #define CFG_F_START 0x01 /* Set when we start updating from a log */
131 #define CFG_F_MARKER 0x02 /* We are within a maker */
132 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
133 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
134 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
136 /* Passed as data param to class_config_parse_llog */
137 struct config_llog_instance {
140 struct super_block *cfg_sb;
141 struct obd_uuid cfg_uuid;
142 int cfg_last_idx; /* for partial llog processing */
145 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
146 struct config_llog_instance *cfg);
147 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
148 struct config_llog_instance *cfg);
150 /* list of active configuration logs */
151 struct config_llog_data {
153 struct ldlm_res_id cld_resid;
154 struct config_llog_instance cld_cfg;
155 struct list_head cld_list_chain;
156 atomic_t cld_refcount;
157 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
158 struct obd_export *cld_mgcexp;
159 unsigned int cld_stopping:1, /* we were told to stop watching */
160 cld_lostlock:1, /* lock not requeued */
164 struct lustre_profile {
165 struct list_head lp_list;
171 struct lustre_profile *class_get_profile(const char * prof);
172 void class_del_profile(const char *prof);
173 void class_del_profiles(void);
175 #define class_export_rpc_get(exp) \
177 atomic_inc(&(exp)->exp_rpc_count); \
178 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
179 (exp), atomic_read(&(exp)->exp_rpc_count)); \
180 class_export_get(exp); \
183 #define class_export_rpc_put(exp) \
185 atomic_dec(&(exp)->exp_rpc_count); \
186 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
187 (exp), atomic_read(&(exp)->exp_rpc_count)); \
188 class_export_put(exp); \
192 struct obd_export *class_export_get(struct obd_export *exp);
193 void class_export_put(struct obd_export *exp);
194 struct obd_export *class_new_export(struct obd_device *obddev,
195 struct obd_uuid *cluuid);
196 void class_unlink_export(struct obd_export *exp);
198 struct obd_import *class_import_get(struct obd_import *);
199 void class_import_put(struct obd_import *);
200 struct obd_import *class_new_import(struct obd_device *obd);
201 void class_destroy_import(struct obd_import *exp);
203 struct obd_type *class_search_type(const char *name);
204 struct obd_type *class_get_type(const char *name);
205 void class_put_type(struct obd_type *type);
206 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
207 struct obd_uuid *cluuid);
208 int class_disconnect(struct obd_export *exp);
209 void class_fail_export(struct obd_export *exp);
210 void class_disconnect_exports(struct obd_device *obddev);
211 int class_manual_cleanup(struct obd_device *obd);
212 void class_disconnect_stale_exports(struct obd_device *,
213 int (*test_export)(struct obd_export *),
214 enum obd_option flags);
216 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
218 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
219 (obd->obd_force ? OBD_OPT_FORCE : 0) |
220 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
224 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
225 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
226 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
227 unsigned int ia_valid);
228 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
229 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
230 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
233 #define OBT(dev) (dev)->obd_type
234 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
235 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
236 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
238 /* Ensure obd_setup: used for cleanup which must be called
239 while obd is stopping */
240 #define OBD_CHECK_DEV(obd) \
243 CERROR("NULL device\n"); \
248 /* ensure obd_setup and !obd_stopping */
249 #define OBD_CHECK_DEV_ACTIVE(obd) \
251 OBD_CHECK_DEV(obd); \
252 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
253 CERROR("Device %d not setup\n", \
261 #define OBD_COUNTER_OFFSET(op) \
262 ((offsetof(struct obd_ops, o_ ## op) - \
263 offsetof(struct obd_ops, o_iocontrol)) \
264 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
266 #define OBD_COUNTER_INCREMENT(obdx, op) \
267 if ((obdx)->obd_stats != NULL) { \
268 unsigned int coffset; \
269 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
270 OBD_COUNTER_OFFSET(op); \
271 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
272 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
275 #define EXP_COUNTER_INCREMENT(export, op) \
276 if ((export)->exp_obd->obd_stats != NULL) { \
277 unsigned int coffset; \
278 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
279 OBD_COUNTER_OFFSET(op); \
280 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
281 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
282 if ((export)->exp_nid_stats != NULL && \
283 (export)->exp_nid_stats->nid_stats != NULL) \
284 lprocfs_counter_incr( \
285 (export)->exp_nid_stats->nid_stats, coffset);\
288 #define MD_COUNTER_OFFSET(op) \
289 ((offsetof(struct md_ops, m_ ## op) - \
290 offsetof(struct md_ops, m_getstatus)) \
291 / sizeof(((struct md_ops *)(0))->m_getstatus))
293 #define MD_COUNTER_INCREMENT(obdx, op) \
294 if ((obd)->md_stats != NULL) { \
295 unsigned int coffset; \
296 coffset = (unsigned int)((obdx)->md_cntr_base) + \
297 MD_COUNTER_OFFSET(op); \
298 LASSERT(coffset < (obdx)->md_stats->ls_num); \
299 lprocfs_counter_incr((obdx)->md_stats, coffset); \
302 #define EXP_MD_COUNTER_INCREMENT(export, op) \
303 if ((export)->exp_obd->obd_stats != NULL) { \
304 unsigned int coffset; \
305 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
306 MD_COUNTER_OFFSET(op); \
307 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
308 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
309 if ((export)->exp_md_stats != NULL) \
310 lprocfs_counter_incr( \
311 (export)->exp_md_stats, coffset); \
315 #define OBD_COUNTER_OFFSET(op)
316 #define OBD_COUNTER_INCREMENT(obd, op)
317 #define EXP_COUNTER_INCREMENT(exp, op)
318 #define MD_COUNTER_INCREMENT(obd, op)
319 #define EXP_MD_COUNTER_INCREMENT(exp, op)
322 #define OBD_CHECK_MD_OP(obd, op, err) \
324 if (!OBT(obd) || !MDP((obd), op)) { \
326 CERROR("md_" #op ": dev %s/%d no operation\n", \
327 obd->obd_name, obd->obd_minor); \
332 #define EXP_CHECK_MD_OP(exp, op) \
334 if ((exp) == NULL) { \
335 CERROR("obd_" #op ": NULL export\n"); \
338 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
339 CERROR("obd_" #op ": cleaned up obd\n"); \
340 RETURN(-EOPNOTSUPP); \
342 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
343 CERROR("obd_" #op ": dev %s/%d no operation\n", \
344 (exp)->exp_obd->obd_name, \
345 (exp)->exp_obd->obd_minor); \
346 RETURN(-EOPNOTSUPP); \
351 #define OBD_CHECK_DT_OP(obd, op, err) \
353 if (!OBT(obd) || !OBP((obd), op)) { \
355 CERROR("obd_" #op ": dev %d no operation\n", \
361 #define EXP_CHECK_DT_OP(exp, op) \
363 if ((exp) == NULL) { \
364 CERROR("obd_" #op ": NULL export\n"); \
367 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
368 CERROR("obd_" #op ": cleaned up obd\n"); \
369 RETURN(-EOPNOTSUPP); \
371 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
372 CERROR("obd_" #op ": dev %d no operation\n", \
373 (exp)->exp_obd->obd_minor); \
374 RETURN(-EOPNOTSUPP); \
378 #define CTXT_CHECK_OP(ctxt, op, err) \
380 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
382 CERROR("lop_" #op ": dev %d no operation\n", \
383 ctxt->loc_obd->obd_minor); \
388 static inline int class_devno_max(void)
390 return MAX_OBD_DEVICES;
393 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
394 void *key, __u32 *vallen, void *val,
395 struct lov_stripe_md *lsm)
400 EXP_CHECK_DT_OP(exp, get_info);
401 EXP_COUNTER_INCREMENT(exp, get_info);
403 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
407 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
408 void *key, obd_count vallen, void *val,
409 struct ptlrpc_request_set *set)
414 EXP_CHECK_DT_OP(exp, set_info_async);
415 EXP_COUNTER_INCREMENT(exp, set_info_async);
417 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
423 * obd-lu integration.
425 * Functionality is being moved into new lu_device-based layering, but some
426 * pieces of configuration process are still based on obd devices.
428 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
429 * subsume ->o_setup() methods of obd devices they replace. The same for
430 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
431 * result, obd_setup() and obd_process_config() branch and call one XOR
434 * Yet neither lu_device_type_operations::ldto_device_fini() nor
435 * lu_device_type_operations::ldto_device_free() fully implement the
436 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
437 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
440 #define DECLARE_LU_VARS(ldt, d) \
441 struct lu_device_type *ldt; \
444 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
447 DECLARE_LU_VARS(ldt, d);
450 ldt = obd->obd_type->typ_lu;
452 struct lu_context session_ctx;
454 lu_context_init(&session_ctx, LCT_SESSION);
455 session_ctx.lc_thread = NULL;
456 lu_context_enter(&session_ctx);
458 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
460 env.le_ses = &session_ctx;
461 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
470 lu_context_exit(&session_ctx);
471 lu_context_fini(&session_ctx);
474 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
475 OBD_COUNTER_INCREMENT(obd, setup);
476 rc = OBP(obd, setup)(obd, cfg);
481 static inline int obd_precleanup(struct obd_device *obd,
482 enum obd_cleanup_stage cleanup_stage)
485 DECLARE_LU_VARS(ldt, d);
489 ldt = obd->obd_type->typ_lu;
491 if (ldt != NULL && d != NULL) {
492 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
495 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
497 ldt->ldt_ops->ldto_device_fini(&env, d);
502 OBD_CHECK_DT_OP(obd, precleanup, 0);
503 OBD_COUNTER_INCREMENT(obd, precleanup);
505 rc = OBP(obd, precleanup)(obd, cleanup_stage);
509 static inline int obd_cleanup(struct obd_device *obd)
512 DECLARE_LU_VARS(ldt, d);
517 ldt = obd->obd_type->typ_lu;
519 if (ldt != NULL && d != NULL) {
522 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
524 ldt->ldt_ops->ldto_device_free(&env, d);
526 obd->obd_lu_dev = NULL;
529 OBD_CHECK_DT_OP(obd, cleanup, 0);
530 OBD_COUNTER_INCREMENT(obd, cleanup);
532 rc = OBP(obd, cleanup)(obd);
537 obd_process_config(struct obd_device *obd, int datalen, void *data)
540 DECLARE_LU_VARS(ldt, d);
545 obd->obd_process_conf = 1;
546 ldt = obd->obd_type->typ_lu;
548 if (ldt != NULL && d != NULL) {
551 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
553 rc = d->ld_ops->ldo_process_config(&env, d, data);
557 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
558 rc = OBP(obd, process_config)(obd, datalen, data);
560 OBD_COUNTER_INCREMENT(obd, process_config);
561 obd->obd_process_conf = 0;
566 /* Pack an in-memory MD struct for storage on disk.
567 * Returns +ve size of packed MD (0 for free), or -ve error.
569 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
570 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
571 * If @*disk_tgt == NULL, it will be allocated
573 static inline int obd_packmd(struct obd_export *exp,
574 struct lov_mds_md **disk_tgt,
575 struct lov_stripe_md *mem_src)
580 EXP_CHECK_DT_OP(exp, packmd);
581 EXP_COUNTER_INCREMENT(exp, packmd);
583 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
587 static inline int obd_size_diskmd(struct obd_export *exp,
588 struct lov_stripe_md *mem_src)
590 return obd_packmd(exp, NULL, mem_src);
593 /* helper functions */
594 static inline int obd_alloc_diskmd(struct obd_export *exp,
595 struct lov_mds_md **disk_tgt)
598 LASSERT(*disk_tgt == NULL);
599 return obd_packmd(exp, disk_tgt, NULL);
602 static inline int obd_free_diskmd(struct obd_export *exp,
603 struct lov_mds_md **disk_tgt)
607 return obd_packmd(exp, disk_tgt, NULL);
610 /* Unpack an MD struct from disk to in-memory format.
611 * Returns +ve size of unpacked MD (0 for free), or -ve error.
613 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
614 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
615 * If @*mem_tgt == NULL, it will be allocated
617 static inline int obd_unpackmd(struct obd_export *exp,
618 struct lov_stripe_md **mem_tgt,
619 struct lov_mds_md *disk_src,
625 EXP_CHECK_DT_OP(exp, unpackmd);
626 EXP_COUNTER_INCREMENT(exp, unpackmd);
628 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
632 /* helper functions */
633 static inline int obd_alloc_memmd(struct obd_export *exp,
634 struct lov_stripe_md **mem_tgt)
637 LASSERT(*mem_tgt == NULL);
638 return obd_unpackmd(exp, mem_tgt, NULL, 0);
641 static inline int obd_free_memmd(struct obd_export *exp,
642 struct lov_stripe_md **mem_tgt)
648 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
653 static inline int obd_checkmd(struct obd_export *exp,
654 struct obd_export *md_exp,
655 struct lov_stripe_md *mem_tgt)
660 EXP_CHECK_DT_OP(exp, checkmd);
661 EXP_COUNTER_INCREMENT(exp, checkmd);
663 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
667 static inline int obd_precreate(struct obd_export *exp)
672 EXP_CHECK_DT_OP(exp, precreate);
673 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
675 rc = OBP(exp->exp_obd, precreate)(exp);
679 static inline int obd_create_async(struct obd_export *exp,
680 struct obd_info *oinfo,
681 struct lov_stripe_md **ea,
682 struct obd_trans_info *oti)
687 EXP_CHECK_DT_OP(exp, create_async);
688 EXP_COUNTER_INCREMENT(exp, create_async);
690 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
694 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
695 struct lov_stripe_md **ea,
696 struct obd_trans_info *oti)
701 EXP_CHECK_DT_OP(exp, create);
702 EXP_COUNTER_INCREMENT(exp, create);
704 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
708 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
709 struct lov_stripe_md *ea,
710 struct obd_trans_info *oti,
711 struct obd_export *md_exp, void *capa)
716 EXP_CHECK_DT_OP(exp, destroy);
717 EXP_COUNTER_INCREMENT(exp, destroy);
719 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
723 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
728 EXP_CHECK_DT_OP(exp, getattr);
729 EXP_COUNTER_INCREMENT(exp, getattr);
731 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
735 static inline int obd_getattr_async(struct obd_export *exp,
736 struct obd_info *oinfo,
737 struct ptlrpc_request_set *set)
742 EXP_CHECK_DT_OP(exp, getattr_async);
743 EXP_COUNTER_INCREMENT(exp, getattr_async);
745 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
749 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
750 struct obd_trans_info *oti)
755 EXP_CHECK_DT_OP(exp, setattr);
756 EXP_COUNTER_INCREMENT(exp, setattr);
758 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
762 /* This performs all the requests set init/wait/destroy actions. */
763 static inline int obd_setattr_rqset(struct obd_export *exp,
764 struct obd_info *oinfo,
765 struct obd_trans_info *oti)
767 struct ptlrpc_request_set *set = NULL;
771 EXP_CHECK_DT_OP(exp, setattr_async);
772 EXP_COUNTER_INCREMENT(exp, setattr_async);
774 set = ptlrpc_prep_set();
778 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
780 rc = ptlrpc_set_wait(set);
781 ptlrpc_set_destroy(set);
785 /* This adds all the requests into @set if @set != NULL, otherwise
786 all requests are sent asynchronously without waiting for response. */
787 static inline int obd_setattr_async(struct obd_export *exp,
788 struct obd_info *oinfo,
789 struct obd_trans_info *oti,
790 struct ptlrpc_request_set *set)
795 EXP_CHECK_DT_OP(exp, setattr_async);
796 EXP_COUNTER_INCREMENT(exp, setattr_async);
798 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
802 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
805 struct obd_device *obd = imp->imp_obd;
809 OBD_CHECK_DEV_ACTIVE(obd);
810 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
811 OBD_COUNTER_INCREMENT(obd, add_conn);
813 rc = OBP(obd, add_conn)(imp, uuid, priority);
817 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
819 struct obd_device *obd = imp->imp_obd;
823 OBD_CHECK_DEV_ACTIVE(obd);
824 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
825 OBD_COUNTER_INCREMENT(obd, del_conn);
827 rc = OBP(obd, del_conn)(imp, uuid);
831 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
833 struct obd_uuid *uuid;
836 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
837 EXP_COUNTER_INCREMENT(exp, get_uuid);
839 uuid = OBP(exp->exp_obd, get_uuid)(exp);
843 static inline int obd_connect(const struct lu_env *env,
844 struct obd_export **exp,struct obd_device *obd,
845 struct obd_uuid *cluuid,
846 struct obd_connect_data *d,
850 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
854 OBD_CHECK_DEV_ACTIVE(obd);
855 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
856 OBD_COUNTER_INCREMENT(obd, connect);
858 rc = OBP(obd, connect)(env, exp, obd, cluuid, d, localdata);
859 /* check that only subset is granted */
860 LASSERT(ergo(d != NULL,
861 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
865 static inline int obd_reconnect(const struct lu_env *env,
866 struct obd_export *exp,
867 struct obd_device *obd,
868 struct obd_uuid *cluuid,
869 struct obd_connect_data *d,
873 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
878 OBD_CHECK_DEV_ACTIVE(obd);
879 OBD_CHECK_DT_OP(obd, reconnect, 0);
880 OBD_COUNTER_INCREMENT(obd, reconnect);
882 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
883 /* check that only subset is granted */
884 LASSERT(ergo(d != NULL,
885 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
889 static inline int obd_disconnect(struct obd_export *exp)
894 EXP_CHECK_DT_OP(exp, disconnect);
895 EXP_COUNTER_INCREMENT(exp, disconnect);
897 rc = OBP(exp->exp_obd, disconnect)(exp);
901 static inline int obd_fid_init(struct obd_export *exp)
906 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
907 EXP_COUNTER_INCREMENT(exp, fid_init);
909 rc = OBP(exp->exp_obd, fid_init)(exp);
913 static inline int obd_fid_fini(struct obd_export *exp)
918 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
919 EXP_COUNTER_INCREMENT(exp, fid_fini);
921 rc = OBP(exp->exp_obd, fid_fini)(exp);
925 static inline int obd_fid_alloc(struct obd_export *exp,
927 struct md_op_data *op_data)
932 EXP_CHECK_DT_OP(exp, fid_alloc);
933 EXP_COUNTER_INCREMENT(exp, fid_alloc);
935 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
939 static inline int obd_fid_delete(struct obd_export *exp,
940 const struct lu_fid *fid)
945 EXP_CHECK_DT_OP(exp, fid_delete);
946 EXP_COUNTER_INCREMENT(exp, fid_delete);
948 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
952 static inline int obd_ping(struct obd_export *exp)
957 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
958 EXP_COUNTER_INCREMENT(exp, ping);
960 rc = OBP(exp->exp_obd, ping)(exp);
964 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
969 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
970 OBD_COUNTER_INCREMENT(obd, pool_new);
972 rc = OBP(obd, pool_new)(obd, poolname);
976 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
981 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
982 OBD_COUNTER_INCREMENT(obd, pool_del);
984 rc = OBP(obd, pool_del)(obd, poolname);
988 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
993 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
994 OBD_COUNTER_INCREMENT(obd, pool_add);
996 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1000 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1005 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1006 OBD_COUNTER_INCREMENT(obd, pool_rem);
1008 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1012 static inline void obd_getref(struct obd_device *obd)
1015 if (OBT(obd) && OBP(obd, getref)) {
1016 OBD_COUNTER_INCREMENT(obd, getref);
1017 OBP(obd, getref)(obd);
1022 static inline void obd_putref(struct obd_device *obd)
1025 if (OBT(obd) && OBP(obd, putref)) {
1026 OBD_COUNTER_INCREMENT(obd, putref);
1027 OBP(obd, putref)(obd);
1032 static inline int obd_init_export(struct obd_export *exp)
1037 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1038 OBP((exp)->exp_obd, init_export))
1039 rc = OBP(exp->exp_obd, init_export)(exp);
1043 static inline int obd_destroy_export(struct obd_export *exp)
1046 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1047 OBP((exp)->exp_obd, destroy_export))
1048 OBP(exp->exp_obd, destroy_export)(exp);
1052 static inline int obd_extent_calc(struct obd_export *exp,
1053 struct lov_stripe_md *md,
1054 int cmd, obd_off *offset)
1058 EXP_CHECK_DT_OP(exp, extent_calc);
1059 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1063 static inline struct dentry *
1064 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1066 LASSERT(exp->exp_obd);
1068 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1073 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1075 LASSERT(exp->exp_obd);
1076 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1078 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1079 dentry, exp->exp_obd);
1085 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
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_async(struct obd_device *obd,
1092 struct obd_info *oinfo,
1094 struct ptlrpc_request_set *rqset)
1102 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1103 OBD_COUNTER_INCREMENT(obd, statfs);
1105 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1106 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1107 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1108 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1110 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1111 " objects "LPU64"/"LPU64"\n",
1112 obd->obd_name, &obd->obd_osfs,
1113 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1114 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1115 spin_lock(&obd->obd_osfs_lock);
1116 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1117 spin_unlock(&obd->obd_osfs_lock);
1118 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1119 if (oinfo->oi_cb_up)
1120 oinfo->oi_cb_up(oinfo, 0);
1125 static inline int obd_statfs_rqset(struct obd_device *obd,
1126 struct obd_statfs *osfs, __u64 max_age,
1129 struct ptlrpc_request_set *set = NULL;
1130 struct obd_info oinfo = { { { 0 } } };
1134 set = ptlrpc_prep_set();
1138 oinfo.oi_osfs = osfs;
1139 oinfo.oi_flags = flags;
1140 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1142 rc = ptlrpc_set_wait(set);
1143 ptlrpc_set_destroy(set);
1147 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1148 * If the cache is older than @max_age we will get a new value from the
1149 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1150 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1151 __u64 max_age, __u32 flags)
1159 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1160 OBD_COUNTER_INCREMENT(obd, statfs);
1162 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1163 obd->obd_osfs_age, max_age);
1164 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1165 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1167 spin_lock(&obd->obd_osfs_lock);
1168 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1169 obd->obd_osfs_age = cfs_time_current_64();
1170 spin_unlock(&obd->obd_osfs_lock);
1173 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1174 " objects "LPU64"/"LPU64"\n",
1175 obd->obd_name, &obd->obd_osfs,
1176 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1177 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1178 spin_lock(&obd->obd_osfs_lock);
1179 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1180 spin_unlock(&obd->obd_osfs_lock);
1185 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1186 struct lov_stripe_md *ea, obd_size start,
1187 obd_size end, void *capa)
1192 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1193 EXP_COUNTER_INCREMENT(exp, sync);
1195 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1199 static inline int obd_punch_rqset(struct obd_export *exp,
1200 struct obd_info *oinfo,
1201 struct obd_trans_info *oti)
1203 struct ptlrpc_request_set *set = NULL;
1207 EXP_CHECK_DT_OP(exp, punch);
1208 EXP_COUNTER_INCREMENT(exp, punch);
1210 set = ptlrpc_prep_set();
1214 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1216 rc = ptlrpc_set_wait(set);
1217 ptlrpc_set_destroy(set);
1221 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1222 struct obd_trans_info *oti,
1223 struct ptlrpc_request_set *rqset)
1228 EXP_CHECK_DT_OP(exp, punch);
1229 EXP_COUNTER_INCREMENT(exp, punch);
1231 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1235 static inline int obd_brw(int cmd, struct obd_export *exp,
1236 struct obd_info *oinfo, obd_count oa_bufs,
1237 struct brw_page *pg, struct obd_trans_info *oti)
1242 EXP_CHECK_DT_OP(exp, brw);
1243 EXP_COUNTER_INCREMENT(exp, brw);
1245 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1246 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1247 "or OBD_BRW_CHECK\n");
1251 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1255 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1256 int objcount, struct obd_ioobj *obj,
1257 struct niobuf_remote *remote, int *pages,
1258 struct niobuf_local *local,
1259 struct obd_trans_info *oti,
1260 struct lustre_capa *capa)
1265 EXP_CHECK_DT_OP(exp, preprw);
1266 EXP_COUNTER_INCREMENT(exp, preprw);
1268 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1269 pages, local, oti, capa);
1273 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1274 int objcount, struct obd_ioobj *obj,
1275 struct niobuf_remote *rnb, int pages,
1276 struct niobuf_local *local,
1277 struct obd_trans_info *oti, int rc)
1281 EXP_CHECK_DT_OP(exp, commitrw);
1282 EXP_COUNTER_INCREMENT(exp, commitrw);
1284 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1285 rnb, pages, local, oti, rc);
1289 static inline int obd_merge_lvb(struct obd_export *exp,
1290 struct lov_stripe_md *lsm,
1291 struct ost_lvb *lvb, int kms_only)
1296 EXP_CHECK_DT_OP(exp, merge_lvb);
1297 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1299 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1303 static inline int obd_adjust_kms(struct obd_export *exp,
1304 struct lov_stripe_md *lsm, obd_off size,
1310 EXP_CHECK_DT_OP(exp, adjust_kms);
1311 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1313 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1317 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1318 int len, void *karg, void *uarg)
1323 EXP_CHECK_DT_OP(exp, iocontrol);
1324 EXP_COUNTER_INCREMENT(exp, iocontrol);
1326 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1330 static inline int obd_enqueue_rqset(struct obd_export *exp,
1331 struct obd_info *oinfo,
1332 struct ldlm_enqueue_info *einfo)
1334 struct ptlrpc_request_set *set = NULL;
1338 EXP_CHECK_DT_OP(exp, enqueue);
1339 EXP_COUNTER_INCREMENT(exp, enqueue);
1341 set = ptlrpc_prep_set();
1345 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1347 rc = ptlrpc_set_wait(set);
1348 ptlrpc_set_destroy(set);
1352 static inline int obd_enqueue(struct obd_export *exp,
1353 struct obd_info *oinfo,
1354 struct ldlm_enqueue_info *einfo,
1355 struct ptlrpc_request_set *set)
1360 EXP_CHECK_DT_OP(exp, enqueue);
1361 EXP_COUNTER_INCREMENT(exp, enqueue);
1363 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1367 static inline int obd_change_cbdata(struct obd_export *exp,
1368 struct lov_stripe_md *lsm,
1369 ldlm_iterator_t it, void *data)
1374 EXP_CHECK_DT_OP(exp, change_cbdata);
1375 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1377 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1381 static inline int obd_cancel(struct obd_export *exp,
1382 struct lov_stripe_md *ea, __u32 mode,
1383 struct lustre_handle *lockh)
1388 EXP_CHECK_DT_OP(exp, cancel);
1389 EXP_COUNTER_INCREMENT(exp, cancel);
1391 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1395 static inline int obd_cancel_unused(struct obd_export *exp,
1396 struct lov_stripe_md *ea,
1397 int flags, void *opaque)
1402 EXP_CHECK_DT_OP(exp, cancel_unused);
1403 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1405 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1409 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1410 struct obd_capa *oc, struct obd_client_handle *handle,
1416 EXP_CHECK_DT_OP(exp, pin);
1417 EXP_COUNTER_INCREMENT(exp, pin);
1419 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1423 static inline int obd_unpin(struct obd_export *exp,
1424 struct obd_client_handle *handle, int flag)
1429 EXP_CHECK_DT_OP(exp, unpin);
1430 EXP_COUNTER_INCREMENT(exp, unpin);
1432 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1437 static inline void obd_import_event(struct obd_device *obd,
1438 struct obd_import *imp,
1439 enum obd_import_event event)
1443 CERROR("NULL device\n");
1447 if (obd->obd_set_up && OBP(obd, import_event)) {
1448 OBD_COUNTER_INCREMENT(obd, import_event);
1449 OBP(obd, import_event)(obd, imp, event);
1454 static inline int obd_llog_connect(struct obd_export *exp,
1455 struct llogd_conn_body *body)
1460 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1461 EXP_COUNTER_INCREMENT(exp, llog_connect);
1463 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1468 static inline int obd_notify(struct obd_device *obd,
1469 struct obd_device *watched,
1470 enum obd_notify_event ev,
1477 /* the check for async_recov is a complete hack - I'm hereby
1478 overloading the meaning to also mean "this was called from
1479 mds_postsetup". I know that my mds is able to handle notifies
1480 by this point, and it needs to get them to execute mds_postrecov. */
1481 if (!obd->obd_set_up && !obd->obd_async_recov) {
1482 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1486 if (!OBP(obd, notify)) {
1487 CERROR("obd %s has no notify handler\n", obd->obd_name);
1491 OBD_COUNTER_INCREMENT(obd, notify);
1492 rc = OBP(obd, notify)(obd, watched, ev, data);
1496 static inline int obd_notify_observer(struct obd_device *observer,
1497 struct obd_device *observed,
1498 enum obd_notify_event ev,
1504 struct obd_notify_upcall *onu;
1506 if (observer->obd_observer)
1507 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1511 * Also, call non-obd listener, if any
1513 onu = &observer->obd_upcall;
1514 if (onu->onu_upcall != NULL)
1515 rc2 = onu->onu_upcall(observer, observed, ev,
1516 onu->onu_owner, NULL);
1520 return rc1 ? rc1 : rc2;
1523 static inline int obd_quotacheck(struct obd_export *exp,
1524 struct obd_quotactl *oqctl)
1529 EXP_CHECK_DT_OP(exp, quotacheck);
1530 EXP_COUNTER_INCREMENT(exp, quotacheck);
1532 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1536 static inline int obd_quotactl(struct obd_export *exp,
1537 struct obd_quotactl *oqctl)
1542 EXP_CHECK_DT_OP(exp, quotactl);
1543 EXP_COUNTER_INCREMENT(exp, quotactl);
1545 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1549 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1550 struct quota_adjust_qunit *oqaq,
1551 struct lustre_quota_ctxt *qctxt)
1553 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1554 struct timeval work_start;
1555 struct timeval work_end;
1561 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1563 do_gettimeofday(&work_start);
1565 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1566 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1568 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt);
1570 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1572 do_gettimeofday(&work_end);
1573 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1574 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1581 static inline int obd_health_check(struct obd_device *obd)
1583 /* returns: 0 on healthy
1584 * >0 on unhealthy + reason code/flag
1585 * however the only suppored reason == 1 right now
1586 * We'll need to define some better reasons
1587 * or flags in the future.
1593 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1594 if (obd == NULL || !OBT(obd)) {
1595 CERROR("cleaned up obd\n");
1596 RETURN(-EOPNOTSUPP);
1598 if (!obd->obd_set_up || obd->obd_stopping)
1600 if (!OBP(obd, health_check))
1603 rc = OBP(obd, health_check)(obd);
1607 static inline int obd_register_observer(struct obd_device *obd,
1608 struct obd_device *observer)
1612 if (obd->obd_observer && observer)
1614 obd->obd_observer = observer;
1619 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1620 obd_page_removal_cb_t cb,
1621 obd_pin_extent_cb pin_cb)
1626 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1627 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1629 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1633 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1634 obd_page_removal_cb_t cb)
1639 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1640 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1642 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1646 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1647 obd_lock_cancel_cb cb)
1652 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1653 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1655 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1659 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1660 obd_lock_cancel_cb cb)
1665 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1666 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1668 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1673 /* metadata helpers */
1674 static inline int md_getstatus(struct obd_export *exp,
1675 struct lu_fid *fid, struct obd_capa **pc)
1680 EXP_CHECK_MD_OP(exp, getstatus);
1681 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1682 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1686 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1687 struct obd_capa *oc, obd_valid valid, int ea_size,
1688 struct ptlrpc_request **request)
1692 EXP_CHECK_MD_OP(exp, getattr);
1693 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1694 rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1699 static inline int md_change_cbdata(struct obd_export *exp,
1700 const struct lu_fid *fid,
1701 ldlm_iterator_t it, void *data)
1705 EXP_CHECK_MD_OP(exp, change_cbdata);
1706 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1707 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1711 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1712 struct md_open_data *mod,
1713 struct ptlrpc_request **request)
1717 EXP_CHECK_MD_OP(exp, close);
1718 EXP_MD_COUNTER_INCREMENT(exp, close);
1719 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1723 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1724 const void *data, int datalen, int mode, __u32 uid,
1725 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1726 struct ptlrpc_request **request)
1730 EXP_CHECK_MD_OP(exp, create);
1731 EXP_MD_COUNTER_INCREMENT(exp, create);
1732 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1733 uid, gid, cap_effective, rdev, request);
1737 static inline int md_done_writing(struct obd_export *exp,
1738 struct md_op_data *op_data,
1739 struct md_open_data *mod)
1743 EXP_CHECK_MD_OP(exp, done_writing);
1744 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1745 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1749 static inline int md_enqueue(struct obd_export *exp,
1750 struct ldlm_enqueue_info *einfo,
1751 struct lookup_intent *it,
1752 struct md_op_data *op_data,
1753 struct lustre_handle *lockh,
1754 void *lmm, int lmmsize,
1755 struct ptlrpc_request **req,
1756 int extra_lock_flags)
1760 EXP_CHECK_MD_OP(exp, enqueue);
1761 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1762 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1763 lmm, lmmsize, req, extra_lock_flags);
1767 static inline int md_getattr_name(struct obd_export *exp,
1768 const struct lu_fid *fid, struct obd_capa *oc,
1769 const char *name, int namelen,
1770 obd_valid valid, int ea_size, __u32 suppgid,
1771 struct ptlrpc_request **request)
1775 EXP_CHECK_MD_OP(exp, getattr_name);
1776 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1777 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1778 valid, ea_size, suppgid, request);
1782 static inline int md_intent_lock(struct obd_export *exp,
1783 struct md_op_data *op_data, void *lmm,
1784 int lmmsize, struct lookup_intent *it,
1785 int flags, struct ptlrpc_request **reqp,
1786 ldlm_blocking_callback cb_blocking,
1787 int extra_lock_flags)
1791 EXP_CHECK_MD_OP(exp, intent_lock);
1792 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1793 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1794 it, flags, reqp, cb_blocking,
1799 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1800 struct ptlrpc_request **request)
1804 EXP_CHECK_MD_OP(exp, link);
1805 EXP_MD_COUNTER_INCREMENT(exp, link);
1806 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1810 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1811 const char *old, int oldlen, const char *new,
1812 int newlen, struct ptlrpc_request **request)
1816 EXP_CHECK_MD_OP(exp, rename);
1817 EXP_MD_COUNTER_INCREMENT(exp, rename);
1818 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1823 static inline int md_is_subdir(struct obd_export *exp,
1824 const struct lu_fid *pfid,
1825 const struct lu_fid *cfid,
1826 struct ptlrpc_request **request)
1830 EXP_CHECK_MD_OP(exp, is_subdir);
1831 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1832 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1836 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1837 void *ea, int ealen, void *ea2, int ea2len,
1838 struct ptlrpc_request **request,
1839 struct md_open_data **mod)
1843 EXP_CHECK_MD_OP(exp, setattr);
1844 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1845 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1846 ea2, ea2len, request, mod);
1850 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1851 struct obd_capa *oc, struct ptlrpc_request **request)
1855 EXP_CHECK_MD_OP(exp, sync);
1856 EXP_MD_COUNTER_INCREMENT(exp, sync);
1857 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1861 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1862 struct obd_capa *oc, __u64 offset,
1864 struct ptlrpc_request **request)
1868 EXP_CHECK_MD_OP(exp, readpage);
1869 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1870 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1874 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1875 struct ptlrpc_request **request)
1879 EXP_CHECK_MD_OP(exp, unlink);
1880 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1881 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1885 static inline int md_get_lustre_md(struct obd_export *exp,
1886 struct ptlrpc_request *req,
1887 struct obd_export *dt_exp,
1888 struct obd_export *md_exp,
1889 struct lustre_md *md)
1892 EXP_CHECK_MD_OP(exp, get_lustre_md);
1893 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1894 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1897 static inline int md_free_lustre_md(struct obd_export *exp,
1898 struct lustre_md *md)
1901 EXP_CHECK_MD_OP(exp, free_lustre_md);
1902 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1903 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1906 static inline int md_setxattr(struct obd_export *exp,
1907 const struct lu_fid *fid, struct obd_capa *oc,
1908 obd_valid valid, const char *name,
1909 const char *input, int input_size,
1910 int output_size, int flags, __u32 suppgid,
1911 struct ptlrpc_request **request)
1914 EXP_CHECK_MD_OP(exp, setxattr);
1915 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1916 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1917 input_size, output_size, flags,
1921 static inline int md_getxattr(struct obd_export *exp,
1922 const struct lu_fid *fid, struct obd_capa *oc,
1923 obd_valid valid, const char *name,
1924 const char *input, int input_size,
1925 int output_size, int flags,
1926 struct ptlrpc_request **request)
1929 EXP_CHECK_MD_OP(exp, getxattr);
1930 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1931 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1932 input_size, output_size, flags,
1936 static inline int md_set_open_replay_data(struct obd_export *exp,
1937 struct obd_client_handle *och,
1938 struct ptlrpc_request *open_req)
1941 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1942 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1943 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1946 static inline int md_clear_open_replay_data(struct obd_export *exp,
1947 struct obd_client_handle *och)
1950 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1951 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1952 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1955 static inline int md_set_lock_data(struct obd_export *exp,
1956 __u64 *lockh, void *data, __u32 *bits)
1959 EXP_CHECK_MD_OP(exp, set_lock_data);
1960 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1961 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1964 static inline int md_cancel_unused(struct obd_export *exp,
1965 const struct lu_fid *fid,
1966 ldlm_policy_data_t *policy,
1967 ldlm_mode_t mode, int flags, void *opaque)
1972 EXP_CHECK_MD_OP(exp, cancel_unused);
1973 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1975 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1980 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
1981 const struct lu_fid *fid,
1983 ldlm_policy_data_t *policy,
1985 struct lustre_handle *lockh)
1988 EXP_CHECK_MD_OP(exp, lock_match);
1989 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1990 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1991 policy, mode, lockh));
1994 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1995 int def_asize, int cookiesize)
1998 EXP_CHECK_MD_OP(exp, init_ea_size);
1999 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2000 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2004 static inline int md_get_remote_perm(struct obd_export *exp,
2005 const struct lu_fid *fid,
2006 struct obd_capa *oc, __u32 suppgid,
2007 struct ptlrpc_request **request)
2010 EXP_CHECK_MD_OP(exp, get_remote_perm);
2011 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2012 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2016 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2021 EXP_CHECK_MD_OP(exp, renew_capa);
2022 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2023 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2027 static inline int md_unpack_capa(struct obd_export *exp,
2028 struct ptlrpc_request *req,
2029 const struct req_msg_field *field,
2030 struct obd_capa **oc)
2034 EXP_CHECK_MD_OP(exp, unpack_capa);
2035 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2036 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2040 static inline int md_intent_getattr_async(struct obd_export *exp,
2041 struct md_enqueue_info *minfo,
2042 struct ldlm_enqueue_info *einfo)
2046 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2047 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2048 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2052 static inline int md_revalidate_lock(struct obd_export *exp,
2053 struct lookup_intent *it,
2058 EXP_CHECK_MD_OP(exp, revalidate_lock);
2059 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2060 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2065 /* OBD Metadata Support */
2067 extern int obd_init_caches(void);
2068 extern void obd_cleanup_caches(void);
2070 /* support routines */
2071 extern cfs_mem_cache_t *obdo_cachep;
2073 #define OBDO_ALLOC(ptr) \
2075 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
2078 #define OBDO_FREE(ptr) \
2080 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2084 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2086 /* something here */
2089 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2091 /* something here */
2094 /* I'm as embarrassed about this as you are.
2096 * <shaver> // XXX do not look into _superhack with remaining eye
2097 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2098 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2101 extern void obd_sysctl_init (void);
2102 extern void obd_sysctl_clean (void);
2105 typedef __u8 class_uuid_t[16];
2106 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2109 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2110 int class_add_uuid(const char *uuid, __u64 nid);
2111 int class_del_uuid (const char *uuid);
2112 void class_init_uuidlist(void);
2113 void class_exit_uuidlist(void);
2116 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2117 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2120 void ll_generate_random_uuid(class_uuid_t uuid_out);
2122 #endif /* __LINUX_OBD_CLASS_H */