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 2008 Sun Microsystems, Inc. All rights reserved
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
40 # include <liblustre.h>
43 #include <obd_support.h>
44 #include <lustre_import.h>
45 #include <lustre_net.h>
47 #include <lustre_lib.h>
48 #include <lustre/lustre_idl.h>
49 #include <lprocfs_status.h>
51 #if defined(__linux__)
52 #include <linux/obd_class.h>
53 #elif defined(__APPLE__)
54 #include <darwin/obd_class.h>
55 #elif defined(__WINNT__)
56 #include <winnt/obd_class.h>
58 #error Unsupported operating system.
61 /* OBD Device Declarations */
62 extern struct obd_device *obd_devs[MAX_OBD_DEVICES];
63 extern cfs_spinlock_t obd_dev_lock;
65 /* OBD Operations Declarations */
66 extern struct obd_device *class_conn2obd(struct lustre_handle *);
67 extern struct obd_device *class_exp2obd(struct obd_export *);
68 extern int class_handle_ioctl(unsigned int cmd, unsigned long arg);
70 struct lu_device_type;
73 struct obd_export *class_conn2export(struct lustre_handle *);
74 int class_register_type(struct obd_ops *, struct md_ops *,
75 struct lprocfs_vars *, const char *nm,
76 struct lu_device_type *ldt);
77 int class_unregister_type(const char *nm);
79 struct obd_device *class_newdev(const char *type_name, const char *name);
80 void class_release_dev(struct obd_device *obd);
82 int class_name2dev(const char *name);
83 struct obd_device *class_name2obd(const char *name);
84 int class_uuid2dev(struct obd_uuid *uuid);
85 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
86 void class_obd_list(void);
87 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
88 const char * typ_name,
89 struct obd_uuid *grp_uuid);
90 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
92 struct obd_device * class_num2obd(int num);
94 int class_notify_sptlrpc_conf(const char *fsname, int namelen);
96 char *obd_export_nid2str(struct obd_export *exp);
98 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
99 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
101 int obd_zombie_impexp_init(void);
102 void obd_zombie_impexp_stop(void);
103 void obd_zombie_impexp_cull(void);
104 void obd_zombie_barrier(void);
105 void obd_exports_barrier(struct obd_device *obd);
108 int class_process_config(struct lustre_cfg *lcfg);
109 int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
110 struct lustre_cfg *lcfg, void *data);
111 int class_attach(struct lustre_cfg *lcfg);
112 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
113 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
114 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
115 struct obd_device *class_incref(struct obd_device *obd,
116 const char *scope, const void *source);
117 void class_decref(struct obd_device *obd,
118 const char *scope, const void *source);
119 void dump_exports(struct obd_device *obd, int locks);
123 extern void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars);
125 static inline void lprocfs_echo_init_vars(struct lprocfs_static_vars *lvars)
127 memset(lvars, 0, sizeof(*lvars));
131 #define CFG_F_START 0x01 /* Set when we start updating from a log */
132 #define CFG_F_MARKER 0x02 /* We are within a maker */
133 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
134 #define CFG_F_COMPAT146 0x08 /* Allow old-style logs */
135 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
137 /* Passed as data param to class_config_parse_llog */
138 struct config_llog_instance {
141 struct super_block *cfg_sb;
142 struct obd_uuid cfg_uuid;
143 int cfg_last_idx; /* for partial llog processing */
146 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
147 struct config_llog_instance *cfg);
148 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
149 struct config_llog_instance *cfg);
151 /* list of active configuration logs */
152 struct config_llog_data {
154 struct ldlm_res_id cld_resid;
155 struct config_llog_instance cld_cfg;
156 cfs_list_t cld_list_chain;
157 cfs_atomic_t cld_refcount;
158 struct config_llog_data *cld_sptlrpc;/* depended sptlrpc log */
159 struct obd_export *cld_mgcexp;
160 unsigned int cld_stopping:1, /* we were told to stop
162 cld_lostlock:1, /* lock not requeued */
166 struct lustre_profile {
173 struct lustre_profile *class_get_profile(const char * prof);
174 void class_del_profile(const char *prof);
175 void class_del_profiles(void);
177 #if LUSTRE_TRACKS_LOCK_EXP_REFS
179 void __class_export_add_lock_ref(struct obd_export *, struct ldlm_lock *);
180 void __class_export_del_lock_ref(struct obd_export *, struct ldlm_lock *);
181 extern void (*class_export_dump_hook)(struct obd_export *);
185 #define __class_export_add_lock_ref(exp, lock) do {} while(0)
186 #define __class_export_del_lock_ref(exp, lock) do {} while(0)
190 #define class_export_rpc_get(exp) \
192 cfs_atomic_inc(&(exp)->exp_rpc_count); \
193 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
194 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
195 class_export_get(exp); \
198 #define class_export_rpc_put(exp) \
200 LASSERT(cfs_atomic_read(&exp->exp_rpc_count) > 0); \
201 cfs_atomic_dec(&(exp)->exp_rpc_count); \
202 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
203 (exp), cfs_atomic_read(&(exp)->exp_rpc_count)); \
204 class_export_put(exp); \
207 #define class_export_lock_get(exp, lock) \
209 cfs_atomic_inc(&(exp)->exp_locks_count); \
210 __class_export_add_lock_ref(exp, lock); \
211 CDEBUG(D_INFO, "lock GETting export %p : new locks_count %d\n", \
212 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
213 class_export_get(exp); \
216 #define class_export_lock_put(exp, lock) \
218 LASSERT(cfs_atomic_read(&exp->exp_locks_count) > 0); \
219 cfs_atomic_dec(&(exp)->exp_locks_count); \
220 __class_export_del_lock_ref(exp, lock); \
221 CDEBUG(D_INFO, "lock PUTting export %p : new locks_count %d\n", \
222 (exp), cfs_atomic_read(&(exp)->exp_locks_count)); \
223 class_export_put(exp); \
226 #define class_export_cb_get(exp) \
228 cfs_atomic_inc(&(exp)->exp_cb_count); \
229 CDEBUG(D_INFO, "callback GETting export %p : new cb_count %d\n",\
230 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
231 class_export_get(exp); \
234 #define class_export_cb_put(exp) \
236 LASSERT(cfs_atomic_read(&exp->exp_cb_count) > 0); \
237 cfs_atomic_dec(&(exp)->exp_cb_count); \
238 CDEBUG(D_INFO, "callback PUTting export %p : new cb_count %d\n",\
239 (exp), cfs_atomic_read(&(exp)->exp_cb_count)); \
240 class_export_put(exp); \
244 struct obd_export *class_export_get(struct obd_export *exp);
245 void class_export_put(struct obd_export *exp);
246 struct obd_export *class_new_export(struct obd_device *obddev,
247 struct obd_uuid *cluuid);
248 void class_unlink_export(struct obd_export *exp);
250 struct obd_import *class_import_get(struct obd_import *);
251 void class_import_put(struct obd_import *);
252 struct obd_import *class_new_import(struct obd_device *obd);
253 void class_destroy_import(struct obd_import *exp);
255 struct obd_type *class_search_type(const char *name);
256 struct obd_type *class_get_type(const char *name);
257 void class_put_type(struct obd_type *type);
258 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
259 struct obd_uuid *cluuid);
260 int class_disconnect(struct obd_export *exp);
261 void class_fail_export(struct obd_export *exp);
262 int class_connected_export(struct obd_export *exp);
263 void class_disconnect_exports(struct obd_device *obddev);
264 int class_manual_cleanup(struct obd_device *obd);
265 void class_disconnect_stale_exports(struct obd_device *,
266 int (*test_export)(struct obd_export *));
267 static inline enum obd_option exp_flags_from_obd(struct obd_device *obd)
269 return ((obd->obd_fail ? OBD_OPT_FAILOVER : 0) |
270 (obd->obd_force ? OBD_OPT_FORCE : 0) |
271 (obd->obd_abort_recovery ? OBD_OPT_ABORT_RECOV : 0) |
275 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
276 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
277 void obdo_from_iattr(struct obdo *oa, struct iattr *attr,
278 unsigned int ia_valid);
279 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
280 void md_from_obdo(struct md_op_data *op_data, struct obdo *oa, obd_flag valid);
281 void obdo_from_md(struct obdo *oa, struct md_op_data *op_data,
284 #define OBT(dev) (dev)->obd_type
285 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
286 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
287 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
289 /* Ensure obd_setup: used for cleanup which must be called
290 while obd is stopping */
291 #define OBD_CHECK_DEV(obd) \
294 CERROR("NULL device\n"); \
299 /* ensure obd_setup and !obd_stopping */
300 #define OBD_CHECK_DEV_ACTIVE(obd) \
302 OBD_CHECK_DEV(obd); \
303 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
304 CERROR("Device %d not setup\n", \
312 #define OBD_COUNTER_OFFSET(op) \
313 ((offsetof(struct obd_ops, o_ ## op) - \
314 offsetof(struct obd_ops, o_iocontrol)) \
315 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
317 #define OBD_COUNTER_INCREMENT(obdx, op) \
318 if ((obdx)->obd_stats != NULL) { \
319 unsigned int coffset; \
320 coffset = (unsigned int)((obdx)->obd_cntr_base) + \
321 OBD_COUNTER_OFFSET(op); \
322 LASSERT(coffset < (obdx)->obd_stats->ls_num); \
323 lprocfs_counter_incr((obdx)->obd_stats, coffset); \
326 #define EXP_COUNTER_INCREMENT(export, op) \
327 if ((export)->exp_obd->obd_stats != NULL) { \
328 unsigned int coffset; \
329 coffset = (unsigned int)((export)->exp_obd->obd_cntr_base) + \
330 OBD_COUNTER_OFFSET(op); \
331 LASSERT(coffset < (export)->exp_obd->obd_stats->ls_num); \
332 lprocfs_counter_incr((export)->exp_obd->obd_stats, coffset); \
333 if ((export)->exp_nid_stats != NULL && \
334 (export)->exp_nid_stats->nid_stats != NULL) \
335 lprocfs_counter_incr( \
336 (export)->exp_nid_stats->nid_stats, coffset);\
339 #define MD_COUNTER_OFFSET(op) \
340 ((offsetof(struct md_ops, m_ ## op) - \
341 offsetof(struct md_ops, m_getstatus)) \
342 / sizeof(((struct md_ops *)(0))->m_getstatus))
344 #define MD_COUNTER_INCREMENT(obdx, op) \
345 if ((obd)->md_stats != NULL) { \
346 unsigned int coffset; \
347 coffset = (unsigned int)((obdx)->md_cntr_base) + \
348 MD_COUNTER_OFFSET(op); \
349 LASSERT(coffset < (obdx)->md_stats->ls_num); \
350 lprocfs_counter_incr((obdx)->md_stats, coffset); \
353 #define EXP_MD_COUNTER_INCREMENT(export, op) \
354 if ((export)->exp_obd->obd_stats != NULL) { \
355 unsigned int coffset; \
356 coffset = (unsigned int)((export)->exp_obd->md_cntr_base) + \
357 MD_COUNTER_OFFSET(op); \
358 LASSERT(coffset < (export)->exp_obd->md_stats->ls_num); \
359 lprocfs_counter_incr((export)->exp_obd->md_stats, coffset); \
360 if ((export)->exp_md_stats != NULL) \
361 lprocfs_counter_incr( \
362 (export)->exp_md_stats, coffset); \
366 #define OBD_COUNTER_OFFSET(op)
367 #define OBD_COUNTER_INCREMENT(obd, op)
368 #define EXP_COUNTER_INCREMENT(exp, op)
369 #define MD_COUNTER_INCREMENT(obd, op)
370 #define EXP_MD_COUNTER_INCREMENT(exp, op)
373 #define OBD_CHECK_MD_OP(obd, op, err) \
375 if (!OBT(obd) || !MDP((obd), op)) { \
377 CERROR("md_" #op ": dev %s/%d no operation\n", \
378 obd->obd_name, obd->obd_minor); \
383 #define EXP_CHECK_MD_OP(exp, op) \
385 if ((exp) == NULL) { \
386 CERROR("obd_" #op ": NULL export\n"); \
389 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
390 CERROR("obd_" #op ": cleaned up obd\n"); \
391 RETURN(-EOPNOTSUPP); \
393 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
394 CERROR("obd_" #op ": dev %s/%d no operation\n", \
395 (exp)->exp_obd->obd_name, \
396 (exp)->exp_obd->obd_minor); \
397 RETURN(-EOPNOTSUPP); \
402 #define OBD_CHECK_DT_OP(obd, op, err) \
404 if (!OBT(obd) || !OBP((obd), op)) { \
406 CERROR("obd_" #op ": dev %d no operation\n", \
412 #define EXP_CHECK_DT_OP(exp, op) \
414 if ((exp) == NULL) { \
415 CERROR("obd_" #op ": NULL export\n"); \
418 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
419 CERROR("obd_" #op ": cleaned up obd\n"); \
420 RETURN(-EOPNOTSUPP); \
422 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
423 CERROR("obd_" #op ": dev %d no operation\n", \
424 (exp)->exp_obd->obd_minor); \
425 RETURN(-EOPNOTSUPP); \
429 #define CTXT_CHECK_OP(ctxt, op, err) \
431 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
433 CERROR("lop_" #op ": dev %d no operation\n", \
434 ctxt->loc_obd->obd_minor); \
439 static inline int class_devno_max(void)
441 return MAX_OBD_DEVICES;
444 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
445 void *key, __u32 *vallen, void *val,
446 struct lov_stripe_md *lsm)
451 EXP_CHECK_DT_OP(exp, get_info);
452 EXP_COUNTER_INCREMENT(exp, get_info);
454 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val, lsm);
458 static inline int obd_set_info_async(struct obd_export *exp, obd_count keylen,
459 void *key, obd_count vallen, void *val,
460 struct ptlrpc_request_set *set)
465 EXP_CHECK_DT_OP(exp, set_info_async);
466 EXP_COUNTER_INCREMENT(exp, set_info_async);
468 rc = OBP(exp->exp_obd, set_info_async)(exp, keylen, key, vallen, val,
474 * obd-lu integration.
476 * Functionality is being moved into new lu_device-based layering, but some
477 * pieces of configuration process are still based on obd devices.
479 * Specifically, lu_device_type_operations::ldto_device_alloc() methods fully
480 * subsume ->o_setup() methods of obd devices they replace. The same for
481 * lu_device_operations::ldo_process_config() and ->o_process_config(). As a
482 * result, obd_setup() and obd_process_config() branch and call one XOR
485 * Yet neither lu_device_type_operations::ldto_device_fini() nor
486 * lu_device_type_operations::ldto_device_free() fully implement the
487 * functionality of ->o_precleanup() and ->o_cleanup() they override. Hence,
488 * obd_precleanup() and obd_cleanup() call both lu_device and obd operations.
491 #define DECLARE_LU_VARS(ldt, d) \
492 struct lu_device_type *ldt; \
495 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
498 DECLARE_LU_VARS(ldt, d);
501 ldt = obd->obd_type->typ_lu;
503 struct lu_context session_ctx;
505 lu_context_init(&session_ctx, LCT_SESSION);
506 session_ctx.lc_thread = NULL;
507 lu_context_enter(&session_ctx);
509 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
511 env.le_ses = &session_ctx;
512 d = ldt->ldt_ops->ldto_device_alloc(&env, ldt, cfg);
521 lu_context_exit(&session_ctx);
522 lu_context_fini(&session_ctx);
525 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
526 OBD_COUNTER_INCREMENT(obd, setup);
527 rc = OBP(obd, setup)(obd, cfg);
532 static inline int obd_precleanup(struct obd_device *obd,
533 enum obd_cleanup_stage cleanup_stage)
536 DECLARE_LU_VARS(ldt, d);
540 ldt = obd->obd_type->typ_lu;
542 if (ldt != NULL && d != NULL) {
543 if (cleanup_stage == OBD_CLEANUP_EXPORTS) {
546 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
548 ldt->ldt_ops->ldto_device_fini(&env, d);
553 OBD_CHECK_DT_OP(obd, precleanup, 0);
554 OBD_COUNTER_INCREMENT(obd, precleanup);
556 rc = OBP(obd, precleanup)(obd, cleanup_stage);
560 static inline int obd_cleanup(struct obd_device *obd)
563 DECLARE_LU_VARS(ldt, d);
568 ldt = obd->obd_type->typ_lu;
570 if (ldt != NULL && d != NULL) {
573 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
575 ldt->ldt_ops->ldto_device_free(&env, d);
577 obd->obd_lu_dev = NULL;
580 OBD_CHECK_DT_OP(obd, cleanup, 0);
581 OBD_COUNTER_INCREMENT(obd, cleanup);
583 rc = OBP(obd, cleanup)(obd);
588 obd_process_config(struct obd_device *obd, int datalen, void *data)
591 DECLARE_LU_VARS(ldt, d);
596 obd->obd_process_conf = 1;
597 ldt = obd->obd_type->typ_lu;
599 if (ldt != NULL && d != NULL) {
602 rc = lu_env_init(&env, ldt->ldt_ctx_tags);
604 rc = d->ld_ops->ldo_process_config(&env, d, data);
608 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
609 rc = OBP(obd, process_config)(obd, datalen, data);
611 OBD_COUNTER_INCREMENT(obd, process_config);
612 obd->obd_process_conf = 0;
617 /* Pack an in-memory MD struct for storage on disk.
618 * Returns +ve size of packed MD (0 for free), or -ve error.
620 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
621 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
622 * If @*disk_tgt == NULL, it will be allocated
624 static inline int obd_packmd(struct obd_export *exp,
625 struct lov_mds_md **disk_tgt,
626 struct lov_stripe_md *mem_src)
631 EXP_CHECK_DT_OP(exp, packmd);
632 EXP_COUNTER_INCREMENT(exp, packmd);
634 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
638 static inline int obd_size_diskmd(struct obd_export *exp,
639 struct lov_stripe_md *mem_src)
641 return obd_packmd(exp, NULL, mem_src);
644 /* helper functions */
645 static inline int obd_alloc_diskmd(struct obd_export *exp,
646 struct lov_mds_md **disk_tgt)
649 LASSERT(*disk_tgt == NULL);
650 return obd_packmd(exp, disk_tgt, NULL);
653 static inline int obd_free_diskmd(struct obd_export *exp,
654 struct lov_mds_md **disk_tgt)
658 return obd_packmd(exp, disk_tgt, NULL);
661 /* Unpack an MD struct from disk to in-memory format.
662 * Returns +ve size of unpacked MD (0 for free), or -ve error.
664 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
665 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
666 * If @*mem_tgt == NULL, it will be allocated
668 static inline int obd_unpackmd(struct obd_export *exp,
669 struct lov_stripe_md **mem_tgt,
670 struct lov_mds_md *disk_src,
676 EXP_CHECK_DT_OP(exp, unpackmd);
677 EXP_COUNTER_INCREMENT(exp, unpackmd);
679 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
683 /* helper functions */
684 static inline int obd_alloc_memmd(struct obd_export *exp,
685 struct lov_stripe_md **mem_tgt)
688 LASSERT(*mem_tgt == NULL);
689 return obd_unpackmd(exp, mem_tgt, NULL, 0);
692 static inline int obd_free_memmd(struct obd_export *exp,
693 struct lov_stripe_md **mem_tgt)
699 rc = obd_unpackmd(exp, mem_tgt, NULL, 0);
704 static inline int obd_precreate(struct obd_export *exp)
709 EXP_CHECK_DT_OP(exp, precreate);
710 OBD_COUNTER_INCREMENT(exp->exp_obd, precreate);
712 rc = OBP(exp->exp_obd, precreate)(exp);
716 static inline int obd_create_async(struct obd_export *exp,
717 struct obd_info *oinfo,
718 struct lov_stripe_md **ea,
719 struct obd_trans_info *oti)
724 EXP_CHECK_DT_OP(exp, create_async);
725 EXP_COUNTER_INCREMENT(exp, create_async);
727 rc = OBP(exp->exp_obd, create_async)(exp, oinfo, ea, oti);
731 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
732 struct lov_stripe_md **ea,
733 struct obd_trans_info *oti)
738 EXP_CHECK_DT_OP(exp, create);
739 EXP_COUNTER_INCREMENT(exp, create);
741 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
745 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
746 struct lov_stripe_md *ea,
747 struct obd_trans_info *oti,
748 struct obd_export *md_exp, void *capa)
753 EXP_CHECK_DT_OP(exp, destroy);
754 EXP_COUNTER_INCREMENT(exp, destroy);
756 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp, capa);
760 static inline int obd_getattr(struct obd_export *exp, struct obd_info *oinfo)
765 EXP_CHECK_DT_OP(exp, getattr);
766 EXP_COUNTER_INCREMENT(exp, getattr);
768 rc = OBP(exp->exp_obd, getattr)(exp, oinfo);
772 static inline int obd_getattr_async(struct obd_export *exp,
773 struct obd_info *oinfo,
774 struct ptlrpc_request_set *set)
779 EXP_CHECK_DT_OP(exp, getattr_async);
780 EXP_COUNTER_INCREMENT(exp, getattr_async);
782 rc = OBP(exp->exp_obd, getattr_async)(exp, oinfo, set);
786 static inline int obd_setattr(struct obd_export *exp, struct obd_info *oinfo,
787 struct obd_trans_info *oti)
792 EXP_CHECK_DT_OP(exp, setattr);
793 EXP_COUNTER_INCREMENT(exp, setattr);
795 rc = OBP(exp->exp_obd, setattr)(exp, oinfo, oti);
799 /* This performs all the requests set init/wait/destroy actions. */
800 static inline int obd_setattr_rqset(struct obd_export *exp,
801 struct obd_info *oinfo,
802 struct obd_trans_info *oti)
804 struct ptlrpc_request_set *set = NULL;
808 EXP_CHECK_DT_OP(exp, setattr_async);
809 EXP_COUNTER_INCREMENT(exp, setattr_async);
811 set = ptlrpc_prep_set();
815 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
817 rc = ptlrpc_set_wait(set);
818 ptlrpc_set_destroy(set);
822 /* This adds all the requests into @set if @set != NULL, otherwise
823 all requests are sent asynchronously without waiting for response. */
824 static inline int obd_setattr_async(struct obd_export *exp,
825 struct obd_info *oinfo,
826 struct obd_trans_info *oti,
827 struct ptlrpc_request_set *set)
832 EXP_CHECK_DT_OP(exp, setattr_async);
833 EXP_COUNTER_INCREMENT(exp, setattr_async);
835 rc = OBP(exp->exp_obd, setattr_async)(exp, oinfo, oti, set);
839 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
842 struct obd_device *obd = imp->imp_obd;
846 OBD_CHECK_DEV_ACTIVE(obd);
847 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
848 OBD_COUNTER_INCREMENT(obd, add_conn);
850 rc = OBP(obd, add_conn)(imp, uuid, priority);
854 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
856 struct obd_device *obd = imp->imp_obd;
860 OBD_CHECK_DEV_ACTIVE(obd);
861 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
862 OBD_COUNTER_INCREMENT(obd, del_conn);
864 rc = OBP(obd, del_conn)(imp, uuid);
868 static inline struct obd_uuid *obd_get_uuid(struct obd_export *exp)
870 struct obd_uuid *uuid;
873 OBD_CHECK_DT_OP(exp->exp_obd, get_uuid, NULL);
874 EXP_COUNTER_INCREMENT(exp, get_uuid);
876 uuid = OBP(exp->exp_obd, get_uuid)(exp);
880 static inline int obd_connect(const struct lu_env *env,
881 struct obd_export **exp,struct obd_device *obd,
882 struct obd_uuid *cluuid,
883 struct obd_connect_data *d,
887 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
891 OBD_CHECK_DEV_ACTIVE(obd);
892 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
893 OBD_COUNTER_INCREMENT(obd, connect);
895 rc = OBP(obd, connect)(env, exp, obd, cluuid, d, localdata);
896 /* check that only subset is granted */
897 LASSERT(ergo(d != NULL,
898 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
902 static inline int obd_reconnect(const struct lu_env *env,
903 struct obd_export *exp,
904 struct obd_device *obd,
905 struct obd_uuid *cluuid,
906 struct obd_connect_data *d,
910 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition
915 OBD_CHECK_DEV_ACTIVE(obd);
916 OBD_CHECK_DT_OP(obd, reconnect, 0);
917 OBD_COUNTER_INCREMENT(obd, reconnect);
919 rc = OBP(obd, reconnect)(env, exp, obd, cluuid, d, localdata);
920 /* check that only subset is granted */
921 LASSERT(ergo(d != NULL,
922 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
926 static inline int obd_disconnect(struct obd_export *exp)
931 EXP_CHECK_DT_OP(exp, disconnect);
932 EXP_COUNTER_INCREMENT(exp, disconnect);
934 rc = OBP(exp->exp_obd, disconnect)(exp);
938 static inline int obd_fid_init(struct obd_export *exp)
943 OBD_CHECK_DT_OP(exp->exp_obd, fid_init, 0);
944 EXP_COUNTER_INCREMENT(exp, fid_init);
946 rc = OBP(exp->exp_obd, fid_init)(exp);
950 static inline int obd_fid_fini(struct obd_export *exp)
955 OBD_CHECK_DT_OP(exp->exp_obd, fid_fini, 0);
956 EXP_COUNTER_INCREMENT(exp, fid_fini);
958 rc = OBP(exp->exp_obd, fid_fini)(exp);
962 static inline int obd_fid_alloc(struct obd_export *exp,
964 struct md_op_data *op_data)
969 EXP_CHECK_DT_OP(exp, fid_alloc);
970 EXP_COUNTER_INCREMENT(exp, fid_alloc);
972 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, op_data);
976 static inline int obd_fid_delete(struct obd_export *exp,
977 const struct lu_fid *fid)
982 EXP_CHECK_DT_OP(exp, fid_delete);
983 EXP_COUNTER_INCREMENT(exp, fid_delete);
985 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
989 static inline int obd_ping(struct obd_export *exp)
994 OBD_CHECK_DT_OP(exp->exp_obd, ping, 0);
995 EXP_COUNTER_INCREMENT(exp, ping);
997 rc = OBP(exp->exp_obd, ping)(exp);
1001 static inline int obd_pool_new(struct obd_device *obd, char *poolname)
1006 OBD_CHECK_DT_OP(obd, pool_new, -EOPNOTSUPP);
1007 OBD_COUNTER_INCREMENT(obd, pool_new);
1009 rc = OBP(obd, pool_new)(obd, poolname);
1013 static inline int obd_pool_del(struct obd_device *obd, char *poolname)
1018 OBD_CHECK_DT_OP(obd, pool_del, -EOPNOTSUPP);
1019 OBD_COUNTER_INCREMENT(obd, pool_del);
1021 rc = OBP(obd, pool_del)(obd, poolname);
1025 static inline int obd_pool_add(struct obd_device *obd, char *poolname, char *ostname)
1030 OBD_CHECK_DT_OP(obd, pool_add, -EOPNOTSUPP);
1031 OBD_COUNTER_INCREMENT(obd, pool_add);
1033 rc = OBP(obd, pool_add)(obd, poolname, ostname);
1037 static inline int obd_pool_rem(struct obd_device *obd, char *poolname, char *ostname)
1042 OBD_CHECK_DT_OP(obd, pool_rem, -EOPNOTSUPP);
1043 OBD_COUNTER_INCREMENT(obd, pool_rem);
1045 rc = OBP(obd, pool_rem)(obd, poolname, ostname);
1049 static inline void obd_getref(struct obd_device *obd)
1052 if (OBT(obd) && OBP(obd, getref)) {
1053 OBD_COUNTER_INCREMENT(obd, getref);
1054 OBP(obd, getref)(obd);
1059 static inline void obd_putref(struct obd_device *obd)
1062 if (OBT(obd) && OBP(obd, putref)) {
1063 OBD_COUNTER_INCREMENT(obd, putref);
1064 OBP(obd, putref)(obd);
1069 static inline int obd_init_export(struct obd_export *exp)
1074 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1075 OBP((exp)->exp_obd, init_export))
1076 rc = OBP(exp->exp_obd, init_export)(exp);
1080 static inline int obd_destroy_export(struct obd_export *exp)
1083 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
1084 OBP((exp)->exp_obd, destroy_export))
1085 OBP(exp->exp_obd, destroy_export)(exp);
1089 static inline int obd_extent_calc(struct obd_export *exp,
1090 struct lov_stripe_md *md,
1091 int cmd, obd_off *offset)
1095 EXP_CHECK_DT_OP(exp, extent_calc);
1096 rc = OBP(exp->exp_obd, extent_calc)(exp, md, cmd, offset);
1100 static inline struct dentry *
1101 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
1103 LASSERT(exp->exp_obd);
1105 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
1110 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
1112 LASSERT(exp->exp_obd);
1113 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
1115 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
1116 dentry, exp->exp_obd);
1121 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1122 * If the cache is older than @max_age we will get a new value from the
1123 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1124 static inline int obd_statfs_async(struct obd_device *obd,
1125 struct obd_info *oinfo,
1127 struct ptlrpc_request_set *rqset)
1135 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1136 OBD_COUNTER_INCREMENT(obd, statfs);
1138 CDEBUG(D_SUPER, "%s: osfs %p age "LPU64", max_age "LPU64"\n",
1139 obd->obd_name, &obd->obd_osfs, obd->obd_osfs_age, max_age);
1140 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1141 rc = OBP(obd, statfs_async)(obd, oinfo, max_age, rqset);
1143 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1144 " objects "LPU64"/"LPU64"\n",
1145 obd->obd_name, &obd->obd_osfs,
1146 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1147 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1148 cfs_spin_lock(&obd->obd_osfs_lock);
1149 memcpy(oinfo->oi_osfs, &obd->obd_osfs, sizeof(*oinfo->oi_osfs));
1150 cfs_spin_unlock(&obd->obd_osfs_lock);
1151 oinfo->oi_flags |= OBD_STATFS_FROM_CACHE;
1152 if (oinfo->oi_cb_up)
1153 oinfo->oi_cb_up(oinfo, 0);
1158 static inline int obd_statfs_rqset(struct obd_device *obd,
1159 struct obd_statfs *osfs, __u64 max_age,
1162 struct ptlrpc_request_set *set = NULL;
1163 struct obd_info oinfo = { { { 0 } } };
1167 set = ptlrpc_prep_set();
1171 oinfo.oi_osfs = osfs;
1172 oinfo.oi_flags = flags;
1173 rc = obd_statfs_async(obd, &oinfo, max_age, set);
1175 rc = ptlrpc_set_wait(set);
1176 ptlrpc_set_destroy(set);
1180 /* @max_age is the oldest time in jiffies that we accept using a cached data.
1181 * If the cache is older than @max_age we will get a new value from the
1182 * target. Use a value of "cfs_time_current() + HZ" to guarantee freshness. */
1183 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
1184 __u64 max_age, __u32 flags)
1192 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
1193 OBD_COUNTER_INCREMENT(obd, statfs);
1195 CDEBUG(D_SUPER, "osfs "LPU64", max_age "LPU64"\n",
1196 obd->obd_osfs_age, max_age);
1197 if (cfs_time_before_64(obd->obd_osfs_age, max_age)) {
1198 rc = OBP(obd, statfs)(obd, osfs, max_age, flags);
1200 cfs_spin_lock(&obd->obd_osfs_lock);
1201 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
1202 obd->obd_osfs_age = cfs_time_current_64();
1203 cfs_spin_unlock(&obd->obd_osfs_lock);
1206 CDEBUG(D_SUPER,"%s: use %p cache blocks "LPU64"/"LPU64
1207 " objects "LPU64"/"LPU64"\n",
1208 obd->obd_name, &obd->obd_osfs,
1209 obd->obd_osfs.os_bavail, obd->obd_osfs.os_blocks,
1210 obd->obd_osfs.os_ffree, obd->obd_osfs.os_files);
1211 cfs_spin_lock(&obd->obd_osfs_lock);
1212 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
1213 cfs_spin_unlock(&obd->obd_osfs_lock);
1218 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
1219 struct lov_stripe_md *ea, obd_size start,
1220 obd_size end, void *capa)
1225 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
1226 EXP_COUNTER_INCREMENT(exp, sync);
1228 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end, capa);
1232 static inline int obd_punch_rqset(struct obd_export *exp,
1233 struct obd_info *oinfo,
1234 struct obd_trans_info *oti)
1236 struct ptlrpc_request_set *set = NULL;
1240 EXP_CHECK_DT_OP(exp, punch);
1241 EXP_COUNTER_INCREMENT(exp, punch);
1243 set = ptlrpc_prep_set();
1247 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, set);
1249 rc = ptlrpc_set_wait(set);
1250 ptlrpc_set_destroy(set);
1254 static inline int obd_punch(struct obd_export *exp, struct obd_info *oinfo,
1255 struct obd_trans_info *oti,
1256 struct ptlrpc_request_set *rqset)
1261 EXP_CHECK_DT_OP(exp, punch);
1262 EXP_COUNTER_INCREMENT(exp, punch);
1264 rc = OBP(exp->exp_obd, punch)(exp, oinfo, oti, rqset);
1268 static inline int obd_brw(int cmd, struct obd_export *exp,
1269 struct obd_info *oinfo, obd_count oa_bufs,
1270 struct brw_page *pg, struct obd_trans_info *oti)
1275 EXP_CHECK_DT_OP(exp, brw);
1276 EXP_COUNTER_INCREMENT(exp, brw);
1278 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
1279 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
1280 "or OBD_BRW_CHECK\n");
1284 rc = OBP(exp->exp_obd, brw)(cmd, exp, oinfo, oa_bufs, pg, oti);
1288 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
1289 int objcount, struct obd_ioobj *obj,
1290 struct niobuf_remote *remote, int *pages,
1291 struct niobuf_local *local,
1292 struct obd_trans_info *oti,
1293 struct lustre_capa *capa)
1298 EXP_CHECK_DT_OP(exp, preprw);
1299 EXP_COUNTER_INCREMENT(exp, preprw);
1301 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, remote,
1302 pages, local, oti, capa);
1306 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
1307 int objcount, struct obd_ioobj *obj,
1308 struct niobuf_remote *rnb, int pages,
1309 struct niobuf_local *local,
1310 struct obd_trans_info *oti, int rc)
1314 EXP_CHECK_DT_OP(exp, commitrw);
1315 EXP_COUNTER_INCREMENT(exp, commitrw);
1317 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj,
1318 rnb, pages, local, oti, rc);
1322 static inline int obd_merge_lvb(struct obd_export *exp,
1323 struct lov_stripe_md *lsm,
1324 struct ost_lvb *lvb, int kms_only)
1329 EXP_CHECK_DT_OP(exp, merge_lvb);
1330 EXP_COUNTER_INCREMENT(exp, merge_lvb);
1332 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1336 static inline int obd_adjust_kms(struct obd_export *exp,
1337 struct lov_stripe_md *lsm, obd_off size,
1343 EXP_CHECK_DT_OP(exp, adjust_kms);
1344 EXP_COUNTER_INCREMENT(exp, adjust_kms);
1346 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1350 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1351 int len, void *karg, void *uarg)
1356 EXP_CHECK_DT_OP(exp, iocontrol);
1357 EXP_COUNTER_INCREMENT(exp, iocontrol);
1359 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1363 static inline int obd_enqueue_rqset(struct obd_export *exp,
1364 struct obd_info *oinfo,
1365 struct ldlm_enqueue_info *einfo)
1367 struct ptlrpc_request_set *set = NULL;
1371 EXP_CHECK_DT_OP(exp, enqueue);
1372 EXP_COUNTER_INCREMENT(exp, enqueue);
1374 set = ptlrpc_prep_set();
1378 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1380 rc = ptlrpc_set_wait(set);
1381 ptlrpc_set_destroy(set);
1385 static inline int obd_enqueue(struct obd_export *exp,
1386 struct obd_info *oinfo,
1387 struct ldlm_enqueue_info *einfo,
1388 struct ptlrpc_request_set *set)
1393 EXP_CHECK_DT_OP(exp, enqueue);
1394 EXP_COUNTER_INCREMENT(exp, enqueue);
1396 rc = OBP(exp->exp_obd, enqueue)(exp, oinfo, einfo, set);
1400 static inline int obd_change_cbdata(struct obd_export *exp,
1401 struct lov_stripe_md *lsm,
1402 ldlm_iterator_t it, void *data)
1407 EXP_CHECK_DT_OP(exp, change_cbdata);
1408 EXP_COUNTER_INCREMENT(exp, change_cbdata);
1410 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1414 static inline int obd_cancel(struct obd_export *exp,
1415 struct lov_stripe_md *ea, __u32 mode,
1416 struct lustre_handle *lockh)
1421 EXP_CHECK_DT_OP(exp, cancel);
1422 EXP_COUNTER_INCREMENT(exp, cancel);
1424 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1428 static inline int obd_cancel_unused(struct obd_export *exp,
1429 struct lov_stripe_md *ea,
1430 int flags, void *opaque)
1435 EXP_CHECK_DT_OP(exp, cancel_unused);
1436 EXP_COUNTER_INCREMENT(exp, cancel_unused);
1438 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1442 static inline int obd_pin(struct obd_export *exp, const struct lu_fid *fid,
1443 struct obd_capa *oc, struct obd_client_handle *handle,
1449 EXP_CHECK_DT_OP(exp, pin);
1450 EXP_COUNTER_INCREMENT(exp, pin);
1452 rc = OBP(exp->exp_obd, pin)(exp, fid, oc, handle, flag);
1456 static inline int obd_unpin(struct obd_export *exp,
1457 struct obd_client_handle *handle, int flag)
1462 EXP_CHECK_DT_OP(exp, unpin);
1463 EXP_COUNTER_INCREMENT(exp, unpin);
1465 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1470 static inline void obd_import_event(struct obd_device *obd,
1471 struct obd_import *imp,
1472 enum obd_import_event event)
1476 CERROR("NULL device\n");
1480 if (obd->obd_set_up && OBP(obd, import_event)) {
1481 OBD_COUNTER_INCREMENT(obd, import_event);
1482 OBP(obd, import_event)(obd, imp, event);
1487 static inline int obd_llog_connect(struct obd_export *exp,
1488 struct llogd_conn_body *body)
1493 OBD_CHECK_DT_OP(exp->exp_obd, llog_connect, 0);
1494 EXP_COUNTER_INCREMENT(exp, llog_connect);
1496 rc = OBP(exp->exp_obd, llog_connect)(exp, body);
1501 static inline int obd_notify(struct obd_device *obd,
1502 struct obd_device *watched,
1503 enum obd_notify_event ev,
1510 /* the check for async_recov is a complete hack - I'm hereby
1511 overloading the meaning to also mean "this was called from
1512 mds_postsetup". I know that my mds is able to handle notifies
1513 by this point, and it needs to get them to execute mds_postrecov. */
1514 if (!obd->obd_set_up && !obd->obd_async_recov) {
1515 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1519 if (!OBP(obd, notify)) {
1520 CERROR("obd %s has no notify handler\n", obd->obd_name);
1524 OBD_COUNTER_INCREMENT(obd, notify);
1525 rc = OBP(obd, notify)(obd, watched, ev, data);
1529 static inline int obd_notify_observer(struct obd_device *observer,
1530 struct obd_device *observed,
1531 enum obd_notify_event ev,
1537 struct obd_notify_upcall *onu;
1539 if (observer->obd_observer)
1540 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1544 * Also, call non-obd listener, if any
1546 onu = &observer->obd_upcall;
1547 if (onu->onu_upcall != NULL)
1548 rc2 = onu->onu_upcall(observer, observed, ev,
1549 onu->onu_owner, NULL);
1553 return rc1 ? rc1 : rc2;
1556 static inline int obd_quotacheck(struct obd_export *exp,
1557 struct obd_quotactl *oqctl)
1562 EXP_CHECK_DT_OP(exp, quotacheck);
1563 EXP_COUNTER_INCREMENT(exp, quotacheck);
1565 rc = OBP(exp->exp_obd, quotacheck)(exp->exp_obd, exp, oqctl);
1569 static inline int obd_quotactl(struct obd_export *exp,
1570 struct obd_quotactl *oqctl)
1575 EXP_CHECK_DT_OP(exp, quotactl);
1576 EXP_COUNTER_INCREMENT(exp, quotactl);
1578 rc = OBP(exp->exp_obd, quotactl)(exp->exp_obd, exp, oqctl);
1582 static inline int obd_quota_adjust_qunit(struct obd_export *exp,
1583 struct quota_adjust_qunit *oqaq,
1584 struct lustre_quota_ctxt *qctxt)
1586 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1587 struct timeval work_start;
1588 struct timeval work_end;
1594 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1596 cfs_gettimeofday(&work_start);
1598 EXP_CHECK_DT_OP(exp, quota_adjust_qunit);
1599 EXP_COUNTER_INCREMENT(exp, quota_adjust_qunit);
1601 rc = OBP(exp->exp_obd, quota_adjust_qunit)(exp, oqaq, qctxt);
1603 #if defined(LPROCFS) && defined(HAVE_QUOTA_SUPPORT)
1605 cfs_gettimeofday(&work_end);
1606 timediff = cfs_timeval_sub(&work_end, &work_start, NULL);
1607 lprocfs_counter_add(qctxt->lqc_stats, LQUOTA_ADJUST_QUNIT,
1614 static inline int obd_health_check(struct obd_device *obd)
1616 /* returns: 0 on healthy
1617 * >0 on unhealthy + reason code/flag
1618 * however the only suppored reason == 1 right now
1619 * We'll need to define some better reasons
1620 * or flags in the future.
1626 /* don't use EXP_CHECK_DT_OP, because NULL method is normal here */
1627 if (obd == NULL || !OBT(obd)) {
1628 CERROR("cleaned up obd\n");
1629 RETURN(-EOPNOTSUPP);
1631 if (!obd->obd_set_up || obd->obd_stopping)
1633 if (!OBP(obd, health_check))
1636 rc = OBP(obd, health_check)(obd);
1640 static inline int obd_register_observer(struct obd_device *obd,
1641 struct obd_device *observer)
1645 cfs_down_write(&obd->obd_observer_link_sem);
1646 if (obd->obd_observer && observer) {
1647 cfs_up_write(&obd->obd_observer_link_sem);
1650 obd->obd_observer = observer;
1651 cfs_up_write(&obd->obd_observer_link_sem);
1655 static inline int obd_pin_observer(struct obd_device *obd,
1656 struct obd_device **observer)
1659 cfs_down_read(&obd->obd_observer_link_sem);
1660 if (!obd->obd_observer) {
1662 cfs_up_read(&obd->obd_observer_link_sem);
1665 *observer = obd->obd_observer;
1669 static inline int obd_unpin_observer(struct obd_device *obd)
1672 cfs_up_read(&obd->obd_observer_link_sem);
1677 static inline int obd_register_page_removal_cb(struct obd_export *exp,
1678 obd_page_removal_cb_t cb,
1679 obd_pin_extent_cb pin_cb)
1684 OBD_CHECK_DT_OP(exp->exp_obd, register_page_removal_cb, 0);
1685 OBD_COUNTER_INCREMENT(exp->exp_obd, register_page_removal_cb);
1687 rc = OBP(exp->exp_obd, register_page_removal_cb)(exp, cb, pin_cb);
1691 static inline int obd_unregister_page_removal_cb(struct obd_export *exp,
1692 obd_page_removal_cb_t cb)
1697 OBD_CHECK_DT_OP(exp->exp_obd, unregister_page_removal_cb, 0);
1698 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_page_removal_cb);
1700 rc = OBP(exp->exp_obd, unregister_page_removal_cb)(exp, cb);
1704 static inline int obd_register_lock_cancel_cb(struct obd_export *exp,
1705 obd_lock_cancel_cb cb)
1710 OBD_CHECK_DT_OP(exp->exp_obd, register_lock_cancel_cb, 0);
1711 OBD_COUNTER_INCREMENT(exp->exp_obd, register_lock_cancel_cb);
1713 rc = OBP(exp->exp_obd, register_lock_cancel_cb)(exp, cb);
1717 static inline int obd_unregister_lock_cancel_cb(struct obd_export *exp,
1718 obd_lock_cancel_cb cb)
1723 OBD_CHECK_DT_OP(exp->exp_obd, unregister_lock_cancel_cb, 0);
1724 OBD_COUNTER_INCREMENT(exp->exp_obd, unregister_lock_cancel_cb);
1726 rc = OBP(exp->exp_obd, unregister_lock_cancel_cb)(exp, cb);
1731 /* metadata helpers */
1732 static inline int md_getstatus(struct obd_export *exp,
1733 struct lu_fid *fid, struct obd_capa **pc)
1738 EXP_CHECK_MD_OP(exp, getstatus);
1739 EXP_MD_COUNTER_INCREMENT(exp, getstatus);
1740 rc = MDP(exp->exp_obd, getstatus)(exp, fid, pc);
1744 static inline int md_getattr(struct obd_export *exp, const struct lu_fid *fid,
1745 struct obd_capa *oc, obd_valid valid, int ea_size,
1746 struct ptlrpc_request **request)
1750 EXP_CHECK_MD_OP(exp, getattr);
1751 EXP_MD_COUNTER_INCREMENT(exp, getattr);
1752 rc = MDP(exp->exp_obd, getattr)(exp, fid, oc, valid,
1757 static inline int md_change_cbdata(struct obd_export *exp,
1758 const struct lu_fid *fid,
1759 ldlm_iterator_t it, void *data)
1763 EXP_CHECK_MD_OP(exp, change_cbdata);
1764 EXP_MD_COUNTER_INCREMENT(exp, change_cbdata);
1765 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1769 static inline int md_close(struct obd_export *exp, struct md_op_data *op_data,
1770 struct md_open_data *mod,
1771 struct ptlrpc_request **request)
1775 EXP_CHECK_MD_OP(exp, close);
1776 EXP_MD_COUNTER_INCREMENT(exp, close);
1777 rc = MDP(exp->exp_obd, close)(exp, op_data, mod, request);
1781 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1782 const void *data, int datalen, int mode, __u32 uid,
1783 __u32 gid, cfs_cap_t cap_effective, __u64 rdev,
1784 struct ptlrpc_request **request)
1788 EXP_CHECK_MD_OP(exp, create);
1789 EXP_MD_COUNTER_INCREMENT(exp, create);
1790 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1791 uid, gid, cap_effective, rdev, request);
1795 static inline int md_done_writing(struct obd_export *exp,
1796 struct md_op_data *op_data,
1797 struct md_open_data *mod)
1801 EXP_CHECK_MD_OP(exp, done_writing);
1802 EXP_MD_COUNTER_INCREMENT(exp, done_writing);
1803 rc = MDP(exp->exp_obd, done_writing)(exp, op_data, mod);
1807 static inline int md_enqueue(struct obd_export *exp,
1808 struct ldlm_enqueue_info *einfo,
1809 struct lookup_intent *it,
1810 struct md_op_data *op_data,
1811 struct lustre_handle *lockh,
1812 void *lmm, int lmmsize,
1813 struct ptlrpc_request **req,
1814 int extra_lock_flags)
1818 EXP_CHECK_MD_OP(exp, enqueue);
1819 EXP_MD_COUNTER_INCREMENT(exp, enqueue);
1820 rc = MDP(exp->exp_obd, enqueue)(exp, einfo, it, op_data, lockh,
1821 lmm, lmmsize, req, extra_lock_flags);
1825 static inline int md_getattr_name(struct obd_export *exp,
1826 const struct lu_fid *fid, struct obd_capa *oc,
1827 const char *name, int namelen,
1828 obd_valid valid, int ea_size, __u32 suppgid,
1829 struct ptlrpc_request **request)
1833 EXP_CHECK_MD_OP(exp, getattr_name);
1834 EXP_MD_COUNTER_INCREMENT(exp, getattr_name);
1835 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, oc, name, namelen,
1836 valid, ea_size, suppgid, request);
1840 static inline int md_intent_lock(struct obd_export *exp,
1841 struct md_op_data *op_data, void *lmm,
1842 int lmmsize, struct lookup_intent *it,
1843 int flags, struct ptlrpc_request **reqp,
1844 ldlm_blocking_callback cb_blocking,
1845 int extra_lock_flags)
1849 EXP_CHECK_MD_OP(exp, intent_lock);
1850 EXP_MD_COUNTER_INCREMENT(exp, intent_lock);
1851 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1852 it, flags, reqp, cb_blocking,
1857 static inline int md_link(struct obd_export *exp, struct md_op_data *op_data,
1858 struct ptlrpc_request **request)
1862 EXP_CHECK_MD_OP(exp, link);
1863 EXP_MD_COUNTER_INCREMENT(exp, link);
1864 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1868 static inline int md_rename(struct obd_export *exp, struct md_op_data *op_data,
1869 const char *old, int oldlen, const char *new,
1870 int newlen, struct ptlrpc_request **request)
1874 EXP_CHECK_MD_OP(exp, rename);
1875 EXP_MD_COUNTER_INCREMENT(exp, rename);
1876 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1881 static inline int md_is_subdir(struct obd_export *exp,
1882 const struct lu_fid *pfid,
1883 const struct lu_fid *cfid,
1884 struct ptlrpc_request **request)
1888 EXP_CHECK_MD_OP(exp, is_subdir);
1889 EXP_MD_COUNTER_INCREMENT(exp, is_subdir);
1890 rc = MDP(exp->exp_obd, is_subdir)(exp, pfid, cfid, request);
1894 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1895 void *ea, int ealen, void *ea2, int ea2len,
1896 struct ptlrpc_request **request,
1897 struct md_open_data **mod)
1901 EXP_CHECK_MD_OP(exp, setattr);
1902 EXP_MD_COUNTER_INCREMENT(exp, setattr);
1903 rc = MDP(exp->exp_obd, setattr)(exp, op_data, ea, ealen,
1904 ea2, ea2len, request, mod);
1908 static inline int md_sync(struct obd_export *exp, const struct lu_fid *fid,
1909 struct obd_capa *oc, struct ptlrpc_request **request)
1913 EXP_CHECK_MD_OP(exp, sync);
1914 EXP_MD_COUNTER_INCREMENT(exp, sync);
1915 rc = MDP(exp->exp_obd, sync)(exp, fid, oc, request);
1919 static inline int md_readpage(struct obd_export *exp, const struct lu_fid *fid,
1920 struct obd_capa *oc, __u64 offset,
1922 struct ptlrpc_request **request)
1926 EXP_CHECK_MD_OP(exp, readpage);
1927 EXP_MD_COUNTER_INCREMENT(exp, readpage);
1928 rc = MDP(exp->exp_obd, readpage)(exp, fid, oc, offset, page, request);
1932 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1933 struct ptlrpc_request **request)
1937 EXP_CHECK_MD_OP(exp, unlink);
1938 EXP_MD_COUNTER_INCREMENT(exp, unlink);
1939 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1943 static inline int md_get_lustre_md(struct obd_export *exp,
1944 struct ptlrpc_request *req,
1945 struct obd_export *dt_exp,
1946 struct obd_export *md_exp,
1947 struct lustre_md *md)
1950 EXP_CHECK_MD_OP(exp, get_lustre_md);
1951 EXP_MD_COUNTER_INCREMENT(exp, get_lustre_md);
1952 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, dt_exp, md_exp, md));
1955 static inline int md_free_lustre_md(struct obd_export *exp,
1956 struct lustre_md *md)
1959 EXP_CHECK_MD_OP(exp, free_lustre_md);
1960 EXP_MD_COUNTER_INCREMENT(exp, free_lustre_md);
1961 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1964 static inline int md_setxattr(struct obd_export *exp,
1965 const struct lu_fid *fid, struct obd_capa *oc,
1966 obd_valid valid, const char *name,
1967 const char *input, int input_size,
1968 int output_size, int flags, __u32 suppgid,
1969 struct ptlrpc_request **request)
1972 EXP_CHECK_MD_OP(exp, setxattr);
1973 EXP_MD_COUNTER_INCREMENT(exp, setxattr);
1974 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, oc, valid, name, input,
1975 input_size, output_size, flags,
1979 static inline int md_getxattr(struct obd_export *exp,
1980 const struct lu_fid *fid, struct obd_capa *oc,
1981 obd_valid valid, const char *name,
1982 const char *input, int input_size,
1983 int output_size, int flags,
1984 struct ptlrpc_request **request)
1987 EXP_CHECK_MD_OP(exp, getxattr);
1988 EXP_MD_COUNTER_INCREMENT(exp, getxattr);
1989 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, oc, valid, name, input,
1990 input_size, output_size, flags,
1994 static inline int md_set_open_replay_data(struct obd_export *exp,
1995 struct obd_client_handle *och,
1996 struct ptlrpc_request *open_req)
1999 EXP_CHECK_MD_OP(exp, set_open_replay_data);
2000 EXP_MD_COUNTER_INCREMENT(exp, set_open_replay_data);
2001 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
2004 static inline int md_clear_open_replay_data(struct obd_export *exp,
2005 struct obd_client_handle *och)
2008 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
2009 EXP_MD_COUNTER_INCREMENT(exp, clear_open_replay_data);
2010 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
2013 static inline int md_set_lock_data(struct obd_export *exp,
2014 __u64 *lockh, void *data, __u32 *bits)
2017 EXP_CHECK_MD_OP(exp, set_lock_data);
2018 EXP_MD_COUNTER_INCREMENT(exp, set_lock_data);
2019 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data, bits));
2022 static inline int md_cancel_unused(struct obd_export *exp,
2023 const struct lu_fid *fid,
2024 ldlm_policy_data_t *policy,
2025 ldlm_mode_t mode, int flags, void *opaque)
2030 EXP_CHECK_MD_OP(exp, cancel_unused);
2031 EXP_MD_COUNTER_INCREMENT(exp, cancel_unused);
2033 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, policy, mode,
2038 static inline ldlm_mode_t md_lock_match(struct obd_export *exp, int flags,
2039 const struct lu_fid *fid,
2041 ldlm_policy_data_t *policy,
2043 struct lustre_handle *lockh)
2046 EXP_CHECK_MD_OP(exp, lock_match);
2047 EXP_MD_COUNTER_INCREMENT(exp, lock_match);
2048 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
2049 policy, mode, lockh));
2052 static inline int md_init_ea_size(struct obd_export *exp, int easize,
2053 int def_asize, int cookiesize)
2056 EXP_CHECK_MD_OP(exp, init_ea_size);
2057 EXP_MD_COUNTER_INCREMENT(exp, init_ea_size);
2058 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize, def_asize,
2062 static inline int md_get_remote_perm(struct obd_export *exp,
2063 const struct lu_fid *fid,
2064 struct obd_capa *oc, __u32 suppgid,
2065 struct ptlrpc_request **request)
2068 EXP_CHECK_MD_OP(exp, get_remote_perm);
2069 EXP_MD_COUNTER_INCREMENT(exp, get_remote_perm);
2070 RETURN(MDP(exp->exp_obd, get_remote_perm)(exp, fid, oc, suppgid,
2074 static inline int md_renew_capa(struct obd_export *exp, struct obd_capa *ocapa,
2079 EXP_CHECK_MD_OP(exp, renew_capa);
2080 EXP_MD_COUNTER_INCREMENT(exp, renew_capa);
2081 rc = MDP(exp->exp_obd, renew_capa)(exp, ocapa, cb);
2085 static inline int md_unpack_capa(struct obd_export *exp,
2086 struct ptlrpc_request *req,
2087 const struct req_msg_field *field,
2088 struct obd_capa **oc)
2092 EXP_CHECK_MD_OP(exp, unpack_capa);
2093 EXP_MD_COUNTER_INCREMENT(exp, unpack_capa);
2094 rc = MDP(exp->exp_obd, unpack_capa)(exp, req, field, oc);
2098 static inline int md_intent_getattr_async(struct obd_export *exp,
2099 struct md_enqueue_info *minfo,
2100 struct ldlm_enqueue_info *einfo)
2104 EXP_CHECK_MD_OP(exp, intent_getattr_async);
2105 EXP_MD_COUNTER_INCREMENT(exp, intent_getattr_async);
2106 rc = MDP(exp->exp_obd, intent_getattr_async)(exp, minfo, einfo);
2110 static inline int md_revalidate_lock(struct obd_export *exp,
2111 struct lookup_intent *it,
2116 EXP_CHECK_MD_OP(exp, revalidate_lock);
2117 EXP_MD_COUNTER_INCREMENT(exp, revalidate_lock);
2118 rc = MDP(exp->exp_obd, revalidate_lock)(exp, it, fid);
2123 /* OBD Metadata Support */
2125 extern int obd_init_caches(void);
2126 extern void obd_cleanup_caches(void);
2128 /* support routines */
2129 extern cfs_mem_cache_t *obdo_cachep;
2131 #define OBDO_ALLOC(ptr) \
2133 OBD_SLAB_ALLOC_PTR((ptr), obdo_cachep); \
2136 #define OBDO_FREE(ptr) \
2138 OBD_SLAB_FREE_PTR((ptr), obdo_cachep); \
2142 static inline void obdo2fid(struct obdo *oa, struct lu_fid *fid)
2144 /* something here */
2147 static inline void fid2obdo(struct lu_fid *fid, struct obdo *oa)
2149 /* something here */
2152 /* I'm as embarrassed about this as you are.
2154 * <shaver> // XXX do not look into _superhack with remaining eye
2155 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
2156 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
2159 extern void obd_sysctl_init (void);
2160 extern void obd_sysctl_clean (void);
2163 typedef __u8 class_uuid_t[16];
2164 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
2167 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
2168 int class_add_uuid(const char *uuid, __u64 nid);
2169 int class_del_uuid (const char *uuid);
2170 void class_init_uuidlist(void);
2171 void class_exit_uuidlist(void);
2174 int mea_name2idx(struct lmv_stripe_md *mea, const char *name, int namelen);
2175 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
2178 void ll_generate_random_uuid(class_uuid_t uuid_out);
2180 #endif /* __LINUX_OBD_CLASS_H */