4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
27 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
30 * Copyright (c) 2011, 2015, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
40 #include <obd_support.h>
41 #include <lustre_import.h>
42 #include <lustre_net.h>
44 #include <lustre_lib.h>
45 #include <lustre/lustre_idl.h>
46 #include <lprocfs_status.h>
48 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
49 * and resends for avoid deadlocks */
50 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
52 #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd
53 * instead of a specific set. This
54 * means that we cannot rely on the set
55 * interpret routine to be called.
56 * lov_statfs_fini() must thus be called
57 * by the request interpret routine */
58 #define OBD_STATFS_FOR_MDT0 0x0008 /* The statfs is only for retrieving
59 * information from MDT0. */
61 /* OBD Device Declarations */
62 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
63 extern struct list_head obd_types;
64 extern spinlock_t obd_types_lock;
65 extern rwlock_t obd_dev_lock;
67 /* OBD Operations Declarations */
68 extern struct obd_device *class_conn2obd(struct lustre_handle *);
69 extern struct obd_device *class_exp2obd(struct obd_export *);
70 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
71 extern int lustre_get_jobid(char *jobid);
73 struct lu_device_type;
76 struct obd_export *class_conn2export(struct lustre_handle *);
77 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
78 struct lprocfs_vars *module_vars,
79 const char *nm, struct lu_device_type *ldt);
80 int class_unregister_type(const char *nm);
82 struct obd_device *class_newdev(const char *type_name, const char *name);
83 void class_release_dev(struct obd_device *obd);
85 int class_name2dev(const char *name);
86 struct obd_device *class_name2obd(const char *name);
87 int class_uuid2dev(struct obd_uuid *uuid);
88 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
89 void class_obd_list(void);
90 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
91 const char * typ_name,
92 struct obd_uuid *grp_uuid);
93 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
95 struct obd_device * class_num2obd(int num);
96 int get_devices_count(void);
98 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
100 char *obd_export_nid2str(struct obd_export *exp);
102 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
103 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
104 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
106 int obd_zombie_impexp_init(void);
107 void obd_zombie_impexp_stop(void);
108 void obd_zombie_impexp_cull(void);
109 void obd_zombie_barrier(void);
110 void obd_exports_barrier(struct obd_device *obd);
111 int kuc_len(int payload_len);
112 struct kuc_hdr * kuc_ptr(void *p);
113 void *kuc_alloc(int payload_len, int transport, int type);
114 void kuc_free(void *p, int payload_len);
115 int obd_get_request_slot(struct client_obd *cli);
116 void obd_put_request_slot(struct client_obd *cli);
117 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
118 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
119 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
120 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
121 int obd_mod_rpc_stats_seq_show(struct client_obd *cli, struct seq_file *seq);
123 __u16 obd_get_mod_rpc_slot(struct client_obd *cli, __u32 opc,
124 struct lookup_intent *it);
125 void obd_put_mod_rpc_slot(struct client_obd *cli, __u32 opc,
126 struct lookup_intent *it, __u16 tag);
130 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
131 struct llog_rec_hdr *, void *);
133 extern atomic_t obd_stale_export_num;
134 extern struct list_head obd_stale_exports;
135 extern spinlock_t obd_stale_export_lock;
137 struct obd_export *obd_stale_export_get(void);
138 void obd_stale_export_put(struct obd_export *exp);
139 void obd_stale_export_adjust(struct obd_export *exp);
142 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
143 const char *new_name);
144 int class_process_config(struct lustre_cfg *lcfg);
145 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
146 struct lustre_cfg *lcfg, void *data);
147 int class_attach(struct lustre_cfg *lcfg);
148 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
149 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
150 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
151 struct obd_device *class_incref(struct obd_device *obd,
152 const char *scope, const void *source);
153 void class_decref(struct obd_device *obd,
154 const char *scope, const void *source);
155 void dump_exports(struct obd_device *obd, int locks);
156 int class_config_llog_handler(const struct lu_env *env,
157 struct llog_handle *handle,
158 struct llog_rec_hdr *rec, void *data);
159 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
160 int class_add_uuid(const char *uuid, __u64 nid);
162 #define CFG_F_START 0x01 /* Set when we start updating from a log */
163 #define CFG_F_MARKER 0x02 /* We are within a maker */
164 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
165 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
166 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
168 /* Passed as data param to class_config_parse_llog */
169 struct config_llog_instance {
172 struct super_block *cfg_sb;
173 struct obd_uuid cfg_uuid;
174 llog_cb_t cfg_callback;
175 int cfg_last_idx; /* for partial llog processing */
179 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
180 char *name, struct config_llog_instance *cfg);
184 CONFIG_T_SPTLRPC = 1,
185 CONFIG_T_RECOVER = 2,
187 CONFIG_T_NODEMAP = 4,
191 #define PARAMS_FILENAME "params"
192 #define LCTL_UPCALL "lctl"
194 /* list of active configuration logs */
195 struct config_llog_data {
196 struct ldlm_res_id cld_resid;
197 struct config_llog_instance cld_cfg;
198 struct list_head cld_list_chain;
199 atomic_t cld_refcount;
200 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
201 struct config_llog_data *cld_params; /* common parameters log */
202 struct config_llog_data *cld_recover;/* imperative recover log */
203 struct config_llog_data *cld_nodemap;/* nodemap log */
204 struct obd_export *cld_mgcexp;
205 struct mutex cld_lock;
207 unsigned int cld_stopping:1, /* we were told to stop
209 cld_lostlock:1; /* lock not requeued */
213 struct lustre_profile {
214 struct list_head lp_list;
219 bool lp_list_deleted;
222 struct lustre_profile *class_get_profile(const char * prof);
223 void class_del_profile(const char *prof);
224 void class_put_profile(struct lustre_profile *lprof);
225 void class_del_profiles(void);
228 #if LUSTRE_TRACKS_LOCK_EXP_REFS
230 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
231 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
232 extern void (*class_export_dump_hook)(struct obd_export *);
236 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
237 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
241 #define class_export_rpc_inc(exp) \
243 atomic_inc(&(exp)->exp_rpc_count); \
244 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
245 (exp), atomic_read(&(exp)->exp_rpc_count)); \
248 #define class_export_rpc_dec(exp) \
250 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
251 atomic_dec(&(exp)->exp_rpc_count); \
252 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
253 (exp), atomic_read(&(exp)->exp_rpc_count)); \
256 #define class_export_lock_get(exp, lock) \
258 atomic_inc(&(exp)->exp_locks_count); \
259 __class_export_add_lock_ref(exp, lock); \
260 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
261 (exp), atomic_read(&(exp)->exp_locks_count)); \
262 class_export_get(exp); \
265 #define class_export_lock_put(exp, lock) \
267 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
268 atomic_dec(&(exp)->exp_locks_count); \
269 __class_export_del_lock_ref(exp, lock); \
270 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
271 (exp), atomic_read(&(exp)->exp_locks_count)); \
272 class_export_put(exp); \
275 #define class_export_cb_get(exp) \
277 atomic_inc(&(exp)->exp_cb_count); \
278 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
279 (exp), atomic_read(&(exp)->exp_cb_count)); \
280 class_export_get(exp); \
283 #define class_export_cb_put(exp) \
285 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
286 atomic_dec(&(exp)->exp_cb_count); \
287 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
288 (exp), atomic_read(&(exp)->exp_cb_count)); \
289 class_export_put(exp); \
293 struct obd_export *class_export_get(struct obd_export *exp);
294 void class_export_put(struct obd_export *exp);
295 struct obd_export *class_new_export(struct obd_device *obddev,
296 struct obd_uuid *cluuid);
297 void class_unlink_export(struct obd_export *exp);
299 struct obd_import *class_import_get(struct obd_import *);
300 void class_import_put(struct obd_import *);
301 struct obd_import *class_new_import(struct obd_device *obd);
302 void class_destroy_import(struct obd_import *exp);
304 struct obd_type *class_search_type(const char *name);
305 struct obd_type *class_get_type(const char *name);
306 void class_put_type(struct obd_type *type);
307 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
308 struct obd_uuid *cluuid);
309 int class_disconnect(struct obd_export *exp);
310 void class_fail_export(struct obd_export *exp);
311 int class_connected_export(struct obd_export *exp);
312 void class_disconnect_exports(struct obd_device *obddev);
313 int class_manual_cleanup(struct obd_device *obd);
314 void class_disconnect_stale_exports(struct obd_device *,
315 int (*test_export)(struct obd_export *));
316 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
318 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
319 (obd->obd_force ? OBD_OPT_FORCE : 0) |
320 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
324 #ifdef HAVE_SERVER_SUPPORT
325 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
327 LASSERT(exp->exp_obd);
328 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
330 return exp->exp_obd->u.obt.obt_lut;
333 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
335 LASSERT(obd->u.obt.obt_lut);
336 return &obd->u.obt.obt_lut->lut_lsd;
344 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
345 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
347 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
348 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
350 #define OBT(dev) (dev)->obd_type
351 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
352 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
353 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
355 /* Ensure obd_setup: used for cleanup which must be called
356 while obd is stopping */
357 #define OBD_CHECK_DEV(obd) \
360 CERROR("NULL device\n"); \
365 /* ensure obd_setup and !obd_stopping */
366 #define OBD_CHECK_DEV_ACTIVE(obd) \
368 OBD_CHECK_DEV(obd); \
369 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
370 CERROR("Device %d not setup\n", \
377 #ifdef CONFIG_PROC_FS
378 #define OBD_COUNTER_OFFSET(op) \
379 ((offsetof(struct obd_ops, o_ ## op) - \
380 offsetof(struct obd_ops, o_iocontrol)) \
381 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
383 /* The '- 1' below is for o_owner. */
384 #define NUM_OBD_STATS \
385 (sizeof(struct obd_ops) / \
386 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
388 #define OBD_COUNTER_INCREMENT(obd, op) \
389 lprocfs_counter_incr((obd)->obd_stats, \
390 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
392 #define EXP_COUNTER_INCREMENT(exp, op) \
395 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
396 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
397 if ((exp)->exp_obd->obd_uses_nid_stats && \
398 (exp)->exp_nid_stats != NULL) \
399 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
403 #define _MD_COUNTER_OFFSET(m_op) \
404 ((offsetof(struct md_ops, m_op) - \
405 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
406 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
408 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
410 #define NUM_MD_STATS \
411 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
412 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
414 /* Note that we only increment md counters for ops whose offset is less
415 * than NUM_MD_STATS. This is explained in a comment in the definition
416 * of struct md_ops. */
417 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
419 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
420 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
421 (exp)->exp_obd->obd_md_cntr_base + \
422 MD_COUNTER_OFFSET(op)); \
426 #define OBD_COUNTER_OFFSET(op)
427 #define OBD_COUNTER_INCREMENT(obd, op)
428 #define EXP_COUNTER_INCREMENT(exp, op)
429 #define EXP_MD_COUNTER_INCREMENT(exp, op)
432 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
434 /* Always add in ldlm_stats */
435 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
436 ,LPROCFS_STATS_FLAG_NOPERCPU);
437 if (tmp->nid_ldlm_stats == NULL)
440 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
442 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
443 tmp->nid_ldlm_stats);
446 #define EXP_CHECK_MD_OP(exp, op) \
448 if ((exp) == NULL) { \
449 CERROR("obd_" #op ": NULL export\n"); \
452 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
453 CERROR("obd_" #op ": cleaned up obd\n"); \
454 RETURN(-EOPNOTSUPP); \
456 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
457 CERROR("obd_" #op ": dev %s/%d no operation\n", \
458 (exp)->exp_obd->obd_name, \
459 (exp)->exp_obd->obd_minor); \
460 RETURN(-EOPNOTSUPP); \
465 #define OBD_CHECK_DT_OP(obd, op, err) \
467 if (!OBT(obd) || !OBP((obd), op)) { \
469 CERROR("obd_" #op ": dev %d no operation\n", \
475 #define EXP_CHECK_DT_OP(exp, op) \
477 if ((exp) == NULL) { \
478 CERROR("obd_" #op ": NULL export\n"); \
481 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
482 CERROR("obd_" #op ": cleaned up obd\n"); \
483 RETURN(-EOPNOTSUPP); \
485 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
486 CERROR("obd_" #op ": dev %d no operation\n", \
487 (exp)->exp_obd->obd_minor); \
488 RETURN(-EOPNOTSUPP); \
492 #define CTXT_CHECK_OP(ctxt, op, err) \
494 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
496 CERROR("lop_" #op ": dev %d no operation\n", \
497 ctxt->loc_obd->obd_minor); \
502 static inline int class_devno_max(void)
504 return MAX_OBD_DEVICES;
507 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
508 __u32 keylen, void *key,
509 __u32 *vallen, void *val)
514 EXP_CHECK_DT_OP(exp, get_info);
515 EXP_COUNTER_INCREMENT(exp, get_info);
517 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
521 static inline int obd_set_info_async(const struct lu_env *env,
522 struct obd_export *exp,
523 __u32 keylen, void *key,
524 __u32 vallen, void *val,
525 struct ptlrpc_request_set *set)
530 EXP_CHECK_DT_OP(exp, set_info_async);
531 EXP_COUNTER_INCREMENT(exp, set_info_async);
533 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
539 * obd-lu integration.
541 * Functionality is being moved into new lu_device-based layering, but some
542 * pieces of configuration process are still based on obd devices.
544 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
545 * subsume ->o_setup() methods of obd devices they replace. The same for
546 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
547 * result, obd_setup() and obd_process_config() branch and call one XOR
550 * Yet neither lu_device_type_operations::ldto_device_fini() nor
551 * lu_device_type_operations::ldto_device_free() fully implement the
552 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
553 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
556 #define DECLARE_LU_VARS(ldt, d) \
557 struct lu_device_type *ldt; \
560 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
563 DECLARE_LU_VARS(ldt, d);
566 ldt = obd->obd_type->typ_lu;
568 struct lu_context session_ctx;
570 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
571 session_ctx.lc_thread = NULL;
572 lu_context_enter(&session_ctx);
574 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
576 env.le_ses = &session_ctx;
577 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
586 lu_context_exit(&session_ctx);
587 lu_context_fini(&session_ctx);
590 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
591 OBD_COUNTER_INCREMENT(obd, setup);
592 rc = OBP(obd, setup)(obd, cfg);
597 static inline int obd_precleanup(struct obd_device *obd)
600 DECLARE_LU_VARS(ldt, d);
604 ldt = obd->obd_type->typ_lu;
606 if (ldt != NULL && d != NULL) {
609 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
611 ldt->ldt_ops->ldto_device_fini(&env, d);
615 OBD_CHECK_DT_OP(obd, precleanup, 0);
616 OBD_COUNTER_INCREMENT(obd, precleanup);
618 rc = OBP(obd, precleanup)(obd);
622 static inline int obd_cleanup(struct obd_device *obd)
625 DECLARE_LU_VARS(ldt, d);
630 ldt = obd->obd_type->typ_lu;
632 if (ldt != NULL && d != NULL) {
635 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
637 ldt->ldt_ops->ldto_device_free(&env, d);
639 obd->obd_lu_dev = NULL;
642 OBD_CHECK_DT_OP(obd, cleanup, 0);
643 OBD_COUNTER_INCREMENT(obd, cleanup);
645 rc = OBP(obd, cleanup)(obd);
649 static inline void obd_cleanup_client_import(struct obd_device *obd)
653 /* If we set up but never connected, the
654 client import will not have been cleaned. */
655 down_write(&obd->u.cli.cl_sem);
656 if (obd->u.cli.cl_import) {
657 struct obd_import *imp;
658 imp = obd->u.cli.cl_import;
659 CDEBUG(D_CONFIG, "%s: client import never connected\n",
661 ptlrpc_invalidate_import(imp);
662 client_destroy_import(imp);
663 obd->u.cli.cl_import = NULL;
665 up_write(&obd->u.cli.cl_sem);
671 obd_process_config(struct obd_device *obd, int datalen, void *data)
674 DECLARE_LU_VARS(ldt, d);
679 obd->obd_process_conf = 1;
680 ldt = obd->obd_type->typ_lu;
682 if (ldt != NULL && d != NULL) {
685 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
687 rc = d->ld_ops->ldo_process_config(&env, d, data);
691 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
692 rc = OBP(obd, process_config)(obd, datalen, data);
694 OBD_COUNTER_INCREMENT(obd, process_config);
695 obd->obd_process_conf = 0;
700 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
706 EXP_CHECK_DT_OP(exp, create);
707 EXP_COUNTER_INCREMENT(exp, create);
709 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
713 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
719 EXP_CHECK_DT_OP(exp, destroy);
720 EXP_COUNTER_INCREMENT(exp, destroy);
722 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
726 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
732 EXP_CHECK_DT_OP(exp, getattr);
733 EXP_COUNTER_INCREMENT(exp, getattr);
734 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
739 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
745 EXP_CHECK_DT_OP(exp, setattr);
746 EXP_COUNTER_INCREMENT(exp, setattr);
747 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
752 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
755 struct obd_device *obd = imp->imp_obd;
759 OBD_CHECK_DEV_ACTIVE(obd);
760 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
761 OBD_COUNTER_INCREMENT(obd, add_conn);
763 rc = OBP(obd, add_conn)(imp, uuid, priority);
767 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
769 struct obd_device *obd = imp->imp_obd;
773 OBD_CHECK_DEV_ACTIVE(obd);
774 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
775 OBD_COUNTER_INCREMENT(obd, del_conn);
777 rc = OBP(obd, del_conn)(imp, uuid);
781 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
783 struct obd_uuid *uuid;
786 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
787 EXP_COUNTER_INCREMENT(exp, get_uuid);
789 uuid = OBP(exp->exp_obd, get_uuid)(exp);
793 /** Create a new /a exp on device /a obd for the uuid /a cluuid
794 * @param exp New export handle
795 * @param d Connect data, supported flags are set, flags also understood
796 * by obd are returned.
798 static inline int obd_connect(const struct lu_env *env,
799 struct obd_export **exp,struct obd_device *obd,
800 struct obd_uuid *cluuid,
801 struct obd_connect_data *data,
805 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
809 OBD_CHECK_DEV_ACTIVE(obd);
810 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
811 OBD_COUNTER_INCREMENT(obd, connect);
813 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
814 /* check that only subset is granted */
815 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
816 data->ocd_connect_flags));
820 static inline int obd_reconnect(const struct lu_env *env,
821 struct obd_export *exp,
822 struct obd_device *obd,
823 struct obd_uuid *cluuid,
824 struct obd_connect_data *d,
828 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
833 OBD_CHECK_DEV_ACTIVE(obd);
834 OBD_CHECK_DT_OP(obd, reconnect, 0);
835 OBD_COUNTER_INCREMENT(obd, reconnect);
837 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
838 /* check that only subset is granted */
839 LASSERT(ergo(d != NULL,
840 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
844 static inline int obd_disconnect(struct obd_export *exp)
849 EXP_CHECK_DT_OP(exp, disconnect);
850 EXP_COUNTER_INCREMENT(exp, disconnect);
852 rc = OBP(exp->exp_obd, disconnect)(exp);
856 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
857 enum lu_cli_type type)
862 OBD_CHECK_DT_OP(obd, fid_init, 0);
863 OBD_COUNTER_INCREMENT(obd, fid_init);
865 rc = OBP(obd, fid_init)(obd, exp, type);
869 static inline int obd_fid_fini(struct obd_device *obd)
874 OBD_CHECK_DT_OP(obd, fid_fini, 0);
875 OBD_COUNTER_INCREMENT(obd, fid_fini);
877 rc = OBP(obd, fid_fini)(obd);
881 static inline int obd_fid_alloc(const struct lu_env *env,
882 struct obd_export *exp,
884 struct md_op_data *op_data)
889 EXP_CHECK_DT_OP(exp, fid_alloc);
890 EXP_COUNTER_INCREMENT(exp, fid_alloc);
892 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
896 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
901 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
902 EXP_COUNTER_INCREMENT(exp, ping);
904 rc = OBP(exp->exp_obd, ping)(env, exp);
908 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
913 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
914 OBD_COUNTER_INCREMENT(obd, pool_new);
916 rc = OBP(obd, pool_new)(obd, poolname);
920 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
925 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
926 OBD_COUNTER_INCREMENT(obd, pool_del);
928 rc = OBP(obd, pool_del)(obd, poolname);
932 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
937 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
938 OBD_COUNTER_INCREMENT(obd, pool_add);
940 rc = OBP(obd, pool_add)(obd, poolname, ostname);
944 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
949 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
950 OBD_COUNTER_INCREMENT(obd, pool_rem);
952 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
956 static inline void obd_getref(struct obd_device *obd)
959 if (OBT(obd) && OBP(obd, getref)) {
960 OBD_COUNTER_INCREMENT(obd, getref);
961 OBP(obd, getref)(obd);
966 static inline void obd_putref(struct obd_device *obd)
969 if (OBT(obd) && OBP(obd, putref)) {
970 OBD_COUNTER_INCREMENT(obd, putref);
971 OBP(obd, putref)(obd);
976 static inline int obd_init_export(struct obd_export *exp)
981 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
982 OBP((exp)->exp_obd, init_export))
983 rc = OBP(exp->exp_obd, init_export)(exp);
987 static inline int obd_destroy_export(struct obd_export *exp)
990 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
991 OBP((exp)->exp_obd, destroy_export))
992 OBP(exp->exp_obd, destroy_export)(exp);
996 /* @max_age is the oldest time in jiffies that we accept using a cached data.
997 * If the cache is older than @max_age we will get a new value from the
998 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
999 static inline int obd_statfs_async(struct obd_export *exp,
1000 struct obd_info *oinfo,
1002 struct ptlrpc_request_set *rqset)
1005 struct obd_device *obd;
1008 if (exp == NULL || exp->exp_obd == NULL)
1012 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1013 OBD_COUNTER_INCREMENT(obd, statfs);
1015 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1016 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1017 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1018 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1020 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1021 " objects "LPU64"/"LPU64"\n",
1022 obd->obd_name, &obd->obd_osfs,
1023 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1024 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1025 spin_lock(&obd->obd_osfs_lock);
1026 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1027 spin_unlock(&obd->obd_osfs_lock);
1028 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1029 if (oinfo->oi_cb_up)
1030 oinfo->oi_cb_up(oinfo, 0);
1035 static inline int obd_statfs_rqset(struct obd_export *exp,
1036 struct obd_statfs *osfs, __u64 max_age,
1039 struct ptlrpc_request_set *set = NULL;
1040 struct obd_info oinfo = {
1048 set = ptlrpc_prep_set();
1052 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1054 rc = ptlrpc_set_wait(set);
1056 ptlrpc_set_destroy(set);
1061 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1062 * If the cache is older than @max_age we will get a new value from the
1063 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1064 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1065 struct obd_statfs *osfs, __u64 max_age,
1069 struct obd_device *obd = exp->exp_obd;
1075 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1076 OBD_COUNTER_INCREMENT(obd, statfs);
1078 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1079 obd->obd_osfs_age, max_age);
1080 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1081 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1083 spin_lock(&obd->obd_osfs_lock);
1084 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1085 obd->obd_osfs_age = cfs_time_current_64();
1086 spin_unlock(&obd->obd_osfs_lock);
1089 CDEBUG(D_SUPER, "%s: use %p cache blocks "LPU64"/"LPU64
1090 " objects "LPU64"/"LPU64"\n",
1091 obd->obd_name, &obd->obd_osfs,
1092 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1093 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1094 spin_lock(&obd->obd_osfs_lock);
1095 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1096 spin_unlock(&obd->obd_osfs_lock);
1101 static inline int obd_preprw(const struct lu_env *env, int cmd,
1102 struct obd_export *exp, struct obdo *oa,
1103 int objcount, struct obd_ioobj *obj,
1104 struct niobuf_remote *remote, int *pages,
1105 struct niobuf_local *local)
1110 EXP_CHECK_DT_OP(exp, preprw);
1111 EXP_COUNTER_INCREMENT(exp, preprw);
1112 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1118 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1119 struct obd_export *exp, struct obdo *oa,
1120 int objcount, struct obd_ioobj *obj,
1121 struct niobuf_remote *rnb, int pages,
1122 struct niobuf_local *local, int rc)
1126 EXP_CHECK_DT_OP(exp, commitrw);
1127 EXP_COUNTER_INCREMENT(exp, commitrw);
1128 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1129 rnb, pages, local, rc);
1134 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1135 int len, void *karg, void __user *uarg)
1140 EXP_CHECK_DT_OP(exp, iocontrol);
1141 EXP_COUNTER_INCREMENT(exp, iocontrol);
1143 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1147 static inline void obd_import_event(struct obd_device *obd,
1148 struct obd_import *imp,
1149 enum obd_import_event event)
1153 CERROR("NULL device\n");
1157 if (obd->obd_set_up && OBP(obd, import_event)) {
1158 OBD_COUNTER_INCREMENT(obd, import_event);
1159 OBP(obd, import_event)(obd, imp, event);
1164 static inline int obd_notify(struct obd_device *obd,
1165 struct obd_device *watched,
1166 enum obd_notify_event ev,
1173 if (!obd->obd_set_up) {
1174 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1178 if (!OBP(obd, notify)) {
1179 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1183 OBD_COUNTER_INCREMENT(obd, notify);
1184 rc = OBP(obd, notify)(obd, watched, ev, data);
1188 static inline int obd_notify_observer(struct obd_device *observer,
1189 struct obd_device *observed,
1190 enum obd_notify_event ev,
1196 struct obd_notify_upcall *onu;
1198 if (observer->obd_observer)
1199 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1203 * Also, call non-obd listener, if any
1205 onu = &observer->obd_upcall;
1206 if (onu->onu_upcall != NULL)
1207 rc2 = onu->onu_upcall(observer, observed, ev,
1208 onu->onu_owner, NULL);
1212 return rc1 ? rc1 : rc2;
1215 static inline int obd_quotactl(struct obd_export *exp,
1216 struct obd_quotactl *oqctl)
1221 EXP_CHECK_DT_OP(exp, quotactl);
1222 EXP_COUNTER_INCREMENT(exp, quotactl);
1224 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1228 static inline int obd_health_check(const struct lu_env *env,
1229 struct obd_device *obd)
1231 /* returns: 0 on healthy
1232 * >0 on unhealthy + reason code/flag
1233 * however the only suppored reason == 1 right now
1234 * We'll need to define some better reasons
1235 * or flags in the future.
1241 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1242 if (obd == NULL || !OBT(obd)) {
1243 CERROR("cleaned up obd\n");
1244 RETURN(-EOPNOTSUPP);
1246 if (!obd->obd_set_up || obd->obd_stopping)
1248 if (!OBP(obd, health_check))
1251 rc = OBP(obd, health_check)(env, obd);
1255 static inline int obd_register_observer(struct obd_device *obd,
1256 struct obd_device *observer)
1260 down_write(&obd->obd_observer_link_sem);
1261 if (obd->obd_observer && observer) {
1262 up_write(&obd->obd_observer_link_sem);
1265 obd->obd_observer = observer;
1266 up_write(&obd->obd_observer_link_sem);
1270 /* metadata helpers */
1271 static inline int md_get_root(struct obd_export *exp, const char *fileset,
1277 EXP_CHECK_MD_OP(exp, get_root);
1278 EXP_MD_COUNTER_INCREMENT(exp, get_root);
1279 rc = MDP(exp->exp_obd, get_root)(exp, fileset, fid);
1284 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1285 struct ptlrpc_request **request)
1289 EXP_CHECK_MD_OP(exp, getattr);
1290 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1291 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1295 static inline int md_null_inode(struct obd_export *exp,
1296 const struct lu_fid *fid)
1300 EXP_CHECK_MD_OP(exp, null_inode);
1301 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1302 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1306 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1307 struct md_open_data *mod,
1308 struct ptlrpc_request **request)
1312 EXP_CHECK_MD_OP(exp, close);
1313 EXP_MD_COUNTER_INCREMENT(exp, close);
1314 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1318 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1319 const void *data, size_t datalen, umode_t mode,
1320 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1321 __u64 rdev, struct ptlrpc_request **request)
1325 EXP_CHECK_MD_OP(exp, create);
1326 EXP_MD_COUNTER_INCREMENT(exp, create);
1327 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1328 uid, gid, cap_effective, rdev, request);
1332 static inline int md_enqueue(struct obd_export *exp,
1333 struct ldlm_enqueue_info *einfo,
1334 const union ldlm_policy_data *policy,
1335 struct lookup_intent *it,
1336 struct md_op_data *op_data,
1337 struct lustre_handle *lockh,
1338 __u64 extra_lock_flags)
1342 EXP_CHECK_MD_OP(exp, enqueue);
1343 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1344 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, it, op_data, lockh,
1349 static inline int md_getattr_name(struct obd_export *exp,
1350 struct md_op_data *op_data,
1351 struct ptlrpc_request **request)
1355 EXP_CHECK_MD_OP(exp, getattr_name);
1356 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1357 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1361 static inline int md_intent_lock(struct obd_export *exp,
1362 struct md_op_data *op_data,
1363 struct lookup_intent *it,
1364 struct ptlrpc_request **reqp,
1365 ldlm_blocking_callback cb_blocking,
1366 __u64 extra_lock_flags)
1370 EXP_CHECK_MD_OP(exp, intent_lock);
1371 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1372 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1377 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1378 struct ptlrpc_request **request)
1382 EXP_CHECK_MD_OP(exp, link);
1383 EXP_MD_COUNTER_INCREMENT(exp, link);
1384 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1388 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1389 const char *old, size_t oldlen, const char *new,
1390 size_t newlen, struct ptlrpc_request **request)
1394 EXP_CHECK_MD_OP(exp, rename);
1395 EXP_MD_COUNTER_INCREMENT(exp, rename);
1396 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1401 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1402 void *ea, size_t ealen,
1403 struct ptlrpc_request **request)
1407 EXP_CHECK_MD_OP(exp, setattr);
1408 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1409 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1413 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1414 struct ptlrpc_request **request)
1419 EXP_CHECK_MD_OP(exp, fsync);
1420 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1421 rc = MDP(exp->exp_obd, fsync)(exp, fid, request);
1426 static inline int md_read_page(struct obd_export *exp,
1427 struct md_op_data *op_data,
1428 struct md_callback *cb_op,
1430 struct page **ppage)
1434 EXP_CHECK_MD_OP(exp, read_page);
1435 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1436 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1441 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1442 struct ptlrpc_request **request)
1446 EXP_CHECK_MD_OP(exp, unlink);
1447 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1448 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1452 static inline int md_get_lustre_md(struct obd_export *exp,
1453 struct ptlrpc_request *req,
1454 struct obd_export *dt_exp,
1455 struct obd_export *md_exp,
1456 struct lustre_md *md)
1459 EXP_CHECK_MD_OP(exp, get_lustre_md);
1460 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1461 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1464 static inline int md_free_lustre_md(struct obd_export *exp,
1465 struct lustre_md *md)
1468 EXP_CHECK_MD_OP(exp, free_lustre_md);
1469 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1470 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1473 static inline int md_merge_attr(struct obd_export *exp,
1474 const struct lmv_stripe_md *lsm,
1475 struct cl_attr *attr,
1476 ldlm_blocking_callback cb)
1479 EXP_CHECK_MD_OP(exp, merge_attr);
1480 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1481 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1484 static inline int md_setxattr(struct obd_export *exp, const struct lu_fid *fid,
1485 u64 valid, const char *name,
1486 const char *input, int input_size,
1487 int output_size, int flags, __u32 suppgid,
1488 struct ptlrpc_request **request)
1491 EXP_CHECK_MD_OP(exp, setxattr);
1492 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1493 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1494 input_size, output_size, flags,
1498 static inline int md_getxattr(struct obd_export *exp, const struct lu_fid *fid,
1499 u64 valid, const char *name,
1500 const char *input, int input_size,
1501 int output_size, int flags,
1502 struct ptlrpc_request **request)
1505 EXP_CHECK_MD_OP(exp, getxattr);
1506 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1507 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1508 input_size, output_size, flags,
1512 static inline int md_set_open_replay_data(struct obd_export *exp,
1513 struct obd_client_handle *och,
1514 struct lookup_intent *it)
1517 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1518 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1519 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1522 static inline int md_clear_open_replay_data(struct obd_export *exp,
1523 struct obd_client_handle *och)
1526 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1527 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1528 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1531 static inline int md_set_lock_data(struct obd_export *exp,
1532 __u64 *lockh, void *data, __u64 *bits)
1535 EXP_CHECK_MD_OP(exp, set_lock_data);
1536 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1537 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1541 int md_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
1542 union ldlm_policy_data *policy, enum ldlm_mode mode,
1543 enum ldlm_cancel_flags cancel_flags, void *opaque)
1548 EXP_CHECK_MD_OP(exp, cancel_unused);
1549 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1551 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1552 cancel_flags, opaque);
1556 static inline enum ldlm_mode md_lock_match(struct obd_export *exp, __u64 flags,
1557 const struct lu_fid *fid,
1558 enum ldlm_type type,
1559 union ldlm_policy_data *policy,
1560 enum ldlm_mode mode,
1561 struct lustre_handle *lockh)
1564 EXP_CHECK_MD_OP(exp, lock_match);
1565 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1566 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1567 policy, mode, lockh));
1570 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1574 EXP_CHECK_MD_OP(exp, init_ea_size);
1575 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1576 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1579 static inline int md_get_remote_perm(struct obd_export *exp,
1580 const struct lu_fid *fid, u32 suppgid,
1581 struct ptlrpc_request **request)
1584 EXP_CHECK_MD_OP(exp, get_remote_perm);
1585 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1587 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, suppgid, request));
1590 static inline int md_intent_getattr_async(struct obd_export *exp,
1591 struct md_enqueue_info *minfo)
1595 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1596 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1597 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo);
1601 static inline int md_revalidate_lock(struct obd_export *exp,
1602 struct lookup_intent *it,
1603 struct lu_fid *fid, __u64 *bits)
1607 EXP_CHECK_MD_OP(exp, revalidate_lock);
1608 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1609 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1613 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1614 const struct lmv_stripe_md *lsm,
1615 const char *name, int namelen,
1620 EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1621 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1622 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1627 /* Unpack an MD struct from disk to in-memory format.
1628 * Returns +ve size of unpacked MD (0 for free), or -ve error.
1630 * If *plsm != NULL and lmm == NULL then *lsm will be freed.
1631 * If *plsm == NULL then it will be allocated.
1633 static inline int md_unpackmd(struct obd_export *exp,
1634 struct lmv_stripe_md **plsm,
1635 const union lmv_mds_md *lmm, size_t lmm_size)
1639 EXP_CHECK_MD_OP(exp, unpackmd);
1640 EXP_MD_COUNTER_INCREMENT(exp, unpackmd);
1641 rc = MDP(exp->exp_obd, unpackmd)(exp, plsm, lmm, lmm_size);
1645 /* OBD Metadata Support */
1647 extern int obd_init_caches(void);
1648 extern void obd_cleanup_caches(void);
1650 /* support routines */
1651 extern struct kmem_cache *obdo_cachep;
1653 #define OBDO_ALLOC(ptr) \
1655 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1658 #define OBDO_FREE(ptr) \
1660 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1664 typedef int (*register_lwp_cb)(void *data);
1666 struct lwp_register_item {
1667 struct obd_export **lri_exp;
1668 register_lwp_cb lri_cb_func;
1670 struct list_head lri_list;
1672 char lri_name[MTI_NAME_MAXLEN];
1675 /* I'm as embarrassed about this as you are.
1677 * <shaver> // XXX do not look into _superhack with remaining eye
1678 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1679 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1682 #ifdef HAVE_SERVER_SUPPORT
1683 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1684 register_lwp_cb cb_func, void *cb_data);
1685 void lustre_deregister_lwp_item(struct obd_export **exp);
1686 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1687 void lustre_notify_lwp_list(struct obd_export *exp);
1688 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1689 #endif /* HAVE_SERVER_SUPPORT */
1690 int lustre_register_fs(void);
1691 int lustre_unregister_fs(void);
1692 int lustre_check_exclusion(struct super_block *sb, char *svname);
1695 extern void obd_sysctl_init (void);
1696 extern void obd_sysctl_clean (void);
1699 typedef __u8 class_uuid_t[16];
1700 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1703 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1704 int class_add_uuid(const char *uuid, __u64 nid);
1705 int class_del_uuid (const char *uuid);
1706 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1707 void class_init_uuidlist(void);
1708 void class_exit_uuidlist(void);
1711 extern char obd_jobid_node[];
1714 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1718 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1719 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1721 /* root squash info */
1722 struct rw_semaphore;
1723 struct root_squash_info {
1726 struct list_head rsi_nosquash_nids;
1727 struct rw_semaphore rsi_sem;
1730 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1732 /* linux-module.c */
1733 extern struct miscdevice obd_psdev;
1734 int class_procfs_init(void);
1735 int class_procfs_clean(void);
1737 #endif /* __LINUX_OBD_CLASS_H */