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, 2012, Intel Corporation.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
40 #include "obd_support.h"
41 #include "lustre_import.h"
42 #include "lustre_net.h"
44 #include "lustre_lib.h"
45 #include "lustre/lustre_idl.h"
46 #include "lprocfs_status.h"
48 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
49 * and resends for avoid deadlocks */
50 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
52 #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd
53 * instead of a specific set. This
54 * means that we cannot rely on the set
55 * interpret routine to be called.
56 * lov_statfs_fini() must thus be called
57 * by the request interpret routine */
58 #define OBD_STATFS_FOR_MDT0 0x0008 /* The statfs is only for retrieving
59 * information from MDT0. */
60 #define OBD_FL_PUNCH 0x00000001 /* To indicate it is punch operation */
62 /* OBD Device Declarations */
63 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
64 extern rwlock_t obd_dev_lock;
66 /* OBD Operations Declarations */
67 extern struct obd_device *class_conn2obd(struct lustre_handle *);
68 extern struct obd_device *class_exp2obd(struct obd_export *);
69 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
70 extern int lustre_get_jobid(char *jobid);
72 struct lu_device_type;
75 struct obd_export *class_conn2export(struct lustre_handle *);
76 int class_register_type(struct obd_ops *, struct md_ops *,
77 struct lprocfs_vars *, const char *nm,
78 struct lu_device_type *ldt);
79 int class_unregister_type(const char *nm);
81 struct obd_device *class_newdev(const char *type_name, const char *name);
82 void class_release_dev(struct obd_device *obd);
84 int class_name2dev(const char *name);
85 struct obd_device *class_name2obd(const char *name);
86 int class_uuid2dev(struct obd_uuid *uuid);
87 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
88 void class_obd_list(void);
89 struct obd_device *class_find_client_obd(struct obd_uuid *tgt_uuid,
91 struct obd_uuid *grp_uuid);
92 struct obd_device *class_devices_in_group(struct obd_uuid *grp_uuid,
94 struct obd_device *class_num2obd(int num);
95 int get_devices_count(void);
97 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
99 char *obd_export_nid2str(struct obd_export *exp);
101 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
102 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
103 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
105 int obd_zombie_impexp_init(void);
106 void obd_zombie_impexp_stop(void);
107 void obd_zombie_impexp_cull(void);
108 void obd_zombie_barrier(void);
109 void obd_exports_barrier(struct obd_device *obd);
110 int kuc_len(int payload_len);
111 struct kuc_hdr *kuc_ptr(void *p);
112 int kuc_ispayload(void *p);
113 void *kuc_alloc(int payload_len, int transport, int type);
114 void kuc_free(void *p, int payload_len);
118 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
119 struct llog_rec_hdr *, void *);
121 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
122 const char *new_name);
123 int class_process_config(struct lustre_cfg *lcfg);
124 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
125 struct lustre_cfg *lcfg, void *data);
126 int class_attach(struct lustre_cfg *lcfg);
127 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
128 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
129 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
130 struct obd_device *class_incref(struct obd_device *obd,
131 const char *scope, const void *source);
132 void class_decref(struct obd_device *obd,
133 const char *scope, const void *source);
134 void dump_exports(struct obd_device *obd, int locks);
135 int class_config_llog_handler(const struct lu_env *env,
136 struct llog_handle *handle,
137 struct llog_rec_hdr *rec, void *data);
138 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
139 int class_add_uuid(const char *uuid, __u64 nid);
142 #if defined (CONFIG_PROC_FS)
143 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
145 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
147 memset(lvars, 0, sizeof(*lvars));
151 #define CFG_F_START 0x01 /* Set when we start updating from a log */
152 #define CFG_F_MARKER 0x02 /* We are within a maker */
153 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
154 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
155 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
157 /* Passed as data param to class_config_parse_llog */
158 struct config_llog_instance {
161 struct super_block *cfg_sb;
162 struct obd_uuid cfg_uuid;
163 llog_cb_t cfg_callback;
164 int cfg_last_idx; /* for partial llog processing */
167 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
168 char *name, struct config_llog_instance *cfg);
169 int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
170 char *name, struct config_llog_instance *cfg);
174 CONFIG_T_SPTLRPC = 1,
175 CONFIG_T_RECOVER = 2,
180 #define PARAMS_FILENAME "params"
181 #define LCTL_UPCALL "lctl"
183 /* list of active configuration logs */
184 struct config_llog_data {
185 struct ldlm_res_id cld_resid;
186 struct config_llog_instance cld_cfg;
187 struct list_head cld_list_chain;
188 atomic_t cld_refcount;
189 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
190 struct config_llog_data *cld_params; /* common parameters log */
191 struct config_llog_data *cld_recover;/* imperative recover log */
192 struct obd_export *cld_mgcexp;
193 struct mutex cld_lock;
195 unsigned int cld_stopping:1, /* we were told to stop
197 cld_lostlock:1; /* lock not requeued */
201 struct lustre_profile {
202 struct list_head lp_list;
208 struct lustre_profile *class_get_profile(const char *prof);
209 void class_del_profile(const char *prof);
210 void class_del_profiles(void);
212 #if LUSTRE_TRACKS_LOCK_EXP_REFS
214 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
215 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
216 extern void (*class_export_dump_hook)(struct obd_export *);
220 #define __class_export_add_lock_ref(exp, lock) do {} while (0)
221 #define __class_export_del_lock_ref(exp, lock) do {} while (0)
225 #define class_export_rpc_inc(exp) \
227 atomic_inc(&(exp)->exp_rpc_count); \
228 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
229 (exp), atomic_read(&(exp)->exp_rpc_count)); \
232 #define class_export_rpc_dec(exp) \
234 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
235 atomic_dec(&(exp)->exp_rpc_count); \
236 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
237 (exp), atomic_read(&(exp)->exp_rpc_count)); \
240 #define class_export_lock_get(exp, lock) \
242 atomic_inc(&(exp)->exp_locks_count); \
243 __class_export_add_lock_ref(exp, lock); \
244 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
245 (exp), atomic_read(&(exp)->exp_locks_count)); \
246 class_export_get(exp); \
249 #define class_export_lock_put(exp, lock) \
251 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
252 atomic_dec(&(exp)->exp_locks_count); \
253 __class_export_del_lock_ref(exp, lock); \
254 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
255 (exp), atomic_read(&(exp)->exp_locks_count)); \
256 class_export_put(exp); \
259 #define class_export_cb_get(exp) \
261 atomic_inc(&(exp)->exp_cb_count); \
262 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
263 (exp), atomic_read(&(exp)->exp_cb_count)); \
264 class_export_get(exp); \
267 #define class_export_cb_put(exp) \
269 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
270 atomic_dec(&(exp)->exp_cb_count); \
271 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
272 (exp), atomic_read(&(exp)->exp_cb_count)); \
273 class_export_put(exp); \
277 struct obd_export *class_export_get(struct obd_export *exp);
278 void class_export_put(struct obd_export *exp);
279 struct obd_export *class_new_export(struct obd_device *obddev,
280 struct obd_uuid *cluuid);
281 void class_unlink_export(struct obd_export *exp);
283 struct obd_import *class_import_get(struct obd_import *);
284 void class_import_put(struct obd_import *);
285 struct obd_import *class_new_import(struct obd_device *obd);
286 void class_destroy_import(struct obd_import *exp);
288 struct obd_type *class_search_type(const char *name);
289 struct obd_type *class_get_type(const char *name);
290 void class_put_type(struct obd_type *type);
291 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
292 struct obd_uuid *cluuid);
293 int class_disconnect(struct obd_export *exp);
294 void class_fail_export(struct obd_export *exp);
295 int class_connected_export(struct obd_export *exp);
296 void class_disconnect_exports(struct obd_device *obddev);
297 int class_manual_cleanup(struct obd_device *obd);
298 void class_disconnect_stale_exports(struct obd_device *,
299 int (*test_export)(struct obd_export *));
300 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
302 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
303 (obd->obd_force ? OBD_OPT_FORCE : 0) |
304 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
311 void obdo_from_la(struct obdo *dst, struct lu_attr *la, __u64 valid);
312 void la_from_obdo(struct lu_attr *la, struct obdo *dst, u32 valid);
313 void obdo_refresh_inode(struct inode *dst, struct obdo *src, u32 valid);
314 void obdo_to_inode(struct inode *dst, struct obdo *src, u32 valid);
316 void obdo_cpy_md(struct obdo *dst, struct obdo *src, u32 valid);
317 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
318 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
319 unsigned int ia_valid);
320 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, u32 valid);
321 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, u32 valid);
322 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
325 void obdo_cpu_to_le(struct obdo *dobdo, struct obdo *sobdo);
326 void obdo_le_to_cpu(struct obdo *dobdo, struct obdo *sobdo);
328 #define OBT(dev) (dev)->obd_type
329 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
330 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
331 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
333 /* Ensure obd_setup: used for cleanup which must be called
334 while obd is stopping */
335 #define OBD_CHECK_DEV(obd) \
338 CERROR("NULL device\n"); \
343 /* ensure obd_setup and !obd_stopping */
344 #define OBD_CHECK_DEV_ACTIVE(obd) \
346 OBD_CHECK_DEV(obd); \
347 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
348 CERROR("Device %d not setup\n", \
355 #if defined (CONFIG_PROC_FS)
356 #define OBD_COUNTER_OFFSET(op) \
357 ((offsetof(struct obd_ops, o_ ## op) - \
358 offsetof(struct obd_ops, o_iocontrol)) \
359 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
361 #define OBD_COUNTER_INCREMENT(obdx, op) \
362 if ((obdx)->obd_stats != NULL) { \
363 unsigned int coffset; \
364 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
365 OBD_COUNTER_OFFSET(op); \
366 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
367 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
370 #define EXP_COUNTER_INCREMENT(export, op) \
371 if ((export)->exp_obd->obd_stats != NULL) { \
372 unsigned int coffset; \
373 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
374 OBD_COUNTER_OFFSET(op); \
375 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
376 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
377 if ((export)->exp_nid_stats != NULL && \
378 (export)->exp_nid_stats->nid_stats != NULL) \
379 lprocfs_counter_incr( \
380 (export)->exp_nid_stats->nid_stats, coffset);\
383 #define MD_COUNTER_OFFSET(op) \
384 ((offsetof(struct md_ops, m_ ## op) - \
385 offsetof(struct md_ops, m_getstatus)) \
386 / sizeof(((struct md_ops *)(0))->m_getstatus))
388 #define MD_COUNTER_INCREMENT(obdx, op) \
389 if ((obd)->md_stats != NULL) { \
390 unsigned int coffset; \
391 coffset = (unsigned int)((obdx)->md_cntr_base) + \
392 MD_COUNTER_OFFSET(op); \
393 LASSERT(coffset < (obdx)->md_stats->ls_num); \
394 lprocfs_counter_incr((obdx)->md_stats, coffset); \
397 #define EXP_MD_COUNTER_INCREMENT(export, op) \
398 if ((export)->exp_obd->obd_stats != NULL) { \
399 unsigned int coffset; \
400 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
401 MD_COUNTER_OFFSET(op); \
402 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
403 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
404 if ((export)->exp_md_stats != NULL) \
405 lprocfs_counter_incr( \
406 (export)->exp_md_stats, coffset); \
410 #define OBD_COUNTER_OFFSET(op)
411 #define OBD_COUNTER_INCREMENT(obd, op)
412 #define EXP_COUNTER_INCREMENT(exp, op)
413 #define MD_COUNTER_INCREMENT(obd, op)
414 #define EXP_MD_COUNTER_INCREMENT(exp, op)
417 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat *tmp)
419 /* Always add in ldlm_stats */
420 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
421 ,LPROCFS_STATS_FLAG_NOPERCPU);
422 if (tmp->nid_ldlm_stats == NULL)
425 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
427 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
428 tmp->nid_ldlm_stats);
431 #define OBD_CHECK_MD_OP(obd, op, err) \
433 if (!OBT(obd) || !MDP((obd), op)) { \
435 CERROR("md_" #op ": dev %s/%d no operation\n", \
436 obd->obd_name, obd->obd_minor); \
441 #define EXP_CHECK_MD_OP(exp, op) \
443 if ((exp) == NULL) { \
444 CERROR("obd_" #op ": NULL export\n"); \
447 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
448 CERROR("obd_" #op ": cleaned up obd\n"); \
449 return -EOPNOTSUPP; \
451 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
452 CERROR("obd_" #op ": dev %s/%d no operation\n", \
453 (exp)->exp_obd->obd_name, \
454 (exp)->exp_obd->obd_minor); \
455 return -EOPNOTSUPP; \
460 #define OBD_CHECK_DT_OP(obd, op, err) \
462 if (!OBT(obd) || !OBP((obd), op)) { \
464 CERROR("obd_" #op ": dev %d no operation\n", \
470 #define EXP_CHECK_DT_OP(exp, op) \
472 if ((exp) == NULL) { \
473 CERROR("obd_" #op ": NULL export\n"); \
476 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
477 CERROR("obd_" #op ": cleaned up obd\n"); \
478 return -EOPNOTSUPP; \
480 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
481 CERROR("obd_" #op ": dev %d no operation\n", \
482 (exp)->exp_obd->obd_minor); \
483 return -EOPNOTSUPP; \
487 #define CTXT_CHECK_OP(ctxt, op, err) \
489 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
491 CERROR("lop_" #op ": dev %d no operation\n", \
492 ctxt->loc_obd->obd_minor); \
497 static inline int class_devno_max(void)
499 return MAX_OBD_DEVICES;
502 static inline int obd_get_info(const struct lu_env *env,
503 struct obd_export *exp, __u32 keylen,
504 void *key, __u32 *vallen, void *val,
505 struct lov_stripe_md *lsm)
509 EXP_CHECK_DT_OP(exp, get_info);
510 EXP_COUNTER_INCREMENT(exp, get_info);
512 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val,
517 static inline int obd_set_info_async(const struct lu_env *env,
518 struct obd_export *exp, u32 keylen,
519 void *key, u32 vallen, void *val,
520 struct ptlrpc_request_set *set)
524 EXP_CHECK_DT_OP(exp, set_info_async);
525 EXP_COUNTER_INCREMENT(exp, set_info_async);
527 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
533 * obd-lu integration.
535 * Functionality is being moved into new lu_device-based layering, but some
536 * pieces of configuration process are still based on obd devices.
538 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
539 * subsume ->o_setup() methods of obd devices they replace. The same for
540 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
541 * result, obd_setup() and obd_process_config() branch and call one XOR
544 * Yet neither lu_device_type_operations::ldto_device_fini() nor
545 * lu_device_type_operations::ldto_device_free() fully implement the
546 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
547 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
550 #define DECLARE_LU_VARS(ldt, d) \
551 struct lu_device_type *ldt; \
554 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
557 DECLARE_LU_VARS(ldt, d);
559 ldt = obd->obd_type->typ_lu;
561 struct lu_context session_ctx;
563 lu_context_init(&session_ctx, LCT_SESSION);
564 session_ctx.lc_thread = NULL;
565 lu_context_enter(&session_ctx);
567 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
569 env.le_ses = &session_ctx;
570 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
579 lu_context_exit(&session_ctx);
580 lu_context_fini(&session_ctx);
583 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
584 OBD_COUNTER_INCREMENT(obd, setup);
585 rc = OBP(obd, setup)(obd, cfg);
590 static inline int obd_precleanup(struct obd_device *obd,
591 enum obd_cleanup_stage cleanup_stage)
594 DECLARE_LU_VARS(ldt, d);
597 ldt = obd->obd_type->typ_lu;
599 if (ldt != NULL && d != NULL) {
600 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
603 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
605 ldt->ldt_ops->ldto_device_fini(&env, d);
610 OBD_CHECK_DT_OP(obd, precleanup, 0);
611 OBD_COUNTER_INCREMENT(obd, precleanup);
613 rc = OBP(obd, precleanup)(obd, cleanup_stage);
617 static inline int obd_cleanup(struct obd_device *obd)
620 DECLARE_LU_VARS(ldt, d);
624 ldt = obd->obd_type->typ_lu;
626 if (ldt != NULL && d != NULL) {
629 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
631 ldt->ldt_ops->ldto_device_free(&env, d);
633 obd->obd_lu_dev = NULL;
636 OBD_CHECK_DT_OP(obd, cleanup, 0);
637 OBD_COUNTER_INCREMENT(obd, cleanup);
639 rc = OBP(obd, cleanup)(obd);
643 static inline void obd_cleanup_client_import(struct obd_device *obd)
645 /* If we set up but never connected, the
646 client import will not have been cleaned. */
647 down_write(&obd->u.cli.cl_sem);
648 if (obd->u.cli.cl_import) {
649 struct obd_import *imp;
650 imp = obd->u.cli.cl_import;
651 CDEBUG(D_CONFIG, "%s: client import never connected\n",
653 ptlrpc_invalidate_import(imp);
654 if (imp->imp_rq_pool) {
655 ptlrpc_free_rq_pool(imp->imp_rq_pool);
656 imp->imp_rq_pool = NULL;
658 client_destroy_import(imp);
659 obd->u.cli.cl_import = NULL;
661 up_write(&obd->u.cli.cl_sem);
665 obd_process_config(struct obd_device *obd, int datalen, void *data)
668 DECLARE_LU_VARS(ldt, d);
672 obd->obd_process_conf = 1;
673 ldt = obd->obd_type->typ_lu;
675 if (ldt != NULL && d != NULL) {
678 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
680 rc = d->ld_ops->ldo_process_config(&env, d, data);
684 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
685 rc = OBP(obd, process_config)(obd, datalen, data);
687 OBD_COUNTER_INCREMENT(obd, process_config);
688 obd->obd_process_conf = 0;
693 /* Pack an in-memory MD struct for storage on disk.
694 * Returns +ve size of packed MD (0 for free), or -ve error.
696 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
697 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
698 * If @*disk_tgt == NULL, it will be allocated
700 static inline int obd_packmd(struct obd_export *exp,
701 struct lov_mds_md **disk_tgt,
702 struct lov_stripe_md *mem_src)
706 EXP_CHECK_DT_OP(exp, packmd);
707 EXP_COUNTER_INCREMENT(exp, packmd);
709 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
713 static inline int obd_size_diskmd(struct obd_export *exp,
714 struct lov_stripe_md *mem_src)
716 return obd_packmd(exp, NULL, mem_src);
719 static inline int obd_free_diskmd(struct obd_export *exp,
720 struct lov_mds_md **disk_tgt)
725 * LU-2590, for caller's convenience, *disk_tgt could be host
726 * endianness, it needs swab to LE if necessary, while just
727 * lov_mds_md header needs it for figuring out how much memory
730 if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
731 (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
732 ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
733 lustre_swab_lov_mds_md(*disk_tgt);
734 return obd_packmd(exp, disk_tgt, NULL);
737 /* Unpack an MD struct from disk to in-memory format.
738 * Returns +ve size of unpacked MD (0 for free), or -ve error.
740 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
741 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
742 * If @*mem_tgt == NULL, it will be allocated
744 static inline int obd_unpackmd(struct obd_export *exp,
745 struct lov_stripe_md **mem_tgt,
746 struct lov_mds_md *disk_src,
751 EXP_CHECK_DT_OP(exp, unpackmd);
752 EXP_COUNTER_INCREMENT(exp, unpackmd);
754 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
758 /* helper functions */
759 static inline int obd_alloc_memmd(struct obd_export *exp,
760 struct lov_stripe_md **mem_tgt)
763 LASSERT(*mem_tgt == NULL);
764 return obd_unpackmd(exp, mem_tgt, NULL, 0);
767 static inline int obd_free_memmd(struct obd_export *exp,
768 struct lov_stripe_md **mem_tgt)
774 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
779 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
780 struct obdo *obdo, struct lov_stripe_md **ea,
781 struct obd_trans_info *oti)
785 EXP_CHECK_DT_OP(exp, create);
786 EXP_COUNTER_INCREMENT(exp, create);
788 rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti);
792 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
793 struct obdo *obdo, struct lov_stripe_md *ea,
794 struct obd_trans_info *oti,
795 struct obd_export *md_exp, void *capa)
799 EXP_CHECK_DT_OP(exp, destroy);
800 EXP_COUNTER_INCREMENT(exp, destroy);
802 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp, capa);
806 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
807 struct obd_info *oinfo)
811 EXP_CHECK_DT_OP(exp, getattr);
812 EXP_COUNTER_INCREMENT(exp, getattr);
814 rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo);
818 static inline int obd_getattr_async(struct obd_export *exp,
819 struct obd_info *oinfo,
820 struct ptlrpc_request_set *set)
824 EXP_CHECK_DT_OP(exp, getattr_async);
825 EXP_COUNTER_INCREMENT(exp, getattr_async);
827 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
831 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
832 struct obd_info *oinfo,
833 struct obd_trans_info *oti)
837 EXP_CHECK_DT_OP(exp, setattr);
838 EXP_COUNTER_INCREMENT(exp, setattr);
840 rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
844 /* This performs all the requests set init/wait/destroy actions. */
845 static inline int obd_setattr_rqset(struct obd_export *exp,
846 struct obd_info *oinfo,
847 struct obd_trans_info *oti)
849 struct ptlrpc_request_set *set = NULL;
852 EXP_CHECK_DT_OP(exp, setattr_async);
853 EXP_COUNTER_INCREMENT(exp, setattr_async);
855 set = ptlrpc_prep_set();
859 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
861 rc = ptlrpc_set_wait(set);
862 ptlrpc_set_destroy(set);
866 /* This adds all the requests into @set if @set != NULL, otherwise
867 all requests are sent asynchronously without waiting for response. */
868 static inline int obd_setattr_async(struct obd_export *exp,
869 struct obd_info *oinfo,
870 struct obd_trans_info *oti,
871 struct ptlrpc_request_set *set)
875 EXP_CHECK_DT_OP(exp, setattr_async);
876 EXP_COUNTER_INCREMENT(exp, setattr_async);
878 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
882 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
885 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;
901 OBD_CHECK_DEV_ACTIVE(obd);
902 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
903 OBD_COUNTER_INCREMENT(obd, del_conn);
905 rc = OBP(obd, del_conn)(imp, uuid);
909 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
911 struct obd_uuid *uuid;
913 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
914 EXP_COUNTER_INCREMENT(exp, get_uuid);
916 uuid = OBP(exp->exp_obd, get_uuid)(exp);
920 /** Create a new /a exp on device /a obd for the uuid /a cluuid
921 * @param exp New export handle
922 * @param d Connect data, supported flags are set, flags also understood
923 * by obd are returned.
925 static inline int obd_connect(const struct lu_env *env,
926 struct obd_export **exp, struct obd_device *obd,
927 struct obd_uuid *cluuid,
928 struct obd_connect_data *data,
932 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
935 OBD_CHECK_DEV_ACTIVE(obd);
936 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
937 OBD_COUNTER_INCREMENT(obd, connect);
939 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
940 /* check that only subset is granted */
941 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
942 data->ocd_connect_flags));
946 static inline int obd_reconnect(const struct lu_env *env,
947 struct obd_export *exp,
948 struct obd_device *obd,
949 struct obd_uuid *cluuid,
950 struct obd_connect_data *d,
954 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
957 OBD_CHECK_DEV_ACTIVE(obd);
958 OBD_CHECK_DT_OP(obd, reconnect, 0);
959 OBD_COUNTER_INCREMENT(obd, reconnect);
961 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
962 /* check that only subset is granted */
963 LASSERT(ergo(d != NULL,
964 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
968 static inline int obd_disconnect(struct obd_export *exp)
972 EXP_CHECK_DT_OP(exp, disconnect);
973 EXP_COUNTER_INCREMENT(exp, disconnect);
975 rc = OBP(exp->exp_obd, disconnect)(exp);
979 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
980 enum lu_cli_type type)
984 OBD_CHECK_DT_OP(obd, fid_init, 0);
985 OBD_COUNTER_INCREMENT(obd, fid_init);
987 rc = OBP(obd, fid_init)(obd, exp, type);
991 static inline int obd_fid_fini(struct obd_device *obd)
995 OBD_CHECK_DT_OP(obd, fid_fini, 0);
996 OBD_COUNTER_INCREMENT(obd, fid_fini);
998 rc = OBP(obd, fid_fini)(obd);
1002 static inline int obd_fid_alloc(struct obd_export *exp,
1004 struct md_op_data *op_data)
1008 EXP_CHECK_DT_OP(exp, fid_alloc);
1009 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1011 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1015 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1019 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1020 OBD_COUNTER_INCREMENT(obd, pool_new);
1022 rc = OBP(obd, pool_new)(obd, poolname);
1026 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1030 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1031 OBD_COUNTER_INCREMENT(obd, pool_del);
1033 rc = OBP(obd, pool_del)(obd, poolname);
1037 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1041 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1042 OBD_COUNTER_INCREMENT(obd, pool_add);
1044 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1048 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1052 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1053 OBD_COUNTER_INCREMENT(obd, pool_rem);
1055 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1059 static inline void obd_getref(struct obd_device *obd)
1061 if (OBT(obd) && OBP(obd, getref)) {
1062 OBD_COUNTER_INCREMENT(obd, getref);
1063 OBP(obd, getref)(obd);
1067 static inline void obd_putref(struct obd_device *obd)
1069 if (OBT(obd) && OBP(obd, putref)) {
1070 OBD_COUNTER_INCREMENT(obd, putref);
1071 OBP(obd, putref)(obd);
1075 static inline int obd_init_export(struct obd_export *exp)
1079 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1080 OBP((exp)->exp_obd, init_export))
1081 rc = OBP(exp->exp_obd, init_export)(exp);
1085 static inline int obd_destroy_export(struct obd_export *exp)
1087 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1088 OBP((exp)->exp_obd, destroy_export))
1089 OBP(exp->exp_obd, destroy_export)(exp);
1093 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1094 * If the cache is older than @max_age we will get a new value from the
1095 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1096 static inline int obd_statfs_async(struct obd_export *exp,
1097 struct obd_info *oinfo,
1099 struct ptlrpc_request_set *rqset)
1102 struct obd_device *obd;
1104 if (exp == NULL || exp->exp_obd == NULL)
1108 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1109 OBD_COUNTER_INCREMENT(obd, statfs);
1111 CDEBUG(D_SUPER, "%s: osfs %p age %llu, max_age %llu\n",
1112 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1113 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1114 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1117 "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1118 obd->obd_name, &obd->obd_osfs,
1119 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1120 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1121 spin_lock(&obd->obd_osfs_lock);
1122 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1123 spin_unlock(&obd->obd_osfs_lock);
1124 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1125 if (oinfo->oi_cb_up)
1126 oinfo->oi_cb_up(oinfo, 0);
1131 static inline int obd_statfs_rqset(struct obd_export *exp,
1132 struct obd_statfs *osfs, __u64 max_age,
1135 struct ptlrpc_request_set *set = NULL;
1136 struct obd_info oinfo = { { { 0 } } };
1139 set = ptlrpc_prep_set();
1143 oinfo.oi_osfs = osfs;
1144 oinfo.oi_flags = flags;
1145 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1147 rc = ptlrpc_set_wait(set);
1148 ptlrpc_set_destroy(set);
1152 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1153 * If the cache is older than @max_age we will get a new value from the
1154 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1155 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1156 struct obd_statfs *osfs, __u64 max_age,
1160 struct obd_device *obd = exp->exp_obd;
1165 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1166 OBD_COUNTER_INCREMENT(obd, statfs);
1168 CDEBUG(D_SUPER, "osfs %llu, max_age %llu\n",
1169 obd->obd_osfs_age, max_age);
1170 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1171 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1173 spin_lock(&obd->obd_osfs_lock);
1174 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1175 obd->obd_osfs_age = cfs_time_current_64();
1176 spin_unlock(&obd->obd_osfs_lock);
1179 CDEBUG(D_SUPER, "%s: use %p cache blocks %llu/%llu objects %llu/%llu\n",
1180 obd->obd_name, &obd->obd_osfs,
1181 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1182 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1183 spin_lock(&obd->obd_osfs_lock);
1184 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1185 spin_unlock(&obd->obd_osfs_lock);
1190 static inline int obd_preprw(const struct lu_env *env, int cmd,
1191 struct obd_export *exp, struct obdo *oa,
1192 int objcount, struct obd_ioobj *obj,
1193 struct niobuf_remote *remote, int *pages,
1194 struct niobuf_local *local,
1195 struct obd_trans_info *oti,
1196 struct lustre_capa *capa)
1200 EXP_CHECK_DT_OP(exp, preprw);
1201 EXP_COUNTER_INCREMENT(exp, preprw);
1203 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1204 pages, local, oti, capa);
1208 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1209 struct obd_export *exp, struct obdo *oa,
1210 int objcount, struct obd_ioobj *obj,
1211 struct niobuf_remote *rnb, int pages,
1212 struct niobuf_local *local,
1213 struct obd_trans_info *oti, int rc)
1215 EXP_CHECK_DT_OP(exp, commitrw);
1216 EXP_COUNTER_INCREMENT(exp, commitrw);
1218 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1219 rnb, pages, local, oti, rc);
1223 static inline int obd_adjust_kms(struct obd_export *exp,
1224 struct lov_stripe_md *lsm, u64 size,
1229 EXP_CHECK_DT_OP(exp, adjust_kms);
1230 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1232 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1236 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1237 int len, void *karg, void *uarg)
1241 EXP_CHECK_DT_OP(exp, iocontrol);
1242 EXP_COUNTER_INCREMENT(exp, iocontrol);
1244 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1248 static inline int obd_find_cbdata(struct obd_export *exp,
1249 struct lov_stripe_md *lsm,
1250 ldlm_iterator_t it, void *data)
1254 EXP_CHECK_DT_OP(exp, find_cbdata);
1255 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1257 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1261 static inline void obd_import_event(struct obd_device *obd,
1262 struct obd_import *imp,
1263 enum obd_import_event event)
1266 CERROR("NULL device\n");
1269 if (obd->obd_set_up && OBP(obd, import_event)) {
1270 OBD_COUNTER_INCREMENT(obd, import_event);
1271 OBP(obd, import_event)(obd, imp, event);
1275 static inline int obd_notify(struct obd_device *obd,
1276 struct obd_device *watched,
1277 enum obd_notify_event ev,
1284 /* the check for async_recov is a complete hack - I'm hereby
1285 overloading the meaning to also mean "this was called from
1286 mds_postsetup". I know that my mds is able to handle notifies
1287 by this point, and it needs to get them to execute mds_postrecov. */
1288 if (!obd->obd_set_up && !obd->obd_async_recov) {
1289 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1293 if (!OBP(obd, notify)) {
1294 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1298 OBD_COUNTER_INCREMENT(obd, notify);
1299 rc = OBP(obd, notify)(obd, watched, ev, data);
1303 static inline int obd_notify_observer(struct obd_device *observer,
1304 struct obd_device *observed,
1305 enum obd_notify_event ev,
1311 struct obd_notify_upcall *onu;
1313 if (observer->obd_observer)
1314 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1318 * Also, call non-obd listener, if any
1320 onu = &observer->obd_upcall;
1321 if (onu->onu_upcall != NULL)
1322 rc2 = onu->onu_upcall(observer, observed, ev,
1323 onu->onu_owner, NULL);
1327 return rc1 ? rc1 : rc2;
1330 static inline int obd_quotacheck(struct obd_export *exp,
1331 struct obd_quotactl *oqctl)
1335 EXP_CHECK_DT_OP(exp, quotacheck);
1336 EXP_COUNTER_INCREMENT(exp, quotacheck);
1338 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1342 static inline int obd_quotactl(struct obd_export *exp,
1343 struct obd_quotactl *oqctl)
1347 EXP_CHECK_DT_OP(exp, quotactl);
1348 EXP_COUNTER_INCREMENT(exp, quotactl);
1350 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1354 static inline int obd_health_check(const struct lu_env *env,
1355 struct obd_device *obd)
1357 /* returns: 0 on healthy
1358 * >0 on unhealthy + reason code/flag
1359 * however the only supported reason == 1 right now
1360 * We'll need to define some better reasons
1361 * or flags in the future.
1366 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1367 if (obd == NULL || !OBT(obd)) {
1368 CERROR("cleaned up obd\n");
1371 if (!obd->obd_set_up || obd->obd_stopping)
1373 if (!OBP(obd, health_check))
1376 rc = OBP(obd, health_check)(env, obd);
1380 static inline int obd_register_observer(struct obd_device *obd,
1381 struct obd_device *observer)
1384 down_write(&obd->obd_observer_link_sem);
1385 if (obd->obd_observer && observer) {
1386 up_write(&obd->obd_observer_link_sem);
1389 obd->obd_observer = observer;
1390 up_write(&obd->obd_observer_link_sem);
1395 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1396 obd_page_removal_cb_t cb,
1397 obd_pin_extent_cb pin_cb)
1401 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1402 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1404 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1408 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1409 obd_page_removal_cb_t cb)
1413 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1414 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1416 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1420 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1421 obd_lock_cancel_cb cb)
1425 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1426 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1428 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1432 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1433 obd_lock_cancel_cb cb)
1437 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1438 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1440 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1445 /* metadata helpers */
1446 static inline int md_getstatus(struct obd_export *exp,
1447 struct lu_fid *fid, struct obd_capa **pc)
1451 EXP_CHECK_MD_OP(exp, getstatus);
1452 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1453 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1457 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1458 struct ptlrpc_request **request)
1462 EXP_CHECK_MD_OP(exp, getattr);
1463 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1464 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1468 static inline int md_null_inode(struct obd_export *exp,
1469 const struct lu_fid *fid)
1473 EXP_CHECK_MD_OP(exp, null_inode);
1474 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1475 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1479 static inline int md_find_cbdata(struct obd_export *exp,
1480 const struct lu_fid *fid,
1481 ldlm_iterator_t it, void *data)
1485 EXP_CHECK_MD_OP(exp, find_cbdata);
1486 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1487 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1491 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1492 struct md_open_data *mod,
1493 struct ptlrpc_request **request)
1497 EXP_CHECK_MD_OP(exp, close);
1498 EXP_MD_COUNTER_INCREMENT(exp, close);
1499 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1503 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1504 const void *data, int datalen, int mode, __u32 uid,
1505 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1506 struct ptlrpc_request **request)
1510 EXP_CHECK_MD_OP(exp, create);
1511 EXP_MD_COUNTER_INCREMENT(exp, create);
1512 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1513 uid, gid, cap_effective, rdev, request);
1517 static inline int md_done_writing(struct obd_export *exp,
1518 struct md_op_data *op_data,
1519 struct md_open_data *mod)
1523 EXP_CHECK_MD_OP(exp, done_writing);
1524 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1525 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1529 static inline int md_enqueue(struct obd_export *exp,
1530 struct ldlm_enqueue_info *einfo,
1531 struct lookup_intent *it,
1532 struct md_op_data *op_data,
1533 struct lustre_handle *lockh,
1534 void *lmm, int lmmsize,
1535 struct ptlrpc_request **req,
1536 __u64 extra_lock_flags)
1540 EXP_CHECK_MD_OP(exp, enqueue);
1541 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1542 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1543 lmm, lmmsize, req, extra_lock_flags);
1547 static inline int md_getattr_name(struct obd_export *exp,
1548 struct md_op_data *op_data,
1549 struct ptlrpc_request **request)
1553 EXP_CHECK_MD_OP(exp, getattr_name);
1554 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1555 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1559 static inline int md_intent_lock(struct obd_export *exp,
1560 struct md_op_data *op_data, void *lmm,
1561 int lmmsize, struct lookup_intent *it,
1562 int lookup_flags, struct ptlrpc_request **reqp,
1563 ldlm_blocking_callback cb_blocking,
1564 __u64 extra_lock_flags)
1568 EXP_CHECK_MD_OP(exp, intent_lock);
1569 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1570 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1571 it, lookup_flags, reqp, cb_blocking,
1576 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1577 struct ptlrpc_request **request)
1581 EXP_CHECK_MD_OP(exp, link);
1582 EXP_MD_COUNTER_INCREMENT(exp, link);
1583 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1587 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1588 const char *old, int oldlen, const char *new,
1589 int newlen, struct ptlrpc_request **request)
1593 EXP_CHECK_MD_OP(exp, rename);
1594 EXP_MD_COUNTER_INCREMENT(exp, rename);
1595 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1600 static inline int md_is_subdir(struct obd_export *exp,
1601 const struct lu_fid *pfid,
1602 const struct lu_fid *cfid,
1603 struct ptlrpc_request **request)
1607 EXP_CHECK_MD_OP(exp, is_subdir);
1608 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1609 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1613 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1614 void *ea, int ealen, void *ea2, int ea2len,
1615 struct ptlrpc_request **request,
1616 struct md_open_data **mod)
1620 EXP_CHECK_MD_OP(exp, setattr);
1621 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1622 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1623 ea2, ea2len, request, mod);
1627 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1628 struct obd_capa *oc, struct ptlrpc_request **request)
1632 EXP_CHECK_MD_OP(exp, sync);
1633 EXP_MD_COUNTER_INCREMENT(exp, sync);
1634 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1638 static inline int md_readpage(struct obd_export *exp, struct md_op_data *opdata,
1639 struct page **pages,
1640 struct ptlrpc_request **request)
1644 EXP_CHECK_MD_OP(exp, readpage);
1645 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1646 rc = MDP(exp->exp_obd, readpage)(exp, opdata, pages, request);
1650 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1651 struct ptlrpc_request **request)
1655 EXP_CHECK_MD_OP(exp, unlink);
1656 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1657 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1661 static inline int md_get_lustre_md(struct obd_export *exp,
1662 struct ptlrpc_request *req,
1663 struct obd_export *dt_exp,
1664 struct obd_export *md_exp,
1665 struct lustre_md *md)
1667 EXP_CHECK_MD_OP(exp, get_lustre_md);
1668 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1669 return MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md);
1672 static inline int md_free_lustre_md(struct obd_export *exp,
1673 struct lustre_md *md)
1675 EXP_CHECK_MD_OP(exp, free_lustre_md);
1676 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1677 return MDP(exp->exp_obd, free_lustre_md)(exp, md);
1680 static inline int md_setxattr(struct obd_export *exp,
1681 const struct lu_fid *fid, struct obd_capa *oc,
1682 u64 valid, const char *name,
1683 const char *input, int input_size,
1684 int output_size, int flags, __u32 suppgid,
1685 struct ptlrpc_request **request)
1687 EXP_CHECK_MD_OP(exp, setxattr);
1688 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1689 return MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1690 input_size, output_size, flags,
1694 static inline int md_getxattr(struct obd_export *exp,
1695 const struct lu_fid *fid, struct obd_capa *oc,
1696 u64 valid, const char *name,
1697 const char *input, int input_size,
1698 int output_size, int flags,
1699 struct ptlrpc_request **request)
1701 EXP_CHECK_MD_OP(exp, getxattr);
1702 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1703 return MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1704 input_size, output_size, flags,
1708 static inline int md_set_open_replay_data(struct obd_export *exp,
1709 struct obd_client_handle *och,
1710 struct lookup_intent *it)
1712 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1713 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
1714 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, it);
1717 static inline int md_clear_open_replay_data(struct obd_export *exp,
1718 struct obd_client_handle *och)
1720 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1721 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
1722 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1725 static inline int md_set_lock_data(struct obd_export *exp,
1726 __u64 *lockh, void *data, __u64 *bits)
1728 EXP_CHECK_MD_OP(exp, set_lock_data);
1729 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
1730 return MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits);
1733 static inline int md_cancel_unused(struct obd_export *exp,
1734 const struct lu_fid *fid,
1735 ldlm_policy_data_t *policy,
1737 ldlm_cancel_flags_t flags,
1742 EXP_CHECK_MD_OP(exp, cancel_unused);
1743 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
1745 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
1750 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
1751 const struct lu_fid *fid,
1753 ldlm_policy_data_t *policy,
1755 struct lustre_handle *lockh)
1757 EXP_CHECK_MD_OP(exp, lock_match);
1758 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
1759 return MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1760 policy, mode, lockh);
1763 static inline int md_init_ea_size(struct obd_export *exp, int easize,
1764 int def_asize, int cookiesize,
1767 EXP_CHECK_MD_OP(exp, init_ea_size);
1768 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
1769 return MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
1770 cookiesize, def_cookiesize);
1773 static inline int md_get_remote_perm(struct obd_export *exp,
1774 const struct lu_fid *fid,
1775 struct obd_capa *oc, __u32 suppgid,
1776 struct ptlrpc_request **request)
1778 EXP_CHECK_MD_OP(exp, get_remote_perm);
1779 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
1780 return MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
1784 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
1789 EXP_CHECK_MD_OP(exp, renew_capa);
1790 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
1791 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
1795 static inline int md_unpack_capa(struct obd_export *exp,
1796 struct ptlrpc_request *req,
1797 const struct req_msg_field *field,
1798 struct obd_capa **oc)
1802 EXP_CHECK_MD_OP(exp, unpack_capa);
1803 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
1804 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
1808 static inline int md_intent_getattr_async(struct obd_export *exp,
1809 struct md_enqueue_info *minfo,
1810 struct ldlm_enqueue_info *einfo)
1814 EXP_CHECK_MD_OP(exp, intent_getattr_async);
1815 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
1816 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
1820 static inline int md_revalidate_lock(struct obd_export *exp,
1821 struct lookup_intent *it,
1822 struct lu_fid *fid, __u64 *bits)
1826 EXP_CHECK_MD_OP(exp, revalidate_lock);
1827 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
1828 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
1833 /* OBD Metadata Support */
1835 extern int obd_init_caches(void);
1836 extern void obd_cleanup_caches(void);
1838 /* support routines */
1839 extern struct kmem_cache *obdo_cachep;
1841 #define OBDO_ALLOC(ptr) \
1843 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, GFP_NOFS); \
1846 #define OBDO_FREE(ptr) \
1848 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
1852 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
1854 /* something here */
1857 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
1859 /* something here */
1862 typedef int (*register_lwp_cb)(void *data);
1864 struct lwp_register_item {
1865 struct obd_export **lri_exp;
1866 register_lwp_cb lri_cb_func;
1868 struct list_head lri_list;
1869 char lri_name[MTI_NAME_MAXLEN];
1872 /* I'm as embarrassed about this as you are.
1874 * <shaver> // XXX do not look into _superhack with remaining eye
1875 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1876 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1881 extern void obd_sysctl_init (void);
1882 extern void obd_sysctl_clean (void);
1885 typedef __u8 class_uuid_t[16];
1886 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1889 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1890 int class_add_uuid(const char *uuid, __u64 nid);
1891 int class_del_uuid (const char *uuid);
1892 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
1893 void class_init_uuidlist(void);
1894 void class_exit_uuidlist(void);
1897 extern char obd_jobid_node[];
1900 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
1902 #endif /* __LINUX_OBD_CLASS_H */