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 <liblustre.h>
43 #include <obd_support.h>
44 #include <lustre_import.h>
45 #include <lustre_net.h>
47 #include <lustre_lib.h>
48 #include <lustre/lustre_idl.h>
49 #include <lprocfs_status.h>
51 #if defined(__linux__)
52 #include <linux/obd_class.h>
54 #error Unsupported operating system.
57 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
58 * and resends for avoid deadlocks */
59 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
61 #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd
62 * instead of a specific set. This
63 * means that we cannot rely on the set
64 * interpret routine to be called.
65 * lov_statfs_fini() must thus be called
66 * by the request interpret routine */
67 #define OBD_STATFS_FOR_MDT0 0x0008 /* The statfs is only for retrieving
68 * information from MDT0. */
70 /* OBD Device Declarations */
71 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
72 extern struct list_head obd_types;
73 extern spinlock_t obd_types_lock;
74 extern rwlock_t obd_dev_lock;
76 /* OBD Operations Declarations */
77 extern struct obd_device *class_conn2obd(struct lustre_handle *);
78 extern struct obd_device *class_exp2obd(struct obd_export *);
79 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
80 extern int lustre_get_jobid(char *jobid);
82 struct lu_device_type;
85 struct obd_export *class_conn2export(struct lustre_handle *);
86 int class_register_type(struct obd_ops *, struct md_ops *, bool enable_proc,
87 struct lprocfs_seq_vars *module_vars,
88 #ifndef HAVE_ONLY_PROCFS_SEQ
89 struct lprocfs_vars *,
91 const char *nm, struct lu_device_type *ldt);
92 int class_unregister_type(const char *nm);
94 struct obd_device *class_newdev(const char *type_name, const char *name);
95 void class_release_dev(struct obd_device *obd);
97 int class_name2dev(const char *name);
98 struct obd_device *class_name2obd(const char *name);
99 int class_uuid2dev(struct obd_uuid *uuid);
100 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
101 void class_obd_list(void);
102 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
103 const char * typ_name,
104 struct obd_uuid *grp_uuid);
105 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
107 struct obd_device * class_num2obd(int num);
108 int get_devices_count(void);
110 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
112 char *obd_export_nid2str(struct obd_export *exp);
114 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
115 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
116 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
118 int obd_zombie_impexp_init(void);
119 void obd_zombie_impexp_stop(void);
120 void obd_zombie_impexp_cull(void);
121 void obd_zombie_barrier(void);
122 void obd_exports_barrier(struct obd_device *obd);
123 int kuc_len(int payload_len);
124 struct kuc_hdr * kuc_ptr(void *p);
125 int kuc_ispayload(void *p);
126 void *kuc_alloc(int payload_len, int transport, int type);
127 void kuc_free(void *p, int payload_len);
128 int obd_get_request_slot(struct client_obd *cli);
129 void obd_put_request_slot(struct client_obd *cli);
130 __u32 obd_get_max_rpcs_in_flight(struct client_obd *cli);
131 int obd_set_max_rpcs_in_flight(struct client_obd *cli, __u32 max);
135 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
136 struct llog_rec_hdr *, void *);
138 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
139 const char *new_name);
140 int class_process_config(struct lustre_cfg *lcfg);
141 #ifndef HAVE_ONLY_PROCFS_SEQ
142 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
143 struct lustre_cfg *lcfg, void *data);
145 int class_process_proc_seq_param(char *prefix, struct lprocfs_seq_vars *lvars,
146 struct lustre_cfg *lcfg, void *data);
147 int class_attach(struct lustre_cfg *lcfg);
148 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
149 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
150 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
151 struct obd_device *class_incref(struct obd_device *obd,
152 const char *scope, const void *source);
153 void class_decref(struct obd_device *obd,
154 const char *scope, const void *source);
155 void dump_exports(struct obd_device *obd, int locks);
156 int class_config_llog_handler(const struct lu_env *env,
157 struct llog_handle *handle,
158 struct llog_rec_hdr *rec, void *data);
159 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
160 int class_add_uuid(const char *uuid, __u64 nid);
162 #define CFG_F_START 0x01 /* Set when we start updating from a log */
163 #define CFG_F_MARKER 0x02 /* We are within a maker */
164 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
165 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
166 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
168 /* Passed as data param to class_config_parse_llog */
169 struct config_llog_instance {
172 struct super_block *cfg_sb;
173 struct obd_uuid cfg_uuid;
174 llog_cb_t cfg_callback;
175 int cfg_last_idx; /* for partial llog processing */
179 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
180 char *name, struct config_llog_instance *cfg);
181 int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
182 char *name, struct config_llog_instance *cfg);
186 CONFIG_T_SPTLRPC = 1,
187 CONFIG_T_RECOVER = 2,
192 #define PARAMS_FILENAME "params"
193 #define LCTL_UPCALL "lctl"
195 /* list of active configuration logs */
196 struct config_llog_data {
197 struct ldlm_res_id cld_resid;
198 struct config_llog_instance cld_cfg;
199 struct list_head cld_list_chain;
200 atomic_t cld_refcount;
201 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
202 struct config_llog_data *cld_params; /* common parameters log */
203 struct config_llog_data *cld_recover;/* imperative recover log */
204 struct obd_export *cld_mgcexp;
205 struct mutex cld_lock;
207 unsigned int cld_stopping:1, /* we were told to stop
209 cld_lostlock:1; /* lock not requeued */
213 struct lustre_profile {
214 struct list_head lp_list;
220 struct lustre_profile *class_get_profile(const char * prof);
221 void class_del_profile(const char *prof);
222 void class_del_profiles(void);
224 #if LUSTRE_TRACKS_LOCK_EXP_REFS
226 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
227 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
228 extern void (*class_export_dump_hook)(struct obd_export *);
232 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
233 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
237 #define class_export_rpc_inc(exp) \
239 atomic_inc(&(exp)->exp_rpc_count); \
240 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
241 (exp), atomic_read(&(exp)->exp_rpc_count)); \
244 #define class_export_rpc_dec(exp) \
246 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
247 atomic_dec(&(exp)->exp_rpc_count); \
248 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
249 (exp), atomic_read(&(exp)->exp_rpc_count)); \
252 #define class_export_lock_get(exp, lock) \
254 atomic_inc(&(exp)->exp_locks_count); \
255 __class_export_add_lock_ref(exp, lock); \
256 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
257 (exp), atomic_read(&(exp)->exp_locks_count)); \
258 class_export_get(exp); \
261 #define class_export_lock_put(exp, lock) \
263 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
264 atomic_dec(&(exp)->exp_locks_count); \
265 __class_export_del_lock_ref(exp, lock); \
266 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
267 (exp), atomic_read(&(exp)->exp_locks_count)); \
268 class_export_put(exp); \
271 #define class_export_cb_get(exp) \
273 atomic_inc(&(exp)->exp_cb_count); \
274 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
275 (exp), atomic_read(&(exp)->exp_cb_count)); \
276 class_export_get(exp); \
279 #define class_export_cb_put(exp) \
281 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
282 atomic_dec(&(exp)->exp_cb_count); \
283 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
284 (exp), atomic_read(&(exp)->exp_cb_count)); \
285 class_export_put(exp); \
289 struct obd_export *class_export_get(struct obd_export *exp);
290 void class_export_put(struct obd_export *exp);
291 struct obd_export *class_new_export(struct obd_device *obddev,
292 struct obd_uuid *cluuid);
293 void class_unlink_export(struct obd_export *exp);
295 struct obd_import *class_import_get(struct obd_import *);
296 void class_import_put(struct obd_import *);
297 struct obd_import *class_new_import(struct obd_device *obd);
298 void class_destroy_import(struct obd_import *exp);
300 struct obd_type *class_search_type(const char *name);
301 struct obd_type *class_get_type(const char *name);
302 void class_put_type(struct obd_type *type);
303 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
304 struct obd_uuid *cluuid);
305 int class_disconnect(struct obd_export *exp);
306 void class_fail_export(struct obd_export *exp);
307 int class_connected_export(struct obd_export *exp);
308 void class_disconnect_exports(struct obd_device *obddev);
309 int class_manual_cleanup(struct obd_device *obd);
310 void class_disconnect_stale_exports(struct obd_device *,
311 int (*test_export)(struct obd_export *));
312 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
314 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
315 (obd->obd_force ? OBD_OPT_FORCE : 0) |
316 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
320 #ifdef HAVE_SERVER_SUPPORT
321 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
323 LASSERT(exp->exp_obd);
324 return exp->exp_obd->u.obt.obt_lut;
327 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
329 LASSERT(obd->u.obt.obt_lut);
330 return &obd->u.obt.obt_lut->lut_lsd;
334 void obdo_cpy_md(struct obdo *dst, const struct obdo *src, obd_flag valid);
335 void obdo_to_ioobj(const struct obdo *oa, struct obd_ioobj *ioobj);
336 void md_from_obdo(struct md_op_data *op_data, const struct obdo *oa,
339 #define OBT(dev) (dev)->obd_type
340 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
341 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
342 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
344 /* Ensure obd_setup: used for cleanup which must be called
345 while obd is stopping */
346 #define OBD_CHECK_DEV(obd) \
349 CERROR("NULL device\n"); \
354 /* ensure obd_setup and !obd_stopping */
355 #define OBD_CHECK_DEV_ACTIVE(obd) \
357 OBD_CHECK_DEV(obd); \
358 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
359 CERROR("Device %d not setup\n", \
367 #define OBD_COUNTER_OFFSET(op) \
368 ((offsetof(struct obd_ops, o_ ## op) - \
369 offsetof(struct obd_ops, o_iocontrol)) \
370 / sizeof(((struct obd_ops *)NULL)->o_iocontrol))
372 /* The '- 1' below is for o_owner. */
373 #define NUM_OBD_STATS \
374 (sizeof(struct obd_ops) / \
375 sizeof(((struct obd_ops *)NULL)->o_iocontrol) - 1)
377 #define OBD_COUNTER_INCREMENT(obd, op) \
378 lprocfs_counter_incr((obd)->obd_stats, \
379 (obd)->obd_cntr_base + OBD_COUNTER_OFFSET(op))
381 #define EXP_COUNTER_INCREMENT(exp, op) \
384 _off = (exp)->exp_obd->obd_cntr_base + OBD_COUNTER_OFFSET(op); \
385 lprocfs_counter_incr((exp)->exp_obd->obd_stats, _off); \
386 if ((exp)->exp_obd->obd_uses_nid_stats && \
387 (exp)->exp_nid_stats != NULL) \
388 lprocfs_counter_incr((exp)->exp_nid_stats->nid_stats, \
392 #define _MD_COUNTER_OFFSET(m_op) \
393 ((offsetof(struct md_ops, m_op) - \
394 offsetof(struct md_ops, MD_STATS_FIRST_OP)) / \
395 sizeof(((struct md_ops *)NULL)->MD_STATS_FIRST_OP))
397 #define MD_COUNTER_OFFSET(op) _MD_COUNTER_OFFSET(m_ ## op)
399 #define NUM_MD_STATS \
400 (_MD_COUNTER_OFFSET(MD_STATS_LAST_OP) - \
401 _MD_COUNTER_OFFSET(MD_STATS_FIRST_OP) + 1)
403 /* Note that we only increment md counters for ops whose offset is less
404 * than NUM_MD_STATS. This is explained in a comment in the definition
405 * of struct md_ops. */
406 #define EXP_MD_COUNTER_INCREMENT(exp, op) \
408 if (MD_COUNTER_OFFSET(op) < NUM_MD_STATS) \
409 lprocfs_counter_incr((exp)->exp_obd->obd_md_stats, \
410 (exp)->exp_obd->obd_md_cntr_base + \
411 MD_COUNTER_OFFSET(op)); \
415 #define OBD_COUNTER_OFFSET(op)
416 #define OBD_COUNTER_INCREMENT(obd, op)
417 #define EXP_COUNTER_INCREMENT(exp, op)
418 #define EXP_MD_COUNTER_INCREMENT(exp, op)
421 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
423 /* Always add in ldlm_stats */
424 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
425 ,LPROCFS_STATS_FLAG_NOPERCPU);
426 if (tmp->nid_ldlm_stats == NULL)
429 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
431 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
432 tmp->nid_ldlm_stats);
435 #define EXP_CHECK_MD_OP(exp, op) \
437 if ((exp) == NULL) { \
438 CERROR("obd_" #op ": NULL export\n"); \
441 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
442 CERROR("obd_" #op ": cleaned up obd\n"); \
443 RETURN(-EOPNOTSUPP); \
445 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
446 CERROR("obd_" #op ": dev %s/%d no operation\n", \
447 (exp)->exp_obd->obd_name, \
448 (exp)->exp_obd->obd_minor); \
449 RETURN(-EOPNOTSUPP); \
454 #define OBD_CHECK_DT_OP(obd, op, err) \
456 if (!OBT(obd) || !OBP((obd), op)) { \
458 CERROR("obd_" #op ": dev %d no operation\n", \
464 #define EXP_CHECK_DT_OP(exp, op) \
466 if ((exp) == NULL) { \
467 CERROR("obd_" #op ": NULL export\n"); \
470 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
471 CERROR("obd_" #op ": cleaned up obd\n"); \
472 RETURN(-EOPNOTSUPP); \
474 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
475 CERROR("obd_" #op ": dev %d no operation\n", \
476 (exp)->exp_obd->obd_minor); \
477 RETURN(-EOPNOTSUPP); \
481 #define CTXT_CHECK_OP(ctxt, op, err) \
483 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
485 CERROR("lop_" #op ": dev %d no operation\n", \
486 ctxt->loc_obd->obd_minor); \
491 static inline int class_devno_max(void)
493 return MAX_OBD_DEVICES;
496 static inline int obd_get_info(const struct lu_env *env,
497 struct obd_export *exp, __u32 keylen,
498 void *key, __u32 *vallen, void *val,
499 struct lov_stripe_md *lsm)
504 EXP_CHECK_DT_OP(exp, get_info);
505 EXP_COUNTER_INCREMENT(exp, get_info);
507 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val,
512 static inline int obd_set_info_async(const struct lu_env *env,
513 struct obd_export *exp, obd_count keylen,
514 void *key, obd_count vallen, void *val,
515 struct ptlrpc_request_set *set)
520 EXP_CHECK_DT_OP(exp, set_info_async);
521 EXP_COUNTER_INCREMENT(exp, set_info_async);
523 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
529 * obd-lu integration.
531 * Functionality is being moved into new lu_device-based layering, but some
532 * pieces of configuration process are still based on obd devices.
534 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
535 * subsume ->o_setup() methods of obd devices they replace. The same for
536 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
537 * result, obd_setup() and obd_process_config() branch and call one XOR
540 * Yet neither lu_device_type_operations::ldto_device_fini() nor
541 * lu_device_type_operations::ldto_device_free() fully implement the
542 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
543 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
546 #define DECLARE_LU_VARS(ldt, d) \
547 struct lu_device_type *ldt; \
550 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
553 DECLARE_LU_VARS(ldt, d);
556 ldt = obd->obd_type->typ_lu;
558 struct lu_context session_ctx;
560 lu_context_init(&session_ctx, LCT_SESSION | LCT_SERVER_SESSION);
561 session_ctx.lc_thread = NULL;
562 lu_context_enter(&session_ctx);
564 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
566 env.le_ses = &session_ctx;
567 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
576 lu_context_exit(&session_ctx);
577 lu_context_fini(&session_ctx);
580 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
581 OBD_COUNTER_INCREMENT(obd, setup);
582 rc = OBP(obd, setup)(obd, cfg);
587 static inline int obd_precleanup(struct obd_device *obd,
588 enum obd_cleanup_stage cleanup_stage)
591 DECLARE_LU_VARS(ldt, d);
595 ldt = obd->obd_type->typ_lu;
597 if (ldt != NULL && d != NULL) {
598 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
601 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
603 ldt->ldt_ops->ldto_device_fini(&env, d);
608 OBD_CHECK_DT_OP(obd, precleanup, 0);
609 OBD_COUNTER_INCREMENT(obd, precleanup);
611 rc = OBP(obd, precleanup)(obd, cleanup_stage);
615 static inline int obd_cleanup(struct obd_device *obd)
618 DECLARE_LU_VARS(ldt, d);
623 ldt = obd->obd_type->typ_lu;
625 if (ldt != NULL && d != NULL) {
628 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
630 ldt->ldt_ops->ldto_device_free(&env, d);
632 obd->obd_lu_dev = NULL;
635 OBD_CHECK_DT_OP(obd, cleanup, 0);
636 OBD_COUNTER_INCREMENT(obd, cleanup);
638 rc = OBP(obd, cleanup)(obd);
642 static inline void obd_cleanup_client_import(struct obd_device *obd)
646 /* If we set up but never connected, the
647 client import will not have been cleaned. */
648 down_write(&obd->u.cli.cl_sem);
649 if (obd->u.cli.cl_import) {
650 struct obd_import *imp;
651 imp = obd->u.cli.cl_import;
652 CDEBUG(D_CONFIG, "%s: client import never connected\n",
654 ptlrpc_invalidate_import(imp);
655 if (imp->imp_rq_pool) {
656 ptlrpc_free_rq_pool(imp->imp_rq_pool);
657 imp->imp_rq_pool = NULL;
659 client_destroy_import(imp);
660 obd->u.cli.cl_import = NULL;
662 up_write(&obd->u.cli.cl_sem);
668 obd_process_config(struct obd_device *obd, int datalen, void *data)
671 DECLARE_LU_VARS(ldt, d);
676 obd->obd_process_conf = 1;
677 ldt = obd->obd_type->typ_lu;
679 if (ldt != NULL && d != NULL) {
682 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
684 rc = d->ld_ops->ldo_process_config(&env, d, data);
688 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
689 rc = OBP(obd, process_config)(obd, datalen, data);
691 OBD_COUNTER_INCREMENT(obd, process_config);
692 obd->obd_process_conf = 0;
697 /* Pack an in-memory MD struct for storage on disk.
698 * Returns +ve size of packed MD (0 for free), or -ve error.
700 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
701 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
702 * If @*disk_tgt == NULL, it will be allocated
704 static inline int obd_packmd(struct obd_export *exp,
705 struct lov_mds_md **disk_tgt,
706 struct lov_stripe_md *mem_src)
711 EXP_CHECK_DT_OP(exp, packmd);
712 EXP_COUNTER_INCREMENT(exp, packmd);
714 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
718 static inline int obd_size_diskmd(struct obd_export *exp,
719 struct lov_stripe_md *mem_src)
721 return obd_packmd(exp, NULL, mem_src);
724 static inline int obd_free_diskmd(struct obd_export *exp,
725 struct lov_mds_md **disk_tgt)
730 * LU-2590, for caller's convenience, *disk_tgt could be host
731 * endianness, it needs swab to LE if necessary, while just
732 * lov_mds_md header needs it for figuring out how much memory
735 if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
736 (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
737 ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
738 lustre_swab_lov_mds_md(*disk_tgt);
739 return obd_packmd(exp, disk_tgt, NULL);
742 /* Unpack an MD struct from disk to in-memory format.
743 * Returns +ve size of unpacked MD (0 for free), or -ve error.
745 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
746 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
747 * If @*mem_tgt == NULL, it will be allocated
749 static inline int obd_unpackmd(struct obd_export *exp,
750 struct lov_stripe_md **mem_tgt,
751 struct lov_mds_md *disk_src,
757 EXP_CHECK_DT_OP(exp, unpackmd);
758 EXP_COUNTER_INCREMENT(exp, unpackmd);
760 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
764 /* helper functions */
765 static inline int obd_alloc_memmd(struct obd_export *exp,
766 struct lov_stripe_md **mem_tgt)
769 LASSERT(*mem_tgt == NULL);
770 return obd_unpackmd(exp, mem_tgt, NULL, 0);
773 static inline int obd_free_memmd(struct obd_export *exp,
774 struct lov_stripe_md **mem_tgt)
780 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
785 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
786 struct obdo *obdo, struct lov_stripe_md **ea,
787 struct obd_trans_info *oti)
792 EXP_CHECK_DT_OP(exp, create);
793 EXP_COUNTER_INCREMENT(exp, create);
795 rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti);
799 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
800 struct obdo *obdo, struct lov_stripe_md *ea,
801 struct obd_trans_info *oti,
802 struct obd_export *md_exp, void *capa)
807 EXP_CHECK_DT_OP(exp, destroy);
808 EXP_COUNTER_INCREMENT(exp, destroy);
810 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp, capa);
814 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
815 struct obd_info *oinfo)
820 EXP_CHECK_DT_OP(exp, getattr);
821 EXP_COUNTER_INCREMENT(exp, getattr);
823 rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo);
827 static inline int obd_getattr_async(struct obd_export *exp,
828 struct obd_info *oinfo,
829 struct ptlrpc_request_set *set)
834 EXP_CHECK_DT_OP(exp, getattr_async);
835 EXP_COUNTER_INCREMENT(exp, getattr_async);
837 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
841 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
842 struct obd_info *oinfo,
843 struct obd_trans_info *oti)
848 EXP_CHECK_DT_OP(exp, setattr);
849 EXP_COUNTER_INCREMENT(exp, setattr);
851 rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
855 /* This performs all the requests set init/wait/destroy actions. */
856 static inline int obd_setattr_rqset(struct obd_export *exp,
857 struct obd_info *oinfo,
858 struct obd_trans_info *oti)
860 struct ptlrpc_request_set *set = NULL;
864 EXP_CHECK_DT_OP(exp, setattr_async);
865 EXP_COUNTER_INCREMENT(exp, setattr_async);
867 set = ptlrpc_prep_set();
871 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
873 rc = ptlrpc_set_wait(set);
874 ptlrpc_set_destroy(set);
878 /* This adds all the requests into @set if @set != NULL, otherwise
879 all requests are sent asynchronously without waiting for response. */
880 static inline int obd_setattr_async(struct obd_export *exp,
881 struct obd_info *oinfo,
882 struct obd_trans_info *oti,
883 struct ptlrpc_request_set *set)
888 EXP_CHECK_DT_OP(exp, setattr_async);
889 EXP_COUNTER_INCREMENT(exp, setattr_async);
891 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
895 static inline int obd_add_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, add_conn, -EOPNOTSUPP);
904 OBD_COUNTER_INCREMENT(obd, add_conn);
906 rc = OBP(obd, add_conn)(imp, uuid, priority);
910 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
912 struct obd_device *obd = imp->imp_obd;
916 OBD_CHECK_DEV_ACTIVE(obd);
917 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
918 OBD_COUNTER_INCREMENT(obd, del_conn);
920 rc = OBP(obd, del_conn)(imp, uuid);
924 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
926 struct obd_uuid *uuid;
929 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
930 EXP_COUNTER_INCREMENT(exp, get_uuid);
932 uuid = OBP(exp->exp_obd, get_uuid)(exp);
936 /** Create a new /a exp on device /a obd for the uuid /a cluuid
937 * @param exp New export handle
938 * @param d Connect data, supported flags are set, flags also understood
939 * by obd are returned.
941 static inline int obd_connect(const struct lu_env *env,
942 struct obd_export **exp,struct obd_device *obd,
943 struct obd_uuid *cluuid,
944 struct obd_connect_data *data,
948 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
952 OBD_CHECK_DEV_ACTIVE(obd);
953 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
954 OBD_COUNTER_INCREMENT(obd, connect);
956 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
957 /* check that only subset is granted */
958 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
959 data->ocd_connect_flags));
963 static inline int obd_reconnect(const struct lu_env *env,
964 struct obd_export *exp,
965 struct obd_device *obd,
966 struct obd_uuid *cluuid,
967 struct obd_connect_data *d,
971 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
976 OBD_CHECK_DEV_ACTIVE(obd);
977 OBD_CHECK_DT_OP(obd, reconnect, 0);
978 OBD_COUNTER_INCREMENT(obd, reconnect);
980 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
981 /* check that only subset is granted */
982 LASSERT(ergo(d != NULL,
983 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
987 static inline int obd_disconnect(struct obd_export *exp)
992 EXP_CHECK_DT_OP(exp, disconnect);
993 EXP_COUNTER_INCREMENT(exp, disconnect);
995 rc = OBP(exp->exp_obd, disconnect)(exp);
999 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
1000 enum lu_cli_type type)
1005 OBD_CHECK_DT_OP(obd, fid_init, 0);
1006 OBD_COUNTER_INCREMENT(obd, fid_init);
1008 rc = OBP(obd, fid_init)(obd, exp, type);
1012 static inline int obd_fid_fini(struct obd_device *obd)
1017 OBD_CHECK_DT_OP(obd, fid_fini, 0);
1018 OBD_COUNTER_INCREMENT(obd, fid_fini);
1020 rc = OBP(obd, fid_fini)(obd);
1024 static inline int obd_fid_alloc(const struct lu_env *env,
1025 struct obd_export *exp,
1027 struct md_op_data *op_data)
1032 EXP_CHECK_DT_OP(exp, fid_alloc);
1033 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1035 rc = OBP(exp->exp_obd, fid_alloc)(env, exp, fid, op_data);
1039 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
1044 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1045 EXP_COUNTER_INCREMENT(exp, ping);
1047 rc = OBP(exp->exp_obd, ping)(env, exp);
1051 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1056 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1057 OBD_COUNTER_INCREMENT(obd, pool_new);
1059 rc = OBP(obd, pool_new)(obd, poolname);
1063 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1068 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1069 OBD_COUNTER_INCREMENT(obd, pool_del);
1071 rc = OBP(obd, pool_del)(obd, poolname);
1075 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1080 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1081 OBD_COUNTER_INCREMENT(obd, pool_add);
1083 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1087 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1092 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1093 OBD_COUNTER_INCREMENT(obd, pool_rem);
1095 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1099 static inline void obd_getref(struct obd_device *obd)
1102 if (OBT(obd) && OBP(obd, getref)) {
1103 OBD_COUNTER_INCREMENT(obd, getref);
1104 OBP(obd, getref)(obd);
1109 static inline void obd_putref(struct obd_device *obd)
1112 if (OBT(obd) && OBP(obd, putref)) {
1113 OBD_COUNTER_INCREMENT(obd, putref);
1114 OBP(obd, putref)(obd);
1119 static inline int obd_init_export(struct obd_export *exp)
1124 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1125 OBP((exp)->exp_obd, init_export))
1126 rc = OBP(exp->exp_obd, init_export)(exp);
1130 static inline int obd_destroy_export(struct obd_export *exp)
1133 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1134 OBP((exp)->exp_obd, destroy_export))
1135 OBP(exp->exp_obd, destroy_export)(exp);
1139 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1140 * If the cache is older than @max_age we will get a new value from the
1141 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1142 static inline int obd_statfs_async(struct obd_export *exp,
1143 struct obd_info *oinfo,
1145 struct ptlrpc_request_set *rqset)
1148 struct obd_device *obd;
1151 if (exp == NULL || exp->exp_obd == NULL)
1155 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1156 OBD_COUNTER_INCREMENT(obd, statfs);
1158 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1159 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1160 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1161 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1163 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1164 " objects "LPU64"/"LPU64"\n",
1165 obd->obd_name, &obd->obd_osfs,
1166 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1167 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1168 spin_lock(&obd->obd_osfs_lock);
1169 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1170 spin_unlock(&obd->obd_osfs_lock);
1171 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1172 if (oinfo->oi_cb_up)
1173 oinfo->oi_cb_up(oinfo, 0);
1178 static inline int obd_statfs_rqset(struct obd_export *exp,
1179 struct obd_statfs *osfs, __u64 max_age,
1182 struct ptlrpc_request_set *set = NULL;
1183 struct obd_info oinfo = { { { 0 } } };
1187 set = ptlrpc_prep_set();
1191 oinfo.oi_osfs = osfs;
1192 oinfo.oi_flags = flags;
1193 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1195 rc = ptlrpc_set_wait(set);
1196 ptlrpc_set_destroy(set);
1200 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1201 * If the cache is older than @max_age we will get a new value from the
1202 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1203 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1204 struct obd_statfs *osfs, __u64 max_age,
1208 struct obd_device *obd = exp->exp_obd;
1214 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1215 OBD_COUNTER_INCREMENT(obd, statfs);
1217 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1218 obd->obd_osfs_age, max_age);
1219 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1220 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1222 spin_lock(&obd->obd_osfs_lock);
1223 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1224 obd->obd_osfs_age = cfs_time_current_64();
1225 spin_unlock(&obd->obd_osfs_lock);
1228 CDEBUG(D_SUPER, "%s: use %p cache blocks "LPU64"/"LPU64
1229 " objects "LPU64"/"LPU64"\n",
1230 obd->obd_name, &obd->obd_osfs,
1231 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1232 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1233 spin_lock(&obd->obd_osfs_lock);
1234 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1235 spin_unlock(&obd->obd_osfs_lock);
1240 static inline int obd_preprw(const struct lu_env *env, int cmd,
1241 struct obd_export *exp, struct obdo *oa,
1242 int objcount, struct obd_ioobj *obj,
1243 struct niobuf_remote *remote, int *pages,
1244 struct niobuf_local *local,
1245 struct obd_trans_info *oti,
1246 struct lustre_capa *capa)
1251 EXP_CHECK_DT_OP(exp, preprw);
1252 EXP_COUNTER_INCREMENT(exp, preprw);
1254 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1255 pages, local, oti, capa);
1259 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1260 struct obd_export *exp, struct obdo *oa,
1261 int objcount, struct obd_ioobj *obj,
1262 struct niobuf_remote *rnb, int pages,
1263 struct niobuf_local *local,
1264 struct obd_trans_info *oti, int rc)
1268 EXP_CHECK_DT_OP(exp, commitrw);
1269 EXP_COUNTER_INCREMENT(exp, commitrw);
1271 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1272 rnb, pages, local, oti, rc);
1276 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1277 int len, void *karg, void *uarg)
1282 EXP_CHECK_DT_OP(exp, iocontrol);
1283 EXP_COUNTER_INCREMENT(exp, iocontrol);
1285 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1289 static inline int obd_change_cbdata(struct obd_export *exp,
1290 struct lov_stripe_md *lsm,
1291 ldlm_iterator_t it, void *data)
1296 EXP_CHECK_DT_OP(exp, change_cbdata);
1297 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1299 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1303 static inline int obd_find_cbdata(struct obd_export *exp,
1304 struct lov_stripe_md *lsm,
1305 ldlm_iterator_t it, void *data)
1310 EXP_CHECK_DT_OP(exp, find_cbdata);
1311 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1313 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1317 static inline void obd_import_event(struct obd_device *obd,
1318 struct obd_import *imp,
1319 enum obd_import_event event)
1323 CERROR("NULL device\n");
1327 if (obd->obd_set_up && OBP(obd, import_event)) {
1328 OBD_COUNTER_INCREMENT(obd, import_event);
1329 OBP(obd, import_event)(obd, imp, event);
1334 static inline int obd_notify(struct obd_device *obd,
1335 struct obd_device *watched,
1336 enum obd_notify_event ev,
1343 if (!obd->obd_set_up) {
1344 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1348 if (!OBP(obd, notify)) {
1349 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1353 OBD_COUNTER_INCREMENT(obd, notify);
1354 rc = OBP(obd, notify)(obd, watched, ev, data);
1358 static inline int obd_notify_observer(struct obd_device *observer,
1359 struct obd_device *observed,
1360 enum obd_notify_event ev,
1366 struct obd_notify_upcall *onu;
1368 if (observer->obd_observer)
1369 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1373 * Also, call non-obd listener, if any
1375 onu = &observer->obd_upcall;
1376 if (onu->onu_upcall != NULL)
1377 rc2 = onu->onu_upcall(observer, observed, ev,
1378 onu->onu_owner, NULL);
1382 return rc1 ? rc1 : rc2;
1385 static inline int obd_quotacheck(struct obd_export *exp,
1386 struct obd_quotactl *oqctl)
1391 EXP_CHECK_DT_OP(exp, quotacheck);
1392 EXP_COUNTER_INCREMENT(exp, quotacheck);
1394 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1398 static inline int obd_quotactl(struct obd_export *exp,
1399 struct obd_quotactl *oqctl)
1404 EXP_CHECK_DT_OP(exp, quotactl);
1405 EXP_COUNTER_INCREMENT(exp, quotactl);
1407 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1411 static inline int obd_health_check(const struct lu_env *env,
1412 struct obd_device *obd)
1414 /* returns: 0 on healthy
1415 * >0 on unhealthy + reason code/flag
1416 * however the only suppored reason == 1 right now
1417 * We'll need to define some better reasons
1418 * or flags in the future.
1424 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1425 if (obd == NULL || !OBT(obd)) {
1426 CERROR("cleaned up obd\n");
1427 RETURN(-EOPNOTSUPP);
1429 if (!obd->obd_set_up || obd->obd_stopping)
1431 if (!OBP(obd, health_check))
1434 rc = OBP(obd, health_check)(env, obd);
1438 static inline int obd_register_observer(struct obd_device *obd,
1439 struct obd_device *observer)
1443 down_write(&obd->obd_observer_link_sem);
1444 if (obd->obd_observer && observer) {
1445 up_write(&obd->obd_observer_link_sem);
1448 obd->obd_observer = observer;
1449 up_write(&obd->obd_observer_link_sem);
1453 /* metadata helpers */
1454 static inline int md_getstatus(struct obd_export *exp,
1455 struct lu_fid *fid, struct obd_capa **pc)
1460 EXP_CHECK_MD_OP(exp, getstatus);
1461 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1462 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1466 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1467 struct ptlrpc_request **request)
1471 EXP_CHECK_MD_OP(exp, getattr);
1472 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1473 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1477 static inline int md_null_inode(struct obd_export *exp,
1478 const struct lu_fid *fid)
1482 EXP_CHECK_MD_OP(exp, null_inode);
1483 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1484 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1488 static inline int md_find_cbdata(struct obd_export *exp,
1489 const struct lu_fid *fid,
1490 ldlm_iterator_t it, void *data)
1494 EXP_CHECK_MD_OP(exp, find_cbdata);
1495 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1496 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1500 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1501 struct md_open_data *mod,
1502 struct ptlrpc_request **request)
1506 EXP_CHECK_MD_OP(exp, close);
1507 EXP_MD_COUNTER_INCREMENT(exp, close);
1508 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1512 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1513 const void *data, int datalen, int mode, __u32 uid,
1514 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1515 struct ptlrpc_request **request)
1519 EXP_CHECK_MD_OP(exp, create);
1520 EXP_MD_COUNTER_INCREMENT(exp, create);
1521 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1522 uid, gid, cap_effective, rdev, request);
1526 static inline int md_done_writing(struct obd_export *exp,
1527 struct md_op_data *op_data,
1528 struct md_open_data *mod)
1532 EXP_CHECK_MD_OP(exp, done_writing);
1533 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1534 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1538 static inline int md_enqueue(struct obd_export *exp,
1539 struct ldlm_enqueue_info *einfo,
1540 const union ldlm_policy_data *policy,
1541 struct lookup_intent *it,
1542 struct md_op_data *op_data,
1543 struct lustre_handle *lockh,
1544 __u64 extra_lock_flags)
1548 EXP_CHECK_MD_OP(exp, enqueue);
1549 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1550 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, policy, it, op_data, lockh,
1555 static inline int md_getattr_name(struct obd_export *exp,
1556 struct md_op_data *op_data,
1557 struct ptlrpc_request **request)
1561 EXP_CHECK_MD_OP(exp, getattr_name);
1562 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1563 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1567 static inline int md_intent_lock(struct obd_export *exp,
1568 struct md_op_data *op_data,
1569 struct lookup_intent *it,
1570 struct ptlrpc_request **reqp,
1571 ldlm_blocking_callback cb_blocking,
1572 __u64 extra_lock_flags)
1576 EXP_CHECK_MD_OP(exp, intent_lock);
1577 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1578 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, it, reqp, cb_blocking,
1583 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1584 struct ptlrpc_request **request)
1588 EXP_CHECK_MD_OP(exp, link);
1589 EXP_MD_COUNTER_INCREMENT(exp, link);
1590 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1594 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1595 const char *old, int oldlen, const char *new,
1596 int newlen, struct ptlrpc_request **request)
1600 EXP_CHECK_MD_OP(exp, rename);
1601 EXP_MD_COUNTER_INCREMENT(exp, rename);
1602 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1607 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1608 void *ea, int ealen, void *ea2, int ea2len,
1609 struct ptlrpc_request **request,
1610 struct md_open_data **mod)
1614 EXP_CHECK_MD_OP(exp, setattr);
1615 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1616 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1617 ea2, ea2len, request, mod);
1621 static inline int md_fsync(struct obd_export *exp, const struct lu_fid *fid,
1622 struct obd_capa *oc, struct ptlrpc_request **request)
1626 EXP_CHECK_MD_OP(exp, fsync);
1627 EXP_MD_COUNTER_INCREMENT(exp, fsync);
1628 rc = MDP(exp->exp_obd, fsync)(exp, fid, oc, request);
1632 static inline int md_read_page(struct obd_export *exp,
1633 struct md_op_data *op_data,
1634 struct md_callback *cb_op,
1636 struct page **ppage)
1640 EXP_CHECK_MD_OP(exp, read_page);
1641 EXP_MD_COUNTER_INCREMENT(exp, read_page);
1642 rc = MDP(exp->exp_obd, read_page)(exp, op_data, cb_op, hash_offset,
1647 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1648 struct ptlrpc_request **request)
1652 EXP_CHECK_MD_OP(exp, unlink);
1653 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1654 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1658 static inline int md_get_lustre_md(struct obd_export *exp,
1659 struct ptlrpc_request *req,
1660 struct obd_export *dt_exp,
1661 struct obd_export *md_exp,
1662 struct lustre_md *md)
1665 EXP_CHECK_MD_OP(exp, get_lustre_md);
1666 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1667 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1670 static inline int md_free_lustre_md(struct obd_export *exp,
1671 struct lustre_md *md)
1674 EXP_CHECK_MD_OP(exp, free_lustre_md);
1675 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1676 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1679 static inline int md_update_lsm_md(struct obd_export *exp,
1680 struct lmv_stripe_md *lsm,
1681 struct mdt_body *body,
1682 ldlm_blocking_callback cb)
1685 EXP_CHECK_MD_OP(exp, update_lsm_md);
1686 EXP_MD_COUNTER_INCREMENT(exp, update_lsm_md);
1687 RETURN(MDP(exp->exp_obd, update_lsm_md)(exp, lsm, body, cb));
1690 static inline int md_merge_attr(struct obd_export *exp,
1691 const struct lmv_stripe_md *lsm,
1692 struct cl_attr *attr)
1695 EXP_CHECK_MD_OP(exp, merge_attr);
1696 EXP_MD_COUNTER_INCREMENT(exp, merge_attr);
1697 RETURN(MDP(exp->exp_obd, merge_attr)(exp, lsm, attr));
1700 static inline int md_setxattr(struct obd_export *exp,
1701 const struct lu_fid *fid, struct obd_capa *oc,
1702 obd_valid valid, const char *name,
1703 const char *input, int input_size,
1704 int output_size, int flags, __u32 suppgid,
1705 struct ptlrpc_request **request)
1708 EXP_CHECK_MD_OP(exp, setxattr);
1709 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1710 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1711 input_size, output_size, flags,
1715 static inline int md_getxattr(struct obd_export *exp,
1716 const struct lu_fid *fid, struct obd_capa *oc,
1717 obd_valid valid, const char *name,
1718 const char *input, int input_size,
1719 int output_size, int flags,
1720 struct ptlrpc_request **request)
1723 EXP_CHECK_MD_OP(exp, getxattr);
1724 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1725 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1726 input_size, output_size, flags,
1730 static inline int md_set_open_replay_data(struct obd_export *exp,
1731 struct obd_client_handle *och,
1732 struct lookup_intent *it)
1735 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1736 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1737 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, it));
1740 static inline int md_clear_open_replay_data(struct obd_export *exp,
1741 struct obd_client_handle *och)
1744 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1745 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1746 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1749 static inline int md_set_lock_data(struct obd_export *exp,
1750 __u64 *lockh, void *data, __u64 *bits)
1753 EXP_CHECK_MD_OP(exp, set_lock_data);
1754 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1755 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
1758 static inline int md_cancel_unused(struct obd_export *exp,
1759 const struct lu_fid *fid,
1760 ldlm_policy_data_t *policy,
1762 ldlm_cancel_flags_t flags,
1768 EXP_CHECK_MD_OP(exp, cancel_unused);
1769 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1771 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1776 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
1777 const struct lu_fid *fid,
1779 ldlm_policy_data_t *policy,
1781 struct lustre_handle *lockh)
1784 EXP_CHECK_MD_OP(exp, lock_match);
1785 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1786 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1787 policy, mode, lockh));
1790 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1791 int def_asize, int cookiesize,
1795 EXP_CHECK_MD_OP(exp, init_ea_size);
1796 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1797 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1798 cookiesize, def_cookiesize));
1801 static inline int md_get_remote_perm(struct obd_export *exp,
1802 const struct lu_fid *fid,
1803 struct obd_capa *oc, __u32 suppgid,
1804 struct ptlrpc_request **request)
1807 EXP_CHECK_MD_OP(exp, get_remote_perm);
1808 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1809 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1813 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1818 EXP_CHECK_MD_OP(exp, renew_capa);
1819 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1820 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1824 static inline int md_unpack_capa(struct obd_export *exp,
1825 struct ptlrpc_request *req,
1826 const struct req_msg_field *field,
1827 struct obd_capa **oc)
1831 EXP_CHECK_MD_OP(exp, unpack_capa);
1832 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
1833 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
1837 static inline int md_intent_getattr_async(struct obd_export *exp,
1838 struct md_enqueue_info *minfo,
1839 struct ldlm_enqueue_info *einfo)
1843 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1844 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1845 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
1849 static inline int md_revalidate_lock(struct obd_export *exp,
1850 struct lookup_intent *it,
1851 struct lu_fid *fid, __u64 *bits)
1855 EXP_CHECK_MD_OP(exp, revalidate_lock);
1856 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1857 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1861 static inline int md_get_fid_from_lsm(struct obd_export *exp,
1862 const struct lmv_stripe_md *lsm,
1863 const char *name, int namelen,
1868 EXP_CHECK_MD_OP(exp, get_fid_from_lsm);
1869 EXP_MD_COUNTER_INCREMENT(exp, get_fid_from_lsm);
1870 rc = MDP(exp->exp_obd, get_fid_from_lsm)(exp, lsm, name, namelen, fid);
1874 /* OBD Metadata Support */
1876 extern int obd_init_caches(void);
1877 extern void obd_cleanup_caches(void);
1879 /* support routines */
1880 extern struct kmem_cache *obdo_cachep;
1882 #define OBDO_ALLOC(ptr) \
1884 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1887 #define OBDO_FREE(ptr) \
1889 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1893 typedef int (*register_lwp_cb)(void *data);
1895 struct lwp_register_item {
1896 struct obd_export **lri_exp;
1897 register_lwp_cb lri_cb_func;
1899 struct list_head lri_list;
1900 char lri_name[MTI_NAME_MAXLEN];
1903 /* I'm as embarrassed about this as you are.
1905 * <shaver> // XXX do not look into _superhack with remaining eye
1906 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1907 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1910 #ifdef HAVE_SERVER_SUPPORT
1911 int lustre_register_lwp_item(const char *lwpname, struct obd_export **exp,
1912 register_lwp_cb cb_func, void *cb_data);
1913 void lustre_deregister_lwp_item(struct obd_export **exp);
1914 struct obd_export *lustre_find_lwp_by_index(const char *dev, __u32 idx);
1915 int tgt_name2lwp_name(const char *tgt_name, char *lwp_name, int len, __u32 idx);
1916 #endif /* HAVE_SERVER_SUPPORT */
1919 extern void obd_sysctl_init (void);
1920 extern void obd_sysctl_clean (void);
1923 typedef __u8 class_uuid_t[16];
1924 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1927 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1928 int class_add_uuid(const char *uuid, __u64 nid);
1929 int class_del_uuid (const char *uuid);
1930 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1931 void class_init_uuidlist(void);
1932 void class_exit_uuidlist(void);
1935 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1937 /* root squash info */
1938 struct rw_semaphore;
1939 struct root_squash_info {
1942 struct list_head rsi_nosquash_nids;
1943 struct rw_semaphore rsi_sem;
1947 int server_name2index(const char *svname, __u32 *idx, const char **endptr);
1949 # define server_name2index(name, idx, ptr) do {} while (0)
1952 #endif /* __LINUX_OBD_CLASS_H */