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];
50 extern spinlock_t obd_dev_lock;
52 /* OBD Operations Declarations */
53 extern struct obd_device *class_conn2obd(struct lustre_handle *);
54 extern struct obd_device *class_exp2obd(struct obd_export *);
57 struct obd_export *class_conn2export(struct lustre_handle *);
58 int class_register_type(struct obd_ops *ops, struct md_ops *md_ops,
59 struct lprocfs_vars *, char *nm);
60 int class_unregister_type(char *nm);
62 struct obd_device *class_newdev(struct obd_type *type);
63 void class_release_dev(struct obd_device *obd);
65 int class_name2dev(char *name);
66 struct obd_device *class_name2obd(char *name);
67 int class_uuid2dev(struct obd_uuid *uuid);
68 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
69 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
71 struct obd_uuid *grp_uuid);
72 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
75 int oig_init(struct obd_io_group **oig);
76 void oig_add_one(struct obd_io_group *oig,
77 struct oig_callback_context *occ);
78 void oig_complete_one(struct obd_io_group *oig,
79 struct oig_callback_context *occ, int rc);
80 void oig_release(struct obd_io_group *oig);
81 int oig_wait(struct obd_io_group *oig);
84 int class_process_config(struct lustre_cfg *lcfg);
86 /* Passed as data param to class_config_parse_handler() */
87 struct config_llog_instance {
89 struct obd_uuid cfg_uuid;
90 ptl_nid_t cfg_local_nid;
92 int class_config_parse_llog(struct llog_ctxt *ctxt, char *name,
93 struct config_llog_instance *cfg);
95 int class_config_process_llog(struct llog_ctxt *ctxt, char *name,
96 struct config_llog_instance *cfg);
97 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
98 struct config_llog_instance *cfg);
100 struct lustre_profile {
101 struct list_head lp_list;
107 struct lustre_profile *class_get_profile(char * prof);
108 void class_del_profile(char *prof);
110 #define class_export_rpc_get(exp) \
112 atomic_inc(&(exp)->exp_rpc_count); \
113 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
114 (exp), atomic_read(&(exp)->exp_rpc_count)); \
115 class_export_get(exp); \
118 #define class_export_rpc_put(exp) \
120 atomic_dec(&(exp)->exp_rpc_count); \
121 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
122 (exp), atomic_read(&(exp)->exp_rpc_count)); \
123 class_export_put(exp); \
126 #define class_export_get(exp) \
128 struct obd_export *exp_ = exp; \
129 atomic_inc(&exp_->exp_refcount); \
130 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
131 atomic_read(&exp_->exp_refcount)); \
135 #define class_export_put(exp) \
137 LASSERT((exp) != NULL); \
138 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
139 atomic_read(&(exp)->exp_refcount) - 1); \
140 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
141 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
142 __class_export_put(exp); \
144 void __class_export_put(struct obd_export *);
145 struct obd_export *class_new_export(struct obd_device *obddev);
146 void class_unlink_export(struct obd_export *exp);
148 struct obd_import *class_import_get(struct obd_import *);
149 void class_import_put(struct obd_import *);
150 struct obd_import *class_new_import(void);
151 void class_destroy_import(struct obd_import *exp);
153 struct obd_type *class_get_type(char *name);
154 void class_put_type(struct obd_type *type);
155 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
156 struct obd_uuid *cluuid);
157 int class_disconnect(struct obd_export *exp, int failover);
158 void class_disconnect_exports(struct obd_device *obddev, int failover);
159 void class_disconnect_stale_exports(struct obd_device *obddev, int failover);
160 /* generic operations shared by various OBD types */
161 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
162 int class_multi_cleanup(struct obd_device *obddev);
166 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
167 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
168 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
169 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
170 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
172 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
173 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
174 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
176 static inline int obd_check_conn(struct lustre_handle *conn)
178 struct obd_device *obd;
180 CERROR("NULL conn\n");
184 obd = class_conn2obd(conn);
186 CERROR("NULL obd\n");
190 if (!obd->obd_attached) {
191 CERROR("obd %d not attached\n", obd->obd_minor);
195 if (!obd->obd_set_up) {
196 CERROR("obd %d not setup\n", obd->obd_minor);
200 if (!obd->obd_type) {
201 CERROR("obd %d not typed\n", obd->obd_minor);
205 if (!obd->obd_type->typ_ops) {
206 CERROR("obd_check_conn: obd %d no operations\n",
214 #define OBT(dev) (dev)->obd_type
215 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
216 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
217 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
219 /* Ensure obd_setup: used for disconnect which might be called while
220 an obd is stopping. */
221 #define OBD_CHECK_SETUP(conn, exp) \
224 CERROR("NULL connection\n"); \
228 exp = class_conn2export(conn); \
230 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
234 if (!(exp)->exp_obd->obd_set_up) { \
235 CERROR("Device %d not setup\n", \
236 (exp)->exp_obd->obd_minor); \
237 class_export_put(exp); \
242 /* Ensure obd_setup and !obd_stopping. */
243 #define OBD_CHECK_ACTIVE(conn, exp) \
246 CERROR("NULL connection\n"); \
250 exp = class_conn2export(conn); \
252 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
256 if (!(exp)->exp_obd->obd_set_up || (exp)->exp_obd->obd_stopping) { \
257 CERROR("Device %d not setup\n", \
258 (exp)->exp_obd->obd_minor); \
259 class_export_put(exp); \
264 /* Ensure obd_setup: used for cleanup which must be called
265 while obd is stopping */
266 #define OBD_CHECK_DEV_STOPPING(obd) \
269 CERROR("NULL device\n"); \
273 if (!(obd)->obd_set_up) { \
274 CERROR("Device %d not setup\n", \
279 if (!(obd)->obd_stopping) { \
280 CERROR("Device %d not stopping\n", \
286 /* ensure obd_setup and !obd_stopping */
287 #define OBD_CHECK_DEV_ACTIVE(obd) \
290 CERROR("NULL device\n"); \
294 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
295 CERROR("Device %d not setup\n", \
303 #define OBD_COUNTER_OFFSET(op) \
304 ((offsetof(struct obd_ops, o_ ## op) - \
305 offsetof(struct obd_ops, o_iocontrol)) \
306 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
308 #define OBD_COUNTER_INCREMENT(obd, op) \
309 if ((obd)->obd_stats != NULL) { \
310 unsigned int coffset; \
311 coffset = (unsigned int)(obd)->obd_cntr_base + \
312 OBD_COUNTER_OFFSET(op); \
313 LASSERT(coffset < obd->obd_stats->ls_num); \
314 lprocfs_counter_incr(obd->obd_stats, coffset); \
316 /* FIXME: real accounting here */
317 #define MD_COUNTER_INCREMENT(obd, op)
319 #define OBD_COUNTER_OFFSET(op)
320 #define OBD_COUNTER_INCREMENT(obd, op)
321 #define MD_COUNTER_INCREMENT(obd, op)
324 #define OBD_CHECK_MD_OP(obd, op, err) \
326 if (!OBT(obd) || !MDP((obd), op)) {\
328 CERROR("obd_md" #op ": dev %d no operation\n", \
334 #define EXP_CHECK_MD_OP(exp, op) \
336 if ((exp) == NULL) { \
337 CERROR("obd_" #op ": NULL export\n"); \
338 portals_debug_dumplog(); \
341 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
342 CERROR("obd_" #op ": cleaned up obd\n"); \
343 RETURN(-EOPNOTSUPP); \
345 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
346 CERROR("obd_" #op ": dev %d no operation\n", \
347 (exp)->exp_obd->obd_minor); \
348 RETURN(-EOPNOTSUPP); \
352 #define OBD_CHECK_OP(obd, op, err) \
354 if (!OBT(obd) || !OBP((obd), op)) {\
356 CERROR("obd_" #op ": dev %d no operation\n", \
362 #define EXP_CHECK_OP(exp, op) \
364 if ((exp) == NULL) { \
365 CERROR("obd_" #op ": NULL export\n"); \
366 portals_debug_dumplog(); \
369 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
370 CERROR("obd_" #op ": cleaned up obd\n"); \
371 RETURN(-EOPNOTSUPP); \
373 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
374 CERROR("obd_" #op ": dev %d no operation\n", \
375 (exp)->exp_obd->obd_minor); \
376 RETURN(-EOPNOTSUPP); \
380 #define CTXT_CHECK_OP(ctxt, op, err) \
382 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
384 CERROR("lop_" #op ": dev %d no operation\n", \
385 ctxt->loc_obd->obd_minor); \
390 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
391 void *key, __u32 *vallen, void *val)
396 EXP_CHECK_OP(exp, get_info);
397 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
399 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
403 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
404 void *key, obd_count vallen, void *val)
409 EXP_CHECK_OP(exp, set_info);
410 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
412 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
416 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
421 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
422 OBD_COUNTER_INCREMENT(obd, setup);
424 rc = OBP(obd, setup)(obd, datalen, data);
428 static inline int obd_precleanup(struct obd_device *obd, int flags)
433 OBD_CHECK_OP(obd, precleanup, 0);
434 OBD_COUNTER_INCREMENT(obd, precleanup);
436 rc = OBP(obd, precleanup)(obd, flags);
440 static inline int obd_cleanup(struct obd_device *obd, int flags)
445 OBD_CHECK_DEV_STOPPING(obd);
446 OBD_CHECK_OP(obd, cleanup, 0);
447 OBD_COUNTER_INCREMENT(obd, cleanup);
449 rc = OBP(obd, cleanup)(obd, flags);
454 obd_process_config(struct obd_device *obd, int datalen, void *data)
459 OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
460 OBD_COUNTER_INCREMENT(obd, process_config);
462 rc = OBP(obd, process_config)(obd, datalen, data);
466 /* Pack an in-memory MD struct for storage on disk.
467 * Returns +ve size of packed MD (0 for free), or -ve error.
469 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
470 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
471 * If @*disk_tgt == NULL, it will be allocated
473 static inline int obd_packmd(struct obd_export *exp,
474 struct lov_mds_md **disk_tgt,
475 struct lov_stripe_md *mem_src)
480 EXP_CHECK_OP(exp, packmd);
481 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
483 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
487 static inline int obd_size_diskmd(struct obd_export *exp,
488 struct lov_stripe_md *mem_src)
490 return obd_packmd(exp, NULL, mem_src);
493 /* helper functions */
494 static inline int obd_alloc_diskmd(struct obd_export *exp,
495 struct lov_mds_md **disk_tgt)
498 LASSERT(*disk_tgt == NULL);
499 return obd_packmd(exp, disk_tgt, NULL);
502 static inline int obd_free_diskmd(struct obd_export *exp,
503 struct lov_mds_md **disk_tgt)
507 return obd_packmd(exp, disk_tgt, NULL);
510 /* Unpack an MD struct from disk to in-memory format.
511 * Returns +ve size of unpacked MD (0 for free), or -ve error.
513 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
514 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
515 * If @*mem_tgt == NULL, it will be allocated
517 static inline int obd_unpackmd(struct obd_export *exp,
518 struct lov_stripe_md **mem_tgt,
519 struct lov_mds_md *disk_src,
525 EXP_CHECK_OP(exp, unpackmd);
526 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
528 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
532 /* helper functions */
533 static inline int obd_alloc_memmd(struct obd_export *exp,
534 struct lov_stripe_md **mem_tgt)
537 LASSERT(*mem_tgt == NULL);
538 return obd_unpackmd(exp, mem_tgt, NULL, 0);
541 static inline int obd_free_memmd(struct obd_export *exp,
542 struct lov_stripe_md **mem_tgt)
546 return obd_unpackmd(exp, mem_tgt, NULL, 0);
549 static inline int obd_revalidate_md(struct obd_export *exp, struct obdo *obdo,
550 struct lov_stripe_md *ea,
551 struct obd_trans_info *oti)
556 EXP_CHECK_OP(exp, revalidate_md);
557 OBD_COUNTER_INCREMENT(exp->exp_obd, revalidate_md);
559 rc = OBP(exp->exp_obd, revalidate_md)(exp, obdo, ea, oti);
563 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
564 struct lov_stripe_md **ea,
565 struct obd_trans_info *oti)
570 EXP_CHECK_OP(exp, create);
571 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
573 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
577 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
578 struct lov_stripe_md *ea,
579 struct obd_trans_info *oti)
584 EXP_CHECK_OP(exp, destroy);
585 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
587 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
591 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
592 struct lov_stripe_md *ea)
597 EXP_CHECK_OP(exp, getattr);
598 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
600 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
604 static inline int obd_getattr_async(struct obd_export *exp,
605 struct obdo *obdo, struct lov_stripe_md *ea,
606 struct ptlrpc_request_set *set)
611 EXP_CHECK_OP(exp, getattr);
612 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
614 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
618 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
619 struct lov_stripe_md *ea,
620 struct obd_trans_info *oti)
625 EXP_CHECK_OP(exp, setattr);
626 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
628 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
631 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
634 struct obd_device *obd = imp->imp_obd;
638 OBD_CHECK_DEV_ACTIVE(obd);
639 OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
640 OBD_COUNTER_INCREMENT(obd, add_conn);
642 rc = OBP(obd, add_conn)(imp, uuid, priority);
646 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
648 struct obd_device *obd = imp->imp_obd;
652 OBD_CHECK_DEV_ACTIVE(obd);
653 OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
654 OBD_COUNTER_INCREMENT(obd, del_conn);
656 rc = OBP(obd, del_conn)(imp, uuid);
661 static inline int obd_connect(struct lustre_handle *conn,
662 struct obd_device *obd, struct obd_uuid *cluuid,
663 unsigned long connect_flags)
668 OBD_CHECK_DEV_ACTIVE(obd);
669 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
670 OBD_COUNTER_INCREMENT(obd, connect);
672 rc = OBP(obd, connect)(conn, obd, cluuid, connect_flags);
676 static inline int obd_connect_post(struct obd_export *exp, unsigned long flags)
681 OBD_CHECK_DEV_ACTIVE(exp->exp_obd);
682 if (!OBT(exp->exp_obd) || !OBP((exp->exp_obd), connect_post))
684 OBD_COUNTER_INCREMENT(exp->exp_obd, connect_post);
685 rc = OBP(exp->exp_obd, connect_post)(exp, flags);
689 static inline int obd_disconnect(struct obd_export *exp, int flags)
694 EXP_CHECK_OP(exp, disconnect);
695 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
697 rc = OBP(exp->exp_obd, disconnect)(exp, flags);
701 static inline int obd_init_export(struct obd_export *exp)
706 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
707 OBP((exp)->exp_obd, init_export))
708 rc = OBP(exp->exp_obd, init_export)(exp);
712 static inline int obd_destroy_export(struct obd_export *exp)
715 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
716 OBP((exp)->exp_obd, destroy_export))
717 OBP(exp->exp_obd, destroy_export)(exp);
721 static inline struct dentry *
722 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
724 LASSERT(exp->exp_obd);
726 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
731 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
734 /* @max_age is the oldest time in jiffies that we accept using a cached data.
735 * If the cache is older than @max_age we will get a new value from the
736 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
737 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
738 unsigned long max_age)
746 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
747 OBD_COUNTER_INCREMENT(obd, statfs);
749 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
750 if (time_before(obd->obd_osfs_age, max_age)) {
751 rc = OBP(obd, statfs)(obd, osfs, max_age);
753 spin_lock(&obd->obd_osfs_lock);
754 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
755 obd->obd_osfs_age = jiffies;
756 spin_unlock(&obd->obd_osfs_lock);
759 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
760 spin_lock(&obd->obd_osfs_lock);
761 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
762 spin_unlock(&obd->obd_osfs_lock);
767 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
768 struct lov_stripe_md *ea, obd_size start,
774 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
775 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
777 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
781 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
782 struct lov_stripe_md *ea, obd_size start,
783 obd_size end, struct obd_trans_info *oti)
788 EXP_CHECK_OP(exp, punch);
789 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
791 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
795 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
796 struct lov_stripe_md *ea, obd_count oa_bufs,
797 struct brw_page *pg, struct obd_trans_info *oti)
802 EXP_CHECK_OP(exp, brw);
803 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
805 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
806 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
807 "or OBD_BRW_CHECK\n");
811 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
815 static inline int obd_brw_async(int cmd, struct obd_export *exp,
816 struct obdo *oa, struct lov_stripe_md *ea,
817 obd_count oa_bufs, struct brw_page *pg,
818 struct ptlrpc_request_set *set,
819 struct obd_trans_info *oti)
824 EXP_CHECK_OP(exp, brw_async);
825 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
827 if (!(cmd & OBD_BRW_RWMASK)) {
828 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
832 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
837 static inline int obd_prep_async_page(struct obd_export *exp,
838 struct lov_stripe_md *lsm,
839 struct lov_oinfo *loi,
840 struct page *page, obd_off offset,
841 struct obd_async_page_ops *ops,
842 void *data, void **res)
847 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
848 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
850 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
855 static inline int obd_queue_async_io(struct obd_export *exp,
856 struct lov_stripe_md *lsm,
857 struct lov_oinfo *loi, void *cookie,
858 int cmd, obd_off off, int count,
859 obd_flag brw_flags, obd_flag async_flags)
864 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
865 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
866 LASSERT(cmd & OBD_BRW_RWMASK);
868 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
869 count, brw_flags, async_flags);
873 static inline int obd_set_async_flags(struct obd_export *exp,
874 struct lov_stripe_md *lsm,
875 struct lov_oinfo *loi, void *cookie,
876 obd_flag async_flags)
881 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
882 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
884 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
889 static inline int obd_queue_group_io(struct obd_export *exp,
890 struct lov_stripe_md *lsm,
891 struct lov_oinfo *loi,
892 struct obd_io_group *oig,
893 void *cookie, int cmd, obd_off off,
894 int count, obd_flag brw_flags,
895 obd_flag async_flags)
900 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
901 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
902 LASSERT(cmd & OBD_BRW_RWMASK);
904 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
905 cmd, off, count, brw_flags,
910 static inline int obd_trigger_group_io(struct obd_export *exp,
911 struct lov_stripe_md *lsm,
912 struct lov_oinfo *loi,
913 struct obd_io_group *oig)
918 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
919 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
921 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
925 static inline int obd_teardown_async_page(struct obd_export *exp,
926 struct lov_stripe_md *lsm,
927 struct lov_oinfo *loi, void *cookie)
932 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
933 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
935 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
939 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
940 int objcount, struct obd_ioobj *obj,
941 int niocount, struct niobuf_remote *remote,
942 struct niobuf_local *local,
943 struct obd_trans_info *oti)
948 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
949 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
951 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
956 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
957 int objcount, struct obd_ioobj *obj,
958 int niocount, struct niobuf_local *local,
959 struct obd_trans_info *oti, int rc)
963 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
964 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
966 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
971 static inline int obd_do_cow(struct obd_export *exp, struct obd_ioobj *obj,
972 int objcount,struct niobuf_remote *rnb)
977 /* there are cases when write_extents is not implemented. */
978 if (!OBP(exp->exp_obd, do_cow))
981 OBD_COUNTER_INCREMENT(exp->exp_obd, do_cow);
983 rc = OBP(exp->exp_obd, do_cow)(exp, obj, objcount, rnb);
988 static inline int obd_write_extents(struct obd_export *exp,
989 struct obd_ioobj *obj,
990 int objcount, int niocount,
991 struct niobuf_local *local,
996 /* there are cases when write_extents is not implemented. */
997 if (!OBP(exp->exp_obd, write_extents))
1000 OBD_COUNTER_INCREMENT(exp->exp_obd, write_extents);
1002 rc = OBP(exp->exp_obd, write_extents)(exp, obj, objcount, niocount,
1007 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1008 int len, void *karg, void *uarg)
1013 EXP_CHECK_OP(exp, iocontrol);
1014 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
1016 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1020 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
1021 __u32 type, ldlm_policy_data_t *policy,
1022 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
1023 void *gl_cb, void *data, __u32 lvb_len,
1024 void *lvb_swabber, struct lustre_handle *lockh)
1029 EXP_CHECK_OP(exp, enqueue);
1030 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1032 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
1033 bl_cb, cp_cb, gl_cb, data, lvb_len,
1034 lvb_swabber, lockh);
1038 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1039 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1040 int *flags, void *data, struct lustre_handle *lockh)
1045 EXP_CHECK_OP(exp, match);
1046 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1048 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1053 static inline int obd_change_cbdata(struct obd_export *exp,
1054 struct lov_stripe_md *lsm,
1055 ldlm_iterator_t it, void *data)
1060 EXP_CHECK_OP(exp, change_cbdata);
1061 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1063 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1067 static inline int obd_cancel(struct obd_export *exp,
1068 struct lov_stripe_md *ea, __u32 mode,
1069 struct lustre_handle *lockh)
1074 EXP_CHECK_OP(exp, cancel);
1075 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1077 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1081 static inline int obd_cancel_unused(struct obd_export *exp,
1082 struct lov_stripe_md *ea, int flags,
1088 EXP_CHECK_OP(exp, cancel_unused);
1089 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1091 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1096 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1098 int objcount, struct obd_ioobj *obj,
1099 int niocount, struct niobuf_remote *remote)
1103 EXP_CHECK_OP(exp, preprw);
1104 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1106 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1108 class_export_put(exp);
1112 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1113 int type, struct obd_client_handle *handle, int flag)
1117 EXP_CHECK_OP(exp, pin);
1118 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1120 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1124 static inline int obd_unpin(struct obd_export *exp,
1125 struct obd_client_handle *handle, int flag)
1129 EXP_CHECK_OP(exp, unpin);
1130 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1132 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1137 static inline void obd_import_event(struct obd_device *obd,
1138 struct obd_import *imp,
1139 enum obd_import_event event)
1141 if (obd->obd_set_up && OBP(obd, import_event)) {
1142 OBD_COUNTER_INCREMENT(obd, import_event);
1143 OBP(obd, import_event)(obd, imp, event);
1147 static inline int obd_llog_connect(struct obd_export *exp,
1148 struct llogd_conn_body *body)
1151 EXP_CHECK_OP(exp, llog_connect);
1152 return OBP(exp->exp_obd, llog_connect)(exp, body);
1155 static inline int obd_notify(struct obd_device *obd, struct obd_device *watched,
1156 int active, void *data)
1158 if (!obd->obd_set_up) {
1159 CERROR("obd %s not set up\n", obd->obd_name);
1163 if (!OBP(obd, notify)) {
1164 CERROR("obd %s has no notify handler\n", obd->obd_name);
1168 OBD_COUNTER_INCREMENT(obd, notify);
1169 return OBP(obd, notify)(obd, watched, active, data);
1172 static inline int obd_register_observer(struct obd_device *obd,
1173 struct obd_device *observer)
1176 if (obd->obd_observer && observer)
1178 obd->obd_observer = observer;
1182 static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
1186 LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
1187 OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1188 rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
1191 static inline int md_getstatus(struct obd_export *exp, struct ll_fid *fid)
1195 EXP_CHECK_MD_OP(exp, getstatus);
1196 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1197 rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1201 /* this function notifies MDC, that inode described by @fid gets removed from
1203 static inline int md_delete_object(struct obd_export *exp,
1209 /* as this method only notifies MDC that inode gets deleted, we can
1210 * return zero if method is not implemented, this means, that OBD does
1211 * not need such a notification. */
1212 if (MDP(exp->exp_obd, delete_object) == NULL)
1215 MD_COUNTER_INCREMENT(exp->exp_obd, delete_object);
1216 rc = MDP(exp->exp_obd, delete_object)(exp, fid);
1220 static inline int md_getattr(struct obd_export *exp, struct ll_fid *fid,
1221 unsigned long valid, unsigned int ea_size,
1222 struct ptlrpc_request **request)
1226 EXP_CHECK_MD_OP(exp, getattr);
1227 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1228 rc = MDP(exp->exp_obd, getattr)(exp, fid, valid, ea_size, request);
1232 static inline int md_change_cbdata(struct obd_export *exp, struct ll_fid *fid,
1233 ldlm_iterator_t it, void *data)
1237 EXP_CHECK_MD_OP(exp, change_cbdata);
1238 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1239 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1243 static inline int md_change_cbdata_name(struct obd_export *exp,
1244 struct ll_fid *fid, char *name,
1245 int namelen, struct ll_fid *fid2,
1246 ldlm_iterator_t it, void *data)
1250 /* this seem to be needed only for lmv. */
1251 if (!MDP(exp->exp_obd, change_cbdata_name))
1256 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
1257 rc = MDP(exp->exp_obd, change_cbdata_name)(exp, fid, name, namelen,
1262 static inline int md_close(struct obd_export *exp, struct obdo *obdo,
1263 struct obd_client_handle *och,
1264 struct ptlrpc_request **request)
1268 EXP_CHECK_MD_OP(exp, close);
1269 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1270 rc = MDP(exp->exp_obd, close)(exp, obdo, och, request);
1274 static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1275 const void *data, int datalen, int mode,
1276 __u32 uid, __u32 gid, __u64 rdev,
1277 struct ptlrpc_request **request)
1281 EXP_CHECK_MD_OP(exp, create);
1282 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1283 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1284 uid, gid, rdev, request);
1288 static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
1292 EXP_CHECK_MD_OP(exp, done_writing);
1293 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1294 rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
1298 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1299 struct lookup_intent *it, int lock_mode,
1300 struct mdc_op_data *data,
1301 struct lustre_handle *lockh,
1302 void *lmm, int lmmsize,
1303 ldlm_completion_callback cb_completion,
1304 ldlm_blocking_callback cb_blocking,
1309 EXP_CHECK_MD_OP(exp, enqueue);
1310 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1311 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1312 data, lockh, lmm, lmmsize,
1313 cb_completion, cb_blocking,
1318 static inline int md_getattr_name(struct obd_export *exp, struct ll_fid *fid,
1319 char *filename, int namelen,
1320 unsigned long valid, unsigned int ea_size,
1321 struct ptlrpc_request **request)
1325 EXP_CHECK_MD_OP(exp, getattr_name);
1326 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1327 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1328 valid, ea_size, request);
1332 static inline int md_intent_lock(struct obd_export *exp,
1333 struct ll_fid *pfid, const char *name,
1334 int len, void *lmm, int lmmsize,
1335 struct ll_fid *cfid, struct lookup_intent *it,
1336 int flags, struct ptlrpc_request **reqp,
1337 ldlm_blocking_callback cb_blocking)
1341 EXP_CHECK_MD_OP(exp, intent_lock);
1342 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1343 rc = MDP(exp->exp_obd, intent_lock)(exp, pfid, name, len,
1344 lmm, lmmsize, cfid, it, flags,
1349 static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
1350 struct ptlrpc_request **request)
1354 EXP_CHECK_MD_OP(exp, link);
1355 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1356 rc = MDP(exp->exp_obd, link)(exp, data, request);
1360 static inline int md_rename(struct obd_export *exp, struct mdc_op_data *data,
1361 const char *old, int oldlen,
1362 const char *new, int newlen,
1363 struct ptlrpc_request **request)
1367 EXP_CHECK_MD_OP(exp, rename);
1368 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1369 rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
1374 static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1375 struct iattr *iattr, void *ea, int ealen,
1376 void *ea2, int ea2len,
1377 struct ptlrpc_request **request)
1381 EXP_CHECK_MD_OP(exp, setattr);
1382 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1383 rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
1384 ea2, ea2len, request);
1388 static inline int md_sync(struct obd_export *exp, struct ll_fid *fid,
1389 struct ptlrpc_request **request)
1393 EXP_CHECK_MD_OP(exp, sync);
1394 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1395 rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1399 static inline int md_readpage(struct obd_export *exp, struct ll_fid *fid,
1400 __u64 offset, struct page *page,
1401 struct ptlrpc_request **request)
1405 EXP_CHECK_MD_OP(exp, readpage);
1406 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1407 rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1411 static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1412 struct ptlrpc_request **request)
1416 EXP_CHECK_MD_OP(exp, unlink);
1417 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1418 rc = MDP(exp->exp_obd, unlink)(exp, data, request);
1422 static inline struct obd_device *md_get_real_obd(struct obd_export *exp,
1423 char *name, int len)
1426 if (MDP(exp->exp_obd, get_real_obd) == NULL)
1427 return exp->exp_obd;
1428 MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
1429 return MDP(exp->exp_obd, get_real_obd)(exp, name, len);
1432 static inline int md_valid_attrs(struct obd_export *exp, struct ll_fid *fid)
1435 EXP_CHECK_MD_OP(exp, valid_attrs);
1436 MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
1437 return MDP(exp->exp_obd, valid_attrs)(exp, fid);
1440 static inline int md_req2lustre_md(struct obd_export *exp,
1441 struct ptlrpc_request *req,
1442 unsigned int offset,
1443 struct obd_export *osc_exp,
1444 struct lustre_md *md)
1447 EXP_CHECK_MD_OP(exp, req2lustre_md);
1448 MD_COUNTER_INCREMENT(exp->exp_obd, req2lustre_md);
1449 return MDP(exp->exp_obd, req2lustre_md)(exp, req, offset, osc_exp, md);
1452 static inline int md_set_open_replay_data(struct obd_export *exp,
1453 struct obd_client_handle *och,
1454 struct ptlrpc_request *open_req)
1457 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1458 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1459 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req);
1462 static inline int md_clear_open_replay_data(struct obd_export *exp,
1463 struct obd_client_handle *och)
1466 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1467 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1468 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1471 static inline int md_store_inode_generation(struct obd_export *exp,
1472 struct ptlrpc_request *req,
1473 int reqoff, int repoff)
1476 EXP_CHECK_MD_OP(exp, store_inode_generation);
1477 MD_COUNTER_INCREMENT(exp->exp_obd, store_inode_generation);
1478 return MDP(exp->exp_obd, store_inode_generation)(exp, req,
1482 static inline int md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
1485 EXP_CHECK_MD_OP(exp, set_lock_data);
1486 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1487 return MDP(exp->exp_obd, set_lock_data)(exp, l, data);
1490 /* OBD Metadata Support */
1492 extern int obd_init_caches(void);
1493 extern void obd_cleanup_caches(void);
1495 /* support routines */
1496 extern kmem_cache_t *obdo_cachep;
1497 static inline struct obdo *obdo_alloc(void)
1501 OBD_SLAB_ALLOC(oa, obdo_cachep, GFP_KERNEL, sizeof(*oa));
1506 static inline void obdo_free(struct obdo *oa)
1510 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1513 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1514 #define to_kdev_t(dev) dev
1515 #define kdev_t_to_nr(dev) dev
1518 /* I'm as embarrassed about this as you are.
1520 * <shaver> // XXX do not look into _superhack with remaining eye
1521 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1522 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1523 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1526 extern void obd_sysctl_init (void);
1527 extern void obd_sysctl_clean (void);
1530 typedef __u8 class_uuid_t[16];
1531 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1532 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1535 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1536 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1537 int class_del_uuid (char *uuid);
1538 void class_init_uuidlist(void);
1539 void class_exit_uuidlist(void);
1542 int mea_name2idx(struct mea *mea, char *name, int namelen);
1543 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1545 #endif /* __LINUX_OBD_CLASS_H */