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.
40 #include <obd_support.h>
41 #include <lustre_import.h>
42 #include <lustre_net.h>
44 #include <lustre_lib.h>
45 #include <lustre/lustre_idl.h>
46 #include <lprocfs_status.h>
48 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
49 * and resends for avoid deadlocks */
50 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
52 #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd
53 * instead of a specific set. This
54 * means that we cannot rely on the set
55 * interpret routine to be called.
56 * lov_statfs_fini() must thus be called
57 * by the request interpret routine */
58 #define OBD_STATFS_FOR_MDT0 0x0008 /* The statfs is only for retrieving
59 * information from MDT0. */
61 /* OBD Device Declarations */
62 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
63 extern struct list_head obd_types;
64 extern spinlock_t obd_types_lock;
65 extern rwlock_t obd_dev_lock;
67 /* OBD Operations Declarations */
68 extern struct obd_device *class_conn2obd(struct lustre_handle *);
69 extern struct obd_device *class_exp2obd(struct obd_export *);
70 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
71 extern int lustre_get_jobid(char *jobid);
73 struct lu_device_type;
76 struct obd_export *class_conn2export(struct lustre_handle *);
77 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
78 struct lprocfs_vars *module_vars,
79 const char *nm, struct lu_device_type *ldt);
80 int class_unregister_type(const char *nm);
82 struct obd_device *class_newdev(const char *type_name, const char *name);
83 void class_release_dev(struct obd_device *obd);
85 int class_name2dev(const char *name);
86 struct obd_device *class_name2obd(const char *name);
87 int class_uuid2dev(struct obd_uuid *uuid);
88 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
89 void class_obd_list(void);
90 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
91 const char * typ_name,
92 struct obd_uuid *grp_uuid);
93 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
95 struct obd_device * class_num2obd(int num);
96 int get_devices_count(void);
98 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
100 char *obd_export_nid2str(struct obd_export *exp);
102 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
103 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
104 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
106 int obd_zombie_impexp_init(void);
107 void obd_zombie_impexp_stop(void);
108 void obd_zombie_impexp_cull(void);
109 void obd_zombie_barrier(void);
110 void obd_exports_barrier(struct obd_device *obd);
111 int kuc_len(int payload_len);
112 struct kuc_hdr * kuc_ptr(void *p);
113 void *kuc_alloc(int payload_len, int transport, int type);
114 void kuc_free(void *p, int payload_len);
115 int obd_get_request_slot(struct client_obd *cli);
116 void obd_put_request_slot(struct client_obd *cli);
117 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
118 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
119 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
120 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
121 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
123 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
124 struct lookup_intent *it);
125 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
126 struct lookup_intent *it, __u16 tag);
130 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
131 struct llog_rec_hdr *, void *);
133 extern atomic_t obd_stale_export_num;
134 extern struct list_head obd_stale_exports;
135 extern spinlock_t obd_stale_export_lock;
137 struct obd_export *obd_stale_export_get(void);
138 void obd_stale_export_put(struct obd_export *exp);
139 void obd_stale_export_adjust(struct obd_export *exp);
142 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
143 const char *new_name);
144 int class_process_config(struct lustre_cfg *lcfg);
145 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
146 struct lustre_cfg *lcfg, void *data);
147 int class_attach(struct lustre_cfg *lcfg);
148 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
149 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
150 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
151 struct obd_device *class_incref(struct obd_device *obd,
152 const char *scope, const void *source);
153 void class_decref(struct obd_device *obd,
154 const char *scope, const void *source);
155 void dump_exports(struct obd_device *obd, int locks);
156 int class_config_llog_handler(const struct lu_env *env,
157 struct llog_handle *handle,
158 struct llog_rec_hdr *rec, void *data);
159 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
160 int class_add_uuid(const char *uuid, __u64 nid);
162 #define CFG_F_START 0x01 /* Set when we start updating from a log */
163 #define CFG_F_MARKER 0x02 /* We are within a maker */
164 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
165 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
166 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
168 /* Passed as data param to class_config_parse_llog */
169 struct config_llog_instance {
172 struct super_block *cfg_sb;
173 struct obd_uuid cfg_uuid;
174 llog_cb_t cfg_callback;
175 int cfg_last_idx; /* for partial llog processing */
179 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
180 char *name, struct config_llog_instance *cfg);
184 CONFIG_T_SPTLRPC = 1,
185 CONFIG_T_RECOVER = 2,
190 #define PARAMS_FILENAME "params"
191 #define LCTL_UPCALL "lctl"
193 /* list of active configuration logs */
194 struct config_llog_data {
195 struct ldlm_res_id cld_resid;
196 struct config_llog_instance cld_cfg;
197 struct list_head cld_list_chain;
198 atomic_t cld_refcount;
199 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
200 struct config_llog_data *cld_params; /* common parameters log */
201 struct config_llog_data *cld_recover;/* imperative recover log */
202 struct obd_export *cld_mgcexp;
203 struct mutex cld_lock;
205 unsigned int cld_stopping:1, /* we were told to stop
207 cld_lostlock:1; /* lock not requeued */
211 struct lustre_profile {
212 struct list_head lp_list;
217 bool lp_list_deleted;
220 struct lustre_profile *class_get_profile(const char * prof);
221 void class_del_profile(const char *prof);
222 void class_put_profile(struct lustre_profile *lprof);
223 void class_del_profiles(void);
226 #if LUSTRE_TRACKS_LOCK_EXP_REFS
228 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
229 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
230 extern void (*class_export_dump_hook)(struct obd_export *);
234 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
235 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
239 #define class_export_rpc_inc(exp) \
241 atomic_inc(&(exp)->exp_rpc_count); \
242 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
243 (exp), atomic_read(&(exp)->exp_rpc_count)); \
246 #define class_export_rpc_dec(exp) \
248 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
249 atomic_dec(&(exp)->exp_rpc_count); \
250 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
251 (exp), atomic_read(&(exp)->exp_rpc_count)); \
254 #define class_export_lock_get(exp, lock) \
256 atomic_inc(&(exp)->exp_locks_count); \
257 __class_export_add_lock_ref(exp, lock); \
258 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
259 (exp), atomic_read(&(exp)->exp_locks_count)); \
260 class_export_get(exp); \
263 #define class_export_lock_put(exp, lock) \
265 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
266 atomic_dec(&(exp)->exp_locks_count); \
267 __class_export_del_lock_ref(exp, lock); \
268 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
269 (exp), atomic_read(&(exp)->exp_locks_count)); \
270 class_export_put(exp); \
273 #define class_export_cb_get(exp) \
275 atomic_inc(&(exp)->exp_cb_count); \
276 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
277 (exp), atomic_read(&(exp)->exp_cb_count)); \
278 class_export_get(exp); \
281 #define class_export_cb_put(exp) \
283 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
284 atomic_dec(&(exp)->exp_cb_count); \
285 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
286 (exp), atomic_read(&(exp)->exp_cb_count)); \
287 class_export_put(exp); \
291 struct obd_export *class_export_get(struct obd_export *exp);
292 void class_export_put(struct obd_export *exp);
293 struct obd_export *class_new_export(struct obd_device *obddev,
294 struct obd_uuid *cluuid);
295 void class_unlink_export(struct obd_export *exp);
297 struct obd_import *class_import_get(struct obd_import *);
298 void class_import_put(struct obd_import *);
299 struct obd_import *class_new_import(struct obd_device *obd);
300 void class_destroy_import(struct obd_import *exp);
302 struct obd_type *class_search_type(const char *name);
303 struct obd_type *class_get_type(const char *name);
304 void class_put_type(struct obd_type *type);
305 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
306 struct obd_uuid *cluuid);
307 int class_disconnect(struct obd_export *exp);
308 void class_fail_export(struct obd_export *exp);
309 int class_connected_export(struct obd_export *exp);
310 void class_disconnect_exports(struct obd_device *obddev);
311 int class_manual_cleanup(struct obd_device *obd);
312 void class_disconnect_stale_exports(struct obd_device *,
313 int (*test_export)(struct obd_export *));
314 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
316 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
317 (obd->obd_force ? OBD_OPT_FORCE : 0) |
318 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
322 #ifdef HAVE_SERVER_SUPPORT
323 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
325 LASSERT(exp->exp_obd);
326 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
328 return exp->exp_obd->u.obt.obt_lut;
331 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
333 LASSERT(obd->u.obt.obt_lut);
334 return &obd->u.obt.obt_lut->lut_lsd;
342 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
343 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
345 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
346 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
348 #define OBT(dev) (dev)->obd_type
349 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
350 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
351 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
353 /* Ensure obd_setup: used for cleanup which must be called
354 while obd is stopping */
355 #define OBD_CHECK_DEV(obd) \
358 CERROR("NULL device\n"); \
363 /* ensure obd_setup and !obd_stopping */
364 #define OBD_CHECK_DEV_ACTIVE(obd) \
366 OBD_CHECK_DEV(obd); \
367 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
368 CERROR("Device %d not setup\n", \
375 #ifdef CONFIG_PROC_FS
376 #define OBD_COUNTER_OFFSET(op) \
377 ((offsetof(struct obd_ops, o_ ## op) - \
378 offsetof(struct obd_ops, o_iocontrol)) \
379 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
381 /* The '- 1' below is for o_owner. */
382 #define NUM_OBD_STATS \
383 (sizeof(struct obd_ops) / \
384 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
386 #define OBD_COUNTER_INCREMENT(obd, op) \
387 lprocfs_counter_incr((obd)->obd_stats, \
388 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
390 #define EXP_COUNTER_INCREMENT(exp, op) \
393 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
394 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
395 if ((exp)->exp_obd->obd_uses_nid_stats && \
396 (exp)->exp_nid_stats != NULL) \
397 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
401 #define _MD_COUNTER_OFFSET(m_op) \
402 ((offsetof(struct md_ops, m_op) - \
403 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
404 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
406 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
408 #define NUM_MD_STATS \
409 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
410 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
412 /* Note that we only increment md counters for ops whose offset is less
413 * than NUM_MD_STATS. This is explained in a comment in the definition
414 * of struct md_ops. */
415 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
417 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
418 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
419 (exp)->exp_obd->obd_md_cntr_base + \
420 MD_COUNTER_OFFSET(op)); \
424 #define OBD_COUNTER_OFFSET(op)
425 #define OBD_COUNTER_INCREMENT(obd, op)
426 #define EXP_COUNTER_INCREMENT(exp, op)
427 #define EXP_MD_COUNTER_INCREMENT(exp, op)
430 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
432 /* Always add in ldlm_stats */
433 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
434 ,LPROCFS_STATS_FLAG_NOPERCPU);
435 if (tmp->nid_ldlm_stats == NULL)
438 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
440 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
441 tmp->nid_ldlm_stats);
444 #define EXP_CHECK_MD_OP(exp, op) \
446 if ((exp) == NULL) { \
447 CERROR("obd_" #op ": NULL export\n"); \
450 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
451 CERROR("obd_" #op ": cleaned up obd\n"); \
452 RETURN(-EOPNOTSUPP); \
454 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
455 CERROR("obd_" #op ": dev %s/%d no operation\n", \
456 (exp)->exp_obd->obd_name, \
457 (exp)->exp_obd->obd_minor); \
458 RETURN(-EOPNOTSUPP); \
463 #define OBD_CHECK_DT_OP(obd, op, err) \
465 if (!OBT(obd) || !OBP((obd), op)) { \
467 CERROR("obd_" #op ": dev %d no operation\n", \
473 #define EXP_CHECK_DT_OP(exp, op) \
475 if ((exp) == NULL) { \
476 CERROR("obd_" #op ": NULL export\n"); \
479 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
480 CERROR("obd_" #op ": cleaned up obd\n"); \
481 RETURN(-EOPNOTSUPP); \
483 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
484 CERROR("obd_" #op ": dev %d no operation\n", \
485 (exp)->exp_obd->obd_minor); \
486 RETURN(-EOPNOTSUPP); \
490 #define CTXT_CHECK_OP(ctxt, op, err) \
492 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
494 CERROR("lop_" #op ": dev %d no operation\n", \
495 ctxt->loc_obd->obd_minor); \
500 static inline int class_devno_max(void)
502 return MAX_OBD_DEVICES;
505 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
506 __u32 keylen, void *key,
507 __u32 *vallen, void *val)
512 EXP_CHECK_DT_OP(exp, get_info);
513 EXP_COUNTER_INCREMENT(exp, get_info);
515 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
519 static inline int obd_set_info_async(const struct lu_env *env,
520 struct obd_export *exp,
521 __u32 keylen, void *key,
522 __u32 vallen, void *val,
523 struct ptlrpc_request_set *set)
528 EXP_CHECK_DT_OP(exp, set_info_async);
529 EXP_COUNTER_INCREMENT(exp, set_info_async);
531 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
537 * obd-lu integration.
539 * Functionality is being moved into new lu_device-based layering, but some
540 * pieces of configuration process are still based on obd devices.
542 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
543 * subsume ->o_setup() methods of obd devices they replace. The same for
544 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
545 * result, obd_setup() and obd_process_config() branch and call one XOR
548 * Yet neither lu_device_type_operations::ldto_device_fini() nor
549 * lu_device_type_operations::ldto_device_free() fully implement the
550 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
551 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
554 #define DECLARE_LU_VARS(ldt, d) \
555 struct lu_device_type *ldt; \
558 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
561 DECLARE_LU_VARS(ldt, d);
564 ldt = obd->obd_type->typ_lu;
566 struct lu_context session_ctx;
568 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
569 session_ctx.lc_thread = NULL;
570 lu_context_enter(&session_ctx);
572 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
574 env.le_ses = &session_ctx;
575 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
584 lu_context_exit(&session_ctx);
585 lu_context_fini(&session_ctx);
588 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
589 OBD_COUNTER_INCREMENT(obd, setup);
590 rc = OBP(obd, setup)(obd, cfg);
595 static inline int obd_precleanup(struct obd_device *obd)
598 DECLARE_LU_VARS(ldt, d);
602 ldt = obd->obd_type->typ_lu;
604 if (ldt != NULL && d != NULL) {
607 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
609 ldt->ldt_ops->ldto_device_fini(&env, d);
613 OBD_CHECK_DT_OP(obd, precleanup, 0);
614 OBD_COUNTER_INCREMENT(obd, precleanup);
616 rc = OBP(obd, precleanup)(obd);
620 static inline int obd_cleanup(struct obd_device *obd)
623 DECLARE_LU_VARS(ldt, d);
628 ldt = obd->obd_type->typ_lu;
630 if (ldt != NULL && d != NULL) {
633 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
635 ldt->ldt_ops->ldto_device_free(&env, d);
637 obd->obd_lu_dev = NULL;
640 OBD_CHECK_DT_OP(obd, cleanup, 0);
641 OBD_COUNTER_INCREMENT(obd, cleanup);
643 rc = OBP(obd, cleanup)(obd);
647 static inline void obd_cleanup_client_import(struct obd_device *obd)
651 /* If we set up but never connected, the
652 client import will not have been cleaned. */
653 down_write(&obd->u.cli.cl_sem);
654 if (obd->u.cli.cl_import) {
655 struct obd_import *imp;
656 imp = obd->u.cli.cl_import;
657 CDEBUG(D_CONFIG, "%s: client import never connected\n",
659 ptlrpc_invalidate_import(imp);
660 client_destroy_import(imp);
661 obd->u.cli.cl_import = NULL;
663 up_write(&obd->u.cli.cl_sem);
669 obd_process_config(struct obd_device *obd, int datalen, void *data)
672 DECLARE_LU_VARS(ldt, d);
677 obd->obd_process_conf = 1;
678 ldt = obd->obd_type->typ_lu;
680 if (ldt != NULL && d != NULL) {
683 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
685 rc = d->ld_ops->ldo_process_config(&env, d, data);
689 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
690 rc = OBP(obd, process_config)(obd, datalen, data);
692 OBD_COUNTER_INCREMENT(obd, process_config);
693 obd->obd_process_conf = 0;
698 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
704 EXP_CHECK_DT_OP(exp, create);
705 EXP_COUNTER_INCREMENT(exp, create);
707 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
711 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
717 EXP_CHECK_DT_OP(exp, destroy);
718 EXP_COUNTER_INCREMENT(exp, destroy);
720 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
724 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
730 EXP_CHECK_DT_OP(exp, getattr);
731 EXP_COUNTER_INCREMENT(exp, getattr);
732 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
737 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
743 EXP_CHECK_DT_OP(exp, setattr);
744 EXP_COUNTER_INCREMENT(exp, setattr);
745 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
750 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
753 struct obd_device *obd = imp->imp_obd;
757 OBD_CHECK_DEV_ACTIVE(obd);
758 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
759 OBD_COUNTER_INCREMENT(obd, add_conn);
761 rc = OBP(obd, add_conn)(imp, uuid, priority);
765 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
767 struct obd_device *obd = imp->imp_obd;
771 OBD_CHECK_DEV_ACTIVE(obd);
772 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
773 OBD_COUNTER_INCREMENT(obd, del_conn);
775 rc = OBP(obd, del_conn)(imp, uuid);
779 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
781 struct obd_uuid *uuid;
784 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
785 EXP_COUNTER_INCREMENT(exp, get_uuid);
787 uuid = OBP(exp->exp_obd, get_uuid)(exp);
791 /** Create a new /a exp on device /a obd for the uuid /a cluuid
792 * @param exp New export handle
793 * @param d Connect data, supported flags are set, flags also understood
794 * by obd are returned.
796 static inline int obd_connect(const struct lu_env *env,
797 struct obd_export **exp,struct obd_device *obd,
798 struct obd_uuid *cluuid,
799 struct obd_connect_data *data,
803 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
807 OBD_CHECK_DEV_ACTIVE(obd);
808 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
809 OBD_COUNTER_INCREMENT(obd, connect);
811 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
812 /* check that only subset is granted */
813 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
814 data->ocd_connect_flags));
818 static inline int obd_reconnect(const struct lu_env *env,
819 struct obd_export *exp,
820 struct obd_device *obd,
821 struct obd_uuid *cluuid,
822 struct obd_connect_data *d,
826 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
831 OBD_CHECK_DEV_ACTIVE(obd);
832 OBD_CHECK_DT_OP(obd, reconnect, 0);
833 OBD_COUNTER_INCREMENT(obd, reconnect);
835 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
836 /* check that only subset is granted */
837 LASSERT(ergo(d != NULL,
838 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
842 static inline int obd_disconnect(struct obd_export *exp)
847 EXP_CHECK_DT_OP(exp, disconnect);
848 EXP_COUNTER_INCREMENT(exp, disconnect);
850 rc = OBP(exp->exp_obd, disconnect)(exp);
854 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
855 enum lu_cli_type type)
860 OBD_CHECK_DT_OP(obd, fid_init, 0);
861 OBD_COUNTER_INCREMENT(obd, fid_init);
863 rc = OBP(obd, fid_init)(obd, exp, type);
867 static inline int obd_fid_fini(struct obd_device *obd)
872 OBD_CHECK_DT_OP(obd, fid_fini, 0);
873 OBD_COUNTER_INCREMENT(obd, fid_fini);
875 rc = OBP(obd, fid_fini)(obd);
879 static inline int obd_fid_alloc(const struct lu_env *env,
880 struct obd_export *exp,
882 struct md_op_data *op_data)
887 EXP_CHECK_DT_OP(exp, fid_alloc);
888 EXP_COUNTER_INCREMENT(exp, fid_alloc);
890 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
894 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
899 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
900 EXP_COUNTER_INCREMENT(exp, ping);
902 rc = OBP(exp->exp_obd, ping)(env, exp);
906 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
911 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
912 OBD_COUNTER_INCREMENT(obd, pool_new);
914 rc = OBP(obd, pool_new)(obd, poolname);
918 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
923 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
924 OBD_COUNTER_INCREMENT(obd, pool_del);
926 rc = OBP(obd, pool_del)(obd, poolname);
930 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
935 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
936 OBD_COUNTER_INCREMENT(obd, pool_add);
938 rc = OBP(obd, pool_add)(obd, poolname, ostname);
942 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
947 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
948 OBD_COUNTER_INCREMENT(obd, pool_rem);
950 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
954 static inline void obd_getref(struct obd_device *obd)
957 if (OBT(obd) && OBP(obd, getref)) {
958 OBD_COUNTER_INCREMENT(obd, getref);
959 OBP(obd, getref)(obd);
964 static inline void obd_putref(struct obd_device *obd)
967 if (OBT(obd) && OBP(obd, putref)) {
968 OBD_COUNTER_INCREMENT(obd, putref);
969 OBP(obd, putref)(obd);
974 static inline int obd_init_export(struct obd_export *exp)
979 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
980 OBP((exp)->exp_obd, init_export))
981 rc = OBP(exp->exp_obd, init_export)(exp);
985 static inline int obd_destroy_export(struct obd_export *exp)
988 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
989 OBP((exp)->exp_obd, destroy_export))
990 OBP(exp->exp_obd, destroy_export)(exp);
994 /* @max_age is the oldest time in jiffies that we accept using a cached data.
995 * If the cache is older than @max_age we will get a new value from the
996 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
997 static inline int obd_statfs_async(struct obd_export *exp,
998 struct obd_info *oinfo,
1000 struct ptlrpc_request_set *rqset)
1003 struct obd_device *obd;
1006 if (exp == NULL || exp->exp_obd == NULL)
1010 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1011 OBD_COUNTER_INCREMENT(obd, statfs);
1013 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1014 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1015 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1016 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1018 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1019 " objects "LPU64"/"LPU64"\n",
1020 obd->obd_name, &obd->obd_osfs,
1021 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1022 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1023 spin_lock(&obd->obd_osfs_lock);
1024 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1025 spin_unlock(&obd->obd_osfs_lock);
1026 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1027 if (oinfo->oi_cb_up)
1028 oinfo->oi_cb_up(oinfo, 0);
1033 static inline int obd_statfs_rqset(struct obd_export *exp,
1034 struct obd_statfs *osfs, __u64 max_age,
1037 struct ptlrpc_request_set *set = NULL;
1038 struct obd_info oinfo = {
1046 set = ptlrpc_prep_set();
1050 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1052 rc = ptlrpc_set_wait(set);
1054 ptlrpc_set_destroy(set);
1059 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1060 * If the cache is older than @max_age we will get a new value from the
1061 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1062 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1063 struct obd_statfs *osfs, __u64 max_age,
1067 struct obd_device *obd = exp->exp_obd;
1073 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1074 OBD_COUNTER_INCREMENT(obd, statfs);
1076 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1077 obd->obd_osfs_age, max_age);
1078 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1079 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1081 spin_lock(&obd->obd_osfs_lock);
1082 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1083 obd->obd_osfs_age = cfs_time_current_64();
1084 spin_unlock(&obd->obd_osfs_lock);
1087 CDEBUG(D_SUPER, "%s: use %p cache blocks "LPU64"/"LPU64
1088 " objects "LPU64"/"LPU64"\n",
1089 obd->obd_name, &obd->obd_osfs,
1090 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1091 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1092 spin_lock(&obd->obd_osfs_lock);
1093 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1094 spin_unlock(&obd->obd_osfs_lock);
1099 static inline int obd_preprw(const struct lu_env *env, int cmd,
1100 struct obd_export *exp, struct obdo *oa,
1101 int objcount, struct obd_ioobj *obj,
1102 struct niobuf_remote *remote, int *pages,
1103 struct niobuf_local *local)
1108 EXP_CHECK_DT_OP(exp, preprw);
1109 EXP_COUNTER_INCREMENT(exp, preprw);
1110 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1116 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1117 struct obd_export *exp, struct obdo *oa,
1118 int objcount, struct obd_ioobj *obj,
1119 struct niobuf_remote *rnb, int pages,
1120 struct niobuf_local *local, int rc)
1124 EXP_CHECK_DT_OP(exp, commitrw);
1125 EXP_COUNTER_INCREMENT(exp, commitrw);
1126 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1127 rnb, pages, local, rc);
1132 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1133 int len, void *karg, void __user *uarg)
1138 EXP_CHECK_DT_OP(exp, iocontrol);
1139 EXP_COUNTER_INCREMENT(exp, iocontrol);
1141 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1145 static inline void obd_import_event(struct obd_device *obd,
1146 struct obd_import *imp,
1147 enum obd_import_event event)
1151 CERROR("NULL device\n");
1155 if (obd->obd_set_up && OBP(obd, import_event)) {
1156 OBD_COUNTER_INCREMENT(obd, import_event);
1157 OBP(obd, import_event)(obd, imp, event);
1162 static inline int obd_notify(struct obd_device *obd,
1163 struct obd_device *watched,
1164 enum obd_notify_event ev,
1171 if (!obd->obd_set_up) {
1172 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1176 if (!OBP(obd, notify)) {
1177 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1181 OBD_COUNTER_INCREMENT(obd, notify);
1182 rc = OBP(obd, notify)(obd, watched, ev, data);
1186 static inline int obd_notify_observer(struct obd_device *observer,
1187 struct obd_device *observed,
1188 enum obd_notify_event ev,
1194 struct obd_notify_upcall *onu;
1196 if (observer->obd_observer)
1197 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1201 * Also, call non-obd listener, if any
1203 onu = &observer->obd_upcall;
1204 if (onu->onu_upcall != NULL)
1205 rc2 = onu->onu_upcall(observer, observed, ev,
1206 onu->onu_owner, NULL);
1210 return rc1 ? rc1 : rc2;
1213 static inline int obd_quotactl(struct obd_export *exp,
1214 struct obd_quotactl *oqctl)
1219 EXP_CHECK_DT_OP(exp, quotactl);
1220 EXP_COUNTER_INCREMENT(exp, quotactl);
1222 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1226 static inline int obd_health_check(const struct lu_env *env,
1227 struct obd_device *obd)
1229 /* returns: 0 on healthy
1230 * >0 on unhealthy + reason code/flag
1231 * however the only suppored reason == 1 right now
1232 * We'll need to define some better reasons
1233 * or flags in the future.
1239 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1240 if (obd == NULL || !OBT(obd)) {
1241 CERROR("cleaned up obd\n");
1242 RETURN(-EOPNOTSUPP);
1244 if (!obd->obd_set_up || obd->obd_stopping)
1246 if (!OBP(obd, health_check))
1249 rc = OBP(obd, health_check)(env, obd);
1253 static inline int obd_register_observer(struct obd_device *obd,
1254 struct obd_device *observer)
1258 down_write(&obd->obd_observer_link_sem);
1259 if (obd->obd_observer && observer) {
1260 up_write(&obd->obd_observer_link_sem);
1263 obd->obd_observer = observer;
1264 up_write(&obd->obd_observer_link_sem);
1268 /* metadata helpers */
1269 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1275 EXP_CHECK_MD_OP(exp, getstatus);
1276 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1277 rc = MDP(exp->exp_obd, getstatus)(exp, fileset, fid);
1282 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1283 struct ptlrpc_request **request)
1287 EXP_CHECK_MD_OP(exp, getattr);
1288 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1289 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1293 static inline int md_null_inode(struct obd_export *exp,
1294 const struct lu_fid *fid)
1298 EXP_CHECK_MD_OP(exp, null_inode);
1299 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1300 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1304 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1305 struct md_open_data *mod,
1306 struct ptlrpc_request **request)
1310 EXP_CHECK_MD_OP(exp, close);
1311 EXP_MD_COUNTER_INCREMENT(exp, close);
1312 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1316 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1317 const void *data, size_t datalen, umode_t mode,
1318 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1319 __u64 rdev, struct ptlrpc_request **request)
1323 EXP_CHECK_MD_OP(exp, create);
1324 EXP_MD_COUNTER_INCREMENT(exp, create);
1325 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1326 uid, gid, cap_effective, rdev, request);
1330 static inline int md_enqueue(struct obd_export *exp,
1331 struct ldlm_enqueue_info *einfo,
1332 const union ldlm_policy_data *policy,
1333 struct lookup_intent *it,
1334 struct md_op_data *op_data,
1335 struct lustre_handle *lockh,
1336 __u64 extra_lock_flags)
1340 EXP_CHECK_MD_OP(exp, enqueue);
1341 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1342 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, it, op_data, lockh,
1347 static inline int md_getattr_name(struct obd_export *exp,
1348 struct md_op_data *op_data,
1349 struct ptlrpc_request **request)
1353 EXP_CHECK_MD_OP(exp, getattr_name);
1354 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1355 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1359 static inline int md_intent_lock(struct obd_export *exp,
1360 struct md_op_data *op_data,
1361 struct lookup_intent *it,
1362 struct ptlrpc_request **reqp,
1363 ldlm_blocking_callback cb_blocking,
1364 __u64 extra_lock_flags)
1368 EXP_CHECK_MD_OP(exp, intent_lock);
1369 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1370 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1375 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1376 struct ptlrpc_request **request)
1380 EXP_CHECK_MD_OP(exp, link);
1381 EXP_MD_COUNTER_INCREMENT(exp, link);
1382 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1386 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1387 const char *old, size_t oldlen, const char *new,
1388 size_t newlen, struct ptlrpc_request **request)
1392 EXP_CHECK_MD_OP(exp, rename);
1393 EXP_MD_COUNTER_INCREMENT(exp, rename);
1394 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1399 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1400 void *ea, size_t ealen,
1401 struct ptlrpc_request **request)
1405 EXP_CHECK_MD_OP(exp, setattr);
1406 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1407 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1411 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1412 struct ptlrpc_request **request)
1417 EXP_CHECK_MD_OP(exp, fsync);
1418 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1419 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1424 static inline int md_read_page(struct obd_export *exp,
1425 struct md_op_data *op_data,
1426 struct md_callback *cb_op,
1428 struct page **ppage)
1432 EXP_CHECK_MD_OP(exp, read_page);
1433 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1434 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1439 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1440 struct ptlrpc_request **request)
1444 EXP_CHECK_MD_OP(exp, unlink);
1445 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1446 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1450 static inline int md_get_lustre_md(struct obd_export *exp,
1451 struct ptlrpc_request *req,
1452 struct obd_export *dt_exp,
1453 struct obd_export *md_exp,
1454 struct lustre_md *md)
1457 EXP_CHECK_MD_OP(exp, get_lustre_md);
1458 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1459 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1462 static inline int md_free_lustre_md(struct obd_export *exp,
1463 struct lustre_md *md)
1466 EXP_CHECK_MD_OP(exp, free_lustre_md);
1467 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1468 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1471 static inline int md_merge_attr(struct obd_export *exp,
1472 const struct lmv_stripe_md *lsm,
1473 struct cl_attr *attr,
1474 ldlm_blocking_callback cb)
1477 EXP_CHECK_MD_OP(exp, merge_attr);
1478 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1479 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1482 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1483 u64 valid, const char *name,
1484 const char *input, int input_size,
1485 int output_size, int flags, __u32 suppgid,
1486 struct ptlrpc_request **request)
1489 EXP_CHECK_MD_OP(exp, setxattr);
1490 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1491 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1492 input_size, output_size, flags,
1496 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1497 u64 valid, const char *name,
1498 const char *input, int input_size,
1499 int output_size, int flags,
1500 struct ptlrpc_request **request)
1503 EXP_CHECK_MD_OP(exp, getxattr);
1504 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1505 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1506 input_size, output_size, flags,
1510 static inline int md_set_open_replay_data(struct obd_export *exp,
1511 struct obd_client_handle *och,
1512 struct lookup_intent *it)
1515 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1516 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1517 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1520 static inline int md_clear_open_replay_data(struct obd_export *exp,
1521 struct obd_client_handle *och)
1524 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1525 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1526 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1529 static inline int md_set_lock_data(struct obd_export *exp,
1530 __u64 *lockh, void *data, __u64 *bits)
1533 EXP_CHECK_MD_OP(exp, set_lock_data);
1534 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1535 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1539 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1540 union ldlm_policy_data *policy, enum ldlm_mode mode,
1541 enum ldlm_cancel_flags cancel_flags, void *opaque)
1546 EXP_CHECK_MD_OP(exp, cancel_unused);
1547 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1549 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1550 cancel_flags, opaque);
1554 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1555 const struct lu_fid *fid,
1556 enum ldlm_type type,
1557 union ldlm_policy_data *policy,
1558 enum ldlm_mode mode,
1559 struct lustre_handle *lockh)
1562 EXP_CHECK_MD_OP(exp, lock_match);
1563 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1564 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1565 policy, mode, lockh));
1568 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1572 EXP_CHECK_MD_OP(exp, init_ea_size);
1573 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1574 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1577 static inline int md_get_remote_perm(struct obd_export *exp,
1578 const struct lu_fid *fid, u32 suppgid,
1579 struct ptlrpc_request **request)
1582 EXP_CHECK_MD_OP(exp, get_remote_perm);
1583 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1585 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, suppgid, request));
1588 static inline int md_intent_getattr_async(struct obd_export *exp,
1589 struct md_enqueue_info *minfo)
1593 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1594 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1595 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1599 static inline int md_revalidate_lock(struct obd_export *exp,
1600 struct lookup_intent *it,
1601 struct lu_fid *fid, __u64 *bits)
1605 EXP_CHECK_MD_OP(exp, revalidate_lock);
1606 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1607 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1611 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1612 const struct lmv_stripe_md *lsm,
1613 const char *name, int namelen,
1618 EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1619 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1620 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1625 /* Unpack an MD struct from disk to in-memory format.
1626 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1628 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1629 * If *plsm == NULL then it will be allocated.
1631 static inline int md_unpackmd(struct obd_export *exp,
1632 struct lmv_stripe_md **plsm,
1633 const union lmv_mds_md *lmm, size_t lmm_size)
1637 EXP_CHECK_MD_OP(exp, unpackmd);
1638 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1639 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1643 /* OBD Metadata Support */
1645 extern int obd_init_caches(void);
1646 extern void obd_cleanup_caches(void);
1648 /* support routines */
1649 extern struct kmem_cache *obdo_cachep;
1651 #define OBDO_ALLOC(ptr) \
1653 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1656 #define OBDO_FREE(ptr) \
1658 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1662 typedef int (*register_lwp_cb)(void *data);
1664 struct lwp_register_item {
1665 struct obd_export **lri_exp;
1666 register_lwp_cb lri_cb_func;
1668 struct list_head lri_list;
1669 char lri_name[MTI_NAME_MAXLEN];
1672 /* I'm as embarrassed about this as you are.
1674 * <shaver> // XXX do not look into _superhack with remaining eye
1675 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1676 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1679 #ifdef HAVE_SERVER_SUPPORT
1680 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1681 register_lwp_cb cb_func, void *cb_data);
1682 void lustre_deregister_lwp_item(struct obd_export **exp);
1683 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1684 void lustre_notify_lwp_list(struct obd_export *exp);
1685 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1686 #endif /* HAVE_SERVER_SUPPORT */
1687 int lustre_register_fs(void);
1688 int lustre_unregister_fs(void);
1689 int lustre_check_exclusion(struct super_block *sb, char *svname);
1692 extern void obd_sysctl_init (void);
1693 extern void obd_sysctl_clean (void);
1696 typedef __u8 class_uuid_t[16];
1697 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1700 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1701 int class_add_uuid(const char *uuid, __u64 nid);
1702 int class_del_uuid (const char *uuid);
1703 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1704 void class_init_uuidlist(void);
1705 void class_exit_uuidlist(void);
1708 extern char obd_jobid_node[];
1711 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1715 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1716 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1718 /* root squash info */
1719 struct rw_semaphore;
1720 struct root_squash_info {
1723 struct list_head rsi_nosquash_nids;
1724 struct rw_semaphore rsi_sem;
1727 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1729 /* linux-module.c */
1730 extern struct miscdevice obd_psdev;
1731 int class_procfs_init(void);
1732 int class_procfs_clean(void);
1734 #endif /* __LINUX_OBD_CLASS_H */