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 char *obd_export_nid2str(struct obd_export *exp);
95 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
96 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
98 int obd_zombie_impexp_init(void);
99 void obd_zombie_impexp_stop(void);
100 void obd_zombie_impexp_cull(void);
101 void obd_zombie_barrier(void);
104 int class_process_config(struct lustre_cfg *lcfg);
105 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
106 struct lustre_cfg *lcfg, void *data);
107 int class_attach(struct lustre_cfg *lcfg);
108 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
109 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
110 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
111 struct obd_device *class_incref(struct obd_device *obd,
112 const char *scope, const void *source);
113 void class_decref(struct obd_device *obd,
114 const char *scope, const void *source);
118 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
120 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
122 memset(lvars, 0, sizeof(*lvars));
126 #define CFG_F_START 0x01 /* Set when we start updating from a log */
127 #define CFG_F_MARKER 0x02 /* We are within a maker */
128 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
129 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
130 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
132 /* Passed as data param to class_config_parse_llog */
133 struct config_llog_instance {
135 struct super_block *cfg_sb;
136 struct obd_uuid cfg_uuid;
137 int cfg_last_idx; /* for partial llog processing */
140 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
141 struct config_llog_instance *cfg);
142 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
143 struct config_llog_instance *cfg);
145 /* list of active configuration logs */
146 struct config_llog_data {
148 struct ldlm_res_id cld_resid;
149 struct config_llog_instance cld_cfg;
150 struct list_head cld_list_chain;
151 atomic_t cld_refcount;
152 struct obd_export *cld_mgcexp;
153 unsigned int cld_stopping:1, /* we were told to stop watching */
154 cld_lostlock:1; /* lock not requeued */
157 struct lustre_profile {
158 struct list_head lp_list;
164 struct lustre_profile *class_get_profile(const char * prof);
165 void class_del_profile(const char *prof);
166 void class_del_profiles(void);
168 #define class_export_rpc_get(exp) \
170 atomic_inc(&(exp)->exp_rpc_count); \
171 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
172 (exp), atomic_read(&(exp)->exp_rpc_count)); \
173 class_export_get(exp); \
176 #define class_export_rpc_put(exp) \
178 atomic_dec(&(exp)->exp_rpc_count); \
179 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
180 (exp), atomic_read(&(exp)->exp_rpc_count)); \
181 class_export_put(exp); \
185 struct obd_export *class_export_get(struct obd_export *exp);
186 void class_export_put(struct obd_export *exp);
187 struct obd_export *class_new_export(struct obd_device *obddev,
188 struct obd_uuid *cluuid);
189 void class_unlink_export(struct obd_export *exp);
191 struct obd_import *class_import_get(struct obd_import *);
192 void class_import_put(struct obd_import *);
193 struct obd_import *class_new_import(struct obd_device *obd);
194 void class_destroy_import(struct obd_import *exp);
196 struct obd_type *class_search_type(const char *name);
197 struct obd_type *class_get_type(const char *name);
198 void class_put_type(struct obd_type *type);
199 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
200 struct obd_uuid *cluuid);
201 int class_disconnect(struct obd_export *exp);
202 void class_fail_export(struct obd_export *exp);
203 void class_disconnect_exports(struct obd_device *obddev);
204 int class_disconnect_stale_exports(struct obd_device *,
205 int (*test_export)(struct obd_export *));
206 int class_manual_cleanup(struct obd_device *obd);
208 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
209 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
210 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
211 unsigned int ia_valid);
212 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
213 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
214 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
217 #define OBT(dev) (dev)->obd_type
218 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
219 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
220 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
222 /* Ensure obd_setup: used for cleanup which must be called
223 while obd is stopping */
224 #define OBD_CHECK_DEV(obd) \
227 CERROR("NULL device\n"); \
232 /* ensure obd_setup and !obd_stopping */
233 #define OBD_CHECK_DEV_ACTIVE(obd) \
235 OBD_CHECK_DEV(obd); \
236 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
237 CERROR("Device %d not setup\n", \
245 #define OBD_COUNTER_OFFSET(op) \
246 ((offsetof(struct obd_ops, o_ ## op) - \
247 offsetof(struct obd_ops, o_iocontrol)) \
248 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
250 #define OBD_COUNTER_INCREMENT(obdx, op) \
251 if ((obdx)->obd_stats != NULL) { \
252 unsigned int coffset; \
253 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
254 OBD_COUNTER_OFFSET(op); \
255 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
256 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
259 #define EXP_COUNTER_INCREMENT(export, op) \
260 if ((export)->exp_obd->obd_stats != NULL) { \
261 unsigned int coffset; \
262 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
263 OBD_COUNTER_OFFSET(op); \
264 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
265 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
266 if ((export)->exp_nid_stats != NULL && \
267 (export)->exp_nid_stats->nid_stats != NULL) \
268 lprocfs_counter_incr( \
269 (export)->exp_nid_stats->nid_stats, coffset);\
272 #define MD_COUNTER_OFFSET(op) \
273 ((offsetof(struct md_ops, m_ ## op) - \
274 offsetof(struct md_ops, m_getstatus)) \
275 / sizeof(((struct md_ops *)(0))->m_getstatus))
277 #define MD_COUNTER_INCREMENT(obdx, op) \
278 if ((obd)->md_stats != NULL) { \
279 unsigned int coffset; \
280 coffset = (unsigned int)((obdx)->md_cntr_base) + \
281 MD_COUNTER_OFFSET(op); \
282 LASSERT(coffset < (obdx)->md_stats->ls_num); \
283 lprocfs_counter_incr((obdx)->md_stats, coffset); \
286 #define EXP_MD_COUNTER_INCREMENT(export, op) \
287 if ((export)->exp_obd->obd_stats != NULL) { \
288 unsigned int coffset; \
289 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
290 MD_COUNTER_OFFSET(op); \
291 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
292 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
293 if ((export)->exp_md_stats != NULL) \
294 lprocfs_counter_incr( \
295 (export)->exp_md_stats, coffset); \
299 #define OBD_COUNTER_OFFSET(op)
300 #define OBD_COUNTER_INCREMENT(obd, op)
301 #define EXP_COUNTER_INCREMENT(exp, op)
302 #define MD_COUNTER_INCREMENT(obd, op)
303 #define EXP_MD_COUNTER_INCREMENT(exp, op)
306 #define OBD_CHECK_MD_OP(obd, op, err) \
308 if (!OBT(obd) || !MDP((obd), op)) { \
310 CERROR("md_" #op ": dev %s/%d no operation\n", \
311 obd->obd_name, obd->obd_minor); \
316 #define EXP_CHECK_MD_OP(exp, op) \
318 if ((exp) == NULL) { \
319 CERROR("obd_" #op ": NULL export\n"); \
322 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
323 CERROR("obd_" #op ": cleaned up obd\n"); \
324 RETURN(-EOPNOTSUPP); \
326 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
327 CERROR("obd_" #op ": dev %s/%d no operation\n", \
328 (exp)->exp_obd->obd_name, \
329 (exp)->exp_obd->obd_minor); \
330 RETURN(-EOPNOTSUPP); \
335 #define OBD_CHECK_DT_OP(obd, op, err) \
337 if (!OBT(obd) || !OBP((obd), op)) { \
339 CERROR("obd_" #op ": dev %d no operation\n", \
345 #define EXP_CHECK_DT_OP(exp, op) \
347 if ((exp) == NULL) { \
348 CERROR("obd_" #op ": NULL export\n"); \
351 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
352 CERROR("obd_" #op ": cleaned up obd\n"); \
353 RETURN(-EOPNOTSUPP); \
355 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
356 CERROR("obd_" #op ": dev %d no operation\n", \
357 (exp)->exp_obd->obd_minor); \
358 RETURN(-EOPNOTSUPP); \
362 #define CTXT_CHECK_OP(ctxt, op, err) \
364 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
366 CERROR("lop_" #op ": dev %d no operation\n", \
367 ctxt->loc_obd->obd_minor); \
372 static inline int class_devno_max(void)
374 return MAX_OBD_DEVICES;
377 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
378 void *key, __u32 *vallen, void *val,
379 struct lov_stripe_md *lsm)
384 EXP_CHECK_DT_OP(exp, get_info);
385 EXP_COUNTER_INCREMENT(exp, get_info);
387 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
391 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
392 void *key, obd_count vallen, void *val,
393 struct ptlrpc_request_set *set)
398 EXP_CHECK_DT_OP(exp, set_info_async);
399 EXP_COUNTER_INCREMENT(exp, set_info_async);
401 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
407 * obd-lu integration.
409 * Functionality is being moved into new lu_device-based layering, but some
410 * pieces of configuration process are still based on obd devices.
412 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
413 * subsume ->o_setup() methods of obd devices they replace. The same for
414 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
415 * result, obd_setup() and obd_process_config() branch and call one XOR
418 * Yet neither lu_device_type_operations::ldto_device_fini() nor
419 * lu_device_type_operations::ldto_device_free() fully implement the
420 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
421 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
424 #define DECLARE_LU_VARS(ldt, d) \
425 struct lu_device_type *ldt; \
428 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
431 DECLARE_LU_VARS(ldt, d);
434 ldt = obd->obd_type->typ_lu;
438 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
440 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
450 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
451 OBD_COUNTER_INCREMENT(obd, setup);
452 rc = OBP(obd, setup)(obd, cfg);
457 static inline int obd_precleanup(struct obd_device *obd,
458 enum obd_cleanup_stage cleanup_stage)
461 DECLARE_LU_VARS(ldt, d);
465 ldt = obd->obd_type->typ_lu;
467 if (ldt != NULL && d != NULL) {
468 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
471 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
473 ldt->ldt_ops->ldto_device_fini(&env, d);
478 OBD_CHECK_DT_OP(obd, precleanup, 0);
479 OBD_COUNTER_INCREMENT(obd, precleanup);
481 rc = OBP(obd, precleanup)(obd, cleanup_stage);
485 static inline int obd_cleanup(struct obd_device *obd)
488 DECLARE_LU_VARS(ldt, d);
493 ldt = obd->obd_type->typ_lu;
495 if (ldt != NULL && d != NULL) {
498 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
500 ldt->ldt_ops->ldto_device_free(&env, d);
502 obd->obd_lu_dev = NULL;
505 OBD_CHECK_DT_OP(obd, cleanup, 0);
506 OBD_COUNTER_INCREMENT(obd, cleanup);
508 rc = OBP(obd, cleanup)(obd);
513 obd_process_config(struct obd_device *obd, int datalen, void *data)
516 DECLARE_LU_VARS(ldt, d);
521 ldt = obd->obd_type->typ_lu;
523 if (ldt != NULL && d != NULL) {
526 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
528 rc = d->ld_ops->ldo_process_config(&env, d, data);
532 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
533 rc = OBP(obd, process_config)(obd, datalen, data);
535 OBD_COUNTER_INCREMENT(obd, process_config);
540 /* Pack an in-memory MD struct for storage on disk.
541 * Returns +ve size of packed MD (0 for free), or -ve error.
543 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
544 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
545 * If @*disk_tgt == NULL, it will be allocated
547 static inline int obd_packmd(struct obd_export *exp,
548 struct lov_mds_md **disk_tgt,
549 struct lov_stripe_md *mem_src)
554 EXP_CHECK_DT_OP(exp, packmd);
555 EXP_COUNTER_INCREMENT(exp, packmd);
557 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
561 static inline int obd_size_diskmd(struct obd_export *exp,
562 struct lov_stripe_md *mem_src)
564 return obd_packmd(exp, NULL, mem_src);
567 /* helper functions */
568 static inline int obd_alloc_diskmd(struct obd_export *exp,
569 struct lov_mds_md **disk_tgt)
572 LASSERT(*disk_tgt == NULL);
573 return obd_packmd(exp, disk_tgt, NULL);
576 static inline int obd_free_diskmd(struct obd_export *exp,
577 struct lov_mds_md **disk_tgt)
581 return obd_packmd(exp, disk_tgt, NULL);
584 /* Unpack an MD struct from disk to in-memory format.
585 * Returns +ve size of unpacked MD (0 for free), or -ve error.
587 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
588 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
589 * If @*mem_tgt == NULL, it will be allocated
591 static inline int obd_unpackmd(struct obd_export *exp,
592 struct lov_stripe_md **mem_tgt,
593 struct lov_mds_md *disk_src,
599 EXP_CHECK_DT_OP(exp, unpackmd);
600 EXP_COUNTER_INCREMENT(exp, unpackmd);
602 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
606 /* helper functions */
607 static inline int obd_alloc_memmd(struct obd_export *exp,
608 struct lov_stripe_md **mem_tgt)
611 LASSERT(*mem_tgt == NULL);
612 return obd_unpackmd(exp, mem_tgt, NULL, 0);
615 static inline int obd_free_memmd(struct obd_export *exp,
616 struct lov_stripe_md **mem_tgt)
622 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
627 static inline int obd_checkmd(struct obd_export *exp,
628 struct obd_export *md_exp,
629 struct lov_stripe_md *mem_tgt)
634 EXP_CHECK_DT_OP(exp, checkmd);
635 EXP_COUNTER_INCREMENT(exp, checkmd);
637 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
641 static inline int obd_precreate(struct obd_export *exp)
646 EXP_CHECK_DT_OP(exp, precreate);
647 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
649 rc = OBP(exp->exp_obd, precreate)(exp);
653 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
654 struct lov_stripe_md **ea,
655 struct obd_trans_info *oti)
660 EXP_CHECK_DT_OP(exp, create);
661 EXP_COUNTER_INCREMENT(exp, create);
663 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
667 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
668 struct lov_stripe_md *ea,
669 struct obd_trans_info *oti,
670 struct obd_export *md_exp, void *capa)
675 EXP_CHECK_DT_OP(exp, destroy);
676 EXP_COUNTER_INCREMENT(exp, destroy);
678 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
682 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
687 EXP_CHECK_DT_OP(exp, getattr);
688 EXP_COUNTER_INCREMENT(exp, getattr);
690 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
694 static inline int obd_getattr_async(struct obd_export *exp,
695 struct obd_info *oinfo,
696 struct ptlrpc_request_set *set)
701 EXP_CHECK_DT_OP(exp, getattr_async);
702 EXP_COUNTER_INCREMENT(exp, getattr_async);
704 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
708 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
709 struct obd_trans_info *oti)
714 EXP_CHECK_DT_OP(exp, setattr);
715 EXP_COUNTER_INCREMENT(exp, setattr);
717 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
721 /* This performs all the requests set init/wait/destroy actions. */
722 static inline int obd_setattr_rqset(struct obd_export *exp,
723 struct obd_info *oinfo,
724 struct obd_trans_info *oti)
726 struct ptlrpc_request_set *set = NULL;
730 EXP_CHECK_DT_OP(exp, setattr_async);
731 EXP_COUNTER_INCREMENT(exp, setattr_async);
733 set = ptlrpc_prep_set();
737 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
739 rc = ptlrpc_set_wait(set);
740 ptlrpc_set_destroy(set);
744 /* This adds all the requests into @set if @set != NULL, otherwise
745 all requests are sent asynchronously without waiting for response. */
746 static inline int obd_setattr_async(struct obd_export *exp,
747 struct obd_info *oinfo,
748 struct obd_trans_info *oti,
749 struct ptlrpc_request_set *set)
754 EXP_CHECK_DT_OP(exp, setattr_async);
755 EXP_COUNTER_INCREMENT(exp, setattr_async);
757 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
761 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
764 struct obd_device *obd = imp->imp_obd;
768 OBD_CHECK_DEV_ACTIVE(obd);
769 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
770 OBD_COUNTER_INCREMENT(obd, add_conn);
772 rc = OBP(obd, add_conn)(imp, uuid, priority);
776 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
778 struct obd_device *obd = imp->imp_obd;
782 OBD_CHECK_DEV_ACTIVE(obd);
783 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
784 OBD_COUNTER_INCREMENT(obd, del_conn);
786 rc = OBP(obd, del_conn)(imp, uuid);
790 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
792 struct obd_uuid *uuid;
795 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
796 EXP_COUNTER_INCREMENT(exp, get_uuid);
798 uuid = OBP(exp->exp_obd, get_uuid)(exp);
802 static inline int obd_connect(const struct lu_env *env,
803 struct lustre_handle *conn,struct obd_device *obd,
804 struct obd_uuid *cluuid,
805 struct obd_connect_data *d,
809 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
813 OBD_CHECK_DEV_ACTIVE(obd);
814 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
815 OBD_COUNTER_INCREMENT(obd, connect);
817 rc = OBP(obd, connect)(env, conn, obd, cluuid, d, localdata);
818 /* check that only subset is granted */
819 LASSERT(ergo(d != NULL,
820 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
824 static inline int obd_reconnect(const struct lu_env *env,
825 struct obd_export *exp,
826 struct obd_device *obd,
827 struct obd_uuid *cluuid,
828 struct obd_connect_data *d,
832 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
837 OBD_CHECK_DEV_ACTIVE(obd);
838 OBD_CHECK_DT_OP(obd, reconnect, 0);
839 OBD_COUNTER_INCREMENT(obd, reconnect);
841 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
842 /* check that only subset is granted */
843 LASSERT(ergo(d != NULL,
844 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
848 static inline int obd_disconnect(struct obd_export *exp)
853 EXP_CHECK_DT_OP(exp, disconnect);
854 EXP_COUNTER_INCREMENT(exp, disconnect);
856 rc = OBP(exp->exp_obd, disconnect)(exp);
860 static inline int obd_fid_init(struct obd_export *exp)
865 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
866 EXP_COUNTER_INCREMENT(exp, fid_init);
868 rc = OBP(exp->exp_obd, fid_init)(exp);
872 static inline int obd_fid_fini(struct obd_export *exp)
877 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
878 EXP_COUNTER_INCREMENT(exp, fid_fini);
880 rc = OBP(exp->exp_obd, fid_fini)(exp);
884 static inline int obd_fid_alloc(struct obd_export *exp,
886 struct md_op_data *op_data)
891 EXP_CHECK_DT_OP(exp, fid_alloc);
892 EXP_COUNTER_INCREMENT(exp, fid_alloc);
894 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
898 static inline int obd_fid_delete(struct obd_export *exp,
899 const struct lu_fid *fid)
904 EXP_CHECK_DT_OP(exp, fid_delete);
905 EXP_COUNTER_INCREMENT(exp, fid_delete);
907 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
911 static inline int obd_ping(struct obd_export *exp)
916 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
917 EXP_COUNTER_INCREMENT(exp, ping);
919 rc = OBP(exp->exp_obd, ping)(exp);
923 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
928 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
929 OBD_COUNTER_INCREMENT(obd, pool_new);
931 rc = OBP(obd, pool_new)(obd, poolname);
935 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
940 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
941 OBD_COUNTER_INCREMENT(obd, pool_del);
943 rc = OBP(obd, pool_del)(obd, poolname);
947 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
952 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
953 OBD_COUNTER_INCREMENT(obd, pool_add);
955 rc = OBP(obd, pool_add)(obd, poolname, ostname);
959 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
964 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
965 OBD_COUNTER_INCREMENT(obd, pool_rem);
967 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
971 static inline int obd_init_export(struct obd_export *exp)
976 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
977 OBP((exp)->exp_obd, init_export))
978 rc = OBP(exp->exp_obd, init_export)(exp);
982 static inline int obd_destroy_export(struct obd_export *exp)
985 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
986 OBP((exp)->exp_obd, destroy_export))
987 OBP(exp->exp_obd, destroy_export)(exp);
991 static inline int obd_extent_calc(struct obd_export *exp,
992 struct lov_stripe_md *md,
993 int cmd, obd_off *offset)
997 EXP_CHECK_DT_OP(exp, extent_calc);
998 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1002 static inline struct dentry *
1003 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1005 LASSERT(exp->exp_obd);
1007 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1012 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1014 LASSERT(exp->exp_obd);
1015 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1017 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1018 dentry, exp->exp_obd);
1024 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
1027 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1028 * If the cache is older than @max_age we will get a new value from the
1029 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1030 static inline int obd_statfs_async(struct obd_device *obd,
1031 struct obd_info *oinfo,
1033 struct ptlrpc_request_set *rqset)
1041 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1042 OBD_COUNTER_INCREMENT(obd, statfs);
1044 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1045 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1046 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1047 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1049 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1050 " objects "LPU64"/"LPU64"\n",
1051 obd->obd_name, &obd->obd_osfs,
1052 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1053 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1054 spin_lock(&obd->obd_osfs_lock);
1055 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1056 spin_unlock(&obd->obd_osfs_lock);
1057 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1058 if (oinfo->oi_cb_up)
1059 oinfo->oi_cb_up(oinfo, 0);
1064 static inline int obd_statfs_rqset(struct obd_device *obd,
1065 struct obd_statfs *osfs, __u64 max_age,
1068 struct ptlrpc_request_set *set = NULL;
1069 struct obd_info oinfo = { { { 0 } } };
1073 set = ptlrpc_prep_set();
1077 oinfo.oi_osfs = osfs;
1078 oinfo.oi_flags = flags;
1079 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1081 rc = ptlrpc_set_wait(set);
1082 ptlrpc_set_destroy(set);
1086 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1087 * If the cache is older than @max_age we will get a new value from the
1088 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1089 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1090 __u64 max_age, __u32 flags)
1098 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1099 OBD_COUNTER_INCREMENT(obd, statfs);
1101 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1102 obd->obd_osfs_age, max_age);
1103 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1104 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1106 spin_lock(&obd->obd_osfs_lock);
1107 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1108 obd->obd_osfs_age = cfs_time_current_64();
1109 spin_unlock(&obd->obd_osfs_lock);
1112 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1113 " objects "LPU64"/"LPU64"\n",
1114 obd->obd_name, &obd->obd_osfs,
1115 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1116 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1117 spin_lock(&obd->obd_osfs_lock);
1118 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1119 spin_unlock(&obd->obd_osfs_lock);
1124 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1125 struct lov_stripe_md *ea, obd_size start,
1126 obd_size end, void *capa)
1131 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1132 EXP_COUNTER_INCREMENT(exp, sync);
1134 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1138 static inline int obd_punch_rqset(struct obd_export *exp,
1139 struct obd_info *oinfo,
1140 struct obd_trans_info *oti)
1142 struct ptlrpc_request_set *set = NULL;
1146 EXP_CHECK_DT_OP(exp, punch);
1147 EXP_COUNTER_INCREMENT(exp, punch);
1149 set = ptlrpc_prep_set();
1153 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1155 rc = ptlrpc_set_wait(set);
1156 ptlrpc_set_destroy(set);
1160 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1161 struct obd_trans_info *oti,
1162 struct ptlrpc_request_set *rqset)
1167 EXP_CHECK_DT_OP(exp, punch);
1168 EXP_COUNTER_INCREMENT(exp, punch);
1170 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1174 static inline int obd_brw(int cmd, struct obd_export *exp,
1175 struct obd_info *oinfo, obd_count oa_bufs,
1176 struct brw_page *pg, struct obd_trans_info *oti)
1181 EXP_CHECK_DT_OP(exp, brw);
1182 EXP_COUNTER_INCREMENT(exp, brw);
1184 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1185 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1186 "or OBD_BRW_CHECK\n");
1190 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1194 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1195 int objcount, struct obd_ioobj *obj,
1196 struct niobuf_remote *remote, int *pages,
1197 struct niobuf_local *local,
1198 struct obd_trans_info *oti,
1199 struct lustre_capa *capa)
1204 EXP_CHECK_DT_OP(exp, preprw);
1205 EXP_COUNTER_INCREMENT(exp, preprw);
1207 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1208 pages, local, oti, capa);
1212 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1213 int objcount, struct obd_ioobj *obj,
1214 struct niobuf_remote *rnb, int pages,
1215 struct niobuf_local *local,
1216 struct obd_trans_info *oti, int rc)
1220 EXP_CHECK_DT_OP(exp, commitrw);
1221 EXP_COUNTER_INCREMENT(exp, commitrw);
1223 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1224 rnb, pages, local, oti, rc);
1228 static inline int obd_merge_lvb(struct obd_export *exp,
1229 struct lov_stripe_md *lsm,
1230 struct ost_lvb *lvb, int kms_only)
1235 EXP_CHECK_DT_OP(exp, merge_lvb);
1236 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1238 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1242 static inline int obd_adjust_kms(struct obd_export *exp,
1243 struct lov_stripe_md *lsm, obd_off size,
1249 EXP_CHECK_DT_OP(exp, adjust_kms);
1250 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1252 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1256 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1257 int len, void *karg, void *uarg)
1262 EXP_CHECK_DT_OP(exp, iocontrol);
1263 EXP_COUNTER_INCREMENT(exp, iocontrol);
1265 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1269 static inline int obd_enqueue_rqset(struct obd_export *exp,
1270 struct obd_info *oinfo,
1271 struct ldlm_enqueue_info *einfo)
1273 struct ptlrpc_request_set *set = NULL;
1277 EXP_CHECK_DT_OP(exp, enqueue);
1278 EXP_COUNTER_INCREMENT(exp, enqueue);
1280 set = ptlrpc_prep_set();
1284 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1286 rc = ptlrpc_set_wait(set);
1287 ptlrpc_set_destroy(set);
1291 static inline int obd_enqueue(struct obd_export *exp,
1292 struct obd_info *oinfo,
1293 struct ldlm_enqueue_info *einfo,
1294 struct ptlrpc_request_set *set)
1299 EXP_CHECK_DT_OP(exp, enqueue);
1300 EXP_COUNTER_INCREMENT(exp, enqueue);
1302 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1306 static inline int obd_change_cbdata(struct obd_export *exp,
1307 struct lov_stripe_md *lsm,
1308 ldlm_iterator_t it, void *data)
1313 EXP_CHECK_DT_OP(exp, change_cbdata);
1314 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1316 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1320 static inline int obd_cancel(struct obd_export *exp,
1321 struct lov_stripe_md *ea, __u32 mode,
1322 struct lustre_handle *lockh)
1327 EXP_CHECK_DT_OP(exp, cancel);
1328 EXP_COUNTER_INCREMENT(exp, cancel);
1330 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1334 static inline int obd_cancel_unused(struct obd_export *exp,
1335 struct lov_stripe_md *ea,
1336 int flags, void *opaque)
1341 EXP_CHECK_DT_OP(exp, cancel_unused);
1342 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1344 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1348 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1349 struct obd_capa *oc, struct obd_client_handle *handle,
1355 EXP_CHECK_DT_OP(exp, pin);
1356 EXP_COUNTER_INCREMENT(exp, pin);
1358 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1362 static inline int obd_unpin(struct obd_export *exp,
1363 struct obd_client_handle *handle, int flag)
1368 EXP_CHECK_DT_OP(exp, unpin);
1369 EXP_COUNTER_INCREMENT(exp, unpin);
1371 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1376 static inline void obd_import_event(struct obd_device *obd,
1377 struct obd_import *imp,
1378 enum obd_import_event event)
1382 CERROR("NULL device\n");
1386 if (obd->obd_set_up && OBP(obd, import_event)) {
1387 OBD_COUNTER_INCREMENT(obd, import_event);
1388 OBP(obd, import_event)(obd, imp, event);
1393 static inline int obd_llog_connect(struct obd_export *exp,
1394 struct llogd_conn_body *body)
1399 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1400 EXP_COUNTER_INCREMENT(exp, llog_connect);
1402 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1407 static inline int obd_notify(struct obd_device *obd,
1408 struct obd_device *watched,
1409 enum obd_notify_event ev,
1416 /* the check for async_recov is a complete hack - I'm hereby
1417 overloading the meaning to also mean "this was called from
1418 mds_postsetup". I know that my mds is able to handle notifies
1419 by this point, and it needs to get them to execute mds_postrecov. */
1420 if (!obd->obd_set_up && !obd->obd_async_recov) {
1421 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1425 if (!OBP(obd, notify)) {
1426 CERROR("obd %s has no notify handler\n", obd->obd_name);
1430 OBD_COUNTER_INCREMENT(obd, notify);
1431 rc = OBP(obd, notify)(obd, watched, ev, data);
1435 static inline int obd_notify_observer(struct obd_device *observer,
1436 struct obd_device *observed,
1437 enum obd_notify_event ev,
1443 struct obd_notify_upcall *onu;
1445 if (observer->obd_observer)
1446 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1450 * Also, call non-obd listener, if any
1452 onu = &observer->obd_upcall;
1453 if (onu->onu_upcall != NULL)
1454 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1458 return rc1 ? rc1 : rc2;
1461 static inline int obd_quotacheck(struct obd_export *exp,
1462 struct obd_quotactl *oqctl)
1467 EXP_CHECK_DT_OP(exp, quotacheck);
1468 EXP_COUNTER_INCREMENT(exp, quotacheck);
1470 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1474 static inline int obd_quotactl(struct obd_export *exp,
1475 struct obd_quotactl *oqctl)
1480 EXP_CHECK_DT_OP(exp, quotactl);
1481 EXP_COUNTER_INCREMENT(exp, quotactl);
1483 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1487 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1488 struct quota_adjust_qunit *oqaq,
1489 struct lustre_quota_ctxt *qctxt)
1491 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1492 struct timeval work_start;
1493 struct timeval work_end;
1499 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1501 do_gettimeofday(&work_start);
1503 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1504 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1506 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt);
1508 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1510 do_gettimeofday(&work_end);
1511 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1512 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1519 static inline int obd_health_check(struct obd_device *obd)
1521 /* returns: 0 on healthy
1522 * >0 on unhealthy + reason code/flag
1523 * however the only suppored reason == 1 right now
1524 * We'll need to define some better reasons
1525 * or flags in the future.
1531 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1532 if (obd == NULL || !OBT(obd)) {
1533 CERROR("cleaned up obd\n");
1534 RETURN(-EOPNOTSUPP);
1536 if (!obd->obd_set_up || obd->obd_stopping)
1538 if (!OBP(obd, health_check))
1541 rc = OBP(obd, health_check)(obd);
1545 static inline int obd_register_observer(struct obd_device *obd,
1546 struct obd_device *observer)
1550 if (obd->obd_observer && observer)
1552 obd->obd_observer = observer;
1557 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1558 obd_page_removal_cb_t cb,
1559 obd_pin_extent_cb pin_cb)
1564 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1565 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1567 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1571 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1572 obd_page_removal_cb_t cb)
1577 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1578 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1580 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1584 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1585 obd_lock_cancel_cb cb)
1590 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1591 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1593 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1597 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1598 obd_lock_cancel_cb cb)
1603 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1604 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1606 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1611 /* metadata helpers */
1612 static inline int md_getstatus(struct obd_export *exp,
1613 struct lu_fid *fid, struct obd_capa **pc)
1618 EXP_CHECK_MD_OP(exp, getstatus);
1619 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1620 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1624 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1625 struct obd_capa *oc, obd_valid valid, int ea_size,
1626 struct ptlrpc_request **request)
1630 EXP_CHECK_MD_OP(exp, getattr);
1631 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1632 rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1637 static inline int md_change_cbdata(struct obd_export *exp,
1638 const struct lu_fid *fid,
1639 ldlm_iterator_t it, void *data)
1643 EXP_CHECK_MD_OP(exp, change_cbdata);
1644 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1645 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1649 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1650 struct md_open_data *mod,
1651 struct ptlrpc_request **request)
1655 EXP_CHECK_MD_OP(exp, close);
1656 EXP_MD_COUNTER_INCREMENT(exp, close);
1657 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1661 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1662 const void *data, int datalen, int mode, __u32 uid,
1663 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1664 struct ptlrpc_request **request)
1668 EXP_CHECK_MD_OP(exp, create);
1669 EXP_MD_COUNTER_INCREMENT(exp, create);
1670 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1671 uid, gid, cap_effective, rdev, request);
1675 static inline int md_done_writing(struct obd_export *exp,
1676 struct md_op_data *op_data,
1677 struct md_open_data *mod)
1681 EXP_CHECK_MD_OP(exp, done_writing);
1682 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1683 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1687 static inline int md_enqueue(struct obd_export *exp,
1688 struct ldlm_enqueue_info *einfo,
1689 struct lookup_intent *it,
1690 struct md_op_data *op_data,
1691 struct lustre_handle *lockh,
1692 void *lmm, int lmmsize,
1693 struct ptlrpc_request **req,
1694 int extra_lock_flags)
1698 EXP_CHECK_MD_OP(exp, enqueue);
1699 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1700 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1701 lmm, lmmsize, req, extra_lock_flags);
1705 static inline int md_getattr_name(struct obd_export *exp,
1706 const struct lu_fid *fid, struct obd_capa *oc,
1707 const char *name, int namelen,
1708 obd_valid valid, int ea_size, __u32 suppgid,
1709 struct ptlrpc_request **request)
1713 EXP_CHECK_MD_OP(exp, getattr_name);
1714 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1715 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1716 valid, ea_size, suppgid, request);
1720 static inline int md_intent_lock(struct obd_export *exp,
1721 struct md_op_data *op_data, void *lmm,
1722 int lmmsize, struct lookup_intent *it,
1723 int flags, struct ptlrpc_request **reqp,
1724 ldlm_blocking_callback cb_blocking,
1725 int extra_lock_flags)
1729 EXP_CHECK_MD_OP(exp, intent_lock);
1730 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1731 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1732 it, flags, reqp, cb_blocking,
1737 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1738 struct ptlrpc_request **request)
1742 EXP_CHECK_MD_OP(exp, link);
1743 EXP_MD_COUNTER_INCREMENT(exp, link);
1744 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1748 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1749 const char *old, int oldlen, const char *new,
1750 int newlen, struct ptlrpc_request **request)
1754 EXP_CHECK_MD_OP(exp, rename);
1755 EXP_MD_COUNTER_INCREMENT(exp, rename);
1756 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1761 static inline int md_is_subdir(struct obd_export *exp,
1762 const struct lu_fid *pfid,
1763 const struct lu_fid *cfid,
1764 struct ptlrpc_request **request)
1768 EXP_CHECK_MD_OP(exp, is_subdir);
1769 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1770 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1774 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1775 void *ea, int ealen, void *ea2, int ea2len,
1776 struct ptlrpc_request **request,
1777 struct md_open_data **mod)
1781 EXP_CHECK_MD_OP(exp, setattr);
1782 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1783 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1784 ea2, ea2len, request, mod);
1788 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1789 struct obd_capa *oc, struct ptlrpc_request **request)
1793 EXP_CHECK_MD_OP(exp, sync);
1794 EXP_MD_COUNTER_INCREMENT(exp, sync);
1795 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1799 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1800 struct obd_capa *oc, __u64 offset,
1802 struct ptlrpc_request **request)
1806 EXP_CHECK_MD_OP(exp, readpage);
1807 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1808 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1812 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1813 struct ptlrpc_request **request)
1817 EXP_CHECK_MD_OP(exp, unlink);
1818 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1819 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1823 static inline int md_get_lustre_md(struct obd_export *exp,
1824 struct ptlrpc_request *req,
1825 struct obd_export *dt_exp,
1826 struct obd_export *md_exp,
1827 struct lustre_md *md)
1830 EXP_CHECK_MD_OP(exp, get_lustre_md);
1831 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1832 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1835 static inline int md_free_lustre_md(struct obd_export *exp,
1836 struct lustre_md *md)
1839 EXP_CHECK_MD_OP(exp, free_lustre_md);
1840 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1841 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1844 static inline int md_setxattr(struct obd_export *exp,
1845 const struct lu_fid *fid, struct obd_capa *oc,
1846 obd_valid valid, const char *name,
1847 const char *input, int input_size,
1848 int output_size, int flags, __u32 suppgid,
1849 struct ptlrpc_request **request)
1852 EXP_CHECK_MD_OP(exp, setxattr);
1853 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1854 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1855 input_size, output_size, flags,
1859 static inline int md_getxattr(struct obd_export *exp,
1860 const struct lu_fid *fid, struct obd_capa *oc,
1861 obd_valid valid, const char *name,
1862 const char *input, int input_size,
1863 int output_size, int flags,
1864 struct ptlrpc_request **request)
1867 EXP_CHECK_MD_OP(exp, getxattr);
1868 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1869 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1870 input_size, output_size, flags,
1874 static inline int md_set_open_replay_data(struct obd_export *exp,
1875 struct obd_client_handle *och,
1876 struct ptlrpc_request *open_req)
1879 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1880 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1881 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1884 static inline int md_clear_open_replay_data(struct obd_export *exp,
1885 struct obd_client_handle *och)
1888 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1889 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1890 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1893 static inline int md_set_lock_data(struct obd_export *exp,
1894 __u64 *lockh, void *data)
1897 EXP_CHECK_MD_OP(exp, set_lock_data);
1898 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1899 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1902 static inline int md_cancel_unused(struct obd_export *exp,
1903 const struct lu_fid *fid,
1904 ldlm_policy_data_t *policy,
1905 ldlm_mode_t mode, int flags, void *opaque)
1910 EXP_CHECK_MD_OP(exp, cancel_unused);
1911 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1913 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1918 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
1919 const struct lu_fid *fid,
1921 ldlm_policy_data_t *policy,
1923 struct lustre_handle *lockh)
1926 EXP_CHECK_MD_OP(exp, lock_match);
1927 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1928 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1929 policy, mode, lockh));
1932 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1933 int def_asize, int cookiesize)
1936 EXP_CHECK_MD_OP(exp, init_ea_size);
1937 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1938 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1942 static inline int md_get_remote_perm(struct obd_export *exp,
1943 const struct lu_fid *fid,
1944 struct obd_capa *oc, __u32 suppgid,
1945 struct ptlrpc_request **request)
1948 EXP_CHECK_MD_OP(exp, get_remote_perm);
1949 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1950 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1954 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1959 EXP_CHECK_MD_OP(exp, renew_capa);
1960 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1961 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1965 static inline int md_unpack_capa(struct obd_export *exp,
1966 struct ptlrpc_request *req,
1967 const struct req_msg_field *field,
1968 struct obd_capa **oc)
1972 EXP_CHECK_MD_OP(exp, unpack_capa);
1973 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
1974 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
1978 static inline int md_intent_getattr_async(struct obd_export *exp,
1979 struct md_enqueue_info *minfo,
1980 struct ldlm_enqueue_info *einfo)
1984 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1985 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1986 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
1990 static inline int md_revalidate_lock(struct obd_export *exp,
1991 struct lookup_intent *it,
1996 EXP_CHECK_MD_OP(exp, revalidate_lock);
1997 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1998 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2003 /* OBD Metadata Support */
2005 extern int obd_init_caches(void);
2006 extern void obd_cleanup_caches(void);
2008 /* support routines */
2009 extern cfs_mem_cache_t *obdo_cachep;
2011 #define OBDO_ALLOC(ptr) \
2013 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
2016 #define OBDO_FREE(ptr) \
2018 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2022 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2024 /* something here */
2027 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2029 /* something here */
2032 /* I'm as embarrassed about this as you are.
2034 * <shaver> // XXX do not look into _superhack with remaining eye
2035 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2036 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2039 extern void obd_sysctl_init (void);
2040 extern void obd_sysctl_clean (void);
2043 typedef __u8 class_uuid_t[16];
2044 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2047 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2048 int class_add_uuid(const char *uuid, __u64 nid);
2049 int class_del_uuid (const char *uuid);
2050 void class_init_uuidlist(void);
2051 void class_exit_uuidlist(void);
2054 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2055 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2058 void ll_generate_random_uuid(class_uuid_t uuid_out);
2060 #endif /* __LINUX_OBD_CLASS_H */