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/time.h>
35 #include <linux/timer.h>
38 #include <linux/obd_support.h>
39 #include <linux/lustre_import.h>
40 #include <linux/lustre_net.h>
41 #include <linux/obd.h>
42 #include <linux/lustre_lib.h>
43 #include <linux/lustre_idl.h>
44 #include <linux/lprocfs_status.h>
45 #include <linux/lustre_log.h>
47 /* OBD Device Declarations */
48 #define MAX_OBD_DEVICES 256
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 *);
57 struct obd_export *class_conn2export(struct lustre_handle *);
58 int class_register_type(struct obd_ops *ops, struct md_ops *md_ops,
59 struct lprocfs_vars *, char *nm);
60 int class_unregister_type(char *nm);
62 struct obd_device *class_newdev(struct obd_type *type);
63 void class_release_dev(struct obd_device *obd);
65 int class_name2dev(char *name);
66 struct obd_device *class_name2obd(char *name);
67 int class_uuid2dev(struct obd_uuid *uuid);
68 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
69 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
71 struct obd_uuid *grp_uuid);
72 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
75 int oig_init(struct obd_io_group **oig);
76 void oig_add_one(struct obd_io_group *oig,
77 struct oig_callback_context *occ);
78 void oig_complete_one(struct obd_io_group *oig,
79 struct oig_callback_context *occ, int rc);
80 void oig_release(struct obd_io_group *oig);
81 int oig_wait(struct obd_io_group *oig);
84 int class_process_config(struct lustre_cfg *lcfg);
86 /* Passed as data param to class_config_parse_handler() */
87 struct config_llog_instance {
89 struct obd_uuid cfg_uuid;
90 ptl_nid_t cfg_local_nid;
93 int class_config_process_llog(struct llog_ctxt *ctxt, char *name,
94 struct config_llog_instance *cfg);
95 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
96 struct config_llog_instance *cfg);
98 struct lustre_profile {
99 struct list_head lp_list;
106 struct lustre_profile *class_get_profile(char * prof);
107 void class_del_profile(char *prof);
109 #define class_export_rpc_get(exp) \
111 atomic_inc(&(exp)->exp_rpc_count); \
112 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
113 (exp), atomic_read(&(exp)->exp_rpc_count)); \
114 class_export_get(exp); \
117 #define class_export_rpc_put(exp) \
119 atomic_dec(&(exp)->exp_rpc_count); \
120 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
121 (exp), atomic_read(&(exp)->exp_rpc_count)); \
122 class_export_put(exp); \
125 #define class_export_get(exp) \
127 struct obd_export *exp_ = exp; \
128 atomic_inc(&exp_->exp_refcount); \
129 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
130 atomic_read(&exp_->exp_refcount)); \
134 #define class_export_put(exp) \
136 LASSERT((exp) != NULL); \
137 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
138 atomic_read(&(exp)->exp_refcount) - 1); \
139 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
140 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
141 __class_export_put(exp); \
144 void __class_export_put(struct obd_export *);
145 struct obd_export *class_new_export(struct obd_device *obddev);
146 void class_unlink_export(struct obd_export *exp);
148 struct obd_import *class_import_get(struct obd_import *);
149 void class_import_put(struct obd_import *);
150 struct obd_import *class_new_import(void);
151 void class_destroy_import(struct obd_import *exp);
153 struct obd_type *class_get_type(char *name);
154 void class_put_type(struct obd_type *type);
155 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
156 struct obd_uuid *cluuid);
157 int class_disconnect(struct obd_export *exp, unsigned long flags);
158 void class_disconnect_exports(struct obd_device *, unsigned long);
159 int class_disconnect_stale_exports(struct obd_device *,
160 int (*test_export)(struct obd_export *),
163 /* generic operations shared by various OBD types */
164 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
165 int class_multi_cleanup(struct obd_device *obddev);
169 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
170 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_valid valid);
171 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_valid valid);
172 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_valid valid);
173 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_valid valid);
175 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_valid valid);
176 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_valid compare);
177 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
179 #define OBT(dev) (dev)->obd_type
180 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
181 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
182 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
184 /* Ensure obd_setup: used for cleanup which must be called
185 while obd is stopping */
186 #define OBD_CHECK_DEV(obd) \
189 CERROR("NULL device\n"); \
194 #define OBD_CHECK_DEV_STOPPING(obd) \
196 OBD_CHECK_DEV(obd); \
197 if (!(obd)->obd_set_up) { \
198 CERROR("Device %d not setup\n", \
203 if (!(obd)->obd_stopping) { \
204 CERROR("Device %d not stopping\n", \
210 /* ensure obd_setup and !obd_stopping */
211 #define OBD_CHECK_DEV_ACTIVE(obd) \
213 OBD_CHECK_DEV(obd); \
214 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
215 CERROR("Device %d not setup\n", \
223 #define OBD_COUNTER_OFFSET(op) \
224 ((offsetof(struct obd_ops, o_ ## op) - \
225 offsetof(struct obd_ops, o_iocontrol)) \
226 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
228 #define OBD_COUNTER_INCREMENT(obd, op) \
229 if ((obd)->obd_stats != NULL) { \
230 unsigned int coffset; \
231 coffset = (unsigned int)(obd)->obd_cntr_base + \
232 OBD_COUNTER_OFFSET(op); \
233 LASSERT(coffset < (obd)->obd_stats->ls_num); \
234 lprocfs_counter_incr((obd)->obd_stats, coffset);\
237 #define MD_COUNTER_OFFSET(op) \
238 ((offsetof(struct md_ops, m_ ## op) - \
239 offsetof(struct md_ops, m_getstatus)) \
240 / sizeof(((struct md_ops *)(0))->m_getstatus))
242 #define MD_COUNTER_INCREMENT(obd, op) \
243 if ((obd)->md_stats != NULL) { \
244 unsigned int coffset; \
245 coffset = (unsigned int)(obd)->md_cntr_base + \
246 MD_COUNTER_OFFSET(op); \
247 LASSERT(coffset < (obd)->md_stats->ls_num); \
248 lprocfs_counter_incr((obd)->md_stats, coffset); \
252 #define OBD_COUNTER_OFFSET(op)
253 #define OBD_COUNTER_INCREMENT(obd, op)
254 #define MD_COUNTER_INCREMENT(obd, op)
257 #define OBD_CHECK_MD_OP(obd, op, err) \
259 if (!OBT(obd) || !MDP((obd), op)) {\
261 CERROR("md_" #op ": dev %s/%d no operation\n", \
262 obd->obd_name, obd->obd_minor); \
267 #define EXP_CHECK_MD_OP(exp, op) \
269 if ((exp) == NULL) { \
270 CERROR("obd_" #op ": NULL export\n"); \
271 portals_debug_dumplog(); \
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); \
286 #define OBD_CHECK_OP(obd, op, err) \
288 if (!OBT(obd) || !OBP((obd), op)) {\
290 CERROR("obd_" #op ": dev %s/%d no operation\n", \
291 obd->obd_name, obd->obd_minor); \
296 #define EXP_CHECK_OP(exp, op) \
298 if ((exp) == NULL) { \
299 CERROR("obd_" #op ": NULL export\n"); \
300 portals_debug_dumplog(); \
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 %s/%d no operation\n", \
309 (exp)->exp_obd->obd_name, \
310 (exp)->exp_obd->obd_minor); \
311 RETURN(-EOPNOTSUPP); \
315 #define CTXT_CHECK_OP(ctxt, op, err) \
317 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
319 CERROR("lop_" #op ": dev %d no operation\n", \
320 ctxt->loc_obd->obd_minor); \
325 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
326 void *key, __u32 *vallen, void *val)
331 EXP_CHECK_OP(exp, get_info);
332 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
334 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
338 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
339 void *key, obd_count vallen, void *val)
344 EXP_CHECK_OP(exp, set_info);
345 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
347 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
351 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
356 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
357 OBD_COUNTER_INCREMENT(obd, setup);
359 rc = OBP(obd, setup)(obd, datalen, data);
363 static inline int obd_precleanup(struct obd_device *obd, int flags)
368 OBD_CHECK_OP(obd, precleanup, 0);
369 OBD_COUNTER_INCREMENT(obd, precleanup);
371 rc = OBP(obd, precleanup)(obd, flags);
375 static inline int obd_cleanup(struct obd_device *obd, int flags)
380 OBD_CHECK_DEV_STOPPING(obd);
381 OBD_CHECK_OP(obd, cleanup, 0);
382 OBD_COUNTER_INCREMENT(obd, cleanup);
384 rc = OBP(obd, cleanup)(obd, flags);
389 obd_process_config(struct obd_device *obd, int datalen, void *data)
394 OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
395 OBD_COUNTER_INCREMENT(obd, process_config);
397 rc = OBP(obd, process_config)(obd, datalen, data);
401 /* Pack an in-memory MD struct for storage on disk.
402 * Returns +ve size of packed MD (0 for free), or -ve error.
404 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
405 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
406 * If @*disk_tgt == NULL, it will be allocated
408 static inline int obd_packmd(struct obd_export *exp,
409 struct lov_mds_md **disk_tgt,
410 struct lov_stripe_md *mem_src)
415 EXP_CHECK_OP(exp, packmd);
416 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
418 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
422 static inline int obd_size_diskmd(struct obd_export *exp,
423 struct lov_stripe_md *mem_src)
425 return obd_packmd(exp, NULL, mem_src);
428 /* helper functions */
429 static inline int obd_alloc_diskmd(struct obd_export *exp,
430 struct lov_mds_md **disk_tgt)
433 LASSERT(*disk_tgt == NULL);
434 return obd_packmd(exp, disk_tgt, NULL);
437 static inline int obd_free_diskmd(struct obd_export *exp,
438 struct lov_mds_md **disk_tgt)
442 return obd_packmd(exp, disk_tgt, NULL);
445 /* Unpack an MD struct from disk to in-memory format.
446 * Returns +ve size of unpacked MD (0 for free), or -ve error.
448 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
449 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
450 * If @*mem_tgt == NULL, it will be allocated
452 static inline int obd_unpackmd(struct obd_export *exp,
453 struct lov_stripe_md **mem_tgt,
454 struct lov_mds_md *disk_src,
460 EXP_CHECK_OP(exp, unpackmd);
461 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
463 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
467 /* helper functions */
468 static inline int obd_alloc_memmd(struct obd_export *exp,
469 struct lov_stripe_md **mem_tgt)
472 LASSERT(*mem_tgt == NULL);
473 return obd_unpackmd(exp, mem_tgt, NULL, 0);
476 static inline int obd_free_memmd(struct obd_export *exp,
477 struct lov_stripe_md **mem_tgt)
481 return obd_unpackmd(exp, mem_tgt, NULL, 0);
484 static inline int obd_revalidate_md(struct obd_export *exp, struct obdo *obdo,
485 struct lov_stripe_md *ea,
486 struct obd_trans_info *oti)
491 EXP_CHECK_OP(exp, revalidate_md);
492 OBD_COUNTER_INCREMENT(exp->exp_obd, revalidate_md);
494 rc = OBP(exp->exp_obd, revalidate_md)(exp, obdo, ea, oti);
498 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
499 void *acl, int acl_size,
500 struct lov_stripe_md **ea,
501 struct obd_trans_info *oti)
506 EXP_CHECK_OP(exp, create);
507 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
509 rc = OBP(exp->exp_obd, create)(exp, obdo, acl, acl_size, ea, oti);
513 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
514 struct lov_stripe_md *ea,
515 struct obd_trans_info *oti)
520 EXP_CHECK_OP(exp, destroy);
521 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
523 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
527 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
528 struct lov_stripe_md *ea)
533 EXP_CHECK_OP(exp, getattr);
534 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
536 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
540 static inline int obd_getattr_async(struct obd_export *exp,
541 struct obdo *obdo, struct lov_stripe_md *ea,
542 struct ptlrpc_request_set *set)
547 EXP_CHECK_OP(exp, getattr);
548 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
550 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
554 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
555 struct lov_stripe_md *ea,
556 struct obd_trans_info *oti,
557 struct lustre_capa *capa)
562 EXP_CHECK_OP(exp, setattr);
563 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
565 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti, capa);
568 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
571 struct obd_device *obd = imp->imp_obd;
575 OBD_CHECK_DEV_ACTIVE(obd);
576 OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
577 OBD_COUNTER_INCREMENT(obd, add_conn);
579 rc = OBP(obd, add_conn)(imp, uuid, priority);
583 static inline int obd_del_conn(struct obd_import *imp,
584 struct obd_uuid *uuid)
586 struct obd_device *obd = imp->imp_obd;
590 OBD_CHECK_DEV_ACTIVE(obd);
591 OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
592 OBD_COUNTER_INCREMENT(obd, del_conn);
594 rc = OBP(obd, del_conn)(imp, uuid);
599 static inline int obd_connect(struct lustre_handle *conn,
600 struct obd_device *obd,
601 struct obd_uuid *cluuid,
602 struct obd_connect_data *data,
608 OBD_CHECK_DEV_ACTIVE(obd);
609 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
610 OBD_COUNTER_INCREMENT(obd, connect);
612 rc = OBP(obd, connect)(conn, obd, cluuid, data, flags);
616 static inline int obd_connect_post(struct obd_export *exp,
623 OBD_CHECK_DEV_ACTIVE(exp->exp_obd);
624 if (!OBT(exp->exp_obd) || !OBP((exp->exp_obd), connect_post))
626 OBD_COUNTER_INCREMENT(exp->exp_obd, connect_post);
627 rc = OBP(exp->exp_obd, connect_post)(exp, initial, flags);
631 static inline int obd_disconnect(struct obd_export *exp,
637 EXP_CHECK_OP(exp, disconnect);
638 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
640 rc = OBP(exp->exp_obd, disconnect)(exp, flags);
644 static inline int obd_init_export(struct obd_export *exp)
649 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
650 OBP((exp)->exp_obd, init_export))
651 rc = OBP(exp->exp_obd, init_export)(exp);
655 static inline int obd_destroy_export(struct obd_export *exp)
658 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
659 OBP((exp)->exp_obd, destroy_export))
660 OBP(exp->exp_obd, destroy_export)(exp);
664 static inline struct dentry *
665 obd_lvfs_id2dentry(struct obd_export *exp, __u64 ino,
668 LASSERT(exp->exp_obd);
670 return lvfs_id2dentry(&exp->exp_obd->obd_lvfs_ctxt,
671 ino, gen, gr, exp->exp_obd);
675 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
678 /* @max_age is the oldest time in jiffies that we accept using a cached data.
679 * If the cache is older than @max_age we will get a new value from the
680 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
681 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
682 unsigned long max_age)
690 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
691 OBD_COUNTER_INCREMENT(obd, statfs);
693 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
694 if (time_before(obd->obd_osfs_age, max_age)) {
695 rc = OBP(obd, statfs)(obd, osfs, max_age);
697 spin_lock(&obd->obd_osfs_lock);
698 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
699 obd->obd_osfs_age = jiffies;
700 spin_unlock(&obd->obd_osfs_lock);
703 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
704 spin_lock(&obd->obd_osfs_lock);
705 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
706 spin_unlock(&obd->obd_osfs_lock);
711 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
712 struct lov_stripe_md *ea, obd_size start,
718 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
719 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
721 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
725 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
726 struct lov_stripe_md *ea, obd_size start,
727 obd_size end, struct obd_trans_info *oti,
728 struct lustre_capa *capa)
733 EXP_CHECK_OP(exp, punch);
734 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
736 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti, capa);
740 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
741 struct lov_stripe_md *ea, obd_count oa_bufs,
742 struct brw_page *pg, struct obd_trans_info *oti)
747 EXP_CHECK_OP(exp, brw);
748 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
750 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
751 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
752 "or OBD_BRW_CHECK\n");
756 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
760 static inline int obd_brw_async(int cmd, struct obd_export *exp,
761 struct obdo *oa, struct lov_stripe_md *ea,
762 obd_count oa_bufs, struct brw_page *pg,
763 struct ptlrpc_request_set *set,
764 struct obd_trans_info *oti)
769 EXP_CHECK_OP(exp, brw_async);
770 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
772 if (!(cmd & OBD_BRW_RWMASK)) {
773 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
777 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
782 static inline int obd_prep_async_page(struct obd_export *exp,
783 struct lov_stripe_md *lsm,
784 struct lov_oinfo *loi,
785 struct page *page, obd_off offset,
786 struct obd_async_page_ops *ops,
787 void *data, void **res)
792 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
793 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
795 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
800 static inline int obd_queue_async_io(struct obd_export *exp,
801 struct lov_stripe_md *lsm,
802 struct lov_oinfo *loi, void *cookie,
803 int cmd, obd_off off, int count,
804 obd_flags brw_flags, obd_flags async_flags)
809 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
810 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
811 LASSERT(cmd & OBD_BRW_RWMASK);
813 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
814 count, brw_flags, async_flags);
818 static inline int obd_set_async_flags(struct obd_export *exp,
819 struct lov_stripe_md *lsm,
820 struct lov_oinfo *loi, void *cookie,
821 obd_flags async_flags)
826 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
827 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
829 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
834 static inline int obd_queue_group_io(struct obd_export *exp,
835 struct lov_stripe_md *lsm,
836 struct lov_oinfo *loi,
837 struct obd_io_group *oig,
838 void *cookie, int cmd, obd_off off,
839 int count, obd_flags brw_flags,
840 obd_flags async_flags)
845 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
846 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
847 LASSERT(cmd & OBD_BRW_RWMASK);
849 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
850 cmd, off, count, brw_flags,
855 static inline int obd_trigger_group_io(struct obd_export *exp,
856 struct lov_stripe_md *lsm,
857 struct lov_oinfo *loi,
858 struct obd_io_group *oig)
863 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
864 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
866 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
870 static inline int obd_teardown_async_page(struct obd_export *exp,
871 struct lov_stripe_md *lsm,
872 struct lov_oinfo *loi, void *cookie)
877 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
878 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
880 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
884 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
885 int objcount, struct obd_ioobj *obj,
886 int niocount, struct niobuf_remote *remote,
887 struct niobuf_local *local,
888 struct obd_trans_info *oti,
889 struct lustre_capa *capa)
894 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
895 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
897 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
898 remote, local, oti, capa);
902 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
903 int objcount, struct obd_ioobj *obj,
904 int niocount, struct niobuf_local *local,
905 struct obd_trans_info *oti, int rc)
909 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
910 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
912 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
917 static inline int obd_do_cow(struct obd_export *exp, struct obd_ioobj *obj,
918 int objcount,struct niobuf_remote *rnb)
923 /* there are cases when write_extents is not implemented. */
924 if (!OBP(exp->exp_obd, do_cow))
927 OBD_COUNTER_INCREMENT(exp->exp_obd, do_cow);
929 rc = OBP(exp->exp_obd, do_cow)(exp, obj, objcount, rnb);
934 static inline int obd_write_extents(struct obd_export *exp,
935 struct obd_ioobj *obj,
936 int objcount, int niocount,
937 struct niobuf_local *local,
942 /* there are cases when write_extents is not implemented. */
943 if (!OBP(exp->exp_obd, write_extents))
946 OBD_COUNTER_INCREMENT(exp->exp_obd, write_extents);
948 rc = OBP(exp->exp_obd, write_extents)(exp, obj, objcount, niocount,
953 static inline int obd_adjust_kms(struct obd_export *exp,
954 struct lov_stripe_md *lsm,
955 obd_off size, int shrink)
960 OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
961 OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
963 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
967 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
968 int len, void *karg, void *uarg)
973 EXP_CHECK_OP(exp, iocontrol);
974 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
976 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
980 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
981 __u32 type, ldlm_policy_data_t *policy,
982 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
983 void *gl_cb, void *data, __u32 lvb_len,
984 void *lvb_swabber, struct lustre_handle *lockh)
989 EXP_CHECK_OP(exp, enqueue);
990 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
992 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
993 bl_cb, cp_cb, gl_cb, data, lvb_len,
998 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
999 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1000 int *flags, void *data, struct lustre_handle *lockh)
1005 EXP_CHECK_OP(exp, match);
1006 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1008 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1013 static inline int obd_change_cbdata(struct obd_export *exp,
1014 struct lov_stripe_md *lsm,
1015 ldlm_iterator_t it, void *data)
1020 EXP_CHECK_OP(exp, change_cbdata);
1021 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1023 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1027 static inline int obd_cancel(struct obd_export *exp,
1028 struct lov_stripe_md *ea, __u32 mode,
1029 struct lustre_handle *lockh)
1034 EXP_CHECK_OP(exp, cancel);
1035 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1037 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1041 static inline int obd_cancel_unused(struct obd_export *exp,
1042 struct lov_stripe_md *ea, int flags,
1048 EXP_CHECK_OP(exp, cancel_unused);
1049 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1051 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1056 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1058 int objcount, struct obd_ioobj *obj,
1059 int niocount, struct niobuf_remote *remote)
1063 EXP_CHECK_OP(exp, preprw);
1064 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1066 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1068 class_export_put(exp);
1072 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1073 int type, struct obd_client_handle *handle, int flag)
1077 EXP_CHECK_OP(exp, pin);
1078 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1080 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1084 static inline int obd_unpin(struct obd_export *exp,
1085 struct obd_client_handle *handle, int flag)
1089 EXP_CHECK_OP(exp, unpin);
1090 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1092 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1097 static inline void obd_import_event(struct obd_device *obd,
1098 struct obd_import *imp,
1099 enum obd_import_event event)
1102 CERROR("NULL device\n");
1106 if (obd->obd_set_up && OBP(obd, import_event)) {
1107 OBD_COUNTER_INCREMENT(obd, import_event);
1108 OBP(obd, import_event)(obd, imp, event);
1112 static inline int obd_llog_connect(struct obd_export *exp,
1113 struct llogd_conn_body *body)
1116 EXP_CHECK_OP(exp, llog_connect);
1117 return OBP(exp->exp_obd, llog_connect)(exp, body);
1120 static inline int obd_notify(struct obd_device *obd, struct obd_device *watched,
1121 int active, void *data)
1124 if (!obd->obd_set_up) {
1125 CERROR("obd %s not set up\n", obd->obd_name);
1129 if (!OBP(obd, notify)) {
1130 CERROR("obd %s has no notify handler\n", obd->obd_name);
1134 OBD_COUNTER_INCREMENT(obd, notify);
1135 return OBP(obd, notify)(obd, watched, active, data);
1138 static inline int obd_register_observer(struct obd_device *obd,
1139 struct obd_device *observer)
1143 if (obd->obd_observer && observer)
1145 obd->obd_observer = observer;
1149 static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
1153 LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
1154 OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1155 rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
1159 static inline int md_getstatus(struct obd_export *exp, struct lustre_id *id)
1163 EXP_CHECK_MD_OP(exp, getstatus);
1164 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1165 rc = MDP(exp->exp_obd, getstatus)(exp, id);
1169 static inline int md_delete_inode(struct obd_export *exp,
1170 struct lustre_id *id)
1175 if (MDP(exp->exp_obd, delete_inode) == NULL)
1178 MD_COUNTER_INCREMENT(exp->exp_obd, delete_inode);
1179 rc = MDP(exp->exp_obd, delete_inode)(exp, id);
1183 static inline int md_getattr(struct obd_export *exp, struct lustre_id *id,
1184 __u64 valid, const char *xattr_name,
1185 const void *xattr_data, unsigned int xattr_datalen,
1186 unsigned int ea_size, struct obd_capa *ocapa,
1187 struct ptlrpc_request **request)
1191 EXP_CHECK_MD_OP(exp, getattr);
1192 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1193 rc = MDP(exp->exp_obd, getattr)(exp, id, valid, xattr_name,
1194 xattr_data, xattr_datalen,
1195 ea_size, ocapa, request);
1199 static inline int md_access_check(struct obd_export *exp, struct lustre_id *id,
1200 struct ptlrpc_request **request)
1204 EXP_CHECK_MD_OP(exp, access_check);
1205 MD_COUNTER_INCREMENT(exp->exp_obd, access_check);
1206 rc = MDP(exp->exp_obd, access_check)(exp, id, request);
1210 static inline int md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
1211 ldlm_iterator_t it, void *data)
1215 EXP_CHECK_MD_OP(exp, change_cbdata);
1216 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1217 rc = MDP(exp->exp_obd, change_cbdata)(exp, id, it, data);
1221 static inline int md_change_cbdata_name(struct obd_export *exp,
1222 struct lustre_id *id, char *name,
1223 int namelen, struct lustre_id *id2,
1224 ldlm_iterator_t it, void *data)
1228 /* this seem to be needed only for lmv. */
1229 if (!MDP(exp->exp_obd, change_cbdata_name))
1234 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
1235 rc = MDP(exp->exp_obd, change_cbdata_name)(exp, id, name, namelen,
1240 static inline int md_close(struct obd_export *exp,
1241 struct mdc_op_data *op_data,
1242 struct obd_client_handle *och,
1243 struct ptlrpc_request **request)
1247 EXP_CHECK_MD_OP(exp, close);
1248 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1249 rc = MDP(exp->exp_obd, close)(exp, op_data, och, request);
1253 static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1254 const void *data, int datalen, int mode,
1255 __u32 uid, __u32 gid, __u64 rdev,
1256 struct ptlrpc_request **request)
1260 EXP_CHECK_MD_OP(exp, create);
1261 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1262 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1263 uid, gid, rdev, request);
1267 static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
1271 EXP_CHECK_MD_OP(exp, done_writing);
1272 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1273 rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
1277 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1278 struct lookup_intent *it, int lock_mode,
1279 struct mdc_op_data *data,
1280 struct lustre_handle *lockh,
1281 void *lmm, int lmmsize,
1282 ldlm_completion_callback cb_completion,
1283 ldlm_blocking_callback cb_blocking,
1288 EXP_CHECK_MD_OP(exp, enqueue);
1289 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1290 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1291 data, lockh, lmm, lmmsize,
1292 cb_completion, cb_blocking,
1297 static inline int md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
1298 char *filename, int namelen,
1299 __u64 valid, unsigned int ea_size,
1300 struct ptlrpc_request **request)
1304 EXP_CHECK_MD_OP(exp, getattr_lock);
1305 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_lock);
1306 rc = MDP(exp->exp_obd, getattr_lock)(exp, id, filename, namelen,
1307 valid, ea_size, request);
1311 static inline int md_intent_lock(struct obd_export *exp,
1312 struct lustre_id *pid, const char *name,
1313 int len, void *lmm, int lmmsize,
1314 struct lustre_id *cid,
1315 struct lookup_intent *it,
1316 int flags, struct ptlrpc_request **reqp,
1317 ldlm_blocking_callback cb_blocking)
1321 EXP_CHECK_MD_OP(exp, intent_lock);
1322 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1323 rc = MDP(exp->exp_obd, intent_lock)(exp, pid, name, len, lmm,
1324 lmmsize, cid, it, flags,
1329 static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
1330 struct ptlrpc_request **request)
1334 EXP_CHECK_MD_OP(exp, link);
1335 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1336 rc = MDP(exp->exp_obd, link)(exp, data, request);
1340 static inline int md_rename(struct obd_export *exp, struct mdc_op_data *data,
1341 const char *old, int oldlen,
1342 const char *new, int newlen,
1343 struct ptlrpc_request **request)
1347 EXP_CHECK_MD_OP(exp, rename);
1348 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1349 rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
1354 static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1355 struct iattr *iattr, void *ea, int ealen,
1356 void *ea2, int ea2len, void *ea3, int ea3len,
1357 struct ptlrpc_request **request)
1361 EXP_CHECK_MD_OP(exp, setattr);
1362 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1363 rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
1364 ea2, ea2len, ea3, ea3len, request);
1368 static inline int md_sync(struct obd_export *exp, struct lustre_id *id,
1369 struct ptlrpc_request **request)
1373 EXP_CHECK_MD_OP(exp, sync);
1374 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1375 rc = MDP(exp->exp_obd, sync)(exp, id, request);
1379 static inline int md_readpage(struct obd_export *exp, struct lustre_id *id,
1380 __u64 offset, struct page *page,
1381 struct ptlrpc_request **request)
1385 EXP_CHECK_MD_OP(exp, readpage);
1386 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1387 rc = MDP(exp->exp_obd, readpage)(exp, id, offset, page, request);
1391 static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1392 struct ptlrpc_request **request)
1396 EXP_CHECK_MD_OP(exp, unlink);
1397 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1398 rc = MDP(exp->exp_obd, unlink)(exp, data, request);
1402 static inline struct obd_device *md_get_real_obd(struct obd_export *exp,
1403 struct lustre_id *fid)
1406 if (MDP(exp->exp_obd, get_real_obd) == NULL)
1407 return exp->exp_obd;
1408 MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
1409 return MDP(exp->exp_obd, get_real_obd)(exp, fid);
1412 static inline int md_valid_attrs(struct obd_export *exp,
1413 struct lustre_id *id)
1416 EXP_CHECK_MD_OP(exp, valid_attrs);
1417 MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
1418 return MDP(exp->exp_obd, valid_attrs)(exp, id);
1421 static inline int md_req2lustre_md(struct obd_export *exp,
1422 struct ptlrpc_request *req,
1423 unsigned int offset,
1424 struct obd_export *osc_exp,
1425 struct lustre_md *md)
1428 EXP_CHECK_MD_OP(exp, req2lustre_md);
1429 MD_COUNTER_INCREMENT(exp->exp_obd, req2lustre_md);
1430 return MDP(exp->exp_obd, req2lustre_md)(exp, req, offset, osc_exp, md);
1433 static inline int md_set_open_replay_data(struct obd_export *exp,
1434 struct obd_client_handle *och,
1435 struct ptlrpc_request *open_req)
1438 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1439 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1440 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req);
1443 static inline int md_clear_open_replay_data(struct obd_export *exp,
1444 struct obd_client_handle *och)
1447 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1448 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1449 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1452 static inline int md_store_inode_generation(struct obd_export *exp,
1453 struct ptlrpc_request *req,
1454 int reqoff, int repoff)
1457 EXP_CHECK_MD_OP(exp, store_inode_generation);
1458 MD_COUNTER_INCREMENT(exp->exp_obd, store_inode_generation);
1459 return MDP(exp->exp_obd, store_inode_generation)(exp, req,
1463 static inline int md_set_lock_data(struct obd_export *exp, __u64 *l,
1467 EXP_CHECK_MD_OP(exp, set_lock_data);
1468 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1469 return MDP(exp->exp_obd, set_lock_data)(exp, l, data);
1472 /* OBD Metadata Support */
1474 extern int obd_init_caches(void);
1475 extern void obd_cleanup_caches(void);
1477 /* support routines */
1478 extern kmem_cache_t *obdo_cachep;
1479 static inline struct obdo *obdo_alloc(void)
1483 OBD_SLAB_ALLOC(oa, obdo_cachep, GFP_KERNEL,
1488 static inline void obdo_free(struct obdo *oa)
1490 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1493 static inline void obdo2id(struct lustre_id *id,
1497 id_ino(id) = oa->o_id;
1498 id_fid(id) = oa->o_fid;
1499 id_group(id) = oa->o_mds;
1500 id_gen(id) = oa->o_generation;
1503 static inline void id2obdo(struct obdo *oa,
1504 struct lustre_id *id)
1507 oa->o_id = id_ino(id);
1508 oa->o_fid = id_fid(id);
1509 oa->o_mds = id_group(id);
1510 oa->o_generation = id_gen(id);
1513 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1514 #define to_kdev_t(dev) dev
1515 #define kdev_t_to_nr(dev) dev
1518 /* I'm as embarrassed about this as you are.
1520 * <shaver> // XXX do not look into _superhack with remaining eye
1521 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1522 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1523 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1526 extern void obd_sysctl_init (void);
1527 extern void obd_sysctl_clean (void);
1530 typedef __u8 class_uuid_t[16];
1531 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1532 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1535 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1536 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1537 int class_del_uuid (char *uuid);
1538 void class_init_uuidlist(void);
1539 void class_exit_uuidlist(void);
1542 int mea_name2idx(struct mea *mea, char *name, int namelen);
1543 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1545 #endif /* __LINUX_OBD_CLASS_H */