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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2016, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
36 #include <obd_support.h>
37 #include <lustre_import.h>
38 #include <lustre_net.h>
40 #include <lustre_lib.h>
41 #include <lustre/lustre_idl.h>
42 #include <lprocfs_status.h>
44 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
45 * and resends for avoid deadlocks */
46 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
48 #define OBD_STATFS_FOR_MDT0 0x0004 /* The statfs is only for retrieving
49 * information from MDT0. */
51 /* OBD Device Declarations */
52 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
53 extern struct list_head obd_types;
54 extern spinlock_t obd_types_lock;
55 extern rwlock_t obd_dev_lock;
57 /* OBD Operations Declarations */
58 extern struct obd_device *class_conn2obd(struct lustre_handle *);
59 extern struct obd_device *class_exp2obd(struct obd_export *);
60 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
61 extern int lustre_get_jobid(char *jobid);
63 struct lu_device_type;
66 struct obd_export *class_conn2export(struct lustre_handle *);
67 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
68 struct lprocfs_vars *module_vars,
69 const char *nm, struct lu_device_type *ldt);
70 int class_unregister_type(const char *nm);
72 struct obd_device *class_newdev(const char *type_name, const char *name);
73 void class_release_dev(struct obd_device *obd);
75 int class_name2dev(const char *name);
76 struct obd_device *class_name2obd(const char *name);
77 int class_uuid2dev(struct obd_uuid *uuid);
78 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
79 void class_obd_list(void);
80 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
81 const char * typ_name,
82 struct obd_uuid *grp_uuid);
83 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
85 struct obd_device * class_num2obd(int num);
86 int get_devices_count(void);
88 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
90 char *obd_export_nid2str(struct obd_export *exp);
92 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
93 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
94 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
97 int obd_zombie_impexp_init(void);
98 void obd_zombie_impexp_stop(void);
99 void obd_zombie_impexp_cull(void);
100 void obd_zombie_barrier(void);
101 void obd_exports_barrier(struct obd_device *obd);
102 int kuc_len(int payload_len);
103 struct kuc_hdr * kuc_ptr(void *p);
104 void *kuc_alloc(int payload_len, int transport, int type);
105 void kuc_free(void *p, int payload_len);
106 int obd_get_request_slot(struct client_obd *cli);
107 void obd_put_request_slot(struct client_obd *cli);
108 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
109 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
110 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
111 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
112 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
114 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
115 struct lookup_intent *it);
116 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
117 struct lookup_intent *it, __u16 tag);
121 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
122 struct llog_rec_hdr *, void *);
124 extern atomic_t obd_stale_export_num;
125 extern struct list_head obd_stale_exports;
126 extern spinlock_t obd_stale_export_lock;
128 struct obd_export *obd_stale_export_get(void);
129 void obd_stale_export_put(struct obd_export *exp);
130 void obd_stale_export_adjust(struct obd_export *exp);
133 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
134 const char *new_name);
135 int class_process_config(struct lustre_cfg *lcfg);
136 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
137 struct lustre_cfg *lcfg, void *data);
138 int class_attach(struct lustre_cfg *lcfg);
139 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
140 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
141 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
142 struct obd_device *class_incref(struct obd_device *obd,
143 const char *scope, const void *source);
144 void class_decref(struct obd_device *obd,
145 const char *scope, const void *source);
146 void dump_exports(struct obd_device *obd, int locks, int debug_level);
147 int class_config_llog_handler(const struct lu_env *env,
148 struct llog_handle *handle,
149 struct llog_rec_hdr *rec, void *data);
150 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
151 int class_add_uuid(const char *uuid, __u64 nid);
153 #define CFG_F_START 0x01 /* Set when we start updating from a log */
154 #define CFG_F_MARKER 0x02 /* We are within a maker */
155 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
156 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
157 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
159 /* Passed as data param to class_config_parse_llog */
160 struct config_llog_instance {
163 struct super_block *cfg_sb;
164 struct obd_uuid cfg_uuid;
165 llog_cb_t cfg_callback;
166 int cfg_last_idx; /* for partial llog processing */
170 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
171 char *name, struct config_llog_instance *cfg);
175 CONFIG_T_SPTLRPC = 1,
176 CONFIG_T_RECOVER = 2,
178 CONFIG_T_NODEMAP = 4,
182 #define PARAMS_FILENAME "params"
183 #define LCTL_UPCALL "lctl"
185 /* list of active configuration logs */
186 struct config_llog_data {
187 struct ldlm_res_id cld_resid;
188 struct config_llog_instance cld_cfg;
189 struct list_head cld_list_chain;
190 atomic_t cld_refcount;
191 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
192 struct config_llog_data *cld_params; /* common parameters log */
193 struct config_llog_data *cld_recover;/* imperative recover log */
194 struct config_llog_data *cld_nodemap;/* nodemap log */
195 struct obd_export *cld_mgcexp;
196 struct mutex cld_lock;
198 unsigned int cld_stopping:1, /* we were told to stop
200 cld_lostlock:1; /* lock not requeued */
204 struct lustre_profile {
205 struct list_head lp_list;
210 bool lp_list_deleted;
213 struct lustre_profile *class_get_profile(const char * prof);
214 void class_del_profile(const char *prof);
215 void class_put_profile(struct lustre_profile *lprof);
216 void class_del_profiles(void);
219 #if LUSTRE_TRACKS_LOCK_EXP_REFS
221 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
222 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
223 extern void (*class_export_dump_hook)(struct obd_export *);
227 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
228 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
232 #define class_export_rpc_inc(exp) \
234 atomic_inc(&(exp)->exp_rpc_count); \
235 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
236 (exp), atomic_read(&(exp)->exp_rpc_count)); \
239 #define class_export_rpc_dec(exp) \
241 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
242 atomic_dec(&(exp)->exp_rpc_count); \
243 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
244 (exp), atomic_read(&(exp)->exp_rpc_count)); \
247 #define class_export_lock_get(exp, lock) \
249 atomic_inc(&(exp)->exp_locks_count); \
250 __class_export_add_lock_ref(exp, lock); \
251 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
252 (exp), atomic_read(&(exp)->exp_locks_count)); \
253 class_export_get(exp); \
256 #define class_export_lock_put(exp, lock) \
258 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
259 atomic_dec(&(exp)->exp_locks_count); \
260 __class_export_del_lock_ref(exp, lock); \
261 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
262 (exp), atomic_read(&(exp)->exp_locks_count)); \
263 class_export_put(exp); \
266 #define class_export_cb_get(exp) \
268 atomic_inc(&(exp)->exp_cb_count); \
269 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
270 (exp), atomic_read(&(exp)->exp_cb_count)); \
271 class_export_get(exp); \
274 #define class_export_cb_put(exp) \
276 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
277 atomic_dec(&(exp)->exp_cb_count); \
278 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
279 (exp), atomic_read(&(exp)->exp_cb_count)); \
280 class_export_put(exp); \
284 struct obd_export *class_export_get(struct obd_export *exp);
285 void class_export_put(struct obd_export *exp);
286 struct obd_export *class_new_export(struct obd_device *obddev,
287 struct obd_uuid *cluuid);
288 void class_unlink_export(struct obd_export *exp);
290 struct obd_import *class_import_get(struct obd_import *);
291 void class_import_put(struct obd_import *);
292 struct obd_import *class_new_import(struct obd_device *obd);
293 void class_destroy_import(struct obd_import *exp);
295 struct obd_type *class_search_type(const char *name);
296 struct obd_type *class_get_type(const char *name);
297 void class_put_type(struct obd_type *type);
298 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
299 struct obd_uuid *cluuid);
300 int class_disconnect(struct obd_export *exp);
301 void class_fail_export(struct obd_export *exp);
302 int class_connected_export(struct obd_export *exp);
303 void class_disconnect_exports(struct obd_device *obddev);
304 int class_manual_cleanup(struct obd_device *obd);
305 void class_disconnect_stale_exports(struct obd_device *,
306 int (*test_export)(struct obd_export *));
307 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
309 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
310 (obd->obd_force ? OBD_OPT_FORCE : 0) |
311 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
315 #ifdef HAVE_SERVER_SUPPORT
316 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
318 LASSERT(exp->exp_obd);
319 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
321 return exp->exp_obd->u.obt.obt_lut;
324 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
326 LASSERT(obd->u.obt.obt_lut);
327 return &obd->u.obt.obt_lut->lut_lsd;
335 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
336 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
338 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
339 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
341 #define OBT(dev) (dev)->obd_type
342 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
343 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
344 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
346 /* Ensure obd_setup: used for cleanup which must be called
347 while obd is stopping */
348 #define OBD_CHECK_DEV(obd) \
351 CERROR("NULL device\n"); \
356 /* ensure obd_setup and !obd_stopping */
357 #define OBD_CHECK_DEV_ACTIVE(obd) \
359 OBD_CHECK_DEV(obd); \
360 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
361 CERROR("Device %d not setup\n", \
368 #ifdef CONFIG_PROC_FS
369 #define OBD_COUNTER_OFFSET(op) \
370 ((offsetof(struct obd_ops, o_ ## op) - \
371 offsetof(struct obd_ops, o_iocontrol)) \
372 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
374 /* The '- 1' below is for o_owner. */
375 #define NUM_OBD_STATS \
376 (sizeof(struct obd_ops) / \
377 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
379 #define OBD_COUNTER_INCREMENT(obd, op) \
380 lprocfs_counter_incr((obd)->obd_stats, \
381 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
383 #define EXP_COUNTER_INCREMENT(exp, op) \
386 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
387 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
388 if ((exp)->exp_obd->obd_uses_nid_stats && \
389 (exp)->exp_nid_stats != NULL) \
390 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
394 #define _MD_COUNTER_OFFSET(m_op) \
395 ((offsetof(struct md_ops, m_op) - \
396 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
397 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
399 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
401 #define NUM_MD_STATS \
402 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
403 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
405 /* Note that we only increment md counters for ops whose offset is less
406 * than NUM_MD_STATS. This is explained in a comment in the definition
407 * of struct md_ops. */
408 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
410 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
411 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
412 (exp)->exp_obd->obd_md_cntr_base + \
413 MD_COUNTER_OFFSET(op)); \
417 #define OBD_COUNTER_OFFSET(op)
418 #define OBD_COUNTER_INCREMENT(obd, op)
419 #define EXP_COUNTER_INCREMENT(exp, op)
420 #define EXP_MD_COUNTER_INCREMENT(exp, op)
423 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
425 /* Always add in ldlm_stats */
426 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
427 ,LPROCFS_STATS_FLAG_NOPERCPU);
428 if (tmp->nid_ldlm_stats == NULL)
431 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
433 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
434 tmp->nid_ldlm_stats);
437 #define EXP_CHECK_MD_OP(exp, op) \
439 if ((exp) == NULL) { \
440 CERROR("obd_" #op ": NULL export\n"); \
443 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
444 CERROR("obd_" #op ": cleaned up obd\n"); \
445 RETURN(-EOPNOTSUPP); \
447 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
448 CERROR("obd_" #op ": dev %s/%d no operation\n", \
449 (exp)->exp_obd->obd_name, \
450 (exp)->exp_obd->obd_minor); \
451 RETURN(-EOPNOTSUPP); \
456 #define OBD_CHECK_DT_OP(obd, op, err) \
458 if (!OBT(obd) || !OBP((obd), op)) { \
460 CERROR("obd_" #op ": dev %d no operation\n", \
466 #define EXP_CHECK_DT_OP(exp, op) \
468 if ((exp) == NULL) { \
469 CERROR("obd_" #op ": NULL export\n"); \
472 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
473 CERROR("obd_" #op ": cleaned up obd\n"); \
474 RETURN(-EOPNOTSUPP); \
476 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
477 CERROR("obd_" #op ": dev %d no operation\n", \
478 (exp)->exp_obd->obd_minor); \
479 RETURN(-EOPNOTSUPP); \
483 #define CTXT_CHECK_OP(ctxt, op, err) \
485 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
487 CERROR("lop_" #op ": dev %d no operation\n", \
488 ctxt->loc_obd->obd_minor); \
493 static inline int class_devno_max(void)
495 return MAX_OBD_DEVICES;
498 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
499 __u32 keylen, void *key,
500 __u32 *vallen, void *val)
505 EXP_CHECK_DT_OP(exp, get_info);
506 EXP_COUNTER_INCREMENT(exp, get_info);
508 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
512 static inline int obd_set_info_async(const struct lu_env *env,
513 struct obd_export *exp,
514 __u32 keylen, void *key,
515 __u32 vallen, void *val,
516 struct ptlrpc_request_set *set)
521 EXP_CHECK_DT_OP(exp, set_info_async);
522 EXP_COUNTER_INCREMENT(exp, set_info_async);
524 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
530 * obd-lu integration.
532 * Functionality is being moved into new lu_device-based layering, but some
533 * pieces of configuration process are still based on obd devices.
535 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
536 * subsume ->o_setup() methods of obd devices they replace. The same for
537 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
538 * result, obd_setup() and obd_process_config() branch and call one XOR
541 * Yet neither lu_device_type_operations::ldto_device_fini() nor
542 * lu_device_type_operations::ldto_device_free() fully implement the
543 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
544 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
547 #define DECLARE_LU_VARS(ldt, d) \
548 struct lu_device_type *ldt; \
551 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
554 DECLARE_LU_VARS(ldt, d);
557 ldt = obd->obd_type->typ_lu;
559 struct lu_context session_ctx;
561 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
562 session_ctx.lc_thread = NULL;
563 lu_context_enter(&session_ctx);
565 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
567 env.le_ses = &session_ctx;
568 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
577 lu_context_exit(&session_ctx);
578 lu_context_fini(&session_ctx);
581 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
582 OBD_COUNTER_INCREMENT(obd, setup);
583 rc = OBP(obd, setup)(obd, cfg);
588 static inline int obd_precleanup(struct obd_device *obd)
591 DECLARE_LU_VARS(ldt, d);
595 ldt = obd->obd_type->typ_lu;
597 if (ldt != NULL && d != NULL) {
600 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
602 ldt->ldt_ops->ldto_device_fini(&env, d);
606 OBD_CHECK_DT_OP(obd, precleanup, 0);
607 OBD_COUNTER_INCREMENT(obd, precleanup);
609 rc = OBP(obd, precleanup)(obd);
613 static inline int obd_cleanup(struct obd_device *obd)
616 DECLARE_LU_VARS(ldt, d);
621 ldt = obd->obd_type->typ_lu;
623 if (ldt != NULL && d != NULL) {
626 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
628 ldt->ldt_ops->ldto_device_free(&env, d);
630 obd->obd_lu_dev = NULL;
633 OBD_CHECK_DT_OP(obd, cleanup, 0);
634 OBD_COUNTER_INCREMENT(obd, cleanup);
636 rc = OBP(obd, cleanup)(obd);
640 static inline void obd_cleanup_client_import(struct obd_device *obd)
644 /* If we set up but never connected, the
645 client import will not have been cleaned. */
646 down_write(&obd->u.cli.cl_sem);
647 if (obd->u.cli.cl_import) {
648 struct obd_import *imp;
649 imp = obd->u.cli.cl_import;
650 CDEBUG(D_CONFIG, "%s: client import never connected\n",
652 ptlrpc_invalidate_import(imp);
653 client_destroy_import(imp);
654 obd->u.cli.cl_import = NULL;
656 up_write(&obd->u.cli.cl_sem);
662 obd_process_config(struct obd_device *obd, int datalen, void *data)
665 DECLARE_LU_VARS(ldt, d);
670 obd->obd_process_conf = 1;
671 ldt = obd->obd_type->typ_lu;
673 if (ldt != NULL && d != NULL) {
676 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
678 rc = d->ld_ops->ldo_process_config(&env, d, data);
682 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
683 rc = OBP(obd, process_config)(obd, datalen, data);
685 OBD_COUNTER_INCREMENT(obd, process_config);
686 obd->obd_process_conf = 0;
691 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
697 EXP_CHECK_DT_OP(exp, create);
698 EXP_COUNTER_INCREMENT(exp, create);
700 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
704 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
710 EXP_CHECK_DT_OP(exp, destroy);
711 EXP_COUNTER_INCREMENT(exp, destroy);
713 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
717 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
723 EXP_CHECK_DT_OP(exp, getattr);
724 EXP_COUNTER_INCREMENT(exp, getattr);
725 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
730 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
736 EXP_CHECK_DT_OP(exp, setattr);
737 EXP_COUNTER_INCREMENT(exp, setattr);
738 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
743 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
746 struct obd_device *obd = imp->imp_obd;
750 OBD_CHECK_DEV_ACTIVE(obd);
751 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
752 OBD_COUNTER_INCREMENT(obd, add_conn);
754 rc = OBP(obd, add_conn)(imp, uuid, priority);
758 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
760 struct obd_device *obd = imp->imp_obd;
764 OBD_CHECK_DEV_ACTIVE(obd);
765 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
766 OBD_COUNTER_INCREMENT(obd, del_conn);
768 rc = OBP(obd, del_conn)(imp, uuid);
772 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
774 struct obd_uuid *uuid;
777 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
778 EXP_COUNTER_INCREMENT(exp, get_uuid);
780 uuid = OBP(exp->exp_obd, get_uuid)(exp);
784 /** Create a new /a exp on device /a obd for the uuid /a cluuid
785 * @param exp New export handle
786 * @param d Connect data, supported flags are set, flags also understood
787 * by obd are returned.
789 static inline int obd_connect(const struct lu_env *env,
790 struct obd_export **exp,struct obd_device *obd,
791 struct obd_uuid *cluuid,
792 struct obd_connect_data *data,
796 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
800 OBD_CHECK_DEV_ACTIVE(obd);
801 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
802 OBD_COUNTER_INCREMENT(obd, connect);
804 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
805 /* check that only subset is granted */
806 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
807 data->ocd_connect_flags));
811 static inline int obd_reconnect(const struct lu_env *env,
812 struct obd_export *exp,
813 struct obd_device *obd,
814 struct obd_uuid *cluuid,
815 struct obd_connect_data *d,
819 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
824 OBD_CHECK_DEV_ACTIVE(obd);
825 OBD_CHECK_DT_OP(obd, reconnect, 0);
826 OBD_COUNTER_INCREMENT(obd, reconnect);
828 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
829 /* check that only subset is granted */
830 LASSERT(ergo(d != NULL,
831 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
835 static inline int obd_disconnect(struct obd_export *exp)
840 EXP_CHECK_DT_OP(exp, disconnect);
841 EXP_COUNTER_INCREMENT(exp, disconnect);
843 rc = OBP(exp->exp_obd, disconnect)(exp);
847 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
848 enum lu_cli_type type)
853 OBD_CHECK_DT_OP(obd, fid_init, 0);
854 OBD_COUNTER_INCREMENT(obd, fid_init);
856 rc = OBP(obd, fid_init)(obd, exp, type);
860 static inline int obd_fid_fini(struct obd_device *obd)
865 OBD_CHECK_DT_OP(obd, fid_fini, 0);
866 OBD_COUNTER_INCREMENT(obd, fid_fini);
868 rc = OBP(obd, fid_fini)(obd);
872 static inline int obd_fid_alloc(const struct lu_env *env,
873 struct obd_export *exp,
875 struct md_op_data *op_data)
880 EXP_CHECK_DT_OP(exp, fid_alloc);
881 EXP_COUNTER_INCREMENT(exp, fid_alloc);
883 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
887 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
892 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
893 EXP_COUNTER_INCREMENT(exp, ping);
895 rc = OBP(exp->exp_obd, ping)(env, exp);
899 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
904 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
905 OBD_COUNTER_INCREMENT(obd, pool_new);
907 rc = OBP(obd, pool_new)(obd, poolname);
911 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
916 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
917 OBD_COUNTER_INCREMENT(obd, pool_del);
919 rc = OBP(obd, pool_del)(obd, poolname);
923 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
928 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
929 OBD_COUNTER_INCREMENT(obd, pool_add);
931 rc = OBP(obd, pool_add)(obd, poolname, ostname);
935 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
940 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
941 OBD_COUNTER_INCREMENT(obd, pool_rem);
943 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
947 static inline void obd_getref(struct obd_device *obd)
950 if (OBT(obd) && OBP(obd, getref)) {
951 OBD_COUNTER_INCREMENT(obd, getref);
952 OBP(obd, getref)(obd);
957 static inline void obd_putref(struct obd_device *obd)
960 if (OBT(obd) && OBP(obd, putref)) {
961 OBD_COUNTER_INCREMENT(obd, putref);
962 OBP(obd, putref)(obd);
967 static inline int obd_init_export(struct obd_export *exp)
972 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
973 OBP((exp)->exp_obd, init_export))
974 rc = OBP(exp->exp_obd, init_export)(exp);
978 static inline int obd_destroy_export(struct obd_export *exp)
981 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
982 OBP((exp)->exp_obd, destroy_export))
983 OBP(exp->exp_obd, destroy_export)(exp);
987 /* @max_age is the oldest time in jiffies that we accept using a cached data.
988 * If the cache is older than @max_age we will get a new value from the
989 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
990 static inline int obd_statfs_async(struct obd_export *exp,
991 struct obd_info *oinfo,
993 struct ptlrpc_request_set *rqset)
996 struct obd_device *obd;
999 if (exp == NULL || exp->exp_obd == NULL)
1003 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1004 OBD_COUNTER_INCREMENT(obd, statfs);
1006 CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n",
1007 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1008 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1009 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1011 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1012 obd->obd_name, &obd->obd_osfs,
1013 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1014 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1015 spin_lock(&obd->obd_osfs_lock);
1016 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1017 spin_unlock(&obd->obd_osfs_lock);
1018 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1019 if (oinfo->oi_cb_up)
1020 oinfo->oi_cb_up(oinfo, 0);
1025 static inline int obd_statfs_rqset(struct obd_export *exp,
1026 struct obd_statfs *osfs, __u64 max_age,
1029 struct ptlrpc_request_set *set = NULL;
1030 struct obd_info oinfo = {
1038 set = ptlrpc_prep_set();
1042 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1044 rc = ptlrpc_set_wait(set);
1046 ptlrpc_set_destroy(set);
1051 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1052 * If the cache is older than @max_age we will get a new value from the
1053 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1054 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1055 struct obd_statfs *osfs, __u64 max_age,
1059 struct obd_device *obd = exp->exp_obd;
1065 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1066 OBD_COUNTER_INCREMENT(obd, statfs);
1068 CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n",
1069 obd->obd_osfs_age, max_age);
1070 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1071 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1073 spin_lock(&obd->obd_osfs_lock);
1074 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1075 obd->obd_osfs_age = cfs_time_current_64();
1076 spin_unlock(&obd->obd_osfs_lock);
1079 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu"
1080 " objects %llu/%llu\n",
1081 obd->obd_name, &obd->obd_osfs,
1082 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1083 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1084 spin_lock(&obd->obd_osfs_lock);
1085 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1086 spin_unlock(&obd->obd_osfs_lock);
1091 static inline int obd_preprw(const struct lu_env *env, int cmd,
1092 struct obd_export *exp, struct obdo *oa,
1093 int objcount, struct obd_ioobj *obj,
1094 struct niobuf_remote *remote, int *pages,
1095 struct niobuf_local *local)
1100 EXP_CHECK_DT_OP(exp, preprw);
1101 EXP_COUNTER_INCREMENT(exp, preprw);
1102 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1108 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1109 struct obd_export *exp, struct obdo *oa,
1110 int objcount, struct obd_ioobj *obj,
1111 struct niobuf_remote *rnb, int pages,
1112 struct niobuf_local *local, int rc)
1116 EXP_CHECK_DT_OP(exp, commitrw);
1117 EXP_COUNTER_INCREMENT(exp, commitrw);
1118 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1119 rnb, pages, local, rc);
1124 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1125 int len, void *karg, void __user *uarg)
1130 EXP_CHECK_DT_OP(exp, iocontrol);
1131 EXP_COUNTER_INCREMENT(exp, iocontrol);
1133 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1137 static inline void obd_import_event(struct obd_device *obd,
1138 struct obd_import *imp,
1139 enum obd_import_event event)
1143 CERROR("NULL device\n");
1147 if (obd->obd_set_up && OBP(obd, import_event)) {
1148 OBD_COUNTER_INCREMENT(obd, import_event);
1149 OBP(obd, import_event)(obd, imp, event);
1154 static inline int obd_notify(struct obd_device *obd,
1155 struct obd_device *watched,
1156 enum obd_notify_event ev,
1163 if (!obd->obd_set_up) {
1164 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1168 if (!OBP(obd, notify)) {
1169 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1173 OBD_COUNTER_INCREMENT(obd, notify);
1174 rc = OBP(obd, notify)(obd, watched, ev, data);
1178 static inline int obd_notify_observer(struct obd_device *observer,
1179 struct obd_device *observed,
1180 enum obd_notify_event ev,
1186 struct obd_notify_upcall *onu;
1188 if (observer->obd_observer)
1189 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1193 * Also, call non-obd listener, if any
1195 onu = &observer->obd_upcall;
1196 if (onu->onu_upcall != NULL)
1197 rc2 = onu->onu_upcall(observer, observed, ev,
1198 onu->onu_owner, NULL);
1202 return rc1 ? rc1 : rc2;
1205 static inline int obd_quotactl(struct obd_export *exp,
1206 struct obd_quotactl *oqctl)
1211 EXP_CHECK_DT_OP(exp, quotactl);
1212 EXP_COUNTER_INCREMENT(exp, quotactl);
1214 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1218 static inline int obd_health_check(const struct lu_env *env,
1219 struct obd_device *obd)
1221 /* returns: 0 on healthy
1222 * >0 on unhealthy + reason code/flag
1223 * however the only suppored reason == 1 right now
1224 * We'll need to define some better reasons
1225 * or flags in the future.
1231 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1232 if (obd == NULL || !OBT(obd)) {
1233 CERROR("cleaned up obd\n");
1234 RETURN(-EOPNOTSUPP);
1236 if (!obd->obd_set_up || obd->obd_stopping)
1238 if (!OBP(obd, health_check))
1241 rc = OBP(obd, health_check)(env, obd);
1245 static inline int obd_register_observer(struct obd_device *obd,
1246 struct obd_device *observer)
1250 down_write(&obd->obd_observer_link_sem);
1251 if (obd->obd_observer && observer) {
1252 up_write(&obd->obd_observer_link_sem);
1255 obd->obd_observer = observer;
1256 up_write(&obd->obd_observer_link_sem);
1260 /* metadata helpers */
1261 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1267 EXP_CHECK_MD_OP(exp, get_root);
1268 EXP_MD_COUNTER_INCREMENT(exp, get_root);
1269 rc = MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1274 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1275 struct ptlrpc_request **request)
1279 EXP_CHECK_MD_OP(exp, getattr);
1280 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1281 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1285 static inline int md_null_inode(struct obd_export *exp,
1286 const struct lu_fid *fid)
1290 EXP_CHECK_MD_OP(exp, null_inode);
1291 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1292 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1296 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1297 struct md_open_data *mod,
1298 struct ptlrpc_request **request)
1302 EXP_CHECK_MD_OP(exp, close);
1303 EXP_MD_COUNTER_INCREMENT(exp, close);
1304 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1308 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1309 const void *data, size_t datalen, umode_t mode,
1310 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1311 __u64 rdev, struct ptlrpc_request **request)
1315 EXP_CHECK_MD_OP(exp, create);
1316 EXP_MD_COUNTER_INCREMENT(exp, create);
1317 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1318 uid, gid, cap_effective, rdev, request);
1322 static inline int md_enqueue(struct obd_export *exp,
1323 struct ldlm_enqueue_info *einfo,
1324 const union ldlm_policy_data *policy,
1325 struct md_op_data *op_data,
1326 struct lustre_handle *lockh,
1327 __u64 extra_lock_flags)
1331 EXP_CHECK_MD_OP(exp, enqueue);
1332 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1333 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1338 static inline int md_getattr_name(struct obd_export *exp,
1339 struct md_op_data *op_data,
1340 struct ptlrpc_request **request)
1344 EXP_CHECK_MD_OP(exp, getattr_name);
1345 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1346 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1350 static inline int md_intent_lock(struct obd_export *exp,
1351 struct md_op_data *op_data,
1352 struct lookup_intent *it,
1353 struct ptlrpc_request **reqp,
1354 ldlm_blocking_callback cb_blocking,
1355 __u64 extra_lock_flags)
1359 EXP_CHECK_MD_OP(exp, intent_lock);
1360 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1361 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1366 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1367 struct ptlrpc_request **request)
1371 EXP_CHECK_MD_OP(exp, link);
1372 EXP_MD_COUNTER_INCREMENT(exp, link);
1373 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1377 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1378 const char *old, size_t oldlen, const char *new,
1379 size_t newlen, struct ptlrpc_request **request)
1383 EXP_CHECK_MD_OP(exp, rename);
1384 EXP_MD_COUNTER_INCREMENT(exp, rename);
1385 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1390 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1391 void *ea, size_t ealen,
1392 struct ptlrpc_request **request)
1396 EXP_CHECK_MD_OP(exp, setattr);
1397 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1398 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1402 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1403 struct ptlrpc_request **request)
1408 EXP_CHECK_MD_OP(exp, fsync);
1409 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1410 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1415 static inline int md_read_page(struct obd_export *exp,
1416 struct md_op_data *op_data,
1417 struct md_callback *cb_op,
1419 struct page **ppage)
1423 EXP_CHECK_MD_OP(exp, read_page);
1424 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1425 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1430 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1431 struct ptlrpc_request **request)
1435 EXP_CHECK_MD_OP(exp, unlink);
1436 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1437 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1441 static inline int md_get_lustre_md(struct obd_export *exp,
1442 struct ptlrpc_request *req,
1443 struct obd_export *dt_exp,
1444 struct obd_export *md_exp,
1445 struct lustre_md *md)
1448 EXP_CHECK_MD_OP(exp, get_lustre_md);
1449 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1450 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1453 static inline int md_free_lustre_md(struct obd_export *exp,
1454 struct lustre_md *md)
1457 EXP_CHECK_MD_OP(exp, free_lustre_md);
1458 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1459 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1462 static inline int md_merge_attr(struct obd_export *exp,
1463 const struct lmv_stripe_md *lsm,
1464 struct cl_attr *attr,
1465 ldlm_blocking_callback cb)
1468 EXP_CHECK_MD_OP(exp, merge_attr);
1469 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1470 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1473 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1474 u64 valid, const char *name,
1475 const char *input, int input_size,
1476 int output_size, int flags, __u32 suppgid,
1477 struct ptlrpc_request **request)
1480 EXP_CHECK_MD_OP(exp, setxattr);
1481 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1482 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1483 input_size, output_size, flags,
1487 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1488 u64 valid, const char *name,
1489 const char *input, int input_size,
1490 int output_size, int flags,
1491 struct ptlrpc_request **request)
1494 EXP_CHECK_MD_OP(exp, getxattr);
1495 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1496 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1497 input_size, output_size, flags,
1501 static inline int md_set_open_replay_data(struct obd_export *exp,
1502 struct obd_client_handle *och,
1503 struct lookup_intent *it)
1506 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1507 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1508 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1511 static inline int md_clear_open_replay_data(struct obd_export *exp,
1512 struct obd_client_handle *och)
1515 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1516 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1517 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1520 static inline int md_set_lock_data(struct obd_export *exp,
1521 const struct lustre_handle *lockh,
1522 void *data, __u64 *bits)
1525 EXP_CHECK_MD_OP(exp, set_lock_data);
1526 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1527 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1531 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1532 union ldlm_policy_data *policy, enum ldlm_mode mode,
1533 enum ldlm_cancel_flags cancel_flags, void *opaque)
1538 EXP_CHECK_MD_OP(exp, cancel_unused);
1539 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1541 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1542 cancel_flags, opaque);
1546 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1547 const struct lu_fid *fid,
1548 enum ldlm_type type,
1549 union ldlm_policy_data *policy,
1550 enum ldlm_mode mode,
1551 struct lustre_handle *lockh)
1554 EXP_CHECK_MD_OP(exp, lock_match);
1555 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1556 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1557 policy, mode, lockh));
1560 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1564 EXP_CHECK_MD_OP(exp, init_ea_size);
1565 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1566 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1569 static inline int md_intent_getattr_async(struct obd_export *exp,
1570 struct md_enqueue_info *minfo)
1574 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1575 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1576 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1580 static inline int md_revalidate_lock(struct obd_export *exp,
1581 struct lookup_intent *it,
1582 struct lu_fid *fid, __u64 *bits)
1586 EXP_CHECK_MD_OP(exp, revalidate_lock);
1587 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1588 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1592 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1593 const struct lmv_stripe_md *lsm,
1594 const char *name, int namelen,
1599 EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1600 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1601 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1606 /* Unpack an MD struct from disk to in-memory format.
1607 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1609 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1610 * If *plsm == NULL then it will be allocated.
1612 static inline int md_unpackmd(struct obd_export *exp,
1613 struct lmv_stripe_md **plsm,
1614 const union lmv_mds_md *lmm, size_t lmm_size)
1618 EXP_CHECK_MD_OP(exp, unpackmd);
1619 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1620 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1624 /* OBD Metadata Support */
1626 extern int obd_init_caches(void);
1627 extern void obd_cleanup_caches(void);
1629 /* support routines */
1630 extern struct kmem_cache *obdo_cachep;
1632 #define OBDO_ALLOC(ptr) \
1634 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1637 #define OBDO_FREE(ptr) \
1639 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1643 typedef int (*register_lwp_cb)(void *data);
1645 struct lwp_register_item {
1646 struct obd_export **lri_exp;
1647 register_lwp_cb lri_cb_func;
1649 struct list_head lri_list;
1651 char lri_name[MTI_NAME_MAXLEN];
1654 /* I'm as embarrassed about this as you are.
1656 * <shaver> // XXX do not look into _superhack with remaining eye
1657 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1658 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1661 #ifdef HAVE_SERVER_SUPPORT
1662 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1663 register_lwp_cb cb_func, void *cb_data);
1664 void lustre_deregister_lwp_item(struct obd_export **exp);
1665 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1666 void lustre_notify_lwp_list(struct obd_export *exp);
1667 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1668 #endif /* HAVE_SERVER_SUPPORT */
1669 int lustre_register_fs(void);
1670 int lustre_unregister_fs(void);
1671 int lustre_check_exclusion(struct super_block *sb, char *svname);
1674 extern void obd_sysctl_init (void);
1675 extern void obd_sysctl_clean (void);
1678 typedef __u8 class_uuid_t[16];
1679 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1682 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1683 int class_add_uuid(const char *uuid, __u64 nid);
1684 int class_del_uuid (const char *uuid);
1685 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1686 void class_init_uuidlist(void);
1687 void class_exit_uuidlist(void);
1690 extern char obd_jobid_node[];
1693 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1697 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1698 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1700 /* root squash info */
1701 struct rw_semaphore;
1702 struct root_squash_info {
1705 struct list_head rsi_nosquash_nids;
1706 struct rw_semaphore rsi_sem;
1709 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1711 /* linux-module.c */
1712 extern struct miscdevice obd_psdev;
1713 int class_procfs_init(void);
1714 int class_procfs_clean(void);
1716 #endif /* __LINUX_OBD_CLASS_H */