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);
106 int class_process_config(struct lustre_cfg *lcfg);
107 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
108 struct lustre_cfg *lcfg, void *data);
109 int class_attach(struct lustre_cfg *lcfg);
110 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
111 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
112 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
113 struct obd_device *class_incref(struct obd_device *obd,
114 const char *scope, const void *source);
115 void class_decref(struct obd_device *obd,
116 const char *scope, const void *source);
120 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
122 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
124 memset(lvars, 0, sizeof(*lvars));
128 #define CFG_F_START 0x01 /* Set when we start updating from a log */
129 #define CFG_F_MARKER 0x02 /* We are within a maker */
130 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
131 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
132 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
134 /* Passed as data param to class_config_parse_llog */
135 struct config_llog_instance {
138 struct super_block *cfg_sb;
139 struct obd_uuid cfg_uuid;
140 int cfg_last_idx; /* for partial llog processing */
143 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
144 struct config_llog_instance *cfg);
145 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
146 struct config_llog_instance *cfg);
148 /* list of active configuration logs */
149 struct config_llog_data {
151 struct ldlm_res_id cld_resid;
152 struct config_llog_instance cld_cfg;
153 struct list_head cld_list_chain;
154 atomic_t cld_refcount;
155 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
156 struct obd_export *cld_mgcexp;
157 unsigned int cld_stopping:1, /* we were told to stop watching */
158 cld_lostlock:1, /* lock not requeued */
162 struct lustre_profile {
163 struct list_head lp_list;
169 struct lustre_profile *class_get_profile(const char * prof);
170 void class_del_profile(const char *prof);
171 void class_del_profiles(void);
173 #define class_export_rpc_get(exp) \
175 atomic_inc(&(exp)->exp_rpc_count); \
176 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
177 (exp), atomic_read(&(exp)->exp_rpc_count)); \
178 class_export_get(exp); \
181 #define class_export_rpc_put(exp) \
183 atomic_dec(&(exp)->exp_rpc_count); \
184 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
185 (exp), atomic_read(&(exp)->exp_rpc_count)); \
186 class_export_put(exp); \
190 struct obd_export *class_export_get(struct obd_export *exp);
191 void class_export_put(struct obd_export *exp);
192 struct obd_export *class_new_export(struct obd_device *obddev,
193 struct obd_uuid *cluuid);
194 void class_unlink_export(struct obd_export *exp);
196 struct obd_import *class_import_get(struct obd_import *);
197 void class_import_put(struct obd_import *);
198 struct obd_import *class_new_import(struct obd_device *obd);
199 void class_destroy_import(struct obd_import *exp);
201 struct obd_type *class_search_type(const char *name);
202 struct obd_type *class_get_type(const char *name);
203 void class_put_type(struct obd_type *type);
204 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
205 struct obd_uuid *cluuid);
206 int class_disconnect(struct obd_export *exp);
207 void class_fail_export(struct obd_export *exp);
208 void class_disconnect_exports(struct obd_device *obddev);
209 int class_disconnect_stale_exports(struct obd_device *,
210 int (*test_export)(struct obd_export *));
211 int class_manual_cleanup(struct obd_device *obd);
213 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
214 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
215 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
216 unsigned int ia_valid);
217 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
218 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
219 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
222 #define OBT(dev) (dev)->obd_type
223 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
224 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
225 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
227 /* Ensure obd_setup: used for cleanup which must be called
228 while obd is stopping */
229 #define OBD_CHECK_DEV(obd) \
232 CERROR("NULL device\n"); \
237 /* ensure obd_setup and !obd_stopping */
238 #define OBD_CHECK_DEV_ACTIVE(obd) \
240 OBD_CHECK_DEV(obd); \
241 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
242 CERROR("Device %d not setup\n", \
250 #define OBD_COUNTER_OFFSET(op) \
251 ((offsetof(struct obd_ops, o_ ## op) - \
252 offsetof(struct obd_ops, o_iocontrol)) \
253 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
255 #define OBD_COUNTER_INCREMENT(obdx, op) \
256 if ((obdx)->obd_stats != NULL) { \
257 unsigned int coffset; \
258 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
259 OBD_COUNTER_OFFSET(op); \
260 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
261 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
264 #define EXP_COUNTER_INCREMENT(export, op) \
265 if ((export)->exp_obd->obd_stats != NULL) { \
266 unsigned int coffset; \
267 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
268 OBD_COUNTER_OFFSET(op); \
269 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
270 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
271 if ((export)->exp_nid_stats != NULL && \
272 (export)->exp_nid_stats->nid_stats != NULL) \
273 lprocfs_counter_incr( \
274 (export)->exp_nid_stats->nid_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,
384 struct lov_stripe_md *lsm)
389 EXP_CHECK_DT_OP(exp, get_info);
390 EXP_COUNTER_INCREMENT(exp, get_info);
392 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
396 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
397 void *key, obd_count vallen, void *val,
398 struct ptlrpc_request_set *set)
403 EXP_CHECK_DT_OP(exp, set_info_async);
404 EXP_COUNTER_INCREMENT(exp, set_info_async);
406 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
412 * obd-lu integration.
414 * Functionality is being moved into new lu_device-based layering, but some
415 * pieces of configuration process are still based on obd devices.
417 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
418 * subsume ->o_setup() methods of obd devices they replace. The same for
419 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
420 * result, obd_setup() and obd_process_config() branch and call one XOR
423 * Yet neither lu_device_type_operations::ldto_device_fini() nor
424 * lu_device_type_operations::ldto_device_free() fully implement the
425 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
426 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
429 #define DECLARE_LU_VARS(ldt, d) \
430 struct lu_device_type *ldt; \
433 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
436 DECLARE_LU_VARS(ldt, d);
439 ldt = obd->obd_type->typ_lu;
441 struct lu_context session_ctx;
443 lu_context_init(&session_ctx, LCT_SESSION);
444 session_ctx.lc_thread = NULL;
445 lu_context_enter(&session_ctx);
447 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
449 env.le_ses = &session_ctx;
450 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
459 lu_context_exit(&session_ctx);
460 lu_context_fini(&session_ctx);
463 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
464 OBD_COUNTER_INCREMENT(obd, setup);
465 rc = OBP(obd, setup)(obd, cfg);
470 static inline int obd_precleanup(struct obd_device *obd,
471 enum obd_cleanup_stage cleanup_stage)
474 DECLARE_LU_VARS(ldt, d);
478 ldt = obd->obd_type->typ_lu;
480 if (ldt != NULL && d != NULL) {
481 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
484 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
486 ldt->ldt_ops->ldto_device_fini(&env, d);
491 OBD_CHECK_DT_OP(obd, precleanup, 0);
492 OBD_COUNTER_INCREMENT(obd, precleanup);
494 rc = OBP(obd, precleanup)(obd, cleanup_stage);
498 static inline int obd_cleanup(struct obd_device *obd)
501 DECLARE_LU_VARS(ldt, d);
506 ldt = obd->obd_type->typ_lu;
508 if (ldt != NULL && d != NULL) {
511 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
513 ldt->ldt_ops->ldto_device_free(&env, d);
515 obd->obd_lu_dev = NULL;
518 OBD_CHECK_DT_OP(obd, cleanup, 0);
519 OBD_COUNTER_INCREMENT(obd, cleanup);
521 rc = OBP(obd, cleanup)(obd);
526 obd_process_config(struct obd_device *obd, int datalen, void *data)
529 DECLARE_LU_VARS(ldt, d);
534 ldt = obd->obd_type->typ_lu;
536 if (ldt != NULL && d != NULL) {
539 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
541 rc = d->ld_ops->ldo_process_config(&env, d, data);
545 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
546 rc = OBP(obd, process_config)(obd, datalen, data);
548 OBD_COUNTER_INCREMENT(obd, process_config);
553 /* Pack an in-memory MD struct for storage on disk.
554 * Returns +ve size of packed MD (0 for free), or -ve error.
556 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
557 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
558 * If @*disk_tgt == NULL, it will be allocated
560 static inline int obd_packmd(struct obd_export *exp,
561 struct lov_mds_md **disk_tgt,
562 struct lov_stripe_md *mem_src)
567 EXP_CHECK_DT_OP(exp, packmd);
568 EXP_COUNTER_INCREMENT(exp, packmd);
570 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
574 static inline int obd_size_diskmd(struct obd_export *exp,
575 struct lov_stripe_md *mem_src)
577 return obd_packmd(exp, NULL, mem_src);
580 /* helper functions */
581 static inline int obd_alloc_diskmd(struct obd_export *exp,
582 struct lov_mds_md **disk_tgt)
585 LASSERT(*disk_tgt == NULL);
586 return obd_packmd(exp, disk_tgt, NULL);
589 static inline int obd_free_diskmd(struct obd_export *exp,
590 struct lov_mds_md **disk_tgt)
594 return obd_packmd(exp, disk_tgt, NULL);
597 /* Unpack an MD struct from disk to in-memory format.
598 * Returns +ve size of unpacked MD (0 for free), or -ve error.
600 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
601 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
602 * If @*mem_tgt == NULL, it will be allocated
604 static inline int obd_unpackmd(struct obd_export *exp,
605 struct lov_stripe_md **mem_tgt,
606 struct lov_mds_md *disk_src,
612 EXP_CHECK_DT_OP(exp, unpackmd);
613 EXP_COUNTER_INCREMENT(exp, unpackmd);
615 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
619 /* helper functions */
620 static inline int obd_alloc_memmd(struct obd_export *exp,
621 struct lov_stripe_md **mem_tgt)
624 LASSERT(*mem_tgt == NULL);
625 return obd_unpackmd(exp, mem_tgt, NULL, 0);
628 static inline int obd_free_memmd(struct obd_export *exp,
629 struct lov_stripe_md **mem_tgt)
635 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
640 static inline int obd_checkmd(struct obd_export *exp,
641 struct obd_export *md_exp,
642 struct lov_stripe_md *mem_tgt)
647 EXP_CHECK_DT_OP(exp, checkmd);
648 EXP_COUNTER_INCREMENT(exp, checkmd);
650 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
654 static inline int obd_precreate(struct obd_export *exp)
659 EXP_CHECK_DT_OP(exp, precreate);
660 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
662 rc = OBP(exp->exp_obd, precreate)(exp);
666 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
667 struct lov_stripe_md **ea,
668 struct obd_trans_info *oti)
673 EXP_CHECK_DT_OP(exp, create);
674 EXP_COUNTER_INCREMENT(exp, create);
676 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
680 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
681 struct lov_stripe_md *ea,
682 struct obd_trans_info *oti,
683 struct obd_export *md_exp, void *capa)
688 EXP_CHECK_DT_OP(exp, destroy);
689 EXP_COUNTER_INCREMENT(exp, destroy);
691 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
695 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
700 EXP_CHECK_DT_OP(exp, getattr);
701 EXP_COUNTER_INCREMENT(exp, getattr);
703 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
707 static inline int obd_getattr_async(struct obd_export *exp,
708 struct obd_info *oinfo,
709 struct ptlrpc_request_set *set)
714 EXP_CHECK_DT_OP(exp, getattr_async);
715 EXP_COUNTER_INCREMENT(exp, getattr_async);
717 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
721 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
722 struct obd_trans_info *oti)
727 EXP_CHECK_DT_OP(exp, setattr);
728 EXP_COUNTER_INCREMENT(exp, setattr);
730 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
734 /* This performs all the requests set init/wait/destroy actions. */
735 static inline int obd_setattr_rqset(struct obd_export *exp,
736 struct obd_info *oinfo,
737 struct obd_trans_info *oti)
739 struct ptlrpc_request_set *set = NULL;
743 EXP_CHECK_DT_OP(exp, setattr_async);
744 EXP_COUNTER_INCREMENT(exp, setattr_async);
746 set = ptlrpc_prep_set();
750 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
752 rc = ptlrpc_set_wait(set);
753 ptlrpc_set_destroy(set);
757 /* This adds all the requests into @set if @set != NULL, otherwise
758 all requests are sent asynchronously without waiting for response. */
759 static inline int obd_setattr_async(struct obd_export *exp,
760 struct obd_info *oinfo,
761 struct obd_trans_info *oti,
762 struct ptlrpc_request_set *set)
767 EXP_CHECK_DT_OP(exp, setattr_async);
768 EXP_COUNTER_INCREMENT(exp, setattr_async);
770 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
774 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
777 struct obd_device *obd = imp->imp_obd;
781 OBD_CHECK_DEV_ACTIVE(obd);
782 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
783 OBD_COUNTER_INCREMENT(obd, add_conn);
785 rc = OBP(obd, add_conn)(imp, uuid, priority);
789 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
791 struct obd_device *obd = imp->imp_obd;
795 OBD_CHECK_DEV_ACTIVE(obd);
796 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
797 OBD_COUNTER_INCREMENT(obd, del_conn);
799 rc = OBP(obd, del_conn)(imp, uuid);
803 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
805 struct obd_uuid *uuid;
808 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
809 EXP_COUNTER_INCREMENT(exp, get_uuid);
811 uuid = OBP(exp->exp_obd, get_uuid)(exp);
815 static inline int obd_connect(const struct lu_env *env,
816 struct lustre_handle *conn,struct obd_device *obd,
817 struct obd_uuid *cluuid,
818 struct obd_connect_data *d,
822 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
826 OBD_CHECK_DEV_ACTIVE(obd);
827 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
828 OBD_COUNTER_INCREMENT(obd, connect);
830 rc = OBP(obd, connect)(env, conn, obd, cluuid, d, localdata);
831 /* check that only subset is granted */
832 LASSERT(ergo(d != NULL,
833 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
837 static inline int obd_reconnect(const struct lu_env *env,
838 struct obd_export *exp,
839 struct obd_device *obd,
840 struct obd_uuid *cluuid,
841 struct obd_connect_data *d,
845 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
850 OBD_CHECK_DEV_ACTIVE(obd);
851 OBD_CHECK_DT_OP(obd, reconnect, 0);
852 OBD_COUNTER_INCREMENT(obd, reconnect);
854 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
855 /* check that only subset is granted */
856 LASSERT(ergo(d != NULL,
857 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
861 static inline int obd_disconnect(struct obd_export *exp)
866 EXP_CHECK_DT_OP(exp, disconnect);
867 EXP_COUNTER_INCREMENT(exp, disconnect);
869 rc = OBP(exp->exp_obd, disconnect)(exp);
873 static inline int obd_fid_init(struct obd_export *exp)
878 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
879 EXP_COUNTER_INCREMENT(exp, fid_init);
881 rc = OBP(exp->exp_obd, fid_init)(exp);
885 static inline int obd_fid_fini(struct obd_export *exp)
890 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
891 EXP_COUNTER_INCREMENT(exp, fid_fini);
893 rc = OBP(exp->exp_obd, fid_fini)(exp);
897 static inline int obd_fid_alloc(struct obd_export *exp,
899 struct md_op_data *op_data)
904 EXP_CHECK_DT_OP(exp, fid_alloc);
905 EXP_COUNTER_INCREMENT(exp, fid_alloc);
907 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
911 static inline int obd_fid_delete(struct obd_export *exp,
912 const struct lu_fid *fid)
917 EXP_CHECK_DT_OP(exp, fid_delete);
918 EXP_COUNTER_INCREMENT(exp, fid_delete);
920 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
924 static inline int obd_ping(struct obd_export *exp)
929 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
930 EXP_COUNTER_INCREMENT(exp, ping);
932 rc = OBP(exp->exp_obd, ping)(exp);
936 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
941 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
942 OBD_COUNTER_INCREMENT(obd, pool_new);
944 rc = OBP(obd, pool_new)(obd, poolname);
948 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
953 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
954 OBD_COUNTER_INCREMENT(obd, pool_del);
956 rc = OBP(obd, pool_del)(obd, poolname);
960 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
965 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
966 OBD_COUNTER_INCREMENT(obd, pool_add);
968 rc = OBP(obd, pool_add)(obd, poolname, ostname);
972 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
977 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
978 OBD_COUNTER_INCREMENT(obd, pool_rem);
980 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
984 static inline int obd_init_export(struct obd_export *exp)
989 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
990 OBP((exp)->exp_obd, init_export))
991 rc = OBP(exp->exp_obd, init_export)(exp);
995 static inline int obd_destroy_export(struct obd_export *exp)
998 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
999 OBP((exp)->exp_obd, destroy_export))
1000 OBP(exp->exp_obd, destroy_export)(exp);
1004 static inline int obd_extent_calc(struct obd_export *exp,
1005 struct lov_stripe_md *md,
1006 int cmd, obd_off *offset)
1010 EXP_CHECK_DT_OP(exp, extent_calc);
1011 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1015 static inline struct dentry *
1016 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1018 LASSERT(exp->exp_obd);
1020 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1025 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1027 LASSERT(exp->exp_obd);
1028 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1030 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1031 dentry, exp->exp_obd);
1037 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
1040 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1041 * If the cache is older than @max_age we will get a new value from the
1042 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1043 static inline int obd_statfs_async(struct obd_device *obd,
1044 struct obd_info *oinfo,
1046 struct ptlrpc_request_set *rqset)
1054 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1055 OBD_COUNTER_INCREMENT(obd, statfs);
1057 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1058 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1059 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1060 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1062 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1063 " objects "LPU64"/"LPU64"\n",
1064 obd->obd_name, &obd->obd_osfs,
1065 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1066 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1067 spin_lock(&obd->obd_osfs_lock);
1068 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1069 spin_unlock(&obd->obd_osfs_lock);
1070 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1071 if (oinfo->oi_cb_up)
1072 oinfo->oi_cb_up(oinfo, 0);
1077 static inline int obd_statfs_rqset(struct obd_device *obd,
1078 struct obd_statfs *osfs, __u64 max_age,
1081 struct ptlrpc_request_set *set = NULL;
1082 struct obd_info oinfo = { { { 0 } } };
1086 set = ptlrpc_prep_set();
1090 oinfo.oi_osfs = osfs;
1091 oinfo.oi_flags = flags;
1092 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1094 rc = ptlrpc_set_wait(set);
1095 ptlrpc_set_destroy(set);
1099 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1100 * If the cache is older than @max_age we will get a new value from the
1101 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1102 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1103 __u64 max_age, __u32 flags)
1111 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1112 OBD_COUNTER_INCREMENT(obd, statfs);
1114 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1115 obd->obd_osfs_age, max_age);
1116 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1117 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1119 spin_lock(&obd->obd_osfs_lock);
1120 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1121 obd->obd_osfs_age = cfs_time_current_64();
1122 spin_unlock(&obd->obd_osfs_lock);
1125 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1126 " objects "LPU64"/"LPU64"\n",
1127 obd->obd_name, &obd->obd_osfs,
1128 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1129 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1130 spin_lock(&obd->obd_osfs_lock);
1131 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1132 spin_unlock(&obd->obd_osfs_lock);
1137 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1138 struct lov_stripe_md *ea, obd_size start,
1139 obd_size end, void *capa)
1144 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1145 EXP_COUNTER_INCREMENT(exp, sync);
1147 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1151 static inline int obd_punch_rqset(struct obd_export *exp,
1152 struct obd_info *oinfo,
1153 struct obd_trans_info *oti)
1155 struct ptlrpc_request_set *set = NULL;
1159 EXP_CHECK_DT_OP(exp, punch);
1160 EXP_COUNTER_INCREMENT(exp, punch);
1162 set = ptlrpc_prep_set();
1166 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1168 rc = ptlrpc_set_wait(set);
1169 ptlrpc_set_destroy(set);
1173 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1174 struct obd_trans_info *oti,
1175 struct ptlrpc_request_set *rqset)
1180 EXP_CHECK_DT_OP(exp, punch);
1181 EXP_COUNTER_INCREMENT(exp, punch);
1183 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1187 static inline int obd_brw(int cmd, struct obd_export *exp,
1188 struct obd_info *oinfo, obd_count oa_bufs,
1189 struct brw_page *pg, struct obd_trans_info *oti)
1194 EXP_CHECK_DT_OP(exp, brw);
1195 EXP_COUNTER_INCREMENT(exp, brw);
1197 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1198 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1199 "or OBD_BRW_CHECK\n");
1203 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1207 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1208 int objcount, struct obd_ioobj *obj,
1209 struct niobuf_remote *remote, int *pages,
1210 struct niobuf_local *local,
1211 struct obd_trans_info *oti,
1212 struct lustre_capa *capa)
1217 EXP_CHECK_DT_OP(exp, preprw);
1218 EXP_COUNTER_INCREMENT(exp, preprw);
1220 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1221 pages, local, oti, capa);
1225 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1226 int objcount, struct obd_ioobj *obj,
1227 struct niobuf_remote *rnb, int pages,
1228 struct niobuf_local *local,
1229 struct obd_trans_info *oti, int rc)
1233 EXP_CHECK_DT_OP(exp, commitrw);
1234 EXP_COUNTER_INCREMENT(exp, commitrw);
1236 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1237 rnb, pages, local, oti, rc);
1241 static inline int obd_merge_lvb(struct obd_export *exp,
1242 struct lov_stripe_md *lsm,
1243 struct ost_lvb *lvb, int kms_only)
1248 EXP_CHECK_DT_OP(exp, merge_lvb);
1249 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1251 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1255 static inline int obd_adjust_kms(struct obd_export *exp,
1256 struct lov_stripe_md *lsm, obd_off size,
1262 EXP_CHECK_DT_OP(exp, adjust_kms);
1263 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1265 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1269 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1270 int len, void *karg, void *uarg)
1275 EXP_CHECK_DT_OP(exp, iocontrol);
1276 EXP_COUNTER_INCREMENT(exp, iocontrol);
1278 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1282 static inline int obd_enqueue_rqset(struct obd_export *exp,
1283 struct obd_info *oinfo,
1284 struct ldlm_enqueue_info *einfo)
1286 struct ptlrpc_request_set *set = NULL;
1290 EXP_CHECK_DT_OP(exp, enqueue);
1291 EXP_COUNTER_INCREMENT(exp, enqueue);
1293 set = ptlrpc_prep_set();
1297 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1299 rc = ptlrpc_set_wait(set);
1300 ptlrpc_set_destroy(set);
1304 static inline int obd_enqueue(struct obd_export *exp,
1305 struct obd_info *oinfo,
1306 struct ldlm_enqueue_info *einfo,
1307 struct ptlrpc_request_set *set)
1312 EXP_CHECK_DT_OP(exp, enqueue);
1313 EXP_COUNTER_INCREMENT(exp, enqueue);
1315 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1319 static inline int obd_change_cbdata(struct obd_export *exp,
1320 struct lov_stripe_md *lsm,
1321 ldlm_iterator_t it, void *data)
1326 EXP_CHECK_DT_OP(exp, change_cbdata);
1327 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1329 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1333 static inline int obd_cancel(struct obd_export *exp,
1334 struct lov_stripe_md *ea, __u32 mode,
1335 struct lustre_handle *lockh)
1340 EXP_CHECK_DT_OP(exp, cancel);
1341 EXP_COUNTER_INCREMENT(exp, cancel);
1343 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1347 static inline int obd_cancel_unused(struct obd_export *exp,
1348 struct lov_stripe_md *ea,
1349 int flags, void *opaque)
1354 EXP_CHECK_DT_OP(exp, cancel_unused);
1355 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1357 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1361 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1362 struct obd_capa *oc, struct obd_client_handle *handle,
1368 EXP_CHECK_DT_OP(exp, pin);
1369 EXP_COUNTER_INCREMENT(exp, pin);
1371 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1375 static inline int obd_unpin(struct obd_export *exp,
1376 struct obd_client_handle *handle, int flag)
1381 EXP_CHECK_DT_OP(exp, unpin);
1382 EXP_COUNTER_INCREMENT(exp, unpin);
1384 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1389 static inline void obd_import_event(struct obd_device *obd,
1390 struct obd_import *imp,
1391 enum obd_import_event event)
1395 CERROR("NULL device\n");
1399 if (obd->obd_set_up && OBP(obd, import_event)) {
1400 OBD_COUNTER_INCREMENT(obd, import_event);
1401 OBP(obd, import_event)(obd, imp, event);
1406 static inline int obd_llog_connect(struct obd_export *exp,
1407 struct llogd_conn_body *body)
1412 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1413 EXP_COUNTER_INCREMENT(exp, llog_connect);
1415 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1420 static inline int obd_notify(struct obd_device *obd,
1421 struct obd_device *watched,
1422 enum obd_notify_event ev,
1429 /* the check for async_recov is a complete hack - I'm hereby
1430 overloading the meaning to also mean "this was called from
1431 mds_postsetup". I know that my mds is able to handle notifies
1432 by this point, and it needs to get them to execute mds_postrecov. */
1433 if (!obd->obd_set_up && !obd->obd_async_recov) {
1434 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1438 if (!OBP(obd, notify)) {
1439 CERROR("obd %s has no notify handler\n", obd->obd_name);
1443 OBD_COUNTER_INCREMENT(obd, notify);
1444 rc = OBP(obd, notify)(obd, watched, ev, data);
1448 static inline int obd_notify_observer(struct obd_device *observer,
1449 struct obd_device *observed,
1450 enum obd_notify_event ev,
1456 struct obd_notify_upcall *onu;
1458 if (observer->obd_observer)
1459 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1463 * Also, call non-obd listener, if any
1465 onu = &observer->obd_upcall;
1466 if (onu->onu_upcall != NULL)
1467 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1471 return rc1 ? rc1 : rc2;
1474 static inline int obd_quotacheck(struct obd_export *exp,
1475 struct obd_quotactl *oqctl)
1480 EXP_CHECK_DT_OP(exp, quotacheck);
1481 EXP_COUNTER_INCREMENT(exp, quotacheck);
1483 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1487 static inline int obd_quotactl(struct obd_export *exp,
1488 struct obd_quotactl *oqctl)
1493 EXP_CHECK_DT_OP(exp, quotactl);
1494 EXP_COUNTER_INCREMENT(exp, quotactl);
1496 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1500 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1501 struct quota_adjust_qunit *oqaq,
1502 struct lustre_quota_ctxt *qctxt)
1504 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1505 struct timeval work_start;
1506 struct timeval work_end;
1512 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1514 do_gettimeofday(&work_start);
1516 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1517 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1519 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt);
1521 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1523 do_gettimeofday(&work_end);
1524 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1525 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1532 static inline int obd_health_check(struct obd_device *obd)
1534 /* returns: 0 on healthy
1535 * >0 on unhealthy + reason code/flag
1536 * however the only suppored reason == 1 right now
1537 * We'll need to define some better reasons
1538 * or flags in the future.
1544 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1545 if (obd == NULL || !OBT(obd)) {
1546 CERROR("cleaned up obd\n");
1547 RETURN(-EOPNOTSUPP);
1549 if (!obd->obd_set_up || obd->obd_stopping)
1551 if (!OBP(obd, health_check))
1554 rc = OBP(obd, health_check)(obd);
1558 static inline int obd_register_observer(struct obd_device *obd,
1559 struct obd_device *observer)
1563 if (obd->obd_observer && observer)
1565 obd->obd_observer = observer;
1570 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1571 obd_page_removal_cb_t cb,
1572 obd_pin_extent_cb pin_cb)
1577 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1578 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1580 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1584 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1585 obd_page_removal_cb_t cb)
1590 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1591 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1593 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1597 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1598 obd_lock_cancel_cb cb)
1603 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1604 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1606 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1610 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1611 obd_lock_cancel_cb cb)
1616 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1617 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1619 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1624 /* metadata helpers */
1625 static inline int md_getstatus(struct obd_export *exp,
1626 struct lu_fid *fid, struct obd_capa **pc)
1631 EXP_CHECK_MD_OP(exp, getstatus);
1632 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1633 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1637 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1638 struct obd_capa *oc, obd_valid valid, int ea_size,
1639 struct ptlrpc_request **request)
1643 EXP_CHECK_MD_OP(exp, getattr);
1644 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1645 rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1650 static inline int md_change_cbdata(struct obd_export *exp,
1651 const struct lu_fid *fid,
1652 ldlm_iterator_t it, void *data)
1656 EXP_CHECK_MD_OP(exp, change_cbdata);
1657 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1658 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1662 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1663 struct md_open_data *mod,
1664 struct ptlrpc_request **request)
1668 EXP_CHECK_MD_OP(exp, close);
1669 EXP_MD_COUNTER_INCREMENT(exp, close);
1670 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1674 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1675 const void *data, int datalen, int mode, __u32 uid,
1676 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1677 struct ptlrpc_request **request)
1681 EXP_CHECK_MD_OP(exp, create);
1682 EXP_MD_COUNTER_INCREMENT(exp, create);
1683 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1684 uid, gid, cap_effective, rdev, request);
1688 static inline int md_done_writing(struct obd_export *exp,
1689 struct md_op_data *op_data,
1690 struct md_open_data *mod)
1694 EXP_CHECK_MD_OP(exp, done_writing);
1695 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1696 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1700 static inline int md_enqueue(struct obd_export *exp,
1701 struct ldlm_enqueue_info *einfo,
1702 struct lookup_intent *it,
1703 struct md_op_data *op_data,
1704 struct lustre_handle *lockh,
1705 void *lmm, int lmmsize,
1706 struct ptlrpc_request **req,
1707 int extra_lock_flags)
1711 EXP_CHECK_MD_OP(exp, enqueue);
1712 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1713 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1714 lmm, lmmsize, req, extra_lock_flags);
1718 static inline int md_getattr_name(struct obd_export *exp,
1719 const struct lu_fid *fid, struct obd_capa *oc,
1720 const char *name, int namelen,
1721 obd_valid valid, int ea_size, __u32 suppgid,
1722 struct ptlrpc_request **request)
1726 EXP_CHECK_MD_OP(exp, getattr_name);
1727 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1728 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1729 valid, ea_size, suppgid, request);
1733 static inline int md_intent_lock(struct obd_export *exp,
1734 struct md_op_data *op_data, void *lmm,
1735 int lmmsize, struct lookup_intent *it,
1736 int flags, struct ptlrpc_request **reqp,
1737 ldlm_blocking_callback cb_blocking,
1738 int extra_lock_flags)
1742 EXP_CHECK_MD_OP(exp, intent_lock);
1743 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1744 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1745 it, flags, reqp, cb_blocking,
1750 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1751 struct ptlrpc_request **request)
1755 EXP_CHECK_MD_OP(exp, link);
1756 EXP_MD_COUNTER_INCREMENT(exp, link);
1757 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1761 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1762 const char *old, int oldlen, const char *new,
1763 int newlen, struct ptlrpc_request **request)
1767 EXP_CHECK_MD_OP(exp, rename);
1768 EXP_MD_COUNTER_INCREMENT(exp, rename);
1769 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1774 static inline int md_is_subdir(struct obd_export *exp,
1775 const struct lu_fid *pfid,
1776 const struct lu_fid *cfid,
1777 struct ptlrpc_request **request)
1781 EXP_CHECK_MD_OP(exp, is_subdir);
1782 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1783 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1787 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1788 void *ea, int ealen, void *ea2, int ea2len,
1789 struct ptlrpc_request **request,
1790 struct md_open_data **mod)
1794 EXP_CHECK_MD_OP(exp, setattr);
1795 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1796 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1797 ea2, ea2len, request, mod);
1801 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1802 struct obd_capa *oc, struct ptlrpc_request **request)
1806 EXP_CHECK_MD_OP(exp, sync);
1807 EXP_MD_COUNTER_INCREMENT(exp, sync);
1808 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1812 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1813 struct obd_capa *oc, __u64 offset,
1815 struct ptlrpc_request **request)
1819 EXP_CHECK_MD_OP(exp, readpage);
1820 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1821 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1825 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1826 struct ptlrpc_request **request)
1830 EXP_CHECK_MD_OP(exp, unlink);
1831 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1832 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1836 static inline int md_get_lustre_md(struct obd_export *exp,
1837 struct ptlrpc_request *req,
1838 struct obd_export *dt_exp,
1839 struct obd_export *md_exp,
1840 struct lustre_md *md)
1843 EXP_CHECK_MD_OP(exp, get_lustre_md);
1844 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1845 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1848 static inline int md_free_lustre_md(struct obd_export *exp,
1849 struct lustre_md *md)
1852 EXP_CHECK_MD_OP(exp, free_lustre_md);
1853 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1854 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1857 static inline int md_setxattr(struct obd_export *exp,
1858 const struct lu_fid *fid, struct obd_capa *oc,
1859 obd_valid valid, const char *name,
1860 const char *input, int input_size,
1861 int output_size, int flags, __u32 suppgid,
1862 struct ptlrpc_request **request)
1865 EXP_CHECK_MD_OP(exp, setxattr);
1866 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1867 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1868 input_size, output_size, flags,
1872 static inline int md_getxattr(struct obd_export *exp,
1873 const struct lu_fid *fid, struct obd_capa *oc,
1874 obd_valid valid, const char *name,
1875 const char *input, int input_size,
1876 int output_size, int flags,
1877 struct ptlrpc_request **request)
1880 EXP_CHECK_MD_OP(exp, getxattr);
1881 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1882 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1883 input_size, output_size, flags,
1887 static inline int md_set_open_replay_data(struct obd_export *exp,
1888 struct obd_client_handle *och,
1889 struct ptlrpc_request *open_req)
1892 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1893 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1894 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1897 static inline int md_clear_open_replay_data(struct obd_export *exp,
1898 struct obd_client_handle *och)
1901 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1902 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1903 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1906 static inline int md_set_lock_data(struct obd_export *exp,
1907 __u64 *lockh, void *data)
1910 EXP_CHECK_MD_OP(exp, set_lock_data);
1911 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1912 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1915 static inline int md_cancel_unused(struct obd_export *exp,
1916 const struct lu_fid *fid,
1917 ldlm_policy_data_t *policy,
1918 ldlm_mode_t mode, int flags, void *opaque)
1923 EXP_CHECK_MD_OP(exp, cancel_unused);
1924 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1926 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1931 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
1932 const struct lu_fid *fid,
1934 ldlm_policy_data_t *policy,
1936 struct lustre_handle *lockh)
1939 EXP_CHECK_MD_OP(exp, lock_match);
1940 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1941 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1942 policy, mode, lockh));
1945 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1946 int def_asize, int cookiesize)
1949 EXP_CHECK_MD_OP(exp, init_ea_size);
1950 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1951 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1955 static inline int md_get_remote_perm(struct obd_export *exp,
1956 const struct lu_fid *fid,
1957 struct obd_capa *oc, __u32 suppgid,
1958 struct ptlrpc_request **request)
1961 EXP_CHECK_MD_OP(exp, get_remote_perm);
1962 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1963 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1967 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1972 EXP_CHECK_MD_OP(exp, renew_capa);
1973 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1974 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1978 static inline int md_unpack_capa(struct obd_export *exp,
1979 struct ptlrpc_request *req,
1980 const struct req_msg_field *field,
1981 struct obd_capa **oc)
1985 EXP_CHECK_MD_OP(exp, unpack_capa);
1986 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
1987 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
1991 static inline int md_intent_getattr_async(struct obd_export *exp,
1992 struct md_enqueue_info *minfo,
1993 struct ldlm_enqueue_info *einfo)
1997 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1998 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1999 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2003 static inline int md_revalidate_lock(struct obd_export *exp,
2004 struct lookup_intent *it,
2009 EXP_CHECK_MD_OP(exp, revalidate_lock);
2010 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2011 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2016 /* OBD Metadata Support */
2018 extern int obd_init_caches(void);
2019 extern void obd_cleanup_caches(void);
2021 /* support routines */
2022 extern cfs_mem_cache_t *obdo_cachep;
2024 #define OBDO_ALLOC(ptr) \
2026 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
2029 #define OBDO_FREE(ptr) \
2031 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2035 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2037 /* something here */
2040 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2042 /* something here */
2045 /* I'm as embarrassed about this as you are.
2047 * <shaver> // XXX do not look into _superhack with remaining eye
2048 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2049 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2052 extern void obd_sysctl_init (void);
2053 extern void obd_sysctl_clean (void);
2056 typedef __u8 class_uuid_t[16];
2057 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2060 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2061 int class_add_uuid(const char *uuid, __u64 nid);
2062 int class_del_uuid (const char *uuid);
2063 void class_init_uuidlist(void);
2064 void class_exit_uuidlist(void);
2067 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2068 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2071 void ll_generate_random_uuid(class_uuid_t uuid_out);
2073 #endif /* __LINUX_OBD_CLASS_H */