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.
32 * Copyright (c) 2011, Whamcloud, Inc.
35 * This file is part of Lustre, http://www.lustre.org/
36 * Lustre is a trademark of Sun Microsystems, Inc.
42 # include <liblustre.h>
45 #include <obd_support.h>
46 #include <lustre_import.h>
47 #include <lustre_net.h>
49 #include <lustre_lib.h>
50 #include <lustre/lustre_idl.h>
51 #include <lprocfs_status.h>
53 #if defined(__linux__)
54 #include <linux/obd_class.h>
55 #elif defined(__APPLE__)
56 #include <darwin/obd_class.h>
57 #elif defined(__WINNT__)
58 #include <winnt/obd_class.h>
60 #error Unsupported operating system.
63 #define OBD_STATFS_NODELAY 0x0001 /* requests should be send without delay
64 * and resends for avoid deadlocks */
65 #define OBD_STATFS_FROM_CACHE 0x0002 /* the statfs callback should not update
67 #define OBD_STATFS_PTLRPCD 0x0004 /* requests will be sent via ptlrpcd
68 * instead of a specific set. This
69 * means that we cannot rely on the set
70 * interpret routine to be called.
71 * lov_statfs_fini() must thus be called
72 * by the request interpret routine */
74 #define OBD_FL_PUNCH 0x00000001 /* To indicate it is punch operation */
76 /* OBD Device Declarations */
77 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
78 extern cfs_rwlock_t obd_dev_lock;
80 /* OBD Operations Declarations */
81 extern struct obd_device *class_conn2obd(struct lustre_handle *);
82 extern struct obd_device *class_exp2obd(struct obd_export *);
83 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
85 struct lu_device_type;
88 struct obd_export *class_conn2export(struct lustre_handle *);
89 int class_register_type(struct obd_ops *, struct md_ops *,
90 struct lprocfs_vars *, const char *nm,
91 struct lu_device_type *ldt);
92 int class_unregister_type(const char *nm);
94 struct obd_device *class_newdev(const char *type_name, const char *name);
95 void class_release_dev(struct obd_device *obd);
97 int class_name2dev(const char *name);
98 struct obd_device *class_name2obd(const char *name);
99 int class_uuid2dev(struct obd_uuid *uuid);
100 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
101 void class_obd_list(void);
102 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
103 const char * typ_name,
104 struct obd_uuid *grp_uuid);
105 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
107 struct obd_device * class_num2obd(int num);
109 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
111 char *obd_export_nid2str(struct obd_export *exp);
113 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
114 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
115 int obd_connect_flags2str(char *page, int count, __u64 flags, char *sep);
117 int obd_zombie_impexp_init(void);
118 void obd_zombie_impexp_stop(void);
119 void obd_zombie_impexp_cull(void);
120 void obd_zombie_barrier(void);
121 void obd_exports_barrier(struct obd_device *obd);
122 int kuc_len(int payload_len);
123 struct kuc_hdr * kuc_ptr(void *p);
124 int kuc_ispayload(void *p);
125 void *kuc_alloc(int payload_len, int transport, int type);
126 void kuc_free(void *p, int payload_len);
129 int class_process_config(struct lustre_cfg *lcfg);
130 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
131 struct lustre_cfg *lcfg, void *data);
132 int class_attach(struct lustre_cfg *lcfg);
133 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
134 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
135 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
136 struct obd_device *class_incref(struct obd_device *obd,
137 const char *scope, const void *source);
138 void class_decref(struct obd_device *obd,
139 const char *scope, const void *source);
140 void dump_exports(struct obd_device *obd, int locks);
144 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
146 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
148 memset(lvars, 0, sizeof(*lvars));
152 #define CFG_F_START 0x01 /* Set when we start updating from a log */
153 #define CFG_F_MARKER 0x02 /* We are within a maker */
154 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
155 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
156 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
158 /* Passed as data param to class_config_parse_llog */
159 struct config_llog_instance {
162 struct super_block *cfg_sb;
163 struct obd_uuid cfg_uuid;
164 int cfg_last_idx; /* for partial llog processing */
167 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
168 struct config_llog_instance *cfg);
169 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
170 struct config_llog_instance *cfg);
174 CONFIG_T_SPTLRPC = 1,
175 CONFIG_T_RECOVER = 2,
179 /* list of active configuration logs */
180 struct config_llog_data {
181 struct ldlm_res_id cld_resid;
182 struct config_llog_instance cld_cfg;
183 cfs_list_t cld_list_chain;
184 cfs_atomic_t cld_refcount;
185 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
186 struct config_llog_data *cld_recover; /* imperative recover log */
187 struct obd_export *cld_mgcexp;
188 cfs_mutex_t cld_lock;
190 unsigned int cld_stopping:1, /* we were told to stop
192 cld_lostlock:1; /* lock not requeued */
196 struct lustre_profile {
203 struct lustre_profile *class_get_profile(const char * prof);
204 void class_del_profile(const char *prof);
205 void class_del_profiles(void);
207 #if LUSTRE_TRACKS_LOCK_EXP_REFS
209 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
210 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
211 extern void (*class_export_dump_hook)(struct obd_export *);
215 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
216 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
220 #define class_export_rpc_get(exp) \
222 cfs_atomic_inc(&(exp)->exp_rpc_count); \
223 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
224 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
225 class_export_get(exp); \
228 #define class_export_rpc_put(exp) \
230 LASSERT_ATOMIC_POS(&exp->exp_rpc_count); \
231 cfs_atomic_dec(&(exp)->exp_rpc_count); \
232 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
233 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
234 class_export_put(exp); \
237 #define class_export_lock_get(exp, lock) \
239 cfs_atomic_inc(&(exp)->exp_locks_count); \
240 __class_export_add_lock_ref(exp, lock); \
241 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
242 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
243 class_export_get(exp); \
246 #define class_export_lock_put(exp, lock) \
248 LASSERT_ATOMIC_POS(&exp->exp_locks_count); \
249 cfs_atomic_dec(&(exp)->exp_locks_count); \
250 __class_export_del_lock_ref(exp, lock); \
251 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
252 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
253 class_export_put(exp); \
256 #define class_export_cb_get(exp) \
258 cfs_atomic_inc(&(exp)->exp_cb_count); \
259 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
260 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
261 class_export_get(exp); \
264 #define class_export_cb_put(exp) \
266 LASSERT_ATOMIC_POS(&exp->exp_cb_count); \
267 cfs_atomic_dec(&(exp)->exp_cb_count); \
268 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
269 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
270 class_export_put(exp); \
274 struct obd_export *class_export_get(struct obd_export *exp);
275 void class_export_put(struct obd_export *exp);
276 struct obd_export *class_new_export(struct obd_device *obddev,
277 struct obd_uuid *cluuid);
278 void class_unlink_export(struct obd_export *exp);
280 struct obd_import *class_import_get(struct obd_import *);
281 void class_import_put(struct obd_import *);
282 struct obd_import *class_new_import(struct obd_device *obd);
283 void class_destroy_import(struct obd_import *exp);
285 struct obd_type *class_search_type(const char *name);
286 struct obd_type *class_get_type(const char *name);
287 void class_put_type(struct obd_type *type);
288 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
289 struct obd_uuid *cluuid);
290 int class_disconnect(struct obd_export *exp);
291 void class_fail_export(struct obd_export *exp);
292 int class_connected_export(struct obd_export *exp);
293 void class_disconnect_exports(struct obd_device *obddev);
294 int class_manual_cleanup(struct obd_device *obd);
295 void class_disconnect_stale_exports(struct obd_device *,
296 int (*test_export)(struct obd_export *));
297 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
299 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
300 (obd->obd_force ? OBD_OPT_FORCE : 0) |
301 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
305 static inline struct lu_target *class_exp2tgt(struct obd_export *exp)
307 LASSERT(exp->exp_obd);
308 return exp->exp_obd->u.obt.obt_lut;
311 static inline struct lr_server_data *class_server_data(struct obd_device *obd)
313 LASSERT(obd->u.obt.obt_lut);
314 return &obd->u.obt.obt_lut->lut_lsd;
317 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
318 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
319 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
320 unsigned int ia_valid);
321 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
322 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
323 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
326 #define OBT(dev) (dev)->obd_type
327 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
328 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
329 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
331 /* Ensure obd_setup: used for cleanup which must be called
332 while obd is stopping */
333 #define OBD_CHECK_DEV(obd) \
336 CERROR("NULL device\n"); \
341 /* ensure obd_setup and !obd_stopping */
342 #define OBD_CHECK_DEV_ACTIVE(obd) \
344 OBD_CHECK_DEV(obd); \
345 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
346 CERROR("Device %d not setup\n", \
354 #define OBD_COUNTER_OFFSET(op) \
355 ((offsetof(struct obd_ops, o_ ## op) - \
356 offsetof(struct obd_ops, o_iocontrol)) \
357 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
359 #define OBD_COUNTER_INCREMENT(obdx, op) \
360 if ((obdx)->obd_stats != NULL) { \
361 unsigned int coffset; \
362 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
363 OBD_COUNTER_OFFSET(op); \
364 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
365 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
368 #define EXP_COUNTER_INCREMENT(export, op) \
369 if ((export)->exp_obd->obd_stats != NULL) { \
370 unsigned int coffset; \
371 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
372 OBD_COUNTER_OFFSET(op); \
373 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
374 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
375 if ((export)->exp_nid_stats != NULL && \
376 (export)->exp_nid_stats->nid_stats != NULL) \
377 lprocfs_counter_incr( \
378 (export)->exp_nid_stats->nid_stats, coffset);\
381 #define MD_COUNTER_OFFSET(op) \
382 ((offsetof(struct md_ops, m_ ## op) - \
383 offsetof(struct md_ops, m_getstatus)) \
384 / sizeof(((struct md_ops *)(0))->m_getstatus))
386 #define MD_COUNTER_INCREMENT(obdx, op) \
387 if ((obd)->md_stats != NULL) { \
388 unsigned int coffset; \
389 coffset = (unsigned int)((obdx)->md_cntr_base) + \
390 MD_COUNTER_OFFSET(op); \
391 LASSERT(coffset < (obdx)->md_stats->ls_num); \
392 lprocfs_counter_incr((obdx)->md_stats, coffset); \
395 #define EXP_MD_COUNTER_INCREMENT(export, op) \
396 if ((export)->exp_obd->obd_stats != NULL) { \
397 unsigned int coffset; \
398 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
399 MD_COUNTER_OFFSET(op); \
400 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
401 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
402 if ((export)->exp_md_stats != NULL) \
403 lprocfs_counter_incr( \
404 (export)->exp_md_stats, coffset); \
408 #define OBD_COUNTER_OFFSET(op)
409 #define OBD_COUNTER_INCREMENT(obd, op)
410 #define EXP_COUNTER_INCREMENT(exp, op)
411 #define MD_COUNTER_INCREMENT(obd, op)
412 #define EXP_MD_COUNTER_INCREMENT(exp, op)
415 static inline int lprocfs_nid_ldlm_stats_init(struct nid_stat* tmp)
417 /* Always add in ldlm_stats */
418 tmp->nid_ldlm_stats = lprocfs_alloc_stats(LDLM_LAST_OPC - LDLM_FIRST_OPC
419 ,LPROCFS_STATS_FLAG_NOPERCPU);
420 if (tmp->nid_ldlm_stats == NULL)
423 lprocfs_init_ldlm_stats(tmp->nid_ldlm_stats);
425 return lprocfs_register_stats(tmp->nid_proc, "ldlm_stats",
426 tmp->nid_ldlm_stats);
429 #define OBD_CHECK_MD_OP(obd, op, err) \
431 if (!OBT(obd) || !MDP((obd), op)) { \
433 CERROR("md_" #op ": dev %s/%d no operation\n", \
434 obd->obd_name, obd->obd_minor); \
439 #define EXP_CHECK_MD_OP(exp, op) \
441 if ((exp) == NULL) { \
442 CERROR("obd_" #op ": NULL export\n"); \
445 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
446 CERROR("obd_" #op ": cleaned up obd\n"); \
447 RETURN(-EOPNOTSUPP); \
449 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
450 CERROR("obd_" #op ": dev %s/%d no operation\n", \
451 (exp)->exp_obd->obd_name, \
452 (exp)->exp_obd->obd_minor); \
453 RETURN(-EOPNOTSUPP); \
458 #define OBD_CHECK_DT_OP(obd, op, err) \
460 if (!OBT(obd) || !OBP((obd), op)) { \
462 CERROR("obd_" #op ": dev %d no operation\n", \
468 #define EXP_CHECK_DT_OP(exp, op) \
470 if ((exp) == NULL) { \
471 CERROR("obd_" #op ": NULL export\n"); \
474 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
475 CERROR("obd_" #op ": cleaned up obd\n"); \
476 RETURN(-EOPNOTSUPP); \
478 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
479 CERROR("obd_" #op ": dev %d no operation\n", \
480 (exp)->exp_obd->obd_minor); \
481 RETURN(-EOPNOTSUPP); \
485 #define CTXT_CHECK_OP(ctxt, op, err) \
487 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
489 CERROR("lop_" #op ": dev %d no operation\n", \
490 ctxt->loc_obd->obd_minor); \
495 static inline int class_devno_max(void)
497 return MAX_OBD_DEVICES;
500 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
501 void *key, __u32 *vallen, void *val,
502 struct lov_stripe_md *lsm)
507 EXP_CHECK_DT_OP(exp, get_info);
508 EXP_COUNTER_INCREMENT(exp, get_info);
510 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
514 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
515 void *key, obd_count vallen, void *val,
516 struct ptlrpc_request_set *set)
521 EXP_CHECK_DT_OP(exp, set_info_async);
522 EXP_COUNTER_INCREMENT(exp, set_info_async);
524 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
530 * obd-lu integration.
532 * Functionality is being moved into new lu_device-based layering, but some
533 * pieces of configuration process are still based on obd devices.
535 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
536 * subsume ->o_setup() methods of obd devices they replace. The same for
537 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
538 * result, obd_setup() and obd_process_config() branch and call one XOR
541 * Yet neither lu_device_type_operations::ldto_device_fini() nor
542 * lu_device_type_operations::ldto_device_free() fully implement the
543 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
544 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
547 #define DECLARE_LU_VARS(ldt, d) \
548 struct lu_device_type *ldt; \
551 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
554 DECLARE_LU_VARS(ldt, d);
557 ldt = obd->obd_type->typ_lu;
559 struct lu_context session_ctx;
561 lu_context_init(&session_ctx, LCT_SESSION);
562 session_ctx.lc_thread = NULL;
563 lu_context_enter(&session_ctx);
565 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
567 env.le_ses = &session_ctx;
568 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
577 lu_context_exit(&session_ctx);
578 lu_context_fini(&session_ctx);
581 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
582 OBD_COUNTER_INCREMENT(obd, setup);
583 rc = OBP(obd, setup)(obd, cfg);
588 static inline int obd_precleanup(struct obd_device *obd,
589 enum obd_cleanup_stage cleanup_stage)
592 DECLARE_LU_VARS(ldt, d);
596 ldt = obd->obd_type->typ_lu;
598 if (ldt != NULL && d != NULL) {
599 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
602 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
604 ldt->ldt_ops->ldto_device_fini(&env, d);
609 OBD_CHECK_DT_OP(obd, precleanup, 0);
610 OBD_COUNTER_INCREMENT(obd, precleanup);
612 rc = OBP(obd, precleanup)(obd, cleanup_stage);
616 static inline int obd_cleanup(struct obd_device *obd)
619 DECLARE_LU_VARS(ldt, d);
624 ldt = obd->obd_type->typ_lu;
626 if (ldt != NULL && d != NULL) {
629 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
631 ldt->ldt_ops->ldto_device_free(&env, d);
633 obd->obd_lu_dev = NULL;
636 OBD_CHECK_DT_OP(obd, cleanup, 0);
637 OBD_COUNTER_INCREMENT(obd, cleanup);
639 rc = OBP(obd, cleanup)(obd);
643 static inline void obd_cleanup_client_import(struct obd_device *obd)
647 /* If we set up but never connected, the
648 client import will not have been cleaned. */
649 cfs_down_write(&obd->u.cli.cl_sem);
650 if (obd->u.cli.cl_import) {
651 struct obd_import *imp;
652 imp = obd->u.cli.cl_import;
653 CDEBUG(D_CONFIG, "%s: client import never connected\n",
655 ptlrpc_invalidate_import(imp);
656 if (imp->imp_rq_pool) {
657 ptlrpc_free_rq_pool(imp->imp_rq_pool);
658 imp->imp_rq_pool = NULL;
660 class_destroy_import(imp);
661 obd->u.cli.cl_import = NULL;
663 cfs_up_write(&obd->u.cli.cl_sem);
669 obd_process_config(struct obd_device *obd, int datalen, void *data)
672 DECLARE_LU_VARS(ldt, d);
677 obd->obd_process_conf = 1;
678 ldt = obd->obd_type->typ_lu;
680 if (ldt != NULL && d != NULL) {
683 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
685 rc = d->ld_ops->ldo_process_config(&env, d, data);
689 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
690 rc = OBP(obd, process_config)(obd, datalen, data);
692 OBD_COUNTER_INCREMENT(obd, process_config);
693 obd->obd_process_conf = 0;
698 /* Pack an in-memory MD struct for storage on disk.
699 * Returns +ve size of packed MD (0 for free), or -ve error.
701 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
702 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
703 * If @*disk_tgt == NULL, it will be allocated
705 static inline int obd_packmd(struct obd_export *exp,
706 struct lov_mds_md **disk_tgt,
707 struct lov_stripe_md *mem_src)
712 EXP_CHECK_DT_OP(exp, packmd);
713 EXP_COUNTER_INCREMENT(exp, packmd);
715 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
719 static inline int obd_size_diskmd(struct obd_export *exp,
720 struct lov_stripe_md *mem_src)
722 return obd_packmd(exp, NULL, mem_src);
725 /* helper functions */
726 static inline int obd_alloc_diskmd(struct obd_export *exp,
727 struct lov_mds_md **disk_tgt)
730 LASSERT(*disk_tgt == NULL);
731 return obd_packmd(exp, disk_tgt, NULL);
734 static inline int obd_free_diskmd(struct obd_export *exp,
735 struct lov_mds_md **disk_tgt)
739 return obd_packmd(exp, disk_tgt, NULL);
742 /* Unpack an MD struct from disk to in-memory format.
743 * Returns +ve size of unpacked MD (0 for free), or -ve error.
745 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
746 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
747 * If @*mem_tgt == NULL, it will be allocated
749 static inline int obd_unpackmd(struct obd_export *exp,
750 struct lov_stripe_md **mem_tgt,
751 struct lov_mds_md *disk_src,
757 EXP_CHECK_DT_OP(exp, unpackmd);
758 EXP_COUNTER_INCREMENT(exp, unpackmd);
760 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
764 /* helper functions */
765 static inline int obd_alloc_memmd(struct obd_export *exp,
766 struct lov_stripe_md **mem_tgt)
769 LASSERT(*mem_tgt == NULL);
770 return obd_unpackmd(exp, mem_tgt, NULL, 0);
773 static inline int obd_free_memmd(struct obd_export *exp,
774 struct lov_stripe_md **mem_tgt)
780 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
785 static inline int obd_precreate(struct obd_export *exp)
790 EXP_CHECK_DT_OP(exp, precreate);
791 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
793 rc = OBP(exp->exp_obd, precreate)(exp);
797 static inline int obd_create_async(struct obd_export *exp,
798 struct obd_info *oinfo,
799 struct lov_stripe_md **ea,
800 struct obd_trans_info *oti)
805 EXP_CHECK_DT_OP(exp, create_async);
806 EXP_COUNTER_INCREMENT(exp, create_async);
808 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
812 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
813 struct lov_stripe_md **ea,
814 struct obd_trans_info *oti)
819 EXP_CHECK_DT_OP(exp, create);
820 EXP_COUNTER_INCREMENT(exp, create);
822 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
826 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
827 struct lov_stripe_md *ea,
828 struct obd_trans_info *oti,
829 struct obd_export *md_exp, void *capa)
834 EXP_CHECK_DT_OP(exp, destroy);
835 EXP_COUNTER_INCREMENT(exp, destroy);
837 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
841 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
846 EXP_CHECK_DT_OP(exp, getattr);
847 EXP_COUNTER_INCREMENT(exp, getattr);
849 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
853 static inline int obd_getattr_async(struct obd_export *exp,
854 struct obd_info *oinfo,
855 struct ptlrpc_request_set *set)
860 EXP_CHECK_DT_OP(exp, getattr_async);
861 EXP_COUNTER_INCREMENT(exp, getattr_async);
863 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
867 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
868 struct obd_trans_info *oti)
873 EXP_CHECK_DT_OP(exp, setattr);
874 EXP_COUNTER_INCREMENT(exp, setattr);
876 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
880 /* This performs all the requests set init/wait/destroy actions. */
881 static inline int obd_setattr_rqset(struct obd_export *exp,
882 struct obd_info *oinfo,
883 struct obd_trans_info *oti)
885 struct ptlrpc_request_set *set = NULL;
889 EXP_CHECK_DT_OP(exp, setattr_async);
890 EXP_COUNTER_INCREMENT(exp, setattr_async);
892 set = ptlrpc_prep_set();
896 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
898 rc = ptlrpc_set_wait(set);
899 ptlrpc_set_destroy(set);
903 /* This adds all the requests into @set if @set != NULL, otherwise
904 all requests are sent asynchronously without waiting for response. */
905 static inline int obd_setattr_async(struct obd_export *exp,
906 struct obd_info *oinfo,
907 struct obd_trans_info *oti,
908 struct ptlrpc_request_set *set)
913 EXP_CHECK_DT_OP(exp, setattr_async);
914 EXP_COUNTER_INCREMENT(exp, setattr_async);
916 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
920 static inline int obd_add_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, add_conn, -EOPNOTSUPP);
929 OBD_COUNTER_INCREMENT(obd, add_conn);
931 rc = OBP(obd, add_conn)(imp, uuid, priority);
935 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
937 struct obd_device *obd = imp->imp_obd;
941 OBD_CHECK_DEV_ACTIVE(obd);
942 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
943 OBD_COUNTER_INCREMENT(obd, del_conn);
945 rc = OBP(obd, del_conn)(imp, uuid);
949 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
951 struct obd_uuid *uuid;
954 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
955 EXP_COUNTER_INCREMENT(exp, get_uuid);
957 uuid = OBP(exp->exp_obd, get_uuid)(exp);
961 /** Create a new /a exp on device /a obd for the uuid /a cluuid
962 * @param exp New export handle
963 * @param d Connect data, supported flags are set, flags also understood
964 * by obd are returned.
966 static inline int obd_connect(const struct lu_env *env,
967 struct obd_export **exp,struct obd_device *obd,
968 struct obd_uuid *cluuid,
969 struct obd_connect_data *data,
973 __u64 ocf = data ? data->ocd_connect_flags : 0; /* for post-condition
977 OBD_CHECK_DEV_ACTIVE(obd);
978 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
979 OBD_COUNTER_INCREMENT(obd, connect);
981 rc = OBP(obd, connect)(env, exp, obd, cluuid, data, localdata);
982 /* check that only subset is granted */
983 LASSERT(ergo(data != NULL, (data->ocd_connect_flags & ocf) ==
984 data->ocd_connect_flags));
988 static inline int obd_reconnect(const struct lu_env *env,
989 struct obd_export *exp,
990 struct obd_device *obd,
991 struct obd_uuid *cluuid,
992 struct obd_connect_data *d,
996 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
1001 OBD_CHECK_DEV_ACTIVE(obd);
1002 OBD_CHECK_DT_OP(obd, reconnect, 0);
1003 OBD_COUNTER_INCREMENT(obd, reconnect);
1005 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
1006 /* check that only subset is granted */
1007 LASSERT(ergo(d != NULL,
1008 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
1012 static inline int obd_disconnect(struct obd_export *exp)
1017 EXP_CHECK_DT_OP(exp, disconnect);
1018 EXP_COUNTER_INCREMENT(exp, disconnect);
1020 rc = OBP(exp->exp_obd, disconnect)(exp);
1024 static inline int obd_fid_init(struct obd_export *exp)
1029 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
1030 EXP_COUNTER_INCREMENT(exp, fid_init);
1032 rc = OBP(exp->exp_obd, fid_init)(exp);
1036 static inline int obd_fid_fini(struct obd_export *exp)
1041 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
1042 EXP_COUNTER_INCREMENT(exp, fid_fini);
1044 rc = OBP(exp->exp_obd, fid_fini)(exp);
1048 static inline int obd_fid_alloc(struct obd_export *exp,
1050 struct md_op_data *op_data)
1055 EXP_CHECK_DT_OP(exp, fid_alloc);
1056 EXP_COUNTER_INCREMENT(exp, fid_alloc);
1058 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
1062 static inline int obd_fid_delete(struct obd_export *exp,
1063 const struct lu_fid *fid)
1068 EXP_CHECK_DT_OP(exp, fid_delete);
1069 EXP_COUNTER_INCREMENT(exp, fid_delete);
1071 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
1075 static inline int obd_ping(struct obd_export *exp)
1080 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
1081 EXP_COUNTER_INCREMENT(exp, ping);
1083 rc = OBP(exp->exp_obd, ping)(exp);
1087 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1092 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1093 OBD_COUNTER_INCREMENT(obd, pool_new);
1095 rc = OBP(obd, pool_new)(obd, poolname);
1099 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1104 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1105 OBD_COUNTER_INCREMENT(obd, pool_del);
1107 rc = OBP(obd, pool_del)(obd, poolname);
1111 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1116 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1117 OBD_COUNTER_INCREMENT(obd, pool_add);
1119 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1123 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1128 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1129 OBD_COUNTER_INCREMENT(obd, pool_rem);
1131 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1135 static inline void obd_getref(struct obd_device *obd)
1138 if (OBT(obd) && OBP(obd, getref)) {
1139 OBD_COUNTER_INCREMENT(obd, getref);
1140 OBP(obd, getref)(obd);
1145 static inline void obd_putref(struct obd_device *obd)
1148 if (OBT(obd) && OBP(obd, putref)) {
1149 OBD_COUNTER_INCREMENT(obd, putref);
1150 OBP(obd, putref)(obd);
1155 static inline int obd_init_export(struct obd_export *exp)
1160 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1161 OBP((exp)->exp_obd, init_export))
1162 rc = OBP(exp->exp_obd, init_export)(exp);
1166 static inline int obd_destroy_export(struct obd_export *exp)
1169 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1170 OBP((exp)->exp_obd, destroy_export))
1171 OBP(exp->exp_obd, destroy_export)(exp);
1175 static inline int obd_extent_calc(struct obd_export *exp,
1176 struct lov_stripe_md *md,
1177 int cmd, obd_off *offset)
1181 EXP_CHECK_DT_OP(exp, extent_calc);
1182 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1186 static inline struct dentry *
1187 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1189 LASSERT(exp->exp_obd);
1191 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1196 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1198 LASSERT(exp->exp_obd);
1199 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1201 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1202 dentry, exp->exp_obd);
1207 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1208 * If the cache is older than @max_age we will get a new value from the
1209 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1210 static inline int obd_statfs_async(struct obd_device *obd,
1211 struct obd_info *oinfo,
1213 struct ptlrpc_request_set *rqset)
1221 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1222 OBD_COUNTER_INCREMENT(obd, statfs);
1224 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1225 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1226 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1227 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1229 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1230 " objects "LPU64"/"LPU64"\n",
1231 obd->obd_name, &obd->obd_osfs,
1232 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1233 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1234 cfs_spin_lock(&obd->obd_osfs_lock);
1235 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1236 cfs_spin_unlock(&obd->obd_osfs_lock);
1237 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1238 if (oinfo->oi_cb_up)
1239 oinfo->oi_cb_up(oinfo, 0);
1244 static inline int obd_statfs_rqset(struct obd_device *obd,
1245 struct obd_statfs *osfs, __u64 max_age,
1248 struct ptlrpc_request_set *set = NULL;
1249 struct obd_info oinfo = { { { 0 } } };
1253 set = ptlrpc_prep_set();
1257 oinfo.oi_osfs = osfs;
1258 oinfo.oi_flags = flags;
1259 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1261 rc = ptlrpc_set_wait(set);
1262 ptlrpc_set_destroy(set);
1266 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1267 * If the cache is older than @max_age we will get a new value from the
1268 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1269 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1270 __u64 max_age, __u32 flags)
1278 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1279 OBD_COUNTER_INCREMENT(obd, statfs);
1281 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1282 obd->obd_osfs_age, max_age);
1283 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1284 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1286 cfs_spin_lock(&obd->obd_osfs_lock);
1287 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1288 obd->obd_osfs_age = cfs_time_current_64();
1289 cfs_spin_unlock(&obd->obd_osfs_lock);
1292 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1293 " objects "LPU64"/"LPU64"\n",
1294 obd->obd_name, &obd->obd_osfs,
1295 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1296 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1297 cfs_spin_lock(&obd->obd_osfs_lock);
1298 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1299 cfs_spin_unlock(&obd->obd_osfs_lock);
1304 static inline int obd_sync_rqset(struct obd_export *exp, struct obd_info *oinfo,
1305 obd_size start, obd_size end)
1307 struct ptlrpc_request_set *set = NULL;
1311 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1312 EXP_COUNTER_INCREMENT(exp, sync);
1314 set = ptlrpc_prep_set();
1318 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1320 rc = ptlrpc_set_wait(set);
1321 ptlrpc_set_destroy(set);
1325 static inline int obd_sync(struct obd_export *exp, struct obd_info *oinfo,
1326 obd_size start, obd_size end,
1327 struct ptlrpc_request_set *set)
1332 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1333 EXP_COUNTER_INCREMENT(exp, sync);
1335 rc = OBP(exp->exp_obd, sync)(exp, oinfo, start, end, set);
1339 static inline int obd_punch_rqset(struct obd_export *exp,
1340 struct obd_info *oinfo,
1341 struct obd_trans_info *oti)
1343 struct ptlrpc_request_set *set = NULL;
1347 EXP_CHECK_DT_OP(exp, punch);
1348 EXP_COUNTER_INCREMENT(exp, punch);
1350 set = ptlrpc_prep_set();
1354 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1356 rc = ptlrpc_set_wait(set);
1357 ptlrpc_set_destroy(set);
1361 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1362 struct obd_trans_info *oti,
1363 struct ptlrpc_request_set *rqset)
1368 EXP_CHECK_DT_OP(exp, punch);
1369 EXP_COUNTER_INCREMENT(exp, punch);
1371 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1375 static inline int obd_brw(int cmd, struct obd_export *exp,
1376 struct obd_info *oinfo, obd_count oa_bufs,
1377 struct brw_page *pg, struct obd_trans_info *oti)
1382 EXP_CHECK_DT_OP(exp, brw);
1383 EXP_COUNTER_INCREMENT(exp, brw);
1385 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1386 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1387 "or OBD_BRW_CHECK\n");
1391 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1395 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1396 int objcount, struct obd_ioobj *obj,
1397 struct niobuf_remote *remote, int *pages,
1398 struct niobuf_local *local,
1399 struct obd_trans_info *oti,
1400 struct lustre_capa *capa)
1405 EXP_CHECK_DT_OP(exp, preprw);
1406 EXP_COUNTER_INCREMENT(exp, preprw);
1408 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1409 pages, local, oti, capa);
1413 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1414 int objcount, struct obd_ioobj *obj,
1415 struct niobuf_remote *rnb, int pages,
1416 struct niobuf_local *local,
1417 struct obd_trans_info *oti, int rc)
1421 EXP_CHECK_DT_OP(exp, commitrw);
1422 EXP_COUNTER_INCREMENT(exp, commitrw);
1424 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1425 rnb, pages, local, oti, rc);
1429 static inline int obd_merge_lvb(struct obd_export *exp,
1430 struct lov_stripe_md *lsm,
1431 struct ost_lvb *lvb, int kms_only)
1436 EXP_CHECK_DT_OP(exp, merge_lvb);
1437 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1439 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1443 static inline int obd_adjust_kms(struct obd_export *exp,
1444 struct lov_stripe_md *lsm, obd_off size,
1450 EXP_CHECK_DT_OP(exp, adjust_kms);
1451 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1453 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1457 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1458 int len, void *karg, void *uarg)
1463 EXP_CHECK_DT_OP(exp, iocontrol);
1464 EXP_COUNTER_INCREMENT(exp, iocontrol);
1466 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1470 static inline int obd_enqueue_rqset(struct obd_export *exp,
1471 struct obd_info *oinfo,
1472 struct ldlm_enqueue_info *einfo)
1474 struct ptlrpc_request_set *set = NULL;
1478 EXP_CHECK_DT_OP(exp, enqueue);
1479 EXP_COUNTER_INCREMENT(exp, enqueue);
1481 set = ptlrpc_prep_set();
1485 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1487 rc = ptlrpc_set_wait(set);
1488 ptlrpc_set_destroy(set);
1492 static inline int obd_enqueue(struct obd_export *exp,
1493 struct obd_info *oinfo,
1494 struct ldlm_enqueue_info *einfo,
1495 struct ptlrpc_request_set *set)
1500 EXP_CHECK_DT_OP(exp, enqueue);
1501 EXP_COUNTER_INCREMENT(exp, enqueue);
1503 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1507 static inline int obd_change_cbdata(struct obd_export *exp,
1508 struct lov_stripe_md *lsm,
1509 ldlm_iterator_t it, void *data)
1514 EXP_CHECK_DT_OP(exp, change_cbdata);
1515 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1517 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1521 static inline int obd_find_cbdata(struct obd_export *exp,
1522 struct lov_stripe_md *lsm,
1523 ldlm_iterator_t it, void *data)
1528 EXP_CHECK_DT_OP(exp, find_cbdata);
1529 EXP_COUNTER_INCREMENT(exp, find_cbdata);
1531 rc = OBP(exp->exp_obd, find_cbdata)(exp, lsm, it, data);
1535 static inline int obd_cancel(struct obd_export *exp,
1536 struct lov_stripe_md *ea, __u32 mode,
1537 struct lustre_handle *lockh)
1542 EXP_CHECK_DT_OP(exp, cancel);
1543 EXP_COUNTER_INCREMENT(exp, cancel);
1545 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1549 static inline int obd_cancel_unused(struct obd_export *exp,
1550 struct lov_stripe_md *ea,
1551 ldlm_cancel_flags_t flags,
1557 EXP_CHECK_DT_OP(exp, cancel_unused);
1558 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1560 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1564 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1565 struct obd_capa *oc, struct obd_client_handle *handle,
1571 EXP_CHECK_DT_OP(exp, pin);
1572 EXP_COUNTER_INCREMENT(exp, pin);
1574 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1578 static inline int obd_unpin(struct obd_export *exp,
1579 struct obd_client_handle *handle, int flag)
1584 EXP_CHECK_DT_OP(exp, unpin);
1585 EXP_COUNTER_INCREMENT(exp, unpin);
1587 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1592 static inline void obd_import_event(struct obd_device *obd,
1593 struct obd_import *imp,
1594 enum obd_import_event event)
1598 CERROR("NULL device\n");
1602 if (obd->obd_set_up && OBP(obd, import_event)) {
1603 OBD_COUNTER_INCREMENT(obd, import_event);
1604 OBP(obd, import_event)(obd, imp, event);
1609 static inline int obd_llog_connect(struct obd_export *exp,
1610 struct llogd_conn_body *body)
1615 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1616 EXP_COUNTER_INCREMENT(exp, llog_connect);
1618 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1623 static inline int obd_notify(struct obd_device *obd,
1624 struct obd_device *watched,
1625 enum obd_notify_event ev,
1632 /* the check for async_recov is a complete hack - I'm hereby
1633 overloading the meaning to also mean "this was called from
1634 mds_postsetup". I know that my mds is able to handle notifies
1635 by this point, and it needs to get them to execute mds_postrecov. */
1636 if (!obd->obd_set_up && !obd->obd_async_recov) {
1637 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1641 if (!OBP(obd, notify)) {
1642 CERROR("obd %s has no notify handler\n", obd->obd_name);
1646 OBD_COUNTER_INCREMENT(obd, notify);
1647 rc = OBP(obd, notify)(obd, watched, ev, data);
1651 static inline int obd_notify_observer(struct obd_device *observer,
1652 struct obd_device *observed,
1653 enum obd_notify_event ev,
1659 struct obd_notify_upcall *onu;
1661 if (observer->obd_observer)
1662 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1666 * Also, call non-obd listener, if any
1668 onu = &observer->obd_upcall;
1669 if (onu->onu_upcall != NULL)
1670 rc2 = onu->onu_upcall(observer, observed, ev,
1671 onu->onu_owner, NULL);
1675 return rc1 ? rc1 : rc2;
1678 static inline int obd_quotacheck(struct obd_export *exp,
1679 struct obd_quotactl *oqctl)
1684 EXP_CHECK_DT_OP(exp, quotacheck);
1685 EXP_COUNTER_INCREMENT(exp, quotacheck);
1687 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1691 static inline int obd_quotactl(struct obd_export *exp,
1692 struct obd_quotactl *oqctl)
1697 EXP_CHECK_DT_OP(exp, quotactl);
1698 EXP_COUNTER_INCREMENT(exp, quotactl);
1700 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1704 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1705 struct quota_adjust_qunit *oqaq,
1706 struct lustre_quota_ctxt *qctxt,
1707 struct ptlrpc_request_set *set)
1709 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1710 struct timeval work_start;
1711 struct timeval work_end;
1717 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1719 cfs_gettimeofday(&work_start);
1721 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1722 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1724 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt, set);
1726 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1728 cfs_gettimeofday(&work_end);
1729 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1730 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1737 static inline int obd_health_check(struct obd_device *obd)
1739 /* returns: 0 on healthy
1740 * >0 on unhealthy + reason code/flag
1741 * however the only suppored reason == 1 right now
1742 * We'll need to define some better reasons
1743 * or flags in the future.
1749 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1750 if (obd == NULL || !OBT(obd)) {
1751 CERROR("cleaned up obd\n");
1752 RETURN(-EOPNOTSUPP);
1754 if (!obd->obd_set_up || obd->obd_stopping)
1756 if (!OBP(obd, health_check))
1759 rc = OBP(obd, health_check)(obd);
1763 static inline int obd_register_observer(struct obd_device *obd,
1764 struct obd_device *observer)
1768 cfs_down_write(&obd->obd_observer_link_sem);
1769 if (obd->obd_observer && observer) {
1770 cfs_up_write(&obd->obd_observer_link_sem);
1773 obd->obd_observer = observer;
1774 cfs_up_write(&obd->obd_observer_link_sem);
1778 static inline int obd_pin_observer(struct obd_device *obd,
1779 struct obd_device **observer)
1782 cfs_down_read(&obd->obd_observer_link_sem);
1783 if (!obd->obd_observer) {
1785 cfs_up_read(&obd->obd_observer_link_sem);
1788 *observer = obd->obd_observer;
1792 static inline int obd_unpin_observer(struct obd_device *obd)
1795 cfs_up_read(&obd->obd_observer_link_sem);
1800 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1801 obd_page_removal_cb_t cb,
1802 obd_pin_extent_cb pin_cb)
1807 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1808 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1810 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1814 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1815 obd_page_removal_cb_t cb)
1820 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1821 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1823 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1827 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1828 obd_lock_cancel_cb cb)
1833 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1834 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1836 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1840 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1841 obd_lock_cancel_cb cb)
1846 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1847 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1849 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1854 /* metadata helpers */
1855 static inline int md_getstatus(struct obd_export *exp,
1856 struct lu_fid *fid, struct obd_capa **pc)
1861 EXP_CHECK_MD_OP(exp, getstatus);
1862 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1863 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1867 static inline int md_getattr(struct obd_export *exp, struct md_op_data *op_data,
1868 struct ptlrpc_request **request)
1872 EXP_CHECK_MD_OP(exp, getattr);
1873 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1874 rc = MDP(exp->exp_obd, getattr)(exp, op_data, request);
1878 static inline int md_change_cbdata(struct obd_export *exp,
1879 const struct lu_fid *fid,
1880 ldlm_iterator_t it, void *data)
1884 EXP_CHECK_MD_OP(exp, change_cbdata);
1885 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1886 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1890 static inline int md_find_cbdata(struct obd_export *exp,
1891 const struct lu_fid *fid,
1892 ldlm_iterator_t it, void *data)
1896 EXP_CHECK_MD_OP(exp, find_cbdata);
1897 EXP_MD_COUNTER_INCREMENT(exp, find_cbdata);
1898 rc = MDP(exp->exp_obd, find_cbdata)(exp, fid, it, data);
1902 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1903 struct md_open_data *mod,
1904 struct ptlrpc_request **request)
1908 EXP_CHECK_MD_OP(exp, close);
1909 EXP_MD_COUNTER_INCREMENT(exp, close);
1910 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1914 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1915 const void *data, int datalen, int mode, __u32 uid,
1916 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1917 struct ptlrpc_request **request)
1921 EXP_CHECK_MD_OP(exp, create);
1922 EXP_MD_COUNTER_INCREMENT(exp, create);
1923 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1924 uid, gid, cap_effective, rdev, request);
1928 static inline int md_done_writing(struct obd_export *exp,
1929 struct md_op_data *op_data,
1930 struct md_open_data *mod)
1934 EXP_CHECK_MD_OP(exp, done_writing);
1935 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1936 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1940 static inline int md_enqueue(struct obd_export *exp,
1941 struct ldlm_enqueue_info *einfo,
1942 struct lookup_intent *it,
1943 struct md_op_data *op_data,
1944 struct lustre_handle *lockh,
1945 void *lmm, int lmmsize,
1946 struct ptlrpc_request **req,
1947 int extra_lock_flags)
1951 EXP_CHECK_MD_OP(exp, enqueue);
1952 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1953 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1954 lmm, lmmsize, req, extra_lock_flags);
1958 static inline int md_getattr_name(struct obd_export *exp,
1959 struct md_op_data *op_data,
1960 struct ptlrpc_request **request)
1964 EXP_CHECK_MD_OP(exp, getattr_name);
1965 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1966 rc = MDP(exp->exp_obd, getattr_name)(exp, op_data, request);
1970 static inline int md_intent_lock(struct obd_export *exp,
1971 struct md_op_data *op_data, void *lmm,
1972 int lmmsize, struct lookup_intent *it,
1973 int flags, struct ptlrpc_request **reqp,
1974 ldlm_blocking_callback cb_blocking,
1975 int extra_lock_flags)
1979 EXP_CHECK_MD_OP(exp, intent_lock);
1980 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1981 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1982 it, flags, reqp, cb_blocking,
1987 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1988 struct ptlrpc_request **request)
1992 EXP_CHECK_MD_OP(exp, link);
1993 EXP_MD_COUNTER_INCREMENT(exp, link);
1994 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1998 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1999 const char *old, int oldlen, const char *new,
2000 int newlen, struct ptlrpc_request **request)
2004 EXP_CHECK_MD_OP(exp, rename);
2005 EXP_MD_COUNTER_INCREMENT(exp, rename);
2006 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
2011 static inline int md_is_subdir(struct obd_export *exp,
2012 const struct lu_fid *pfid,
2013 const struct lu_fid *cfid,
2014 struct ptlrpc_request **request)
2018 EXP_CHECK_MD_OP(exp, is_subdir);
2019 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
2020 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
2024 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
2025 void *ea, int ealen, void *ea2, int ea2len,
2026 struct ptlrpc_request **request,
2027 struct md_open_data **mod)
2031 EXP_CHECK_MD_OP(exp, setattr);
2032 EXP_MD_COUNTER_INCREMENT(exp, setattr);
2033 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
2034 ea2, ea2len, request, mod);
2038 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
2039 struct obd_capa *oc, struct ptlrpc_request **request)
2043 EXP_CHECK_MD_OP(exp, sync);
2044 EXP_MD_COUNTER_INCREMENT(exp, sync);
2045 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
2049 static inline int md_readpage(struct obd_export *exp, struct md_op_data *opdata,
2050 struct page **pages,
2051 struct ptlrpc_request **request)
2055 EXP_CHECK_MD_OP(exp, readpage);
2056 EXP_MD_COUNTER_INCREMENT(exp, readpage);
2057 rc = MDP(exp->exp_obd, readpage)(exp, opdata, pages, request);
2061 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
2062 struct ptlrpc_request **request)
2066 EXP_CHECK_MD_OP(exp, unlink);
2067 EXP_MD_COUNTER_INCREMENT(exp, unlink);
2068 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
2072 static inline int md_get_lustre_md(struct obd_export *exp,
2073 struct ptlrpc_request *req,
2074 struct obd_export *dt_exp,
2075 struct obd_export *md_exp,
2076 struct lustre_md *md)
2079 EXP_CHECK_MD_OP(exp, get_lustre_md);
2080 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
2081 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
2084 static inline int md_free_lustre_md(struct obd_export *exp,
2085 struct lustre_md *md)
2088 EXP_CHECK_MD_OP(exp, free_lustre_md);
2089 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
2090 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
2093 static inline int md_setxattr(struct obd_export *exp,
2094 const struct lu_fid *fid, struct obd_capa *oc,
2095 obd_valid valid, const char *name,
2096 const char *input, int input_size,
2097 int output_size, int flags, __u32 suppgid,
2098 struct ptlrpc_request **request)
2101 EXP_CHECK_MD_OP(exp, setxattr);
2102 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
2103 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
2104 input_size, output_size, flags,
2108 static inline int md_getxattr(struct obd_export *exp,
2109 const struct lu_fid *fid, struct obd_capa *oc,
2110 obd_valid valid, const char *name,
2111 const char *input, int input_size,
2112 int output_size, int flags,
2113 struct ptlrpc_request **request)
2116 EXP_CHECK_MD_OP(exp, getxattr);
2117 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
2118 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
2119 input_size, output_size, flags,
2123 static inline int md_set_open_replay_data(struct obd_export *exp,
2124 struct obd_client_handle *och,
2125 struct ptlrpc_request *open_req)
2128 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2129 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2130 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2133 static inline int md_clear_open_replay_data(struct obd_export *exp,
2134 struct obd_client_handle *och)
2137 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2138 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2139 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2142 static inline int md_set_lock_data(struct obd_export *exp,
2143 __u64 *lockh, void *data, __u64 *bits)
2146 EXP_CHECK_MD_OP(exp, set_lock_data);
2147 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2148 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2151 static inline int md_cancel_unused(struct obd_export *exp,
2152 const struct lu_fid *fid,
2153 ldlm_policy_data_t *policy,
2155 ldlm_cancel_flags_t flags,
2161 EXP_CHECK_MD_OP(exp, cancel_unused);
2162 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2164 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2169 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2170 const struct lu_fid *fid,
2172 ldlm_policy_data_t *policy,
2174 struct lustre_handle *lockh)
2177 EXP_CHECK_MD_OP(exp, lock_match);
2178 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2179 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2180 policy, mode, lockh));
2183 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2184 int def_asize, int cookiesize)
2187 EXP_CHECK_MD_OP(exp, init_ea_size);
2188 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2189 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2193 static inline int md_get_remote_perm(struct obd_export *exp,
2194 const struct lu_fid *fid,
2195 struct obd_capa *oc, __u32 suppgid,
2196 struct ptlrpc_request **request)
2199 EXP_CHECK_MD_OP(exp, get_remote_perm);
2200 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2201 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2205 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2210 EXP_CHECK_MD_OP(exp, renew_capa);
2211 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2212 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2216 static inline int md_unpack_capa(struct obd_export *exp,
2217 struct ptlrpc_request *req,
2218 const struct req_msg_field *field,
2219 struct obd_capa **oc)
2223 EXP_CHECK_MD_OP(exp, unpack_capa);
2224 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2225 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2229 static inline int md_intent_getattr_async(struct obd_export *exp,
2230 struct md_enqueue_info *minfo,
2231 struct ldlm_enqueue_info *einfo)
2235 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2236 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2237 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2241 static inline int md_revalidate_lock(struct obd_export *exp,
2242 struct lookup_intent *it,
2243 struct lu_fid *fid, __u64 *bits)
2247 EXP_CHECK_MD_OP(exp, revalidate_lock);
2248 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2249 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid, bits);
2254 /* OBD Metadata Support */
2256 extern int obd_init_caches(void);
2257 extern void obd_cleanup_caches(void);
2259 /* support routines */
2260 extern cfs_mem_cache_t *obdo_cachep;
2262 #define OBDO_ALLOC(ptr) \
2264 OBD_SLAB_ALLOC_PTR_GFP((ptr), obdo_cachep, CFS_ALLOC_IO); \
2267 #define OBDO_FREE(ptr) \
2269 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2273 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2275 /* something here */
2278 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2280 /* something here */
2283 /* I'm as embarrassed about this as you are.
2285 * <shaver> // XXX do not look into _superhack with remaining eye
2286 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2287 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2290 extern void obd_sysctl_init (void);
2291 extern void obd_sysctl_clean (void);
2294 typedef __u8 class_uuid_t[16];
2295 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2298 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2299 int class_add_uuid(const char *uuid, __u64 nid);
2300 int class_del_uuid (const char *uuid);
2301 int class_check_uuid(struct obd_uuid *uuid, __u64 nid);
2302 void class_init_uuidlist(void);
2303 void class_exit_uuidlist(void);
2306 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2307 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2310 #define ll_generate_random_uuid(uuid_out) cfs_get_random_bytes(uuid_out, sizeof(class_uuid_t))
2312 #endif /* __LINUX_OBD_CLASS_H */