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 #include <linux/obd_class.h>
50 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
51 * and resends for avoid deadlocks */
52 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
54 #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd
55 * instead of a specific set. This
56 * means that we cannot rely on the set
57 * interpret routine to be called.
58 * lov_statfs_fini() must thus be called
59 * by the request interpret routine */
60 #define OBD_STATFS_FOR_MDT0 0x0008 /* The statfs is only for retrieving
61 * information from MDT0. */
62 #define OBD_FL_PUNCH 0x00000001 /* To indicate it is punch operation */
64 /* OBD Device Declarations */
65 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
66 extern rwlock_t obd_dev_lock;
68 /* OBD Operations Declarations */
69 extern struct obd_device *class_conn2obd(struct lustre_handle *);
70 extern struct obd_device *class_exp2obd(struct obd_export *);
71 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
72 extern int lustre_get_jobid(char *jobid);
74 struct lu_device_type;
77 struct obd_export *class_conn2export(struct lustre_handle *);
78 int class_register_type(struct obd_ops *, struct md_ops *,
79 struct lprocfs_vars *, const char *nm,
80 struct lu_device_type *ldt);
81 int class_unregister_type(const char *nm);
83 struct obd_device *class_newdev(const char *type_name, const char *name);
84 void class_release_dev(struct obd_device *obd);
86 int class_name2dev(const char *name);
87 struct obd_device *class_name2obd(const char *name);
88 int class_uuid2dev(struct obd_uuid *uuid);
89 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
90 void class_obd_list(void);
91 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
92 const char * typ_name,
93 struct obd_uuid *grp_uuid);
94 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
96 struct obd_device * class_num2obd(int num);
97 int get_devices_count(void);
99 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
101 char *obd_export_nid2str(struct obd_export *exp);
103 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
104 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
105 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
107 int obd_zombie_impexp_init(void);
108 void obd_zombie_impexp_stop(void);
109 void obd_zombie_impexp_cull(void);
110 void obd_zombie_barrier(void);
111 void obd_exports_barrier(struct obd_device *obd);
112 int kuc_len(int payload_len);
113 struct kuc_hdr * kuc_ptr(void *p);
114 int kuc_ispayload(void *p);
115 void *kuc_alloc(int payload_len, int transport, int type);
116 void kuc_free(void *p, int payload_len);
120 typedef int (*llog_cb_t)(const struct lu_env *, struct llog_handle *,
121 struct llog_rec_hdr *, void *);
123 struct lustre_cfg *lustre_cfg_rename(struct lustre_cfg *cfg,
124 const char *new_name);
125 int class_process_config(struct lustre_cfg *lcfg);
126 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
127 struct lustre_cfg *lcfg, void *data);
128 int class_attach(struct lustre_cfg *lcfg);
129 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
130 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
131 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
132 struct obd_device *class_incref(struct obd_device *obd,
133 const char *scope, const void *source);
134 void class_decref(struct obd_device *obd,
135 const char *scope, const void *source);
136 void dump_exports(struct obd_device *obd, int locks);
137 int class_config_llog_handler(const struct lu_env *env,
138 struct llog_handle *handle,
139 struct llog_rec_hdr *rec, void *data);
140 int class_add_conn(struct obd_device *obd, struct lustre_cfg *lcfg);
141 int class_add_uuid(const char *uuid, __u64 nid);
145 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
147 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
149 memset(lvars, 0, sizeof(*lvars));
153 #define CFG_F_START 0x01 /* Set when we start updating from a log */
154 #define CFG_F_MARKER 0x02 /* We are within a maker */
155 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
156 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
157 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
159 /* Passed as data param to class_config_parse_llog */
160 struct config_llog_instance {
163 struct super_block *cfg_sb;
164 struct obd_uuid cfg_uuid;
165 llog_cb_t cfg_callback;
166 int cfg_last_idx; /* for partial llog processing */
169 int class_config_parse_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
170 char *name, struct config_llog_instance *cfg);
171 int class_config_dump_llog(const struct lu_env *env, struct llog_ctxt *ctxt,
172 char *name, struct config_llog_instance *cfg);
176 CONFIG_T_SPTLRPC = 1,
177 CONFIG_T_RECOVER = 2,
181 /* list of active configuration logs */
182 struct config_llog_data {
183 struct ldlm_res_id cld_resid;
184 struct config_llog_instance cld_cfg;
185 struct list_head cld_list_chain;
186 atomic_t cld_refcount;
187 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
188 struct config_llog_data *cld_recover; /* imperative recover log */
189 struct obd_export *cld_mgcexp;
190 struct mutex cld_lock;
192 unsigned int cld_stopping:1, /* we were told to stop
194 cld_lostlock:1; /* lock not requeued */
198 struct lustre_profile {
199 struct list_head lp_list;
205 struct lustre_profile *class_get_profile(const char * prof);
206 void class_del_profile(const char *prof);
207 void class_del_profiles(void);
209 #if LUSTRE_TRACKS_LOCK_EXP_REFS
211 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
212 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
213 extern void (*class_export_dump_hook)(struct obd_export *);
217 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
218 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
222 #define class_export_rpc_inc(exp) \
224 atomic_inc(&(exp)->exp_rpc_count); \
225 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
226 (exp), atomic_read(&(exp)->exp_rpc_count)); \
229 #define class_export_rpc_dec(exp) \
231 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
232 atomic_dec(&(exp)->exp_rpc_count); \
233 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
234 (exp), atomic_read(&(exp)->exp_rpc_count)); \
237 #define class_export_lock_get(exp, lock) \
239 atomic_inc(&(exp)->exp_locks_count); \
240 __class_export_add_lock_ref(exp, lock); \
241 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
242 (exp), atomic_read(&(exp)->exp_locks_count)); \
243 class_export_get(exp); \
246 #define class_export_lock_put(exp, lock) \
248 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
249 atomic_dec(&(exp)->exp_locks_count); \
250 __class_export_del_lock_ref(exp, lock); \
251 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
252 (exp), atomic_read(&(exp)->exp_locks_count)); \
253 class_export_put(exp); \
256 #define class_export_cb_get(exp) \
258 atomic_inc(&(exp)->exp_cb_count); \
259 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
260 (exp), atomic_read(&(exp)->exp_cb_count)); \
261 class_export_get(exp); \
264 #define class_export_cb_put(exp) \
266 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
267 atomic_dec(&(exp)->exp_cb_count); \
268 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
269 (exp), atomic_read(&(exp)->exp_cb_count)); \
270 class_export_put(exp); \
274 struct obd_export *class_export_get(struct obd_export *exp);
275 void class_export_put(struct obd_export *exp);
276 struct obd_export *class_new_export(struct obd_device *obddev,
277 struct obd_uuid *cluuid);
278 void class_unlink_export(struct obd_export *exp);
280 struct obd_import *class_import_get(struct obd_import *);
281 void class_import_put(struct obd_import *);
282 struct obd_import *class_new_import(struct obd_device *obd);
283 void class_destroy_import(struct obd_import *exp);
285 struct obd_type *class_search_type(const char *name);
286 struct obd_type *class_get_type(const char *name);
287 void class_put_type(struct obd_type *type);
288 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
289 struct obd_uuid *cluuid);
290 int class_disconnect(struct obd_export *exp);
291 void class_fail_export(struct obd_export *exp);
292 int class_connected_export(struct obd_export *exp);
293 void class_disconnect_exports(struct obd_device *obddev);
294 int class_manual_cleanup(struct obd_device *obd);
295 void class_disconnect_stale_exports(struct obd_device *,
296 int (*test_export)(struct obd_export *));
297 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
299 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
300 (obd->obd_force ? OBD_OPT_FORCE : 0) |
301 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
306 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
307 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
308 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
309 unsigned int ia_valid);
310 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
311 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
312 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
315 void obdo_cpu_to_le(struct obdo *dobdo, struct obdo *sobdo);
316 void obdo_le_to_cpu(struct obdo *dobdo, struct obdo *sobdo);
318 #define OBT(dev) (dev)->obd_type
319 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
320 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
321 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
323 /* Ensure obd_setup: used for cleanup which must be called
324 while obd is stopping */
325 #define OBD_CHECK_DEV(obd) \
328 CERROR("NULL device\n"); \
333 /* ensure obd_setup and !obd_stopping */
334 #define OBD_CHECK_DEV_ACTIVE(obd) \
336 OBD_CHECK_DEV(obd); \
337 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
338 CERROR("Device %d not setup\n", \
346 #define OBD_COUNTER_OFFSET(op) \
347 ((offsetof(struct obd_ops, o_ ## op) - \
348 offsetof(struct obd_ops, o_iocontrol)) \
349 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
351 #define OBD_COUNTER_INCREMENT(obdx, op) \
352 if ((obdx)->obd_stats != NULL) { \
353 unsigned int coffset; \
354 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
355 OBD_COUNTER_OFFSET(op); \
356 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
357 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
360 #define EXP_COUNTER_INCREMENT(export, op) \
361 if ((export)->exp_obd->obd_stats != NULL) { \
362 unsigned int coffset; \
363 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
364 OBD_COUNTER_OFFSET(op); \
365 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
366 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
367 if ((export)->exp_nid_stats != NULL && \
368 (export)->exp_nid_stats->nid_stats != NULL) \
369 lprocfs_counter_incr( \
370 (export)->exp_nid_stats->nid_stats, coffset);\
373 #define MD_COUNTER_OFFSET(op) \
374 ((offsetof(struct md_ops, m_ ## op) - \
375 offsetof(struct md_ops, m_getstatus)) \
376 / sizeof(((struct md_ops *)(0))->m_getstatus))
378 #define MD_COUNTER_INCREMENT(obdx, op) \
379 if ((obd)->md_stats != NULL) { \
380 unsigned int coffset; \
381 coffset = (unsigned int)((obdx)->md_cntr_base) + \
382 MD_COUNTER_OFFSET(op); \
383 LASSERT(coffset < (obdx)->md_stats->ls_num); \
384 lprocfs_counter_incr((obdx)->md_stats, coffset); \
387 #define EXP_MD_COUNTER_INCREMENT(export, op) \
388 if ((export)->exp_obd->obd_stats != NULL) { \
389 unsigned int coffset; \
390 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
391 MD_COUNTER_OFFSET(op); \
392 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
393 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
394 if ((export)->exp_md_stats != NULL) \
395 lprocfs_counter_incr( \
396 (export)->exp_md_stats, coffset); \
400 #define OBD_COUNTER_OFFSET(op)
401 #define OBD_COUNTER_INCREMENT(obd, op)
402 #define EXP_COUNTER_INCREMENT(exp, op)
403 #define MD_COUNTER_INCREMENT(obd, op)
404 #define EXP_MD_COUNTER_INCREMENT(exp, op)
407 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
409 /* Always add in ldlm_stats */
410 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
411 ,LPROCFS_STATS_FLAG_NOPERCPU);
412 if (tmp->nid_ldlm_stats == NULL)
415 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
417 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
418 tmp->nid_ldlm_stats);
421 #define OBD_CHECK_MD_OP(obd, op, err) \
423 if (!OBT(obd) || !MDP((obd), op)) { \
425 CERROR("md_" #op ": dev %s/%d no operation\n", \
426 obd->obd_name, obd->obd_minor); \
431 #define EXP_CHECK_MD_OP(exp, op) \
433 if ((exp) == NULL) { \
434 CERROR("obd_" #op ": NULL export\n"); \
437 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
438 CERROR("obd_" #op ": cleaned up obd\n"); \
439 RETURN(-EOPNOTSUPP); \
441 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
442 CERROR("obd_" #op ": dev %s/%d no operation\n", \
443 (exp)->exp_obd->obd_name, \
444 (exp)->exp_obd->obd_minor); \
445 RETURN(-EOPNOTSUPP); \
450 #define OBD_CHECK_DT_OP(obd, op, err) \
452 if (!OBT(obd) || !OBP((obd), op)) { \
454 CERROR("obd_" #op ": dev %d no operation\n", \
460 #define EXP_CHECK_DT_OP(exp, op) \
462 if ((exp) == NULL) { \
463 CERROR("obd_" #op ": NULL export\n"); \
466 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
467 CERROR("obd_" #op ": cleaned up obd\n"); \
468 RETURN(-EOPNOTSUPP); \
470 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
471 CERROR("obd_" #op ": dev %d no operation\n", \
472 (exp)->exp_obd->obd_minor); \
473 RETURN(-EOPNOTSUPP); \
477 #define CTXT_CHECK_OP(ctxt, op, err) \
479 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
481 CERROR("lop_" #op ": dev %d no operation\n", \
482 ctxt->loc_obd->obd_minor); \
487 static inline int class_devno_max(void)
489 return MAX_OBD_DEVICES;
492 static inline int obd_get_info(const struct lu_env *env,
493 struct obd_export *exp, __u32 keylen,
494 void *key, __u32 *vallen, void *val,
495 struct lov_stripe_md *lsm)
500 EXP_CHECK_DT_OP(exp, get_info);
501 EXP_COUNTER_INCREMENT(exp, get_info);
503 rc = OBP(exp->exp_obd, get_info)(env, exp, keylen, key, vallen, val,
508 static inline int obd_set_info_async(const struct lu_env *env,
509 struct obd_export *exp, obd_count keylen,
510 void *key, obd_count vallen, void *val,
511 struct ptlrpc_request_set *set)
516 EXP_CHECK_DT_OP(exp, set_info_async);
517 EXP_COUNTER_INCREMENT(exp, set_info_async);
519 rc = OBP(exp->exp_obd, set_info_async)(env, exp, keylen, key, vallen,
525 * obd-lu integration.
527 * Functionality is being moved into new lu_device-based layering, but some
528 * pieces of configuration process are still based on obd devices.
530 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
531 * subsume ->o_setup() methods of obd devices they replace. The same for
532 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
533 * result, obd_setup() and obd_process_config() branch and call one XOR
536 * Yet neither lu_device_type_operations::ldto_device_fini() nor
537 * lu_device_type_operations::ldto_device_free() fully implement the
538 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
539 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
542 #define DECLARE_LU_VARS(ldt, d) \
543 struct lu_device_type *ldt; \
546 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
549 DECLARE_LU_VARS(ldt, d);
552 ldt = obd->obd_type->typ_lu;
554 struct lu_context session_ctx;
556 lu_context_init(&session_ctx, LCT_SESSION);
557 session_ctx.lc_thread = NULL;
558 lu_context_enter(&session_ctx);
560 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
562 env.le_ses = &session_ctx;
563 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
572 lu_context_exit(&session_ctx);
573 lu_context_fini(&session_ctx);
576 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
577 OBD_COUNTER_INCREMENT(obd, setup);
578 rc = OBP(obd, setup)(obd, cfg);
583 static inline int obd_precleanup(struct obd_device *obd,
584 enum obd_cleanup_stage cleanup_stage)
587 DECLARE_LU_VARS(ldt, d);
591 ldt = obd->obd_type->typ_lu;
593 if (ldt != NULL && d != NULL) {
594 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
597 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
599 ldt->ldt_ops->ldto_device_fini(&env, d);
604 OBD_CHECK_DT_OP(obd, precleanup, 0);
605 OBD_COUNTER_INCREMENT(obd, precleanup);
607 rc = OBP(obd, precleanup)(obd, cleanup_stage);
611 static inline int obd_cleanup(struct obd_device *obd)
614 DECLARE_LU_VARS(ldt, d);
619 ldt = obd->obd_type->typ_lu;
621 if (ldt != NULL && d != NULL) {
624 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
626 ldt->ldt_ops->ldto_device_free(&env, d);
628 obd->obd_lu_dev = NULL;
631 OBD_CHECK_DT_OP(obd, cleanup, 0);
632 OBD_COUNTER_INCREMENT(obd, cleanup);
634 rc = OBP(obd, cleanup)(obd);
638 static inline void obd_cleanup_client_import(struct obd_device *obd)
642 /* If we set up but never connected, the
643 client import will not have been cleaned. */
644 down_write(&obd->u.cli.cl_sem);
645 if (obd->u.cli.cl_import) {
646 struct obd_import *imp;
647 imp = obd->u.cli.cl_import;
648 CDEBUG(D_CONFIG, "%s: client import never connected\n",
650 ptlrpc_invalidate_import(imp);
651 if (imp->imp_rq_pool) {
652 ptlrpc_free_rq_pool(imp->imp_rq_pool);
653 imp->imp_rq_pool = NULL;
655 client_destroy_import(imp);
656 obd->u.cli.cl_import = NULL;
658 up_write(&obd->u.cli.cl_sem);
664 obd_process_config(struct obd_device *obd, int datalen, void *data)
667 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)
707 EXP_CHECK_DT_OP(exp, packmd);
708 EXP_COUNTER_INCREMENT(exp, packmd);
710 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
714 static inline int obd_size_diskmd(struct obd_export *exp,
715 struct lov_stripe_md *mem_src)
717 return obd_packmd(exp, NULL, mem_src);
720 /* helper functions */
721 static inline int obd_alloc_diskmd(struct obd_export *exp,
722 struct lov_mds_md **disk_tgt)
725 LASSERT(*disk_tgt == NULL);
726 return obd_packmd(exp, disk_tgt, NULL);
729 static inline int obd_free_diskmd(struct obd_export *exp,
730 struct lov_mds_md **disk_tgt)
735 * LU-2590, for caller's convenience, *disk_tgt could be host
736 * endianness, it needs swab to LE if necessary, while just
737 * lov_mds_md header needs it for figuring out how much memory
740 if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
741 (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
742 ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
743 lustre_swab_lov_mds_md(*disk_tgt);
744 return obd_packmd(exp, disk_tgt, NULL);
747 /* Unpack an MD struct from disk to in-memory format.
748 * Returns +ve size of unpacked MD (0 for free), or -ve error.
750 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
751 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
752 * If @*mem_tgt == NULL, it will be allocated
754 static inline int obd_unpackmd(struct obd_export *exp,
755 struct lov_stripe_md **mem_tgt,
756 struct lov_mds_md *disk_src,
762 EXP_CHECK_DT_OP(exp, unpackmd);
763 EXP_COUNTER_INCREMENT(exp, unpackmd);
765 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
769 /* helper functions */
770 static inline int obd_alloc_memmd(struct obd_export *exp,
771 struct lov_stripe_md **mem_tgt)
774 LASSERT(*mem_tgt == NULL);
775 return obd_unpackmd(exp, mem_tgt, NULL, 0);
778 static inline int obd_free_memmd(struct obd_export *exp,
779 struct lov_stripe_md **mem_tgt)
785 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
790 static inline int obd_precreate(struct obd_export *exp)
795 EXP_CHECK_DT_OP(exp, precreate);
796 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
798 rc = OBP(exp->exp_obd, precreate)(exp);
802 static inline int obd_create_async(struct obd_export *exp,
803 struct obd_info *oinfo,
804 struct lov_stripe_md **ea,
805 struct obd_trans_info *oti)
810 EXP_CHECK_DT_OP(exp, create_async);
811 EXP_COUNTER_INCREMENT(exp, create_async);
813 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
817 static inline int obd_create(const struct lu_env *env, struct obd_export *exp,
818 struct obdo *obdo, struct lov_stripe_md **ea,
819 struct obd_trans_info *oti)
824 EXP_CHECK_DT_OP(exp, create);
825 EXP_COUNTER_INCREMENT(exp, create);
827 rc = OBP(exp->exp_obd, create)(env, exp, obdo, ea, oti);
831 static inline int obd_destroy(const struct lu_env *env, struct obd_export *exp,
832 struct obdo *obdo, struct lov_stripe_md *ea,
833 struct obd_trans_info *oti,
834 struct obd_export *md_exp, void *capa)
839 EXP_CHECK_DT_OP(exp, destroy);
840 EXP_COUNTER_INCREMENT(exp, destroy);
842 rc = OBP(exp->exp_obd, destroy)(env, exp, obdo, ea, oti, md_exp, capa);
846 static inline int obd_getattr(const struct lu_env *env, struct obd_export *exp,
847 struct obd_info *oinfo)
852 EXP_CHECK_DT_OP(exp, getattr);
853 EXP_COUNTER_INCREMENT(exp, getattr);
855 rc = OBP(exp->exp_obd, getattr)(env, exp, oinfo);
859 static inline int obd_getattr_async(struct obd_export *exp,
860 struct obd_info *oinfo,
861 struct ptlrpc_request_set *set)
866 EXP_CHECK_DT_OP(exp, getattr_async);
867 EXP_COUNTER_INCREMENT(exp, getattr_async);
869 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
873 static inline int obd_setattr(const struct lu_env *env, struct obd_export *exp,
874 struct obd_info *oinfo,
875 struct obd_trans_info *oti)
880 EXP_CHECK_DT_OP(exp, setattr);
881 EXP_COUNTER_INCREMENT(exp, setattr);
883 rc = OBP(exp->exp_obd, setattr)(env, exp, oinfo, oti);
887 /* This performs all the requests set init/wait/destroy actions. */
888 static inline int obd_setattr_rqset(struct obd_export *exp,
889 struct obd_info *oinfo,
890 struct obd_trans_info *oti)
892 struct ptlrpc_request_set *set = NULL;
896 EXP_CHECK_DT_OP(exp, setattr_async);
897 EXP_COUNTER_INCREMENT(exp, setattr_async);
899 set = ptlrpc_prep_set();
903 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
905 rc = ptlrpc_set_wait(set);
906 ptlrpc_set_destroy(set);
910 /* This adds all the requests into @set if @set != NULL, otherwise
911 all requests are sent asynchronously without waiting for response. */
912 static inline int obd_setattr_async(struct obd_export *exp,
913 struct obd_info *oinfo,
914 struct obd_trans_info *oti,
915 struct ptlrpc_request_set *set)
920 EXP_CHECK_DT_OP(exp, setattr_async);
921 EXP_COUNTER_INCREMENT(exp, setattr_async);
923 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
927 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
930 struct obd_device *obd = imp->imp_obd;
934 OBD_CHECK_DEV_ACTIVE(obd);
935 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
936 OBD_COUNTER_INCREMENT(obd, add_conn);
938 rc = OBP(obd, add_conn)(imp, uuid, priority);
942 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
944 struct obd_device *obd = imp->imp_obd;
948 OBD_CHECK_DEV_ACTIVE(obd);
949 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
950 OBD_COUNTER_INCREMENT(obd, del_conn);
952 rc = OBP(obd, del_conn)(imp, uuid);
956 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
958 struct obd_uuid *uuid;
961 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
962 EXP_COUNTER_INCREMENT(exp, get_uuid);
964 uuid = OBP(exp->exp_obd, get_uuid)(exp);
968 /** Create a new /a exp on device /a obd for the uuid /a cluuid
969 * @param exp New export handle
970 * @param d Connect data, supported flags are set, flags also understood
971 * by obd are returned.
973 static inline int obd_connect(const struct lu_env *env,
974 struct obd_export **exp,struct obd_device *obd,
975 struct obd_uuid *cluuid,
976 struct obd_connect_data *data,
980 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
984 OBD_CHECK_DEV_ACTIVE(obd);
985 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
986 OBD_COUNTER_INCREMENT(obd, connect);
988 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
989 /* check that only subset is granted */
990 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
991 data->ocd_connect_flags));
995 static inline int obd_reconnect(const struct lu_env *env,
996 struct obd_export *exp,
997 struct obd_device *obd,
998 struct obd_uuid *cluuid,
999 struct obd_connect_data *d,
1003 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
1008 OBD_CHECK_DEV_ACTIVE(obd);
1009 OBD_CHECK_DT_OP(obd, reconnect, 0);
1010 OBD_COUNTER_INCREMENT(obd, reconnect);
1012 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
1013 /* check that only subset is granted */
1014 LASSERT(ergo(d != NULL,
1015 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
1019 static inline int obd_disconnect(struct obd_export *exp)
1024 EXP_CHECK_DT_OP(exp, disconnect);
1025 EXP_COUNTER_INCREMENT(exp, disconnect);
1027 rc = OBP(exp->exp_obd, disconnect)(exp);
1031 static inline int obd_fid_init(struct obd_device *obd, struct obd_export *exp,
1032 enum lu_cli_type type)
1037 OBD_CHECK_DT_OP(obd, fid_init, 0);
1038 OBD_COUNTER_INCREMENT(obd, fid_init);
1040 rc = OBP(obd, fid_init)(obd, exp, type);
1044 static inline int obd_fid_fini(struct obd_device *obd)
1049 OBD_CHECK_DT_OP(obd, fid_fini, 0);
1050 OBD_COUNTER_INCREMENT(obd, fid_fini);
1052 rc = OBP(obd, fid_fini)(obd);
1056 static inline int obd_fid_alloc(struct obd_export *exp,
1058 struct md_op_data *op_data)
1063 EXP_CHECK_DT_OP(exp, fid_alloc);
1064 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1066 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1070 static inline int obd_ping(const struct lu_env *env, struct obd_export *exp)
1075 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1076 EXP_COUNTER_INCREMENT(exp, ping);
1078 rc = OBP(exp->exp_obd, ping)(env, exp);
1082 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1087 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1088 OBD_COUNTER_INCREMENT(obd, pool_new);
1090 rc = OBP(obd, pool_new)(obd, poolname);
1094 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1099 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1100 OBD_COUNTER_INCREMENT(obd, pool_del);
1102 rc = OBP(obd, pool_del)(obd, poolname);
1106 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1111 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1112 OBD_COUNTER_INCREMENT(obd, pool_add);
1114 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1118 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1123 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1124 OBD_COUNTER_INCREMENT(obd, pool_rem);
1126 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1130 static inline void obd_getref(struct obd_device *obd)
1133 if (OBT(obd) && OBP(obd, getref)) {
1134 OBD_COUNTER_INCREMENT(obd, getref);
1135 OBP(obd, getref)(obd);
1140 static inline void obd_putref(struct obd_device *obd)
1143 if (OBT(obd) && OBP(obd, putref)) {
1144 OBD_COUNTER_INCREMENT(obd, putref);
1145 OBP(obd, putref)(obd);
1150 static inline int obd_init_export(struct obd_export *exp)
1155 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1156 OBP((exp)->exp_obd, init_export))
1157 rc = OBP(exp->exp_obd, init_export)(exp);
1161 static inline int obd_destroy_export(struct obd_export *exp)
1164 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1165 OBP((exp)->exp_obd, destroy_export))
1166 OBP(exp->exp_obd, destroy_export)(exp);
1170 static inline int obd_extent_calc(struct obd_export *exp,
1171 struct lov_stripe_md *md,
1172 int cmd, obd_off *offset)
1176 EXP_CHECK_DT_OP(exp, extent_calc);
1177 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1181 static inline struct dentry *
1182 obd_lvfs_fid2dentry(struct obd_export *exp, struct ost_id *oi, __u32 gen)
1184 struct lvfs_run_ctxt *ctxt = &exp->exp_obd->obd_lvfs_ctxt;
1185 LASSERT(exp->exp_obd);
1187 return ctxt->cb_ops.l_fid2dentry(ostid_id(oi), gen, ostid_seq(oi),
1191 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1192 * If the cache is older than @max_age we will get a new value from the
1193 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1194 static inline int obd_statfs_async(struct obd_export *exp,
1195 struct obd_info *oinfo,
1197 struct ptlrpc_request_set *rqset)
1200 struct obd_device *obd;
1203 if (exp == NULL || exp->exp_obd == NULL)
1207 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1208 OBD_COUNTER_INCREMENT(obd, statfs);
1210 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1211 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1212 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1213 rc = OBP(obd, statfs_async)(exp, oinfo, max_age, rqset);
1215 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1216 " objects "LPU64"/"LPU64"\n",
1217 obd->obd_name, &obd->obd_osfs,
1218 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1219 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1220 spin_lock(&obd->obd_osfs_lock);
1221 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1222 spin_unlock(&obd->obd_osfs_lock);
1223 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1224 if (oinfo->oi_cb_up)
1225 oinfo->oi_cb_up(oinfo, 0);
1230 static inline int obd_statfs_rqset(struct obd_export *exp,
1231 struct obd_statfs *osfs, __u64 max_age,
1234 struct ptlrpc_request_set *set = NULL;
1235 struct obd_info oinfo = { { { 0 } } };
1239 set = ptlrpc_prep_set();
1243 oinfo.oi_osfs = osfs;
1244 oinfo.oi_flags = flags;
1245 rc = obd_statfs_async(exp, &oinfo, max_age, set);
1247 rc = ptlrpc_set_wait(set);
1248 ptlrpc_set_destroy(set);
1252 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1253 * If the cache is older than @max_age we will get a new value from the
1254 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1255 static inline int obd_statfs(const struct lu_env *env, struct obd_export *exp,
1256 struct obd_statfs *osfs, __u64 max_age,
1260 struct obd_device *obd = exp->exp_obd;
1266 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1267 OBD_COUNTER_INCREMENT(obd, statfs);
1269 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1270 obd->obd_osfs_age, max_age);
1271 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1272 rc = OBP(obd, statfs)(env, exp, osfs, max_age, flags);
1274 spin_lock(&obd->obd_osfs_lock);
1275 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1276 obd->obd_osfs_age = cfs_time_current_64();
1277 spin_unlock(&obd->obd_osfs_lock);
1280 CDEBUG(D_SUPER, "%s: use %p cache blocks "LPU64"/"LPU64
1281 " objects "LPU64"/"LPU64"\n",
1282 obd->obd_name, &obd->obd_osfs,
1283 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1284 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1285 spin_lock(&obd->obd_osfs_lock);
1286 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1287 spin_unlock(&obd->obd_osfs_lock);
1292 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
1293 obd_size start, obd_size end)
1295 struct ptlrpc_request_set *set = NULL;
1299 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1300 EXP_COUNTER_INCREMENT(exp, sync);
1302 set = ptlrpc_prep_set();
1306 rc = OBP(exp->exp_obd, sync)(NULL, exp, oinfo, start, end, set);
1308 rc = ptlrpc_set_wait(set);
1309 ptlrpc_set_destroy(set);
1313 static inline int obd_sync(const struct lu_env *env, struct obd_export *exp,
1314 struct obd_info *oinfo, obd_size start, obd_size end,
1315 struct ptlrpc_request_set *set)
1320 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1321 EXP_COUNTER_INCREMENT(exp, sync);
1323 rc = OBP(exp->exp_obd, sync)(env, exp, oinfo, start, end, set);
1327 static inline int obd_punch_rqset(struct obd_export *exp,
1328 struct obd_info *oinfo,
1329 struct obd_trans_info *oti)
1331 struct ptlrpc_request_set *set = NULL;
1335 EXP_CHECK_DT_OP(exp, punch);
1336 EXP_COUNTER_INCREMENT(exp, punch);
1338 set = ptlrpc_prep_set();
1342 rc = OBP(exp->exp_obd, punch)(NULL, exp, oinfo, oti, set);
1344 rc = ptlrpc_set_wait(set);
1345 ptlrpc_set_destroy(set);
1349 static inline int obd_punch(const struct lu_env *env, struct obd_export *exp,
1350 struct obd_info *oinfo, struct obd_trans_info *oti,
1351 struct ptlrpc_request_set *rqset)
1356 EXP_CHECK_DT_OP(exp, punch);
1357 EXP_COUNTER_INCREMENT(exp, punch);
1359 rc = OBP(exp->exp_obd, punch)(env, exp, oinfo, oti, rqset);
1363 static inline int obd_brw(int cmd, struct obd_export *exp,
1364 struct obd_info *oinfo, obd_count oa_bufs,
1365 struct brw_page *pg, struct obd_trans_info *oti)
1370 EXP_CHECK_DT_OP(exp, brw);
1371 EXP_COUNTER_INCREMENT(exp, brw);
1373 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1374 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1375 "or OBD_BRW_CHECK\n");
1379 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1383 static inline int obd_preprw(const struct lu_env *env, int cmd,
1384 struct obd_export *exp, struct obdo *oa,
1385 int objcount, struct obd_ioobj *obj,
1386 struct niobuf_remote *remote, int *pages,
1387 struct niobuf_local *local,
1388 struct obd_trans_info *oti,
1389 struct lustre_capa *capa)
1394 EXP_CHECK_DT_OP(exp, preprw);
1395 EXP_COUNTER_INCREMENT(exp, preprw);
1397 rc = OBP(exp->exp_obd, preprw)(env, cmd, exp, oa, objcount, obj, remote,
1398 pages, local, oti, capa);
1402 static inline int obd_commitrw(const struct lu_env *env, int cmd,
1403 struct obd_export *exp, struct obdo *oa,
1404 int objcount, struct obd_ioobj *obj,
1405 struct niobuf_remote *rnb, int pages,
1406 struct niobuf_local *local,
1407 struct obd_trans_info *oti, int rc)
1411 EXP_CHECK_DT_OP(exp, commitrw);
1412 EXP_COUNTER_INCREMENT(exp, commitrw);
1414 rc = OBP(exp->exp_obd, commitrw)(env, cmd, exp, oa, objcount, obj,
1415 rnb, pages, local, oti, rc);
1419 static inline int obd_merge_lvb(struct obd_export *exp,
1420 struct lov_stripe_md *lsm,
1421 struct ost_lvb *lvb, int kms_only)
1426 EXP_CHECK_DT_OP(exp, merge_lvb);
1427 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1429 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1433 static inline int obd_adjust_kms(struct obd_export *exp,
1434 struct lov_stripe_md *lsm, obd_off size,
1440 EXP_CHECK_DT_OP(exp, adjust_kms);
1441 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1443 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1447 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1448 int len, void *karg, void *uarg)
1453 EXP_CHECK_DT_OP(exp, iocontrol);
1454 EXP_COUNTER_INCREMENT(exp, iocontrol);
1456 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1460 static inline int obd_enqueue_rqset(struct obd_export *exp,
1461 struct obd_info *oinfo,
1462 struct ldlm_enqueue_info *einfo)
1464 struct ptlrpc_request_set *set = NULL;
1468 EXP_CHECK_DT_OP(exp, enqueue);
1469 EXP_COUNTER_INCREMENT(exp, enqueue);
1471 set = ptlrpc_prep_set();
1475 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1477 rc = ptlrpc_set_wait(set);
1478 ptlrpc_set_destroy(set);
1482 static inline int obd_enqueue(struct obd_export *exp,
1483 struct obd_info *oinfo,
1484 struct ldlm_enqueue_info *einfo,
1485 struct ptlrpc_request_set *set)
1490 EXP_CHECK_DT_OP(exp, enqueue);
1491 EXP_COUNTER_INCREMENT(exp, enqueue);
1493 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1497 static inline int obd_change_cbdata(struct obd_export *exp,
1498 struct lov_stripe_md *lsm,
1499 ldlm_iterator_t it, void *data)
1504 EXP_CHECK_DT_OP(exp, change_cbdata);
1505 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1507 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1511 static inline int obd_find_cbdata(struct obd_export *exp,
1512 struct lov_stripe_md *lsm,
1513 ldlm_iterator_t it, void *data)
1518 EXP_CHECK_DT_OP(exp, find_cbdata);
1519 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1521 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1525 static inline int obd_cancel(struct obd_export *exp,
1526 struct lov_stripe_md *ea, __u32 mode,
1527 struct lustre_handle *lockh)
1532 EXP_CHECK_DT_OP(exp, cancel);
1533 EXP_COUNTER_INCREMENT(exp, cancel);
1535 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1539 static inline int obd_cancel_unused(struct obd_export *exp,
1540 struct lov_stripe_md *ea,
1541 ldlm_cancel_flags_t flags,
1547 EXP_CHECK_DT_OP(exp, cancel_unused);
1548 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1550 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1554 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1555 struct obd_capa *oc, struct obd_client_handle *handle,
1561 EXP_CHECK_DT_OP(exp, pin);
1562 EXP_COUNTER_INCREMENT(exp, pin);
1564 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1568 static inline int obd_unpin(struct obd_export *exp,
1569 struct obd_client_handle *handle, int flag)
1574 EXP_CHECK_DT_OP(exp, unpin);
1575 EXP_COUNTER_INCREMENT(exp, unpin);
1577 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1582 static inline void obd_import_event(struct obd_device *obd,
1583 struct obd_import *imp,
1584 enum obd_import_event event)
1588 CERROR("NULL device\n");
1592 if (obd->obd_set_up && OBP(obd, import_event)) {
1593 OBD_COUNTER_INCREMENT(obd, import_event);
1594 OBP(obd, import_event)(obd, imp, event);
1599 static inline int obd_llog_connect(struct obd_export *exp,
1600 struct llogd_conn_body *body)
1605 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1606 EXP_COUNTER_INCREMENT(exp, llog_connect);
1608 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1613 static inline int obd_notify(struct obd_device *obd,
1614 struct obd_device *watched,
1615 enum obd_notify_event ev,
1622 /* the check for async_recov is a complete hack - I'm hereby
1623 overloading the meaning to also mean "this was called from
1624 mds_postsetup". I know that my mds is able to handle notifies
1625 by this point, and it needs to get them to execute mds_postrecov. */
1626 if (!obd->obd_set_up && !obd->obd_async_recov) {
1627 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1631 if (!OBP(obd, notify)) {
1632 CDEBUG(D_HA, "obd %s has no notify handler\n", obd->obd_name);
1636 OBD_COUNTER_INCREMENT(obd, notify);
1637 rc = OBP(obd, notify)(obd, watched, ev, data);
1641 static inline int obd_notify_observer(struct obd_device *observer,
1642 struct obd_device *observed,
1643 enum obd_notify_event ev,
1649 struct obd_notify_upcall *onu;
1651 if (observer->obd_observer)
1652 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1656 * Also, call non-obd listener, if any
1658 onu = &observer->obd_upcall;
1659 if (onu->onu_upcall != NULL)
1660 rc2 = onu->onu_upcall(observer, observed, ev,
1661 onu->onu_owner, NULL);
1665 return rc1 ? rc1 : rc2;
1668 static inline int obd_quotacheck(struct obd_export *exp,
1669 struct obd_quotactl *oqctl)
1674 EXP_CHECK_DT_OP(exp, quotacheck);
1675 EXP_COUNTER_INCREMENT(exp, quotacheck);
1677 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1681 static inline int obd_quotactl(struct obd_export *exp,
1682 struct obd_quotactl *oqctl)
1687 EXP_CHECK_DT_OP(exp, quotactl);
1688 EXP_COUNTER_INCREMENT(exp, quotactl);
1690 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1694 static inline int obd_health_check(const struct lu_env *env,
1695 struct obd_device *obd)
1697 /* returns: 0 on healthy
1698 * >0 on unhealthy + reason code/flag
1699 * however the only suppored reason == 1 right now
1700 * We'll need to define some better reasons
1701 * or flags in the future.
1707 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1708 if (obd == NULL || !OBT(obd)) {
1709 CERROR("cleaned up obd\n");
1710 RETURN(-EOPNOTSUPP);
1712 if (!obd->obd_set_up || obd->obd_stopping)
1714 if (!OBP(obd, health_check))
1717 rc = OBP(obd, health_check)(env, obd);
1721 static inline int obd_register_observer(struct obd_device *obd,
1722 struct obd_device *observer)
1726 down_write(&obd->obd_observer_link_sem);
1727 if (obd->obd_observer && observer) {
1728 up_write(&obd->obd_observer_link_sem);
1731 obd->obd_observer = observer;
1732 up_write(&obd->obd_observer_link_sem);
1736 static inline int obd_pin_observer(struct obd_device *obd,
1737 struct obd_device **observer)
1740 down_read(&obd->obd_observer_link_sem);
1741 if (!obd->obd_observer) {
1743 up_read(&obd->obd_observer_link_sem);
1746 *observer = obd->obd_observer;
1750 static inline int obd_unpin_observer(struct obd_device *obd)
1753 up_read(&obd->obd_observer_link_sem);
1758 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1759 obd_page_removal_cb_t cb,
1760 obd_pin_extent_cb pin_cb)
1765 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1766 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1768 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1772 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1773 obd_page_removal_cb_t cb)
1778 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1779 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1781 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1785 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1786 obd_lock_cancel_cb cb)
1791 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1792 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1794 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1798 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1799 obd_lock_cancel_cb cb)
1804 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1805 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1807 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1812 /* metadata helpers */
1813 static inline int md_getstatus(struct obd_export *exp,
1814 struct lu_fid *fid, struct obd_capa **pc)
1819 EXP_CHECK_MD_OP(exp, getstatus);
1820 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1821 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1825 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1826 struct ptlrpc_request **request)
1830 EXP_CHECK_MD_OP(exp, getattr);
1831 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1832 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1836 static inline int md_null_inode(struct obd_export *exp,
1837 const struct lu_fid *fid)
1841 EXP_CHECK_MD_OP(exp, null_inode);
1842 EXP_MD_COUNTER_INCREMENT(exp, null_inode);
1843 rc = MDP(exp->exp_obd, null_inode)(exp, fid);
1847 static inline int md_find_cbdata(struct obd_export *exp,
1848 const struct lu_fid *fid,
1849 ldlm_iterator_t it, void *data)
1853 EXP_CHECK_MD_OP(exp, find_cbdata);
1854 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1855 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1859 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1860 struct md_open_data *mod,
1861 struct ptlrpc_request **request)
1865 EXP_CHECK_MD_OP(exp, close);
1866 EXP_MD_COUNTER_INCREMENT(exp, close);
1867 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1871 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1872 const void *data, int datalen, int mode, __u32 uid,
1873 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1874 struct ptlrpc_request **request)
1878 EXP_CHECK_MD_OP(exp, create);
1879 EXP_MD_COUNTER_INCREMENT(exp, create);
1880 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1881 uid, gid, cap_effective, rdev, request);
1885 static inline int md_done_writing(struct obd_export *exp,
1886 struct md_op_data *op_data,
1887 struct md_open_data *mod)
1891 EXP_CHECK_MD_OP(exp, done_writing);
1892 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1893 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1897 static inline int md_enqueue(struct obd_export *exp,
1898 struct ldlm_enqueue_info *einfo,
1899 struct lookup_intent *it,
1900 struct md_op_data *op_data,
1901 struct lustre_handle *lockh,
1902 void *lmm, int lmmsize,
1903 struct ptlrpc_request **req,
1904 int extra_lock_flags)
1908 EXP_CHECK_MD_OP(exp, enqueue);
1909 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1910 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1911 lmm, lmmsize, req, extra_lock_flags);
1915 static inline int md_getattr_name(struct obd_export *exp,
1916 struct md_op_data *op_data,
1917 struct ptlrpc_request **request)
1921 EXP_CHECK_MD_OP(exp, getattr_name);
1922 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1923 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1927 static inline int md_intent_lock(struct obd_export *exp,
1928 struct md_op_data *op_data, void *lmm,
1929 int lmmsize, struct lookup_intent *it,
1930 int lookup_flags, struct ptlrpc_request **reqp,
1931 ldlm_blocking_callback cb_blocking,
1932 __u64 extra_lock_flags)
1936 EXP_CHECK_MD_OP(exp, intent_lock);
1937 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1938 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1939 it, lookup_flags, reqp, cb_blocking,
1944 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1945 struct ptlrpc_request **request)
1949 EXP_CHECK_MD_OP(exp, link);
1950 EXP_MD_COUNTER_INCREMENT(exp, link);
1951 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1955 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1956 const char *old, int oldlen, const char *new,
1957 int newlen, struct ptlrpc_request **request)
1961 EXP_CHECK_MD_OP(exp, rename);
1962 EXP_MD_COUNTER_INCREMENT(exp, rename);
1963 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1968 static inline int md_is_subdir(struct obd_export *exp,
1969 const struct lu_fid *pfid,
1970 const struct lu_fid *cfid,
1971 struct ptlrpc_request **request)
1975 EXP_CHECK_MD_OP(exp, is_subdir);
1976 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1977 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1981 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1982 void *ea, int ealen, void *ea2, int ea2len,
1983 struct ptlrpc_request **request,
1984 struct md_open_data **mod)
1988 EXP_CHECK_MD_OP(exp, setattr);
1989 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1990 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1991 ea2, ea2len, request, mod);
1995 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1996 struct obd_capa *oc, struct ptlrpc_request **request)
2000 EXP_CHECK_MD_OP(exp, sync);
2001 EXP_MD_COUNTER_INCREMENT(exp, sync);
2002 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
2006 static inline int md_readpage(struct obd_export *exp, struct md_op_data *opdata,
2007 struct page **pages,
2008 struct ptlrpc_request **request)
2012 EXP_CHECK_MD_OP(exp, readpage);
2013 EXP_MD_COUNTER_INCREMENT(exp, readpage);
2014 rc = MDP(exp->exp_obd, readpage)(exp, opdata, pages, request);
2018 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
2019 struct ptlrpc_request **request)
2023 EXP_CHECK_MD_OP(exp, unlink);
2024 EXP_MD_COUNTER_INCREMENT(exp, unlink);
2025 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
2029 static inline int md_get_lustre_md(struct obd_export *exp,
2030 struct ptlrpc_request *req,
2031 struct obd_export *dt_exp,
2032 struct obd_export *md_exp,
2033 struct lustre_md *md)
2036 EXP_CHECK_MD_OP(exp, get_lustre_md);
2037 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
2038 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
2041 static inline int md_free_lustre_md(struct obd_export *exp,
2042 struct lustre_md *md)
2045 EXP_CHECK_MD_OP(exp, free_lustre_md);
2046 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2047 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2050 static inline int md_setxattr(struct obd_export *exp,
2051 const struct lu_fid *fid, struct obd_capa *oc,
2052 obd_valid valid, const char *name,
2053 const char *input, int input_size,
2054 int output_size, int flags, __u32 suppgid,
2055 struct ptlrpc_request **request)
2058 EXP_CHECK_MD_OP(exp, setxattr);
2059 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2060 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2061 input_size, output_size, flags,
2065 static inline int md_getxattr(struct obd_export *exp,
2066 const struct lu_fid *fid, struct obd_capa *oc,
2067 obd_valid valid, const char *name,
2068 const char *input, int input_size,
2069 int output_size, int flags,
2070 struct ptlrpc_request **request)
2073 EXP_CHECK_MD_OP(exp, getxattr);
2074 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2075 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2076 input_size, output_size, flags,
2080 static inline int md_set_open_replay_data(struct obd_export *exp,
2081 struct obd_client_handle *och,
2082 struct ptlrpc_request *open_req)
2085 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2086 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2087 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2090 static inline int md_clear_open_replay_data(struct obd_export *exp,
2091 struct obd_client_handle *och)
2094 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2095 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2096 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2099 static inline int md_set_lock_data(struct obd_export *exp,
2100 __u64 *lockh, void *data, __u64 *bits)
2103 EXP_CHECK_MD_OP(exp, set_lock_data);
2104 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2105 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2108 static inline int md_cancel_unused(struct obd_export *exp,
2109 const struct lu_fid *fid,
2110 ldlm_policy_data_t *policy,
2112 ldlm_cancel_flags_t flags,
2118 EXP_CHECK_MD_OP(exp, cancel_unused);
2119 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2121 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2126 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, __u64 flags,
2127 const struct lu_fid *fid,
2129 ldlm_policy_data_t *policy,
2131 struct lustre_handle *lockh)
2134 EXP_CHECK_MD_OP(exp, lock_match);
2135 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2136 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2137 policy, mode, lockh));
2140 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2141 int def_asize, int cookiesize)
2144 EXP_CHECK_MD_OP(exp, init_ea_size);
2145 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2146 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2150 static inline int md_get_remote_perm(struct obd_export *exp,
2151 const struct lu_fid *fid,
2152 struct obd_capa *oc, __u32 suppgid,
2153 struct ptlrpc_request **request)
2156 EXP_CHECK_MD_OP(exp, get_remote_perm);
2157 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2158 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2162 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2167 EXP_CHECK_MD_OP(exp, renew_capa);
2168 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2169 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2173 static inline int md_unpack_capa(struct obd_export *exp,
2174 struct ptlrpc_request *req,
2175 const struct req_msg_field *field,
2176 struct obd_capa **oc)
2180 EXP_CHECK_MD_OP(exp, unpack_capa);
2181 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2182 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2186 static inline int md_intent_getattr_async(struct obd_export *exp,
2187 struct md_enqueue_info *minfo,
2188 struct ldlm_enqueue_info *einfo)
2192 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2193 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2194 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2198 static inline int md_revalidate_lock(struct obd_export *exp,
2199 struct lookup_intent *it,
2200 struct lu_fid *fid, __u64 *bits)
2204 EXP_CHECK_MD_OP(exp, revalidate_lock);
2205 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2206 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
2211 /* OBD Metadata Support */
2213 extern int obd_init_caches(void);
2214 extern void obd_cleanup_caches(void);
2216 /* support routines */
2217 extern struct kmem_cache *obdo_cachep;
2219 #define OBDO_ALLOC(ptr) \
2221 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, __GFP_IO); \
2224 #define OBDO_FREE(ptr) \
2226 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2230 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2232 /* something here */
2235 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2237 /* something here */
2240 typedef int (*register_lwp_cb)(void *data);
2242 struct lwp_register_item {
2243 struct obd_export **lri_exp;
2244 register_lwp_cb lri_cb_func;
2246 struct list_head lri_list;
2247 char lri_name[MTI_NAME_MAXLEN];
2250 /* I'm as embarrassed about this as you are.
2252 * <shaver> // XXX do not look into _superhack with remaining eye
2253 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2254 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2259 extern void obd_sysctl_init (void);
2260 extern void obd_sysctl_clean (void);
2263 typedef __u8 class_uuid_t[16];
2264 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2267 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2268 int class_add_uuid(const char *uuid, __u64 nid);
2269 int class_del_uuid (const char *uuid);
2270 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
2271 void class_init_uuidlist(void);
2272 void class_exit_uuidlist(void);
2275 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2276 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2279 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2281 #endif /* __LINUX_OBD_CLASS_H */