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 extern rwlock_t obd_dev_lock;
53 /* OBD Operations Declarations */
54 extern struct obd_device *class_conn2obd(struct lustre_handle *);
55 extern struct obd_device *class_exp2obd(struct obd_export *);
56 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
57 extern int lustre_get_jobid(char *jobid);
59 struct lu_device_type;
62 struct obd_export *class_conn2export(struct lustre_handle *);
63 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
64 struct lprocfs_vars *module_vars,
65 const char *nm, struct lu_device_type *ldt);
66 int class_unregister_type(const char *nm);
68 struct obd_device *class_newdev(const char *type_name, const char *name);
69 void class_release_dev(struct obd_device *obd);
71 int class_name2dev(const char *name);
72 struct obd_device *class_name2obd(const char *name);
73 int class_uuid2dev(struct obd_uuid *uuid);
74 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
75 void class_obd_list(void);
76 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
77 const char * typ_name,
78 struct obd_uuid *grp_uuid);
79 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
81 struct obd_device * class_num2obd(int num);
82 int get_devices_count(void);
84 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
86 char *obd_export_nid2str(struct obd_export *exp);
88 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
89 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
90 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
93 int obd_zombie_impexp_init(void);
94 void obd_zombie_impexp_stop(void);
95 void obd_zombie_impexp_cull(void);
96 void obd_zombie_barrier(void);
97 void obd_exports_barrier(struct obd_device *obd);
98 int kuc_len(int payload_len);
99 struct kuc_hdr * kuc_ptr(void *p);
100 void *kuc_alloc(int payload_len, int transport, int type);
101 void kuc_free(void *p, int payload_len);
102 int obd_get_request_slot(struct client_obd *cli);
103 void obd_put_request_slot(struct client_obd *cli);
104 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
105 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
106 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
107 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
108 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
110 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
111 struct lookup_intent *it);
112 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
113 struct lookup_intent *it, __u16 tag);
117 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
118 struct llog_rec_hdr *, void *);
120 struct obd_export *obd_stale_export_get(void);
121 void obd_stale_export_put(struct obd_export *exp);
122 void obd_stale_export_adjust(struct obd_export *exp);
125 /* For interoperability */
126 struct cfg_interop_param {
131 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
132 const char *new_name);
133 int class_process_config(struct lustre_cfg *lcfg);
134 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
135 struct lustre_cfg *lcfg, void *data);
136 int class_attach(struct lustre_cfg *lcfg);
137 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
138 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
139 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
141 int class_find_param(char *buf, char *key, char **valp);
142 struct cfg_interop_param *class_find_old_param(const char *param,
143 struct cfg_interop_param *ptr);
144 int class_get_next_param(char **params, char *copy);
145 int class_match_param(char *buf, const char *key, char **valp);
146 int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh);
147 int class_parse_nid_quiet(char *buf, lnet_nid_t *nid, char **endh);
148 int class_parse_net(char *buf, u32 *net, char **endh);
149 int class_match_nid(char *buf, char *key, lnet_nid_t nid);
150 int class_match_net(char *buf, char *key, u32 net);
152 struct obd_device *class_incref(struct obd_device *obd,
153 const char *scope, const void *source);
154 void class_decref(struct obd_device *obd,
155 const char *scope, const void *source);
156 void dump_exports(struct obd_device *obd, int locks, int debug_level);
157 int class_config_llog_handler(const struct lu_env *env,
158 struct llog_handle *handle,
159 struct llog_rec_hdr *rec, void *data);
160 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
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 */
180 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
181 char *name, struct config_llog_instance *cfg);
183 #define CONFIG_SUB_SPTLRPC 0x01
184 #define CONFIG_SUB_RECOVER 0x02
185 #define CONFIG_SUB_PARAMS 0x04
186 #define CONFIG_SUB_NODEMAP 0x08
187 #define CONFIG_SUB_BARRIER 0x10
189 /* Sub clds should be attached to the config_llog_data when processing
190 * config log for client or server target. */
191 #define CONFIG_SUB_CLIENT (CONFIG_SUB_SPTLRPC | CONFIG_SUB_RECOVER | \
193 #define CONFIG_SUB_SERVER (CONFIG_SUB_CLIENT | CONFIG_SUB_NODEMAP | \
196 #define PARAMS_FILENAME "params"
197 #define BARRIER_FILENAME "barrier"
198 #define LCTL_UPCALL "lctl"
200 static inline bool logname_is_barrier(const char *logname)
204 /* logname for barrier is "fsname-barrier" */
205 ptr = strstr(logname, BARRIER_FILENAME);
206 if (ptr && (ptr - logname) >= 2 &&
207 *(ptr - 1) == '-' && *(ptr + 7) == '\0')
213 /* list of active configuration logs */
214 struct config_llog_data {
215 struct ldlm_res_id cld_resid;
216 struct config_llog_instance cld_cfg;
217 struct list_head cld_list_chain;
218 atomic_t cld_refcount;
219 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
220 struct config_llog_data *cld_params; /* common parameters log */
221 struct config_llog_data *cld_recover;/* imperative recover log */
222 struct config_llog_data *cld_nodemap;/* nodemap log */
223 struct config_llog_data *cld_barrier;/* barrier log (for MDT only) */
224 struct obd_export *cld_mgcexp;
225 struct mutex cld_lock;
227 unsigned int cld_stopping:1, /* we were told to stop
229 cld_lostlock:1; /* lock not requeued */
233 struct lustre_profile {
234 struct list_head lp_list;
239 bool lp_list_deleted;
242 struct lustre_profile *class_get_profile(const char * prof);
243 void class_del_profile(const char *prof);
244 void class_put_profile(struct lustre_profile *lprof);
245 void class_del_profiles(void);
248 #if LUSTRE_TRACKS_LOCK_EXP_REFS
250 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
251 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
252 extern void (*class_export_dump_hook)(struct obd_export *);
256 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
257 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
261 #define class_export_rpc_inc(exp) \
263 atomic_inc(&(exp)->exp_rpc_count); \
264 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
265 (exp), atomic_read(&(exp)->exp_rpc_count)); \
268 #define class_export_rpc_dec(exp) \
270 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
271 atomic_dec(&(exp)->exp_rpc_count); \
272 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
273 (exp), atomic_read(&(exp)->exp_rpc_count)); \
276 #define class_export_lock_get(exp, lock) \
278 atomic_inc(&(exp)->exp_locks_count); \
279 __class_export_add_lock_ref(exp, lock); \
280 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
281 (exp), atomic_read(&(exp)->exp_locks_count)); \
282 class_export_get(exp); \
285 #define class_export_lock_put(exp, lock) \
287 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
288 atomic_dec(&(exp)->exp_locks_count); \
289 __class_export_del_lock_ref(exp, lock); \
290 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
291 (exp), atomic_read(&(exp)->exp_locks_count)); \
292 class_export_put(exp); \
295 #define class_export_cb_get(exp) \
297 atomic_inc(&(exp)->exp_cb_count); \
298 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
299 (exp), atomic_read(&(exp)->exp_cb_count)); \
300 class_export_get(exp); \
303 #define class_export_cb_put(exp) \
305 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
306 atomic_dec(&(exp)->exp_cb_count); \
307 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
308 (exp), atomic_read(&(exp)->exp_cb_count)); \
309 class_export_put(exp); \
313 struct obd_export *class_export_get(struct obd_export *exp);
314 void class_export_put(struct obd_export *exp);
315 struct obd_export *class_new_export(struct obd_device *obddev,
316 struct obd_uuid *cluuid);
317 void class_unlink_export(struct obd_export *exp);
319 struct obd_import *class_import_get(struct obd_import *);
320 void class_import_put(struct obd_import *);
321 struct obd_import *class_new_import(struct obd_device *obd);
322 void class_destroy_import(struct obd_import *exp);
324 struct obd_type *class_search_type(const char *name);
325 struct obd_type *class_get_type(const char *name);
326 void class_put_type(struct obd_type *type);
327 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
328 struct obd_uuid *cluuid);
329 int class_disconnect(struct obd_export *exp);
330 void class_fail_export(struct obd_export *exp);
331 int class_connected_export(struct obd_export *exp);
332 void class_disconnect_exports(struct obd_device *obddev);
333 int class_manual_cleanup(struct obd_device *obd);
334 void class_disconnect_stale_exports(struct obd_device *,
335 int (*test_export)(struct obd_export *));
336 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
338 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
339 (obd->obd_force ? OBD_OPT_FORCE : 0) |
340 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
344 #ifdef HAVE_SERVER_SUPPORT
345 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
347 LASSERT(exp->exp_obd);
348 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
350 return exp->exp_obd->u.obt.obt_lut;
353 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
355 LASSERT(obd->u.obt.obt_lut);
356 return &obd->u.obt.obt_lut->lut_lsd;
364 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
365 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
367 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
368 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
370 #define OBT(dev) (dev)->obd_type
371 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
372 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
373 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
375 /* Ensure obd_setup: used for cleanup which must be called
376 while obd is stopping */
377 #define OBD_CHECK_DEV(obd) \
380 CERROR("NULL device\n"); \
385 /* ensure obd_setup and !obd_stopping */
386 #define OBD_CHECK_DEV_ACTIVE(obd) \
388 OBD_CHECK_DEV(obd); \
389 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
390 CERROR("Device %d not setup\n", \
397 #ifdef CONFIG_PROC_FS
398 #define OBD_COUNTER_OFFSET(op) \
399 ((offsetof(struct obd_ops, o_ ## op) - \
400 offsetof(struct obd_ops, o_iocontrol)) \
401 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
403 /* The '- 1' below is for o_owner. */
404 #define NUM_OBD_STATS \
405 (sizeof(struct obd_ops) / \
406 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
408 #define OBD_COUNTER_INCREMENT(obd, op) \
409 lprocfs_counter_incr((obd)->obd_stats, \
410 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
412 #define EXP_COUNTER_INCREMENT(exp, op) \
415 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
416 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
417 if ((exp)->exp_obd->obd_uses_nid_stats && \
418 (exp)->exp_nid_stats != NULL) \
419 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
423 #define _MD_COUNTER_OFFSET(m_op) \
424 ((offsetof(struct md_ops, m_op) - \
425 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
426 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
428 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
430 #define NUM_MD_STATS \
431 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
432 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
434 /* Note that we only increment md counters for ops whose offset is less
435 * than NUM_MD_STATS. This is explained in a comment in the definition
436 * of struct md_ops. */
437 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
439 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
440 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
441 (exp)->exp_obd->obd_md_cntr_base + \
442 MD_COUNTER_OFFSET(op)); \
446 #define OBD_COUNTER_OFFSET(op)
447 #define OBD_COUNTER_INCREMENT(obd, op)
448 #define EXP_COUNTER_INCREMENT(exp, op)
449 #define EXP_MD_COUNTER_INCREMENT(exp, op)
452 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
454 /* Always add in ldlm_stats */
455 tmp->nid_ldlm_stats =
456 lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC,
457 LPROCFS_STATS_FLAG_NOPERCPU);
458 if (tmp->nid_ldlm_stats == NULL)
461 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
463 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
464 tmp->nid_ldlm_stats);
467 #define EXP_CHECK_MD_OP(exp, op) \
469 if ((exp) == NULL) { \
470 CERROR("obd_" #op ": NULL export\n"); \
473 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
474 CERROR("obd_" #op ": cleaned up obd\n"); \
475 RETURN(-EOPNOTSUPP); \
477 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
478 CERROR("%s: obd_" #op ": dev %d no operation\n", \
479 (exp)->exp_obd->obd_name, \
480 (exp)->exp_obd->obd_minor); \
481 RETURN(-EOPNOTSUPP); \
486 #define OBD_CHECK_DT_OP(obd, op, err) \
488 if (!OBT(obd) || !OBP((obd), op)) { \
490 CERROR("%s: no obd_" #op " operation\n", \
496 #define EXP_CHECK_DT_OP(exp, op) \
498 if ((exp) == NULL) { \
499 CERROR("obd_" #op ": NULL export\n"); \
502 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
503 CERROR("obd_" #op ": cleaned up obd\n"); \
504 RETURN(-EOPNOTSUPP); \
506 OBD_CHECK_DT_OP((exp)->exp_obd, op, -EOPNOTSUPP); \
509 #define CTXT_CHECK_OP(ctxt, op, err) \
511 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
513 CERROR("%s: no lop_" #op "operation\n", \
514 ctxt->loc_obd->obd_name); \
519 static inline int class_devno_max(void)
521 return MAX_OBD_DEVICES;
524 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
525 __u32 keylen, void *key,
526 __u32 *vallen, void *val)
531 EXP_CHECK_DT_OP(exp, get_info);
532 EXP_COUNTER_INCREMENT(exp, get_info);
534 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
538 static inline int obd_set_info_async(const struct lu_env *env,
539 struct obd_export *exp,
540 __u32 keylen, void *key,
541 __u32 vallen, void *val,
542 struct ptlrpc_request_set *set)
547 EXP_CHECK_DT_OP(exp, set_info_async);
548 EXP_COUNTER_INCREMENT(exp, set_info_async);
550 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
556 * obd-lu integration.
558 * Functionality is being moved into new lu_device-based layering, but some
559 * pieces of configuration process are still based on obd devices.
561 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
562 * subsume ->o_setup() methods of obd devices they replace. The same for
563 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
564 * result, obd_setup() and obd_process_config() branch and call one XOR
567 * Yet neither lu_device_type_operations::ldto_device_fini() nor
568 * lu_device_type_operations::ldto_device_free() fully implement the
569 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
570 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
573 #define DECLARE_LU_VARS(ldt, d) \
574 struct lu_device_type *ldt; \
577 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
580 DECLARE_LU_VARS(ldt, d);
583 ldt = obd->obd_type->typ_lu;
585 struct lu_context session_ctx;
587 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
588 session_ctx.lc_thread = NULL;
589 lu_context_enter(&session_ctx);
591 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
593 env.le_ses = &session_ctx;
594 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
603 lu_context_exit(&session_ctx);
604 lu_context_fini(&session_ctx);
607 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
608 OBD_COUNTER_INCREMENT(obd, setup);
609 rc = OBP(obd, setup)(obd, cfg);
614 static inline int obd_precleanup(struct obd_device *obd)
617 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_fini(&env, d);
632 OBD_CHECK_DT_OP(obd, precleanup, 0);
633 OBD_COUNTER_INCREMENT(obd, precleanup);
635 rc = OBP(obd, precleanup)(obd);
639 static inline int obd_cleanup(struct obd_device *obd)
642 DECLARE_LU_VARS(ldt, d);
647 ldt = obd->obd_type->typ_lu;
649 if (ldt != NULL && d != NULL) {
652 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
654 ldt->ldt_ops->ldto_device_free(&env, d);
656 obd->obd_lu_dev = NULL;
659 OBD_CHECK_DT_OP(obd, cleanup, 0);
660 OBD_COUNTER_INCREMENT(obd, cleanup);
662 rc = OBP(obd, cleanup)(obd);
666 static inline void obd_cleanup_client_import(struct obd_device *obd)
670 /* If we set up but never connected, the
671 client import will not have been cleaned. */
672 down_write(&obd->u.cli.cl_sem);
673 if (obd->u.cli.cl_import) {
674 struct obd_import *imp;
675 imp = obd->u.cli.cl_import;
676 CDEBUG(D_CONFIG, "%s: client import never connected\n",
678 ptlrpc_invalidate_import(imp);
679 client_destroy_import(imp);
680 obd->u.cli.cl_import = NULL;
682 up_write(&obd->u.cli.cl_sem);
688 obd_process_config(struct obd_device *obd, int datalen, void *data)
691 DECLARE_LU_VARS(ldt, d);
696 obd->obd_process_conf = 1;
697 ldt = obd->obd_type->typ_lu;
699 if (ldt != NULL && d != NULL) {
702 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
704 rc = d->ld_ops->ldo_process_config(&env, d, data);
708 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
709 rc = OBP(obd, process_config)(obd, datalen, data);
711 OBD_COUNTER_INCREMENT(obd, process_config);
712 obd->obd_process_conf = 0;
717 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
723 EXP_CHECK_DT_OP(exp, create);
724 EXP_COUNTER_INCREMENT(exp, create);
726 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
730 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
736 EXP_CHECK_DT_OP(exp, destroy);
737 EXP_COUNTER_INCREMENT(exp, destroy);
739 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
743 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
749 EXP_CHECK_DT_OP(exp, getattr);
750 EXP_COUNTER_INCREMENT(exp, getattr);
751 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
756 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
762 EXP_CHECK_DT_OP(exp, setattr);
763 EXP_COUNTER_INCREMENT(exp, setattr);
764 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
769 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
772 struct obd_device *obd = imp->imp_obd;
776 OBD_CHECK_DEV_ACTIVE(obd);
777 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
778 OBD_COUNTER_INCREMENT(obd, add_conn);
780 rc = OBP(obd, add_conn)(imp, uuid, priority);
784 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
786 struct obd_device *obd = imp->imp_obd;
790 OBD_CHECK_DEV_ACTIVE(obd);
791 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
792 OBD_COUNTER_INCREMENT(obd, del_conn);
794 rc = OBP(obd, del_conn)(imp, uuid);
798 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
800 struct obd_uuid *uuid;
803 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
804 EXP_COUNTER_INCREMENT(exp, get_uuid);
806 uuid = OBP(exp->exp_obd, get_uuid)(exp);
810 /** Create a new /a exp on device /a obd for the uuid /a cluuid
811 * @param exp New export handle
812 * @param d Connect data, supported flags are set, flags also understood
813 * by obd are returned.
815 static inline int obd_connect(const struct lu_env *env,
816 struct obd_export **exp,struct obd_device *obd,
817 struct obd_uuid *cluuid,
818 struct obd_connect_data *data,
822 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
826 OBD_CHECK_DEV_ACTIVE(obd);
827 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
828 OBD_COUNTER_INCREMENT(obd, connect);
830 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
831 /* check that only subset is granted */
832 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
833 data->ocd_connect_flags));
837 static inline int obd_reconnect(const struct lu_env *env,
838 struct obd_export *exp,
839 struct obd_device *obd,
840 struct obd_uuid *cluuid,
841 struct obd_connect_data *d,
845 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
850 OBD_CHECK_DEV_ACTIVE(obd);
851 OBD_CHECK_DT_OP(obd, reconnect, 0);
852 OBD_COUNTER_INCREMENT(obd, reconnect);
854 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
855 /* check that only subset is granted */
856 LASSERT(ergo(d != NULL,
857 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
861 static inline int obd_disconnect(struct obd_export *exp)
866 EXP_CHECK_DT_OP(exp, disconnect);
867 EXP_COUNTER_INCREMENT(exp, disconnect);
869 rc = OBP(exp->exp_obd, disconnect)(exp);
873 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
874 enum lu_cli_type type)
879 OBD_CHECK_DT_OP(obd, fid_init, 0);
880 OBD_COUNTER_INCREMENT(obd, fid_init);
882 rc = OBP(obd, fid_init)(obd, exp, type);
886 static inline int obd_fid_fini(struct obd_device *obd)
891 OBD_CHECK_DT_OP(obd, fid_fini, 0);
892 OBD_COUNTER_INCREMENT(obd, fid_fini);
894 rc = OBP(obd, fid_fini)(obd);
898 static inline int obd_fid_alloc(const struct lu_env *env,
899 struct obd_export *exp,
901 struct md_op_data *op_data)
906 EXP_CHECK_DT_OP(exp, fid_alloc);
907 EXP_COUNTER_INCREMENT(exp, fid_alloc);
909 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
913 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
918 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
919 EXP_COUNTER_INCREMENT(exp, ping);
921 rc = OBP(exp->exp_obd, ping)(env, exp);
925 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
930 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
931 OBD_COUNTER_INCREMENT(obd, pool_new);
933 rc = OBP(obd, pool_new)(obd, poolname);
937 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
942 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
943 OBD_COUNTER_INCREMENT(obd, pool_del);
945 rc = OBP(obd, pool_del)(obd, poolname);
949 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
954 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
955 OBD_COUNTER_INCREMENT(obd, pool_add);
957 rc = OBP(obd, pool_add)(obd, poolname, ostname);
961 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
966 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
967 OBD_COUNTER_INCREMENT(obd, pool_rem);
969 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
973 static inline void obd_getref(struct obd_device *obd)
976 if (OBT(obd) && OBP(obd, getref)) {
977 OBD_COUNTER_INCREMENT(obd, getref);
978 OBP(obd, getref)(obd);
983 static inline void obd_putref(struct obd_device *obd)
986 if (OBT(obd) && OBP(obd, putref)) {
987 OBD_COUNTER_INCREMENT(obd, putref);
988 OBP(obd, putref)(obd);
993 static inline int obd_init_export(struct obd_export *exp)
998 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
999 OBP((exp)->exp_obd, init_export))
1000 rc = OBP(exp->exp_obd, init_export)(exp);
1004 static inline int obd_destroy_export(struct obd_export *exp)
1007 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1008 OBP((exp)->exp_obd, destroy_export))
1009 OBP(exp->exp_obd, destroy_export)(exp);
1013 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1014 * If the cache is older than @max_age we will get a new value from the
1015 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1016 static inline int obd_statfs_async(struct obd_export *exp,
1017 struct obd_info *oinfo,
1019 struct ptlrpc_request_set *rqset)
1022 struct obd_device *obd;
1025 if (exp == NULL || exp->exp_obd == NULL)
1029 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1030 OBD_COUNTER_INCREMENT(obd, statfs);
1032 CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n",
1033 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1034 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1035 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1037 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1038 obd->obd_name, &obd->obd_osfs,
1039 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1040 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1041 spin_lock(&obd->obd_osfs_lock);
1042 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1043 spin_unlock(&obd->obd_osfs_lock);
1044 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1045 if (oinfo->oi_cb_up)
1046 oinfo->oi_cb_up(oinfo, 0);
1051 static inline int obd_statfs_rqset(struct obd_export *exp,
1052 struct obd_statfs *osfs, __u64 max_age,
1055 struct ptlrpc_request_set *set = NULL;
1056 struct obd_info oinfo = {
1064 set = ptlrpc_prep_set();
1068 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1070 rc = ptlrpc_set_wait(set);
1072 ptlrpc_set_destroy(set);
1077 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1078 * If the cache is older than @max_age we will get a new value from the
1079 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1080 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1081 struct obd_statfs *osfs, __u64 max_age,
1085 struct obd_device *obd = exp->exp_obd;
1091 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1092 OBD_COUNTER_INCREMENT(obd, statfs);
1094 CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n",
1095 obd->obd_osfs_age, max_age);
1096 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1097 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1099 spin_lock(&obd->obd_osfs_lock);
1100 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1101 obd->obd_osfs_age = cfs_time_current_64();
1102 spin_unlock(&obd->obd_osfs_lock);
1105 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu"
1106 " objects %llu/%llu\n",
1107 obd->obd_name, &obd->obd_osfs,
1108 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1109 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1110 spin_lock(&obd->obd_osfs_lock);
1111 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1112 spin_unlock(&obd->obd_osfs_lock);
1117 static inline int obd_preprw(const struct lu_env *env, int cmd,
1118 struct obd_export *exp, struct obdo *oa,
1119 int objcount, struct obd_ioobj *obj,
1120 struct niobuf_remote *remote, int *pages,
1121 struct niobuf_local *local)
1126 EXP_CHECK_DT_OP(exp, preprw);
1127 EXP_COUNTER_INCREMENT(exp, preprw);
1128 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1134 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1135 struct obd_export *exp, struct obdo *oa,
1136 int objcount, struct obd_ioobj *obj,
1137 struct niobuf_remote *rnb, int pages,
1138 struct niobuf_local *local, int rc)
1142 EXP_CHECK_DT_OP(exp, commitrw);
1143 EXP_COUNTER_INCREMENT(exp, commitrw);
1144 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1145 rnb, pages, local, rc);
1150 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1151 int len, void *karg, void __user *uarg)
1156 EXP_CHECK_DT_OP(exp, iocontrol);
1157 EXP_COUNTER_INCREMENT(exp, iocontrol);
1159 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1163 static inline void obd_import_event(struct obd_device *obd,
1164 struct obd_import *imp,
1165 enum obd_import_event event)
1169 CERROR("NULL device\n");
1173 if (obd->obd_set_up && OBP(obd, import_event)) {
1174 OBD_COUNTER_INCREMENT(obd, import_event);
1175 OBP(obd, import_event)(obd, imp, event);
1180 static inline int obd_notify(struct obd_device *obd,
1181 struct obd_device *watched,
1182 enum obd_notify_event ev)
1188 if (!obd->obd_set_up) {
1189 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1193 if (!OBP(obd, notify)) {
1194 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1198 OBD_COUNTER_INCREMENT(obd, notify);
1199 rc = OBP(obd, notify)(obd, watched, ev);
1204 static inline int obd_notify_observer(struct obd_device *observer,
1205 struct obd_device *observed,
1206 enum obd_notify_event ev)
1210 struct obd_notify_upcall *onu;
1212 if (observer->obd_observer)
1213 rc = obd_notify(observer->obd_observer, observed, ev);
1216 * Also, call non-obd listener, if any
1218 onu = &observer->obd_upcall;
1219 if (onu->onu_upcall != NULL)
1220 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1222 return rc ? rc : rc2;
1225 static inline int obd_quotactl(struct obd_export *exp,
1226 struct obd_quotactl *oqctl)
1231 EXP_CHECK_DT_OP(exp, quotactl);
1232 EXP_COUNTER_INCREMENT(exp, quotactl);
1234 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1238 static inline int obd_health_check(const struct lu_env *env,
1239 struct obd_device *obd)
1241 /* returns: 0 on healthy
1242 * >0 on unhealthy + reason code/flag
1243 * however the only suppored reason == 1 right now
1244 * We'll need to define some better reasons
1245 * or flags in the future.
1251 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1252 if (obd == NULL || !OBT(obd)) {
1253 CERROR("cleaned up obd\n");
1254 RETURN(-EOPNOTSUPP);
1256 if (!obd->obd_set_up || obd->obd_stopping)
1258 if (!OBP(obd, health_check))
1261 rc = OBP(obd, health_check)(env, obd);
1265 static inline int obd_register_observer(struct obd_device *obd,
1266 struct obd_device *observer)
1270 down_write(&obd->obd_observer_link_sem);
1271 if (obd->obd_observer && observer) {
1272 up_write(&obd->obd_observer_link_sem);
1275 obd->obd_observer = observer;
1276 up_write(&obd->obd_observer_link_sem);
1280 /* metadata helpers */
1281 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1287 EXP_CHECK_MD_OP(exp, get_root);
1288 EXP_MD_COUNTER_INCREMENT(exp, get_root);
1289 rc = MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1294 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1295 struct ptlrpc_request **request)
1299 EXP_CHECK_MD_OP(exp, getattr);
1300 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1301 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1305 static inline int md_null_inode(struct obd_export *exp,
1306 const struct lu_fid *fid)
1310 EXP_CHECK_MD_OP(exp, null_inode);
1311 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1312 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1316 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1317 struct md_open_data *mod,
1318 struct ptlrpc_request **request)
1322 EXP_CHECK_MD_OP(exp, close);
1323 EXP_MD_COUNTER_INCREMENT(exp, close);
1324 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1328 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1329 const void *data, size_t datalen, umode_t mode,
1330 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1331 __u64 rdev, struct ptlrpc_request **request)
1335 EXP_CHECK_MD_OP(exp, create);
1336 EXP_MD_COUNTER_INCREMENT(exp, create);
1337 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1338 uid, gid, cap_effective, rdev, request);
1342 static inline int md_enqueue(struct obd_export *exp,
1343 struct ldlm_enqueue_info *einfo,
1344 const union ldlm_policy_data *policy,
1345 struct md_op_data *op_data,
1346 struct lustre_handle *lockh,
1347 __u64 extra_lock_flags)
1351 EXP_CHECK_MD_OP(exp, enqueue);
1352 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1353 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1358 static inline int md_getattr_name(struct obd_export *exp,
1359 struct md_op_data *op_data,
1360 struct ptlrpc_request **request)
1364 EXP_CHECK_MD_OP(exp, getattr_name);
1365 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1366 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1370 static inline int md_intent_lock(struct obd_export *exp,
1371 struct md_op_data *op_data,
1372 struct lookup_intent *it,
1373 struct ptlrpc_request **reqp,
1374 ldlm_blocking_callback cb_blocking,
1375 __u64 extra_lock_flags)
1379 EXP_CHECK_MD_OP(exp, intent_lock);
1380 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1381 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1386 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1387 struct ptlrpc_request **request)
1391 EXP_CHECK_MD_OP(exp, link);
1392 EXP_MD_COUNTER_INCREMENT(exp, link);
1393 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1397 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1398 const char *old, size_t oldlen, const char *new,
1399 size_t newlen, struct ptlrpc_request **request)
1403 EXP_CHECK_MD_OP(exp, rename);
1404 EXP_MD_COUNTER_INCREMENT(exp, rename);
1405 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1410 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1411 void *ea, size_t ealen,
1412 struct ptlrpc_request **request)
1416 EXP_CHECK_MD_OP(exp, setattr);
1417 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1418 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1422 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1423 struct ptlrpc_request **request)
1428 EXP_CHECK_MD_OP(exp, fsync);
1429 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1430 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1435 static inline int md_read_page(struct obd_export *exp,
1436 struct md_op_data *op_data,
1437 struct md_callback *cb_op,
1439 struct page **ppage)
1443 EXP_CHECK_MD_OP(exp, read_page);
1444 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1445 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1450 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1451 struct ptlrpc_request **request)
1455 EXP_CHECK_MD_OP(exp, unlink);
1456 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1457 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1461 static inline int md_get_lustre_md(struct obd_export *exp,
1462 struct ptlrpc_request *req,
1463 struct obd_export *dt_exp,
1464 struct obd_export *md_exp,
1465 struct lustre_md *md)
1468 EXP_CHECK_MD_OP(exp, get_lustre_md);
1469 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1470 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1473 static inline int md_free_lustre_md(struct obd_export *exp,
1474 struct lustre_md *md)
1477 EXP_CHECK_MD_OP(exp, free_lustre_md);
1478 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1479 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1482 static inline int md_merge_attr(struct obd_export *exp,
1483 const struct lmv_stripe_md *lsm,
1484 struct cl_attr *attr,
1485 ldlm_blocking_callback cb)
1488 EXP_CHECK_MD_OP(exp, merge_attr);
1489 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1490 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1493 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1494 u64 valid, const char *name,
1495 const char *input, int input_size,
1496 int output_size, int flags, __u32 suppgid,
1497 struct ptlrpc_request **request)
1500 EXP_CHECK_MD_OP(exp, setxattr);
1501 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1502 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1503 input_size, output_size, flags,
1507 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1508 u64 valid, const char *name,
1509 const char *input, int input_size,
1510 int output_size, int flags,
1511 struct ptlrpc_request **request)
1514 EXP_CHECK_MD_OP(exp, getxattr);
1515 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1516 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1517 input_size, output_size, flags,
1521 static inline int md_set_open_replay_data(struct obd_export *exp,
1522 struct obd_client_handle *och,
1523 struct lookup_intent *it)
1526 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1527 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1528 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1531 static inline int md_clear_open_replay_data(struct obd_export *exp,
1532 struct obd_client_handle *och)
1535 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1536 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1537 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1540 static inline int md_set_lock_data(struct obd_export *exp,
1541 const struct lustre_handle *lockh,
1542 void *data, __u64 *bits)
1545 EXP_CHECK_MD_OP(exp, set_lock_data);
1546 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1547 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1551 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1552 union ldlm_policy_data *policy, enum ldlm_mode mode,
1553 enum ldlm_cancel_flags cancel_flags, void *opaque)
1558 EXP_CHECK_MD_OP(exp, cancel_unused);
1559 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1561 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1562 cancel_flags, opaque);
1566 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1567 const struct lu_fid *fid,
1568 enum ldlm_type type,
1569 union ldlm_policy_data *policy,
1570 enum ldlm_mode mode,
1571 struct lustre_handle *lockh)
1574 EXP_CHECK_MD_OP(exp, lock_match);
1575 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1576 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1577 policy, mode, lockh));
1580 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1584 EXP_CHECK_MD_OP(exp, init_ea_size);
1585 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1586 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1589 static inline int md_intent_getattr_async(struct obd_export *exp,
1590 struct md_enqueue_info *minfo)
1594 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1595 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1596 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1600 static inline int md_revalidate_lock(struct obd_export *exp,
1601 struct lookup_intent *it,
1602 struct lu_fid *fid, __u64 *bits)
1606 EXP_CHECK_MD_OP(exp, revalidate_lock);
1607 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1608 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1612 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1613 const struct lmv_stripe_md *lsm,
1614 const char *name, int namelen,
1619 EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1620 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1621 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1626 /* Unpack an MD struct from disk to in-memory format.
1627 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1629 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1630 * If *plsm == NULL then it will be allocated.
1632 static inline int md_unpackmd(struct obd_export *exp,
1633 struct lmv_stripe_md **plsm,
1634 const union lmv_mds_md *lmm, size_t lmm_size)
1638 EXP_CHECK_MD_OP(exp, unpackmd);
1639 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1640 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1644 /* OBD Metadata Support */
1646 extern int obd_init_caches(void);
1647 extern void obd_cleanup_caches(void);
1649 /* support routines */
1650 extern struct kmem_cache *obdo_cachep;
1652 #define OBDO_ALLOC(ptr) \
1654 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1657 #define OBDO_FREE(ptr) \
1659 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1663 typedef int (*register_lwp_cb)(void *data);
1665 struct lwp_register_item {
1666 struct obd_export **lri_exp;
1667 register_lwp_cb lri_cb_func;
1669 struct list_head lri_list;
1671 char lri_name[MTI_NAME_MAXLEN];
1674 /* I'm as embarrassed about this as you are.
1676 * <shaver> // XXX do not look into _superhack with remaining eye
1677 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1678 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1681 #ifdef HAVE_SERVER_SUPPORT
1682 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1683 register_lwp_cb cb_func, void *cb_data);
1684 void lustre_deregister_lwp_item(struct obd_export **exp);
1685 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1686 void lustre_notify_lwp_list(struct obd_export *exp);
1687 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1688 #endif /* HAVE_SERVER_SUPPORT */
1689 int lustre_register_fs(void);
1690 int lustre_unregister_fs(void);
1691 int lustre_check_exclusion(struct super_block *sb, char *svname);
1694 extern int obd_sysctl_init(void);
1695 extern void obd_sysctl_clean(void);
1698 typedef __u8 class_uuid_t[16];
1699 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1702 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1703 int class_add_uuid(const char *uuid, __u64 nid);
1704 int class_del_uuid (const char *uuid);
1705 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
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 obd_ioctl_getdata(char **buf, int *len, void __user *arg);
1732 int class_procfs_init(void);
1733 int class_procfs_clean(void);
1735 #endif /* __LINUX_OBD_CLASS_H */