1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
43 # include <liblustre.h>
46 #include <obd_support.h>
47 #include <lustre_import.h>
48 #include <lustre_net.h>
50 #include <lustre_lib.h>
51 #include <lustre/lustre_idl.h>
52 #include <lprocfs_status.h>
54 #if defined(__linux__)
55 #include <linux/obd_class.h>
56 #elif defined(__APPLE__)
57 #include <darwin/obd_class.h>
58 #elif defined(__WINNT__)
59 #include <winnt/obd_class.h>
61 #error Unsupported operating system.
64 /* OBD Device Declarations */
65 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
66 extern cfs_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);
73 struct lu_device_type;
76 struct obd_export *class_conn2export(struct lustre_handle *);
77 int class_register_type(struct obd_ops *, struct md_ops *,
78 struct lprocfs_vars *, const char *nm,
79 struct lu_device_type *ldt);
80 int class_unregister_type(const char *nm);
82 struct obd_device *class_newdev(const char *type_name, const char *name);
83 void class_release_dev(struct obd_device *obd);
85 int class_name2dev(const char *name);
86 struct obd_device *class_name2obd(const char *name);
87 int class_uuid2dev(struct obd_uuid *uuid);
88 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
89 void class_obd_list(void);
90 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
91 const char * typ_name,
92 struct obd_uuid *grp_uuid);
93 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
95 struct obd_device * class_num2obd(int num);
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);
117 int class_process_config(struct lustre_cfg *lcfg);
118 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
119 struct lustre_cfg *lcfg, void *data);
120 int class_attach(struct lustre_cfg *lcfg);
121 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
122 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
123 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
124 struct obd_device *class_incref(struct obd_device *obd,
125 const char *scope, const void *source);
126 void class_decref(struct obd_device *obd,
127 const char *scope, const void *source);
128 void dump_exports(struct obd_device *obd, int locks);
132 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
134 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
136 memset(lvars, 0, sizeof(*lvars));
140 #define CFG_F_START 0x01 /* Set when we start updating from a log */
141 #define CFG_F_MARKER 0x02 /* We are within a maker */
142 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
143 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
144 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
146 /* Passed as data param to class_config_parse_llog */
147 struct config_llog_instance {
150 struct super_block *cfg_sb;
151 struct obd_uuid cfg_uuid;
152 int cfg_last_idx; /* for partial llog processing */
155 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
156 struct config_llog_instance *cfg);
157 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
158 struct config_llog_instance *cfg);
162 CONFIG_T_SPTLRPC = 1,
163 CONFIG_T_RECOVER = 2,
167 /* list of active configuration logs */
168 struct config_llog_data {
169 struct ldlm_res_id cld_resid;
170 struct config_llog_instance cld_cfg;
171 cfs_list_t cld_list_chain;
172 cfs_atomic_t cld_refcount;
173 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
174 struct config_llog_data *cld_recover; /* imperative recover log */
175 struct obd_export *cld_mgcexp;
176 cfs_mutex_t cld_lock;
178 unsigned int cld_stopping:1, /* we were told to stop
180 cld_lostlock:1; /* lock not requeued */
184 struct lustre_profile {
191 struct lustre_profile *class_get_profile(const char * prof);
192 void class_del_profile(const char *prof);
193 void class_del_profiles(void);
195 #if LUSTRE_TRACKS_LOCK_EXP_REFS
197 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
198 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
199 extern void (*class_export_dump_hook)(struct obd_export *);
203 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
204 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
208 #define class_export_rpc_get(exp) \
210 cfs_atomic_inc(&(exp)->exp_rpc_count); \
211 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
212 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
213 class_export_get(exp); \
216 #define class_export_rpc_put(exp) \
218 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
219 cfs_atomic_dec(&(exp)->exp_rpc_count); \
220 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
221 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
222 class_export_put(exp); \
225 #define class_export_lock_get(exp, lock) \
227 cfs_atomic_inc(&(exp)->exp_locks_count); \
228 __class_export_add_lock_ref(exp, lock); \
229 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
230 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
231 class_export_get(exp); \
234 #define class_export_lock_put(exp, lock) \
236 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
237 cfs_atomic_dec(&(exp)->exp_locks_count); \
238 __class_export_del_lock_ref(exp, lock); \
239 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
240 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
241 class_export_put(exp); \
244 #define class_export_cb_get(exp) \
246 cfs_atomic_inc(&(exp)->exp_cb_count); \
247 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
248 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
249 class_export_get(exp); \
252 #define class_export_cb_put(exp) \
254 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
255 cfs_atomic_dec(&(exp)->exp_cb_count); \
256 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
257 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
258 class_export_put(exp); \
262 struct obd_export *class_export_get(struct obd_export *exp);
263 void class_export_put(struct obd_export *exp);
264 struct obd_export *class_new_export(struct obd_device *obddev,
265 struct obd_uuid *cluuid);
266 void class_unlink_export(struct obd_export *exp);
268 struct obd_import *class_import_get(struct obd_import *);
269 void class_import_put(struct obd_import *);
270 struct obd_import *class_new_import(struct obd_device *obd);
271 void class_destroy_import(struct obd_import *exp);
273 struct obd_type *class_search_type(const char *name);
274 struct obd_type *class_get_type(const char *name);
275 void class_put_type(struct obd_type *type);
276 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
277 struct obd_uuid *cluuid);
278 int class_disconnect(struct obd_export *exp);
279 void class_fail_export(struct obd_export *exp);
280 int class_connected_export(struct obd_export *exp);
281 void class_disconnect_exports(struct obd_device *obddev);
282 int class_manual_cleanup(struct obd_device *obd);
283 void class_disconnect_stale_exports(struct obd_device *,
284 int (*test_export)(struct obd_export *));
285 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
287 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
288 (obd->obd_force ? OBD_OPT_FORCE : 0) |
289 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
293 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
295 LASSERT(exp->exp_obd);
296 return exp->exp_obd->u.obt.obt_lut;
299 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
301 LASSERT(obd->u.obt.obt_lut);
302 return &obd->u.obt.obt_lut->lut_lsd;
305 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
306 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
307 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
308 unsigned int ia_valid);
309 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
310 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
311 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
314 #define OBT(dev) (dev)->obd_type
315 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
316 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
317 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
319 /* Ensure obd_setup: used for cleanup which must be called
320 while obd is stopping */
321 #define OBD_CHECK_DEV(obd) \
324 CERROR("NULL device\n"); \
329 /* ensure obd_setup and !obd_stopping */
330 #define OBD_CHECK_DEV_ACTIVE(obd) \
332 OBD_CHECK_DEV(obd); \
333 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
334 CERROR("Device %d not setup\n", \
342 #define OBD_COUNTER_OFFSET(op) \
343 ((offsetof(struct obd_ops, o_ ## op) - \
344 offsetof(struct obd_ops, o_iocontrol)) \
345 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
347 #define OBD_COUNTER_INCREMENT(obdx, op) \
348 if ((obdx)->obd_stats != NULL) { \
349 unsigned int coffset; \
350 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
351 OBD_COUNTER_OFFSET(op); \
352 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
353 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
356 #define EXP_COUNTER_INCREMENT(export, op) \
357 if ((export)->exp_obd->obd_stats != NULL) { \
358 unsigned int coffset; \
359 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
360 OBD_COUNTER_OFFSET(op); \
361 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
362 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
363 if ((export)->exp_nid_stats != NULL && \
364 (export)->exp_nid_stats->nid_stats != NULL) \
365 lprocfs_counter_incr( \
366 (export)->exp_nid_stats->nid_stats, coffset);\
369 #define MD_COUNTER_OFFSET(op) \
370 ((offsetof(struct md_ops, m_ ## op) - \
371 offsetof(struct md_ops, m_getstatus)) \
372 / sizeof(((struct md_ops *)(0))->m_getstatus))
374 #define MD_COUNTER_INCREMENT(obdx, op) \
375 if ((obd)->md_stats != NULL) { \
376 unsigned int coffset; \
377 coffset = (unsigned int)((obdx)->md_cntr_base) + \
378 MD_COUNTER_OFFSET(op); \
379 LASSERT(coffset < (obdx)->md_stats->ls_num); \
380 lprocfs_counter_incr((obdx)->md_stats, coffset); \
383 #define EXP_MD_COUNTER_INCREMENT(export, op) \
384 if ((export)->exp_obd->obd_stats != NULL) { \
385 unsigned int coffset; \
386 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
387 MD_COUNTER_OFFSET(op); \
388 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
389 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
390 if ((export)->exp_md_stats != NULL) \
391 lprocfs_counter_incr( \
392 (export)->exp_md_stats, coffset); \
396 #define OBD_COUNTER_OFFSET(op)
397 #define OBD_COUNTER_INCREMENT(obd, op)
398 #define EXP_COUNTER_INCREMENT(exp, op)
399 #define MD_COUNTER_INCREMENT(obd, op)
400 #define EXP_MD_COUNTER_INCREMENT(exp, op)
403 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
405 /* Always add in ldlm_stats */
406 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
407 ,LPROCFS_STATS_FLAG_NOPERCPU);
408 if (tmp->nid_ldlm_stats == NULL)
411 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
413 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
414 tmp->nid_ldlm_stats);
417 #define OBD_CHECK_MD_OP(obd, op, err) \
419 if (!OBT(obd) || !MDP((obd), op)) { \
421 CERROR("md_" #op ": dev %s/%d no operation\n", \
422 obd->obd_name, obd->obd_minor); \
427 #define EXP_CHECK_MD_OP(exp, op) \
429 if ((exp) == NULL) { \
430 CERROR("obd_" #op ": NULL export\n"); \
433 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
434 CERROR("obd_" #op ": cleaned up obd\n"); \
435 RETURN(-EOPNOTSUPP); \
437 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
438 CERROR("obd_" #op ": dev %s/%d no operation\n", \
439 (exp)->exp_obd->obd_name, \
440 (exp)->exp_obd->obd_minor); \
441 RETURN(-EOPNOTSUPP); \
446 #define OBD_CHECK_DT_OP(obd, op, err) \
448 if (!OBT(obd) || !OBP((obd), op)) { \
450 CERROR("obd_" #op ": dev %d no operation\n", \
456 #define EXP_CHECK_DT_OP(exp, op) \
458 if ((exp) == NULL) { \
459 CERROR("obd_" #op ": NULL export\n"); \
462 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
463 CERROR("obd_" #op ": cleaned up obd\n"); \
464 RETURN(-EOPNOTSUPP); \
466 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
467 CERROR("obd_" #op ": dev %d no operation\n", \
468 (exp)->exp_obd->obd_minor); \
469 RETURN(-EOPNOTSUPP); \
473 #define CTXT_CHECK_OP(ctxt, op, err) \
475 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
477 CERROR("lop_" #op ": dev %d no operation\n", \
478 ctxt->loc_obd->obd_minor); \
483 static inline int class_devno_max(void)
485 return MAX_OBD_DEVICES;
488 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
489 void *key, __u32 *vallen, void *val,
490 struct lov_stripe_md *lsm)
495 EXP_CHECK_DT_OP(exp, get_info);
496 EXP_COUNTER_INCREMENT(exp, get_info);
498 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
502 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
503 void *key, obd_count vallen, void *val,
504 struct ptlrpc_request_set *set)
509 EXP_CHECK_DT_OP(exp, set_info_async);
510 EXP_COUNTER_INCREMENT(exp, set_info_async);
512 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
518 * obd-lu integration.
520 * Functionality is being moved into new lu_device-based layering, but some
521 * pieces of configuration process are still based on obd devices.
523 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
524 * subsume ->o_setup() methods of obd devices they replace. The same for
525 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
526 * result, obd_setup() and obd_process_config() branch and call one XOR
529 * Yet neither lu_device_type_operations::ldto_device_fini() nor
530 * lu_device_type_operations::ldto_device_free() fully implement the
531 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
532 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
535 #define DECLARE_LU_VARS(ldt, d) \
536 struct lu_device_type *ldt; \
539 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
542 DECLARE_LU_VARS(ldt, d);
545 ldt = obd->obd_type->typ_lu;
547 struct lu_context session_ctx;
549 lu_context_init(&session_ctx, LCT_SESSION);
550 session_ctx.lc_thread = NULL;
551 lu_context_enter(&session_ctx);
553 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
555 env.le_ses = &session_ctx;
556 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
565 lu_context_exit(&session_ctx);
566 lu_context_fini(&session_ctx);
569 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
570 OBD_COUNTER_INCREMENT(obd, setup);
571 rc = OBP(obd, setup)(obd, cfg);
576 static inline int obd_precleanup(struct obd_device *obd,
577 enum obd_cleanup_stage cleanup_stage)
580 DECLARE_LU_VARS(ldt, d);
584 ldt = obd->obd_type->typ_lu;
586 if (ldt != NULL && d != NULL) {
587 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
590 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
592 ldt->ldt_ops->ldto_device_fini(&env, d);
597 OBD_CHECK_DT_OP(obd, precleanup, 0);
598 OBD_COUNTER_INCREMENT(obd, precleanup);
600 rc = OBP(obd, precleanup)(obd, cleanup_stage);
604 static inline int obd_cleanup(struct obd_device *obd)
607 DECLARE_LU_VARS(ldt, d);
612 ldt = obd->obd_type->typ_lu;
614 if (ldt != NULL && d != NULL) {
617 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
619 ldt->ldt_ops->ldto_device_free(&env, d);
621 obd->obd_lu_dev = NULL;
624 OBD_CHECK_DT_OP(obd, cleanup, 0);
625 OBD_COUNTER_INCREMENT(obd, cleanup);
627 rc = OBP(obd, cleanup)(obd);
631 static inline void obd_cleanup_client_import(struct obd_device *obd)
635 /* If we set up but never connected, the
636 client import will not have been cleaned. */
637 cfs_down_write(&obd->u.cli.cl_sem);
638 if (obd->u.cli.cl_import) {
639 struct obd_import *imp;
640 imp = obd->u.cli.cl_import;
641 CDEBUG(D_CONFIG, "%s: client import never connected\n",
643 ptlrpc_invalidate_import(imp);
644 if (imp->imp_rq_pool) {
645 ptlrpc_free_rq_pool(imp->imp_rq_pool);
646 imp->imp_rq_pool = NULL;
648 class_destroy_import(imp);
649 obd->u.cli.cl_import = NULL;
651 cfs_up_write(&obd->u.cli.cl_sem);
657 obd_process_config(struct obd_device *obd, int datalen, void *data)
660 DECLARE_LU_VARS(ldt, d);
665 obd->obd_process_conf = 1;
666 ldt = obd->obd_type->typ_lu;
668 if (ldt != NULL && d != NULL) {
671 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
673 rc = d->ld_ops->ldo_process_config(&env, d, data);
677 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
678 rc = OBP(obd, process_config)(obd, datalen, data);
680 OBD_COUNTER_INCREMENT(obd, process_config);
681 obd->obd_process_conf = 0;
686 /* Pack an in-memory MD struct for storage on disk.
687 * Returns +ve size of packed MD (0 for free), or -ve error.
689 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
690 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
691 * If @*disk_tgt == NULL, it will be allocated
693 static inline int obd_packmd(struct obd_export *exp,
694 struct lov_mds_md **disk_tgt,
695 struct lov_stripe_md *mem_src)
700 EXP_CHECK_DT_OP(exp, packmd);
701 EXP_COUNTER_INCREMENT(exp, packmd);
703 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
707 static inline int obd_size_diskmd(struct obd_export *exp,
708 struct lov_stripe_md *mem_src)
710 return obd_packmd(exp, NULL, mem_src);
713 /* helper functions */
714 static inline int obd_alloc_diskmd(struct obd_export *exp,
715 struct lov_mds_md **disk_tgt)
718 LASSERT(*disk_tgt == NULL);
719 return obd_packmd(exp, disk_tgt, NULL);
722 static inline int obd_free_diskmd(struct obd_export *exp,
723 struct lov_mds_md **disk_tgt)
727 return obd_packmd(exp, disk_tgt, NULL);
730 /* Unpack an MD struct from disk to in-memory format.
731 * Returns +ve size of unpacked MD (0 for free), or -ve error.
733 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
734 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
735 * If @*mem_tgt == NULL, it will be allocated
737 static inline int obd_unpackmd(struct obd_export *exp,
738 struct lov_stripe_md **mem_tgt,
739 struct lov_mds_md *disk_src,
745 EXP_CHECK_DT_OP(exp, unpackmd);
746 EXP_COUNTER_INCREMENT(exp, unpackmd);
748 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
752 /* helper functions */
753 static inline int obd_alloc_memmd(struct obd_export *exp,
754 struct lov_stripe_md **mem_tgt)
757 LASSERT(*mem_tgt == NULL);
758 return obd_unpackmd(exp, mem_tgt, NULL, 0);
761 static inline int obd_free_memmd(struct obd_export *exp,
762 struct lov_stripe_md **mem_tgt)
768 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
773 static inline int obd_precreate(struct obd_export *exp)
778 EXP_CHECK_DT_OP(exp, precreate);
779 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
781 rc = OBP(exp->exp_obd, precreate)(exp);
785 static inline int obd_create_async(struct obd_export *exp,
786 struct obd_info *oinfo,
787 struct lov_stripe_md **ea,
788 struct obd_trans_info *oti)
793 EXP_CHECK_DT_OP(exp, create_async);
794 EXP_COUNTER_INCREMENT(exp, create_async);
796 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
800 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
801 struct lov_stripe_md **ea,
802 struct obd_trans_info *oti)
807 EXP_CHECK_DT_OP(exp, create);
808 EXP_COUNTER_INCREMENT(exp, create);
810 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
814 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
815 struct lov_stripe_md *ea,
816 struct obd_trans_info *oti,
817 struct obd_export *md_exp, void *capa)
822 EXP_CHECK_DT_OP(exp, destroy);
823 EXP_COUNTER_INCREMENT(exp, destroy);
825 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
829 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
834 EXP_CHECK_DT_OP(exp, getattr);
835 EXP_COUNTER_INCREMENT(exp, getattr);
837 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
841 static inline int obd_getattr_async(struct obd_export *exp,
842 struct obd_info *oinfo,
843 struct ptlrpc_request_set *set)
848 EXP_CHECK_DT_OP(exp, getattr_async);
849 EXP_COUNTER_INCREMENT(exp, getattr_async);
851 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
855 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
856 struct obd_trans_info *oti)
861 EXP_CHECK_DT_OP(exp, setattr);
862 EXP_COUNTER_INCREMENT(exp, setattr);
864 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
868 /* This performs all the requests set init/wait/destroy actions. */
869 static inline int obd_setattr_rqset(struct obd_export *exp,
870 struct obd_info *oinfo,
871 struct obd_trans_info *oti)
873 struct ptlrpc_request_set *set = NULL;
877 EXP_CHECK_DT_OP(exp, setattr_async);
878 EXP_COUNTER_INCREMENT(exp, setattr_async);
880 set = ptlrpc_prep_set();
884 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
886 rc = ptlrpc_set_wait(set);
887 ptlrpc_set_destroy(set);
891 /* This adds all the requests into @set if @set != NULL, otherwise
892 all requests are sent asynchronously without waiting for response. */
893 static inline int obd_setattr_async(struct obd_export *exp,
894 struct obd_info *oinfo,
895 struct obd_trans_info *oti,
896 struct ptlrpc_request_set *set)
901 EXP_CHECK_DT_OP(exp, setattr_async);
902 EXP_COUNTER_INCREMENT(exp, setattr_async);
904 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
908 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
911 struct obd_device *obd = imp->imp_obd;
915 OBD_CHECK_DEV_ACTIVE(obd);
916 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
917 OBD_COUNTER_INCREMENT(obd, add_conn);
919 rc = OBP(obd, add_conn)(imp, uuid, priority);
923 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
925 struct obd_device *obd = imp->imp_obd;
929 OBD_CHECK_DEV_ACTIVE(obd);
930 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
931 OBD_COUNTER_INCREMENT(obd, del_conn);
933 rc = OBP(obd, del_conn)(imp, uuid);
937 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
939 struct obd_uuid *uuid;
942 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
943 EXP_COUNTER_INCREMENT(exp, get_uuid);
945 uuid = OBP(exp->exp_obd, get_uuid)(exp);
949 /** Create a new /a exp on device /a obd for the uuid /a cluuid
950 * @param exp New export handle
951 * @param d Connect data, supported flags are set, flags also understood
952 * by obd are returned.
954 static inline int obd_connect(const struct lu_env *env,
955 struct obd_export **exp,struct obd_device *obd,
956 struct obd_uuid *cluuid,
957 struct obd_connect_data *data,
961 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
965 OBD_CHECK_DEV_ACTIVE(obd);
966 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
967 OBD_COUNTER_INCREMENT(obd, connect);
969 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
970 /* check that only subset is granted */
971 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
972 data->ocd_connect_flags));
976 static inline int obd_reconnect(const struct lu_env *env,
977 struct obd_export *exp,
978 struct obd_device *obd,
979 struct obd_uuid *cluuid,
980 struct obd_connect_data *d,
984 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
989 OBD_CHECK_DEV_ACTIVE(obd);
990 OBD_CHECK_DT_OP(obd, reconnect, 0);
991 OBD_COUNTER_INCREMENT(obd, reconnect);
993 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
994 /* check that only subset is granted */
995 LASSERT(ergo(d != NULL,
996 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
1000 static inline int obd_disconnect(struct obd_export *exp)
1005 EXP_CHECK_DT_OP(exp, disconnect);
1006 EXP_COUNTER_INCREMENT(exp, disconnect);
1008 rc = OBP(exp->exp_obd, disconnect)(exp);
1012 static inline int obd_fid_init(struct obd_export *exp)
1017 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
1018 EXP_COUNTER_INCREMENT(exp, fid_init);
1020 rc = OBP(exp->exp_obd, fid_init)(exp);
1024 static inline int obd_fid_fini(struct obd_export *exp)
1029 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
1030 EXP_COUNTER_INCREMENT(exp, fid_fini);
1032 rc = OBP(exp->exp_obd, fid_fini)(exp);
1036 static inline int obd_fid_alloc(struct obd_export *exp,
1038 struct md_op_data *op_data)
1043 EXP_CHECK_DT_OP(exp, fid_alloc);
1044 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1046 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1050 static inline int obd_fid_delete(struct obd_export *exp,
1051 const struct lu_fid *fid)
1056 EXP_CHECK_DT_OP(exp, fid_delete);
1057 EXP_COUNTER_INCREMENT(exp, fid_delete);
1059 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
1063 static inline int obd_ping(struct obd_export *exp)
1068 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1069 EXP_COUNTER_INCREMENT(exp, ping);
1071 rc = OBP(exp->exp_obd, ping)(exp);
1075 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1080 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1081 OBD_COUNTER_INCREMENT(obd, pool_new);
1083 rc = OBP(obd, pool_new)(obd, poolname);
1087 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1092 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1093 OBD_COUNTER_INCREMENT(obd, pool_del);
1095 rc = OBP(obd, pool_del)(obd, poolname);
1099 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1104 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1105 OBD_COUNTER_INCREMENT(obd, pool_add);
1107 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1111 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1116 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1117 OBD_COUNTER_INCREMENT(obd, pool_rem);
1119 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1123 static inline void obd_getref(struct obd_device *obd)
1126 if (OBT(obd) && OBP(obd, getref)) {
1127 OBD_COUNTER_INCREMENT(obd, getref);
1128 OBP(obd, getref)(obd);
1133 static inline void obd_putref(struct obd_device *obd)
1136 if (OBT(obd) && OBP(obd, putref)) {
1137 OBD_COUNTER_INCREMENT(obd, putref);
1138 OBP(obd, putref)(obd);
1143 static inline int obd_init_export(struct obd_export *exp)
1148 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1149 OBP((exp)->exp_obd, init_export))
1150 rc = OBP(exp->exp_obd, init_export)(exp);
1154 static inline int obd_destroy_export(struct obd_export *exp)
1157 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1158 OBP((exp)->exp_obd, destroy_export))
1159 OBP(exp->exp_obd, destroy_export)(exp);
1163 static inline int obd_extent_calc(struct obd_export *exp,
1164 struct lov_stripe_md *md,
1165 int cmd, obd_off *offset)
1169 EXP_CHECK_DT_OP(exp, extent_calc);
1170 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1174 static inline struct dentry *
1175 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1177 LASSERT(exp->exp_obd);
1179 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1184 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1186 LASSERT(exp->exp_obd);
1187 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1189 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1190 dentry, exp->exp_obd);
1195 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1196 * If the cache is older than @max_age we will get a new value from the
1197 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1198 static inline int obd_statfs_async(struct obd_device *obd,
1199 struct obd_info *oinfo,
1201 struct ptlrpc_request_set *rqset)
1209 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1210 OBD_COUNTER_INCREMENT(obd, statfs);
1212 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1213 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1214 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1215 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1217 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1218 " objects "LPU64"/"LPU64"\n",
1219 obd->obd_name, &obd->obd_osfs,
1220 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1221 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1222 cfs_spin_lock(&obd->obd_osfs_lock);
1223 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1224 cfs_spin_unlock(&obd->obd_osfs_lock);
1225 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1226 if (oinfo->oi_cb_up)
1227 oinfo->oi_cb_up(oinfo, 0);
1232 static inline int obd_statfs_rqset(struct obd_device *obd,
1233 struct obd_statfs *osfs, __u64 max_age,
1236 struct ptlrpc_request_set *set = NULL;
1237 struct obd_info oinfo = { { { 0 } } };
1241 set = ptlrpc_prep_set();
1245 oinfo.oi_osfs = osfs;
1246 oinfo.oi_flags = flags;
1247 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1249 rc = ptlrpc_set_wait(set);
1250 ptlrpc_set_destroy(set);
1254 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1255 * If the cache is older than @max_age we will get a new value from the
1256 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1257 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1258 __u64 max_age, __u32 flags)
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)(obd, osfs, max_age, flags);
1274 cfs_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 cfs_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 cfs_spin_lock(&obd->obd_osfs_lock);
1286 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1287 cfs_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)(exp, oinfo, start, end, set);
1308 rc = ptlrpc_set_wait(set);
1309 ptlrpc_set_destroy(set);
1313 static inline int obd_sync(struct obd_export *exp, struct obd_info *oinfo,
1314 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)(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)(exp, oinfo, oti, set);
1344 rc = ptlrpc_set_wait(set);
1345 ptlrpc_set_destroy(set);
1349 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1350 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)(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(int cmd, struct obd_export *exp, struct obdo *oa,
1384 int objcount, struct obd_ioobj *obj,
1385 struct niobuf_remote *remote, int *pages,
1386 struct niobuf_local *local,
1387 struct obd_trans_info *oti,
1388 struct lustre_capa *capa)
1393 EXP_CHECK_DT_OP(exp, preprw);
1394 EXP_COUNTER_INCREMENT(exp, preprw);
1396 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1397 pages, local, oti, capa);
1401 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1402 int objcount, struct obd_ioobj *obj,
1403 struct niobuf_remote *rnb, int pages,
1404 struct niobuf_local *local,
1405 struct obd_trans_info *oti, int rc)
1409 EXP_CHECK_DT_OP(exp, commitrw);
1410 EXP_COUNTER_INCREMENT(exp, commitrw);
1412 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1413 rnb, pages, local, oti, rc);
1417 static inline int obd_merge_lvb(struct obd_export *exp,
1418 struct lov_stripe_md *lsm,
1419 struct ost_lvb *lvb, int kms_only)
1424 EXP_CHECK_DT_OP(exp, merge_lvb);
1425 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1427 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1431 static inline int obd_adjust_kms(struct obd_export *exp,
1432 struct lov_stripe_md *lsm, obd_off size,
1438 EXP_CHECK_DT_OP(exp, adjust_kms);
1439 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1441 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1445 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1446 int len, void *karg, void *uarg)
1451 EXP_CHECK_DT_OP(exp, iocontrol);
1452 EXP_COUNTER_INCREMENT(exp, iocontrol);
1454 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1458 static inline int obd_enqueue_rqset(struct obd_export *exp,
1459 struct obd_info *oinfo,
1460 struct ldlm_enqueue_info *einfo)
1462 struct ptlrpc_request_set *set = NULL;
1466 EXP_CHECK_DT_OP(exp, enqueue);
1467 EXP_COUNTER_INCREMENT(exp, enqueue);
1469 set = ptlrpc_prep_set();
1473 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1475 rc = ptlrpc_set_wait(set);
1476 ptlrpc_set_destroy(set);
1480 static inline int obd_enqueue(struct obd_export *exp,
1481 struct obd_info *oinfo,
1482 struct ldlm_enqueue_info *einfo,
1483 struct ptlrpc_request_set *set)
1488 EXP_CHECK_DT_OP(exp, enqueue);
1489 EXP_COUNTER_INCREMENT(exp, enqueue);
1491 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1495 static inline int obd_change_cbdata(struct obd_export *exp,
1496 struct lov_stripe_md *lsm,
1497 ldlm_iterator_t it, void *data)
1502 EXP_CHECK_DT_OP(exp, change_cbdata);
1503 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1505 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1509 static inline int obd_find_cbdata(struct obd_export *exp,
1510 struct lov_stripe_md *lsm,
1511 ldlm_iterator_t it, void *data)
1516 EXP_CHECK_DT_OP(exp, find_cbdata);
1517 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1519 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1523 static inline int obd_cancel(struct obd_export *exp,
1524 struct lov_stripe_md *ea, __u32 mode,
1525 struct lustre_handle *lockh)
1530 EXP_CHECK_DT_OP(exp, cancel);
1531 EXP_COUNTER_INCREMENT(exp, cancel);
1533 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1537 static inline int obd_cancel_unused(struct obd_export *exp,
1538 struct lov_stripe_md *ea,
1539 ldlm_cancel_flags_t flags,
1545 EXP_CHECK_DT_OP(exp, cancel_unused);
1546 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1548 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1552 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1553 struct obd_capa *oc, struct obd_client_handle *handle,
1559 EXP_CHECK_DT_OP(exp, pin);
1560 EXP_COUNTER_INCREMENT(exp, pin);
1562 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1566 static inline int obd_unpin(struct obd_export *exp,
1567 struct obd_client_handle *handle, int flag)
1572 EXP_CHECK_DT_OP(exp, unpin);
1573 EXP_COUNTER_INCREMENT(exp, unpin);
1575 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1580 static inline void obd_import_event(struct obd_device *obd,
1581 struct obd_import *imp,
1582 enum obd_import_event event)
1586 CERROR("NULL device\n");
1590 if (obd->obd_set_up && OBP(obd, import_event)) {
1591 OBD_COUNTER_INCREMENT(obd, import_event);
1592 OBP(obd, import_event)(obd, imp, event);
1597 static inline int obd_llog_connect(struct obd_export *exp,
1598 struct llogd_conn_body *body)
1603 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1604 EXP_COUNTER_INCREMENT(exp, llog_connect);
1606 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1611 static inline int obd_notify(struct obd_device *obd,
1612 struct obd_device *watched,
1613 enum obd_notify_event ev,
1620 /* the check for async_recov is a complete hack - I'm hereby
1621 overloading the meaning to also mean "this was called from
1622 mds_postsetup". I know that my mds is able to handle notifies
1623 by this point, and it needs to get them to execute mds_postrecov. */
1624 if (!obd->obd_set_up && !obd->obd_async_recov) {
1625 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1629 if (!OBP(obd, notify)) {
1630 CERROR("obd %s has no notify handler\n", obd->obd_name);
1634 OBD_COUNTER_INCREMENT(obd, notify);
1635 rc = OBP(obd, notify)(obd, watched, ev, data);
1639 static inline int obd_notify_observer(struct obd_device *observer,
1640 struct obd_device *observed,
1641 enum obd_notify_event ev,
1647 struct obd_notify_upcall *onu;
1649 if (observer->obd_observer)
1650 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1654 * Also, call non-obd listener, if any
1656 onu = &observer->obd_upcall;
1657 if (onu->onu_upcall != NULL)
1658 rc2 = onu->onu_upcall(observer, observed, ev,
1659 onu->onu_owner, NULL);
1663 return rc1 ? rc1 : rc2;
1666 static inline int obd_quotacheck(struct obd_export *exp,
1667 struct obd_quotactl *oqctl)
1672 EXP_CHECK_DT_OP(exp, quotacheck);
1673 EXP_COUNTER_INCREMENT(exp, quotacheck);
1675 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1679 static inline int obd_quotactl(struct obd_export *exp,
1680 struct obd_quotactl *oqctl)
1685 EXP_CHECK_DT_OP(exp, quotactl);
1686 EXP_COUNTER_INCREMENT(exp, quotactl);
1688 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1692 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1693 struct quota_adjust_qunit *oqaq,
1694 struct lustre_quota_ctxt *qctxt,
1695 struct ptlrpc_request_set *set)
1697 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1698 struct timeval work_start;
1699 struct timeval work_end;
1705 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1707 cfs_gettimeofday(&work_start);
1709 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1710 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1712 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt, set);
1714 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1716 cfs_gettimeofday(&work_end);
1717 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1718 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1725 static inline int obd_health_check(struct obd_device *obd)
1727 /* returns: 0 on healthy
1728 * >0 on unhealthy + reason code/flag
1729 * however the only suppored reason == 1 right now
1730 * We'll need to define some better reasons
1731 * or flags in the future.
1737 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1738 if (obd == NULL || !OBT(obd)) {
1739 CERROR("cleaned up obd\n");
1740 RETURN(-EOPNOTSUPP);
1742 if (!obd->obd_set_up || obd->obd_stopping)
1744 if (!OBP(obd, health_check))
1747 rc = OBP(obd, health_check)(obd);
1751 static inline int obd_register_observer(struct obd_device *obd,
1752 struct obd_device *observer)
1756 cfs_down_write(&obd->obd_observer_link_sem);
1757 if (obd->obd_observer && observer) {
1758 cfs_up_write(&obd->obd_observer_link_sem);
1761 obd->obd_observer = observer;
1762 cfs_up_write(&obd->obd_observer_link_sem);
1766 static inline int obd_pin_observer(struct obd_device *obd,
1767 struct obd_device **observer)
1770 cfs_down_read(&obd->obd_observer_link_sem);
1771 if (!obd->obd_observer) {
1773 cfs_up_read(&obd->obd_observer_link_sem);
1776 *observer = obd->obd_observer;
1780 static inline int obd_unpin_observer(struct obd_device *obd)
1783 cfs_up_read(&obd->obd_observer_link_sem);
1788 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1789 obd_page_removal_cb_t cb,
1790 obd_pin_extent_cb pin_cb)
1795 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1796 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1798 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1802 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1803 obd_page_removal_cb_t cb)
1808 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1809 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1811 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1815 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1816 obd_lock_cancel_cb cb)
1821 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1822 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1824 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1828 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1829 obd_lock_cancel_cb cb)
1834 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1835 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1837 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1842 /* metadata helpers */
1843 static inline int md_getstatus(struct obd_export *exp,
1844 struct lu_fid *fid, struct obd_capa **pc)
1849 EXP_CHECK_MD_OP(exp, getstatus);
1850 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1851 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1855 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1856 struct ptlrpc_request **request)
1860 EXP_CHECK_MD_OP(exp, getattr);
1861 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1862 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1866 static inline int md_change_cbdata(struct obd_export *exp,
1867 const struct lu_fid *fid,
1868 ldlm_iterator_t it, void *data)
1872 EXP_CHECK_MD_OP(exp, change_cbdata);
1873 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1874 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1878 static inline int md_find_cbdata(struct obd_export *exp,
1879 const struct lu_fid *fid,
1880 ldlm_iterator_t it, void *data)
1884 EXP_CHECK_MD_OP(exp, find_cbdata);
1885 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1886 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1890 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1891 struct md_open_data *mod,
1892 struct ptlrpc_request **request)
1896 EXP_CHECK_MD_OP(exp, close);
1897 EXP_MD_COUNTER_INCREMENT(exp, close);
1898 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1902 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1903 const void *data, int datalen, int mode, __u32 uid,
1904 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1905 struct ptlrpc_request **request)
1909 EXP_CHECK_MD_OP(exp, create);
1910 EXP_MD_COUNTER_INCREMENT(exp, create);
1911 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1912 uid, gid, cap_effective, rdev, request);
1916 static inline int md_done_writing(struct obd_export *exp,
1917 struct md_op_data *op_data,
1918 struct md_open_data *mod)
1922 EXP_CHECK_MD_OP(exp, done_writing);
1923 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1924 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1928 static inline int md_enqueue(struct obd_export *exp,
1929 struct ldlm_enqueue_info *einfo,
1930 struct lookup_intent *it,
1931 struct md_op_data *op_data,
1932 struct lustre_handle *lockh,
1933 void *lmm, int lmmsize,
1934 struct ptlrpc_request **req,
1935 int extra_lock_flags)
1939 EXP_CHECK_MD_OP(exp, enqueue);
1940 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1941 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1942 lmm, lmmsize, req, extra_lock_flags);
1946 static inline int md_getattr_name(struct obd_export *exp,
1947 struct md_op_data *op_data,
1948 struct ptlrpc_request **request)
1952 EXP_CHECK_MD_OP(exp, getattr_name);
1953 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1954 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1958 static inline int md_intent_lock(struct obd_export *exp,
1959 struct md_op_data *op_data, void *lmm,
1960 int lmmsize, struct lookup_intent *it,
1961 int flags, struct ptlrpc_request **reqp,
1962 ldlm_blocking_callback cb_blocking,
1963 int extra_lock_flags)
1967 EXP_CHECK_MD_OP(exp, intent_lock);
1968 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1969 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1970 it, flags, reqp, cb_blocking,
1975 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1976 struct ptlrpc_request **request)
1980 EXP_CHECK_MD_OP(exp, link);
1981 EXP_MD_COUNTER_INCREMENT(exp, link);
1982 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1986 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1987 const char *old, int oldlen, const char *new,
1988 int newlen, struct ptlrpc_request **request)
1992 EXP_CHECK_MD_OP(exp, rename);
1993 EXP_MD_COUNTER_INCREMENT(exp, rename);
1994 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1999 static inline int md_is_subdir(struct obd_export *exp,
2000 const struct lu_fid *pfid,
2001 const struct lu_fid *cfid,
2002 struct ptlrpc_request **request)
2006 EXP_CHECK_MD_OP(exp, is_subdir);
2007 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
2008 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
2012 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
2013 void *ea, int ealen, void *ea2, int ea2len,
2014 struct ptlrpc_request **request,
2015 struct md_open_data **mod)
2019 EXP_CHECK_MD_OP(exp, setattr);
2020 EXP_MD_COUNTER_INCREMENT(exp, setattr);
2021 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
2022 ea2, ea2len, request, mod);
2026 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
2027 struct obd_capa *oc, struct ptlrpc_request **request)
2031 EXP_CHECK_MD_OP(exp, sync);
2032 EXP_MD_COUNTER_INCREMENT(exp, sync);
2033 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
2037 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
2038 struct obd_capa *oc, __u64 offset,
2039 struct page **pages, unsigned npages,
2040 struct ptlrpc_request **request)
2044 EXP_CHECK_MD_OP(exp, readpage);
2045 EXP_MD_COUNTER_INCREMENT(exp, readpage);
2046 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, pages, npages,
2051 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
2052 struct ptlrpc_request **request)
2056 EXP_CHECK_MD_OP(exp, unlink);
2057 EXP_MD_COUNTER_INCREMENT(exp, unlink);
2058 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
2062 static inline int md_get_lustre_md(struct obd_export *exp,
2063 struct ptlrpc_request *req,
2064 struct obd_export *dt_exp,
2065 struct obd_export *md_exp,
2066 struct lustre_md *md)
2069 EXP_CHECK_MD_OP(exp, get_lustre_md);
2070 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
2071 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
2074 static inline int md_free_lustre_md(struct obd_export *exp,
2075 struct lustre_md *md)
2078 EXP_CHECK_MD_OP(exp, free_lustre_md);
2079 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2080 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2083 static inline int md_setxattr(struct obd_export *exp,
2084 const struct lu_fid *fid, struct obd_capa *oc,
2085 obd_valid valid, const char *name,
2086 const char *input, int input_size,
2087 int output_size, int flags, __u32 suppgid,
2088 struct ptlrpc_request **request)
2091 EXP_CHECK_MD_OP(exp, setxattr);
2092 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2093 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2094 input_size, output_size, flags,
2098 static inline int md_getxattr(struct obd_export *exp,
2099 const struct lu_fid *fid, struct obd_capa *oc,
2100 obd_valid valid, const char *name,
2101 const char *input, int input_size,
2102 int output_size, int flags,
2103 struct ptlrpc_request **request)
2106 EXP_CHECK_MD_OP(exp, getxattr);
2107 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2108 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2109 input_size, output_size, flags,
2113 static inline int md_set_open_replay_data(struct obd_export *exp,
2114 struct obd_client_handle *och,
2115 struct ptlrpc_request *open_req)
2118 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2119 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2120 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2123 static inline int md_clear_open_replay_data(struct obd_export *exp,
2124 struct obd_client_handle *och)
2127 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2128 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2129 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2132 static inline int md_set_lock_data(struct obd_export *exp,
2133 __u64 *lockh, void *data, __u32 *bits)
2136 EXP_CHECK_MD_OP(exp, set_lock_data);
2137 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2138 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2141 static inline int md_cancel_unused(struct obd_export *exp,
2142 const struct lu_fid *fid,
2143 ldlm_policy_data_t *policy,
2145 ldlm_cancel_flags_t flags,
2151 EXP_CHECK_MD_OP(exp, cancel_unused);
2152 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2154 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2159 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2160 const struct lu_fid *fid,
2162 ldlm_policy_data_t *policy,
2164 struct lustre_handle *lockh)
2167 EXP_CHECK_MD_OP(exp, lock_match);
2168 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2169 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2170 policy, mode, lockh));
2173 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2174 int def_asize, int cookiesize)
2177 EXP_CHECK_MD_OP(exp, init_ea_size);
2178 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2179 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2183 static inline int md_get_remote_perm(struct obd_export *exp,
2184 const struct lu_fid *fid,
2185 struct obd_capa *oc, __u32 suppgid,
2186 struct ptlrpc_request **request)
2189 EXP_CHECK_MD_OP(exp, get_remote_perm);
2190 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2191 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2195 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2200 EXP_CHECK_MD_OP(exp, renew_capa);
2201 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2202 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2206 static inline int md_unpack_capa(struct obd_export *exp,
2207 struct ptlrpc_request *req,
2208 const struct req_msg_field *field,
2209 struct obd_capa **oc)
2213 EXP_CHECK_MD_OP(exp, unpack_capa);
2214 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2215 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2219 static inline int md_intent_getattr_async(struct obd_export *exp,
2220 struct md_enqueue_info *minfo,
2221 struct ldlm_enqueue_info *einfo)
2225 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2226 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2227 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2231 static inline int md_revalidate_lock(struct obd_export *exp,
2232 struct lookup_intent *it,
2237 EXP_CHECK_MD_OP(exp, revalidate_lock);
2238 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2239 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2244 /* OBD Metadata Support */
2246 extern int obd_init_caches(void);
2247 extern void obd_cleanup_caches(void);
2249 /* support routines */
2250 extern cfs_mem_cache_t *obdo_cachep;
2252 #define OBDO_ALLOC(ptr) \
2254 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, CFS_ALLOC_IO); \
2257 #define OBDO_FREE(ptr) \
2259 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2263 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2265 /* something here */
2268 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2270 /* something here */
2273 /* I'm as embarrassed about this as you are.
2275 * <shaver> // XXX do not look into _superhack with remaining eye
2276 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2277 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2280 extern void obd_sysctl_init (void);
2281 extern void obd_sysctl_clean (void);
2284 typedef __u8 class_uuid_t[16];
2285 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2288 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2289 int class_add_uuid(const char *uuid, __u64 nid);
2290 int class_del_uuid (const char *uuid);
2291 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
2292 void class_init_uuidlist(void);
2293 void class_exit_uuidlist(void);
2296 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2297 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2300 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2302 #endif /* __LINUX_OBD_CLASS_H */