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 <portals/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_mds.h>
47 /* OBD Device Declarations */
48 #define MAX_OBD_DEVICES 256
49 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
51 /* OBD Operations Declarations */
52 extern struct obd_device *class_conn2obd(struct lustre_handle *);
53 extern struct obd_device *class_exp2obd(struct obd_export *);
56 struct obd_export *class_conn2export(struct lustre_handle *);
57 int class_register_type(struct obd_ops *ops, struct md_ops *md_ops,
58 struct lprocfs_vars *, char *nm);
59 int class_unregister_type(char *nm);
61 struct obd_device *class_newdev(int *dev);
63 int class_name2dev(char *name);
64 struct obd_device *class_name2obd(char *name);
65 int class_uuid2dev(struct obd_uuid *uuid);
66 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
67 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
69 struct obd_uuid *grp_uuid);
70 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
73 int oig_init(struct obd_io_group **oig);
74 void oig_add_one(struct obd_io_group *oig,
75 struct oig_callback_context *occ);
76 void oig_complete_one(struct obd_io_group *oig,
77 struct oig_callback_context *occ, int rc);
78 void oig_release(struct obd_io_group *oig);
79 int oig_wait(struct obd_io_group *oig);
82 int class_process_config(struct lustre_cfg *lcfg);
83 int class_attach(struct lustre_cfg *lcfg);
84 int class_setup(struct obd_device *obd, struct lustre_cfg *lcfg);
85 int class_cleanup(struct obd_device *obd, struct lustre_cfg *lcfg);
86 int class_detach(struct obd_device *obd, struct lustre_cfg *lcfg);
88 /* Passed as data param to class_config_parse_llog */
89 struct config_llog_instance {
91 struct obd_uuid cfg_uuid;
92 ptl_nid_t cfg_local_nid;
94 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
95 struct config_llog_instance *cfg);
96 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
97 struct config_llog_instance *cfg);
99 struct lustre_profile {
100 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_get(exp) \
111 struct obd_export *exp_ = exp; \
112 atomic_inc(&exp_->exp_refcount); \
113 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
114 atomic_read(&exp_->exp_refcount)); \
118 #define class_export_put(exp) \
120 LASSERT((exp) != NULL); \
121 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
122 atomic_read(&(exp)->exp_refcount) - 1); \
123 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
124 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
125 __class_export_put(exp); \
127 void __class_export_put(struct obd_export *);
128 struct obd_export *class_new_export(struct obd_device *obddev);
129 void class_unlink_export(struct obd_export *exp);
131 struct obd_import *class_import_get(struct obd_import *);
132 void class_import_put(struct obd_import *);
133 struct obd_import *class_new_import(void);
134 void class_destroy_import(struct obd_import *exp);
136 struct obd_type *class_get_type(char *name);
137 void class_put_type(struct obd_type *type);
138 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
139 struct obd_uuid *cluuid);
140 int class_disconnect(struct obd_export *exp, int failover);
141 void class_disconnect_exports(struct obd_device *obddev, int failover);
142 /* generic operations shared by various OBD types */
143 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
144 int class_multi_cleanup(struct obd_device *obddev);
148 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
149 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
150 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
151 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
152 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
154 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
155 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
156 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
158 static inline int obd_check_conn(struct lustre_handle *conn)
160 struct obd_device *obd;
162 CERROR("NULL conn\n");
166 obd = class_conn2obd(conn);
168 CERROR("NULL obd\n");
172 if (!obd->obd_attached) {
173 CERROR("obd %d not attached\n", obd->obd_minor);
177 if (!obd->obd_set_up) {
178 CERROR("obd %d not setup\n", obd->obd_minor);
182 if (!obd->obd_type) {
183 CERROR("obd %d not typed\n", obd->obd_minor);
187 if (!obd->obd_type->typ_ops) {
188 CERROR("obd_check_conn: obd %d no operations\n",
196 #define OBT(dev) (dev)->obd_type
197 #define OBP(dev, op) (dev)->obd_type->typ_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 disconnect which might be called while
202 an obd is stopping. */
203 #define OBD_CHECK_SETUP(conn, exp) \
206 CERROR("NULL connection\n"); \
210 exp = class_conn2export(conn); \
212 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
216 if (!(exp)->exp_obd->obd_set_up) { \
217 CERROR("Device %d not setup\n", \
218 (exp)->exp_obd->obd_minor); \
219 class_export_put(exp); \
224 /* Ensure obd_setup and !obd_stopping. */
225 #define OBD_CHECK_ACTIVE(conn, exp) \
228 CERROR("NULL connection\n"); \
232 exp = class_conn2export(conn); \
234 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
238 if (!(exp)->exp_obd->obd_set_up || (exp)->exp_obd->obd_stopping) { \
239 CERROR("Device %d not setup\n", \
240 (exp)->exp_obd->obd_minor); \
241 class_export_put(exp); \
246 /* Ensure obd_setup: used for cleanup which must be called
247 while obd is stopping */
248 #define OBD_CHECK_DEV_STOPPING(obd) \
251 CERROR("NULL device\n"); \
255 if (!(obd)->obd_set_up) { \
256 CERROR("Device %d not setup\n", \
261 if (!(obd)->obd_stopping) { \
262 CERROR("Device %d not stopping\n", \
268 /* ensure obd_setup and !obd_stopping */
269 #define OBD_CHECK_DEV_ACTIVE(obd) \
272 CERROR("NULL device\n"); \
276 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
277 CERROR("Device %d not setup\n", \
285 #define OBD_COUNTER_OFFSET(op) \
286 ((offsetof(struct obd_ops, o_ ## op) - \
287 offsetof(struct obd_ops, o_iocontrol)) \
288 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
290 #define OBD_COUNTER_INCREMENT(obd, op) \
291 if ((obd)->obd_stats != NULL) { \
292 unsigned int coffset; \
293 coffset = (unsigned int)(obd)->obd_cntr_base + \
294 OBD_COUNTER_OFFSET(op); \
295 LASSERT(coffset < obd->obd_stats->ls_num); \
296 lprocfs_counter_incr(obd->obd_stats, coffset); \
298 /* FIXME: real accounting here */
299 #define MD_COUNTER_INCREMENT(obd, op)
301 #define OBD_COUNTER_OFFSET(op)
302 #define OBD_COUNTER_INCREMENT(obd, op)
303 #define MD_COUNTER_INCREMENT(obd, op)
306 #define OBD_CHECK_MD_OP(obd, op, err) \
308 if (!OBT(obd) || !MDP((obd), op)) {\
310 CERROR("obd_md" #op ": dev %d no operation\n", \
316 #define EXP_CHECK_MD_OP(exp, op) \
318 if ((exp) == NULL) { \
319 CERROR("obd_" #op ": NULL export\n"); \
322 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
323 CERROR("obd_" #op ": cleaned up obd\n"); \
324 RETURN(-EOPNOTSUPP); \
326 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
327 CERROR("obd_" #op ": dev %d no operation\n", \
328 (exp)->exp_obd->obd_minor); \
329 RETURN(-EOPNOTSUPP); \
333 #define OBD_CHECK_OP(obd, op, err) \
335 if (!OBT(obd) || !OBP((obd), op)) {\
337 CERROR("obd_" #op ": dev %d no operation\n", \
343 #define EXP_CHECK_OP(exp, op) \
345 if ((exp) == NULL) { \
346 CERROR("obd_" #op ": NULL export\n"); \
349 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
350 CERROR("obd_" #op ": cleaned up obd\n"); \
351 RETURN(-EOPNOTSUPP); \
353 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
354 CERROR("obd_" #op ": dev %d no operation\n", \
355 (exp)->exp_obd->obd_minor); \
356 RETURN(-EOPNOTSUPP); \
360 #define CTXT_CHECK_OP(ctxt, op, err) \
362 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
364 CERROR("lop_" #op ": dev %d no operation\n", \
365 ctxt->loc_obd->obd_minor); \
370 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
371 void *key, __u32 *vallen, void *val)
376 EXP_CHECK_OP(exp, get_info);
377 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
379 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
383 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
384 void *key, obd_count vallen, void *val)
389 EXP_CHECK_OP(exp, set_info);
390 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
392 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
396 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
401 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
402 OBD_COUNTER_INCREMENT(obd, setup);
404 rc = OBP(obd, setup)(obd, datalen, data);
408 static inline int obd_precleanup(struct obd_device *obd, int flags)
413 OBD_CHECK_OP(obd, precleanup, 0);
414 OBD_COUNTER_INCREMENT(obd, precleanup);
416 rc = OBP(obd, precleanup)(obd, flags);
420 static inline int obd_cleanup(struct obd_device *obd, int flags)
425 OBD_CHECK_DEV_STOPPING(obd);
426 OBD_CHECK_OP(obd, cleanup, 0);
427 OBD_COUNTER_INCREMENT(obd, cleanup);
429 rc = OBP(obd, cleanup)(obd, flags);
433 /* Pack an in-memory MD struct for storage on disk.
434 * Returns +ve size of packed MD (0 for free), or -ve error.
436 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
437 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
438 * If @*disk_tgt == NULL, it will be allocated
440 static inline int obd_packmd(struct obd_export *exp,
441 struct lov_mds_md **disk_tgt,
442 struct lov_stripe_md *mem_src)
447 EXP_CHECK_OP(exp, packmd);
448 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
450 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
454 static inline int obd_size_diskmd(struct obd_export *exp,
455 struct lov_stripe_md *mem_src)
457 return obd_packmd(exp, NULL, mem_src);
460 /* helper functions */
461 static inline int obd_alloc_diskmd(struct obd_export *exp,
462 struct lov_mds_md **disk_tgt)
465 LASSERT(*disk_tgt == NULL);
466 return obd_packmd(exp, disk_tgt, NULL);
469 static inline int obd_free_diskmd(struct obd_export *exp,
470 struct lov_mds_md **disk_tgt)
474 return obd_packmd(exp, disk_tgt, NULL);
477 /* Unpack an MD struct from disk to in-memory format.
478 * Returns +ve size of unpacked MD (0 for free), or -ve error.
480 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
481 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
482 * If @*mem_tgt == NULL, it will be allocated
484 static inline int obd_unpackmd(struct obd_export *exp,
485 struct lov_stripe_md **mem_tgt,
486 struct lov_mds_md *disk_src,
492 EXP_CHECK_OP(exp, unpackmd);
493 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
495 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
499 /* helper functions */
500 static inline int obd_alloc_memmd(struct obd_export *exp,
501 struct lov_stripe_md **mem_tgt)
504 LASSERT(*mem_tgt == NULL);
505 return obd_unpackmd(exp, mem_tgt, NULL, 0);
508 static inline int obd_free_memmd(struct obd_export *exp,
509 struct lov_stripe_md **mem_tgt)
513 return obd_unpackmd(exp, mem_tgt, NULL, 0);
516 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
517 struct lov_stripe_md **ea,
518 struct obd_trans_info *oti)
523 EXP_CHECK_OP(exp, create);
524 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
526 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
530 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
531 struct lov_stripe_md *ea,
532 struct obd_trans_info *oti)
537 EXP_CHECK_OP(exp, destroy);
538 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
540 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
544 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
545 struct lov_stripe_md *ea)
550 EXP_CHECK_OP(exp, getattr);
551 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
553 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
557 static inline int obd_getattr_async(struct obd_export *exp,
558 struct obdo *obdo, struct lov_stripe_md *ea,
559 struct ptlrpc_request_set *set)
564 EXP_CHECK_OP(exp, getattr);
565 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
567 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
571 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
572 struct lov_stripe_md *ea,
573 struct obd_trans_info *oti)
578 EXP_CHECK_OP(exp, setattr);
579 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
581 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
585 static inline int obd_connect(struct lustre_handle *conn,
586 struct obd_device *obd, struct obd_uuid *cluuid)
591 OBD_CHECK_DEV_ACTIVE(obd);
592 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
593 OBD_COUNTER_INCREMENT(obd, connect);
595 rc = OBP(obd, connect)(conn, obd, cluuid);
599 static inline int obd_disconnect(struct obd_export *exp, int flags)
604 EXP_CHECK_OP(exp, disconnect);
605 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
607 rc = OBP(exp->exp_obd, disconnect)(exp, flags);
611 static inline int obd_init_export(struct obd_export *exp)
616 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
617 OBP((exp)->exp_obd, init_export))
618 rc = OBP(exp->exp_obd, init_export)(exp);
622 static inline int obd_destroy_export(struct obd_export *exp)
625 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
626 OBP((exp)->exp_obd, destroy_export))
627 OBP(exp->exp_obd, destroy_export)(exp);
631 static inline struct dentry *
632 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
634 LASSERT(exp->exp_obd);
636 return lvfs_fid2dentry(&exp->exp_obd->obd_ctxt, id_ino, gen, gr,
641 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
644 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
645 unsigned long max_age)
653 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
654 OBD_COUNTER_INCREMENT(obd, statfs);
656 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
657 if (time_before(obd->obd_osfs_age, max_age)) {
658 rc = OBP(obd, statfs)(obd, osfs, max_age);
659 spin_lock(&obd->obd_osfs_lock);
660 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
661 obd->obd_osfs_age = jiffies;
662 spin_unlock(&obd->obd_osfs_lock);
664 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
665 spin_lock(&obd->obd_osfs_lock);
666 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
667 spin_unlock(&obd->obd_osfs_lock);
672 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
673 struct lov_stripe_md *ea, obd_size start,
679 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
680 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
682 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
686 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
687 struct lov_stripe_md *ea, obd_size start,
688 obd_size end, struct obd_trans_info *oti)
693 EXP_CHECK_OP(exp, punch);
694 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
696 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
700 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
701 struct lov_stripe_md *ea, obd_count oa_bufs,
702 struct brw_page *pg, struct obd_trans_info *oti)
707 EXP_CHECK_OP(exp, brw);
708 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
710 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
711 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
712 "or OBD_BRW_CHECK\n");
716 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
720 static inline int obd_brw_async(int cmd, struct obd_export *exp,
721 struct obdo *oa, struct lov_stripe_md *ea,
722 obd_count oa_bufs, struct brw_page *pg,
723 struct ptlrpc_request_set *set,
724 struct obd_trans_info *oti)
729 EXP_CHECK_OP(exp, brw_async);
730 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
732 if (!(cmd & OBD_BRW_RWMASK)) {
733 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
737 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
742 static inline int obd_prep_async_page(struct obd_export *exp,
743 struct lov_stripe_md *lsm,
744 struct lov_oinfo *loi,
745 struct page *page, obd_off offset,
746 struct obd_async_page_ops *ops,
747 void *data, void **res)
752 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
753 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
755 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
760 static inline int obd_queue_async_io(struct obd_export *exp,
761 struct lov_stripe_md *lsm,
762 struct lov_oinfo *loi, void *cookie,
763 int cmd, obd_off off, int count,
764 obd_flag brw_flags, obd_flag async_flags)
769 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
770 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
771 LASSERT(cmd & OBD_BRW_RWMASK);
773 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
774 count, brw_flags, async_flags);
778 static inline int obd_set_async_flags(struct obd_export *exp,
779 struct lov_stripe_md *lsm,
780 struct lov_oinfo *loi, void *cookie,
781 obd_flag async_flags)
786 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
787 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
789 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
794 static inline int obd_queue_group_io(struct obd_export *exp,
795 struct lov_stripe_md *lsm,
796 struct lov_oinfo *loi,
797 struct obd_io_group *oig,
798 void *cookie, int cmd, obd_off off,
799 int count, obd_flag brw_flags,
800 obd_flag async_flags)
805 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
806 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
807 LASSERT(cmd & OBD_BRW_RWMASK);
809 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
810 cmd, off, count, brw_flags,
815 static inline int obd_trigger_group_io(struct obd_export *exp,
816 struct lov_stripe_md *lsm,
817 struct lov_oinfo *loi,
818 struct obd_io_group *oig)
823 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
824 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
826 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
830 static inline int obd_teardown_async_page(struct obd_export *exp,
831 struct lov_stripe_md *lsm,
832 struct lov_oinfo *loi, void *cookie)
837 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
838 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
840 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
844 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
845 int objcount, struct obd_ioobj *obj,
846 int niocount, struct niobuf_remote *remote,
847 struct niobuf_local *local,
848 struct obd_trans_info *oti)
853 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
854 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
856 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
861 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
862 int objcount, struct obd_ioobj *obj,
863 int niocount, struct niobuf_local *local,
864 struct obd_trans_info *oti, int rc)
868 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
869 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
871 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
876 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
877 int len, void *karg, void *uarg)
882 EXP_CHECK_OP(exp, iocontrol);
883 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
885 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
889 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
890 __u32 type, ldlm_policy_data_t *policy,
891 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
892 void *gl_cb, void *data, __u32 lvb_len,
893 void *lvb_swabber, struct lustre_handle *lockh)
898 EXP_CHECK_OP(exp, enqueue);
899 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
901 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
902 bl_cb, cp_cb, gl_cb, data, lvb_len,
907 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
908 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
909 int *flags, void *data, struct lustre_handle *lockh)
914 EXP_CHECK_OP(exp, match);
915 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
917 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
922 static inline int obd_change_cbdata(struct obd_export *exp,
923 struct lov_stripe_md *lsm,
924 ldlm_iterator_t it, void *data)
929 EXP_CHECK_OP(exp, change_cbdata);
930 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
932 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
936 static inline int obd_cancel(struct obd_export *exp,
937 struct lov_stripe_md *ea, __u32 mode,
938 struct lustre_handle *lockh)
943 EXP_CHECK_OP(exp, cancel);
944 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
946 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
950 static inline int obd_cancel_unused(struct obd_export *exp,
951 struct lov_stripe_md *ea, int flags,
957 EXP_CHECK_OP(exp, cancel_unused);
958 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
960 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
965 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
967 int objcount, struct obd_ioobj *obj,
968 int niocount, struct niobuf_remote *remote)
972 EXP_CHECK_OP(exp, preprw);
973 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
975 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
977 class_export_put(exp);
981 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
982 int type, struct obd_client_handle *handle, int flag)
986 EXP_CHECK_OP(exp, pin);
987 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
989 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
993 static inline int obd_unpin(struct obd_export *exp,
994 struct obd_client_handle *handle, int flag)
998 EXP_CHECK_OP(exp, unpin);
999 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1001 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1006 static inline void obd_import_event(struct obd_device *obd,
1007 struct obd_import *imp,
1008 enum obd_import_event event)
1010 if (obd->obd_set_up && OBP(obd, import_event)) {
1011 OBD_COUNTER_INCREMENT(obd, import_event);
1012 OBP(obd, import_event)(obd, imp, event);
1016 static inline int obd_llog_connect(struct obd_device *obd,
1017 struct llogd_conn_body *body)
1020 if (!obd->obd_set_up) {
1021 CERROR("obd %s not set up\n", obd->obd_name);
1025 if (!OBP(obd, llog_connect)) {
1026 CERROR("obd %s has no llog_connect handler\n", obd->obd_name);
1030 return OBP(obd, llog_connect)(obd, body);
1033 static inline int obd_notify(struct obd_device *obd,
1034 struct obd_device *watched,
1037 if (!obd->obd_set_up) {
1038 CERROR("obd %s not set up\n", obd->obd_name);
1042 if (!OBP(obd, notify)) {
1043 CERROR("obd %s has no notify handler\n", obd->obd_name);
1047 OBD_COUNTER_INCREMENT(obd, notify);
1048 return OBP(obd, notify)(obd, watched, active);
1051 static inline int obd_register_observer(struct obd_device *obd,
1052 struct obd_device *observer)
1055 if (obd->obd_observer && observer)
1057 obd->obd_observer = observer;
1061 static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
1065 LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
1066 OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1067 rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
1071 static inline int md_getstatus(struct obd_export *exp, struct ll_fid *fid)
1075 EXP_CHECK_MD_OP(exp, getstatus);
1076 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1077 rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1081 static inline int md_getattr(struct obd_export *exp, struct ll_fid *fid,
1082 unsigned long valid, unsigned int ea_size,
1083 struct ptlrpc_request **request)
1086 EXP_CHECK_MD_OP(exp, getattr);
1087 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1088 rc = MDP(exp->exp_obd, getattr)(exp, fid, valid, ea_size, request);
1092 static inline int md_change_cbdata(struct obd_export *exp, struct ll_fid *fid,
1093 ldlm_iterator_t it, void *data)
1097 EXP_CHECK_MD_OP(exp, change_cbdata);
1098 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1099 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1103 static inline int md_change_cbdata_name(struct obd_export *exp,
1104 struct ll_fid *fid, char *name,
1105 int namelen, struct ll_fid *fid2,
1106 ldlm_iterator_t it, void *data)
1110 EXP_CHECK_MD_OP(exp, change_cbdata_name);
1111 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
1112 rc = MDP(exp->exp_obd, change_cbdata_name)(exp, fid, name, namelen,
1117 static inline int md_close(struct obd_export *exp, struct obdo *obdo,
1118 struct obd_client_handle *och,
1119 struct ptlrpc_request **request)
1123 EXP_CHECK_MD_OP(exp, close);
1124 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1125 rc = MDP(exp->exp_obd, close)(exp, obdo, och, request);
1129 static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1130 const void *data, int datalen, int mode,
1131 __u32 uid, __u32 gid, __u64 rdev,
1132 struct ptlrpc_request **request)
1136 EXP_CHECK_MD_OP(exp, create);
1137 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1138 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1139 uid, gid, rdev, request);
1143 static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
1147 EXP_CHECK_MD_OP(exp, done_writing);
1148 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1149 rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
1153 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1154 struct lookup_intent *it, int lock_mode,
1155 struct mdc_op_data *data,
1156 struct lustre_handle *lockh,
1157 void *lmm, int lmmsize,
1158 ldlm_completion_callback cb_completion,
1159 ldlm_blocking_callback cb_blocking,
1164 EXP_CHECK_MD_OP(exp, enqueue);
1165 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1166 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1167 data, lockh, lmm, lmmsize,
1168 cb_completion, cb_blocking,
1173 static inline int md_getattr_name(struct obd_export *exp, struct ll_fid *fid,
1174 char *filename, int namelen,
1175 unsigned long valid, unsigned int ea_size,
1176 struct ptlrpc_request **request)
1180 EXP_CHECK_MD_OP(exp, getattr_name);
1181 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1182 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1183 valid, ea_size, request);
1187 static inline int md_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
1188 struct ll_fid *pfid, const char *name,
1189 int len, void *lmm, int lmmsize,
1190 struct ll_fid *cfid, struct lookup_intent *it,
1191 int flags, struct ptlrpc_request **reqp,
1192 ldlm_blocking_callback cb_blocking)
1196 EXP_CHECK_MD_OP(exp, intent_lock);
1197 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1198 rc = MDP(exp->exp_obd, intent_lock)(exp, uctxt, pfid, name, len,
1199 lmm, lmmsize, cfid, it, flags,
1204 static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
1205 struct ptlrpc_request **request)
1209 EXP_CHECK_MD_OP(exp, link);
1210 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1211 rc = MDP(exp->exp_obd, link)(exp, data, request);
1215 static inline int md_rename(struct obd_export *exp,
1216 struct mdc_op_data *data,
1217 const char *old, int oldlen,
1218 const char *new, int newlen,
1219 struct ptlrpc_request **request)
1223 EXP_CHECK_MD_OP(exp, rename);
1224 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1225 rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
1230 static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1231 struct iattr *iattr, void *ea, int ealen,
1232 void *ea2, int ea2len,
1233 struct ptlrpc_request **request)
1237 EXP_CHECK_MD_OP(exp, setattr);
1238 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1239 rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
1240 ea2, ea2len, request);
1244 static inline int md_sync(struct obd_export *exp, struct ll_fid *fid,
1245 struct ptlrpc_request **request)
1249 EXP_CHECK_MD_OP(exp, sync);
1250 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1251 rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1255 static inline int md_readpage(struct obd_export *exp, struct ll_fid *fid,
1256 __u64 offset, struct page *page,
1257 struct ptlrpc_request **request)
1261 EXP_CHECK_MD_OP(exp, readpage);
1262 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1263 rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1267 static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1268 struct ptlrpc_request **request)
1272 EXP_CHECK_MD_OP(exp, unlink);
1273 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1274 rc = MDP(exp->exp_obd, unlink)(exp, data, request);
1278 static inline struct obd_device * md_get_real_obd(struct obd_export *exp,
1279 char *name, int len)
1282 if (MDP(exp->exp_obd, get_real_obd) == NULL)
1283 return exp->exp_obd;
1284 MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
1285 return MDP(exp->exp_obd, get_real_obd)(exp, name, len);
1288 static inline int md_valid_attrs(struct obd_export *exp, struct ll_fid *fid)
1291 EXP_CHECK_MD_OP(exp, valid_attrs);
1292 MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
1293 return MDP(exp->exp_obd, valid_attrs)(exp, fid);
1296 /* OBD Metadata Support */
1298 extern int obd_init_caches(void);
1299 extern void obd_cleanup_caches(void);
1301 /* support routines */
1302 extern kmem_cache_t *obdo_cachep;
1303 static inline struct obdo *obdo_alloc(void)
1307 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
1310 CDEBUG(D_MALLOC, "kmem_cache_alloced oa at %p\n", oa);
1311 memset(oa, 0, sizeof (*oa));
1316 static inline void obdo_free(struct obdo *oa)
1320 CDEBUG(D_MALLOC, "kmem_cache_freed oa at %p\n", oa);
1321 kmem_cache_free(obdo_cachep, oa);
1324 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1325 #define to_kdev_t(dev) dev
1326 #define kdev_t_to_nr(dev) dev
1329 /* I'm as embarrassed about this as you are.
1331 * <shaver> // XXX do not look into _superhack with remaining eye
1332 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1333 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1334 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1337 extern void obd_sysctl_init (void);
1338 extern void obd_sysctl_clean (void);
1341 typedef __u8 class_uuid_t[16];
1342 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1343 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1346 int lustre_uuid_to_peer(char *uuid, ptl_handle_ni_t *peer_ni, ptl_nid_t *peer_nid);
1347 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1348 int class_del_uuid (char *uuid);
1349 void class_init_uuidlist(void);
1350 void class_exit_uuidlist(void);
1353 int mea_name2idx(struct mea *mea, char *name, int namelen);
1355 #endif /* __LINUX_OBD_CLASS_H */