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, 2013, 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 #include <linux/obd_class.h>
50 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
51 * and resends for avoid deadlocks */
52 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
54 #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd
55 * instead of a specific set. This
56 * means that we cannot rely on the set
57 * interpret routine to be called.
58 * lov_statfs_fini() must thus be called
59 * by the request interpret routine */
60 #define OBD_STATFS_FOR_MDT0 0x0008 /* The statfs is only for retrieving
61 * information from MDT0. */
63 /* OBD Device Declarations */
64 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
65 extern struct list_head obd_types;
66 extern spinlock_t obd_types_lock;
67 extern rwlock_t obd_dev_lock;
69 /* OBD Operations Declarations */
70 extern struct obd_device *class_conn2obd(struct lustre_handle *);
71 extern struct obd_device *class_exp2obd(struct obd_export *);
72 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
73 extern int lustre_get_jobid(char *jobid);
75 struct lu_device_type;
78 struct obd_export *class_conn2export(struct lustre_handle *);
79 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
80 struct lprocfs_seq_vars *module_vars,
81 const char *nm, struct lu_device_type *ldt);
82 int class_unregister_type(const char *nm);
84 struct obd_device *class_newdev(const char *type_name, const char *name);
85 void class_release_dev(struct obd_device *obd);
87 int class_name2dev(const char *name);
88 struct obd_device *class_name2obd(const char *name);
89 int class_uuid2dev(struct obd_uuid *uuid);
90 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
91 void class_obd_list(void);
92 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
93 const char * typ_name,
94 struct obd_uuid *grp_uuid);
95 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
97 struct obd_device * class_num2obd(int num);
98 int get_devices_count(void);
100 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
102 char *obd_export_nid2str(struct obd_export *exp);
104 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
105 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
106 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
108 int obd_zombie_impexp_init(void);
109 void obd_zombie_impexp_stop(void);
110 void obd_zombie_impexp_cull(void);
111 void obd_zombie_barrier(void);
112 void obd_exports_barrier(struct obd_device *obd);
113 int kuc_len(int payload_len);
114 struct kuc_hdr * kuc_ptr(void *p);
115 int kuc_ispayload(void *p);
116 void *kuc_alloc(int payload_len, int transport, int type);
117 void kuc_free(void *p, int payload_len);
118 int obd_get_request_slot(struct client_obd *cli);
119 void obd_put_request_slot(struct client_obd *cli);
120 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
121 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 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_seq_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 return exp->exp_obd->u.obt.obt_lut;
313 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
315 LASSERT(obd->u.obt.obt_lut);
316 return &obd->u.obt.obt_lut->lut_lsd;
320 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, obd_flag valid);
321 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
322 void md_from_obdo(struct md_op_data *op_data, const struct obdo *oa,
325 #define OBT(dev) (dev)->obd_type
326 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
327 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
328 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
330 /* Ensure obd_setup: used for cleanup which must be called
331 while obd is stopping */
332 #define OBD_CHECK_DEV(obd) \
335 CERROR("NULL device\n"); \
340 /* ensure obd_setup and !obd_stopping */
341 #define OBD_CHECK_DEV_ACTIVE(obd) \
343 OBD_CHECK_DEV(obd); \
344 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
345 CERROR("Device %d not setup\n", \
353 #define OBD_COUNTER_OFFSET(op) \
354 ((offsetof(struct obd_ops, o_ ## op) - \
355 offsetof(struct obd_ops, o_iocontrol)) \
356 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
358 /* The '- 1' below is for o_owner. */
359 #define NUM_OBD_STATS \
360 (sizeof(struct obd_ops) / \
361 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
363 #define OBD_COUNTER_INCREMENT(obd, op) \
364 lprocfs_counter_incr((obd)->obd_stats, \
365 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
367 #define EXP_COUNTER_INCREMENT(exp, op) \
370 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
371 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
372 if ((exp)->exp_obd->obd_uses_nid_stats && \
373 (exp)->exp_nid_stats != NULL) \
374 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
378 #define _MD_COUNTER_OFFSET(m_op) \
379 ((offsetof(struct md_ops, m_op) - \
380 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
381 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
383 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
385 #define NUM_MD_STATS \
386 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
387 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
389 /* Note that we only increment md counters for ops whose offset is less
390 * than NUM_MD_STATS. This is explained in a comment in the definition
391 * of struct md_ops. */
392 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
394 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
395 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
396 (exp)->exp_obd->obd_md_cntr_base + \
397 MD_COUNTER_OFFSET(op)); \
401 #define OBD_COUNTER_OFFSET(op)
402 #define OBD_COUNTER_INCREMENT(obd, op)
403 #define EXP_COUNTER_INCREMENT(exp, op)
404 #define EXP_MD_COUNTER_INCREMENT(exp, op)
407 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
409 /* Always add in ldlm_stats */
410 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
411 ,LPROCFS_STATS_FLAG_NOPERCPU);
412 if (tmp->nid_ldlm_stats == NULL)
415 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
417 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
418 tmp->nid_ldlm_stats);
421 #define EXP_CHECK_MD_OP(exp, op) \
423 if ((exp) == NULL) { \
424 CERROR("obd_" #op ": NULL export\n"); \
427 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
428 CERROR("obd_" #op ": cleaned up obd\n"); \
429 RETURN(-EOPNOTSUPP); \
431 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
432 CERROR("obd_" #op ": dev %s/%d no operation\n", \
433 (exp)->exp_obd->obd_name, \
434 (exp)->exp_obd->obd_minor); \
435 RETURN(-EOPNOTSUPP); \
440 #define OBD_CHECK_DT_OP(obd, op, err) \
442 if (!OBT(obd) || !OBP((obd), op)) { \
444 CERROR("obd_" #op ": dev %d no operation\n", \
450 #define EXP_CHECK_DT_OP(exp, op) \
452 if ((exp) == NULL) { \
453 CERROR("obd_" #op ": NULL export\n"); \
456 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
457 CERROR("obd_" #op ": cleaned up obd\n"); \
458 RETURN(-EOPNOTSUPP); \
460 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
461 CERROR("obd_" #op ": dev %d no operation\n", \
462 (exp)->exp_obd->obd_minor); \
463 RETURN(-EOPNOTSUPP); \
467 #define CTXT_CHECK_OP(ctxt, op, err) \
469 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
471 CERROR("lop_" #op ": dev %d no operation\n", \
472 ctxt->loc_obd->obd_minor); \
477 static inline int class_devno_max(void)
479 return MAX_OBD_DEVICES;
482 static inline int obd_get_info(const struct lu_env *env,
483 struct obd_export *exp, __u32 keylen,
484 void *key, __u32 *vallen, void *val,
485 struct lov_stripe_md *lsm)
490 EXP_CHECK_DT_OP(exp, get_info);
491 EXP_COUNTER_INCREMENT(exp, get_info);
493 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val,
498 static inline int obd_set_info_async(const struct lu_env *env,
499 struct obd_export *exp, obd_count keylen,
500 void *key, obd_count vallen, void *val,
501 struct ptlrpc_request_set *set)
506 EXP_CHECK_DT_OP(exp, set_info_async);
507 EXP_COUNTER_INCREMENT(exp, set_info_async);
509 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
515 * obd-lu integration.
517 * Functionality is being moved into new lu_device-based layering, but some
518 * pieces of configuration process are still based on obd devices.
520 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
521 * subsume ->o_setup() methods of obd devices they replace. The same for
522 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
523 * result, obd_setup() and obd_process_config() branch and call one XOR
526 * Yet neither lu_device_type_operations::ldto_device_fini() nor
527 * lu_device_type_operations::ldto_device_free() fully implement the
528 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
529 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
532 #define DECLARE_LU_VARS(ldt, d) \
533 struct lu_device_type *ldt; \
536 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
539 DECLARE_LU_VARS(ldt, d);
542 ldt = obd->obd_type->typ_lu;
544 struct lu_context session_ctx;
546 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
547 session_ctx.lc_thread = NULL;
548 lu_context_enter(&session_ctx);
550 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
552 env.le_ses = &session_ctx;
553 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
562 lu_context_exit(&session_ctx);
563 lu_context_fini(&session_ctx);
566 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
567 OBD_COUNTER_INCREMENT(obd, setup);
568 rc = OBP(obd, setup)(obd, cfg);
573 static inline int obd_precleanup(struct obd_device *obd,
574 enum obd_cleanup_stage cleanup_stage)
577 DECLARE_LU_VARS(ldt, d);
581 ldt = obd->obd_type->typ_lu;
583 if (ldt != NULL && d != NULL) {
584 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
587 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
589 ldt->ldt_ops->ldto_device_fini(&env, d);
594 OBD_CHECK_DT_OP(obd, precleanup, 0);
595 OBD_COUNTER_INCREMENT(obd, precleanup);
597 rc = OBP(obd, precleanup)(obd, cleanup_stage);
601 static inline int obd_cleanup(struct obd_device *obd)
604 DECLARE_LU_VARS(ldt, d);
609 ldt = obd->obd_type->typ_lu;
611 if (ldt != NULL && d != NULL) {
614 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
616 ldt->ldt_ops->ldto_device_free(&env, d);
618 obd->obd_lu_dev = NULL;
621 OBD_CHECK_DT_OP(obd, cleanup, 0);
622 OBD_COUNTER_INCREMENT(obd, cleanup);
624 rc = OBP(obd, cleanup)(obd);
628 static inline void obd_cleanup_client_import(struct obd_device *obd)
632 /* If we set up but never connected, the
633 client import will not have been cleaned. */
634 down_write(&obd->u.cli.cl_sem);
635 if (obd->u.cli.cl_import) {
636 struct obd_import *imp;
637 imp = obd->u.cli.cl_import;
638 CDEBUG(D_CONFIG, "%s: client import never connected\n",
640 ptlrpc_invalidate_import(imp);
641 if (imp->imp_rq_pool) {
642 ptlrpc_free_rq_pool(imp->imp_rq_pool);
643 imp->imp_rq_pool = NULL;
645 client_destroy_import(imp);
646 obd->u.cli.cl_import = NULL;
648 up_write(&obd->u.cli.cl_sem);
654 obd_process_config(struct obd_device *obd, int datalen, void *data)
657 DECLARE_LU_VARS(ldt, d);
662 obd->obd_process_conf = 1;
663 ldt = obd->obd_type->typ_lu;
665 if (ldt != NULL && d != NULL) {
668 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
670 rc = d->ld_ops->ldo_process_config(&env, d, data);
674 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
675 rc = OBP(obd, process_config)(obd, datalen, data);
677 OBD_COUNTER_INCREMENT(obd, process_config);
678 obd->obd_process_conf = 0;
683 /* Pack an in-memory MD struct for storage on disk.
684 * Returns +ve size of packed MD (0 for free), or -ve error.
686 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
687 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
688 * If @*disk_tgt == NULL, it will be allocated
690 static inline int obd_packmd(struct obd_export *exp,
691 struct lov_mds_md **disk_tgt,
692 struct lov_stripe_md *mem_src)
697 EXP_CHECK_DT_OP(exp, packmd);
698 EXP_COUNTER_INCREMENT(exp, packmd);
700 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
704 static inline int obd_size_diskmd(struct obd_export *exp,
705 struct lov_stripe_md *mem_src)
707 return obd_packmd(exp, NULL, 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 /* helper functions */
751 static inline int obd_alloc_memmd(struct obd_export *exp,
752 struct lov_stripe_md **mem_tgt)
755 LASSERT(*mem_tgt == NULL);
756 return obd_unpackmd(exp, mem_tgt, NULL, 0);
759 static inline int obd_free_memmd(struct obd_export *exp,
760 struct lov_stripe_md **mem_tgt)
766 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
771 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
772 struct obdo *obdo, struct lov_stripe_md **ea,
773 struct obd_trans_info *oti)
778 EXP_CHECK_DT_OP(exp, create);
779 EXP_COUNTER_INCREMENT(exp, create);
781 rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti);
785 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
786 struct obdo *obdo, struct lov_stripe_md *ea,
787 struct obd_trans_info *oti,
788 struct obd_export *md_exp, void *capa)
793 EXP_CHECK_DT_OP(exp, destroy);
794 EXP_COUNTER_INCREMENT(exp, destroy);
796 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp, capa);
800 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
801 struct obd_info *oinfo)
806 EXP_CHECK_DT_OP(exp, getattr);
807 EXP_COUNTER_INCREMENT(exp, getattr);
809 rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo);
813 static inline int obd_getattr_async(struct obd_export *exp,
814 struct obd_info *oinfo,
815 struct ptlrpc_request_set *set)
820 EXP_CHECK_DT_OP(exp, getattr_async);
821 EXP_COUNTER_INCREMENT(exp, getattr_async);
823 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
827 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
828 struct obd_info *oinfo,
829 struct obd_trans_info *oti)
834 EXP_CHECK_DT_OP(exp, setattr);
835 EXP_COUNTER_INCREMENT(exp, setattr);
837 rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
841 /* This performs all the requests set init/wait/destroy actions. */
842 static inline int obd_setattr_rqset(struct obd_export *exp,
843 struct obd_info *oinfo,
844 struct obd_trans_info *oti)
846 struct ptlrpc_request_set *set = NULL;
850 EXP_CHECK_DT_OP(exp, setattr_async);
851 EXP_COUNTER_INCREMENT(exp, setattr_async);
853 set = ptlrpc_prep_set();
857 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
859 rc = ptlrpc_set_wait(set);
860 ptlrpc_set_destroy(set);
864 /* This adds all the requests into @set if @set != NULL, otherwise
865 all requests are sent asynchronously without waiting for response. */
866 static inline int obd_setattr_async(struct obd_export *exp,
867 struct obd_info *oinfo,
868 struct obd_trans_info *oti,
869 struct ptlrpc_request_set *set)
874 EXP_CHECK_DT_OP(exp, setattr_async);
875 EXP_COUNTER_INCREMENT(exp, setattr_async);
877 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
881 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
884 struct obd_device *obd = imp->imp_obd;
888 OBD_CHECK_DEV_ACTIVE(obd);
889 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
890 OBD_COUNTER_INCREMENT(obd, add_conn);
892 rc = OBP(obd, add_conn)(imp, uuid, priority);
896 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
898 struct obd_device *obd = imp->imp_obd;
902 OBD_CHECK_DEV_ACTIVE(obd);
903 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
904 OBD_COUNTER_INCREMENT(obd, del_conn);
906 rc = OBP(obd, del_conn)(imp, uuid);
910 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
912 struct obd_uuid *uuid;
915 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
916 EXP_COUNTER_INCREMENT(exp, get_uuid);
918 uuid = OBP(exp->exp_obd, get_uuid)(exp);
922 /** Create a new /a exp on device /a obd for the uuid /a cluuid
923 * @param exp New export handle
924 * @param d Connect data, supported flags are set, flags also understood
925 * by obd are returned.
927 static inline int obd_connect(const struct lu_env *env,
928 struct obd_export **exp,struct obd_device *obd,
929 struct obd_uuid *cluuid,
930 struct obd_connect_data *data,
934 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
938 OBD_CHECK_DEV_ACTIVE(obd);
939 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
940 OBD_COUNTER_INCREMENT(obd, connect);
942 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
943 /* check that only subset is granted */
944 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
945 data->ocd_connect_flags));
949 static inline int obd_reconnect(const struct lu_env *env,
950 struct obd_export *exp,
951 struct obd_device *obd,
952 struct obd_uuid *cluuid,
953 struct obd_connect_data *d,
957 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
962 OBD_CHECK_DEV_ACTIVE(obd);
963 OBD_CHECK_DT_OP(obd, reconnect, 0);
964 OBD_COUNTER_INCREMENT(obd, reconnect);
966 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
967 /* check that only subset is granted */
968 LASSERT(ergo(d != NULL,
969 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
973 static inline int obd_disconnect(struct obd_export *exp)
978 EXP_CHECK_DT_OP(exp, disconnect);
979 EXP_COUNTER_INCREMENT(exp, disconnect);
981 rc = OBP(exp->exp_obd, disconnect)(exp);
985 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
986 enum lu_cli_type type)
991 OBD_CHECK_DT_OP(obd, fid_init, 0);
992 OBD_COUNTER_INCREMENT(obd, fid_init);
994 rc = OBP(obd, fid_init)(obd, exp, type);
998 static inline int obd_fid_fini(struct obd_device *obd)
1003 OBD_CHECK_DT_OP(obd, fid_fini, 0);
1004 OBD_COUNTER_INCREMENT(obd, fid_fini);
1006 rc = OBP(obd, fid_fini)(obd);
1010 static inline int obd_fid_alloc(const struct lu_env *env,
1011 struct obd_export *exp,
1013 struct md_op_data *op_data)
1018 EXP_CHECK_DT_OP(exp, fid_alloc);
1019 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1021 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
1025 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
1030 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1031 EXP_COUNTER_INCREMENT(exp, ping);
1033 rc = OBP(exp->exp_obd, ping)(env, exp);
1037 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1042 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1043 OBD_COUNTER_INCREMENT(obd, pool_new);
1045 rc = OBP(obd, pool_new)(obd, poolname);
1049 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1054 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1055 OBD_COUNTER_INCREMENT(obd, pool_del);
1057 rc = OBP(obd, pool_del)(obd, poolname);
1061 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1066 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1067 OBD_COUNTER_INCREMENT(obd, pool_add);
1069 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1073 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1078 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1079 OBD_COUNTER_INCREMENT(obd, pool_rem);
1081 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1085 static inline void obd_getref(struct obd_device *obd)
1088 if (OBT(obd) && OBP(obd, getref)) {
1089 OBD_COUNTER_INCREMENT(obd, getref);
1090 OBP(obd, getref)(obd);
1095 static inline void obd_putref(struct obd_device *obd)
1098 if (OBT(obd) && OBP(obd, putref)) {
1099 OBD_COUNTER_INCREMENT(obd, putref);
1100 OBP(obd, putref)(obd);
1105 static inline int obd_init_export(struct obd_export *exp)
1110 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1111 OBP((exp)->exp_obd, init_export))
1112 rc = OBP(exp->exp_obd, init_export)(exp);
1116 static inline int obd_destroy_export(struct obd_export *exp)
1119 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1120 OBP((exp)->exp_obd, destroy_export))
1121 OBP(exp->exp_obd, destroy_export)(exp);
1125 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1126 * If the cache is older than @max_age we will get a new value from the
1127 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1128 static inline int obd_statfs_async(struct obd_export *exp,
1129 struct obd_info *oinfo,
1131 struct ptlrpc_request_set *rqset)
1134 struct obd_device *obd;
1137 if (exp == NULL || exp->exp_obd == NULL)
1141 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1142 OBD_COUNTER_INCREMENT(obd, statfs);
1144 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1145 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1146 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1147 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1149 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1150 " objects "LPU64"/"LPU64"\n",
1151 obd->obd_name, &obd->obd_osfs,
1152 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1153 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1154 spin_lock(&obd->obd_osfs_lock);
1155 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1156 spin_unlock(&obd->obd_osfs_lock);
1157 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1158 if (oinfo->oi_cb_up)
1159 oinfo->oi_cb_up(oinfo, 0);
1164 static inline int obd_statfs_rqset(struct obd_export *exp,
1165 struct obd_statfs *osfs, __u64 max_age,
1168 struct ptlrpc_request_set *set = NULL;
1169 struct obd_info oinfo = { { { 0 } } };
1173 set = ptlrpc_prep_set();
1177 oinfo.oi_osfs = osfs;
1178 oinfo.oi_flags = flags;
1179 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1181 rc = ptlrpc_set_wait(set);
1182 ptlrpc_set_destroy(set);
1186 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1187 * If the cache is older than @max_age we will get a new value from the
1188 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1189 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1190 struct obd_statfs *osfs, __u64 max_age,
1194 struct obd_device *obd = exp->exp_obd;
1200 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1201 OBD_COUNTER_INCREMENT(obd, statfs);
1203 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1204 obd->obd_osfs_age, max_age);
1205 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1206 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1208 spin_lock(&obd->obd_osfs_lock);
1209 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1210 obd->obd_osfs_age = cfs_time_current_64();
1211 spin_unlock(&obd->obd_osfs_lock);
1214 CDEBUG(D_SUPER, "%s: use %p cache blocks "LPU64"/"LPU64
1215 " objects "LPU64"/"LPU64"\n",
1216 obd->obd_name, &obd->obd_osfs,
1217 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1218 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1219 spin_lock(&obd->obd_osfs_lock);
1220 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1221 spin_unlock(&obd->obd_osfs_lock);
1226 static inline int obd_preprw(const struct lu_env *env, int cmd,
1227 struct obd_export *exp, struct obdo *oa,
1228 int objcount, struct obd_ioobj *obj,
1229 struct niobuf_remote *remote, int *pages,
1230 struct niobuf_local *local,
1231 struct obd_trans_info *oti,
1232 struct lustre_capa *capa)
1237 EXP_CHECK_DT_OP(exp, preprw);
1238 EXP_COUNTER_INCREMENT(exp, preprw);
1240 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1241 pages, local, oti, capa);
1245 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1246 struct obd_export *exp, struct obdo *oa,
1247 int objcount, struct obd_ioobj *obj,
1248 struct niobuf_remote *rnb, int pages,
1249 struct niobuf_local *local,
1250 struct obd_trans_info *oti, int rc)
1254 EXP_CHECK_DT_OP(exp, commitrw);
1255 EXP_COUNTER_INCREMENT(exp, commitrw);
1257 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1258 rnb, pages, local, oti, rc);
1262 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1263 int len, void *karg, void *uarg)
1268 EXP_CHECK_DT_OP(exp, iocontrol);
1269 EXP_COUNTER_INCREMENT(exp, iocontrol);
1271 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1275 static inline int obd_change_cbdata(struct obd_export *exp,
1276 struct lov_stripe_md *lsm,
1277 ldlm_iterator_t it, void *data)
1282 EXP_CHECK_DT_OP(exp, change_cbdata);
1283 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1285 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1289 static inline int obd_find_cbdata(struct obd_export *exp,
1290 struct lov_stripe_md *lsm,
1291 ldlm_iterator_t it, void *data)
1296 EXP_CHECK_DT_OP(exp, find_cbdata);
1297 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1299 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1303 static inline void obd_import_event(struct obd_device *obd,
1304 struct obd_import *imp,
1305 enum obd_import_event event)
1309 CERROR("NULL device\n");
1313 if (obd->obd_set_up && OBP(obd, import_event)) {
1314 OBD_COUNTER_INCREMENT(obd, import_event);
1315 OBP(obd, import_event)(obd, imp, event);
1320 static inline int obd_notify(struct obd_device *obd,
1321 struct obd_device *watched,
1322 enum obd_notify_event ev,
1329 if (!obd->obd_set_up) {
1330 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1334 if (!OBP(obd, notify)) {
1335 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1339 OBD_COUNTER_INCREMENT(obd, notify);
1340 rc = OBP(obd, notify)(obd, watched, ev, data);
1344 static inline int obd_notify_observer(struct obd_device *observer,
1345 struct obd_device *observed,
1346 enum obd_notify_event ev,
1352 struct obd_notify_upcall *onu;
1354 if (observer->obd_observer)
1355 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1359 * Also, call non-obd listener, if any
1361 onu = &observer->obd_upcall;
1362 if (onu->onu_upcall != NULL)
1363 rc2 = onu->onu_upcall(observer, observed, ev,
1364 onu->onu_owner, NULL);
1368 return rc1 ? rc1 : rc2;
1371 static inline int obd_quotacheck(struct obd_export *exp,
1372 struct obd_quotactl *oqctl)
1377 EXP_CHECK_DT_OP(exp, quotacheck);
1378 EXP_COUNTER_INCREMENT(exp, quotacheck);
1380 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1384 static inline int obd_quotactl(struct obd_export *exp,
1385 struct obd_quotactl *oqctl)
1390 EXP_CHECK_DT_OP(exp, quotactl);
1391 EXP_COUNTER_INCREMENT(exp, quotactl);
1393 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1397 static inline int obd_health_check(const struct lu_env *env,
1398 struct obd_device *obd)
1400 /* returns: 0 on healthy
1401 * >0 on unhealthy + reason code/flag
1402 * however the only suppored reason == 1 right now
1403 * We'll need to define some better reasons
1404 * or flags in the future.
1410 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1411 if (obd == NULL || !OBT(obd)) {
1412 CERROR("cleaned up obd\n");
1413 RETURN(-EOPNOTSUPP);
1415 if (!obd->obd_set_up || obd->obd_stopping)
1417 if (!OBP(obd, health_check))
1420 rc = OBP(obd, health_check)(env, obd);
1424 static inline int obd_register_observer(struct obd_device *obd,
1425 struct obd_device *observer)
1429 down_write(&obd->obd_observer_link_sem);
1430 if (obd->obd_observer && observer) {
1431 up_write(&obd->obd_observer_link_sem);
1434 obd->obd_observer = observer;
1435 up_write(&obd->obd_observer_link_sem);
1439 /* metadata helpers */
1440 static inline int md_getstatus(struct obd_export *exp,
1441 struct lu_fid *fid, struct obd_capa **pc)
1446 EXP_CHECK_MD_OP(exp, getstatus);
1447 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1448 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1452 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1453 struct ptlrpc_request **request)
1457 EXP_CHECK_MD_OP(exp, getattr);
1458 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1459 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1463 static inline int md_null_inode(struct obd_export *exp,
1464 const struct lu_fid *fid)
1468 EXP_CHECK_MD_OP(exp, null_inode);
1469 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1470 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1474 static inline int md_find_cbdata(struct obd_export *exp,
1475 const struct lu_fid *fid,
1476 ldlm_iterator_t it, void *data)
1480 EXP_CHECK_MD_OP(exp, find_cbdata);
1481 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1482 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1486 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1487 struct md_open_data *mod,
1488 struct ptlrpc_request **request)
1492 EXP_CHECK_MD_OP(exp, close);
1493 EXP_MD_COUNTER_INCREMENT(exp, close);
1494 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1498 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1499 const void *data, int datalen, int mode, __u32 uid,
1500 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1501 struct ptlrpc_request **request)
1505 EXP_CHECK_MD_OP(exp, create);
1506 EXP_MD_COUNTER_INCREMENT(exp, create);
1507 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1508 uid, gid, cap_effective, rdev, request);
1512 static inline int md_done_writing(struct obd_export *exp,
1513 struct md_op_data *op_data,
1514 struct md_open_data *mod)
1518 EXP_CHECK_MD_OP(exp, done_writing);
1519 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1520 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1524 static inline int md_enqueue(struct obd_export *exp,
1525 struct ldlm_enqueue_info *einfo,
1526 const union ldlm_policy_data *policy,
1527 struct lookup_intent *it,
1528 struct md_op_data *op_data,
1529 struct lustre_handle *lockh,
1530 __u64 extra_lock_flags)
1534 EXP_CHECK_MD_OP(exp, enqueue);
1535 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1536 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, it, op_data, lockh,
1541 static inline int md_getattr_name(struct obd_export *exp,
1542 struct md_op_data *op_data,
1543 struct ptlrpc_request **request)
1547 EXP_CHECK_MD_OP(exp, getattr_name);
1548 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1549 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1553 static inline int md_intent_lock(struct obd_export *exp,
1554 struct md_op_data *op_data,
1555 struct lookup_intent *it,
1556 struct ptlrpc_request **reqp,
1557 ldlm_blocking_callback cb_blocking,
1558 __u64 extra_lock_flags)
1562 EXP_CHECK_MD_OP(exp, intent_lock);
1563 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1564 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1569 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1570 struct ptlrpc_request **request)
1574 EXP_CHECK_MD_OP(exp, link);
1575 EXP_MD_COUNTER_INCREMENT(exp, link);
1576 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1580 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1581 const char *old, int oldlen, const char *new,
1582 int newlen, struct ptlrpc_request **request)
1586 EXP_CHECK_MD_OP(exp, rename);
1587 EXP_MD_COUNTER_INCREMENT(exp, rename);
1588 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1593 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1594 void *ea, int ealen, void *ea2, int ea2len,
1595 struct ptlrpc_request **request,
1596 struct md_open_data **mod)
1600 EXP_CHECK_MD_OP(exp, setattr);
1601 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1602 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1603 ea2, ea2len, request, mod);
1607 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1608 struct obd_capa *oc, struct ptlrpc_request **request)
1612 EXP_CHECK_MD_OP(exp, fsync);
1613 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1614 rc = MDP(exp->exp_obd, fsync)(exp, fid, oc, request);
1618 static inline int md_read_page(struct obd_export *exp,
1619 struct md_op_data *op_data,
1620 struct md_callback *cb_op,
1622 struct page **ppage)
1626 EXP_CHECK_MD_OP(exp, read_page);
1627 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1628 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1633 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1634 struct ptlrpc_request **request)
1638 EXP_CHECK_MD_OP(exp, unlink);
1639 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1640 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1644 static inline int md_get_lustre_md(struct obd_export *exp,
1645 struct ptlrpc_request *req,
1646 struct obd_export *dt_exp,
1647 struct obd_export *md_exp,
1648 struct lustre_md *md)
1651 EXP_CHECK_MD_OP(exp, get_lustre_md);
1652 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1653 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1656 static inline int md_free_lustre_md(struct obd_export *exp,
1657 struct lustre_md *md)
1660 EXP_CHECK_MD_OP(exp, free_lustre_md);
1661 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1662 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1665 static inline int md_update_lsm_md(struct obd_export *exp,
1666 struct lmv_stripe_md *lsm,
1667 struct mdt_body *body,
1668 ldlm_blocking_callback cb)
1671 EXP_CHECK_MD_OP(exp, update_lsm_md);
1672 EXP_MD_COUNTER_INCREMENT(exp, update_lsm_md);
1673 RETURN(MDP(exp->exp_obd, update_lsm_md)(exp, lsm, body, cb));
1676 static inline int md_merge_attr(struct obd_export *exp,
1677 const struct lmv_stripe_md *lsm,
1678 struct cl_attr *attr)
1681 EXP_CHECK_MD_OP(exp, merge_attr);
1682 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1683 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr));
1686 static inline int md_setxattr(struct obd_export *exp,
1687 const struct lu_fid *fid, struct obd_capa *oc,
1688 obd_valid valid, const char *name,
1689 const char *input, int input_size,
1690 int output_size, int flags, __u32 suppgid,
1691 struct ptlrpc_request **request)
1694 EXP_CHECK_MD_OP(exp, setxattr);
1695 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1696 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1697 input_size, output_size, flags,
1701 static inline int md_getxattr(struct obd_export *exp,
1702 const struct lu_fid *fid, struct obd_capa *oc,
1703 obd_valid valid, const char *name,
1704 const char *input, int input_size,
1705 int output_size, int flags,
1706 struct ptlrpc_request **request)
1709 EXP_CHECK_MD_OP(exp, getxattr);
1710 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1711 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1712 input_size, output_size, flags,
1716 static inline int md_set_open_replay_data(struct obd_export *exp,
1717 struct obd_client_handle *och,
1718 struct lookup_intent *it)
1721 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1722 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1723 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1726 static inline int md_clear_open_replay_data(struct obd_export *exp,
1727 struct obd_client_handle *och)
1730 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1731 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1732 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1735 static inline int md_set_lock_data(struct obd_export *exp,
1736 __u64 *lockh, void *data, __u64 *bits)
1739 EXP_CHECK_MD_OP(exp, set_lock_data);
1740 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1741 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1744 static inline int md_cancel_unused(struct obd_export *exp,
1745 const struct lu_fid *fid,
1746 ldlm_policy_data_t *policy,
1748 ldlm_cancel_flags_t flags,
1754 EXP_CHECK_MD_OP(exp, cancel_unused);
1755 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1757 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1762 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
1763 const struct lu_fid *fid,
1765 ldlm_policy_data_t *policy,
1767 struct lustre_handle *lockh)
1770 EXP_CHECK_MD_OP(exp, lock_match);
1771 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1772 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1773 policy, mode, lockh));
1776 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1777 int def_asize, int cookiesize,
1781 EXP_CHECK_MD_OP(exp, init_ea_size);
1782 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1783 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1784 cookiesize, def_cookiesize));
1787 static inline int md_get_remote_perm(struct obd_export *exp,
1788 const struct lu_fid *fid,
1789 struct obd_capa *oc, __u32 suppgid,
1790 struct ptlrpc_request **request)
1793 EXP_CHECK_MD_OP(exp, get_remote_perm);
1794 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1795 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1799 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1804 EXP_CHECK_MD_OP(exp, renew_capa);
1805 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1806 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1810 static inline int md_unpack_capa(struct obd_export *exp,
1811 struct ptlrpc_request *req,
1812 const struct req_msg_field *field,
1813 struct obd_capa **oc)
1817 EXP_CHECK_MD_OP(exp, unpack_capa);
1818 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
1819 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
1823 static inline int md_intent_getattr_async(struct obd_export *exp,
1824 struct md_enqueue_info *minfo,
1825 struct ldlm_enqueue_info *einfo)
1829 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1830 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1831 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
1835 static inline int md_revalidate_lock(struct obd_export *exp,
1836 struct lookup_intent *it,
1837 struct lu_fid *fid, __u64 *bits)
1841 EXP_CHECK_MD_OP(exp, revalidate_lock);
1842 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1843 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1847 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1848 const struct lmv_stripe_md *lsm,
1849 const char *name, int namelen,
1854 EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1855 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1856 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1860 /* OBD Metadata Support */
1862 extern int obd_init_caches(void);
1863 extern void obd_cleanup_caches(void);
1865 /* support routines */
1866 extern struct kmem_cache *obdo_cachep;
1868 #define OBDO_ALLOC(ptr) \
1870 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1873 #define OBDO_FREE(ptr) \
1875 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1879 typedef int (*register_lwp_cb)(void *data);
1881 struct lwp_register_item {
1882 struct obd_export **lri_exp;
1883 register_lwp_cb lri_cb_func;
1885 struct list_head lri_list;
1886 char lri_name[MTI_NAME_MAXLEN];
1889 /* I'm as embarrassed about this as you are.
1891 * <shaver> // XXX do not look into _superhack with remaining eye
1892 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1893 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1896 #ifdef HAVE_SERVER_SUPPORT
1897 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1898 register_lwp_cb cb_func, void *cb_data);
1899 void lustre_deregister_lwp_item(struct obd_export **exp);
1900 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1901 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1902 #endif /* HAVE_SERVER_SUPPORT */
1905 extern void obd_sysctl_init (void);
1906 extern void obd_sysctl_clean (void);
1909 typedef __u8 class_uuid_t[16];
1910 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1913 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1914 int class_add_uuid(const char *uuid, __u64 nid);
1915 int class_del_uuid (const char *uuid);
1916 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1917 void class_init_uuidlist(void);
1918 void class_exit_uuidlist(void);
1921 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1925 void statfs_pack(struct obd_statfs *osfs, struct kstatfs *sfs);
1926 void statfs_unpack(struct kstatfs *sfs, struct obd_statfs *osfs);
1928 /* root squash info */
1929 struct rw_semaphore;
1930 struct root_squash_info {
1933 struct list_head rsi_nosquash_nids;
1934 struct rw_semaphore rsi_sem;
1937 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1939 #endif /* __LINUX_OBD_CLASS_H */