1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #ifndef __LINUX_CLASS_OBD_H
24 #define __LINUX_CLASS_OBD_H
27 #include <sys/types.h>
28 #include <libcfs/list.h>
30 #include <asm/segment.h>
31 #include <asm/uaccess.h>
32 #include <linux/types.h>
34 #include <linux/dcache.h>
35 #include <linux/time.h>
36 #include <linux/timer.h>
39 #include <linux/obd_support.h>
40 #include <linux/lustre_import.h>
41 #include <linux/lustre_net.h>
42 #include <linux/obd.h>
43 #include <linux/lustre_lib.h>
44 #include <linux/lustre_idl.h>
45 #include <linux/lprocfs_status.h>
47 /* OBD Device Declarations */
48 #define MAX_OBD_DEVICES 520
49 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
50 extern spinlock_t obd_dev_lock;
52 /* OBD Operations Declarations */
53 extern struct obd_device *class_conn2obd(struct lustre_handle *);
54 extern struct obd_device *class_exp2obd(struct obd_export *);
56 struct lu_device_type;
59 struct obd_export *class_conn2export(struct lustre_handle *);
60 int class_register_type(struct obd_ops *, struct md_ops *,
61 struct lprocfs_vars *, const char *nm,
62 struct lu_device_type *ldt);
63 int class_unregister_type(const char *nm);
65 struct obd_device *class_newdev(struct obd_type *type, char *name);
66 void class_release_dev(struct obd_device *obd);
68 int class_name2dev(const char *name);
69 struct obd_device *class_name2obd(const char *name);
70 int class_uuid2dev(struct obd_uuid *uuid);
71 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
72 void class_obd_list(void);
73 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
74 const char * typ_name,
75 struct obd_uuid *grp_uuid);
76 struct obd_device * class_find_client_notype(struct obd_uuid *tgt_uuid,
77 struct obd_uuid *grp_uuid);
78 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
81 int oig_init(struct obd_io_group **oig);
82 void oig_add_one(struct obd_io_group *oig,
83 struct oig_callback_context *occ);
84 void oig_complete_one(struct obd_io_group *oig,
85 struct oig_callback_context *occ, int rc);
86 void oig_release(struct obd_io_group *oig);
87 int oig_wait(struct obd_io_group *oig);
89 char *obd_export_nid2str(struct obd_export *exp);
91 int obd_export_evict_by_nid(struct obd_device *obd, const char *nid);
92 int obd_export_evict_by_uuid(struct obd_device *obd, const char *uuid);
95 int class_process_config(struct lustre_cfg *lcfg);
96 int class_attach(struct lustre_cfg *lcfg);
97 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
98 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
99 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
100 struct obd_device *class_incref(struct obd_device *obd);
101 void class_decref(struct obd_device *obd);
103 #define CFG_F_START 0x01 /* Set when we start updating from a log */
104 #define CFG_F_MARKER 0x02 /* We are within a maker */
105 #define CFG_F_SKIP 0x04 /* We should ignore this cfg command */
106 #define CFG_F_COMPAT146 0x08 /* Translation to new obd names required */
107 #define CFG_F_EXCLUDE 0x10 /* OST exclusion list */
110 /* Passed as data param to class_config_parse_llog */
111 struct config_llog_instance {
113 struct super_block *cfg_sb;
114 struct obd_uuid cfg_uuid;
115 int cfg_last_idx; /* for partial llog processing */
118 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
119 struct config_llog_instance *cfg);
120 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
121 struct config_llog_instance *cfg);
123 /* list of active configuration logs */
124 struct config_llog_data {
126 struct ldlm_res_id cld_resid;
127 struct config_llog_instance cld_cfg;
128 struct list_head cld_list_chain;
129 atomic_t cld_refcount;
130 unsigned int cld_stopping:1;
133 struct lustre_profile {
134 struct list_head lp_list;
140 struct lustre_profile *class_get_profile(const char * prof);
141 void class_del_profile(const char *prof);
144 #define class_export_get(exp) \
146 struct obd_export *exp_ = exp; \
147 atomic_inc(&exp_->exp_refcount); \
148 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
149 atomic_read(&exp_->exp_refcount)); \
153 #define class_export_put(exp) \
155 LASSERT((exp) != NULL); \
156 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
157 atomic_read(&(exp)->exp_refcount) - 1); \
158 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
159 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
160 __class_export_put(exp); \
162 void __class_export_put(struct obd_export *);
163 struct obd_export *class_new_export(struct obd_device *obddev,
164 struct obd_uuid *cluuid);
165 void class_unlink_export(struct obd_export *exp);
167 struct obd_import *class_import_get(struct obd_import *);
168 void class_import_put(struct obd_import *);
169 struct obd_import *class_new_import(struct obd_device *obd);
170 void class_destroy_import(struct obd_import *exp);
172 struct obd_type *class_search_type(const char *name);
173 struct obd_type *class_get_type(const char *name);
174 void class_put_type(struct obd_type *type);
175 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
176 struct obd_uuid *cluuid);
177 int class_disconnect(struct obd_export *exp);
178 void class_fail_export(struct obd_export *exp);
179 void class_disconnect_exports(struct obd_device *obddev);
180 void class_disconnect_stale_exports(struct obd_device *obddev);
181 int class_manual_cleanup(struct obd_device *obd);
185 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
186 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
187 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
188 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
189 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
191 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
192 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
193 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
196 #define OBT(dev) (dev)->obd_type
197 #define OBP(dev, op) (dev)->obd_type->typ_dt_ops->o_ ## op
198 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
199 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
201 /* Ensure obd_setup: used for cleanup which must be called
202 while obd is stopping */
203 #define OBD_CHECK_DEV(obd) \
206 CERROR("NULL device\n"); \
211 /* ensure obd_setup and !obd_stopping */
212 #define OBD_CHECK_DEV_ACTIVE(obd) \
214 OBD_CHECK_DEV(obd); \
215 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
216 CERROR("Device %d not setup\n", \
224 #define OBD_COUNTER_OFFSET(op) \
225 ((offsetof(struct obd_ops, o_ ## op) - \
226 offsetof(struct obd_ops, o_iocontrol)) \
227 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
229 #define OBD_COUNTER_INCREMENT(obd, op) \
230 if ((obd)->obd_stats != NULL) { \
231 unsigned int coffset; \
232 coffset = (unsigned int)(obd)->obd_cntr_base + \
233 OBD_COUNTER_OFFSET(op); \
234 LASSERT(coffset < obd->obd_stats->ls_num); \
235 lprocfs_counter_incr(obd->obd_stats, coffset); \
238 #define MD_COUNTER_OFFSET(op) \
239 ((offsetof(struct md_ops, m_ ## op) - \
240 offsetof(struct md_ops, m_getstatus)) \
241 / sizeof(((struct md_ops *)(0))->m_getstatus))
243 #define MD_COUNTER_INCREMENT(obd, op) \
244 if ((obd)->md_stats != NULL) { \
245 unsigned int coffset; \
246 coffset = (unsigned int)(obd)->md_cntr_base + \
247 MD_COUNTER_OFFSET(op); \
248 LASSERT(coffset < (obd)->md_stats->ls_num); \
249 lprocfs_counter_incr((obd)->md_stats, coffset); \
253 #define OBD_COUNTER_OFFSET(op)
254 #define OBD_COUNTER_INCREMENT(obd, op)
255 #define MD_COUNTER_INCREMENT(obd, op)
258 #define OBD_CHECK_MD_OP(obd, op, err) \
260 if (!OBT(obd) || !MDP((obd), op)) { \
262 CERROR("md_" #op ": dev %s/%d no operation\n", \
263 obd->obd_name, obd->obd_minor); \
268 #define EXP_CHECK_MD_OP(exp, op) \
270 if ((exp) == NULL) { \
271 CERROR("obd_" #op ": NULL export\n"); \
274 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
275 CERROR("obd_" #op ": cleaned up obd\n"); \
276 RETURN(-EOPNOTSUPP); \
278 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
279 CERROR("obd_" #op ": dev %s/%d no operation\n", \
280 (exp)->exp_obd->obd_name, \
281 (exp)->exp_obd->obd_minor); \
282 RETURN(-EOPNOTSUPP); \
287 #define OBD_CHECK_DT_OP(obd, op, err) \
289 if (!OBT(obd) || !OBP((obd), op)) { \
291 CERROR("obd_" #op ": dev %d no operation\n", \
297 #define EXP_CHECK_DT_OP(exp, op) \
299 if ((exp) == NULL) { \
300 CERROR("obd_" #op ": NULL export\n"); \
303 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
304 CERROR("obd_" #op ": cleaned up obd\n"); \
305 RETURN(-EOPNOTSUPP); \
307 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
308 CERROR("obd_" #op ": dev %d no operation\n", \
309 (exp)->exp_obd->obd_minor); \
310 RETURN(-EOPNOTSUPP); \
314 #define CTXT_CHECK_OP(ctxt, op, err) \
316 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
318 CERROR("lop_" #op ": dev %d no operation\n", \
319 ctxt->loc_obd->obd_minor); \
324 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
325 void *key, __u32 *vallen, void *val)
330 EXP_CHECK_DT_OP(exp, get_info);
331 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
333 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
337 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
338 void *key, obd_count vallen, void *val)
343 EXP_CHECK_DT_OP(exp, set_info);
344 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
346 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
350 static inline int obd_setup(struct obd_device *obd, struct lustre_cfg *cfg)
353 struct lu_device_type *ldt;
356 ldt = obd->obd_type->typ_lu;
360 d = ldt->ldt_ops->ldto_device_alloc(ldt, cfg);
368 OBD_CHECK_DT_OP(obd, setup, -EOPNOTSUPP);
369 OBD_COUNTER_INCREMENT(obd, setup);
370 rc = OBP(obd, setup)(obd, cfg);
375 static inline int obd_precleanup(struct obd_device *obd,
376 enum obd_cleanup_stage cleanup_stage)
381 OBD_CHECK_DT_OP(obd, precleanup, 0);
382 OBD_COUNTER_INCREMENT(obd, precleanup);
384 rc = OBP(obd, precleanup)(obd, cleanup_stage);
388 static inline int obd_cleanup(struct obd_device *obd)
392 struct lu_device_type *ldt;
397 ldt = obd->obd_type->typ_lu;
399 if (ldt != NULL && d != NULL) {
400 ldt->ldt_ops->ldto_device_free(d);
401 obd->obd_lu_dev = NULL;
404 OBD_CHECK_DT_OP(obd, cleanup, 0);
405 rc = OBP(obd, cleanup)(obd);
407 OBD_COUNTER_INCREMENT(obd, cleanup);
412 obd_process_config(struct obd_device *obd, int datalen, void *data)
416 struct lu_device_type *ldt;
421 ldt = obd->obd_type->typ_lu;
423 if (ldt != NULL && d != NULL) {
424 rc = d->ld_ops->ldo_process_config(d,
425 (struct lustre_cfg *)data);
427 OBD_CHECK_DT_OP(obd, process_config, -EOPNOTSUPP);
428 rc = OBP(obd, process_config)(obd, datalen, data);
430 OBD_COUNTER_INCREMENT(obd, process_config);
435 /* Pack an in-memory MD struct for storage on disk.
436 * Returns +ve size of packed MD (0 for free), or -ve error.
438 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
439 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
440 * If @*disk_tgt == NULL, it will be allocated
442 static inline int obd_packmd(struct obd_export *exp,
443 struct lov_mds_md **disk_tgt,
444 struct lov_stripe_md *mem_src)
449 EXP_CHECK_DT_OP(exp, packmd);
450 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
452 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
456 static inline int obd_size_diskmd(struct obd_export *exp,
457 struct lov_stripe_md *mem_src)
459 return obd_packmd(exp, NULL, mem_src);
462 /* helper functions */
463 static inline int obd_alloc_diskmd(struct obd_export *exp,
464 struct lov_mds_md **disk_tgt)
467 LASSERT(*disk_tgt == NULL);
468 return obd_packmd(exp, disk_tgt, NULL);
471 static inline int obd_free_diskmd(struct obd_export *exp,
472 struct lov_mds_md **disk_tgt)
476 return obd_packmd(exp, disk_tgt, NULL);
479 /* Unpack an MD struct from disk to in-memory format.
480 * Returns +ve size of unpacked MD (0 for free), or -ve error.
482 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
483 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
484 * If @*mem_tgt == NULL, it will be allocated
486 static inline int obd_unpackmd(struct obd_export *exp,
487 struct lov_stripe_md **mem_tgt,
488 struct lov_mds_md *disk_src,
494 EXP_CHECK_DT_OP(exp, unpackmd);
495 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
497 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
501 /* helper functions */
502 static inline int obd_alloc_memmd(struct obd_export *exp,
503 struct lov_stripe_md **mem_tgt)
506 LASSERT(*mem_tgt == NULL);
507 return obd_unpackmd(exp, mem_tgt, NULL, 0);
510 static inline int obd_free_memmd(struct obd_export *exp,
511 struct lov_stripe_md **mem_tgt)
515 return obd_unpackmd(exp, mem_tgt, NULL, 0);
518 static inline int obd_checkmd(struct obd_export *exp,
519 struct obd_export *md_exp,
520 struct lov_stripe_md *mem_tgt)
525 EXP_CHECK_DT_OP(exp, checkmd);
526 OBD_COUNTER_INCREMENT(exp->exp_obd, checkmd);
528 rc = OBP(exp->exp_obd, checkmd)(exp, md_exp, mem_tgt);
532 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
533 struct lov_stripe_md **ea,
534 struct obd_trans_info *oti)
539 EXP_CHECK_DT_OP(exp, create);
540 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
542 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
546 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
547 struct lov_stripe_md *ea,
548 struct obd_trans_info *oti,
549 struct obd_export *md_exp)
554 EXP_CHECK_DT_OP(exp, destroy);
555 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
557 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti, md_exp);
561 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
562 struct lov_stripe_md *ea)
567 EXP_CHECK_DT_OP(exp, getattr);
568 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
570 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
574 static inline int obd_getattr_async(struct obd_export *exp,
575 struct obdo *obdo, struct lov_stripe_md *ea,
576 struct ptlrpc_request_set *set)
581 EXP_CHECK_DT_OP(exp, getattr);
582 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
584 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
588 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
589 struct lov_stripe_md *ea,
590 struct obd_trans_info *oti)
595 EXP_CHECK_DT_OP(exp, setattr);
596 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
598 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
602 static inline int obd_setattr_async(struct obd_export *exp,
604 struct lov_stripe_md *ea,
605 struct obd_trans_info *oti)
610 EXP_CHECK_DT_OP(exp, setattr_async);
611 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr_async);
613 rc = OBP(exp->exp_obd, setattr_async)(exp, obdo, ea, oti);
617 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
620 struct obd_device *obd = imp->imp_obd;
624 OBD_CHECK_DEV_ACTIVE(obd);
625 OBD_CHECK_DT_OP(obd, add_conn, -EOPNOTSUPP);
626 OBD_COUNTER_INCREMENT(obd, add_conn);
628 rc = OBP(obd, add_conn)(imp, uuid, priority);
632 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
634 struct obd_device *obd = imp->imp_obd;
638 OBD_CHECK_DEV_ACTIVE(obd);
639 OBD_CHECK_DT_OP(obd, del_conn, -EOPNOTSUPP);
640 OBD_COUNTER_INCREMENT(obd, del_conn);
642 rc = OBP(obd, del_conn)(imp, uuid);
646 static inline int obd_connect(struct lustre_handle *conn,struct obd_device *obd,
647 struct obd_uuid *cluuid,
648 struct obd_connect_data *d)
651 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
654 OBD_CHECK_DEV_ACTIVE(obd);
655 OBD_CHECK_DT_OP(obd, connect, -EOPNOTSUPP);
656 OBD_COUNTER_INCREMENT(obd, connect);
658 rc = OBP(obd, connect)(conn, obd, cluuid, d);
659 /* check that only subset is granted */
660 LASSERT(ergo(d != NULL,
661 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
665 static inline int obd_reconnect(struct obd_export *exp,
666 struct obd_device *obd,
667 struct obd_uuid *cluuid,
668 struct obd_connect_data *d)
671 __u64 ocf = d ? d->ocd_connect_flags : 0; /* for post-condition check */
674 OBD_CHECK_DEV_ACTIVE(obd);
675 OBD_CHECK_DT_OP(obd, reconnect, 0);
676 OBD_COUNTER_INCREMENT(obd, reconnect);
678 rc = OBP(obd, reconnect)(exp, obd, cluuid, d);
679 /* check that only subset is granted */
680 LASSERT(ergo(d != NULL,
681 (d->ocd_connect_flags & ocf) == d->ocd_connect_flags));
685 static inline int obd_disconnect(struct obd_export *exp)
690 EXP_CHECK_DT_OP(exp, disconnect);
691 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
693 rc = OBP(exp->exp_obd, disconnect)(exp);
697 static inline int obd_fid_alloc(struct obd_export *exp,
699 struct placement_hint *hint)
704 if (OBP(exp->exp_obd, fid_alloc) == NULL)
707 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_alloc);
709 rc = OBP(exp->exp_obd, fid_alloc)(exp, fid, hint);
713 static inline int obd_fid_delete(struct obd_export *exp,
719 if (OBP(exp->exp_obd, fid_delete) == NULL)
722 OBD_COUNTER_INCREMENT(exp->exp_obd, fid_delete);
723 rc = OBP(exp->exp_obd, fid_delete)(exp, fid);
727 static inline int obd_init_export(struct obd_export *exp)
732 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
733 OBP((exp)->exp_obd, init_export))
734 rc = OBP(exp->exp_obd, init_export)(exp);
738 static inline int obd_destroy_export(struct obd_export *exp)
741 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
742 OBP((exp)->exp_obd, destroy_export))
743 OBP(exp->exp_obd, destroy_export)(exp);
747 static inline struct dentry *
748 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
750 LASSERT(exp->exp_obd);
752 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
757 obd_lvfs_open_llog(struct obd_export *exp, __u64 id_ino, struct dentry *dentry)
759 LASSERT(exp->exp_obd);
760 CERROR("FIXME what's the story here? This needs to be an obd fn?\n");
762 return lvfs_open_llog(&exp->exp_obd->obd_lvfs_ctxt, id_ino,
763 dentry, exp->exp_obd);
769 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
772 /* @max_age is the oldest time in jiffies that we accept using a cached data.
773 * If the cache is older than @max_age we will get a new value from the
774 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
775 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
776 unsigned long max_age)
784 OBD_CHECK_DT_OP(obd, statfs, -EOPNOTSUPP);
785 OBD_COUNTER_INCREMENT(obd, statfs);
787 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
788 if (time_before(obd->obd_osfs_age, max_age)) {
789 rc = OBP(obd, statfs)(obd, osfs, max_age);
791 spin_lock(&obd->obd_osfs_lock);
792 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
793 obd->obd_osfs_age = jiffies;
794 spin_unlock(&obd->obd_osfs_lock);
797 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
798 spin_lock(&obd->obd_osfs_lock);
799 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
800 spin_unlock(&obd->obd_osfs_lock);
805 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
806 struct lov_stripe_md *ea, obd_size start,
812 OBD_CHECK_DT_OP(exp->exp_obd, sync, -EOPNOTSUPP);
813 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
815 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
819 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
820 struct lov_stripe_md *ea, obd_size start,
821 obd_size end, struct obd_trans_info *oti)
826 EXP_CHECK_DT_OP(exp, punch);
827 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
829 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
833 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
834 struct lov_stripe_md *ea, obd_count oa_bufs,
835 struct brw_page *pg, struct obd_trans_info *oti)
840 EXP_CHECK_DT_OP(exp, brw);
841 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
843 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
844 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
845 "or OBD_BRW_CHECK\n");
849 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
853 static inline int obd_brw_async(int cmd, struct obd_export *exp,
854 struct obdo *oa, struct lov_stripe_md *ea,
855 obd_count oa_bufs, struct brw_page *pg,
856 struct ptlrpc_request_set *set,
857 struct obd_trans_info *oti)
862 EXP_CHECK_DT_OP(exp, brw_async);
863 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
865 if (!(cmd & OBD_BRW_RWMASK)) {
866 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
870 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
875 static inline int obd_prep_async_page(struct obd_export *exp,
876 struct lov_stripe_md *lsm,
877 struct lov_oinfo *loi,
878 struct page *page, obd_off offset,
879 struct obd_async_page_ops *ops,
880 void *data, void **res)
885 OBD_CHECK_DT_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
886 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
888 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
893 static inline int obd_queue_async_io(struct obd_export *exp,
894 struct lov_stripe_md *lsm,
895 struct lov_oinfo *loi, void *cookie,
896 int cmd, obd_off off, int count,
897 obd_flag brw_flags, obd_flag async_flags)
902 OBD_CHECK_DT_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
903 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
904 LASSERT(cmd & OBD_BRW_RWMASK);
906 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
907 count, brw_flags, async_flags);
911 static inline int obd_set_async_flags(struct obd_export *exp,
912 struct lov_stripe_md *lsm,
913 struct lov_oinfo *loi, void *cookie,
914 obd_flag async_flags)
919 OBD_CHECK_DT_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
920 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
922 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
927 static inline int obd_queue_group_io(struct obd_export *exp,
928 struct lov_stripe_md *lsm,
929 struct lov_oinfo *loi,
930 struct obd_io_group *oig,
931 void *cookie, int cmd, obd_off off,
932 int count, obd_flag brw_flags,
933 obd_flag async_flags)
938 OBD_CHECK_DT_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
939 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
940 LASSERT(cmd & OBD_BRW_RWMASK);
942 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
943 cmd, off, count, brw_flags,
948 static inline int obd_trigger_group_io(struct obd_export *exp,
949 struct lov_stripe_md *lsm,
950 struct lov_oinfo *loi,
951 struct obd_io_group *oig)
956 OBD_CHECK_DT_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
957 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
959 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
963 static inline int obd_teardown_async_page(struct obd_export *exp,
964 struct lov_stripe_md *lsm,
965 struct lov_oinfo *loi, void *cookie)
970 OBD_CHECK_DT_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
971 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
973 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
977 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
978 int objcount, struct obd_ioobj *obj,
979 int niocount, struct niobuf_remote *remote,
980 struct niobuf_local *local,
981 struct obd_trans_info *oti)
986 OBD_CHECK_DT_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
987 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
989 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
994 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
995 int objcount, struct obd_ioobj *obj,
996 int niocount, struct niobuf_local *local,
997 struct obd_trans_info *oti, int rc)
1001 OBD_CHECK_DT_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
1002 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
1004 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
1009 static inline int obd_merge_lvb(struct obd_export *exp,
1010 struct lov_stripe_md *lsm,
1011 struct ost_lvb *lvb, int kms_only)
1016 OBD_CHECK_DT_OP(exp->exp_obd, merge_lvb, -EOPNOTSUPP);
1017 OBD_COUNTER_INCREMENT(exp->exp_obd, merge_lvb);
1019 rc = OBP(exp->exp_obd, merge_lvb)(exp, lsm, lvb, kms_only);
1023 static inline int obd_adjust_kms(struct obd_export *exp,
1024 struct lov_stripe_md *lsm, obd_off size,
1030 OBD_CHECK_DT_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
1031 OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
1033 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
1037 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1038 int len, void *karg, void *uarg)
1043 EXP_CHECK_DT_OP(exp, iocontrol);
1044 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
1046 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1050 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
1051 __u32 type, ldlm_policy_data_t *policy,
1052 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
1053 void *gl_cb, void *data, __u32 lvb_len,
1054 void *lvb_swabber, struct lustre_handle *lockh)
1059 EXP_CHECK_DT_OP(exp, enqueue);
1060 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1062 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
1063 bl_cb, cp_cb, gl_cb, data, lvb_len,
1064 lvb_swabber, lockh);
1068 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1069 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1070 int *flags, void *data, struct lustre_handle *lockh)
1075 EXP_CHECK_DT_OP(exp, match);
1076 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1078 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1083 static inline int obd_change_cbdata(struct obd_export *exp,
1084 struct lov_stripe_md *lsm,
1085 ldlm_iterator_t it, void *data)
1090 EXP_CHECK_DT_OP(exp, change_cbdata);
1091 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1093 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1097 static inline int obd_cancel(struct obd_export *exp,
1098 struct lov_stripe_md *ea, __u32 mode,
1099 struct lustre_handle *lockh)
1104 EXP_CHECK_DT_OP(exp, cancel);
1105 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1107 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1111 static inline int obd_cancel_unused(struct obd_export *exp,
1112 struct lov_stripe_md *ea,
1113 int flags, void *opaque)
1118 EXP_CHECK_DT_OP(exp, cancel_unused);
1119 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1121 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1125 static inline int obd_join_lru(struct obd_export *exp,
1126 struct lov_stripe_md *ea, int join)
1131 EXP_CHECK_DT_OP(exp, join_lru);
1132 OBD_COUNTER_INCREMENT(exp->exp_obd, join_lru);
1134 rc = OBP(exp->exp_obd, join_lru)(exp, ea, join);
1138 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1140 int objcount, struct obd_ioobj *obj,
1141 int niocount, struct niobuf_remote *remote)
1145 EXP_CHECK_DT_OP(exp, preprw);
1146 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1148 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1150 class_export_put(exp);
1154 static inline int obd_pin(struct obd_export *exp, struct lu_fid *fid,
1155 struct obd_client_handle *handle, int flag)
1159 EXP_CHECK_DT_OP(exp, pin);
1160 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1162 rc = OBP(exp->exp_obd, pin)(exp, fid, handle, flag);
1166 static inline int obd_unpin(struct obd_export *exp,
1167 struct obd_client_handle *handle, int flag)
1171 EXP_CHECK_DT_OP(exp, unpin);
1172 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1174 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1179 static inline void obd_import_event(struct obd_device *obd,
1180 struct obd_import *imp,
1181 enum obd_import_event event)
1184 CERROR("NULL device\n");
1188 if (obd->obd_set_up && OBP(obd, import_event)) {
1189 OBD_COUNTER_INCREMENT(obd, import_event);
1190 OBP(obd, import_event)(obd, imp, event);
1194 static inline int obd_notify(struct obd_device *obd,
1195 struct obd_device *watched,
1196 enum obd_notify_event ev,
1201 /* the check for async_recov is a complete hack - I'm hereby
1202 overloading the meaning to also mean "this was called from
1203 mds_postsetup". I know that my mds is able to handle notifies
1204 by this point, and it needs to get them to execute mds_postrecov. */
1205 if (!obd->obd_set_up && !obd->obd_async_recov) {
1206 CDEBUG(D_HA, "obd %s not set up\n", obd->obd_name);
1210 if (!OBP(obd, notify)) {
1211 CERROR("obd %s has no notify handler\n", obd->obd_name);
1215 OBD_COUNTER_INCREMENT(obd, notify);
1216 return OBP(obd, notify)(obd, watched, ev, data);
1219 static inline int obd_notify_observer(struct obd_device *observer,
1220 struct obd_device *observed,
1221 enum obd_notify_event ev,
1227 struct obd_notify_upcall *onu;
1229 if (observer->obd_observer)
1230 rc1 = obd_notify(observer->obd_observer, observed, ev, data);
1234 * Also, call non-obd listener, if any
1236 onu = &observer->obd_upcall;
1237 if (onu->onu_upcall != NULL)
1238 rc2 = onu->onu_upcall(observer, observed, ev, onu->onu_owner);
1242 return rc1 ? rc1 : rc2;
1245 static inline int obd_quotacheck(struct obd_export *exp,
1246 struct obd_quotactl *oqctl)
1251 EXP_CHECK_DT_OP(exp, quotacheck);
1252 OBD_COUNTER_INCREMENT(exp->exp_obd, quotacheck);
1254 rc = OBP(exp->exp_obd, quotacheck)(exp, oqctl);
1258 static inline int obd_quotactl(struct obd_export *exp,
1259 struct obd_quotactl *oqctl)
1264 EXP_CHECK_DT_OP(exp, quotactl);
1265 OBD_COUNTER_INCREMENT(exp->exp_obd, quotactl);
1267 rc = OBP(exp->exp_obd, quotactl)(exp, oqctl);
1271 static inline int obd_health_check(struct obd_device *obd)
1273 /* returns: 0 on healthy
1274 * >0 on unhealthy + reason code/flag
1275 * however the only suppored reason == 1 right now
1276 * We'll need to define some better reasons
1277 * or flags in the future.
1283 /* don't use EXP_CHECK_OP, because NULL method is normal here */
1284 if (obd == NULL || !OBT(obd)) {
1285 CERROR("cleaned up obd\n");
1286 RETURN(-EOPNOTSUPP);
1288 if (!obd->obd_set_up || obd->obd_stopping)
1290 if (!OBP(obd, health_check))
1293 rc = OBP(obd, health_check)(obd);
1297 static inline int obd_register_observer(struct obd_device *obd,
1298 struct obd_device *observer)
1302 if (obd->obd_observer && observer)
1304 obd->obd_observer = observer;
1308 /* metadata helpers */
1309 static inline int md_getstatus(struct obd_export *exp, struct lu_fid *fid)
1314 EXP_CHECK_MD_OP(exp, getstatus);
1315 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1316 rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1320 static inline int md_getattr(struct obd_export *exp, struct lu_fid *fid,
1321 obd_valid valid, int ea_size,
1322 struct ptlrpc_request **request)
1326 EXP_CHECK_MD_OP(exp, getattr);
1327 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1328 rc = MDP(exp->exp_obd, getattr)(exp, fid, valid,
1333 static inline int md_change_cbdata(struct obd_export *exp, struct lu_fid *fid,
1334 ldlm_iterator_t it, void *data)
1338 EXP_CHECK_MD_OP(exp, change_cbdata);
1339 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1340 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1344 static inline int md_close(struct obd_export *exp,
1345 struct md_op_data *op_data,
1346 struct obd_client_handle *och,
1347 struct ptlrpc_request **request)
1351 EXP_CHECK_MD_OP(exp, close);
1352 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1353 rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1357 static inline int md_create(struct obd_export *exp, struct md_op_data *op_data,
1358 const void *data, int datalen, int mode,
1359 __u32 uid, __u32 gid, __u32 cap_effective, __u64 rdev,
1360 struct ptlrpc_request **request)
1364 EXP_CHECK_MD_OP(exp, create);
1365 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1366 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1367 uid, gid, cap_effective, rdev, request);
1371 static inline int md_done_writing(struct obd_export *exp,
1372 struct md_op_data *op_data)
1376 EXP_CHECK_MD_OP(exp, done_writing);
1377 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1378 rc = MDP(exp->exp_obd, done_writing)(exp, op_data);
1382 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1383 struct lookup_intent *it, int lock_mode,
1384 struct md_op_data *op_data,
1385 struct lustre_handle *lockh,
1386 void *lmm, int lmmsize,
1387 ldlm_completion_callback cb_completion,
1388 ldlm_blocking_callback cb_blocking,
1389 void *cb_data, int extra_lock_flags)
1393 EXP_CHECK_MD_OP(exp, enqueue);
1394 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1395 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1396 op_data, lockh, lmm, lmmsize,
1397 cb_completion, cb_blocking,
1398 cb_data, extra_lock_flags);
1402 static inline int md_getattr_name(struct obd_export *exp, struct lu_fid *fid,
1403 const char *filename, int namelen,
1404 obd_valid valid, int ea_size,
1405 struct ptlrpc_request **request)
1409 EXP_CHECK_MD_OP(exp, getattr_name);
1410 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1411 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1412 valid, ea_size, request);
1416 static inline int md_intent_lock(struct obd_export *exp,
1417 struct md_op_data *op_data,
1418 void *lmm, int lmmsize,
1419 struct lookup_intent *it,
1420 int flags, struct ptlrpc_request **reqp,
1421 ldlm_blocking_callback cb_blocking,
1422 int extra_lock_flags)
1426 EXP_CHECK_MD_OP(exp, intent_lock);
1427 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1428 rc = MDP(exp->exp_obd, intent_lock)(exp, op_data, lmm, lmmsize,
1429 it, flags, reqp, cb_blocking,
1434 static inline int md_link(struct obd_export *exp,
1435 struct md_op_data *op_data,
1436 struct ptlrpc_request **request)
1440 EXP_CHECK_MD_OP(exp, link);
1441 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1442 rc = MDP(exp->exp_obd, link)(exp, op_data, request);
1446 static inline int md_rename(struct obd_export *exp,
1447 struct md_op_data *op_data,
1448 const char *old, int oldlen,
1449 const char *new, int newlen,
1450 struct ptlrpc_request **request)
1454 EXP_CHECK_MD_OP(exp, rename);
1455 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1456 rc = MDP(exp->exp_obd, rename)(exp, op_data, old, oldlen, new,
1461 static inline int md_setattr(struct obd_export *exp, struct md_op_data *op_data,
1462 struct iattr *iattr, void *ea, int ealen,
1463 void *ea2, int ea2len, struct ptlrpc_request **request)
1467 EXP_CHECK_MD_OP(exp, setattr);
1468 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1469 rc = MDP(exp->exp_obd, setattr)(exp, op_data, iattr, ea, ealen,
1470 ea2, ea2len, request);
1474 static inline int md_sync(struct obd_export *exp, struct lu_fid *fid,
1475 struct ptlrpc_request **request)
1479 EXP_CHECK_MD_OP(exp, sync);
1480 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1481 rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1485 static inline int md_readpage(struct obd_export *exp, struct lu_fid *fid,
1486 __u64 offset, struct page *page,
1487 struct ptlrpc_request **request)
1491 EXP_CHECK_MD_OP(exp, readpage);
1492 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1493 rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1497 static inline int md_unlink(struct obd_export *exp, struct md_op_data *op_data,
1498 struct ptlrpc_request **request)
1502 EXP_CHECK_MD_OP(exp, unlink);
1503 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1504 rc = MDP(exp->exp_obd, unlink)(exp, op_data, request);
1508 static inline int md_get_lustre_md(struct obd_export *exp,
1509 struct ptlrpc_request *req,
1510 int offset, struct obd_export *dt_exp,
1511 struct lustre_md *md)
1514 EXP_CHECK_MD_OP(exp, get_lustre_md);
1515 MD_COUNTER_INCREMENT(exp->exp_obd, get_lustre_md);
1516 RETURN(MDP(exp->exp_obd, get_lustre_md)(exp, req, offset,
1520 static inline int md_free_lustre_md(struct obd_export *exp,
1521 struct lustre_md *md)
1524 EXP_CHECK_MD_OP(exp, free_lustre_md);
1525 MD_COUNTER_INCREMENT(exp->exp_obd, free_lustre_md);
1526 RETURN(MDP(exp->exp_obd, free_lustre_md)(exp, md));
1529 static inline int md_setxattr(struct obd_export *exp, struct lu_fid *fid,
1530 obd_valid valid, const char *name,
1531 const char *input, int input_size,
1532 int output_size, int flags,
1533 struct ptlrpc_request **request)
1536 EXP_CHECK_MD_OP(exp, setxattr);
1537 MD_COUNTER_INCREMENT(exp->exp_obd, setxattr);
1538 RETURN(MDP(exp->exp_obd, setxattr)(exp, fid, valid, name, input,
1539 input_size, output_size, flags,
1543 static inline int md_getxattr(struct obd_export *exp, struct lu_fid *fid,
1544 obd_valid valid, const char *name,
1545 const char *input, int input_size,
1546 int output_size, int flags,
1547 struct ptlrpc_request **request)
1550 EXP_CHECK_MD_OP(exp, getxattr);
1551 MD_COUNTER_INCREMENT(exp->exp_obd, getxattr);
1552 RETURN(MDP(exp->exp_obd, getxattr)(exp, fid, valid, name, input,
1553 input_size, output_size, flags,
1557 static inline int md_set_open_replay_data(struct obd_export *exp,
1558 struct obd_client_handle *och,
1559 struct ptlrpc_request *open_req)
1562 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1563 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1564 RETURN(MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req));
1567 static inline int md_clear_open_replay_data(struct obd_export *exp,
1568 struct obd_client_handle *och)
1571 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1572 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1573 RETURN(MDP(exp->exp_obd, clear_open_replay_data)(exp, och));
1576 static inline int md_set_lock_data(struct obd_export *exp,
1577 __u64 *lockh, void *data)
1580 EXP_CHECK_MD_OP(exp, set_lock_data);
1581 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1582 RETURN(MDP(exp->exp_obd, set_lock_data)(exp, lockh, data));
1585 static inline int md_cancel_unused(struct obd_export *exp,
1587 int flags, void *opaque)
1592 EXP_CHECK_MD_OP(exp, cancel_unused);
1593 MD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1595 rc = MDP(exp->exp_obd, cancel_unused)(exp, fid, flags, opaque);
1599 static inline int md_lock_match(struct obd_export *exp, int flags,
1600 struct lu_fid *fid, ldlm_type_t type,
1601 ldlm_policy_data_t *policy, ldlm_mode_t mode,
1602 struct lustre_handle *lockh)
1605 EXP_CHECK_MD_OP(exp, lock_match);
1606 MD_COUNTER_INCREMENT(exp->exp_obd, lock_match);
1607 RETURN(MDP(exp->exp_obd, lock_match)(exp, flags, fid, type,
1608 policy, mode, lockh));
1611 static inline int md_init_ea_size(struct obd_export *exp,
1612 int easize, int def_asize,
1616 EXP_CHECK_MD_OP(exp, init_ea_size);
1617 MD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1618 RETURN(MDP(exp->exp_obd, init_ea_size)(exp, easize,
1623 /* OBD Metadata Support */
1624 extern int obd_init_caches(void);
1625 extern void obd_cleanup_caches(void);
1627 /* support routines */
1628 extern kmem_cache_t *obdo_cachep;
1629 static inline struct obdo *obdo_alloc(void)
1633 OBD_SLAB_ALLOC(oa, obdo_cachep, SLAB_KERNEL, sizeof(*oa));
1638 static inline void obdo_free(struct obdo *oa)
1640 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1643 static inline void obdo2fid(struct obdo *oa,
1646 /* something here */
1649 static inline void fid2obdo(struct lu_fid *fid,
1652 /* something here */
1655 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1656 #define to_kdev_t(dev) dev
1657 #define kdev_t_to_nr(dev) dev
1660 /* I'm as embarrassed about this as you are.
1662 * <shaver> // XXX do not look into _superhack with remaining eye
1663 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1664 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1667 extern void obd_sysctl_init (void);
1668 extern void obd_sysctl_clean (void);
1671 typedef __u8 class_uuid_t[16];
1672 void class_generate_random_uuid(class_uuid_t uuid);
1673 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1676 int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index);
1677 int class_add_uuid(const char *uuid, __u64 nid);
1678 int class_del_uuid (const char *uuid);
1679 void class_init_uuidlist(void);
1680 void class_exit_uuidlist(void);
1683 int mea_name2idx(struct lmv_stripe_md *mea, char *name, int namelen);
1684 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1686 #endif /* __LINUX_OBD_CLASS_H */