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_log.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);
84 /* Passed as data param to class_config_parse_handler() */
85 struct config_llog_instance {
87 struct obd_uuid cfg_uuid;
88 ptl_nid_t cfg_local_nid;
91 int class_config_process_llog(struct llog_ctxt *ctxt, char *name,
92 struct config_llog_instance *cfg);
93 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
94 struct config_llog_instance *cfg);
96 struct lustre_profile {
97 struct list_head lp_list;
103 struct lustre_profile *class_get_profile(char * prof);
104 void class_del_profile(char *prof);
106 #define class_export_rpc_get(exp) \
108 atomic_inc(&(exp)->exp_rpc_count); \
109 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
110 (exp), atomic_read(&(exp)->exp_rpc_count)); \
111 class_export_get(exp); \
114 #define class_export_rpc_put(exp) \
116 atomic_dec(&(exp)->exp_rpc_count); \
117 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
118 (exp), atomic_read(&(exp)->exp_rpc_count)); \
119 class_export_put(exp); \
122 #define class_export_get(exp) \
124 struct obd_export *exp_ = exp; \
125 atomic_inc(&exp_->exp_refcount); \
126 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
127 atomic_read(&exp_->exp_refcount)); \
131 #define class_export_put(exp) \
133 LASSERT((exp) != NULL); \
134 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
135 atomic_read(&(exp)->exp_refcount) - 1); \
136 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
137 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
138 __class_export_put(exp); \
140 void __class_export_put(struct obd_export *);
141 struct obd_export *class_new_export(struct obd_device *obddev);
142 void class_unlink_export(struct obd_export *exp);
144 struct obd_import *class_import_get(struct obd_import *);
145 void class_import_put(struct obd_import *);
146 struct obd_import *class_new_import(void);
147 void class_destroy_import(struct obd_import *exp);
149 struct obd_type *class_get_type(char *name);
150 void class_put_type(struct obd_type *type);
151 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
152 struct obd_uuid *cluuid);
153 int class_disconnect(struct obd_export *exp, int failover);
154 void class_disconnect_exports(struct obd_device *obddev, int failover);
155 /* generic operations shared by various OBD types */
156 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
157 int class_multi_cleanup(struct obd_device *obddev);
161 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
162 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
163 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
164 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
165 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
167 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
168 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
169 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
171 static inline int obd_check_conn(struct lustre_handle *conn)
173 struct obd_device *obd;
175 CERROR("NULL conn\n");
179 obd = class_conn2obd(conn);
181 CERROR("NULL obd\n");
185 if (!obd->obd_attached) {
186 CERROR("obd %d not attached\n", obd->obd_minor);
190 if (!obd->obd_set_up) {
191 CERROR("obd %d not setup\n", obd->obd_minor);
195 if (!obd->obd_type) {
196 CERROR("obd %d not typed\n", obd->obd_minor);
200 if (!obd->obd_type->typ_ops) {
201 CERROR("obd_check_conn: obd %d no operations\n",
209 #define OBT(dev) (dev)->obd_type
210 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
211 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
212 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
214 /* Ensure obd_setup: used for disconnect which might be called while
215 an obd is stopping. */
216 #define OBD_CHECK_SETUP(conn, exp) \
219 CERROR("NULL connection\n"); \
223 exp = class_conn2export(conn); \
225 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
229 if (!(exp)->exp_obd->obd_set_up) { \
230 CERROR("Device %d not setup\n", \
231 (exp)->exp_obd->obd_minor); \
232 class_export_put(exp); \
237 /* Ensure obd_setup and !obd_stopping. */
238 #define OBD_CHECK_ACTIVE(conn, exp) \
241 CERROR("NULL connection\n"); \
245 exp = class_conn2export(conn); \
247 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
251 if (!(exp)->exp_obd->obd_set_up || (exp)->exp_obd->obd_stopping) { \
252 CERROR("Device %d not setup\n", \
253 (exp)->exp_obd->obd_minor); \
254 class_export_put(exp); \
259 /* Ensure obd_setup: used for cleanup which must be called
260 while obd is stopping */
261 #define OBD_CHECK_DEV_STOPPING(obd) \
264 CERROR("NULL device\n"); \
268 if (!(obd)->obd_set_up) { \
269 CERROR("Device %d not setup\n", \
274 if (!(obd)->obd_stopping) { \
275 CERROR("Device %d not stopping\n", \
281 /* ensure obd_setup and !obd_stopping */
282 #define OBD_CHECK_DEV_ACTIVE(obd) \
285 CERROR("NULL device\n"); \
289 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
290 CERROR("Device %d not setup\n", \
298 #define OBD_COUNTER_OFFSET(op) \
299 ((offsetof(struct obd_ops, o_ ## op) - \
300 offsetof(struct obd_ops, o_iocontrol)) \
301 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
303 #define OBD_COUNTER_INCREMENT(obd, op) \
304 if ((obd)->obd_stats != NULL) { \
305 unsigned int coffset; \
306 coffset = (unsigned int)(obd)->obd_cntr_base + \
307 OBD_COUNTER_OFFSET(op); \
308 LASSERT(coffset < obd->obd_stats->ls_num); \
309 lprocfs_counter_incr(obd->obd_stats, coffset); \
311 /* FIXME: real accounting here */
312 #define MD_COUNTER_INCREMENT(obd, op)
314 #define OBD_COUNTER_OFFSET(op)
315 #define OBD_COUNTER_INCREMENT(obd, op)
316 #define MD_COUNTER_INCREMENT(obd, op)
319 #define OBD_CHECK_MD_OP(obd, op, err) \
321 if (!OBT(obd) || !MDP((obd), op)) {\
323 CERROR("obd_md" #op ": dev %d no operation\n", \
329 #define EXP_CHECK_MD_OP(exp, op) \
331 if ((exp) == NULL) { \
332 CERROR("obd_" #op ": NULL export\n"); \
335 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
336 CERROR("obd_" #op ": cleaned up obd\n"); \
337 RETURN(-EOPNOTSUPP); \
339 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
340 CERROR("obd_" #op ": dev %d no operation\n", \
341 (exp)->exp_obd->obd_minor); \
342 RETURN(-EOPNOTSUPP); \
346 #define OBD_CHECK_OP(obd, op, err) \
348 if (!OBT(obd) || !OBP((obd), op)) {\
350 CERROR("obd_" #op ": dev %d no operation\n", \
356 #define EXP_CHECK_OP(exp, op) \
358 if ((exp) == NULL) { \
359 CERROR("obd_" #op ": NULL export\n"); \
362 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
363 CERROR("obd_" #op ": cleaned up obd\n"); \
364 RETURN(-EOPNOTSUPP); \
366 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
367 CERROR("obd_" #op ": dev %d no operation\n", \
368 (exp)->exp_obd->obd_minor); \
369 RETURN(-EOPNOTSUPP); \
373 #define CTXT_CHECK_OP(ctxt, op, err) \
375 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
377 CERROR("lop_" #op ": dev %d no operation\n", \
378 ctxt->loc_obd->obd_minor); \
383 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
384 void *key, __u32 *vallen, void *val)
389 EXP_CHECK_OP(exp, get_info);
390 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
392 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
396 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
397 void *key, obd_count vallen, void *val)
402 EXP_CHECK_OP(exp, set_info);
403 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
405 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
409 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
414 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
415 OBD_COUNTER_INCREMENT(obd, setup);
417 rc = OBP(obd, setup)(obd, datalen, data);
421 static inline int obd_precleanup(struct obd_device *obd, int flags)
426 OBD_CHECK_OP(obd, precleanup, 0);
427 OBD_COUNTER_INCREMENT(obd, precleanup);
429 rc = OBP(obd, precleanup)(obd, flags);
433 static inline int obd_cleanup(struct obd_device *obd, int flags)
438 OBD_CHECK_DEV_STOPPING(obd);
439 OBD_CHECK_OP(obd, cleanup, 0);
440 OBD_COUNTER_INCREMENT(obd, cleanup);
442 rc = OBP(obd, cleanup)(obd, flags);
447 obd_process_config(struct obd_device *obd, int datalen, void *data)
452 OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
453 OBD_COUNTER_INCREMENT(obd, process_config);
455 rc = OBP(obd, process_config)(obd, datalen, data);
459 /* Pack an in-memory MD struct for storage on disk.
460 * Returns +ve size of packed MD (0 for free), or -ve error.
462 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
463 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
464 * If @*disk_tgt == NULL, it will be allocated
466 static inline int obd_packmd(struct obd_export *exp,
467 struct lov_mds_md **disk_tgt,
468 struct lov_stripe_md *mem_src)
473 EXP_CHECK_OP(exp, packmd);
474 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
476 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
480 static inline int obd_size_diskmd(struct obd_export *exp,
481 struct lov_stripe_md *mem_src)
483 return obd_packmd(exp, NULL, mem_src);
486 /* helper functions */
487 static inline int obd_alloc_diskmd(struct obd_export *exp,
488 struct lov_mds_md **disk_tgt)
491 LASSERT(*disk_tgt == NULL);
492 return obd_packmd(exp, disk_tgt, NULL);
495 static inline int obd_free_diskmd(struct obd_export *exp,
496 struct lov_mds_md **disk_tgt)
500 return obd_packmd(exp, disk_tgt, NULL);
503 /* Unpack an MD struct from disk to in-memory format.
504 * Returns +ve size of unpacked MD (0 for free), or -ve error.
506 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
507 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
508 * If @*mem_tgt == NULL, it will be allocated
510 static inline int obd_unpackmd(struct obd_export *exp,
511 struct lov_stripe_md **mem_tgt,
512 struct lov_mds_md *disk_src,
518 EXP_CHECK_OP(exp, unpackmd);
519 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
521 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
525 /* helper functions */
526 static inline int obd_alloc_memmd(struct obd_export *exp,
527 struct lov_stripe_md **mem_tgt)
530 LASSERT(*mem_tgt == NULL);
531 return obd_unpackmd(exp, mem_tgt, NULL, 0);
534 static inline int obd_free_memmd(struct obd_export *exp,
535 struct lov_stripe_md **mem_tgt)
539 return obd_unpackmd(exp, mem_tgt, NULL, 0);
542 static inline int obd_revalidate_md(struct obd_export *exp, struct obdo *obdo,
543 struct lov_stripe_md *ea,
544 struct obd_trans_info *oti)
549 EXP_CHECK_OP(exp, revalidate_md);
550 OBD_COUNTER_INCREMENT(exp->exp_obd, revalidate_md);
552 rc = OBP(exp->exp_obd, revalidate_md)(exp, obdo, ea, oti);
556 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
557 struct lov_stripe_md **ea,
558 struct obd_trans_info *oti)
563 EXP_CHECK_OP(exp, create);
564 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
566 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
570 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
571 struct lov_stripe_md *ea,
572 struct obd_trans_info *oti)
577 EXP_CHECK_OP(exp, destroy);
578 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
580 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
584 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
585 struct lov_stripe_md *ea)
590 EXP_CHECK_OP(exp, getattr);
591 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
593 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
597 static inline int obd_getattr_async(struct obd_export *exp,
598 struct obdo *obdo, struct lov_stripe_md *ea,
599 struct ptlrpc_request_set *set)
604 EXP_CHECK_OP(exp, getattr);
605 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
607 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
611 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
612 struct lov_stripe_md *ea,
613 struct obd_trans_info *oti)
618 EXP_CHECK_OP(exp, setattr);
619 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
621 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
625 static inline int obd_connect(struct lustre_handle *conn,
626 struct obd_device *obd, struct obd_uuid *cluuid,
627 unsigned long connect_flags)
632 OBD_CHECK_DEV_ACTIVE(obd);
633 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
634 OBD_COUNTER_INCREMENT(obd, connect);
636 rc = OBP(obd, connect)(conn, obd, cluuid, connect_flags);
640 static inline int obd_connect_post(struct obd_export *exp)
645 OBD_CHECK_DEV_ACTIVE(exp->exp_obd);
646 if (!OBT(exp->exp_obd) || !OBP((exp->exp_obd), connect_post))
648 OBD_COUNTER_INCREMENT(exp->exp_obd, connect_post);
649 rc = OBP(exp->exp_obd, connect_post)(exp);
653 static inline int obd_disconnect(struct obd_export *exp, int flags)
658 EXP_CHECK_OP(exp, disconnect);
659 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
661 rc = OBP(exp->exp_obd, disconnect)(exp, flags);
665 static inline int obd_init_export(struct obd_export *exp)
670 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
671 OBP((exp)->exp_obd, init_export))
672 rc = OBP(exp->exp_obd, init_export)(exp);
676 static inline int obd_destroy_export(struct obd_export *exp)
679 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
680 OBP((exp)->exp_obd, destroy_export))
681 OBP(exp->exp_obd, destroy_export)(exp);
685 static inline struct dentry *
686 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
688 LASSERT(exp->exp_obd);
690 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
695 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
698 /* @max_age is the oldest time in jiffies that we accept using a cached data.
699 * If the cache is older than @max_age we will get a new value from the
700 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
701 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
702 unsigned long max_age)
710 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
711 OBD_COUNTER_INCREMENT(obd, statfs);
713 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
714 if (time_before(obd->obd_osfs_age, max_age)) {
715 rc = OBP(obd, statfs)(obd, osfs, max_age);
717 spin_lock(&obd->obd_osfs_lock);
718 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
719 obd->obd_osfs_age = jiffies;
720 spin_unlock(&obd->obd_osfs_lock);
723 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
724 spin_lock(&obd->obd_osfs_lock);
725 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
726 spin_unlock(&obd->obd_osfs_lock);
731 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
732 struct lov_stripe_md *ea, obd_size start,
738 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
739 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
741 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
745 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
746 struct lov_stripe_md *ea, obd_size start,
747 obd_size end, struct obd_trans_info *oti)
752 EXP_CHECK_OP(exp, punch);
753 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
755 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
759 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
760 struct lov_stripe_md *ea, obd_count oa_bufs,
761 struct brw_page *pg, struct obd_trans_info *oti)
766 EXP_CHECK_OP(exp, brw);
767 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
769 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
770 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
771 "or OBD_BRW_CHECK\n");
775 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
779 static inline int obd_brw_async(int cmd, struct obd_export *exp,
780 struct obdo *oa, struct lov_stripe_md *ea,
781 obd_count oa_bufs, struct brw_page *pg,
782 struct ptlrpc_request_set *set,
783 struct obd_trans_info *oti)
788 EXP_CHECK_OP(exp, brw_async);
789 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
791 if (!(cmd & OBD_BRW_RWMASK)) {
792 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
796 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
801 static inline int obd_prep_async_page(struct obd_export *exp,
802 struct lov_stripe_md *lsm,
803 struct lov_oinfo *loi,
804 struct page *page, obd_off offset,
805 struct obd_async_page_ops *ops,
806 void *data, void **res)
811 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
812 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
814 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
819 static inline int obd_queue_async_io(struct obd_export *exp,
820 struct lov_stripe_md *lsm,
821 struct lov_oinfo *loi, void *cookie,
822 int cmd, obd_off off, int count,
823 obd_flag brw_flags, obd_flag async_flags)
828 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
829 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
830 LASSERT(cmd & OBD_BRW_RWMASK);
832 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
833 count, brw_flags, async_flags);
837 static inline int obd_set_async_flags(struct obd_export *exp,
838 struct lov_stripe_md *lsm,
839 struct lov_oinfo *loi, void *cookie,
840 obd_flag async_flags)
845 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
846 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
848 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
853 static inline int obd_queue_group_io(struct obd_export *exp,
854 struct lov_stripe_md *lsm,
855 struct lov_oinfo *loi,
856 struct obd_io_group *oig,
857 void *cookie, int cmd, obd_off off,
858 int count, obd_flag brw_flags,
859 obd_flag async_flags)
864 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
865 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
866 LASSERT(cmd & OBD_BRW_RWMASK);
868 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
869 cmd, off, count, brw_flags,
874 static inline int obd_trigger_group_io(struct obd_export *exp,
875 struct lov_stripe_md *lsm,
876 struct lov_oinfo *loi,
877 struct obd_io_group *oig)
882 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
883 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
885 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
889 static inline int obd_teardown_async_page(struct obd_export *exp,
890 struct lov_stripe_md *lsm,
891 struct lov_oinfo *loi, void *cookie)
896 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
897 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
899 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
903 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
904 int objcount, struct obd_ioobj *obj,
905 int niocount, struct niobuf_remote *remote,
906 struct niobuf_local *local,
907 struct obd_trans_info *oti)
912 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
913 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
915 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
920 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
921 int objcount, struct obd_ioobj *obj,
922 int niocount, struct niobuf_local *local,
923 struct obd_trans_info *oti, int rc)
927 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
928 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
930 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
935 static inline int obd_do_cow(struct obd_export *exp, struct obd_ioobj *obj,
936 int objcount,struct niobuf_remote *rnb)
941 /* there are cases when write_extents is not implemented. */
942 if (!OBP(exp->exp_obd, do_cow))
945 OBD_COUNTER_INCREMENT(exp->exp_obd, do_cow);
947 rc = OBP(exp->exp_obd, do_cow)(exp, obj, objcount, rnb);
952 static inline int obd_write_extents(struct obd_export *exp,
953 struct obd_ioobj *obj,
954 int objcount, int niocount,
955 struct niobuf_local *local,
960 /* there are cases when write_extents is not implemented. */
961 if (!OBP(exp->exp_obd, write_extents))
964 OBD_COUNTER_INCREMENT(exp->exp_obd, write_extents);
966 rc = OBP(exp->exp_obd, write_extents)(exp, obj, objcount, niocount,
971 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
972 int len, void *karg, void *uarg)
977 EXP_CHECK_OP(exp, iocontrol);
978 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
980 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
984 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
985 __u32 type, ldlm_policy_data_t *policy,
986 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
987 void *gl_cb, void *data, __u32 lvb_len,
988 void *lvb_swabber, struct lustre_handle *lockh)
993 EXP_CHECK_OP(exp, enqueue);
994 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
996 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
997 bl_cb, cp_cb, gl_cb, data, lvb_len,
1002 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1003 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1004 int *flags, void *data, struct lustre_handle *lockh)
1009 EXP_CHECK_OP(exp, match);
1010 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1012 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1017 static inline int obd_change_cbdata(struct obd_export *exp,
1018 struct lov_stripe_md *lsm,
1019 ldlm_iterator_t it, void *data)
1024 EXP_CHECK_OP(exp, change_cbdata);
1025 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1027 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1031 static inline int obd_cancel(struct obd_export *exp,
1032 struct lov_stripe_md *ea, __u32 mode,
1033 struct lustre_handle *lockh)
1038 EXP_CHECK_OP(exp, cancel);
1039 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1041 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1045 static inline int obd_cancel_unused(struct obd_export *exp,
1046 struct lov_stripe_md *ea, int flags,
1052 EXP_CHECK_OP(exp, cancel_unused);
1053 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1055 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1060 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1062 int objcount, struct obd_ioobj *obj,
1063 int niocount, struct niobuf_remote *remote)
1067 EXP_CHECK_OP(exp, preprw);
1068 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1070 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1072 class_export_put(exp);
1076 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1077 int type, struct obd_client_handle *handle, int flag)
1081 EXP_CHECK_OP(exp, pin);
1082 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1084 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1088 static inline int obd_unpin(struct obd_export *exp,
1089 struct obd_client_handle *handle, int flag)
1093 EXP_CHECK_OP(exp, unpin);
1094 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1096 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1101 static inline void obd_import_event(struct obd_device *obd,
1102 struct obd_import *imp,
1103 enum obd_import_event event)
1105 if (obd->obd_set_up && OBP(obd, import_event)) {
1106 OBD_COUNTER_INCREMENT(obd, import_event);
1107 OBP(obd, import_event)(obd, imp, event);
1111 static inline int obd_llog_connect(struct obd_export *exp,
1112 struct llogd_conn_body *body)
1115 EXP_CHECK_OP(exp, llog_connect);
1116 return OBP(exp->exp_obd, llog_connect)(exp, body);
1119 static inline int obd_notify(struct obd_device *obd, struct obd_device *watched,
1120 int active, void *data)
1122 if (!obd->obd_set_up) {
1123 CERROR("obd %s not set up\n", obd->obd_name);
1127 if (!OBP(obd, notify)) {
1128 CERROR("obd %s has no notify handler\n", obd->obd_name);
1132 OBD_COUNTER_INCREMENT(obd, notify);
1133 return OBP(obd, notify)(obd, watched, active, data);
1136 static inline int obd_register_observer(struct obd_device *obd,
1137 struct obd_device *observer)
1140 if (obd->obd_observer && observer)
1142 obd->obd_observer = observer;
1146 static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
1150 LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
1151 OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1152 rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
1156 static inline int md_getstatus(struct obd_export *exp, struct ll_fid *fid)
1160 EXP_CHECK_MD_OP(exp, getstatus);
1161 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1162 rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1166 /* this function notifies MDC, that inode described by @fid gets removed from
1168 static inline int md_delete_object(struct obd_export *exp,
1174 /* as this method only notifies MDC that inode gets deleted, we can
1175 * return zero if method is not implemented, this means, that OBD does
1176 * not need such a notification. */
1177 if (MDP(exp->exp_obd, delete_object) == NULL)
1180 MD_COUNTER_INCREMENT(exp->exp_obd, delete_object);
1181 rc = MDP(exp->exp_obd, delete_object)(exp, fid);
1185 static inline int md_getattr(struct obd_export *exp, struct ll_fid *fid,
1186 unsigned long valid, unsigned int ea_size,
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, fid, valid, ea_size, request);
1197 static inline int md_change_cbdata(struct obd_export *exp, struct ll_fid *fid,
1198 ldlm_iterator_t it, void *data)
1202 EXP_CHECK_MD_OP(exp, change_cbdata);
1203 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1204 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1208 static inline int md_change_cbdata_name(struct obd_export *exp,
1209 struct ll_fid *fid, char *name,
1210 int namelen, struct ll_fid *fid2,
1211 ldlm_iterator_t it, void *data)
1215 /* this seem to be needed only for lmv. */
1216 if (!MDP(exp->exp_obd, change_cbdata_name))
1221 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
1222 rc = MDP(exp->exp_obd, change_cbdata_name)(exp, fid, name, namelen,
1227 static inline int md_close(struct obd_export *exp, struct obdo *obdo,
1228 struct obd_client_handle *och,
1229 struct ptlrpc_request **request)
1233 EXP_CHECK_MD_OP(exp, close);
1234 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1235 rc = MDP(exp->exp_obd, close)(exp, obdo, och, request);
1239 static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1240 const void *data, int datalen, int mode,
1241 __u32 uid, __u32 gid, __u64 rdev,
1242 struct ptlrpc_request **request)
1246 EXP_CHECK_MD_OP(exp, create);
1247 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1248 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1249 uid, gid, rdev, request);
1253 static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
1257 EXP_CHECK_MD_OP(exp, done_writing);
1258 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1259 rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
1263 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1264 struct lookup_intent *it, int lock_mode,
1265 struct mdc_op_data *data,
1266 struct lustre_handle *lockh,
1267 void *lmm, int lmmsize,
1268 ldlm_completion_callback cb_completion,
1269 ldlm_blocking_callback cb_blocking,
1274 EXP_CHECK_MD_OP(exp, enqueue);
1275 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1276 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1277 data, lockh, lmm, lmmsize,
1278 cb_completion, cb_blocking,
1283 static inline int md_getattr_name(struct obd_export *exp, struct ll_fid *fid,
1284 char *filename, int namelen,
1285 unsigned long valid, unsigned int ea_size,
1286 struct ptlrpc_request **request)
1290 EXP_CHECK_MD_OP(exp, getattr_name);
1291 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1292 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1293 valid, ea_size, request);
1297 static inline int md_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
1298 struct ll_fid *pfid, const char *name,
1299 int len, void *lmm, int lmmsize,
1300 struct ll_fid *cfid, struct lookup_intent *it,
1301 int flags, struct ptlrpc_request **reqp,
1302 ldlm_blocking_callback cb_blocking)
1306 EXP_CHECK_MD_OP(exp, intent_lock);
1307 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1308 rc = MDP(exp->exp_obd, intent_lock)(exp, uctxt, pfid, name, len,
1309 lmm, lmmsize, cfid, it, flags,
1314 static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
1315 struct ptlrpc_request **request)
1319 EXP_CHECK_MD_OP(exp, link);
1320 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1321 rc = MDP(exp->exp_obd, link)(exp, data, request);
1325 static inline int md_rename(struct obd_export *exp, struct mdc_op_data *data,
1326 const char *old, int oldlen,
1327 const char *new, int newlen,
1328 struct ptlrpc_request **request)
1332 EXP_CHECK_MD_OP(exp, rename);
1333 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1334 rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
1339 static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1340 struct iattr *iattr, void *ea, int ealen,
1341 void *ea2, int ea2len,
1342 struct ptlrpc_request **request)
1346 EXP_CHECK_MD_OP(exp, setattr);
1347 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1348 rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
1349 ea2, ea2len, request);
1353 static inline int md_sync(struct obd_export *exp, struct ll_fid *fid,
1354 struct ptlrpc_request **request)
1358 EXP_CHECK_MD_OP(exp, sync);
1359 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1360 rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1364 static inline int md_readpage(struct obd_export *exp, struct ll_fid *fid,
1365 __u64 offset, struct page *page,
1366 struct ptlrpc_request **request)
1370 EXP_CHECK_MD_OP(exp, readpage);
1371 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1372 rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1376 static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1377 struct ptlrpc_request **request)
1381 EXP_CHECK_MD_OP(exp, unlink);
1382 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1383 rc = MDP(exp->exp_obd, unlink)(exp, data, request);
1387 static inline struct obd_device *md_get_real_obd(struct obd_export *exp,
1388 char *name, int len)
1391 if (MDP(exp->exp_obd, get_real_obd) == NULL)
1392 return exp->exp_obd;
1393 MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
1394 return MDP(exp->exp_obd, get_real_obd)(exp, name, len);
1397 static inline int md_valid_attrs(struct obd_export *exp, struct ll_fid *fid)
1400 EXP_CHECK_MD_OP(exp, valid_attrs);
1401 MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
1402 return MDP(exp->exp_obd, valid_attrs)(exp, fid);
1405 static inline int md_req2lustre_md(struct obd_export *exp,
1406 struct ptlrpc_request *req,
1407 unsigned int offset,
1408 struct obd_export *osc_exp,
1409 struct lustre_md *md)
1412 EXP_CHECK_MD_OP(exp, req2lustre_md);
1413 MD_COUNTER_INCREMENT(exp->exp_obd, req2lustre_md);
1414 return MDP(exp->exp_obd, req2lustre_md)(exp, req, offset, osc_exp, md);
1417 static inline int md_set_open_replay_data(struct obd_export *exp,
1418 struct obd_client_handle *och,
1419 struct ptlrpc_request *open_req)
1422 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1423 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1424 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req);
1427 static inline int md_clear_open_replay_data(struct obd_export *exp,
1428 struct obd_client_handle *och)
1431 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1432 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1433 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1436 static inline int md_store_inode_generation(struct obd_export *exp,
1437 struct ptlrpc_request *req,
1438 int reqoff, int repoff)
1441 EXP_CHECK_MD_OP(exp, store_inode_generation);
1442 MD_COUNTER_INCREMENT(exp->exp_obd, store_inode_generation);
1443 return MDP(exp->exp_obd, store_inode_generation)(exp, req,
1447 static inline int md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
1450 EXP_CHECK_MD_OP(exp, set_lock_data);
1451 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1452 return MDP(exp->exp_obd, set_lock_data)(exp, l, data);
1455 /* OBD Metadata Support */
1457 extern int obd_init_caches(void);
1458 extern void obd_cleanup_caches(void);
1460 /* support routines */
1461 extern kmem_cache_t *obdo_cachep;
1462 static inline struct obdo *obdo_alloc(void)
1466 OBD_SLAB_ALLOC(oa, obdo_cachep, GFP_KERNEL, sizeof(*oa));
1471 static inline void obdo_free(struct obdo *oa)
1475 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1478 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1479 #define to_kdev_t(dev) dev
1480 #define kdev_t_to_nr(dev) dev
1483 /* I'm as embarrassed about this as you are.
1485 * <shaver> // XXX do not look into _superhack with remaining eye
1486 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1487 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1488 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1491 extern void obd_sysctl_init (void);
1492 extern void obd_sysctl_clean (void);
1495 typedef __u8 class_uuid_t[16];
1496 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1497 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1500 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1501 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1502 int class_del_uuid (char *uuid);
1503 void class_init_uuidlist(void);
1504 void class_exit_uuidlist(void);
1507 int mea_name2idx(struct mea *mea, char *name, int namelen);
1508 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1510 #endif /* __LINUX_OBD_CLASS_H */