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_FOR_MDT0 0x0004 /* The statfs is only for retrieving
53 * information from MDT0. */
55 /* OBD Device Declarations */
56 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
57 extern struct list_head obd_types;
58 extern spinlock_t obd_types_lock;
59 extern rwlock_t obd_dev_lock;
61 /* OBD Operations Declarations */
62 extern struct obd_device *class_conn2obd(struct lustre_handle *);
63 extern struct obd_device *class_exp2obd(struct obd_export *);
64 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
65 extern int lustre_get_jobid(char *jobid);
67 struct lu_device_type;
70 struct obd_export *class_conn2export(struct lustre_handle *);
71 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
72 struct lprocfs_vars *module_vars,
73 const char *nm, struct lu_device_type *ldt);
74 int class_unregister_type(const char *nm);
76 struct obd_device *class_newdev(const char *type_name, const char *name);
77 void class_release_dev(struct obd_device *obd);
79 int class_name2dev(const char *name);
80 struct obd_device *class_name2obd(const char *name);
81 int class_uuid2dev(struct obd_uuid *uuid);
82 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
83 void class_obd_list(void);
84 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
85 const char * typ_name,
86 struct obd_uuid *grp_uuid);
87 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
89 struct obd_device * class_num2obd(int num);
90 int get_devices_count(void);
92 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
94 char *obd_export_nid2str(struct obd_export *exp);
96 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
97 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
98 int obd_connect_flags2str(char *page, int count, __u64 flags, __u64 flags2,
101 int obd_zombie_impexp_init(void);
102 void obd_zombie_impexp_stop(void);
103 void obd_zombie_impexp_cull(void);
104 void obd_zombie_barrier(void);
105 void obd_exports_barrier(struct obd_device *obd);
106 int kuc_len(int payload_len);
107 struct kuc_hdr * kuc_ptr(void *p);
108 void *kuc_alloc(int payload_len, int transport, int type);
109 void kuc_free(void *p, int payload_len);
110 int obd_get_request_slot(struct client_obd *cli);
111 void obd_put_request_slot(struct client_obd *cli);
112 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
113 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
114 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
115 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
116 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
118 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
119 struct lookup_intent *it);
120 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
121 struct lookup_intent *it, __u16 tag);
125 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
126 struct llog_rec_hdr *, void *);
128 extern atomic_t obd_stale_export_num;
129 extern struct list_head obd_stale_exports;
130 extern spinlock_t obd_stale_export_lock;
132 struct obd_export *obd_stale_export_get(void);
133 void obd_stale_export_put(struct obd_export *exp);
134 void obd_stale_export_adjust(struct obd_export *exp);
137 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
138 const char *new_name);
139 int class_process_config(struct lustre_cfg *lcfg);
140 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
141 struct lustre_cfg *lcfg, void *data);
142 int class_attach(struct lustre_cfg *lcfg);
143 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
144 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
145 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
146 struct obd_device *class_incref(struct obd_device *obd,
147 const char *scope, const void *source);
148 void class_decref(struct obd_device *obd,
149 const char *scope, const void *source);
150 void dump_exports(struct obd_device *obd, int locks, int debug_level);
151 int class_config_llog_handler(const struct lu_env *env,
152 struct llog_handle *handle,
153 struct llog_rec_hdr *rec, void *data);
154 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
155 int class_add_uuid(const char *uuid, __u64 nid);
157 #define CFG_F_START 0x01 /* Set when we start updating from a log */
158 #define CFG_F_MARKER 0x02 /* We are within a maker */
159 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
160 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
161 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
163 /* Passed as data param to class_config_parse_llog */
164 struct config_llog_instance {
167 struct super_block *cfg_sb;
168 struct obd_uuid cfg_uuid;
169 llog_cb_t cfg_callback;
170 int cfg_last_idx; /* for partial llog processing */
174 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
175 char *name, struct config_llog_instance *cfg);
179 CONFIG_T_SPTLRPC = 1,
180 CONFIG_T_RECOVER = 2,
182 CONFIG_T_NODEMAP = 4,
186 #define PARAMS_FILENAME "params"
187 #define LCTL_UPCALL "lctl"
189 /* list of active configuration logs */
190 struct config_llog_data {
191 struct ldlm_res_id cld_resid;
192 struct config_llog_instance cld_cfg;
193 struct list_head cld_list_chain;
194 atomic_t cld_refcount;
195 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
196 struct config_llog_data *cld_params; /* common parameters log */
197 struct config_llog_data *cld_recover;/* imperative recover log */
198 struct config_llog_data *cld_nodemap;/* nodemap log */
199 struct obd_export *cld_mgcexp;
200 struct mutex cld_lock;
202 unsigned int cld_stopping:1, /* we were told to stop
204 cld_lostlock:1; /* lock not requeued */
208 struct lustre_profile {
209 struct list_head lp_list;
214 bool lp_list_deleted;
217 struct lustre_profile *class_get_profile(const char * prof);
218 void class_del_profile(const char *prof);
219 void class_put_profile(struct lustre_profile *lprof);
220 void class_del_profiles(void);
223 #if LUSTRE_TRACKS_LOCK_EXP_REFS
225 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
226 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
227 extern void (*class_export_dump_hook)(struct obd_export *);
231 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
232 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
236 #define class_export_rpc_inc(exp) \
238 atomic_inc(&(exp)->exp_rpc_count); \
239 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
240 (exp), atomic_read(&(exp)->exp_rpc_count)); \
243 #define class_export_rpc_dec(exp) \
245 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
246 atomic_dec(&(exp)->exp_rpc_count); \
247 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
248 (exp), atomic_read(&(exp)->exp_rpc_count)); \
251 #define class_export_lock_get(exp, lock) \
253 atomic_inc(&(exp)->exp_locks_count); \
254 __class_export_add_lock_ref(exp, lock); \
255 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
256 (exp), atomic_read(&(exp)->exp_locks_count)); \
257 class_export_get(exp); \
260 #define class_export_lock_put(exp, lock) \
262 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
263 atomic_dec(&(exp)->exp_locks_count); \
264 __class_export_del_lock_ref(exp, lock); \
265 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
266 (exp), atomic_read(&(exp)->exp_locks_count)); \
267 class_export_put(exp); \
270 #define class_export_cb_get(exp) \
272 atomic_inc(&(exp)->exp_cb_count); \
273 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
274 (exp), atomic_read(&(exp)->exp_cb_count)); \
275 class_export_get(exp); \
278 #define class_export_cb_put(exp) \
280 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
281 atomic_dec(&(exp)->exp_cb_count); \
282 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
283 (exp), atomic_read(&(exp)->exp_cb_count)); \
284 class_export_put(exp); \
288 struct obd_export *class_export_get(struct obd_export *exp);
289 void class_export_put(struct obd_export *exp);
290 struct obd_export *class_new_export(struct obd_device *obddev,
291 struct obd_uuid *cluuid);
292 void class_unlink_export(struct obd_export *exp);
294 struct obd_import *class_import_get(struct obd_import *);
295 void class_import_put(struct obd_import *);
296 struct obd_import *class_new_import(struct obd_device *obd);
297 void class_destroy_import(struct obd_import *exp);
299 struct obd_type *class_search_type(const char *name);
300 struct obd_type *class_get_type(const char *name);
301 void class_put_type(struct obd_type *type);
302 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
303 struct obd_uuid *cluuid);
304 int class_disconnect(struct obd_export *exp);
305 void class_fail_export(struct obd_export *exp);
306 int class_connected_export(struct obd_export *exp);
307 void class_disconnect_exports(struct obd_device *obddev);
308 int class_manual_cleanup(struct obd_device *obd);
309 void class_disconnect_stale_exports(struct obd_device *,
310 int (*test_export)(struct obd_export *));
311 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
313 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
314 (obd->obd_force ? OBD_OPT_FORCE : 0) |
315 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
319 #ifdef HAVE_SERVER_SUPPORT
320 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
322 LASSERT(exp->exp_obd);
323 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
325 return exp->exp_obd->u.obt.obt_lut;
328 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
330 LASSERT(obd->u.obt.obt_lut);
331 return &obd->u.obt.obt_lut->lut_lsd;
339 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
340 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
342 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
343 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
345 #define OBT(dev) (dev)->obd_type
346 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
347 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
348 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
350 /* Ensure obd_setup: used for cleanup which must be called
351 while obd is stopping */
352 #define OBD_CHECK_DEV(obd) \
355 CERROR("NULL device\n"); \
360 /* ensure obd_setup and !obd_stopping */
361 #define OBD_CHECK_DEV_ACTIVE(obd) \
363 OBD_CHECK_DEV(obd); \
364 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
365 CERROR("Device %d not setup\n", \
372 #ifdef CONFIG_PROC_FS
373 #define OBD_COUNTER_OFFSET(op) \
374 ((offsetof(struct obd_ops, o_ ## op) - \
375 offsetof(struct obd_ops, o_iocontrol)) \
376 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
378 /* The '- 1' below is for o_owner. */
379 #define NUM_OBD_STATS \
380 (sizeof(struct obd_ops) / \
381 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
383 #define OBD_COUNTER_INCREMENT(obd, op) \
384 lprocfs_counter_incr((obd)->obd_stats, \
385 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
387 #define EXP_COUNTER_INCREMENT(exp, op) \
390 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
391 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
392 if ((exp)->exp_obd->obd_uses_nid_stats && \
393 (exp)->exp_nid_stats != NULL) \
394 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
398 #define _MD_COUNTER_OFFSET(m_op) \
399 ((offsetof(struct md_ops, m_op) - \
400 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
401 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
403 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
405 #define NUM_MD_STATS \
406 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
407 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
409 /* Note that we only increment md counters for ops whose offset is less
410 * than NUM_MD_STATS. This is explained in a comment in the definition
411 * of struct md_ops. */
412 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
414 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
415 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
416 (exp)->exp_obd->obd_md_cntr_base + \
417 MD_COUNTER_OFFSET(op)); \
421 #define OBD_COUNTER_OFFSET(op)
422 #define OBD_COUNTER_INCREMENT(obd, op)
423 #define EXP_COUNTER_INCREMENT(exp, op)
424 #define EXP_MD_COUNTER_INCREMENT(exp, op)
427 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
429 /* Always add in ldlm_stats */
430 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
431 ,LPROCFS_STATS_FLAG_NOPERCPU);
432 if (tmp->nid_ldlm_stats == NULL)
435 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
437 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
438 tmp->nid_ldlm_stats);
441 #define EXP_CHECK_MD_OP(exp, op) \
443 if ((exp) == NULL) { \
444 CERROR("obd_" #op ": NULL export\n"); \
447 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
448 CERROR("obd_" #op ": cleaned up obd\n"); \
449 RETURN(-EOPNOTSUPP); \
451 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
452 CERROR("obd_" #op ": dev %s/%d no operation\n", \
453 (exp)->exp_obd->obd_name, \
454 (exp)->exp_obd->obd_minor); \
455 RETURN(-EOPNOTSUPP); \
460 #define OBD_CHECK_DT_OP(obd, op, err) \
462 if (!OBT(obd) || !OBP((obd), op)) { \
464 CERROR("obd_" #op ": dev %d no operation\n", \
470 #define EXP_CHECK_DT_OP(exp, op) \
472 if ((exp) == NULL) { \
473 CERROR("obd_" #op ": NULL export\n"); \
476 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
477 CERROR("obd_" #op ": cleaned up obd\n"); \
478 RETURN(-EOPNOTSUPP); \
480 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
481 CERROR("obd_" #op ": dev %d no operation\n", \
482 (exp)->exp_obd->obd_minor); \
483 RETURN(-EOPNOTSUPP); \
487 #define CTXT_CHECK_OP(ctxt, op, err) \
489 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
491 CERROR("lop_" #op ": dev %d no operation\n", \
492 ctxt->loc_obd->obd_minor); \
497 static inline int class_devno_max(void)
499 return MAX_OBD_DEVICES;
502 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
503 __u32 keylen, void *key,
504 __u32 *vallen, void *val)
509 EXP_CHECK_DT_OP(exp, get_info);
510 EXP_COUNTER_INCREMENT(exp, get_info);
512 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
516 static inline int obd_set_info_async(const struct lu_env *env,
517 struct obd_export *exp,
518 __u32 keylen, void *key,
519 __u32 vallen, void *val,
520 struct ptlrpc_request_set *set)
525 EXP_CHECK_DT_OP(exp, set_info_async);
526 EXP_COUNTER_INCREMENT(exp, set_info_async);
528 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
534 * obd-lu integration.
536 * Functionality is being moved into new lu_device-based layering, but some
537 * pieces of configuration process are still based on obd devices.
539 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
540 * subsume ->o_setup() methods of obd devices they replace. The same for
541 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
542 * result, obd_setup() and obd_process_config() branch and call one XOR
545 * Yet neither lu_device_type_operations::ldto_device_fini() nor
546 * lu_device_type_operations::ldto_device_free() fully implement the
547 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
548 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
551 #define DECLARE_LU_VARS(ldt, d) \
552 struct lu_device_type *ldt; \
555 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
558 DECLARE_LU_VARS(ldt, d);
561 ldt = obd->obd_type->typ_lu;
563 struct lu_context session_ctx;
565 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
566 session_ctx.lc_thread = NULL;
567 lu_context_enter(&session_ctx);
569 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
571 env.le_ses = &session_ctx;
572 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
581 lu_context_exit(&session_ctx);
582 lu_context_fini(&session_ctx);
585 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
586 OBD_COUNTER_INCREMENT(obd, setup);
587 rc = OBP(obd, setup)(obd, cfg);
592 static inline int obd_precleanup(struct obd_device *obd)
595 DECLARE_LU_VARS(ldt, d);
599 ldt = obd->obd_type->typ_lu;
601 if (ldt != NULL && d != NULL) {
604 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
606 ldt->ldt_ops->ldto_device_fini(&env, d);
610 OBD_CHECK_DT_OP(obd, precleanup, 0);
611 OBD_COUNTER_INCREMENT(obd, precleanup);
613 rc = OBP(obd, precleanup)(obd);
617 static inline int obd_cleanup(struct obd_device *obd)
620 DECLARE_LU_VARS(ldt, d);
625 ldt = obd->obd_type->typ_lu;
627 if (ldt != NULL && d != NULL) {
630 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
632 ldt->ldt_ops->ldto_device_free(&env, d);
634 obd->obd_lu_dev = NULL;
637 OBD_CHECK_DT_OP(obd, cleanup, 0);
638 OBD_COUNTER_INCREMENT(obd, cleanup);
640 rc = OBP(obd, cleanup)(obd);
644 static inline void obd_cleanup_client_import(struct obd_device *obd)
648 /* If we set up but never connected, the
649 client import will not have been cleaned. */
650 down_write(&obd->u.cli.cl_sem);
651 if (obd->u.cli.cl_import) {
652 struct obd_import *imp;
653 imp = obd->u.cli.cl_import;
654 CDEBUG(D_CONFIG, "%s: client import never connected\n",
656 ptlrpc_invalidate_import(imp);
657 client_destroy_import(imp);
658 obd->u.cli.cl_import = NULL;
660 up_write(&obd->u.cli.cl_sem);
666 obd_process_config(struct obd_device *obd, int datalen, void *data)
669 DECLARE_LU_VARS(ldt, d);
674 obd->obd_process_conf = 1;
675 ldt = obd->obd_type->typ_lu;
677 if (ldt != NULL && d != NULL) {
680 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
682 rc = d->ld_ops->ldo_process_config(&env, d, data);
686 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
687 rc = OBP(obd, process_config)(obd, datalen, data);
689 OBD_COUNTER_INCREMENT(obd, process_config);
690 obd->obd_process_conf = 0;
695 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
701 EXP_CHECK_DT_OP(exp, create);
702 EXP_COUNTER_INCREMENT(exp, create);
704 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
708 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
714 EXP_CHECK_DT_OP(exp, destroy);
715 EXP_COUNTER_INCREMENT(exp, destroy);
717 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
721 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
727 EXP_CHECK_DT_OP(exp, getattr);
728 EXP_COUNTER_INCREMENT(exp, getattr);
729 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
734 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
740 EXP_CHECK_DT_OP(exp, setattr);
741 EXP_COUNTER_INCREMENT(exp, setattr);
742 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
747 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
750 struct obd_device *obd = imp->imp_obd;
754 OBD_CHECK_DEV_ACTIVE(obd);
755 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
756 OBD_COUNTER_INCREMENT(obd, add_conn);
758 rc = OBP(obd, add_conn)(imp, uuid, priority);
762 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
764 struct obd_device *obd = imp->imp_obd;
768 OBD_CHECK_DEV_ACTIVE(obd);
769 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
770 OBD_COUNTER_INCREMENT(obd, del_conn);
772 rc = OBP(obd, del_conn)(imp, uuid);
776 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
778 struct obd_uuid *uuid;
781 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
782 EXP_COUNTER_INCREMENT(exp, get_uuid);
784 uuid = OBP(exp->exp_obd, get_uuid)(exp);
788 /** Create a new /a exp on device /a obd for the uuid /a cluuid
789 * @param exp New export handle
790 * @param d Connect data, supported flags are set, flags also understood
791 * by obd are returned.
793 static inline int obd_connect(const struct lu_env *env,
794 struct obd_export **exp,struct obd_device *obd,
795 struct obd_uuid *cluuid,
796 struct obd_connect_data *data,
800 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
804 OBD_CHECK_DEV_ACTIVE(obd);
805 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
806 OBD_COUNTER_INCREMENT(obd, connect);
808 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
809 /* check that only subset is granted */
810 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
811 data->ocd_connect_flags));
815 static inline int obd_reconnect(const struct lu_env *env,
816 struct obd_export *exp,
817 struct obd_device *obd,
818 struct obd_uuid *cluuid,
819 struct obd_connect_data *d,
823 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
828 OBD_CHECK_DEV_ACTIVE(obd);
829 OBD_CHECK_DT_OP(obd, reconnect, 0);
830 OBD_COUNTER_INCREMENT(obd, reconnect);
832 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
833 /* check that only subset is granted */
834 LASSERT(ergo(d != NULL,
835 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
839 static inline int obd_disconnect(struct obd_export *exp)
844 EXP_CHECK_DT_OP(exp, disconnect);
845 EXP_COUNTER_INCREMENT(exp, disconnect);
847 rc = OBP(exp->exp_obd, disconnect)(exp);
851 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
852 enum lu_cli_type type)
857 OBD_CHECK_DT_OP(obd, fid_init, 0);
858 OBD_COUNTER_INCREMENT(obd, fid_init);
860 rc = OBP(obd, fid_init)(obd, exp, type);
864 static inline int obd_fid_fini(struct obd_device *obd)
869 OBD_CHECK_DT_OP(obd, fid_fini, 0);
870 OBD_COUNTER_INCREMENT(obd, fid_fini);
872 rc = OBP(obd, fid_fini)(obd);
876 static inline int obd_fid_alloc(const struct lu_env *env,
877 struct obd_export *exp,
879 struct md_op_data *op_data)
884 EXP_CHECK_DT_OP(exp, fid_alloc);
885 EXP_COUNTER_INCREMENT(exp, fid_alloc);
887 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
891 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
896 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
897 EXP_COUNTER_INCREMENT(exp, ping);
899 rc = OBP(exp->exp_obd, ping)(env, exp);
903 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
908 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
909 OBD_COUNTER_INCREMENT(obd, pool_new);
911 rc = OBP(obd, pool_new)(obd, poolname);
915 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
920 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
921 OBD_COUNTER_INCREMENT(obd, pool_del);
923 rc = OBP(obd, pool_del)(obd, poolname);
927 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
932 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
933 OBD_COUNTER_INCREMENT(obd, pool_add);
935 rc = OBP(obd, pool_add)(obd, poolname, ostname);
939 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
944 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
945 OBD_COUNTER_INCREMENT(obd, pool_rem);
947 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
951 static inline void obd_getref(struct obd_device *obd)
954 if (OBT(obd) && OBP(obd, getref)) {
955 OBD_COUNTER_INCREMENT(obd, getref);
956 OBP(obd, getref)(obd);
961 static inline void obd_putref(struct obd_device *obd)
964 if (OBT(obd) && OBP(obd, putref)) {
965 OBD_COUNTER_INCREMENT(obd, putref);
966 OBP(obd, putref)(obd);
971 static inline int obd_init_export(struct obd_export *exp)
976 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
977 OBP((exp)->exp_obd, init_export))
978 rc = OBP(exp->exp_obd, init_export)(exp);
982 static inline int obd_destroy_export(struct obd_export *exp)
985 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
986 OBP((exp)->exp_obd, destroy_export))
987 OBP(exp->exp_obd, destroy_export)(exp);
991 /* @max_age is the oldest time in jiffies that we accept using a cached data.
992 * If the cache is older than @max_age we will get a new value from the
993 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
994 static inline int obd_statfs_async(struct obd_export *exp,
995 struct obd_info *oinfo,
997 struct ptlrpc_request_set *rqset)
1000 struct obd_device *obd;
1003 if (exp == NULL || exp->exp_obd == NULL)
1007 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1008 OBD_COUNTER_INCREMENT(obd, statfs);
1010 CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n",
1011 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1012 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1013 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1015 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1016 obd->obd_name, &obd->obd_osfs,
1017 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1018 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1019 spin_lock(&obd->obd_osfs_lock);
1020 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1021 spin_unlock(&obd->obd_osfs_lock);
1022 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1023 if (oinfo->oi_cb_up)
1024 oinfo->oi_cb_up(oinfo, 0);
1029 static inline int obd_statfs_rqset(struct obd_export *exp,
1030 struct obd_statfs *osfs, __u64 max_age,
1033 struct ptlrpc_request_set *set = NULL;
1034 struct obd_info oinfo = {
1042 set = ptlrpc_prep_set();
1046 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1048 rc = ptlrpc_set_wait(set);
1050 ptlrpc_set_destroy(set);
1055 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1056 * If the cache is older than @max_age we will get a new value from the
1057 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1058 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1059 struct obd_statfs *osfs, __u64 max_age,
1063 struct obd_device *obd = exp->exp_obd;
1069 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1070 OBD_COUNTER_INCREMENT(obd, statfs);
1072 CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n",
1073 obd->obd_osfs_age, max_age);
1074 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1075 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1077 spin_lock(&obd->obd_osfs_lock);
1078 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1079 obd->obd_osfs_age = cfs_time_current_64();
1080 spin_unlock(&obd->obd_osfs_lock);
1083 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu"
1084 " objects %llu/%llu\n",
1085 obd->obd_name, &obd->obd_osfs,
1086 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1087 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1088 spin_lock(&obd->obd_osfs_lock);
1089 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1090 spin_unlock(&obd->obd_osfs_lock);
1095 static inline int obd_preprw(const struct lu_env *env, int cmd,
1096 struct obd_export *exp, struct obdo *oa,
1097 int objcount, struct obd_ioobj *obj,
1098 struct niobuf_remote *remote, int *pages,
1099 struct niobuf_local *local)
1104 EXP_CHECK_DT_OP(exp, preprw);
1105 EXP_COUNTER_INCREMENT(exp, preprw);
1106 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1112 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1113 struct obd_export *exp, struct obdo *oa,
1114 int objcount, struct obd_ioobj *obj,
1115 struct niobuf_remote *rnb, int pages,
1116 struct niobuf_local *local, int rc)
1120 EXP_CHECK_DT_OP(exp, commitrw);
1121 EXP_COUNTER_INCREMENT(exp, commitrw);
1122 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1123 rnb, pages, local, rc);
1128 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1129 int len, void *karg, void __user *uarg)
1134 EXP_CHECK_DT_OP(exp, iocontrol);
1135 EXP_COUNTER_INCREMENT(exp, iocontrol);
1137 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1141 static inline void obd_import_event(struct obd_device *obd,
1142 struct obd_import *imp,
1143 enum obd_import_event event)
1147 CERROR("NULL device\n");
1151 if (obd->obd_set_up && OBP(obd, import_event)) {
1152 OBD_COUNTER_INCREMENT(obd, import_event);
1153 OBP(obd, import_event)(obd, imp, event);
1158 static inline int obd_notify(struct obd_device *obd,
1159 struct obd_device *watched,
1160 enum obd_notify_event ev,
1167 if (!obd->obd_set_up) {
1168 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1172 if (!OBP(obd, notify)) {
1173 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1177 OBD_COUNTER_INCREMENT(obd, notify);
1178 rc = OBP(obd, notify)(obd, watched, ev, data);
1182 static inline int obd_notify_observer(struct obd_device *observer,
1183 struct obd_device *observed,
1184 enum obd_notify_event ev,
1190 struct obd_notify_upcall *onu;
1192 if (observer->obd_observer)
1193 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1197 * Also, call non-obd listener, if any
1199 onu = &observer->obd_upcall;
1200 if (onu->onu_upcall != NULL)
1201 rc2 = onu->onu_upcall(observer, observed, ev,
1202 onu->onu_owner, NULL);
1206 return rc1 ? rc1 : rc2;
1209 static inline int obd_quotactl(struct obd_export *exp,
1210 struct obd_quotactl *oqctl)
1215 EXP_CHECK_DT_OP(exp, quotactl);
1216 EXP_COUNTER_INCREMENT(exp, quotactl);
1218 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1222 static inline int obd_health_check(const struct lu_env *env,
1223 struct obd_device *obd)
1225 /* returns: 0 on healthy
1226 * >0 on unhealthy + reason code/flag
1227 * however the only suppored reason == 1 right now
1228 * We'll need to define some better reasons
1229 * or flags in the future.
1235 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1236 if (obd == NULL || !OBT(obd)) {
1237 CERROR("cleaned up obd\n");
1238 RETURN(-EOPNOTSUPP);
1240 if (!obd->obd_set_up || obd->obd_stopping)
1242 if (!OBP(obd, health_check))
1245 rc = OBP(obd, health_check)(env, obd);
1249 static inline int obd_register_observer(struct obd_device *obd,
1250 struct obd_device *observer)
1254 down_write(&obd->obd_observer_link_sem);
1255 if (obd->obd_observer && observer) {
1256 up_write(&obd->obd_observer_link_sem);
1259 obd->obd_observer = observer;
1260 up_write(&obd->obd_observer_link_sem);
1264 /* metadata helpers */
1265 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1271 EXP_CHECK_MD_OP(exp, get_root);
1272 EXP_MD_COUNTER_INCREMENT(exp, get_root);
1273 rc = MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1278 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1279 struct ptlrpc_request **request)
1283 EXP_CHECK_MD_OP(exp, getattr);
1284 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1285 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1289 static inline int md_null_inode(struct obd_export *exp,
1290 const struct lu_fid *fid)
1294 EXP_CHECK_MD_OP(exp, null_inode);
1295 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1296 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1300 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1301 struct md_open_data *mod,
1302 struct ptlrpc_request **request)
1306 EXP_CHECK_MD_OP(exp, close);
1307 EXP_MD_COUNTER_INCREMENT(exp, close);
1308 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1312 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1313 const void *data, size_t datalen, umode_t mode,
1314 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1315 __u64 rdev, struct ptlrpc_request **request)
1319 EXP_CHECK_MD_OP(exp, create);
1320 EXP_MD_COUNTER_INCREMENT(exp, create);
1321 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1322 uid, gid, cap_effective, rdev, request);
1326 static inline int md_enqueue(struct obd_export *exp,
1327 struct ldlm_enqueue_info *einfo,
1328 const union ldlm_policy_data *policy,
1329 struct md_op_data *op_data,
1330 struct lustre_handle *lockh,
1331 __u64 extra_lock_flags)
1335 EXP_CHECK_MD_OP(exp, enqueue);
1336 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1337 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, op_data, lockh,
1342 static inline int md_getattr_name(struct obd_export *exp,
1343 struct md_op_data *op_data,
1344 struct ptlrpc_request **request)
1348 EXP_CHECK_MD_OP(exp, getattr_name);
1349 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1350 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1354 static inline int md_intent_lock(struct obd_export *exp,
1355 struct md_op_data *op_data,
1356 struct lookup_intent *it,
1357 struct ptlrpc_request **reqp,
1358 ldlm_blocking_callback cb_blocking,
1359 __u64 extra_lock_flags)
1363 EXP_CHECK_MD_OP(exp, intent_lock);
1364 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1365 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1370 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1371 struct ptlrpc_request **request)
1375 EXP_CHECK_MD_OP(exp, link);
1376 EXP_MD_COUNTER_INCREMENT(exp, link);
1377 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1381 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1382 const char *old, size_t oldlen, const char *new,
1383 size_t newlen, struct ptlrpc_request **request)
1387 EXP_CHECK_MD_OP(exp, rename);
1388 EXP_MD_COUNTER_INCREMENT(exp, rename);
1389 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1394 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1395 void *ea, size_t ealen,
1396 struct ptlrpc_request **request)
1400 EXP_CHECK_MD_OP(exp, setattr);
1401 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1402 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1406 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1407 struct ptlrpc_request **request)
1412 EXP_CHECK_MD_OP(exp, fsync);
1413 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1414 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1419 static inline int md_read_page(struct obd_export *exp,
1420 struct md_op_data *op_data,
1421 struct md_callback *cb_op,
1423 struct page **ppage)
1427 EXP_CHECK_MD_OP(exp, read_page);
1428 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1429 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1434 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1435 struct ptlrpc_request **request)
1439 EXP_CHECK_MD_OP(exp, unlink);
1440 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1441 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1445 static inline int md_get_lustre_md(struct obd_export *exp,
1446 struct ptlrpc_request *req,
1447 struct obd_export *dt_exp,
1448 struct obd_export *md_exp,
1449 struct lustre_md *md)
1452 EXP_CHECK_MD_OP(exp, get_lustre_md);
1453 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1454 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1457 static inline int md_free_lustre_md(struct obd_export *exp,
1458 struct lustre_md *md)
1461 EXP_CHECK_MD_OP(exp, free_lustre_md);
1462 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1463 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1466 static inline int md_merge_attr(struct obd_export *exp,
1467 const struct lmv_stripe_md *lsm,
1468 struct cl_attr *attr,
1469 ldlm_blocking_callback cb)
1472 EXP_CHECK_MD_OP(exp, merge_attr);
1473 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1474 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1477 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1478 u64 valid, const char *name,
1479 const char *input, int input_size,
1480 int output_size, int flags, __u32 suppgid,
1481 struct ptlrpc_request **request)
1484 EXP_CHECK_MD_OP(exp, setxattr);
1485 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1486 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1487 input_size, output_size, flags,
1491 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1492 u64 valid, const char *name,
1493 const char *input, int input_size,
1494 int output_size, int flags,
1495 struct ptlrpc_request **request)
1498 EXP_CHECK_MD_OP(exp, getxattr);
1499 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1500 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1501 input_size, output_size, flags,
1505 static inline int md_set_open_replay_data(struct obd_export *exp,
1506 struct obd_client_handle *och,
1507 struct lookup_intent *it)
1510 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1511 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1512 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1515 static inline int md_clear_open_replay_data(struct obd_export *exp,
1516 struct obd_client_handle *och)
1519 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1520 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1521 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1524 static inline int md_set_lock_data(struct obd_export *exp,
1525 const struct lustre_handle *lockh,
1526 void *data, __u64 *bits)
1529 EXP_CHECK_MD_OP(exp, set_lock_data);
1530 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1531 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1535 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1536 union ldlm_policy_data *policy, enum ldlm_mode mode,
1537 enum ldlm_cancel_flags cancel_flags, void *opaque)
1542 EXP_CHECK_MD_OP(exp, cancel_unused);
1543 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1545 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1546 cancel_flags, opaque);
1550 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1551 const struct lu_fid *fid,
1552 enum ldlm_type type,
1553 union ldlm_policy_data *policy,
1554 enum ldlm_mode mode,
1555 struct lustre_handle *lockh)
1558 EXP_CHECK_MD_OP(exp, lock_match);
1559 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1560 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1561 policy, mode, lockh));
1564 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1568 EXP_CHECK_MD_OP(exp, init_ea_size);
1569 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1570 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1573 static inline int md_intent_getattr_async(struct obd_export *exp,
1574 struct md_enqueue_info *minfo)
1578 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1579 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1580 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1584 static inline int md_revalidate_lock(struct obd_export *exp,
1585 struct lookup_intent *it,
1586 struct lu_fid *fid, __u64 *bits)
1590 EXP_CHECK_MD_OP(exp, revalidate_lock);
1591 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1592 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1596 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1597 const struct lmv_stripe_md *lsm,
1598 const char *name, int namelen,
1603 EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1604 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1605 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1610 /* Unpack an MD struct from disk to in-memory format.
1611 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1613 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1614 * If *plsm == NULL then it will be allocated.
1616 static inline int md_unpackmd(struct obd_export *exp,
1617 struct lmv_stripe_md **plsm,
1618 const union lmv_mds_md *lmm, size_t lmm_size)
1622 EXP_CHECK_MD_OP(exp, unpackmd);
1623 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1624 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1628 /* OBD Metadata Support */
1630 extern int obd_init_caches(void);
1631 extern void obd_cleanup_caches(void);
1633 /* support routines */
1634 extern struct kmem_cache *obdo_cachep;
1636 #define OBDO_ALLOC(ptr) \
1638 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1641 #define OBDO_FREE(ptr) \
1643 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1647 typedef int (*register_lwp_cb)(void *data);
1649 struct lwp_register_item {
1650 struct obd_export **lri_exp;
1651 register_lwp_cb lri_cb_func;
1653 struct list_head lri_list;
1655 char lri_name[MTI_NAME_MAXLEN];
1658 /* I'm as embarrassed about this as you are.
1660 * <shaver> // XXX do not look into _superhack with remaining eye
1661 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1662 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1665 #ifdef HAVE_SERVER_SUPPORT
1666 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1667 register_lwp_cb cb_func, void *cb_data);
1668 void lustre_deregister_lwp_item(struct obd_export **exp);
1669 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1670 void lustre_notify_lwp_list(struct obd_export *exp);
1671 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1672 #endif /* HAVE_SERVER_SUPPORT */
1673 int lustre_register_fs(void);
1674 int lustre_unregister_fs(void);
1675 int lustre_check_exclusion(struct super_block *sb, char *svname);
1678 extern void obd_sysctl_init (void);
1679 extern void obd_sysctl_clean (void);
1682 typedef __u8 class_uuid_t[16];
1683 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1686 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1687 int class_add_uuid(const char *uuid, __u64 nid);
1688 int class_del_uuid (const char *uuid);
1689 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1690 void class_init_uuidlist(void);
1691 void class_exit_uuidlist(void);
1694 extern char obd_jobid_node[];
1697 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1701 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1702 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1704 /* root squash info */
1705 struct rw_semaphore;
1706 struct root_squash_info {
1709 struct list_head rsi_nosquash_nids;
1710 struct rw_semaphore rsi_sem;
1713 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1715 /* linux-module.c */
1716 extern struct miscdevice obd_psdev;
1717 int class_procfs_init(void);
1718 int class_procfs_clean(void);
1720 #endif /* __LINUX_OBD_CLASS_H */