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,
166 /* list of active configuration logs */
167 struct config_llog_data {
168 struct ldlm_res_id cld_resid;
169 struct config_llog_instance cld_cfg;
170 cfs_list_t cld_list_chain;
171 cfs_atomic_t cld_refcount;
172 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
173 struct obd_export *cld_mgcexp;
174 cfs_mutex_t cld_lock;
176 unsigned int cld_stopping:1, /* we were told to stop
178 cld_lostlock:1; /* lock not requeued */
182 struct lustre_profile {
189 struct lustre_profile *class_get_profile(const char * prof);
190 void class_del_profile(const char *prof);
191 void class_del_profiles(void);
193 #if LUSTRE_TRACKS_LOCK_EXP_REFS
195 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
196 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
197 extern void (*class_export_dump_hook)(struct obd_export *);
201 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
202 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
206 #define class_export_rpc_get(exp) \
208 cfs_atomic_inc(&(exp)->exp_rpc_count); \
209 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
210 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
211 class_export_get(exp); \
214 #define class_export_rpc_put(exp) \
216 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
217 cfs_atomic_dec(&(exp)->exp_rpc_count); \
218 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
219 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
220 class_export_put(exp); \
223 #define class_export_lock_get(exp, lock) \
225 cfs_atomic_inc(&(exp)->exp_locks_count); \
226 __class_export_add_lock_ref(exp, lock); \
227 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
228 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
229 class_export_get(exp); \
232 #define class_export_lock_put(exp, lock) \
234 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
235 cfs_atomic_dec(&(exp)->exp_locks_count); \
236 __class_export_del_lock_ref(exp, lock); \
237 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
238 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
239 class_export_put(exp); \
242 #define class_export_cb_get(exp) \
244 cfs_atomic_inc(&(exp)->exp_cb_count); \
245 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
246 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
247 class_export_get(exp); \
250 #define class_export_cb_put(exp) \
252 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
253 cfs_atomic_dec(&(exp)->exp_cb_count); \
254 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
255 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
256 class_export_put(exp); \
260 struct obd_export *class_export_get(struct obd_export *exp);
261 void class_export_put(struct obd_export *exp);
262 struct obd_export *class_new_export(struct obd_device *obddev,
263 struct obd_uuid *cluuid);
264 void class_unlink_export(struct obd_export *exp);
266 struct obd_import *class_import_get(struct obd_import *);
267 void class_import_put(struct obd_import *);
268 struct obd_import *class_new_import(struct obd_device *obd);
269 void class_destroy_import(struct obd_import *exp);
271 struct obd_type *class_search_type(const char *name);
272 struct obd_type *class_get_type(const char *name);
273 void class_put_type(struct obd_type *type);
274 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
275 struct obd_uuid *cluuid);
276 int class_disconnect(struct obd_export *exp);
277 void class_fail_export(struct obd_export *exp);
278 int class_connected_export(struct obd_export *exp);
279 void class_disconnect_exports(struct obd_device *obddev);
280 int class_manual_cleanup(struct obd_device *obd);
281 void class_disconnect_stale_exports(struct obd_device *,
282 int (*test_export)(struct obd_export *));
283 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
285 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
286 (obd->obd_force ? OBD_OPT_FORCE : 0) |
287 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
291 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
293 LASSERT(exp->exp_obd);
294 return exp->exp_obd->u.obt.obt_lut;
297 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
299 LASSERT(obd->u.obt.obt_lut);
300 return &obd->u.obt.obt_lut->lut_lsd;
303 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
304 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
305 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
306 unsigned int ia_valid);
307 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
308 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
309 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
312 #define OBT(dev) (dev)->obd_type
313 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
314 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
315 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
317 /* Ensure obd_setup: used for cleanup which must be called
318 while obd is stopping */
319 #define OBD_CHECK_DEV(obd) \
322 CERROR("NULL device\n"); \
327 /* ensure obd_setup and !obd_stopping */
328 #define OBD_CHECK_DEV_ACTIVE(obd) \
330 OBD_CHECK_DEV(obd); \
331 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
332 CERROR("Device %d not setup\n", \
340 #define OBD_COUNTER_OFFSET(op) \
341 ((offsetof(struct obd_ops, o_ ## op) - \
342 offsetof(struct obd_ops, o_iocontrol)) \
343 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
345 #define OBD_COUNTER_INCREMENT(obdx, op) \
346 if ((obdx)->obd_stats != NULL) { \
347 unsigned int coffset; \
348 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
349 OBD_COUNTER_OFFSET(op); \
350 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
351 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
354 #define EXP_COUNTER_INCREMENT(export, op) \
355 if ((export)->exp_obd->obd_stats != NULL) { \
356 unsigned int coffset; \
357 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
358 OBD_COUNTER_OFFSET(op); \
359 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
360 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
361 if ((export)->exp_nid_stats != NULL && \
362 (export)->exp_nid_stats->nid_stats != NULL) \
363 lprocfs_counter_incr( \
364 (export)->exp_nid_stats->nid_stats, coffset);\
367 #define MD_COUNTER_OFFSET(op) \
368 ((offsetof(struct md_ops, m_ ## op) - \
369 offsetof(struct md_ops, m_getstatus)) \
370 / sizeof(((struct md_ops *)(0))->m_getstatus))
372 #define MD_COUNTER_INCREMENT(obdx, op) \
373 if ((obd)->md_stats != NULL) { \
374 unsigned int coffset; \
375 coffset = (unsigned int)((obdx)->md_cntr_base) + \
376 MD_COUNTER_OFFSET(op); \
377 LASSERT(coffset < (obdx)->md_stats->ls_num); \
378 lprocfs_counter_incr((obdx)->md_stats, coffset); \
381 #define EXP_MD_COUNTER_INCREMENT(export, op) \
382 if ((export)->exp_obd->obd_stats != NULL) { \
383 unsigned int coffset; \
384 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
385 MD_COUNTER_OFFSET(op); \
386 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
387 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
388 if ((export)->exp_md_stats != NULL) \
389 lprocfs_counter_incr( \
390 (export)->exp_md_stats, coffset); \
394 #define OBD_COUNTER_OFFSET(op)
395 #define OBD_COUNTER_INCREMENT(obd, op)
396 #define EXP_COUNTER_INCREMENT(exp, op)
397 #define MD_COUNTER_INCREMENT(obd, op)
398 #define EXP_MD_COUNTER_INCREMENT(exp, op)
401 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
403 /* Always add in ldlm_stats */
404 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
405 ,LPROCFS_STATS_FLAG_NOPERCPU);
406 if (tmp->nid_ldlm_stats == NULL)
409 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
411 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
412 tmp->nid_ldlm_stats);
415 #define OBD_CHECK_MD_OP(obd, op, err) \
417 if (!OBT(obd) || !MDP((obd), op)) { \
419 CERROR("md_" #op ": dev %s/%d no operation\n", \
420 obd->obd_name, obd->obd_minor); \
425 #define EXP_CHECK_MD_OP(exp, op) \
427 if ((exp) == NULL) { \
428 CERROR("obd_" #op ": NULL export\n"); \
431 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
432 CERROR("obd_" #op ": cleaned up obd\n"); \
433 RETURN(-EOPNOTSUPP); \
435 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
436 CERROR("obd_" #op ": dev %s/%d no operation\n", \
437 (exp)->exp_obd->obd_name, \
438 (exp)->exp_obd->obd_minor); \
439 RETURN(-EOPNOTSUPP); \
444 #define OBD_CHECK_DT_OP(obd, op, err) \
446 if (!OBT(obd) || !OBP((obd), op)) { \
448 CERROR("obd_" #op ": dev %d no operation\n", \
454 #define EXP_CHECK_DT_OP(exp, op) \
456 if ((exp) == NULL) { \
457 CERROR("obd_" #op ": NULL export\n"); \
460 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
461 CERROR("obd_" #op ": cleaned up obd\n"); \
462 RETURN(-EOPNOTSUPP); \
464 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
465 CERROR("obd_" #op ": dev %d no operation\n", \
466 (exp)->exp_obd->obd_minor); \
467 RETURN(-EOPNOTSUPP); \
471 #define CTXT_CHECK_OP(ctxt, op, err) \
473 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
475 CERROR("lop_" #op ": dev %d no operation\n", \
476 ctxt->loc_obd->obd_minor); \
481 static inline int class_devno_max(void)
483 return MAX_OBD_DEVICES;
486 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
487 void *key, __u32 *vallen, void *val,
488 struct lov_stripe_md *lsm)
493 EXP_CHECK_DT_OP(exp, get_info);
494 EXP_COUNTER_INCREMENT(exp, get_info);
496 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
500 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
501 void *key, obd_count vallen, void *val,
502 struct ptlrpc_request_set *set)
507 EXP_CHECK_DT_OP(exp, set_info_async);
508 EXP_COUNTER_INCREMENT(exp, set_info_async);
510 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
516 * obd-lu integration.
518 * Functionality is being moved into new lu_device-based layering, but some
519 * pieces of configuration process are still based on obd devices.
521 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
522 * subsume ->o_setup() methods of obd devices they replace. The same for
523 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
524 * result, obd_setup() and obd_process_config() branch and call one XOR
527 * Yet neither lu_device_type_operations::ldto_device_fini() nor
528 * lu_device_type_operations::ldto_device_free() fully implement the
529 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
530 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
533 #define DECLARE_LU_VARS(ldt, d) \
534 struct lu_device_type *ldt; \
537 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
540 DECLARE_LU_VARS(ldt, d);
543 ldt = obd->obd_type->typ_lu;
545 struct lu_context session_ctx;
547 lu_context_init(&session_ctx, LCT_SESSION);
548 session_ctx.lc_thread = NULL;
549 lu_context_enter(&session_ctx);
551 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
553 env.le_ses = &session_ctx;
554 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
563 lu_context_exit(&session_ctx);
564 lu_context_fini(&session_ctx);
567 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
568 OBD_COUNTER_INCREMENT(obd, setup);
569 rc = OBP(obd, setup)(obd, cfg);
574 static inline int obd_precleanup(struct obd_device *obd,
575 enum obd_cleanup_stage cleanup_stage)
578 DECLARE_LU_VARS(ldt, d);
582 ldt = obd->obd_type->typ_lu;
584 if (ldt != NULL && d != NULL) {
585 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
588 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
590 ldt->ldt_ops->ldto_device_fini(&env, d);
595 OBD_CHECK_DT_OP(obd, precleanup, 0);
596 OBD_COUNTER_INCREMENT(obd, precleanup);
598 rc = OBP(obd, precleanup)(obd, cleanup_stage);
602 static inline int obd_cleanup(struct obd_device *obd)
605 DECLARE_LU_VARS(ldt, d);
610 ldt = obd->obd_type->typ_lu;
612 if (ldt != NULL && d != NULL) {
615 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
617 ldt->ldt_ops->ldto_device_free(&env, d);
619 obd->obd_lu_dev = NULL;
622 OBD_CHECK_DT_OP(obd, cleanup, 0);
623 OBD_COUNTER_INCREMENT(obd, cleanup);
625 rc = OBP(obd, cleanup)(obd);
629 static inline void obd_cleanup_client_import(struct obd_device *obd)
633 /* If we set up but never connected, the
634 client import will not have been cleaned. */
635 cfs_down_write(&obd->u.cli.cl_sem);
636 if (obd->u.cli.cl_import) {
637 struct obd_import *imp;
638 imp = obd->u.cli.cl_import;
639 CDEBUG(D_CONFIG, "%s: client import never connected\n",
641 ptlrpc_invalidate_import(imp);
642 if (imp->imp_rq_pool) {
643 ptlrpc_free_rq_pool(imp->imp_rq_pool);
644 imp->imp_rq_pool = NULL;
646 class_destroy_import(imp);
647 obd->u.cli.cl_import = NULL;
649 cfs_up_write(&obd->u.cli.cl_sem);
655 obd_process_config(struct obd_device *obd, int datalen, void *data)
658 DECLARE_LU_VARS(ldt, d);
663 obd->obd_process_conf = 1;
664 ldt = obd->obd_type->typ_lu;
666 if (ldt != NULL && d != NULL) {
669 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
671 rc = d->ld_ops->ldo_process_config(&env, d, data);
675 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
676 rc = OBP(obd, process_config)(obd, datalen, data);
678 OBD_COUNTER_INCREMENT(obd, process_config);
679 obd->obd_process_conf = 0;
684 /* Pack an in-memory MD struct for storage on disk.
685 * Returns +ve size of packed MD (0 for free), or -ve error.
687 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
688 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
689 * If @*disk_tgt == NULL, it will be allocated
691 static inline int obd_packmd(struct obd_export *exp,
692 struct lov_mds_md **disk_tgt,
693 struct lov_stripe_md *mem_src)
698 EXP_CHECK_DT_OP(exp, packmd);
699 EXP_COUNTER_INCREMENT(exp, packmd);
701 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
705 static inline int obd_size_diskmd(struct obd_export *exp,
706 struct lov_stripe_md *mem_src)
708 return obd_packmd(exp, NULL, mem_src);
711 /* helper functions */
712 static inline int obd_alloc_diskmd(struct obd_export *exp,
713 struct lov_mds_md **disk_tgt)
716 LASSERT(*disk_tgt == NULL);
717 return obd_packmd(exp, disk_tgt, NULL);
720 static inline int obd_free_diskmd(struct obd_export *exp,
721 struct lov_mds_md **disk_tgt)
725 return obd_packmd(exp, disk_tgt, NULL);
728 /* Unpack an MD struct from disk to in-memory format.
729 * Returns +ve size of unpacked MD (0 for free), or -ve error.
731 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
732 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
733 * If @*mem_tgt == NULL, it will be allocated
735 static inline int obd_unpackmd(struct obd_export *exp,
736 struct lov_stripe_md **mem_tgt,
737 struct lov_mds_md *disk_src,
743 EXP_CHECK_DT_OP(exp, unpackmd);
744 EXP_COUNTER_INCREMENT(exp, unpackmd);
746 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
750 /* helper functions */
751 static inline int obd_alloc_memmd(struct obd_export *exp,
752 struct lov_stripe_md **mem_tgt)
755 LASSERT(*mem_tgt == NULL);
756 return obd_unpackmd(exp, mem_tgt, NULL, 0);
759 static inline int obd_free_memmd(struct obd_export *exp,
760 struct lov_stripe_md **mem_tgt)
766 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
771 static inline int obd_precreate(struct obd_export *exp)
776 EXP_CHECK_DT_OP(exp, precreate);
777 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
779 rc = OBP(exp->exp_obd, precreate)(exp);
783 static inline int obd_create_async(struct obd_export *exp,
784 struct obd_info *oinfo,
785 struct lov_stripe_md **ea,
786 struct obd_trans_info *oti)
791 EXP_CHECK_DT_OP(exp, create_async);
792 EXP_COUNTER_INCREMENT(exp, create_async);
794 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
798 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
799 struct lov_stripe_md **ea,
800 struct obd_trans_info *oti)
805 EXP_CHECK_DT_OP(exp, create);
806 EXP_COUNTER_INCREMENT(exp, create);
808 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
812 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
813 struct lov_stripe_md *ea,
814 struct obd_trans_info *oti,
815 struct obd_export *md_exp, void *capa)
820 EXP_CHECK_DT_OP(exp, destroy);
821 EXP_COUNTER_INCREMENT(exp, destroy);
823 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
827 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
832 EXP_CHECK_DT_OP(exp, getattr);
833 EXP_COUNTER_INCREMENT(exp, getattr);
835 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
839 static inline int obd_getattr_async(struct obd_export *exp,
840 struct obd_info *oinfo,
841 struct ptlrpc_request_set *set)
846 EXP_CHECK_DT_OP(exp, getattr_async);
847 EXP_COUNTER_INCREMENT(exp, getattr_async);
849 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
853 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
854 struct obd_trans_info *oti)
859 EXP_CHECK_DT_OP(exp, setattr);
860 EXP_COUNTER_INCREMENT(exp, setattr);
862 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
866 /* This performs all the requests set init/wait/destroy actions. */
867 static inline int obd_setattr_rqset(struct obd_export *exp,
868 struct obd_info *oinfo,
869 struct obd_trans_info *oti)
871 struct ptlrpc_request_set *set = NULL;
875 EXP_CHECK_DT_OP(exp, setattr_async);
876 EXP_COUNTER_INCREMENT(exp, setattr_async);
878 set = ptlrpc_prep_set();
882 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
884 rc = ptlrpc_set_wait(set);
885 ptlrpc_set_destroy(set);
889 /* This adds all the requests into @set if @set != NULL, otherwise
890 all requests are sent asynchronously without waiting for response. */
891 static inline int obd_setattr_async(struct obd_export *exp,
892 struct obd_info *oinfo,
893 struct obd_trans_info *oti,
894 struct ptlrpc_request_set *set)
899 EXP_CHECK_DT_OP(exp, setattr_async);
900 EXP_COUNTER_INCREMENT(exp, setattr_async);
902 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
906 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
909 struct obd_device *obd = imp->imp_obd;
913 OBD_CHECK_DEV_ACTIVE(obd);
914 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
915 OBD_COUNTER_INCREMENT(obd, add_conn);
917 rc = OBP(obd, add_conn)(imp, uuid, priority);
921 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
923 struct obd_device *obd = imp->imp_obd;
927 OBD_CHECK_DEV_ACTIVE(obd);
928 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
929 OBD_COUNTER_INCREMENT(obd, del_conn);
931 rc = OBP(obd, del_conn)(imp, uuid);
935 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
937 struct obd_uuid *uuid;
940 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
941 EXP_COUNTER_INCREMENT(exp, get_uuid);
943 uuid = OBP(exp->exp_obd, get_uuid)(exp);
947 /** Create a new /a exp on device /a obd for the uuid /a cluuid
948 * @param exp New export handle
949 * @param d Connect data, supported flags are set, flags also understood
950 * by obd are returned.
952 static inline int obd_connect(const struct lu_env *env,
953 struct obd_export **exp,struct obd_device *obd,
954 struct obd_uuid *cluuid,
955 struct obd_connect_data *data,
959 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
963 OBD_CHECK_DEV_ACTIVE(obd);
964 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
965 OBD_COUNTER_INCREMENT(obd, connect);
967 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
968 /* check that only subset is granted */
969 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
970 data->ocd_connect_flags));
974 static inline int obd_reconnect(const struct lu_env *env,
975 struct obd_export *exp,
976 struct obd_device *obd,
977 struct obd_uuid *cluuid,
978 struct obd_connect_data *d,
982 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
987 OBD_CHECK_DEV_ACTIVE(obd);
988 OBD_CHECK_DT_OP(obd, reconnect, 0);
989 OBD_COUNTER_INCREMENT(obd, reconnect);
991 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
992 /* check that only subset is granted */
993 LASSERT(ergo(d != NULL,
994 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
998 static inline int obd_disconnect(struct obd_export *exp)
1003 EXP_CHECK_DT_OP(exp, disconnect);
1004 EXP_COUNTER_INCREMENT(exp, disconnect);
1006 rc = OBP(exp->exp_obd, disconnect)(exp);
1010 static inline int obd_fid_init(struct obd_export *exp)
1015 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
1016 EXP_COUNTER_INCREMENT(exp, fid_init);
1018 rc = OBP(exp->exp_obd, fid_init)(exp);
1022 static inline int obd_fid_fini(struct obd_export *exp)
1027 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
1028 EXP_COUNTER_INCREMENT(exp, fid_fini);
1030 rc = OBP(exp->exp_obd, fid_fini)(exp);
1034 static inline int obd_fid_alloc(struct obd_export *exp,
1036 struct md_op_data *op_data)
1041 EXP_CHECK_DT_OP(exp, fid_alloc);
1042 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1044 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1048 static inline int obd_fid_delete(struct obd_export *exp,
1049 const struct lu_fid *fid)
1054 EXP_CHECK_DT_OP(exp, fid_delete);
1055 EXP_COUNTER_INCREMENT(exp, fid_delete);
1057 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
1061 static inline int obd_ping(struct obd_export *exp)
1066 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1067 EXP_COUNTER_INCREMENT(exp, ping);
1069 rc = OBP(exp->exp_obd, ping)(exp);
1073 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1078 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1079 OBD_COUNTER_INCREMENT(obd, pool_new);
1081 rc = OBP(obd, pool_new)(obd, poolname);
1085 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1090 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1091 OBD_COUNTER_INCREMENT(obd, pool_del);
1093 rc = OBP(obd, pool_del)(obd, poolname);
1097 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1102 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1103 OBD_COUNTER_INCREMENT(obd, pool_add);
1105 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1109 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1114 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1115 OBD_COUNTER_INCREMENT(obd, pool_rem);
1117 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1121 static inline void obd_getref(struct obd_device *obd)
1124 if (OBT(obd) && OBP(obd, getref)) {
1125 OBD_COUNTER_INCREMENT(obd, getref);
1126 OBP(obd, getref)(obd);
1131 static inline void obd_putref(struct obd_device *obd)
1134 if (OBT(obd) && OBP(obd, putref)) {
1135 OBD_COUNTER_INCREMENT(obd, putref);
1136 OBP(obd, putref)(obd);
1141 static inline int obd_init_export(struct obd_export *exp)
1146 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1147 OBP((exp)->exp_obd, init_export))
1148 rc = OBP(exp->exp_obd, init_export)(exp);
1152 static inline int obd_destroy_export(struct obd_export *exp)
1155 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1156 OBP((exp)->exp_obd, destroy_export))
1157 OBP(exp->exp_obd, destroy_export)(exp);
1161 static inline int obd_extent_calc(struct obd_export *exp,
1162 struct lov_stripe_md *md,
1163 int cmd, obd_off *offset)
1167 EXP_CHECK_DT_OP(exp, extent_calc);
1168 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1172 static inline struct dentry *
1173 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1175 LASSERT(exp->exp_obd);
1177 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1182 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1184 LASSERT(exp->exp_obd);
1185 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1187 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1188 dentry, exp->exp_obd);
1193 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1194 * If the cache is older than @max_age we will get a new value from the
1195 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1196 static inline int obd_statfs_async(struct obd_device *obd,
1197 struct obd_info *oinfo,
1199 struct ptlrpc_request_set *rqset)
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)(obd, 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 cfs_spin_lock(&obd->obd_osfs_lock);
1221 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1222 cfs_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_device *obd,
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(obd, &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(struct obd_device *obd, struct obd_statfs *osfs,
1256 __u64 max_age, __u32 flags)
1264 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1265 OBD_COUNTER_INCREMENT(obd, statfs);
1267 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1268 obd->obd_osfs_age, max_age);
1269 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1270 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1272 cfs_spin_lock(&obd->obd_osfs_lock);
1273 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1274 obd->obd_osfs_age = cfs_time_current_64();
1275 cfs_spin_unlock(&obd->obd_osfs_lock);
1278 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1279 " objects "LPU64"/"LPU64"\n",
1280 obd->obd_name, &obd->obd_osfs,
1281 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1282 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1283 cfs_spin_lock(&obd->obd_osfs_lock);
1284 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1285 cfs_spin_unlock(&obd->obd_osfs_lock);
1290 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
1291 obd_size start, obd_size end)
1293 struct ptlrpc_request_set *set = NULL;
1297 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1298 EXP_COUNTER_INCREMENT(exp, sync);
1300 set = ptlrpc_prep_set();
1304 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1306 rc = ptlrpc_set_wait(set);
1307 ptlrpc_set_destroy(set);
1311 static inline int obd_sync(struct obd_export *exp, struct obd_info *oinfo,
1312 obd_size start, obd_size end,
1313 struct ptlrpc_request_set *set)
1318 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1319 EXP_COUNTER_INCREMENT(exp, sync);
1321 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1325 static inline int obd_punch_rqset(struct obd_export *exp,
1326 struct obd_info *oinfo,
1327 struct obd_trans_info *oti)
1329 struct ptlrpc_request_set *set = NULL;
1333 EXP_CHECK_DT_OP(exp, punch);
1334 EXP_COUNTER_INCREMENT(exp, punch);
1336 set = ptlrpc_prep_set();
1340 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1342 rc = ptlrpc_set_wait(set);
1343 ptlrpc_set_destroy(set);
1347 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1348 struct obd_trans_info *oti,
1349 struct ptlrpc_request_set *rqset)
1354 EXP_CHECK_DT_OP(exp, punch);
1355 EXP_COUNTER_INCREMENT(exp, punch);
1357 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1361 static inline int obd_brw(int cmd, struct obd_export *exp,
1362 struct obd_info *oinfo, obd_count oa_bufs,
1363 struct brw_page *pg, struct obd_trans_info *oti)
1368 EXP_CHECK_DT_OP(exp, brw);
1369 EXP_COUNTER_INCREMENT(exp, brw);
1371 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1372 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1373 "or OBD_BRW_CHECK\n");
1377 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1381 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1382 int objcount, struct obd_ioobj *obj,
1383 struct niobuf_remote *remote, int *pages,
1384 struct niobuf_local *local,
1385 struct obd_trans_info *oti,
1386 struct lustre_capa *capa)
1391 EXP_CHECK_DT_OP(exp, preprw);
1392 EXP_COUNTER_INCREMENT(exp, preprw);
1394 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1395 pages, local, oti, capa);
1399 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1400 int objcount, struct obd_ioobj *obj,
1401 struct niobuf_remote *rnb, int pages,
1402 struct niobuf_local *local,
1403 struct obd_trans_info *oti, int rc)
1407 EXP_CHECK_DT_OP(exp, commitrw);
1408 EXP_COUNTER_INCREMENT(exp, commitrw);
1410 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1411 rnb, pages, local, oti, rc);
1415 static inline int obd_merge_lvb(struct obd_export *exp,
1416 struct lov_stripe_md *lsm,
1417 struct ost_lvb *lvb, int kms_only)
1422 EXP_CHECK_DT_OP(exp, merge_lvb);
1423 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1425 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1429 static inline int obd_adjust_kms(struct obd_export *exp,
1430 struct lov_stripe_md *lsm, obd_off size,
1436 EXP_CHECK_DT_OP(exp, adjust_kms);
1437 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1439 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1443 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1444 int len, void *karg, void *uarg)
1449 EXP_CHECK_DT_OP(exp, iocontrol);
1450 EXP_COUNTER_INCREMENT(exp, iocontrol);
1452 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1456 static inline int obd_enqueue_rqset(struct obd_export *exp,
1457 struct obd_info *oinfo,
1458 struct ldlm_enqueue_info *einfo)
1460 struct ptlrpc_request_set *set = NULL;
1464 EXP_CHECK_DT_OP(exp, enqueue);
1465 EXP_COUNTER_INCREMENT(exp, enqueue);
1467 set = ptlrpc_prep_set();
1471 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1473 rc = ptlrpc_set_wait(set);
1474 ptlrpc_set_destroy(set);
1478 static inline int obd_enqueue(struct obd_export *exp,
1479 struct obd_info *oinfo,
1480 struct ldlm_enqueue_info *einfo,
1481 struct ptlrpc_request_set *set)
1486 EXP_CHECK_DT_OP(exp, enqueue);
1487 EXP_COUNTER_INCREMENT(exp, enqueue);
1489 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1493 static inline int obd_change_cbdata(struct obd_export *exp,
1494 struct lov_stripe_md *lsm,
1495 ldlm_iterator_t it, void *data)
1500 EXP_CHECK_DT_OP(exp, change_cbdata);
1501 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1503 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1507 static inline int obd_find_cbdata(struct obd_export *exp,
1508 struct lov_stripe_md *lsm,
1509 ldlm_iterator_t it, void *data)
1514 EXP_CHECK_DT_OP(exp, find_cbdata);
1515 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1517 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1521 static inline int obd_cancel(struct obd_export *exp,
1522 struct lov_stripe_md *ea, __u32 mode,
1523 struct lustre_handle *lockh)
1528 EXP_CHECK_DT_OP(exp, cancel);
1529 EXP_COUNTER_INCREMENT(exp, cancel);
1531 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1535 static inline int obd_cancel_unused(struct obd_export *exp,
1536 struct lov_stripe_md *ea,
1537 ldlm_cancel_flags_t flags,
1543 EXP_CHECK_DT_OP(exp, cancel_unused);
1544 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1546 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1550 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1551 struct obd_capa *oc, struct obd_client_handle *handle,
1557 EXP_CHECK_DT_OP(exp, pin);
1558 EXP_COUNTER_INCREMENT(exp, pin);
1560 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1564 static inline int obd_unpin(struct obd_export *exp,
1565 struct obd_client_handle *handle, int flag)
1570 EXP_CHECK_DT_OP(exp, unpin);
1571 EXP_COUNTER_INCREMENT(exp, unpin);
1573 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1578 static inline void obd_import_event(struct obd_device *obd,
1579 struct obd_import *imp,
1580 enum obd_import_event event)
1584 CERROR("NULL device\n");
1588 if (obd->obd_set_up && OBP(obd, import_event)) {
1589 OBD_COUNTER_INCREMENT(obd, import_event);
1590 OBP(obd, import_event)(obd, imp, event);
1595 static inline int obd_llog_connect(struct obd_export *exp,
1596 struct llogd_conn_body *body)
1601 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1602 EXP_COUNTER_INCREMENT(exp, llog_connect);
1604 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1609 static inline int obd_notify(struct obd_device *obd,
1610 struct obd_device *watched,
1611 enum obd_notify_event ev,
1618 /* the check for async_recov is a complete hack - I'm hereby
1619 overloading the meaning to also mean "this was called from
1620 mds_postsetup". I know that my mds is able to handle notifies
1621 by this point, and it needs to get them to execute mds_postrecov. */
1622 if (!obd->obd_set_up && !obd->obd_async_recov) {
1623 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1627 if (!OBP(obd, notify)) {
1628 CERROR("obd %s has no notify handler\n", obd->obd_name);
1632 OBD_COUNTER_INCREMENT(obd, notify);
1633 rc = OBP(obd, notify)(obd, watched, ev, data);
1637 static inline int obd_notify_observer(struct obd_device *observer,
1638 struct obd_device *observed,
1639 enum obd_notify_event ev,
1645 struct obd_notify_upcall *onu;
1647 if (observer->obd_observer)
1648 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1652 * Also, call non-obd listener, if any
1654 onu = &observer->obd_upcall;
1655 if (onu->onu_upcall != NULL)
1656 rc2 = onu->onu_upcall(observer, observed, ev,
1657 onu->onu_owner, NULL);
1661 return rc1 ? rc1 : rc2;
1664 static inline int obd_quotacheck(struct obd_export *exp,
1665 struct obd_quotactl *oqctl)
1670 EXP_CHECK_DT_OP(exp, quotacheck);
1671 EXP_COUNTER_INCREMENT(exp, quotacheck);
1673 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1677 static inline int obd_quotactl(struct obd_export *exp,
1678 struct obd_quotactl *oqctl)
1683 EXP_CHECK_DT_OP(exp, quotactl);
1684 EXP_COUNTER_INCREMENT(exp, quotactl);
1686 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1690 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1691 struct quota_adjust_qunit *oqaq,
1692 struct lustre_quota_ctxt *qctxt,
1693 struct ptlrpc_request_set *set)
1695 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1696 struct timeval work_start;
1697 struct timeval work_end;
1703 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1705 cfs_gettimeofday(&work_start);
1707 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1708 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1710 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt, set);
1712 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1714 cfs_gettimeofday(&work_end);
1715 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1716 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1723 static inline int obd_health_check(struct obd_device *obd)
1725 /* returns: 0 on healthy
1726 * >0 on unhealthy + reason code/flag
1727 * however the only suppored reason == 1 right now
1728 * We'll need to define some better reasons
1729 * or flags in the future.
1735 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1736 if (obd == NULL || !OBT(obd)) {
1737 CERROR("cleaned up obd\n");
1738 RETURN(-EOPNOTSUPP);
1740 if (!obd->obd_set_up || obd->obd_stopping)
1742 if (!OBP(obd, health_check))
1745 rc = OBP(obd, health_check)(obd);
1749 static inline int obd_register_observer(struct obd_device *obd,
1750 struct obd_device *observer)
1754 cfs_down_write(&obd->obd_observer_link_sem);
1755 if (obd->obd_observer && observer) {
1756 cfs_up_write(&obd->obd_observer_link_sem);
1759 obd->obd_observer = observer;
1760 cfs_up_write(&obd->obd_observer_link_sem);
1764 static inline int obd_pin_observer(struct obd_device *obd,
1765 struct obd_device **observer)
1768 cfs_down_read(&obd->obd_observer_link_sem);
1769 if (!obd->obd_observer) {
1771 cfs_up_read(&obd->obd_observer_link_sem);
1774 *observer = obd->obd_observer;
1778 static inline int obd_unpin_observer(struct obd_device *obd)
1781 cfs_up_read(&obd->obd_observer_link_sem);
1786 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1787 obd_page_removal_cb_t cb,
1788 obd_pin_extent_cb pin_cb)
1793 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1794 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1796 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1800 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1801 obd_page_removal_cb_t cb)
1806 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1807 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1809 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1813 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1814 obd_lock_cancel_cb cb)
1819 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1820 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1822 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1826 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1827 obd_lock_cancel_cb cb)
1832 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1833 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1835 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1840 /* metadata helpers */
1841 static inline int md_getstatus(struct obd_export *exp,
1842 struct lu_fid *fid, struct obd_capa **pc)
1847 EXP_CHECK_MD_OP(exp, getstatus);
1848 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1849 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1853 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1854 struct ptlrpc_request **request)
1858 EXP_CHECK_MD_OP(exp, getattr);
1859 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1860 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1864 static inline int md_change_cbdata(struct obd_export *exp,
1865 const struct lu_fid *fid,
1866 ldlm_iterator_t it, void *data)
1870 EXP_CHECK_MD_OP(exp, change_cbdata);
1871 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1872 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1876 static inline int md_find_cbdata(struct obd_export *exp,
1877 const struct lu_fid *fid,
1878 ldlm_iterator_t it, void *data)
1882 EXP_CHECK_MD_OP(exp, find_cbdata);
1883 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1884 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1888 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1889 struct md_open_data *mod,
1890 struct ptlrpc_request **request)
1894 EXP_CHECK_MD_OP(exp, close);
1895 EXP_MD_COUNTER_INCREMENT(exp, close);
1896 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1900 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1901 const void *data, int datalen, int mode, __u32 uid,
1902 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1903 struct ptlrpc_request **request)
1907 EXP_CHECK_MD_OP(exp, create);
1908 EXP_MD_COUNTER_INCREMENT(exp, create);
1909 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1910 uid, gid, cap_effective, rdev, request);
1914 static inline int md_done_writing(struct obd_export *exp,
1915 struct md_op_data *op_data,
1916 struct md_open_data *mod)
1920 EXP_CHECK_MD_OP(exp, done_writing);
1921 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1922 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1926 static inline int md_enqueue(struct obd_export *exp,
1927 struct ldlm_enqueue_info *einfo,
1928 struct lookup_intent *it,
1929 struct md_op_data *op_data,
1930 struct lustre_handle *lockh,
1931 void *lmm, int lmmsize,
1932 struct ptlrpc_request **req,
1933 int extra_lock_flags)
1937 EXP_CHECK_MD_OP(exp, enqueue);
1938 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1939 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1940 lmm, lmmsize, req, extra_lock_flags);
1944 static inline int md_getattr_name(struct obd_export *exp,
1945 struct md_op_data *op_data,
1946 struct ptlrpc_request **request)
1950 EXP_CHECK_MD_OP(exp, getattr_name);
1951 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1952 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1956 static inline int md_intent_lock(struct obd_export *exp,
1957 struct md_op_data *op_data, void *lmm,
1958 int lmmsize, struct lookup_intent *it,
1959 int flags, struct ptlrpc_request **reqp,
1960 ldlm_blocking_callback cb_blocking,
1961 int extra_lock_flags)
1965 EXP_CHECK_MD_OP(exp, intent_lock);
1966 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1967 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1968 it, flags, reqp, cb_blocking,
1973 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1974 struct ptlrpc_request **request)
1978 EXP_CHECK_MD_OP(exp, link);
1979 EXP_MD_COUNTER_INCREMENT(exp, link);
1980 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1984 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1985 const char *old, int oldlen, const char *new,
1986 int newlen, struct ptlrpc_request **request)
1990 EXP_CHECK_MD_OP(exp, rename);
1991 EXP_MD_COUNTER_INCREMENT(exp, rename);
1992 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1997 static inline int md_is_subdir(struct obd_export *exp,
1998 const struct lu_fid *pfid,
1999 const struct lu_fid *cfid,
2000 struct ptlrpc_request **request)
2004 EXP_CHECK_MD_OP(exp, is_subdir);
2005 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
2006 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
2010 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
2011 void *ea, int ealen, void *ea2, int ea2len,
2012 struct ptlrpc_request **request,
2013 struct md_open_data **mod)
2017 EXP_CHECK_MD_OP(exp, setattr);
2018 EXP_MD_COUNTER_INCREMENT(exp, setattr);
2019 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
2020 ea2, ea2len, request, mod);
2024 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
2025 struct obd_capa *oc, struct ptlrpc_request **request)
2029 EXP_CHECK_MD_OP(exp, sync);
2030 EXP_MD_COUNTER_INCREMENT(exp, sync);
2031 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
2035 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
2036 struct obd_capa *oc, __u64 offset,
2037 struct page **pages, unsigned npages,
2038 struct ptlrpc_request **request)
2042 EXP_CHECK_MD_OP(exp, readpage);
2043 EXP_MD_COUNTER_INCREMENT(exp, readpage);
2044 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, pages, npages,
2049 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
2050 struct ptlrpc_request **request)
2054 EXP_CHECK_MD_OP(exp, unlink);
2055 EXP_MD_COUNTER_INCREMENT(exp, unlink);
2056 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
2060 static inline int md_get_lustre_md(struct obd_export *exp,
2061 struct ptlrpc_request *req,
2062 struct obd_export *dt_exp,
2063 struct obd_export *md_exp,
2064 struct lustre_md *md)
2067 EXP_CHECK_MD_OP(exp, get_lustre_md);
2068 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
2069 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
2072 static inline int md_free_lustre_md(struct obd_export *exp,
2073 struct lustre_md *md)
2076 EXP_CHECK_MD_OP(exp, free_lustre_md);
2077 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2078 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2081 static inline int md_setxattr(struct obd_export *exp,
2082 const struct lu_fid *fid, struct obd_capa *oc,
2083 obd_valid valid, const char *name,
2084 const char *input, int input_size,
2085 int output_size, int flags, __u32 suppgid,
2086 struct ptlrpc_request **request)
2089 EXP_CHECK_MD_OP(exp, setxattr);
2090 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2091 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2092 input_size, output_size, flags,
2096 static inline int md_getxattr(struct obd_export *exp,
2097 const struct lu_fid *fid, struct obd_capa *oc,
2098 obd_valid valid, const char *name,
2099 const char *input, int input_size,
2100 int output_size, int flags,
2101 struct ptlrpc_request **request)
2104 EXP_CHECK_MD_OP(exp, getxattr);
2105 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2106 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2107 input_size, output_size, flags,
2111 static inline int md_set_open_replay_data(struct obd_export *exp,
2112 struct obd_client_handle *och,
2113 struct ptlrpc_request *open_req)
2116 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2117 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2118 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2121 static inline int md_clear_open_replay_data(struct obd_export *exp,
2122 struct obd_client_handle *och)
2125 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2126 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2127 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2130 static inline int md_set_lock_data(struct obd_export *exp,
2131 __u64 *lockh, void *data, __u32 *bits)
2134 EXP_CHECK_MD_OP(exp, set_lock_data);
2135 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2136 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2139 static inline int md_cancel_unused(struct obd_export *exp,
2140 const struct lu_fid *fid,
2141 ldlm_policy_data_t *policy,
2143 ldlm_cancel_flags_t flags,
2149 EXP_CHECK_MD_OP(exp, cancel_unused);
2150 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2152 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2157 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2158 const struct lu_fid *fid,
2160 ldlm_policy_data_t *policy,
2162 struct lustre_handle *lockh)
2165 EXP_CHECK_MD_OP(exp, lock_match);
2166 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2167 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2168 policy, mode, lockh));
2171 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2172 int def_asize, int cookiesize)
2175 EXP_CHECK_MD_OP(exp, init_ea_size);
2176 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2177 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2181 static inline int md_get_remote_perm(struct obd_export *exp,
2182 const struct lu_fid *fid,
2183 struct obd_capa *oc, __u32 suppgid,
2184 struct ptlrpc_request **request)
2187 EXP_CHECK_MD_OP(exp, get_remote_perm);
2188 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2189 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2193 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2198 EXP_CHECK_MD_OP(exp, renew_capa);
2199 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2200 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2204 static inline int md_unpack_capa(struct obd_export *exp,
2205 struct ptlrpc_request *req,
2206 const struct req_msg_field *field,
2207 struct obd_capa **oc)
2211 EXP_CHECK_MD_OP(exp, unpack_capa);
2212 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2213 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2217 static inline int md_intent_getattr_async(struct obd_export *exp,
2218 struct md_enqueue_info *minfo,
2219 struct ldlm_enqueue_info *einfo)
2223 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2224 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2225 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2229 static inline int md_revalidate_lock(struct obd_export *exp,
2230 struct lookup_intent *it,
2235 EXP_CHECK_MD_OP(exp, revalidate_lock);
2236 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2237 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2242 /* OBD Metadata Support */
2244 extern int obd_init_caches(void);
2245 extern void obd_cleanup_caches(void);
2247 /* support routines */
2248 extern cfs_mem_cache_t *obdo_cachep;
2250 #define OBDO_ALLOC(ptr) \
2252 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, CFS_ALLOC_IO); \
2255 #define OBDO_FREE(ptr) \
2257 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2261 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2263 /* something here */
2266 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2268 /* something here */
2271 /* I'm as embarrassed about this as you are.
2273 * <shaver> // XXX do not look into _superhack with remaining eye
2274 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2275 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2278 extern void obd_sysctl_init (void);
2279 extern void obd_sysctl_clean (void);
2282 typedef __u8 class_uuid_t[16];
2283 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2286 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2287 int class_add_uuid(const char *uuid, __u64 nid);
2288 int class_del_uuid (const char *uuid);
2289 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
2290 void class_init_uuidlist(void);
2291 void class_exit_uuidlist(void);
2294 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2295 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2298 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2300 #endif /* __LINUX_OBD_CLASS_H */