4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
39 #include "obd_support.h"
40 #include "lustre_import.h"
41 #include "lustre_net.h"
43 #include "lustre_lib.h"
44 #include "lustre/lustre_idl.h"
45 #include "lprocfs_status.h"
47 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
48 * and resends for avoid deadlocks
50 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
53 #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd
54 * instead of a specific set. This
55 * means that we cannot rely on the set
56 * interpret routine to be called.
57 * lov_statfs_fini() must thus be called
58 * by the request interpret routine
60 #define OBD_STATFS_FOR_MDT0 0x0008 /* The statfs is only for retrieving
61 * information from MDT0.
63 #define OBD_FL_PUNCH 0x00000001 /* To indicate it is punch operation */
65 /* OBD Device Declarations */
66 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
67 extern rwlock_t obd_dev_lock;
69 /* OBD Operations Declarations */
70 struct obd_device *class_exp2obd(struct obd_export *);
71 int class_handle_ioctl(unsigned int cmd, unsigned long arg);
72 int lustre_get_jobid(char *jobid);
74 struct lu_device_type;
77 extern struct list_head obd_types;
78 struct obd_export *class_conn2export(struct lustre_handle *);
79 int class_register_type(struct obd_ops *, struct md_ops *,
80 const char *nm, struct lu_device_type *ldt);
81 int class_unregister_type(const char *nm);
83 struct obd_device *class_newdev(const char *type_name, const char *name);
84 void class_release_dev(struct obd_device *obd);
86 int class_name2dev(const char *name);
87 struct obd_device *class_name2obd(const char *name);
88 int class_uuid2dev(struct obd_uuid *uuid);
89 struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
91 struct obd_uuid *grp_uuid);
92 struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
94 struct obd_device *class_num2obd(int num);
96 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
98 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
100 int obd_zombie_impexp_init(void);
101 void obd_zombie_impexp_stop(void);
102 void obd_zombie_barrier(void);
106 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
107 struct llog_rec_hdr *, void *);
109 int class_process_config(struct lustre_cfg *lcfg);
110 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
111 struct lustre_cfg *lcfg, void *data);
112 struct obd_device *class_incref(struct obd_device *obd,
113 const char *scope, const void *source);
114 void class_decref(struct obd_device *obd,
115 const char *scope, const void *source);
116 int class_config_llog_handler(const struct lu_env *env,
117 struct llog_handle *handle,
118 struct llog_rec_hdr *rec, void *data);
119 int class_add_uuid(const char *uuid, __u64 nid);
122 void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
124 #define CFG_F_START 0x01 /* Set when we start updating from a log */
125 #define CFG_F_MARKER 0x02 /* We are within a maker */
126 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
127 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
128 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
130 /* Passed as data param to class_config_parse_llog */
131 struct config_llog_instance {
134 struct super_block *cfg_sb;
135 struct obd_uuid cfg_uuid;
136 llog_cb_t cfg_callback;
137 int cfg_last_idx; /* for partial llog processing */
141 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
142 char *name, struct config_llog_instance *cfg);
145 CONFIG_T_SPTLRPC = 1,
146 CONFIG_T_RECOVER = 2,
151 #define PARAMS_FILENAME "params"
152 #define LCTL_UPCALL "lctl"
154 /* list of active configuration logs */
155 struct config_llog_data {
156 struct ldlm_res_id cld_resid;
157 struct config_llog_instance cld_cfg;
158 struct list_head cld_list_chain;
159 atomic_t cld_refcount;
160 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
161 struct config_llog_data *cld_params; /* common parameters log */
162 struct config_llog_data *cld_recover;/* imperative recover log */
163 struct obd_export *cld_mgcexp;
164 struct mutex cld_lock;
166 unsigned int cld_stopping:1, /* we were told to stop
169 cld_lostlock:1; /* lock not requeued */
173 struct lustre_profile {
174 struct list_head lp_list;
180 struct lustre_profile *class_get_profile(const char *prof);
181 void class_del_profile(const char *prof);
182 void class_del_profiles(void);
184 #if LUSTRE_TRACKS_LOCK_EXP_REFS
186 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
187 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
188 extern void (*class_export_dump_hook)(struct obd_export *);
192 #define __class_export_add_lock_ref(exp, lock) do {} while (0)
193 #define __class_export_del_lock_ref(exp, lock) do {} while (0)
198 struct obd_export *class_export_get(struct obd_export *exp);
199 void class_export_put(struct obd_export *exp);
200 struct obd_export *class_new_export(struct obd_device *obddev,
201 struct obd_uuid *cluuid);
202 void class_unlink_export(struct obd_export *exp);
204 struct obd_import *class_import_get(struct obd_import *);
205 void class_import_put(struct obd_import *);
206 struct obd_import *class_new_import(struct obd_device *obd);
207 void class_destroy_import(struct obd_import *exp);
209 void class_put_type(struct obd_type *type);
210 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
211 struct obd_uuid *cluuid);
212 int class_disconnect(struct obd_export *exp);
213 void class_fail_export(struct obd_export *exp);
214 int class_manual_cleanup(struct obd_device *obd);
216 static inline void class_export_rpc_inc(struct obd_export *exp)
218 atomic_inc(&(exp)->exp_rpc_count);
219 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n",
220 (exp), atomic_read(&(exp)->exp_rpc_count));
223 static inline void class_export_rpc_dec(struct obd_export *exp)
225 LASSERT_ATOMIC_POS(&exp->exp_rpc_count);
226 atomic_dec(&(exp)->exp_rpc_count);
227 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",
228 (exp), atomic_read(&(exp)->exp_rpc_count));
231 static inline struct obd_export *class_export_lock_get(struct obd_export *exp,
232 struct ldlm_lock *lock)
234 atomic_inc(&(exp)->exp_locks_count);
235 __class_export_add_lock_ref(exp, lock);
236 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n",
237 (exp), atomic_read(&(exp)->exp_locks_count));
238 return class_export_get(exp);
241 static inline void class_export_lock_put(struct obd_export *exp,
242 struct ldlm_lock *lock)
244 LASSERT_ATOMIC_POS(&exp->exp_locks_count);
245 atomic_dec(&(exp)->exp_locks_count);
246 __class_export_del_lock_ref(exp, lock);
247 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n",
248 (exp), atomic_read(&(exp)->exp_locks_count));
249 class_export_put(exp);
252 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
254 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
255 (obd->obd_force ? OBD_OPT_FORCE : 0) |
259 static inline int lprocfs_climp_check(struct obd_device *obd)
261 down_read(&(obd)->u.cli.cl_sem);
262 if (!(obd)->u.cli.cl_import) {
263 up_read(&(obd)->u.cli.cl_sem);
272 void obdo_refresh_inode(struct inode *dst, struct obdo *src, u32 valid);
274 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
275 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, u32 valid);
277 #define OBT(dev) (dev)->obd_type
278 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->op
279 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->op
280 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
282 /* Ensure obd_setup: used for cleanup which must be called
283 * while obd is stopping
285 static inline int obd_check_dev(struct obd_device *obd)
288 CERROR("NULL device\n");
294 /* ensure obd_setup and !obd_stopping */
295 static inline int obd_check_dev_active(struct obd_device *obd)
299 rc = obd_check_dev(obd);
302 if (!obd->obd_set_up || obd->obd_stopping) {
303 CERROR("Device %d not setup\n", obd->obd_minor);
309 #define OBD_COUNTER_OFFSET(op) \
310 ((offsetof(struct obd_ops, op) - \
311 offsetof(struct obd_ops, iocontrol)) \
312 / sizeof(((struct obd_ops *)(0))->iocontrol))
314 #define OBD_COUNTER_INCREMENT(obdx, op) \
315 if ((obdx)->obd_stats) { \
316 unsigned int coffset; \
317 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
318 OBD_COUNTER_OFFSET(op); \
319 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
320 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
323 #define EXP_COUNTER_INCREMENT(export, op) \
324 if ((export)->exp_obd->obd_stats) { \
325 unsigned int coffset; \
326 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
327 OBD_COUNTER_OFFSET(op); \
328 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
329 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
332 #define MD_COUNTER_OFFSET(op) \
333 ((offsetof(struct md_ops, op) - \
334 offsetof(struct md_ops, getstatus)) \
335 / sizeof(((struct md_ops *)(0))->getstatus))
337 #define MD_COUNTER_INCREMENT(obdx, op) \
338 if ((obd)->md_stats) { \
339 unsigned int coffset; \
340 coffset = (unsigned int)((obdx)->md_cntr_base) + \
341 MD_COUNTER_OFFSET(op); \
342 LASSERT(coffset < (obdx)->md_stats->ls_num); \
343 lprocfs_counter_incr((obdx)->md_stats, coffset); \
346 #define EXP_MD_COUNTER_INCREMENT(export, op) \
347 if ((export)->exp_obd->obd_stats) { \
348 unsigned int coffset; \
349 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
350 MD_COUNTER_OFFSET(op); \
351 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
352 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
353 if ((export)->exp_md_stats) \
354 lprocfs_counter_incr( \
355 (export)->exp_md_stats, coffset); \
358 #define EXP_CHECK_MD_OP(exp, op) \
361 CERROR("obd_" #op ": NULL export\n"); \
364 if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) { \
365 CERROR("obd_" #op ": cleaned up obd\n"); \
366 return -EOPNOTSUPP; \
368 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
369 CERROR("obd_" #op ": dev %s/%d no operation\n", \
370 (exp)->exp_obd->obd_name, \
371 (exp)->exp_obd->obd_minor); \
372 return -EOPNOTSUPP; \
376 #define OBD_CHECK_DT_OP(obd, op, err) \
378 if (!OBT(obd) || !OBP((obd), op)) { \
380 CERROR("obd_" #op ": dev %d no operation\n", \
386 #define EXP_CHECK_DT_OP(exp, op) \
389 CERROR("obd_" #op ": NULL export\n"); \
392 if (!(exp)->exp_obd || !OBT((exp)->exp_obd)) { \
393 CERROR("obd_" #op ": cleaned up obd\n"); \
394 return -EOPNOTSUPP; \
396 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
397 CERROR("obd_" #op ": dev %d no operation\n", \
398 (exp)->exp_obd->obd_minor); \
399 return -EOPNOTSUPP; \
403 #define CTXT_CHECK_OP(ctxt, op, err) \
405 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
407 CERROR("lop_" #op ": dev %d no operation\n", \
408 ctxt->loc_obd->obd_minor); \
413 static inline int class_devno_max(void)
415 return MAX_OBD_DEVICES;
418 static inline int obd_get_info(const struct lu_env *env,
419 struct obd_export *exp, __u32 keylen,
420 void *key, __u32 *vallen, void *val,
421 struct lov_stripe_md *lsm)
425 EXP_CHECK_DT_OP(exp, get_info);
426 EXP_COUNTER_INCREMENT(exp, get_info);
428 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val,
433 static inline int obd_set_info_async(const struct lu_env *env,
434 struct obd_export *exp, u32 keylen,
435 void *key, u32 vallen, void *val,
436 struct ptlrpc_request_set *set)
440 EXP_CHECK_DT_OP(exp, set_info_async);
441 EXP_COUNTER_INCREMENT(exp, set_info_async);
443 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
449 * obd-lu integration.
451 * Functionality is being moved into new lu_device-based layering, but some
452 * pieces of configuration process are still based on obd devices.
454 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
455 * subsume ->o_setup() methods of obd devices they replace. The same for
456 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
457 * result, obd_setup() and obd_process_config() branch and call one XOR
460 * Yet neither lu_device_type_operations::ldto_device_fini() nor
461 * lu_device_type_operations::ldto_device_free() fully implement the
462 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
463 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
466 #define DECLARE_LU_VARS(ldt, d) \
467 struct lu_device_type *ldt; \
470 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
473 DECLARE_LU_VARS(ldt, d);
475 ldt = obd->obd_type->typ_lu;
477 struct lu_context session_ctx;
480 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
481 session_ctx.lc_thread = NULL;
482 lu_context_enter(&session_ctx);
484 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
486 env.le_ses = &session_ctx;
487 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
497 lu_context_exit(&session_ctx);
498 lu_context_fini(&session_ctx);
501 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
502 OBD_COUNTER_INCREMENT(obd, setup);
503 rc = OBP(obd, setup)(obd, cfg);
508 static inline int obd_precleanup(struct obd_device *obd,
509 enum obd_cleanup_stage cleanup_stage)
512 DECLARE_LU_VARS(ldt, d);
514 rc = obd_check_dev(obd);
517 ldt = obd->obd_type->typ_lu;
520 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
523 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
525 ldt->ldt_ops->ldto_device_fini(&env, d);
530 OBD_CHECK_DT_OP(obd, precleanup, 0);
531 OBD_COUNTER_INCREMENT(obd, precleanup);
533 rc = OBP(obd, precleanup)(obd, cleanup_stage);
537 static inline int obd_cleanup(struct obd_device *obd)
540 DECLARE_LU_VARS(ldt, d);
542 rc = obd_check_dev(obd);
546 ldt = obd->obd_type->typ_lu;
551 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
553 ldt->ldt_ops->ldto_device_free(&env, d);
555 obd->obd_lu_dev = NULL;
558 OBD_CHECK_DT_OP(obd, cleanup, 0);
559 OBD_COUNTER_INCREMENT(obd, cleanup);
561 rc = OBP(obd, cleanup)(obd);
565 static inline void obd_cleanup_client_import(struct obd_device *obd)
567 /* If we set up but never connected, the
568 * client import will not have been cleaned.
570 down_write(&obd->u.cli.cl_sem);
571 if (obd->u.cli.cl_import) {
572 struct obd_import *imp;
574 imp = obd->u.cli.cl_import;
575 CDEBUG(D_CONFIG, "%s: client import never connected\n",
577 ptlrpc_invalidate_import(imp);
578 client_destroy_import(imp);
579 obd->u.cli.cl_import = NULL;
581 up_write(&obd->u.cli.cl_sem);
585 obd_process_config(struct obd_device *obd, int datalen, void *data)
588 DECLARE_LU_VARS(ldt, d);
590 rc = obd_check_dev(obd);
594 obd->obd_process_conf = 1;
595 ldt = obd->obd_type->typ_lu;
600 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
602 rc = d->ld_ops->ldo_process_config(&env, d, data);
606 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
607 rc = OBP(obd, process_config)(obd, datalen, data);
609 OBD_COUNTER_INCREMENT(obd, process_config);
610 obd->obd_process_conf = 0;
615 /* Pack an in-memory MD struct for storage on disk.
616 * Returns +ve size of packed MD (0 for free), or -ve error.
618 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
619 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
620 * If @*disk_tgt == NULL, it will be allocated
622 static inline int obd_packmd(struct obd_export *exp,
623 struct lov_mds_md **disk_tgt,
624 struct lov_stripe_md *mem_src)
628 EXP_CHECK_DT_OP(exp, packmd);
629 EXP_COUNTER_INCREMENT(exp, packmd);
631 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
635 static inline int obd_size_diskmd(struct obd_export *exp,
636 struct lov_stripe_md *mem_src)
638 return obd_packmd(exp, NULL, mem_src);
641 static inline int obd_free_diskmd(struct obd_export *exp,
642 struct lov_mds_md **disk_tgt)
647 * LU-2590, for caller's convenience, *disk_tgt could be host
648 * endianness, it needs swab to LE if necessary, while just
649 * lov_mds_md header needs it for figuring out how much memory
652 if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
653 (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
654 ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
655 lustre_swab_lov_mds_md(*disk_tgt);
656 return obd_packmd(exp, disk_tgt, NULL);
659 /* Unpack an MD struct from disk to in-memory format.
660 * Returns +ve size of unpacked MD (0 for free), or -ve error.
662 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
663 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
664 * If @*mem_tgt == NULL, it will be allocated
666 static inline int obd_unpackmd(struct obd_export *exp,
667 struct lov_stripe_md **mem_tgt,
668 struct lov_mds_md *disk_src,
673 EXP_CHECK_DT_OP(exp, unpackmd);
674 EXP_COUNTER_INCREMENT(exp, unpackmd);
676 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
680 /* helper functions */
681 static inline int obd_alloc_memmd(struct obd_export *exp,
682 struct lov_stripe_md **mem_tgt)
686 return obd_unpackmd(exp, mem_tgt, NULL, 0);
689 static inline int obd_free_memmd(struct obd_export *exp,
690 struct lov_stripe_md **mem_tgt)
696 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
701 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
702 struct obdo *obdo, struct lov_stripe_md **ea,
703 struct obd_trans_info *oti)
707 EXP_CHECK_DT_OP(exp, create);
708 EXP_COUNTER_INCREMENT(exp, create);
710 rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti);
714 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
715 struct obdo *obdo, struct lov_stripe_md *ea,
716 struct obd_trans_info *oti,
717 struct obd_export *md_exp)
721 EXP_CHECK_DT_OP(exp, destroy);
722 EXP_COUNTER_INCREMENT(exp, destroy);
724 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp);
728 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
729 struct obd_info *oinfo)
733 EXP_CHECK_DT_OP(exp, getattr);
734 EXP_COUNTER_INCREMENT(exp, getattr);
736 rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo);
740 static inline int obd_getattr_async(struct obd_export *exp,
741 struct obd_info *oinfo,
742 struct ptlrpc_request_set *set)
746 EXP_CHECK_DT_OP(exp, getattr_async);
747 EXP_COUNTER_INCREMENT(exp, getattr_async);
749 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
753 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
754 struct obd_info *oinfo,
755 struct obd_trans_info *oti)
759 EXP_CHECK_DT_OP(exp, setattr);
760 EXP_COUNTER_INCREMENT(exp, setattr);
762 rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
766 /* This performs all the requests set init/wait/destroy actions. */
767 static inline int obd_setattr_rqset(struct obd_export *exp,
768 struct obd_info *oinfo,
769 struct obd_trans_info *oti)
771 struct ptlrpc_request_set *set = NULL;
774 EXP_CHECK_DT_OP(exp, setattr_async);
775 EXP_COUNTER_INCREMENT(exp, setattr_async);
777 set = ptlrpc_prep_set();
781 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
783 rc = ptlrpc_set_wait(set);
784 ptlrpc_set_destroy(set);
788 /* This adds all the requests into @set if @set != NULL, otherwise
789 * all requests are sent asynchronously without waiting for response.
791 static inline int obd_setattr_async(struct obd_export *exp,
792 struct obd_info *oinfo,
793 struct obd_trans_info *oti,
794 struct ptlrpc_request_set *set)
798 EXP_CHECK_DT_OP(exp, setattr_async);
799 EXP_COUNTER_INCREMENT(exp, setattr_async);
801 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
805 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
808 struct obd_device *obd = imp->imp_obd;
811 rc = obd_check_dev_active(obd);
814 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
815 OBD_COUNTER_INCREMENT(obd, add_conn);
817 rc = OBP(obd, add_conn)(imp, uuid, priority);
821 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
823 struct obd_device *obd = imp->imp_obd;
826 rc = obd_check_dev_active(obd);
829 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
830 OBD_COUNTER_INCREMENT(obd, del_conn);
832 rc = OBP(obd, del_conn)(imp, uuid);
836 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
838 struct obd_uuid *uuid;
840 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
841 EXP_COUNTER_INCREMENT(exp, get_uuid);
843 uuid = OBP(exp->exp_obd, get_uuid)(exp);
847 /** Create a new /a exp on device /a obd for the uuid /a cluuid
848 * @param exp New export handle
849 * @param d Connect data, supported flags are set, flags also understood
850 * by obd are returned.
852 static inline int obd_connect(const struct lu_env *env,
853 struct obd_export **exp, struct obd_device *obd,
854 struct obd_uuid *cluuid,
855 struct obd_connect_data *data,
859 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
863 rc = obd_check_dev_active(obd);
866 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
867 OBD_COUNTER_INCREMENT(obd, connect);
869 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
870 /* check that only subset is granted */
871 LASSERT(ergo(data, (data->ocd_connect_flags & ocf) ==
872 data->ocd_connect_flags));
876 static inline int obd_reconnect(const struct lu_env *env,
877 struct obd_export *exp,
878 struct obd_device *obd,
879 struct obd_uuid *cluuid,
880 struct obd_connect_data *d,
884 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
886 rc = obd_check_dev_active(obd);
889 OBD_CHECK_DT_OP(obd, reconnect, 0);
890 OBD_COUNTER_INCREMENT(obd, reconnect);
892 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
893 /* check that only subset is granted */
894 LASSERT(ergo(d, (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
898 static inline int obd_disconnect(struct obd_export *exp)
902 EXP_CHECK_DT_OP(exp, disconnect);
903 EXP_COUNTER_INCREMENT(exp, disconnect);
905 rc = OBP(exp->exp_obd, disconnect)(exp);
909 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
910 enum lu_cli_type type)
914 OBD_CHECK_DT_OP(obd, fid_init, 0);
915 OBD_COUNTER_INCREMENT(obd, fid_init);
917 rc = OBP(obd, fid_init)(obd, exp, type);
921 static inline int obd_fid_fini(struct obd_device *obd)
925 OBD_CHECK_DT_OP(obd, fid_fini, 0);
926 OBD_COUNTER_INCREMENT(obd, fid_fini);
928 rc = OBP(obd, fid_fini)(obd);
932 static inline int obd_fid_alloc(struct obd_export *exp,
934 struct md_op_data *op_data)
938 EXP_CHECK_DT_OP(exp, fid_alloc);
939 EXP_COUNTER_INCREMENT(exp, fid_alloc);
941 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
945 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
949 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
950 OBD_COUNTER_INCREMENT(obd, pool_new);
952 rc = OBP(obd, pool_new)(obd, poolname);
956 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
960 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
961 OBD_COUNTER_INCREMENT(obd, pool_del);
963 rc = OBP(obd, pool_del)(obd, poolname);
967 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
971 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
972 OBD_COUNTER_INCREMENT(obd, pool_add);
974 rc = OBP(obd, pool_add)(obd, poolname, ostname);
978 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
982 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
983 OBD_COUNTER_INCREMENT(obd, pool_rem);
985 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
989 static inline void obd_getref(struct obd_device *obd)
991 if (OBT(obd) && OBP(obd, getref)) {
992 OBD_COUNTER_INCREMENT(obd, getref);
993 OBP(obd, getref)(obd);
997 static inline void obd_putref(struct obd_device *obd)
999 if (OBT(obd) && OBP(obd, putref)) {
1000 OBD_COUNTER_INCREMENT(obd, putref);
1001 OBP(obd, putref)(obd);
1005 static inline int obd_init_export(struct obd_export *exp)
1009 if ((exp)->exp_obd && OBT((exp)->exp_obd) &&
1010 OBP((exp)->exp_obd, init_export))
1011 rc = OBP(exp->exp_obd, init_export)(exp);
1015 static inline int obd_destroy_export(struct obd_export *exp)
1017 if ((exp)->exp_obd && OBT((exp)->exp_obd) &&
1018 OBP((exp)->exp_obd, destroy_export))
1019 OBP(exp->exp_obd, destroy_export)(exp);
1023 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1024 * If the cache is older than @max_age we will get a new value from the
1025 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness.
1027 static inline int obd_statfs_async(struct obd_export *exp,
1028 struct obd_info *oinfo,
1030 struct ptlrpc_request_set *rqset)
1033 struct obd_device *obd;
1035 if (!exp || !exp->exp_obd)
1039 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1040 OBD_COUNTER_INCREMENT(obd, statfs);
1042 CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n",
1043 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1044 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1045 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1048 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1049 obd->obd_name, &obd->obd_osfs,
1050 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1051 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1052 spin_lock(&obd->obd_osfs_lock);
1053 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1054 spin_unlock(&obd->obd_osfs_lock);
1055 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1056 if (oinfo->oi_cb_up)
1057 oinfo->oi_cb_up(oinfo, 0);
1062 static inline int obd_statfs_rqset(struct obd_export *exp,
1063 struct obd_statfs *osfs, __u64 max_age,
1066 struct ptlrpc_request_set *set = NULL;
1067 struct obd_info oinfo = { };
1070 set = ptlrpc_prep_set();
1074 oinfo.oi_osfs = osfs;
1075 oinfo.oi_flags = flags;
1076 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1078 rc = ptlrpc_set_wait(set);
1079 ptlrpc_set_destroy(set);
1083 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1084 * If the cache is older than @max_age we will get a new value from the
1085 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness.
1087 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1088 struct obd_statfs *osfs, __u64 max_age,
1092 struct obd_device *obd = exp->exp_obd;
1097 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1098 OBD_COUNTER_INCREMENT(obd, statfs);
1100 CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n",
1101 obd->obd_osfs_age, max_age);
1102 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1103 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1105 spin_lock(&obd->obd_osfs_lock);
1106 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1107 obd->obd_osfs_age = cfs_time_current_64();
1108 spin_unlock(&obd->obd_osfs_lock);
1111 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1112 obd->obd_name, &obd->obd_osfs,
1113 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1114 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1115 spin_lock(&obd->obd_osfs_lock);
1116 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1117 spin_unlock(&obd->obd_osfs_lock);
1122 static inline int obd_preprw(const struct lu_env *env, int cmd,
1123 struct obd_export *exp, struct obdo *oa,
1124 int objcount, struct obd_ioobj *obj,
1125 struct niobuf_remote *remote, int *pages,
1126 struct niobuf_local *local,
1127 struct obd_trans_info *oti)
1131 EXP_CHECK_DT_OP(exp, preprw);
1132 EXP_COUNTER_INCREMENT(exp, preprw);
1134 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1139 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1140 struct obd_export *exp, struct obdo *oa,
1141 int objcount, struct obd_ioobj *obj,
1142 struct niobuf_remote *rnb, int pages,
1143 struct niobuf_local *local,
1144 struct obd_trans_info *oti, int rc)
1146 EXP_CHECK_DT_OP(exp, commitrw);
1147 EXP_COUNTER_INCREMENT(exp, commitrw);
1149 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1150 rnb, pages, local, oti, rc);
1154 static inline int obd_adjust_kms(struct obd_export *exp,
1155 struct lov_stripe_md *lsm, u64 size,
1160 EXP_CHECK_DT_OP(exp, adjust_kms);
1161 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1163 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1167 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1168 int len, void *karg, void __user *uarg)
1172 EXP_CHECK_DT_OP(exp, iocontrol);
1173 EXP_COUNTER_INCREMENT(exp, iocontrol);
1175 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1179 static inline int obd_find_cbdata(struct obd_export *exp,
1180 struct lov_stripe_md *lsm,
1181 ldlm_iterator_t it, void *data)
1185 EXP_CHECK_DT_OP(exp, find_cbdata);
1186 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1188 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1192 static inline void obd_import_event(struct obd_device *obd,
1193 struct obd_import *imp,
1194 enum obd_import_event event)
1197 CERROR("NULL device\n");
1200 if (obd->obd_set_up && OBP(obd, import_event)) {
1201 OBD_COUNTER_INCREMENT(obd, import_event);
1202 OBP(obd, import_event)(obd, imp, event);
1206 static inline int obd_notify(struct obd_device *obd,
1207 struct obd_device *watched,
1208 enum obd_notify_event ev,
1213 rc = obd_check_dev(obd);
1217 /* the check for async_recov is a complete hack - I'm hereby
1218 * overloading the meaning to also mean "this was called from
1219 * mds_postsetup". I know that my mds is able to handle notifies
1220 * by this point, and it needs to get them to execute mds_postrecov.
1222 if (!obd->obd_set_up && !obd->obd_async_recov) {
1223 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1227 if (!OBP(obd, notify)) {
1228 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1232 OBD_COUNTER_INCREMENT(obd, notify);
1233 rc = OBP(obd, notify)(obd, watched, ev, data);
1237 static inline int obd_notify_observer(struct obd_device *observer,
1238 struct obd_device *observed,
1239 enum obd_notify_event ev,
1245 struct obd_notify_upcall *onu;
1247 if (observer->obd_observer)
1248 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1252 * Also, call non-obd listener, if any
1254 onu = &observer->obd_upcall;
1255 if (onu->onu_upcall)
1256 rc2 = onu->onu_upcall(observer, observed, ev,
1257 onu->onu_owner, NULL);
1261 return rc1 ? rc1 : rc2;
1264 static inline int obd_quotacheck(struct obd_export *exp,
1265 struct obd_quotactl *oqctl)
1269 EXP_CHECK_DT_OP(exp, quotacheck);
1270 EXP_COUNTER_INCREMENT(exp, quotacheck);
1272 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1276 static inline int obd_quotactl(struct obd_export *exp,
1277 struct obd_quotactl *oqctl)
1281 EXP_CHECK_DT_OP(exp, quotactl);
1282 EXP_COUNTER_INCREMENT(exp, quotactl);
1284 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1288 static inline int obd_health_check(const struct lu_env *env,
1289 struct obd_device *obd)
1291 /* returns: 0 on healthy
1292 * >0 on unhealthy + reason code/flag
1293 * however the only supported reason == 1 right now
1294 * We'll need to define some better reasons
1295 * or flags in the future.
1300 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1301 if (!obd || !OBT(obd)) {
1302 CERROR("cleaned up obd\n");
1305 if (!obd->obd_set_up || obd->obd_stopping)
1307 if (!OBP(obd, health_check))
1310 rc = OBP(obd, health_check)(env, obd);
1314 static inline int obd_register_observer(struct obd_device *obd,
1315 struct obd_device *observer)
1319 rc = obd_check_dev(obd);
1322 down_write(&obd->obd_observer_link_sem);
1323 if (obd->obd_observer && observer) {
1324 up_write(&obd->obd_observer_link_sem);
1327 obd->obd_observer = observer;
1328 up_write(&obd->obd_observer_link_sem);
1332 /* metadata helpers */
1333 static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid)
1337 EXP_CHECK_MD_OP(exp, getstatus);
1338 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1339 rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1343 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1344 struct ptlrpc_request **request)
1348 EXP_CHECK_MD_OP(exp, getattr);
1349 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1350 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1354 static inline int md_null_inode(struct obd_export *exp,
1355 const struct lu_fid *fid)
1359 EXP_CHECK_MD_OP(exp, null_inode);
1360 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1361 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1365 static inline int md_find_cbdata(struct obd_export *exp,
1366 const struct lu_fid *fid,
1367 ldlm_iterator_t it, void *data)
1371 EXP_CHECK_MD_OP(exp, find_cbdata);
1372 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1373 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1377 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1378 struct md_open_data *mod,
1379 struct ptlrpc_request **request)
1383 EXP_CHECK_MD_OP(exp, close);
1384 EXP_MD_COUNTER_INCREMENT(exp, close);
1385 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1389 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1390 const void *data, int datalen, int mode, __u32 uid,
1391 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1392 struct ptlrpc_request **request)
1396 EXP_CHECK_MD_OP(exp, create);
1397 EXP_MD_COUNTER_INCREMENT(exp, create);
1398 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1399 uid, gid, cap_effective, rdev, request);
1403 static inline int md_done_writing(struct obd_export *exp,
1404 struct md_op_data *op_data,
1405 struct md_open_data *mod)
1409 EXP_CHECK_MD_OP(exp, done_writing);
1410 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1411 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1415 static inline int md_enqueue(struct obd_export *exp,
1416 struct ldlm_enqueue_info *einfo,
1417 struct lookup_intent *it,
1418 struct md_op_data *op_data,
1419 struct lustre_handle *lockh,
1420 void *lmm, int lmmsize,
1421 struct ptlrpc_request **req,
1422 __u64 extra_lock_flags)
1426 EXP_CHECK_MD_OP(exp, enqueue);
1427 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1428 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1429 lmm, lmmsize, req, extra_lock_flags);
1433 static inline int md_getattr_name(struct obd_export *exp,
1434 struct md_op_data *op_data,
1435 struct ptlrpc_request **request)
1439 EXP_CHECK_MD_OP(exp, getattr_name);
1440 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1441 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1445 static inline int md_intent_lock(struct obd_export *exp,
1446 struct md_op_data *op_data, void *lmm,
1447 int lmmsize, struct lookup_intent *it,
1448 int lookup_flags, struct ptlrpc_request **reqp,
1449 ldlm_blocking_callback cb_blocking,
1450 __u64 extra_lock_flags)
1454 EXP_CHECK_MD_OP(exp, intent_lock);
1455 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1456 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1457 it, lookup_flags, reqp, cb_blocking,
1462 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1463 struct ptlrpc_request **request)
1467 EXP_CHECK_MD_OP(exp, link);
1468 EXP_MD_COUNTER_INCREMENT(exp, link);
1469 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1473 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1474 const char *old, int oldlen, const char *new,
1475 int newlen, struct ptlrpc_request **request)
1479 EXP_CHECK_MD_OP(exp, rename);
1480 EXP_MD_COUNTER_INCREMENT(exp, rename);
1481 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1486 static inline int md_is_subdir(struct obd_export *exp,
1487 const struct lu_fid *pfid,
1488 const struct lu_fid *cfid,
1489 struct ptlrpc_request **request)
1493 EXP_CHECK_MD_OP(exp, is_subdir);
1494 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1495 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1499 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1500 void *ea, int ealen, void *ea2, int ea2len,
1501 struct ptlrpc_request **request,
1502 struct md_open_data **mod)
1506 EXP_CHECK_MD_OP(exp, setattr);
1507 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1508 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1509 ea2, ea2len, request, mod);
1513 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1514 struct ptlrpc_request **request)
1518 EXP_CHECK_MD_OP(exp, sync);
1519 EXP_MD_COUNTER_INCREMENT(exp, sync);
1520 rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1524 static inline int md_readpage(struct obd_export *exp, struct md_op_data *opdata,
1525 struct page **pages,
1526 struct ptlrpc_request **request)
1530 EXP_CHECK_MD_OP(exp, readpage);
1531 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1532 rc = MDP(exp->exp_obd, readpage)(exp, opdata, pages, request);
1536 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1537 struct ptlrpc_request **request)
1541 EXP_CHECK_MD_OP(exp, unlink);
1542 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1543 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1547 static inline int md_get_lustre_md(struct obd_export *exp,
1548 struct ptlrpc_request *req,
1549 struct obd_export *dt_exp,
1550 struct obd_export *md_exp,
1551 struct lustre_md *md)
1553 EXP_CHECK_MD_OP(exp, get_lustre_md);
1554 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1555 return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md);
1558 static inline int md_free_lustre_md(struct obd_export *exp,
1559 struct lustre_md *md)
1561 EXP_CHECK_MD_OP(exp, free_lustre_md);
1562 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1563 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1566 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1567 u64 valid, const char *name,
1568 const char *input, int input_size,
1569 int output_size, int flags, __u32 suppgid,
1570 struct ptlrpc_request **request)
1572 EXP_CHECK_MD_OP(exp, setxattr);
1573 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1574 return MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1575 input_size, output_size, flags,
1579 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1580 u64 valid, const char *name,
1581 const char *input, int input_size,
1582 int output_size, int flags,
1583 struct ptlrpc_request **request)
1585 EXP_CHECK_MD_OP(exp, getxattr);
1586 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1587 return MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1588 input_size, output_size, flags,
1592 static inline int md_set_open_replay_data(struct obd_export *exp,
1593 struct obd_client_handle *och,
1594 struct lookup_intent *it)
1596 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1597 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1598 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1601 static inline int md_clear_open_replay_data(struct obd_export *exp,
1602 struct obd_client_handle *och)
1604 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1605 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1606 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1609 static inline int md_set_lock_data(struct obd_export *exp,
1610 __u64 *lockh, void *data, __u64 *bits)
1612 EXP_CHECK_MD_OP(exp, set_lock_data);
1613 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1614 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1617 static inline int md_cancel_unused(struct obd_export *exp,
1618 const struct lu_fid *fid,
1619 ldlm_policy_data_t *policy,
1620 enum ldlm_mode mode,
1621 enum ldlm_cancel_flags flags,
1626 EXP_CHECK_MD_OP(exp, cancel_unused);
1627 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1629 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1634 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1635 const struct lu_fid *fid,
1636 enum ldlm_type type,
1637 ldlm_policy_data_t *policy,
1638 enum ldlm_mode mode,
1639 struct lustre_handle *lockh)
1641 EXP_CHECK_MD_OP(exp, lock_match);
1642 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1643 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1644 policy, mode, lockh);
1647 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1648 int def_asize, int cookiesize,
1651 EXP_CHECK_MD_OP(exp, init_ea_size);
1652 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1653 return MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1654 cookiesize, def_cookiesize);
1657 static inline int md_get_remote_perm(struct obd_export *exp,
1658 const struct lu_fid *fid, __u32 suppgid,
1659 struct ptlrpc_request **request)
1661 EXP_CHECK_MD_OP(exp, get_remote_perm);
1662 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1663 return MDP(exp->exp_obd, get_remote_perm)(exp, fid, suppgid,
1667 static inline int md_intent_getattr_async(struct obd_export *exp,
1668 struct md_enqueue_info *minfo,
1669 struct ldlm_enqueue_info *einfo)
1673 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1674 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1675 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
1679 static inline int md_revalidate_lock(struct obd_export *exp,
1680 struct lookup_intent *it,
1681 struct lu_fid *fid, __u64 *bits)
1685 EXP_CHECK_MD_OP(exp, revalidate_lock);
1686 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1687 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1691 /* OBD Metadata Support */
1693 int obd_init_caches(void);
1694 void obd_cleanup_caches(void);
1696 /* support routines */
1697 extern struct kmem_cache *obdo_cachep;
1699 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
1701 /* something here */
1704 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
1706 /* something here */
1709 typedef int (*register_lwp_cb)(void *data);
1711 struct lwp_register_item {
1712 struct obd_export **lri_exp;
1713 register_lwp_cb lri_cb_func;
1715 struct list_head lri_list;
1716 char lri_name[MTI_NAME_MAXLEN];
1719 /* I'm as embarrassed about this as you are.
1721 * <shaver> // XXX do not look into _superhack with remaining eye
1722 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV
1724 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1729 int obd_sysctl_init(void);
1732 typedef __u8 class_uuid_t[16];
1733 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1736 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1737 int class_add_uuid(const char *uuid, __u64 nid);
1738 int class_del_uuid(const char *uuid);
1739 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1740 void class_init_uuidlist(void);
1741 void class_exit_uuidlist(void);
1744 extern char obd_jobid_node[];
1745 extern struct miscdevice obd_psdev;
1746 extern spinlock_t obd_types_lock;
1749 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1751 #endif /* __LINUX_OBD_CLASS_H */