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_spinlock_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);
104 int obd_zombie_impexp_init(void);
105 void obd_zombie_impexp_stop(void);
106 void obd_zombie_impexp_cull(void);
107 void obd_zombie_barrier(void);
108 void obd_exports_barrier(struct obd_device *obd);
109 int kuc_len(int payload_len);
110 struct kuc_hdr * kuc_ptr(void *p);
111 int kuc_ispayload(void *p);
112 void *kuc_alloc(int payload_len, int transport, int type);
113 void kuc_free(void *p, int payload_len);
116 int class_process_config(struct lustre_cfg *lcfg);
117 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
118 struct lustre_cfg *lcfg, void *data);
119 int class_attach(struct lustre_cfg *lcfg);
120 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
121 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
122 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
123 struct obd_device *class_incref(struct obd_device *obd,
124 const char *scope, const void *source);
125 void class_decref(struct obd_device *obd,
126 const char *scope, const void *source);
127 void dump_exports(struct obd_device *obd, int locks);
131 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
133 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
135 memset(lvars, 0, sizeof(*lvars));
139 #define CFG_F_START 0x01 /* Set when we start updating from a log */
140 #define CFG_F_MARKER 0x02 /* We are within a maker */
141 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
142 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
143 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
145 /* Passed as data param to class_config_parse_llog */
146 struct config_llog_instance {
148 char cfg_instance[sizeof(void*) * 2 + 1];
149 struct super_block *cfg_sb;
150 struct obd_uuid cfg_uuid;
151 int cfg_last_idx; /* for partial llog processing */
154 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
155 struct config_llog_instance *cfg);
156 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
157 struct config_llog_instance *cfg);
159 /* list of active configuration logs */
160 struct config_llog_data {
162 struct ldlm_res_id cld_resid;
163 struct config_llog_instance cld_cfg;
164 cfs_list_t cld_list_chain;
165 cfs_atomic_t cld_refcount;
166 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
167 struct obd_export *cld_mgcexp;
168 cfs_mutex_t cld_lock;
169 unsigned int cld_stopping:1, /* we were told to stop
171 cld_lostlock:1, /* lock not requeued */
175 struct lustre_profile {
182 struct lustre_profile *class_get_profile(const char * prof);
183 void class_del_profile(const char *prof);
184 void class_del_profiles(void);
186 #if LUSTRE_TRACKS_LOCK_EXP_REFS
188 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
189 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
190 extern void (*class_export_dump_hook)(struct obd_export *);
194 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
195 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
199 #define class_export_rpc_get(exp) \
201 cfs_atomic_inc(&(exp)->exp_rpc_count); \
202 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
203 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
204 class_export_get(exp); \
207 #define class_export_rpc_put(exp) \
209 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
210 cfs_atomic_dec(&(exp)->exp_rpc_count); \
211 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
212 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
213 class_export_put(exp); \
216 #define class_export_lock_get(exp, lock) \
218 cfs_atomic_inc(&(exp)->exp_locks_count); \
219 __class_export_add_lock_ref(exp, lock); \
220 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
221 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
222 class_export_get(exp); \
225 #define class_export_lock_put(exp, lock) \
227 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
228 cfs_atomic_dec(&(exp)->exp_locks_count); \
229 __class_export_del_lock_ref(exp, lock); \
230 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
231 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
232 class_export_put(exp); \
235 #define class_export_cb_get(exp) \
237 cfs_atomic_inc(&(exp)->exp_cb_count); \
238 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
239 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
240 class_export_get(exp); \
243 #define class_export_cb_put(exp) \
245 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
246 cfs_atomic_dec(&(exp)->exp_cb_count); \
247 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
248 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
249 class_export_put(exp); \
253 struct obd_export *class_export_get(struct obd_export *exp);
254 void class_export_put(struct obd_export *exp);
255 struct obd_export *class_new_export(struct obd_device *obddev,
256 struct obd_uuid *cluuid);
257 void class_unlink_export(struct obd_export *exp);
259 struct obd_import *class_import_get(struct obd_import *);
260 void class_import_put(struct obd_import *);
261 struct obd_import *class_new_import(struct obd_device *obd);
262 void class_destroy_import(struct obd_import *exp);
264 struct obd_type *class_search_type(const char *name);
265 struct obd_type *class_get_type(const char *name);
266 void class_put_type(struct obd_type *type);
267 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
268 struct obd_uuid *cluuid);
269 int class_disconnect(struct obd_export *exp);
270 void class_fail_export(struct obd_export *exp);
271 int class_connected_export(struct obd_export *exp);
272 void class_disconnect_exports(struct obd_device *obddev);
273 int class_manual_cleanup(struct obd_device *obd);
274 void class_disconnect_stale_exports(struct obd_device *,
275 int (*test_export)(struct obd_export *));
276 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
278 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
279 (obd->obd_force ? OBD_OPT_FORCE : 0) |
280 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
284 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
286 LASSERT(exp->exp_obd);
287 return exp->exp_obd->u.obt.obt_lut;
290 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
292 LASSERT(obd->u.obt.obt_lut);
293 return &obd->u.obt.obt_lut->lut_lsd;
296 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
297 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
298 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
299 unsigned int ia_valid);
300 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
301 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
302 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
305 #define OBT(dev) (dev)->obd_type
306 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
307 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
308 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
310 /* Ensure obd_setup: used for cleanup which must be called
311 while obd is stopping */
312 #define OBD_CHECK_DEV(obd) \
315 CERROR("NULL device\n"); \
320 /* ensure obd_setup and !obd_stopping */
321 #define OBD_CHECK_DEV_ACTIVE(obd) \
323 OBD_CHECK_DEV(obd); \
324 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
325 CERROR("Device %d not setup\n", \
333 #define OBD_COUNTER_OFFSET(op) \
334 ((offsetof(struct obd_ops, o_ ## op) - \
335 offsetof(struct obd_ops, o_iocontrol)) \
336 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
338 #define OBD_COUNTER_INCREMENT(obdx, op) \
339 if ((obdx)->obd_stats != NULL) { \
340 unsigned int coffset; \
341 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
342 OBD_COUNTER_OFFSET(op); \
343 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
344 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
347 #define EXP_COUNTER_INCREMENT(export, op) \
348 if ((export)->exp_obd->obd_stats != NULL) { \
349 unsigned int coffset; \
350 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
351 OBD_COUNTER_OFFSET(op); \
352 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
353 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
354 if ((export)->exp_nid_stats != NULL && \
355 (export)->exp_nid_stats->nid_stats != NULL) \
356 lprocfs_counter_incr( \
357 (export)->exp_nid_stats->nid_stats, coffset);\
360 #define MD_COUNTER_OFFSET(op) \
361 ((offsetof(struct md_ops, m_ ## op) - \
362 offsetof(struct md_ops, m_getstatus)) \
363 / sizeof(((struct md_ops *)(0))->m_getstatus))
365 #define MD_COUNTER_INCREMENT(obdx, op) \
366 if ((obd)->md_stats != NULL) { \
367 unsigned int coffset; \
368 coffset = (unsigned int)((obdx)->md_cntr_base) + \
369 MD_COUNTER_OFFSET(op); \
370 LASSERT(coffset < (obdx)->md_stats->ls_num); \
371 lprocfs_counter_incr((obdx)->md_stats, coffset); \
374 #define EXP_MD_COUNTER_INCREMENT(export, op) \
375 if ((export)->exp_obd->obd_stats != NULL) { \
376 unsigned int coffset; \
377 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
378 MD_COUNTER_OFFSET(op); \
379 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
380 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
381 if ((export)->exp_md_stats != NULL) \
382 lprocfs_counter_incr( \
383 (export)->exp_md_stats, coffset); \
387 #define OBD_COUNTER_OFFSET(op)
388 #define OBD_COUNTER_INCREMENT(obd, op)
389 #define EXP_COUNTER_INCREMENT(exp, op)
390 #define MD_COUNTER_INCREMENT(obd, op)
391 #define EXP_MD_COUNTER_INCREMENT(exp, op)
394 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
396 /* Always add in ldlm_stats */
397 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
398 ,LPROCFS_STATS_FLAG_NOPERCPU);
399 if (tmp->nid_ldlm_stats == NULL)
402 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
404 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
405 tmp->nid_ldlm_stats);
408 #define OBD_CHECK_MD_OP(obd, op, err) \
410 if (!OBT(obd) || !MDP((obd), op)) { \
412 CERROR("md_" #op ": dev %s/%d no operation\n", \
413 obd->obd_name, obd->obd_minor); \
418 #define EXP_CHECK_MD_OP(exp, op) \
420 if ((exp) == NULL) { \
421 CERROR("obd_" #op ": NULL export\n"); \
424 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
425 CERROR("obd_" #op ": cleaned up obd\n"); \
426 RETURN(-EOPNOTSUPP); \
428 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
429 CERROR("obd_" #op ": dev %s/%d no operation\n", \
430 (exp)->exp_obd->obd_name, \
431 (exp)->exp_obd->obd_minor); \
432 RETURN(-EOPNOTSUPP); \
437 #define OBD_CHECK_DT_OP(obd, op, err) \
439 if (!OBT(obd) || !OBP((obd), op)) { \
441 CERROR("obd_" #op ": dev %d no operation\n", \
447 #define EXP_CHECK_DT_OP(exp, op) \
449 if ((exp) == NULL) { \
450 CERROR("obd_" #op ": NULL export\n"); \
453 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
454 CERROR("obd_" #op ": cleaned up obd\n"); \
455 RETURN(-EOPNOTSUPP); \
457 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
458 CERROR("obd_" #op ": dev %d no operation\n", \
459 (exp)->exp_obd->obd_minor); \
460 RETURN(-EOPNOTSUPP); \
464 #define CTXT_CHECK_OP(ctxt, op, err) \
466 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
468 CERROR("lop_" #op ": dev %d no operation\n", \
469 ctxt->loc_obd->obd_minor); \
474 static inline int class_devno_max(void)
476 return MAX_OBD_DEVICES;
479 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
480 void *key, __u32 *vallen, void *val,
481 struct lov_stripe_md *lsm)
486 EXP_CHECK_DT_OP(exp, get_info);
487 EXP_COUNTER_INCREMENT(exp, get_info);
489 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
493 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
494 void *key, obd_count vallen, void *val,
495 struct ptlrpc_request_set *set)
500 EXP_CHECK_DT_OP(exp, set_info_async);
501 EXP_COUNTER_INCREMENT(exp, set_info_async);
503 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
509 * obd-lu integration.
511 * Functionality is being moved into new lu_device-based layering, but some
512 * pieces of configuration process are still based on obd devices.
514 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
515 * subsume ->o_setup() methods of obd devices they replace. The same for
516 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
517 * result, obd_setup() and obd_process_config() branch and call one XOR
520 * Yet neither lu_device_type_operations::ldto_device_fini() nor
521 * lu_device_type_operations::ldto_device_free() fully implement the
522 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
523 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
526 #define DECLARE_LU_VARS(ldt, d) \
527 struct lu_device_type *ldt; \
530 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
533 DECLARE_LU_VARS(ldt, d);
536 ldt = obd->obd_type->typ_lu;
538 struct lu_context session_ctx;
540 lu_context_init(&session_ctx, LCT_SESSION);
541 session_ctx.lc_thread = NULL;
542 lu_context_enter(&session_ctx);
544 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
546 env.le_ses = &session_ctx;
547 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
556 lu_context_exit(&session_ctx);
557 lu_context_fini(&session_ctx);
560 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
561 OBD_COUNTER_INCREMENT(obd, setup);
562 rc = OBP(obd, setup)(obd, cfg);
567 static inline int obd_precleanup(struct obd_device *obd,
568 enum obd_cleanup_stage cleanup_stage)
571 DECLARE_LU_VARS(ldt, d);
575 ldt = obd->obd_type->typ_lu;
577 if (ldt != NULL && d != NULL) {
578 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
581 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
583 ldt->ldt_ops->ldto_device_fini(&env, d);
588 OBD_CHECK_DT_OP(obd, precleanup, 0);
589 OBD_COUNTER_INCREMENT(obd, precleanup);
591 rc = OBP(obd, precleanup)(obd, cleanup_stage);
595 static inline int obd_cleanup(struct obd_device *obd)
598 DECLARE_LU_VARS(ldt, d);
603 ldt = obd->obd_type->typ_lu;
605 if (ldt != NULL && d != NULL) {
608 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
610 ldt->ldt_ops->ldto_device_free(&env, d);
612 obd->obd_lu_dev = NULL;
615 OBD_CHECK_DT_OP(obd, cleanup, 0);
616 OBD_COUNTER_INCREMENT(obd, cleanup);
618 rc = OBP(obd, cleanup)(obd);
622 static inline void obd_cleanup_client_import(struct obd_device *obd)
626 /* If we set up but never connected, the
627 client import will not have been cleaned. */
628 cfs_down_write(&obd->u.cli.cl_sem);
629 if (obd->u.cli.cl_import) {
630 struct obd_import *imp;
631 imp = obd->u.cli.cl_import;
632 CDEBUG(D_CONFIG, "%s: client import never connected\n",
634 ptlrpc_invalidate_import(imp);
635 if (imp->imp_rq_pool) {
636 ptlrpc_free_rq_pool(imp->imp_rq_pool);
637 imp->imp_rq_pool = NULL;
639 class_destroy_import(imp);
640 obd->u.cli.cl_import = NULL;
642 cfs_up_write(&obd->u.cli.cl_sem);
648 obd_process_config(struct obd_device *obd, int datalen, void *data)
651 DECLARE_LU_VARS(ldt, d);
656 obd->obd_process_conf = 1;
657 ldt = obd->obd_type->typ_lu;
659 if (ldt != NULL && d != NULL) {
662 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
664 rc = d->ld_ops->ldo_process_config(&env, d, data);
668 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
669 rc = OBP(obd, process_config)(obd, datalen, data);
671 OBD_COUNTER_INCREMENT(obd, process_config);
672 obd->obd_process_conf = 0;
677 /* Pack an in-memory MD struct for storage on disk.
678 * Returns +ve size of packed MD (0 for free), or -ve error.
680 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
681 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
682 * If @*disk_tgt == NULL, it will be allocated
684 static inline int obd_packmd(struct obd_export *exp,
685 struct lov_mds_md **disk_tgt,
686 struct lov_stripe_md *mem_src)
691 EXP_CHECK_DT_OP(exp, packmd);
692 EXP_COUNTER_INCREMENT(exp, packmd);
694 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
698 static inline int obd_size_diskmd(struct obd_export *exp,
699 struct lov_stripe_md *mem_src)
701 return obd_packmd(exp, NULL, mem_src);
704 /* helper functions */
705 static inline int obd_alloc_diskmd(struct obd_export *exp,
706 struct lov_mds_md **disk_tgt)
709 LASSERT(*disk_tgt == NULL);
710 return obd_packmd(exp, disk_tgt, NULL);
713 static inline int obd_free_diskmd(struct obd_export *exp,
714 struct lov_mds_md **disk_tgt)
718 return obd_packmd(exp, disk_tgt, NULL);
721 /* Unpack an MD struct from disk to in-memory format.
722 * Returns +ve size of unpacked MD (0 for free), or -ve error.
724 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
725 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
726 * If @*mem_tgt == NULL, it will be allocated
728 static inline int obd_unpackmd(struct obd_export *exp,
729 struct lov_stripe_md **mem_tgt,
730 struct lov_mds_md *disk_src,
736 EXP_CHECK_DT_OP(exp, unpackmd);
737 EXP_COUNTER_INCREMENT(exp, unpackmd);
739 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
743 /* helper functions */
744 static inline int obd_alloc_memmd(struct obd_export *exp,
745 struct lov_stripe_md **mem_tgt)
748 LASSERT(*mem_tgt == NULL);
749 return obd_unpackmd(exp, mem_tgt, NULL, 0);
752 static inline int obd_free_memmd(struct obd_export *exp,
753 struct lov_stripe_md **mem_tgt)
759 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
764 static inline int obd_precreate(struct obd_export *exp)
769 EXP_CHECK_DT_OP(exp, precreate);
770 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
772 rc = OBP(exp->exp_obd, precreate)(exp);
776 static inline int obd_create_async(struct obd_export *exp,
777 struct obd_info *oinfo,
778 struct lov_stripe_md **ea,
779 struct obd_trans_info *oti)
784 EXP_CHECK_DT_OP(exp, create_async);
785 EXP_COUNTER_INCREMENT(exp, create_async);
787 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
791 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
792 struct lov_stripe_md **ea,
793 struct obd_trans_info *oti)
798 EXP_CHECK_DT_OP(exp, create);
799 EXP_COUNTER_INCREMENT(exp, create);
801 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
805 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
806 struct lov_stripe_md *ea,
807 struct obd_trans_info *oti,
808 struct obd_export *md_exp, void *capa)
813 EXP_CHECK_DT_OP(exp, destroy);
814 EXP_COUNTER_INCREMENT(exp, destroy);
816 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
820 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
825 EXP_CHECK_DT_OP(exp, getattr);
826 EXP_COUNTER_INCREMENT(exp, getattr);
828 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
832 static inline int obd_getattr_async(struct obd_export *exp,
833 struct obd_info *oinfo,
834 struct ptlrpc_request_set *set)
839 EXP_CHECK_DT_OP(exp, getattr_async);
840 EXP_COUNTER_INCREMENT(exp, getattr_async);
842 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
846 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
847 struct obd_trans_info *oti)
852 EXP_CHECK_DT_OP(exp, setattr);
853 EXP_COUNTER_INCREMENT(exp, setattr);
855 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
859 /* This performs all the requests set init/wait/destroy actions. */
860 static inline int obd_setattr_rqset(struct obd_export *exp,
861 struct obd_info *oinfo,
862 struct obd_trans_info *oti)
864 struct ptlrpc_request_set *set = NULL;
868 EXP_CHECK_DT_OP(exp, setattr_async);
869 EXP_COUNTER_INCREMENT(exp, setattr_async);
871 set = ptlrpc_prep_set();
875 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
877 rc = ptlrpc_set_wait(set);
878 ptlrpc_set_destroy(set);
882 /* This adds all the requests into @set if @set != NULL, otherwise
883 all requests are sent asynchronously without waiting for response. */
884 static inline int obd_setattr_async(struct obd_export *exp,
885 struct obd_info *oinfo,
886 struct obd_trans_info *oti,
887 struct ptlrpc_request_set *set)
892 EXP_CHECK_DT_OP(exp, setattr_async);
893 EXP_COUNTER_INCREMENT(exp, setattr_async);
895 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
899 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
902 struct obd_device *obd = imp->imp_obd;
906 OBD_CHECK_DEV_ACTIVE(obd);
907 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
908 OBD_COUNTER_INCREMENT(obd, add_conn);
910 rc = OBP(obd, add_conn)(imp, uuid, priority);
914 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
916 struct obd_device *obd = imp->imp_obd;
920 OBD_CHECK_DEV_ACTIVE(obd);
921 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
922 OBD_COUNTER_INCREMENT(obd, del_conn);
924 rc = OBP(obd, del_conn)(imp, uuid);
928 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
930 struct obd_uuid *uuid;
933 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
934 EXP_COUNTER_INCREMENT(exp, get_uuid);
936 uuid = OBP(exp->exp_obd, get_uuid)(exp);
940 /** Create a new /a exp on device /a obd for the uuid /a cluuid
941 * @param exp New export handle
942 * @param d Connect data, supported flags are set, flags also understood
943 * by obd are returned.
945 static inline int obd_connect(const struct lu_env *env,
946 struct obd_export **exp,struct obd_device *obd,
947 struct obd_uuid *cluuid,
948 struct obd_connect_data *d,
952 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
956 OBD_CHECK_DEV_ACTIVE(obd);
957 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
958 OBD_COUNTER_INCREMENT(obd, connect);
960 rc = OBP(obd, connect)(env, exp, obd, cluuid, d, localdata);
961 /* check that only subset is granted */
962 LASSERT(ergo(d != NULL,
963 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
967 static inline int obd_reconnect(const struct lu_env *env,
968 struct obd_export *exp,
969 struct obd_device *obd,
970 struct obd_uuid *cluuid,
971 struct obd_connect_data *d,
975 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
980 OBD_CHECK_DEV_ACTIVE(obd);
981 OBD_CHECK_DT_OP(obd, reconnect, 0);
982 OBD_COUNTER_INCREMENT(obd, reconnect);
984 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
985 /* check that only subset is granted */
986 LASSERT(ergo(d != NULL,
987 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
991 static inline int obd_disconnect(struct obd_export *exp)
996 EXP_CHECK_DT_OP(exp, disconnect);
997 EXP_COUNTER_INCREMENT(exp, disconnect);
999 rc = OBP(exp->exp_obd, disconnect)(exp);
1003 static inline int obd_fid_init(struct obd_export *exp)
1008 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
1009 EXP_COUNTER_INCREMENT(exp, fid_init);
1011 rc = OBP(exp->exp_obd, fid_init)(exp);
1015 static inline int obd_fid_fini(struct obd_export *exp)
1020 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
1021 EXP_COUNTER_INCREMENT(exp, fid_fini);
1023 rc = OBP(exp->exp_obd, fid_fini)(exp);
1027 static inline int obd_fid_alloc(struct obd_export *exp,
1029 struct md_op_data *op_data)
1034 EXP_CHECK_DT_OP(exp, fid_alloc);
1035 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1037 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1041 static inline int obd_fid_delete(struct obd_export *exp,
1042 const struct lu_fid *fid)
1047 EXP_CHECK_DT_OP(exp, fid_delete);
1048 EXP_COUNTER_INCREMENT(exp, fid_delete);
1050 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
1054 static inline int obd_ping(struct obd_export *exp)
1059 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1060 EXP_COUNTER_INCREMENT(exp, ping);
1062 rc = OBP(exp->exp_obd, ping)(exp);
1066 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1071 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1072 OBD_COUNTER_INCREMENT(obd, pool_new);
1074 rc = OBP(obd, pool_new)(obd, poolname);
1078 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1083 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1084 OBD_COUNTER_INCREMENT(obd, pool_del);
1086 rc = OBP(obd, pool_del)(obd, poolname);
1090 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1095 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1096 OBD_COUNTER_INCREMENT(obd, pool_add);
1098 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1102 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1107 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1108 OBD_COUNTER_INCREMENT(obd, pool_rem);
1110 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1114 static inline void obd_getref(struct obd_device *obd)
1117 if (OBT(obd) && OBP(obd, getref)) {
1118 OBD_COUNTER_INCREMENT(obd, getref);
1119 OBP(obd, getref)(obd);
1124 static inline void obd_putref(struct obd_device *obd)
1127 if (OBT(obd) && OBP(obd, putref)) {
1128 OBD_COUNTER_INCREMENT(obd, putref);
1129 OBP(obd, putref)(obd);
1134 static inline int obd_init_export(struct obd_export *exp)
1139 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1140 OBP((exp)->exp_obd, init_export))
1141 rc = OBP(exp->exp_obd, init_export)(exp);
1145 static inline int obd_destroy_export(struct obd_export *exp)
1148 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1149 OBP((exp)->exp_obd, destroy_export))
1150 OBP(exp->exp_obd, destroy_export)(exp);
1154 static inline int obd_extent_calc(struct obd_export *exp,
1155 struct lov_stripe_md *md,
1156 int cmd, obd_off *offset)
1160 EXP_CHECK_DT_OP(exp, extent_calc);
1161 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1165 static inline struct dentry *
1166 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1168 LASSERT(exp->exp_obd);
1170 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1175 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1177 LASSERT(exp->exp_obd);
1178 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1180 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1181 dentry, exp->exp_obd);
1186 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1187 * If the cache is older than @max_age we will get a new value from the
1188 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1189 static inline int obd_statfs_async(struct obd_device *obd,
1190 struct obd_info *oinfo,
1192 struct ptlrpc_request_set *rqset)
1200 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1201 OBD_COUNTER_INCREMENT(obd, statfs);
1203 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1204 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1205 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1206 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1208 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1209 " objects "LPU64"/"LPU64"\n",
1210 obd->obd_name, &obd->obd_osfs,
1211 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1212 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1213 cfs_spin_lock(&obd->obd_osfs_lock);
1214 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1215 cfs_spin_unlock(&obd->obd_osfs_lock);
1216 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1217 if (oinfo->oi_cb_up)
1218 oinfo->oi_cb_up(oinfo, 0);
1223 static inline int obd_statfs_rqset(struct obd_device *obd,
1224 struct obd_statfs *osfs, __u64 max_age,
1227 struct ptlrpc_request_set *set = NULL;
1228 struct obd_info oinfo = { { { 0 } } };
1232 set = ptlrpc_prep_set();
1236 oinfo.oi_osfs = osfs;
1237 oinfo.oi_flags = flags;
1238 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1240 rc = ptlrpc_set_wait(set);
1241 ptlrpc_set_destroy(set);
1245 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1246 * If the cache is older than @max_age we will get a new value from the
1247 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1248 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1249 __u64 max_age, __u32 flags)
1257 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1258 OBD_COUNTER_INCREMENT(obd, statfs);
1260 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1261 obd->obd_osfs_age, max_age);
1262 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1263 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1265 cfs_spin_lock(&obd->obd_osfs_lock);
1266 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1267 obd->obd_osfs_age = cfs_time_current_64();
1268 cfs_spin_unlock(&obd->obd_osfs_lock);
1271 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1272 " objects "LPU64"/"LPU64"\n",
1273 obd->obd_name, &obd->obd_osfs,
1274 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1275 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1276 cfs_spin_lock(&obd->obd_osfs_lock);
1277 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1278 cfs_spin_unlock(&obd->obd_osfs_lock);
1283 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
1284 obd_size start, obd_size end)
1286 struct ptlrpc_request_set *set = NULL;
1290 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1291 EXP_COUNTER_INCREMENT(exp, sync);
1293 set = ptlrpc_prep_set();
1297 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1299 rc = ptlrpc_set_wait(set);
1300 ptlrpc_set_destroy(set);
1304 static inline int obd_sync(struct obd_export *exp, struct obd_info *oinfo,
1305 obd_size start, obd_size end,
1306 struct ptlrpc_request_set *set)
1311 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1312 EXP_COUNTER_INCREMENT(exp, sync);
1314 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1318 static inline int obd_punch_rqset(struct obd_export *exp,
1319 struct obd_info *oinfo,
1320 struct obd_trans_info *oti)
1322 struct ptlrpc_request_set *set = NULL;
1326 EXP_CHECK_DT_OP(exp, punch);
1327 EXP_COUNTER_INCREMENT(exp, punch);
1329 set = ptlrpc_prep_set();
1333 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1335 rc = ptlrpc_set_wait(set);
1336 ptlrpc_set_destroy(set);
1340 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1341 struct obd_trans_info *oti,
1342 struct ptlrpc_request_set *rqset)
1347 EXP_CHECK_DT_OP(exp, punch);
1348 EXP_COUNTER_INCREMENT(exp, punch);
1350 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1354 static inline int obd_brw(int cmd, struct obd_export *exp,
1355 struct obd_info *oinfo, obd_count oa_bufs,
1356 struct brw_page *pg, struct obd_trans_info *oti)
1361 EXP_CHECK_DT_OP(exp, brw);
1362 EXP_COUNTER_INCREMENT(exp, brw);
1364 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1365 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1366 "or OBD_BRW_CHECK\n");
1370 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1374 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1375 int objcount, struct obd_ioobj *obj,
1376 struct niobuf_remote *remote, int *pages,
1377 struct niobuf_local *local,
1378 struct obd_trans_info *oti,
1379 struct lustre_capa *capa)
1384 EXP_CHECK_DT_OP(exp, preprw);
1385 EXP_COUNTER_INCREMENT(exp, preprw);
1387 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1388 pages, local, oti, capa);
1392 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1393 int objcount, struct obd_ioobj *obj,
1394 struct niobuf_remote *rnb, int pages,
1395 struct niobuf_local *local,
1396 struct obd_trans_info *oti, int rc)
1400 EXP_CHECK_DT_OP(exp, commitrw);
1401 EXP_COUNTER_INCREMENT(exp, commitrw);
1403 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1404 rnb, pages, local, oti, rc);
1408 static inline int obd_merge_lvb(struct obd_export *exp,
1409 struct lov_stripe_md *lsm,
1410 struct ost_lvb *lvb, int kms_only)
1415 EXP_CHECK_DT_OP(exp, merge_lvb);
1416 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1418 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1422 static inline int obd_adjust_kms(struct obd_export *exp,
1423 struct lov_stripe_md *lsm, obd_off size,
1429 EXP_CHECK_DT_OP(exp, adjust_kms);
1430 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1432 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1436 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1437 int len, void *karg, void *uarg)
1442 EXP_CHECK_DT_OP(exp, iocontrol);
1443 EXP_COUNTER_INCREMENT(exp, iocontrol);
1445 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1449 static inline int obd_enqueue_rqset(struct obd_export *exp,
1450 struct obd_info *oinfo,
1451 struct ldlm_enqueue_info *einfo)
1453 struct ptlrpc_request_set *set = NULL;
1457 EXP_CHECK_DT_OP(exp, enqueue);
1458 EXP_COUNTER_INCREMENT(exp, enqueue);
1460 set = ptlrpc_prep_set();
1464 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1466 rc = ptlrpc_set_wait(set);
1467 ptlrpc_set_destroy(set);
1471 static inline int obd_enqueue(struct obd_export *exp,
1472 struct obd_info *oinfo,
1473 struct ldlm_enqueue_info *einfo,
1474 struct ptlrpc_request_set *set)
1479 EXP_CHECK_DT_OP(exp, enqueue);
1480 EXP_COUNTER_INCREMENT(exp, enqueue);
1482 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1486 static inline int obd_change_cbdata(struct obd_export *exp,
1487 struct lov_stripe_md *lsm,
1488 ldlm_iterator_t it, void *data)
1493 EXP_CHECK_DT_OP(exp, change_cbdata);
1494 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1496 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1500 static inline int obd_find_cbdata(struct obd_export *exp,
1501 struct lov_stripe_md *lsm,
1502 ldlm_iterator_t it, void *data)
1507 EXP_CHECK_DT_OP(exp, find_cbdata);
1508 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1510 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1514 static inline int obd_cancel(struct obd_export *exp,
1515 struct lov_stripe_md *ea, __u32 mode,
1516 struct lustre_handle *lockh)
1521 EXP_CHECK_DT_OP(exp, cancel);
1522 EXP_COUNTER_INCREMENT(exp, cancel);
1524 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1528 static inline int obd_cancel_unused(struct obd_export *exp,
1529 struct lov_stripe_md *ea,
1530 ldlm_cancel_flags_t flags,
1536 EXP_CHECK_DT_OP(exp, cancel_unused);
1537 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1539 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1543 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1544 struct obd_capa *oc, struct obd_client_handle *handle,
1550 EXP_CHECK_DT_OP(exp, pin);
1551 EXP_COUNTER_INCREMENT(exp, pin);
1553 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1557 static inline int obd_unpin(struct obd_export *exp,
1558 struct obd_client_handle *handle, int flag)
1563 EXP_CHECK_DT_OP(exp, unpin);
1564 EXP_COUNTER_INCREMENT(exp, unpin);
1566 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1571 static inline void obd_import_event(struct obd_device *obd,
1572 struct obd_import *imp,
1573 enum obd_import_event event)
1577 CERROR("NULL device\n");
1581 if (obd->obd_set_up && OBP(obd, import_event)) {
1582 OBD_COUNTER_INCREMENT(obd, import_event);
1583 OBP(obd, import_event)(obd, imp, event);
1588 static inline int obd_llog_connect(struct obd_export *exp,
1589 struct llogd_conn_body *body)
1594 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1595 EXP_COUNTER_INCREMENT(exp, llog_connect);
1597 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1602 static inline int obd_notify(struct obd_device *obd,
1603 struct obd_device *watched,
1604 enum obd_notify_event ev,
1611 /* the check for async_recov is a complete hack - I'm hereby
1612 overloading the meaning to also mean "this was called from
1613 mds_postsetup". I know that my mds is able to handle notifies
1614 by this point, and it needs to get them to execute mds_postrecov. */
1615 if (!obd->obd_set_up && !obd->obd_async_recov) {
1616 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1620 if (!OBP(obd, notify)) {
1621 CERROR("obd %s has no notify handler\n", obd->obd_name);
1625 OBD_COUNTER_INCREMENT(obd, notify);
1626 rc = OBP(obd, notify)(obd, watched, ev, data);
1630 static inline int obd_notify_observer(struct obd_device *observer,
1631 struct obd_device *observed,
1632 enum obd_notify_event ev,
1638 struct obd_notify_upcall *onu;
1640 if (observer->obd_observer)
1641 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1645 * Also, call non-obd listener, if any
1647 onu = &observer->obd_upcall;
1648 if (onu->onu_upcall != NULL)
1649 rc2 = onu->onu_upcall(observer, observed, ev,
1650 onu->onu_owner, NULL);
1654 return rc1 ? rc1 : rc2;
1657 static inline int obd_quotacheck(struct obd_export *exp,
1658 struct obd_quotactl *oqctl)
1663 EXP_CHECK_DT_OP(exp, quotacheck);
1664 EXP_COUNTER_INCREMENT(exp, quotacheck);
1666 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1670 static inline int obd_quotactl(struct obd_export *exp,
1671 struct obd_quotactl *oqctl)
1676 EXP_CHECK_DT_OP(exp, quotactl);
1677 EXP_COUNTER_INCREMENT(exp, quotactl);
1679 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1683 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1684 struct quota_adjust_qunit *oqaq,
1685 struct lustre_quota_ctxt *qctxt,
1686 struct ptlrpc_request_set *set)
1688 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1689 struct timeval work_start;
1690 struct timeval work_end;
1696 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1698 cfs_gettimeofday(&work_start);
1700 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1701 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1703 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt, set);
1705 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1707 cfs_gettimeofday(&work_end);
1708 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1709 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1716 static inline int obd_health_check(struct obd_device *obd)
1718 /* returns: 0 on healthy
1719 * >0 on unhealthy + reason code/flag
1720 * however the only suppored reason == 1 right now
1721 * We'll need to define some better reasons
1722 * or flags in the future.
1728 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1729 if (obd == NULL || !OBT(obd)) {
1730 CERROR("cleaned up obd\n");
1731 RETURN(-EOPNOTSUPP);
1733 if (!obd->obd_set_up || obd->obd_stopping)
1735 if (!OBP(obd, health_check))
1738 rc = OBP(obd, health_check)(obd);
1742 static inline int obd_register_observer(struct obd_device *obd,
1743 struct obd_device *observer)
1747 cfs_down_write(&obd->obd_observer_link_sem);
1748 if (obd->obd_observer && observer) {
1749 cfs_up_write(&obd->obd_observer_link_sem);
1752 obd->obd_observer = observer;
1753 cfs_up_write(&obd->obd_observer_link_sem);
1757 static inline int obd_pin_observer(struct obd_device *obd,
1758 struct obd_device **observer)
1761 cfs_down_read(&obd->obd_observer_link_sem);
1762 if (!obd->obd_observer) {
1764 cfs_up_read(&obd->obd_observer_link_sem);
1767 *observer = obd->obd_observer;
1771 static inline int obd_unpin_observer(struct obd_device *obd)
1774 cfs_up_read(&obd->obd_observer_link_sem);
1779 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1780 obd_page_removal_cb_t cb,
1781 obd_pin_extent_cb pin_cb)
1786 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1787 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1789 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1793 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1794 obd_page_removal_cb_t cb)
1799 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1800 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1802 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1806 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1807 obd_lock_cancel_cb cb)
1812 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1813 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1815 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1819 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1820 obd_lock_cancel_cb cb)
1825 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1826 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1828 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1833 /* metadata helpers */
1834 static inline int md_getstatus(struct obd_export *exp,
1835 struct lu_fid *fid, struct obd_capa **pc)
1840 EXP_CHECK_MD_OP(exp, getstatus);
1841 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1842 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1846 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1847 struct ptlrpc_request **request)
1851 EXP_CHECK_MD_OP(exp, getattr);
1852 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1853 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1857 static inline int md_change_cbdata(struct obd_export *exp,
1858 const struct lu_fid *fid,
1859 ldlm_iterator_t it, void *data)
1863 EXP_CHECK_MD_OP(exp, change_cbdata);
1864 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1865 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1869 static inline int md_find_cbdata(struct obd_export *exp,
1870 const struct lu_fid *fid,
1871 ldlm_iterator_t it, void *data)
1875 EXP_CHECK_MD_OP(exp, find_cbdata);
1876 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1877 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1881 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1882 struct md_open_data *mod,
1883 struct ptlrpc_request **request)
1887 EXP_CHECK_MD_OP(exp, close);
1888 EXP_MD_COUNTER_INCREMENT(exp, close);
1889 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1893 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1894 const void *data, int datalen, int mode, __u32 uid,
1895 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1896 struct ptlrpc_request **request)
1900 EXP_CHECK_MD_OP(exp, create);
1901 EXP_MD_COUNTER_INCREMENT(exp, create);
1902 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1903 uid, gid, cap_effective, rdev, request);
1907 static inline int md_done_writing(struct obd_export *exp,
1908 struct md_op_data *op_data,
1909 struct md_open_data *mod)
1913 EXP_CHECK_MD_OP(exp, done_writing);
1914 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1915 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1919 static inline int md_enqueue(struct obd_export *exp,
1920 struct ldlm_enqueue_info *einfo,
1921 struct lookup_intent *it,
1922 struct md_op_data *op_data,
1923 struct lustre_handle *lockh,
1924 void *lmm, int lmmsize,
1925 struct ptlrpc_request **req,
1926 int extra_lock_flags)
1930 EXP_CHECK_MD_OP(exp, enqueue);
1931 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1932 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1933 lmm, lmmsize, req, extra_lock_flags);
1937 static inline int md_getattr_name(struct obd_export *exp,
1938 struct md_op_data *op_data,
1939 struct ptlrpc_request **request)
1943 EXP_CHECK_MD_OP(exp, getattr_name);
1944 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1945 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1949 static inline int md_intent_lock(struct obd_export *exp,
1950 struct md_op_data *op_data, void *lmm,
1951 int lmmsize, struct lookup_intent *it,
1952 int flags, struct ptlrpc_request **reqp,
1953 ldlm_blocking_callback cb_blocking,
1954 int extra_lock_flags)
1958 EXP_CHECK_MD_OP(exp, intent_lock);
1959 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1960 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1961 it, flags, reqp, cb_blocking,
1966 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1967 struct ptlrpc_request **request)
1971 EXP_CHECK_MD_OP(exp, link);
1972 EXP_MD_COUNTER_INCREMENT(exp, link);
1973 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1977 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1978 const char *old, int oldlen, const char *new,
1979 int newlen, struct ptlrpc_request **request)
1983 EXP_CHECK_MD_OP(exp, rename);
1984 EXP_MD_COUNTER_INCREMENT(exp, rename);
1985 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1990 static inline int md_is_subdir(struct obd_export *exp,
1991 const struct lu_fid *pfid,
1992 const struct lu_fid *cfid,
1993 struct ptlrpc_request **request)
1997 EXP_CHECK_MD_OP(exp, is_subdir);
1998 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1999 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
2003 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
2004 void *ea, int ealen, void *ea2, int ea2len,
2005 struct ptlrpc_request **request,
2006 struct md_open_data **mod)
2010 EXP_CHECK_MD_OP(exp, setattr);
2011 EXP_MD_COUNTER_INCREMENT(exp, setattr);
2012 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
2013 ea2, ea2len, request, mod);
2017 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
2018 struct obd_capa *oc, struct ptlrpc_request **request)
2022 EXP_CHECK_MD_OP(exp, sync);
2023 EXP_MD_COUNTER_INCREMENT(exp, sync);
2024 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
2028 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
2029 struct obd_capa *oc, __u64 offset,
2030 struct page **pages, unsigned npages,
2031 struct ptlrpc_request **request)
2035 EXP_CHECK_MD_OP(exp, readpage);
2036 EXP_MD_COUNTER_INCREMENT(exp, readpage);
2037 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, pages, npages,
2042 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
2043 struct ptlrpc_request **request)
2047 EXP_CHECK_MD_OP(exp, unlink);
2048 EXP_MD_COUNTER_INCREMENT(exp, unlink);
2049 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
2053 static inline int md_get_lustre_md(struct obd_export *exp,
2054 struct ptlrpc_request *req,
2055 struct obd_export *dt_exp,
2056 struct obd_export *md_exp,
2057 struct lustre_md *md)
2060 EXP_CHECK_MD_OP(exp, get_lustre_md);
2061 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
2062 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
2065 static inline int md_free_lustre_md(struct obd_export *exp,
2066 struct lustre_md *md)
2069 EXP_CHECK_MD_OP(exp, free_lustre_md);
2070 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2071 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2074 static inline int md_setxattr(struct obd_export *exp,
2075 const struct lu_fid *fid, struct obd_capa *oc,
2076 obd_valid valid, const char *name,
2077 const char *input, int input_size,
2078 int output_size, int flags, __u32 suppgid,
2079 struct ptlrpc_request **request)
2082 EXP_CHECK_MD_OP(exp, setxattr);
2083 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2084 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2085 input_size, output_size, flags,
2089 static inline int md_getxattr(struct obd_export *exp,
2090 const struct lu_fid *fid, struct obd_capa *oc,
2091 obd_valid valid, const char *name,
2092 const char *input, int input_size,
2093 int output_size, int flags,
2094 struct ptlrpc_request **request)
2097 EXP_CHECK_MD_OP(exp, getxattr);
2098 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2099 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2100 input_size, output_size, flags,
2104 static inline int md_set_open_replay_data(struct obd_export *exp,
2105 struct obd_client_handle *och,
2106 struct ptlrpc_request *open_req)
2109 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2110 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2111 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2114 static inline int md_clear_open_replay_data(struct obd_export *exp,
2115 struct obd_client_handle *och)
2118 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2119 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2120 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2123 static inline int md_set_lock_data(struct obd_export *exp,
2124 __u64 *lockh, void *data, __u32 *bits)
2127 EXP_CHECK_MD_OP(exp, set_lock_data);
2128 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2129 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2132 static inline int md_cancel_unused(struct obd_export *exp,
2133 const struct lu_fid *fid,
2134 ldlm_policy_data_t *policy,
2136 ldlm_cancel_flags_t flags,
2142 EXP_CHECK_MD_OP(exp, cancel_unused);
2143 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2145 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2150 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2151 const struct lu_fid *fid,
2153 ldlm_policy_data_t *policy,
2155 struct lustre_handle *lockh)
2158 EXP_CHECK_MD_OP(exp, lock_match);
2159 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2160 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2161 policy, mode, lockh));
2164 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2165 int def_asize, int cookiesize)
2168 EXP_CHECK_MD_OP(exp, init_ea_size);
2169 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2170 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2174 static inline int md_get_remote_perm(struct obd_export *exp,
2175 const struct lu_fid *fid,
2176 struct obd_capa *oc, __u32 suppgid,
2177 struct ptlrpc_request **request)
2180 EXP_CHECK_MD_OP(exp, get_remote_perm);
2181 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2182 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2186 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2191 EXP_CHECK_MD_OP(exp, renew_capa);
2192 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2193 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2197 static inline int md_unpack_capa(struct obd_export *exp,
2198 struct ptlrpc_request *req,
2199 const struct req_msg_field *field,
2200 struct obd_capa **oc)
2204 EXP_CHECK_MD_OP(exp, unpack_capa);
2205 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2206 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2210 static inline int md_intent_getattr_async(struct obd_export *exp,
2211 struct md_enqueue_info *minfo,
2212 struct ldlm_enqueue_info *einfo)
2216 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2217 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2218 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2222 static inline int md_revalidate_lock(struct obd_export *exp,
2223 struct lookup_intent *it,
2228 EXP_CHECK_MD_OP(exp, revalidate_lock);
2229 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2230 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2235 /* OBD Metadata Support */
2237 extern int obd_init_caches(void);
2238 extern void obd_cleanup_caches(void);
2240 /* support routines */
2241 extern cfs_mem_cache_t *obdo_cachep;
2243 #define OBDO_ALLOC(ptr) \
2245 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, CFS_ALLOC_IO); \
2248 #define OBDO_FREE(ptr) \
2250 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2254 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2256 /* something here */
2259 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2261 /* something here */
2264 /* I'm as embarrassed about this as you are.
2266 * <shaver> // XXX do not look into _superhack with remaining eye
2267 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2268 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2271 extern void obd_sysctl_init (void);
2272 extern void obd_sysctl_clean (void);
2275 typedef __u8 class_uuid_t[16];
2276 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2279 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2280 int class_add_uuid(const char *uuid, __u64 nid);
2281 int class_del_uuid (const char *uuid);
2282 void class_init_uuidlist(void);
2283 void class_exit_uuidlist(void);
2286 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2287 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2290 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2292 #endif /* __LINUX_OBD_CLASS_H */