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, 2014, 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 int kuc_ispayload(void *p);
114 void *kuc_alloc(int payload_len, int transport, int type);
115 void kuc_free(void *p, int payload_len);
116 int obd_get_request_slot(struct client_obd *cli);
117 void obd_put_request_slot(struct client_obd *cli);
118 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
119 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
120 __u16 obd_get_max_mod_rpcs_in_flight(struct client_obd *cli);
121 int obd_set_max_mod_rpcs_in_flight(struct client_obd *cli, __u16 max);
125 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
126 struct llog_rec_hdr *, void *);
128 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
129 const char *new_name);
130 int class_process_config(struct lustre_cfg *lcfg);
131 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
132 struct lustre_cfg *lcfg, void *data);
133 int class_attach(struct lustre_cfg *lcfg);
134 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
135 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
136 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
137 struct obd_device *class_incref(struct obd_device *obd,
138 const char *scope, const void *source);
139 void class_decref(struct obd_device *obd,
140 const char *scope, const void *source);
141 void dump_exports(struct obd_device *obd, int locks);
142 int class_config_llog_handler(const struct lu_env *env,
143 struct llog_handle *handle,
144 struct llog_rec_hdr *rec, void *data);
145 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
146 int class_add_uuid(const char *uuid, __u64 nid);
148 #define CFG_F_START 0x01 /* Set when we start updating from a log */
149 #define CFG_F_MARKER 0x02 /* We are within a maker */
150 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
151 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
152 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
154 /* Passed as data param to class_config_parse_llog */
155 struct config_llog_instance {
158 struct super_block *cfg_sb;
159 struct obd_uuid cfg_uuid;
160 llog_cb_t cfg_callback;
161 int cfg_last_idx; /* for partial llog processing */
165 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
166 char *name, struct config_llog_instance *cfg);
167 int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
168 char *name, struct config_llog_instance *cfg);
172 CONFIG_T_SPTLRPC = 1,
173 CONFIG_T_RECOVER = 2,
178 #define PARAMS_FILENAME "params"
179 #define LCTL_UPCALL "lctl"
181 /* list of active configuration logs */
182 struct config_llog_data {
183 struct ldlm_res_id cld_resid;
184 struct config_llog_instance cld_cfg;
185 struct list_head cld_list_chain;
186 atomic_t cld_refcount;
187 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
188 struct config_llog_data *cld_params; /* common parameters log */
189 struct config_llog_data *cld_recover;/* imperative recover log */
190 struct obd_export *cld_mgcexp;
191 struct mutex cld_lock;
193 unsigned int cld_stopping:1, /* we were told to stop
195 cld_lostlock:1; /* lock not requeued */
199 struct lustre_profile {
200 struct list_head lp_list;
206 struct lustre_profile *class_get_profile(const char * prof);
207 void class_del_profile(const char *prof);
208 void class_del_profiles(void);
210 #if LUSTRE_TRACKS_LOCK_EXP_REFS
212 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
213 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
214 extern void (*class_export_dump_hook)(struct obd_export *);
218 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
219 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
223 #define class_export_rpc_inc(exp) \
225 atomic_inc(&(exp)->exp_rpc_count); \
226 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
227 (exp), atomic_read(&(exp)->exp_rpc_count)); \
230 #define class_export_rpc_dec(exp) \
232 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
233 atomic_dec(&(exp)->exp_rpc_count); \
234 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
235 (exp), atomic_read(&(exp)->exp_rpc_count)); \
238 #define class_export_lock_get(exp, lock) \
240 atomic_inc(&(exp)->exp_locks_count); \
241 __class_export_add_lock_ref(exp, lock); \
242 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
243 (exp), atomic_read(&(exp)->exp_locks_count)); \
244 class_export_get(exp); \
247 #define class_export_lock_put(exp, lock) \
249 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
250 atomic_dec(&(exp)->exp_locks_count); \
251 __class_export_del_lock_ref(exp, lock); \
252 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
253 (exp), atomic_read(&(exp)->exp_locks_count)); \
254 class_export_put(exp); \
257 #define class_export_cb_get(exp) \
259 atomic_inc(&(exp)->exp_cb_count); \
260 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
261 (exp), atomic_read(&(exp)->exp_cb_count)); \
262 class_export_get(exp); \
265 #define class_export_cb_put(exp) \
267 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
268 atomic_dec(&(exp)->exp_cb_count); \
269 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
270 (exp), atomic_read(&(exp)->exp_cb_count)); \
271 class_export_put(exp); \
275 struct obd_export *class_export_get(struct obd_export *exp);
276 void class_export_put(struct obd_export *exp);
277 struct obd_export *class_new_export(struct obd_device *obddev,
278 struct obd_uuid *cluuid);
279 void class_unlink_export(struct obd_export *exp);
281 struct obd_import *class_import_get(struct obd_import *);
282 void class_import_put(struct obd_import *);
283 struct obd_import *class_new_import(struct obd_device *obd);
284 void class_destroy_import(struct obd_import *exp);
286 struct obd_type *class_search_type(const char *name);
287 struct obd_type *class_get_type(const char *name);
288 void class_put_type(struct obd_type *type);
289 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
290 struct obd_uuid *cluuid);
291 int class_disconnect(struct obd_export *exp);
292 void class_fail_export(struct obd_export *exp);
293 int class_connected_export(struct obd_export *exp);
294 void class_disconnect_exports(struct obd_device *obddev);
295 int class_manual_cleanup(struct obd_device *obd);
296 void class_disconnect_stale_exports(struct obd_device *,
297 int (*test_export)(struct obd_export *));
298 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
300 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
301 (obd->obd_force ? OBD_OPT_FORCE : 0) |
302 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
306 #ifdef HAVE_SERVER_SUPPORT
307 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
309 LASSERT(exp->exp_obd);
310 if (exp->exp_obd->u.obt.obt_magic != OBT_MAGIC)
312 return exp->exp_obd->u.obt.obt_lut;
315 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
317 LASSERT(obd->u.obt.obt_lut);
318 return &obd->u.obt.obt_lut->lut_lsd;
326 void obdo_from_la(struct obdo *dst, const struct lu_attr *la, u64 valid);
327 void la_from_obdo(struct lu_attr *la, const struct obdo *dst, u64 valid);
329 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, u64 valid);
330 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
332 #define OBT(dev) (dev)->obd_type
333 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
334 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
335 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
337 /* Ensure obd_setup: used for cleanup which must be called
338 while obd is stopping */
339 #define OBD_CHECK_DEV(obd) \
342 CERROR("NULL device\n"); \
347 /* ensure obd_setup and !obd_stopping */
348 #define OBD_CHECK_DEV_ACTIVE(obd) \
350 OBD_CHECK_DEV(obd); \
351 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
352 CERROR("Device %d not setup\n", \
359 #ifdef CONFIG_PROC_FS
360 #define OBD_COUNTER_OFFSET(op) \
361 ((offsetof(struct obd_ops, o_ ## op) - \
362 offsetof(struct obd_ops, o_iocontrol)) \
363 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
365 /* The '- 1' below is for o_owner. */
366 #define NUM_OBD_STATS \
367 (sizeof(struct obd_ops) / \
368 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
370 #define OBD_COUNTER_INCREMENT(obd, op) \
371 lprocfs_counter_incr((obd)->obd_stats, \
372 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
374 #define EXP_COUNTER_INCREMENT(exp, op) \
377 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
378 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
379 if ((exp)->exp_obd->obd_uses_nid_stats && \
380 (exp)->exp_nid_stats != NULL) \
381 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
385 #define _MD_COUNTER_OFFSET(m_op) \
386 ((offsetof(struct md_ops, m_op) - \
387 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
388 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
390 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
392 #define NUM_MD_STATS \
393 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
394 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
396 /* Note that we only increment md counters for ops whose offset is less
397 * than NUM_MD_STATS. This is explained in a comment in the definition
398 * of struct md_ops. */
399 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
401 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
402 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
403 (exp)->exp_obd->obd_md_cntr_base + \
404 MD_COUNTER_OFFSET(op)); \
408 #define OBD_COUNTER_OFFSET(op)
409 #define OBD_COUNTER_INCREMENT(obd, op)
410 #define EXP_COUNTER_INCREMENT(exp, op)
411 #define EXP_MD_COUNTER_INCREMENT(exp, op)
414 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
416 /* Always add in ldlm_stats */
417 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
418 ,LPROCFS_STATS_FLAG_NOPERCPU);
419 if (tmp->nid_ldlm_stats == NULL)
422 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
424 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
425 tmp->nid_ldlm_stats);
428 #define EXP_CHECK_MD_OP(exp, op) \
430 if ((exp) == NULL) { \
431 CERROR("obd_" #op ": NULL export\n"); \
434 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
435 CERROR("obd_" #op ": cleaned up obd\n"); \
436 RETURN(-EOPNOTSUPP); \
438 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
439 CERROR("obd_" #op ": dev %s/%d no operation\n", \
440 (exp)->exp_obd->obd_name, \
441 (exp)->exp_obd->obd_minor); \
442 RETURN(-EOPNOTSUPP); \
447 #define OBD_CHECK_DT_OP(obd, op, err) \
449 if (!OBT(obd) || !OBP((obd), op)) { \
451 CERROR("obd_" #op ": dev %d no operation\n", \
457 #define EXP_CHECK_DT_OP(exp, op) \
459 if ((exp) == NULL) { \
460 CERROR("obd_" #op ": NULL export\n"); \
463 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
464 CERROR("obd_" #op ": cleaned up obd\n"); \
465 RETURN(-EOPNOTSUPP); \
467 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
468 CERROR("obd_" #op ": dev %d no operation\n", \
469 (exp)->exp_obd->obd_minor); \
470 RETURN(-EOPNOTSUPP); \
474 #define CTXT_CHECK_OP(ctxt, op, err) \
476 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
478 CERROR("lop_" #op ": dev %d no operation\n", \
479 ctxt->loc_obd->obd_minor); \
484 static inline int class_devno_max(void)
486 return MAX_OBD_DEVICES;
489 static inline int obd_get_info(const struct lu_env *env, struct obd_export *exp,
490 __u32 keylen, void *key,
491 __u32 *vallen, void *val)
496 EXP_CHECK_DT_OP(exp, get_info);
497 EXP_COUNTER_INCREMENT(exp, get_info);
499 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val);
503 static inline int obd_set_info_async(const struct lu_env *env,
504 struct obd_export *exp,
505 __u32 keylen, void *key,
506 __u32 vallen, void *val,
507 struct ptlrpc_request_set *set)
512 EXP_CHECK_DT_OP(exp, set_info_async);
513 EXP_COUNTER_INCREMENT(exp, set_info_async);
515 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
521 * obd-lu integration.
523 * Functionality is being moved into new lu_device-based layering, but some
524 * pieces of configuration process are still based on obd devices.
526 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
527 * subsume ->o_setup() methods of obd devices they replace. The same for
528 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
529 * result, obd_setup() and obd_process_config() branch and call one XOR
532 * Yet neither lu_device_type_operations::ldto_device_fini() nor
533 * lu_device_type_operations::ldto_device_free() fully implement the
534 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
535 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
538 #define DECLARE_LU_VARS(ldt, d) \
539 struct lu_device_type *ldt; \
542 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
545 DECLARE_LU_VARS(ldt, d);
548 ldt = obd->obd_type->typ_lu;
550 struct lu_context session_ctx;
552 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
553 session_ctx.lc_thread = NULL;
554 lu_context_enter(&session_ctx);
556 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
558 env.le_ses = &session_ctx;
559 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
568 lu_context_exit(&session_ctx);
569 lu_context_fini(&session_ctx);
572 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
573 OBD_COUNTER_INCREMENT(obd, setup);
574 rc = OBP(obd, setup)(obd, cfg);
579 static inline int obd_precleanup(struct obd_device *obd,
580 enum obd_cleanup_stage cleanup_stage)
583 DECLARE_LU_VARS(ldt, d);
587 ldt = obd->obd_type->typ_lu;
589 if (ldt != NULL && d != NULL) {
590 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
593 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
595 ldt->ldt_ops->ldto_device_fini(&env, d);
600 OBD_CHECK_DT_OP(obd, precleanup, 0);
601 OBD_COUNTER_INCREMENT(obd, precleanup);
603 rc = OBP(obd, precleanup)(obd, cleanup_stage);
607 static inline int obd_cleanup(struct obd_device *obd)
610 DECLARE_LU_VARS(ldt, d);
615 ldt = obd->obd_type->typ_lu;
617 if (ldt != NULL && d != NULL) {
620 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
622 ldt->ldt_ops->ldto_device_free(&env, d);
624 obd->obd_lu_dev = NULL;
627 OBD_CHECK_DT_OP(obd, cleanup, 0);
628 OBD_COUNTER_INCREMENT(obd, cleanup);
630 rc = OBP(obd, cleanup)(obd);
634 static inline void obd_cleanup_client_import(struct obd_device *obd)
638 /* If we set up but never connected, the
639 client import will not have been cleaned. */
640 down_write(&obd->u.cli.cl_sem);
641 if (obd->u.cli.cl_import) {
642 struct obd_import *imp;
643 imp = obd->u.cli.cl_import;
644 CDEBUG(D_CONFIG, "%s: client import never connected\n",
646 ptlrpc_invalidate_import(imp);
647 if (imp->imp_rq_pool) {
648 ptlrpc_free_rq_pool(imp->imp_rq_pool);
649 imp->imp_rq_pool = NULL;
651 client_destroy_import(imp);
652 obd->u.cli.cl_import = NULL;
654 up_write(&obd->u.cli.cl_sem);
660 obd_process_config(struct obd_device *obd, int datalen, void *data)
663 DECLARE_LU_VARS(ldt, d);
668 obd->obd_process_conf = 1;
669 ldt = obd->obd_type->typ_lu;
671 if (ldt != NULL && d != NULL) {
674 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
676 rc = d->ld_ops->ldo_process_config(&env, d, data);
680 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
681 rc = OBP(obd, process_config)(obd, datalen, data);
683 OBD_COUNTER_INCREMENT(obd, process_config);
684 obd->obd_process_conf = 0;
689 /* Pack an in-memory MD struct for storage on disk.
690 * Returns +ve size of packed MD (0 for free), or -ve error.
692 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
693 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
694 * If @*disk_tgt == NULL, it will be allocated
696 static inline int obd_packmd(struct obd_export *exp,
697 struct lov_mds_md **disk_tgt,
698 struct lov_stripe_md *mem_src)
703 EXP_CHECK_DT_OP(exp, packmd);
704 EXP_COUNTER_INCREMENT(exp, packmd);
706 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
710 static inline int obd_free_diskmd(struct obd_export *exp,
711 struct lov_mds_md **disk_tgt)
716 * LU-2590, for caller's convenience, *disk_tgt could be host
717 * endianness, it needs swab to LE if necessary, while just
718 * lov_mds_md header needs it for figuring out how much memory
721 if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
722 (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
723 ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
724 lustre_swab_lov_mds_md(*disk_tgt);
725 return obd_packmd(exp, disk_tgt, NULL);
728 /* Unpack an MD struct from disk to in-memory format.
729 * Returns +ve size of unpacked MD (0 for free), or -ve error.
731 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
732 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
733 * If @*mem_tgt == NULL, it will be allocated
735 static inline int obd_unpackmd(struct obd_export *exp,
736 struct lov_stripe_md **mem_tgt,
737 struct lov_mds_md *disk_src,
743 EXP_CHECK_DT_OP(exp, unpackmd);
744 EXP_COUNTER_INCREMENT(exp, unpackmd);
746 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
750 static inline int obd_free_memmd(struct obd_export *exp,
751 struct lov_stripe_md **mem_tgt)
757 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
762 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
768 EXP_CHECK_DT_OP(exp, create);
769 EXP_COUNTER_INCREMENT(exp, create);
771 rc = OBP(exp->exp_obd, create)(env, exp, obdo);
775 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
781 EXP_CHECK_DT_OP(exp, destroy);
782 EXP_COUNTER_INCREMENT(exp, destroy);
784 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo);
788 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
794 EXP_CHECK_DT_OP(exp, getattr);
795 EXP_COUNTER_INCREMENT(exp, getattr);
796 rc = OBP(exp->exp_obd, getattr)(env, exp, oa);
801 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
807 EXP_CHECK_DT_OP(exp, setattr);
808 EXP_COUNTER_INCREMENT(exp, setattr);
809 rc = OBP(exp->exp_obd, setattr)(env, exp, oa);
814 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
817 struct obd_device *obd = imp->imp_obd;
821 OBD_CHECK_DEV_ACTIVE(obd);
822 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
823 OBD_COUNTER_INCREMENT(obd, add_conn);
825 rc = OBP(obd, add_conn)(imp, uuid, priority);
829 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
831 struct obd_device *obd = imp->imp_obd;
835 OBD_CHECK_DEV_ACTIVE(obd);
836 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
837 OBD_COUNTER_INCREMENT(obd, del_conn);
839 rc = OBP(obd, del_conn)(imp, uuid);
843 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
845 struct obd_uuid *uuid;
848 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
849 EXP_COUNTER_INCREMENT(exp, get_uuid);
851 uuid = OBP(exp->exp_obd, get_uuid)(exp);
855 /** Create a new /a exp on device /a obd for the uuid /a cluuid
856 * @param exp New export handle
857 * @param d Connect data, supported flags are set, flags also understood
858 * by obd are returned.
860 static inline int obd_connect(const struct lu_env *env,
861 struct obd_export **exp,struct obd_device *obd,
862 struct obd_uuid *cluuid,
863 struct obd_connect_data *data,
867 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
871 OBD_CHECK_DEV_ACTIVE(obd);
872 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
873 OBD_COUNTER_INCREMENT(obd, connect);
875 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
876 /* check that only subset is granted */
877 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
878 data->ocd_connect_flags));
882 static inline int obd_reconnect(const struct lu_env *env,
883 struct obd_export *exp,
884 struct obd_device *obd,
885 struct obd_uuid *cluuid,
886 struct obd_connect_data *d,
890 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
895 OBD_CHECK_DEV_ACTIVE(obd);
896 OBD_CHECK_DT_OP(obd, reconnect, 0);
897 OBD_COUNTER_INCREMENT(obd, reconnect);
899 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
900 /* check that only subset is granted */
901 LASSERT(ergo(d != NULL,
902 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
906 static inline int obd_disconnect(struct obd_export *exp)
911 EXP_CHECK_DT_OP(exp, disconnect);
912 EXP_COUNTER_INCREMENT(exp, disconnect);
914 rc = OBP(exp->exp_obd, disconnect)(exp);
918 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
919 enum lu_cli_type type)
924 OBD_CHECK_DT_OP(obd, fid_init, 0);
925 OBD_COUNTER_INCREMENT(obd, fid_init);
927 rc = OBP(obd, fid_init)(obd, exp, type);
931 static inline int obd_fid_fini(struct obd_device *obd)
936 OBD_CHECK_DT_OP(obd, fid_fini, 0);
937 OBD_COUNTER_INCREMENT(obd, fid_fini);
939 rc = OBP(obd, fid_fini)(obd);
943 static inline int obd_fid_alloc(const struct lu_env *env,
944 struct obd_export *exp,
946 struct md_op_data *op_data)
951 EXP_CHECK_DT_OP(exp, fid_alloc);
952 EXP_COUNTER_INCREMENT(exp, fid_alloc);
954 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
958 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
963 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
964 EXP_COUNTER_INCREMENT(exp, ping);
966 rc = OBP(exp->exp_obd, ping)(env, exp);
970 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
975 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
976 OBD_COUNTER_INCREMENT(obd, pool_new);
978 rc = OBP(obd, pool_new)(obd, poolname);
982 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
987 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
988 OBD_COUNTER_INCREMENT(obd, pool_del);
990 rc = OBP(obd, pool_del)(obd, poolname);
994 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
999 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1000 OBD_COUNTER_INCREMENT(obd, pool_add);
1002 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1006 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1011 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1012 OBD_COUNTER_INCREMENT(obd, pool_rem);
1014 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1018 static inline void obd_getref(struct obd_device *obd)
1021 if (OBT(obd) && OBP(obd, getref)) {
1022 OBD_COUNTER_INCREMENT(obd, getref);
1023 OBP(obd, getref)(obd);
1028 static inline void obd_putref(struct obd_device *obd)
1031 if (OBT(obd) && OBP(obd, putref)) {
1032 OBD_COUNTER_INCREMENT(obd, putref);
1033 OBP(obd, putref)(obd);
1038 static inline int obd_init_export(struct obd_export *exp)
1043 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1044 OBP((exp)->exp_obd, init_export))
1045 rc = OBP(exp->exp_obd, init_export)(exp);
1049 static inline int obd_destroy_export(struct obd_export *exp)
1052 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1053 OBP((exp)->exp_obd, destroy_export))
1054 OBP(exp->exp_obd, destroy_export)(exp);
1058 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1059 * If the cache is older than @max_age we will get a new value from the
1060 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1061 static inline int obd_statfs_async(struct obd_export *exp,
1062 struct obd_info *oinfo,
1064 struct ptlrpc_request_set *rqset)
1067 struct obd_device *obd;
1070 if (exp == NULL || exp->exp_obd == NULL)
1074 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1075 OBD_COUNTER_INCREMENT(obd, statfs);
1077 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1078 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1079 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1080 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1082 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1083 " objects "LPU64"/"LPU64"\n",
1084 obd->obd_name, &obd->obd_osfs,
1085 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1086 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1087 spin_lock(&obd->obd_osfs_lock);
1088 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1089 spin_unlock(&obd->obd_osfs_lock);
1090 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1091 if (oinfo->oi_cb_up)
1092 oinfo->oi_cb_up(oinfo, 0);
1097 static inline int obd_statfs_rqset(struct obd_export *exp,
1098 struct obd_statfs *osfs, __u64 max_age,
1101 struct ptlrpc_request_set *set = NULL;
1102 struct obd_info oinfo = {
1110 set = ptlrpc_prep_set();
1114 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1116 rc = ptlrpc_set_wait(set);
1118 ptlrpc_set_destroy(set);
1123 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1124 * If the cache is older than @max_age we will get a new value from the
1125 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1126 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1127 struct obd_statfs *osfs, __u64 max_age,
1131 struct obd_device *obd = exp->exp_obd;
1137 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1138 OBD_COUNTER_INCREMENT(obd, statfs);
1140 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1141 obd->obd_osfs_age, max_age);
1142 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1143 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1145 spin_lock(&obd->obd_osfs_lock);
1146 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1147 obd->obd_osfs_age = cfs_time_current_64();
1148 spin_unlock(&obd->obd_osfs_lock);
1151 CDEBUG(D_SUPER, "%s: use %p cache blocks "LPU64"/"LPU64
1152 " objects "LPU64"/"LPU64"\n",
1153 obd->obd_name, &obd->obd_osfs,
1154 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1155 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1156 spin_lock(&obd->obd_osfs_lock);
1157 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1158 spin_unlock(&obd->obd_osfs_lock);
1163 static inline int obd_preprw(const struct lu_env *env, int cmd,
1164 struct obd_export *exp, struct obdo *oa,
1165 int objcount, struct obd_ioobj *obj,
1166 struct niobuf_remote *remote, int *pages,
1167 struct niobuf_local *local)
1172 EXP_CHECK_DT_OP(exp, preprw);
1173 EXP_COUNTER_INCREMENT(exp, preprw);
1174 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1180 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1181 struct obd_export *exp, struct obdo *oa,
1182 int objcount, struct obd_ioobj *obj,
1183 struct niobuf_remote *rnb, int pages,
1184 struct niobuf_local *local, int rc)
1188 EXP_CHECK_DT_OP(exp, commitrw);
1189 EXP_COUNTER_INCREMENT(exp, commitrw);
1190 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1191 rnb, pages, local, rc);
1196 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1197 int len, void *karg, void __user *uarg)
1202 EXP_CHECK_DT_OP(exp, iocontrol);
1203 EXP_COUNTER_INCREMENT(exp, iocontrol);
1205 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1209 static inline void obd_import_event(struct obd_device *obd,
1210 struct obd_import *imp,
1211 enum obd_import_event event)
1215 CERROR("NULL device\n");
1219 if (obd->obd_set_up && OBP(obd, import_event)) {
1220 OBD_COUNTER_INCREMENT(obd, import_event);
1221 OBP(obd, import_event)(obd, imp, event);
1226 static inline int obd_notify(struct obd_device *obd,
1227 struct obd_device *watched,
1228 enum obd_notify_event ev,
1235 if (!obd->obd_set_up) {
1236 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1240 if (!OBP(obd, notify)) {
1241 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1245 OBD_COUNTER_INCREMENT(obd, notify);
1246 rc = OBP(obd, notify)(obd, watched, ev, data);
1250 static inline int obd_notify_observer(struct obd_device *observer,
1251 struct obd_device *observed,
1252 enum obd_notify_event ev,
1258 struct obd_notify_upcall *onu;
1260 if (observer->obd_observer)
1261 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1265 * Also, call non-obd listener, if any
1267 onu = &observer->obd_upcall;
1268 if (onu->onu_upcall != NULL)
1269 rc2 = onu->onu_upcall(observer, observed, ev,
1270 onu->onu_owner, NULL);
1274 return rc1 ? rc1 : rc2;
1277 static inline int obd_quotactl(struct obd_export *exp,
1278 struct obd_quotactl *oqctl)
1283 EXP_CHECK_DT_OP(exp, quotactl);
1284 EXP_COUNTER_INCREMENT(exp, quotactl);
1286 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1290 static inline int obd_health_check(const struct lu_env *env,
1291 struct obd_device *obd)
1293 /* returns: 0 on healthy
1294 * >0 on unhealthy + reason code/flag
1295 * however the only suppored reason == 1 right now
1296 * We'll need to define some better reasons
1297 * or flags in the future.
1303 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1304 if (obd == NULL || !OBT(obd)) {
1305 CERROR("cleaned up obd\n");
1306 RETURN(-EOPNOTSUPP);
1308 if (!obd->obd_set_up || obd->obd_stopping)
1310 if (!OBP(obd, health_check))
1313 rc = OBP(obd, health_check)(env, obd);
1317 static inline int obd_register_observer(struct obd_device *obd,
1318 struct obd_device *observer)
1322 down_write(&obd->obd_observer_link_sem);
1323 if (obd->obd_observer && observer) {
1324 up_write(&obd->obd_observer_link_sem);
1327 obd->obd_observer = observer;
1328 up_write(&obd->obd_observer_link_sem);
1332 /* metadata helpers */
1333 static inline int md_getstatus(struct obd_export *exp,
1334 struct lu_fid *fid, struct obd_capa **pc)
1339 EXP_CHECK_MD_OP(exp, getstatus);
1340 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1341 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1345 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1346 struct ptlrpc_request **request)
1350 EXP_CHECK_MD_OP(exp, getattr);
1351 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1352 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1356 static inline int md_null_inode(struct obd_export *exp,
1357 const struct lu_fid *fid)
1361 EXP_CHECK_MD_OP(exp, null_inode);
1362 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1363 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1367 static inline int md_find_cbdata(struct obd_export *exp,
1368 const struct lu_fid *fid,
1369 ldlm_iterator_t it, void *data)
1373 EXP_CHECK_MD_OP(exp, find_cbdata);
1374 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1375 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1379 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1380 struct md_open_data *mod,
1381 struct ptlrpc_request **request)
1385 EXP_CHECK_MD_OP(exp, close);
1386 EXP_MD_COUNTER_INCREMENT(exp, close);
1387 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1391 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1392 const void *data, size_t datalen, umode_t mode,
1393 uid_t uid, gid_t gid, cfs_cap_t cap_effective,
1394 __u64 rdev, struct ptlrpc_request **request)
1398 EXP_CHECK_MD_OP(exp, create);
1399 EXP_MD_COUNTER_INCREMENT(exp, create);
1400 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1401 uid, gid, cap_effective, rdev, request);
1405 static inline int md_enqueue(struct obd_export *exp,
1406 struct ldlm_enqueue_info *einfo,
1407 const union ldlm_policy_data *policy,
1408 struct lookup_intent *it,
1409 struct md_op_data *op_data,
1410 struct lustre_handle *lockh,
1411 __u64 extra_lock_flags)
1415 EXP_CHECK_MD_OP(exp, enqueue);
1416 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1417 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, it, op_data, lockh,
1422 static inline int md_getattr_name(struct obd_export *exp,
1423 struct md_op_data *op_data,
1424 struct ptlrpc_request **request)
1428 EXP_CHECK_MD_OP(exp, getattr_name);
1429 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1430 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1434 static inline int md_intent_lock(struct obd_export *exp,
1435 struct md_op_data *op_data,
1436 struct lookup_intent *it,
1437 struct ptlrpc_request **reqp,
1438 ldlm_blocking_callback cb_blocking,
1439 __u64 extra_lock_flags)
1443 EXP_CHECK_MD_OP(exp, intent_lock);
1444 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1445 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1450 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1451 struct ptlrpc_request **request)
1455 EXP_CHECK_MD_OP(exp, link);
1456 EXP_MD_COUNTER_INCREMENT(exp, link);
1457 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1461 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1462 const char *old, size_t oldlen, const char *new,
1463 size_t newlen, struct ptlrpc_request **request)
1467 EXP_CHECK_MD_OP(exp, rename);
1468 EXP_MD_COUNTER_INCREMENT(exp, rename);
1469 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1474 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1475 void *ea, size_t ealen,
1476 struct ptlrpc_request **request)
1480 EXP_CHECK_MD_OP(exp, setattr);
1481 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1482 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen, request);
1486 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1487 struct obd_capa *oc, struct ptlrpc_request **request)
1491 EXP_CHECK_MD_OP(exp, fsync);
1492 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1493 rc = MDP(exp->exp_obd, fsync)(exp, fid, oc, request);
1497 static inline int md_read_page(struct obd_export *exp,
1498 struct md_op_data *op_data,
1499 struct md_callback *cb_op,
1501 struct page **ppage)
1505 EXP_CHECK_MD_OP(exp, read_page);
1506 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1507 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1512 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1513 struct ptlrpc_request **request)
1517 EXP_CHECK_MD_OP(exp, unlink);
1518 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1519 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1523 static inline int md_get_lustre_md(struct obd_export *exp,
1524 struct ptlrpc_request *req,
1525 struct obd_export *dt_exp,
1526 struct obd_export *md_exp,
1527 struct lustre_md *md)
1530 EXP_CHECK_MD_OP(exp, get_lustre_md);
1531 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1532 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1535 static inline int md_free_lustre_md(struct obd_export *exp,
1536 struct lustre_md *md)
1539 EXP_CHECK_MD_OP(exp, free_lustre_md);
1540 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1541 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1544 static inline int md_merge_attr(struct obd_export *exp,
1545 const struct lmv_stripe_md *lsm,
1546 struct cl_attr *attr,
1547 ldlm_blocking_callback cb)
1550 EXP_CHECK_MD_OP(exp, merge_attr);
1551 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1552 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr, cb));
1555 static inline int md_setxattr(struct obd_export *exp,
1556 const struct lu_fid *fid, struct obd_capa *oc,
1557 u64 valid, const char *name,
1558 const char *input, int input_size,
1559 int output_size, int flags, __u32 suppgid,
1560 struct ptlrpc_request **request)
1563 EXP_CHECK_MD_OP(exp, setxattr);
1564 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1565 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1566 input_size, output_size, flags,
1570 static inline int md_getxattr(struct obd_export *exp,
1571 const struct lu_fid *fid, struct obd_capa *oc,
1572 u64 valid, const char *name,
1573 const char *input, int input_size,
1574 int output_size, int flags,
1575 struct ptlrpc_request **request)
1578 EXP_CHECK_MD_OP(exp, getxattr);
1579 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1580 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1581 input_size, output_size, flags,
1585 static inline int md_set_open_replay_data(struct obd_export *exp,
1586 struct obd_client_handle *och,
1587 struct lookup_intent *it)
1590 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1591 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1592 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1595 static inline int md_clear_open_replay_data(struct obd_export *exp,
1596 struct obd_client_handle *och)
1599 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1600 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1601 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1604 static inline int md_set_lock_data(struct obd_export *exp,
1605 __u64 *lockh, void *data, __u64 *bits)
1608 EXP_CHECK_MD_OP(exp, set_lock_data);
1609 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1610 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1613 static inline int md_cancel_unused(struct obd_export *exp,
1614 const struct lu_fid *fid,
1615 ldlm_policy_data_t *policy,
1617 ldlm_cancel_flags_t flags,
1623 EXP_CHECK_MD_OP(exp, cancel_unused);
1624 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1626 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1631 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
1632 const struct lu_fid *fid,
1634 ldlm_policy_data_t *policy,
1636 struct lustre_handle *lockh)
1639 EXP_CHECK_MD_OP(exp, lock_match);
1640 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1641 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1642 policy, mode, lockh));
1645 static inline int md_init_ea_size(struct obd_export *exp, __u32 ea_size,
1649 EXP_CHECK_MD_OP(exp, init_ea_size);
1650 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1651 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, ea_size, def_ea_size));
1654 static inline int md_get_remote_perm(struct obd_export *exp,
1655 const struct lu_fid *fid,
1656 struct obd_capa *oc, __u32 suppgid,
1657 struct ptlrpc_request **request)
1660 EXP_CHECK_MD_OP(exp, get_remote_perm);
1661 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1662 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1666 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1671 EXP_CHECK_MD_OP(exp, renew_capa);
1672 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1673 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1677 static inline int md_unpack_capa(struct obd_export *exp,
1678 struct ptlrpc_request *req,
1679 const struct req_msg_field *field,
1680 struct obd_capa **oc)
1684 EXP_CHECK_MD_OP(exp, unpack_capa);
1685 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
1686 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
1690 static inline int md_intent_getattr_async(struct obd_export *exp,
1691 struct md_enqueue_info *minfo,
1692 struct ldlm_enqueue_info *einfo)
1696 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1697 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1698 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
1702 static inline int md_revalidate_lock(struct obd_export *exp,
1703 struct lookup_intent *it,
1704 struct lu_fid *fid, __u64 *bits)
1708 EXP_CHECK_MD_OP(exp, revalidate_lock);
1709 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1710 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1714 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1715 const struct lmv_stripe_md *lsm,
1716 const char *name, int namelen,
1721 EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1722 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1723 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1727 /* OBD Metadata Support */
1729 extern int obd_init_caches(void);
1730 extern void obd_cleanup_caches(void);
1732 /* support routines */
1733 extern struct kmem_cache *obdo_cachep;
1735 #define OBDO_ALLOC(ptr) \
1737 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1740 #define OBDO_FREE(ptr) \
1742 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1746 typedef int (*register_lwp_cb)(void *data);
1748 struct lwp_register_item {
1749 struct obd_export **lri_exp;
1750 register_lwp_cb lri_cb_func;
1752 struct list_head lri_list;
1753 char lri_name[MTI_NAME_MAXLEN];
1756 /* I'm as embarrassed about this as you are.
1758 * <shaver> // XXX do not look into _superhack with remaining eye
1759 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1760 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1763 #ifdef HAVE_SERVER_SUPPORT
1764 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1765 register_lwp_cb cb_func, void *cb_data);
1766 void lustre_deregister_lwp_item(struct obd_export **exp);
1767 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1768 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1769 #endif /* HAVE_SERVER_SUPPORT */
1770 int lustre_register_fs(void);
1771 int lustre_unregister_fs(void);
1772 int lustre_check_exclusion(struct super_block *sb, char *svname);
1775 extern void obd_sysctl_init (void);
1776 extern void obd_sysctl_clean (void);
1779 typedef __u8 class_uuid_t[16];
1780 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1783 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1784 int class_add_uuid(const char *uuid, __u64 nid);
1785 int class_del_uuid (const char *uuid);
1786 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1787 void class_init_uuidlist(void);
1788 void class_exit_uuidlist(void);
1791 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1795 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1796 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1798 /* root squash info */
1799 struct rw_semaphore;
1800 struct root_squash_info {
1803 struct list_head rsi_nosquash_nids;
1804 struct rw_semaphore rsi_sem;
1807 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1809 /* linux-module.c */
1810 extern struct miscdevice obd_psdev;
1811 int class_procfs_init(void);
1812 int class_procfs_clean(void);
1814 #endif /* __LINUX_OBD_CLASS_H */