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_lvfs_ctxt, id_ino, gen, gr,
641 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
644 /* @max_age is the oldest time in jiffies that we accept using a cached data.
645 * If the cache is older than @max_age we will get a new value from the
646 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
647 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
648 unsigned long max_age)
656 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
657 OBD_COUNTER_INCREMENT(obd, statfs);
659 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
660 if (time_before(obd->obd_osfs_age, max_age)) {
661 rc = OBP(obd, statfs)(obd, osfs, max_age);
663 spin_lock(&obd->obd_osfs_lock);
664 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
665 obd->obd_osfs_age = jiffies;
666 spin_unlock(&obd->obd_osfs_lock);
669 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
670 spin_lock(&obd->obd_osfs_lock);
671 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
672 spin_unlock(&obd->obd_osfs_lock);
677 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
678 struct lov_stripe_md *ea, obd_size start,
684 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
685 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
687 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
691 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
692 struct lov_stripe_md *ea, obd_size start,
693 obd_size end, struct obd_trans_info *oti)
698 EXP_CHECK_OP(exp, punch);
699 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
701 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
705 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
706 struct lov_stripe_md *ea, obd_count oa_bufs,
707 struct brw_page *pg, struct obd_trans_info *oti)
712 EXP_CHECK_OP(exp, brw);
713 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
715 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
716 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
717 "or OBD_BRW_CHECK\n");
721 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
725 static inline int obd_brw_async(int cmd, struct obd_export *exp,
726 struct obdo *oa, struct lov_stripe_md *ea,
727 obd_count oa_bufs, struct brw_page *pg,
728 struct ptlrpc_request_set *set,
729 struct obd_trans_info *oti)
734 EXP_CHECK_OP(exp, brw_async);
735 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
737 if (!(cmd & OBD_BRW_RWMASK)) {
738 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
742 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
747 static inline int obd_prep_async_page(struct obd_export *exp,
748 struct lov_stripe_md *lsm,
749 struct lov_oinfo *loi,
750 struct page *page, obd_off offset,
751 struct obd_async_page_ops *ops,
752 void *data, void **res)
757 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
758 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
760 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
765 static inline int obd_queue_async_io(struct obd_export *exp,
766 struct lov_stripe_md *lsm,
767 struct lov_oinfo *loi, void *cookie,
768 int cmd, obd_off off, int count,
769 obd_flag brw_flags, obd_flag async_flags)
774 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
775 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
776 LASSERT(cmd & OBD_BRW_RWMASK);
778 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
779 count, brw_flags, async_flags);
783 static inline int obd_set_async_flags(struct obd_export *exp,
784 struct lov_stripe_md *lsm,
785 struct lov_oinfo *loi, void *cookie,
786 obd_flag async_flags)
791 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
792 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
794 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
799 static inline int obd_queue_group_io(struct obd_export *exp,
800 struct lov_stripe_md *lsm,
801 struct lov_oinfo *loi,
802 struct obd_io_group *oig,
803 void *cookie, int cmd, obd_off off,
804 int count, obd_flag brw_flags,
805 obd_flag async_flags)
810 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
811 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
812 LASSERT(cmd & OBD_BRW_RWMASK);
814 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
815 cmd, off, count, brw_flags,
820 static inline int obd_trigger_group_io(struct obd_export *exp,
821 struct lov_stripe_md *lsm,
822 struct lov_oinfo *loi,
823 struct obd_io_group *oig)
828 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
829 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
831 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
835 static inline int obd_teardown_async_page(struct obd_export *exp,
836 struct lov_stripe_md *lsm,
837 struct lov_oinfo *loi, void *cookie)
842 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
843 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
845 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
849 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
850 int objcount, struct obd_ioobj *obj,
851 int niocount, struct niobuf_remote *remote,
852 struct niobuf_local *local,
853 struct obd_trans_info *oti)
858 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
859 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
861 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
866 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
867 int objcount, struct obd_ioobj *obj,
868 int niocount, struct niobuf_local *local,
869 struct obd_trans_info *oti, int rc)
873 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
874 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
876 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
881 static inline int obd_write_extents(struct obd_export *exp, struct obd_ioobj *obj,
882 int niocount, struct niobuf_local *local, int rc)
886 /* there are cases when write_extents is not implemented. */
887 if (!OBP(exp->exp_obd, write_extents))
890 OBD_COUNTER_INCREMENT(exp->exp_obd, write_extents);
892 rc = OBP(exp->exp_obd, write_extents)(exp, obj, niocount, local, rc);
896 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
897 int len, void *karg, void *uarg)
902 EXP_CHECK_OP(exp, iocontrol);
903 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
905 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
909 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
910 __u32 type, ldlm_policy_data_t *policy,
911 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
912 void *gl_cb, void *data, __u32 lvb_len,
913 void *lvb_swabber, struct lustre_handle *lockh)
918 EXP_CHECK_OP(exp, enqueue);
919 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
921 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
922 bl_cb, cp_cb, gl_cb, data, lvb_len,
927 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
928 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
929 int *flags, void *data, struct lustre_handle *lockh)
934 EXP_CHECK_OP(exp, match);
935 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
937 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
942 static inline int obd_change_cbdata(struct obd_export *exp,
943 struct lov_stripe_md *lsm,
944 ldlm_iterator_t it, void *data)
949 EXP_CHECK_OP(exp, change_cbdata);
950 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
952 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
956 static inline int obd_cancel(struct obd_export *exp,
957 struct lov_stripe_md *ea, __u32 mode,
958 struct lustre_handle *lockh)
963 EXP_CHECK_OP(exp, cancel);
964 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
966 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
970 static inline int obd_cancel_unused(struct obd_export *exp,
971 struct lov_stripe_md *ea, int flags,
977 EXP_CHECK_OP(exp, cancel_unused);
978 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
980 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
985 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
987 int objcount, struct obd_ioobj *obj,
988 int niocount, struct niobuf_remote *remote)
992 EXP_CHECK_OP(exp, preprw);
993 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
995 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
997 class_export_put(exp);
1001 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1002 int type, struct obd_client_handle *handle, int flag)
1006 EXP_CHECK_OP(exp, pin);
1007 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1009 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1013 static inline int obd_unpin(struct obd_export *exp,
1014 struct obd_client_handle *handle, int flag)
1018 EXP_CHECK_OP(exp, unpin);
1019 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1021 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1026 static inline void obd_import_event(struct obd_device *obd,
1027 struct obd_import *imp,
1028 enum obd_import_event event)
1030 if (obd->obd_set_up && OBP(obd, import_event)) {
1031 OBD_COUNTER_INCREMENT(obd, import_event);
1032 OBP(obd, import_event)(obd, imp, event);
1036 static inline int obd_llog_connect(struct obd_device *obd,
1037 struct llogd_conn_body *body)
1040 if (!obd->obd_set_up) {
1041 CERROR("obd %s not set up\n", obd->obd_name);
1045 if (!OBP(obd, llog_connect)) {
1046 CERROR("obd %s has no llog_connect handler\n", obd->obd_name);
1050 return OBP(obd, llog_connect)(obd, body);
1053 static inline int obd_notify(struct obd_device *obd,
1054 struct obd_device *watched,
1057 if (!obd->obd_set_up) {
1058 CERROR("obd %s not set up\n", obd->obd_name);
1062 if (!OBP(obd, notify)) {
1063 CERROR("obd %s has no notify handler\n", obd->obd_name);
1067 OBD_COUNTER_INCREMENT(obd, notify);
1068 return OBP(obd, notify)(obd, watched, active);
1071 static inline int obd_register_observer(struct obd_device *obd,
1072 struct obd_device *observer)
1075 if (obd->obd_observer && observer)
1077 obd->obd_observer = observer;
1081 static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
1085 LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
1086 OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1087 rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
1091 static inline int md_getstatus(struct obd_export *exp, struct ll_fid *fid)
1095 EXP_CHECK_MD_OP(exp, getstatus);
1096 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1097 rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1101 static inline int md_getattr(struct obd_export *exp, struct ll_fid *fid,
1102 unsigned long valid, unsigned int ea_size,
1103 struct ptlrpc_request **request)
1106 EXP_CHECK_MD_OP(exp, getattr);
1107 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1108 rc = MDP(exp->exp_obd, getattr)(exp, fid, valid, ea_size, request);
1112 static inline int md_change_cbdata(struct obd_export *exp, struct ll_fid *fid,
1113 ldlm_iterator_t it, void *data)
1117 EXP_CHECK_MD_OP(exp, change_cbdata);
1118 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1119 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1123 static inline int md_change_cbdata_name(struct obd_export *exp,
1124 struct ll_fid *fid, char *name,
1125 int namelen, struct ll_fid *fid2,
1126 ldlm_iterator_t it, void *data)
1130 /* this seem to be needed only for lmv. */
1131 if (!MDP(exp->exp_obd, change_cbdata_name))
1136 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
1137 rc = MDP(exp->exp_obd, change_cbdata_name)(exp, fid, name, namelen,
1142 static inline int md_close(struct obd_export *exp, struct obdo *obdo,
1143 struct obd_client_handle *och,
1144 struct ptlrpc_request **request)
1148 EXP_CHECK_MD_OP(exp, close);
1149 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1150 rc = MDP(exp->exp_obd, close)(exp, obdo, och, request);
1154 static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1155 const void *data, int datalen, int mode,
1156 __u32 uid, __u32 gid, __u64 rdev,
1157 struct ptlrpc_request **request)
1161 EXP_CHECK_MD_OP(exp, create);
1162 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1163 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1164 uid, gid, rdev, request);
1168 static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
1172 EXP_CHECK_MD_OP(exp, done_writing);
1173 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1174 rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
1178 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1179 struct lookup_intent *it, int lock_mode,
1180 struct mdc_op_data *data,
1181 struct lustre_handle *lockh,
1182 void *lmm, int lmmsize,
1183 ldlm_completion_callback cb_completion,
1184 ldlm_blocking_callback cb_blocking,
1189 EXP_CHECK_MD_OP(exp, enqueue);
1190 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1191 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1192 data, lockh, lmm, lmmsize,
1193 cb_completion, cb_blocking,
1198 static inline int md_getattr_name(struct obd_export *exp, struct ll_fid *fid,
1199 char *filename, int namelen,
1200 unsigned long valid, unsigned int ea_size,
1201 struct ptlrpc_request **request)
1205 EXP_CHECK_MD_OP(exp, getattr_name);
1206 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1207 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1208 valid, ea_size, request);
1212 static inline int md_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
1213 struct ll_fid *pfid, const char *name,
1214 int len, void *lmm, int lmmsize,
1215 struct ll_fid *cfid, struct lookup_intent *it,
1216 int flags, struct ptlrpc_request **reqp,
1217 ldlm_blocking_callback cb_blocking)
1221 EXP_CHECK_MD_OP(exp, intent_lock);
1222 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1223 rc = MDP(exp->exp_obd, intent_lock)(exp, uctxt, pfid, name, len,
1224 lmm, lmmsize, cfid, it, flags,
1229 static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
1230 struct ptlrpc_request **request)
1234 EXP_CHECK_MD_OP(exp, link);
1235 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1236 rc = MDP(exp->exp_obd, link)(exp, data, request);
1240 static inline int md_rename(struct obd_export *exp, struct mdc_op_data *data,
1241 const char *old, int oldlen,
1242 const char *new, int newlen,
1243 struct ptlrpc_request **request)
1247 EXP_CHECK_MD_OP(exp, rename);
1248 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1249 rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
1254 static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1255 struct iattr *iattr, void *ea, int ealen,
1256 void *ea2, int ea2len,
1257 struct ptlrpc_request **request)
1261 EXP_CHECK_MD_OP(exp, setattr);
1262 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1263 rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
1264 ea2, ea2len, request);
1268 static inline int md_sync(struct obd_export *exp, struct ll_fid *fid,
1269 struct ptlrpc_request **request)
1273 EXP_CHECK_MD_OP(exp, sync);
1274 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1275 rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1279 static inline int md_readpage(struct obd_export *exp, struct ll_fid *fid,
1280 __u64 offset, struct page *page,
1281 struct ptlrpc_request **request)
1285 EXP_CHECK_MD_OP(exp, readpage);
1286 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1287 rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1291 static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1292 struct ptlrpc_request **request)
1296 EXP_CHECK_MD_OP(exp, unlink);
1297 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1298 rc = MDP(exp->exp_obd, unlink)(exp, data, request);
1302 static inline struct obd_device * md_get_real_obd(struct obd_export *exp,
1303 char *name, int len)
1306 if (MDP(exp->exp_obd, get_real_obd) == NULL)
1307 return exp->exp_obd;
1308 MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
1309 return MDP(exp->exp_obd, get_real_obd)(exp, name, len);
1312 static inline int md_valid_attrs(struct obd_export *exp, struct ll_fid *fid)
1315 EXP_CHECK_MD_OP(exp, valid_attrs);
1316 MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
1317 return MDP(exp->exp_obd, valid_attrs)(exp, fid);
1320 static inline int md_req2lustre_md(struct obd_export *exp,
1321 struct ptlrpc_request *req,
1322 unsigned int offset,
1323 struct obd_export *osc_exp,
1324 struct lustre_md *md)
1327 EXP_CHECK_MD_OP(exp, req2lustre_md);
1328 MD_COUNTER_INCREMENT(exp->exp_obd, req2lustre_md);
1329 return MDP(exp->exp_obd, req2lustre_md)(exp, req, offset, osc_exp, md);
1332 static inline int md_set_open_replay_data(struct obd_export *exp,
1333 struct obd_client_handle *och,
1334 struct ptlrpc_request *open_req)
1337 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1338 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1339 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req);
1342 static inline int md_clear_open_replay_data(struct obd_export *exp,
1343 struct obd_client_handle *och)
1346 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1347 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1348 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1351 static inline int md_store_inode_generation(struct obd_export *exp,
1352 struct ptlrpc_request *req,
1353 int reqoff, int repoff)
1356 EXP_CHECK_MD_OP(exp, store_inode_generation);
1357 MD_COUNTER_INCREMENT(exp->exp_obd, store_inode_generation);
1358 return MDP(exp->exp_obd, store_inode_generation)(exp, req,
1362 static inline int md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
1365 EXP_CHECK_MD_OP(exp, set_lock_data);
1366 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1367 return MDP(exp->exp_obd, set_lock_data)(exp, l, data);
1370 /* OBD Metadata Support */
1372 extern int obd_init_caches(void);
1373 extern void obd_cleanup_caches(void);
1375 /* support routines */
1376 extern kmem_cache_t *obdo_cachep;
1377 static inline struct obdo *obdo_alloc(void)
1381 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
1384 CDEBUG(D_MALLOC, "kmem_cache_alloced oa at %p\n", oa);
1385 memset(oa, 0, sizeof (*oa));
1390 static inline void obdo_free(struct obdo *oa)
1394 CDEBUG(D_MALLOC, "kmem_cache_freed oa at %p\n", oa);
1395 kmem_cache_free(obdo_cachep, oa);
1398 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1399 #define to_kdev_t(dev) dev
1400 #define kdev_t_to_nr(dev) dev
1403 /* I'm as embarrassed about this as you are.
1405 * <shaver> // XXX do not look into _superhack with remaining eye
1406 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1407 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1408 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1411 extern void obd_sysctl_init (void);
1412 extern void obd_sysctl_clean (void);
1415 typedef __u8 class_uuid_t[16];
1416 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1417 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1420 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1421 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1422 int class_del_uuid (char *uuid);
1423 void class_init_uuidlist(void);
1424 void class_exit_uuidlist(void);
1427 int mea_name2idx(struct mea *mea, char *name, int namelen);
1428 int raw_name2idx(int count, const char *name, int namelen);
1430 #endif /* __LINUX_OBD_CLASS_H */