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); \
145 void __class_export_put(struct obd_export *);
146 struct obd_export *class_new_export(struct obd_device *obddev);
147 void class_unlink_export(struct obd_export *exp);
149 struct obd_import *class_import_get(struct obd_import *);
150 void class_import_put(struct obd_import *);
151 struct obd_import *class_new_import(void);
152 void class_destroy_import(struct obd_import *exp);
154 struct obd_type *class_get_type(char *name);
155 void class_put_type(struct obd_type *type);
156 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
157 struct obd_uuid *cluuid);
158 int class_disconnect(struct obd_export *exp, int flags);
159 void class_disconnect_exports(struct obd_device *obddev, int flags);
160 void class_disconnect_stale_exports(struct obd_device *obddev, int flags);
162 /* generic operations shared by various OBD types */
163 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
164 int class_multi_cleanup(struct obd_device *obddev);
168 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
169 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
170 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
171 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
172 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
174 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
175 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
176 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
178 static inline int obd_check_conn(struct lustre_handle *conn)
180 struct obd_device *obd;
182 CERROR("NULL conn\n");
186 obd = class_conn2obd(conn);
188 CERROR("NULL obd\n");
192 if (!obd->obd_attached) {
193 CERROR("obd %d not attached\n", obd->obd_minor);
197 if (!obd->obd_set_up) {
198 CERROR("obd %d not setup\n", obd->obd_minor);
202 if (!obd->obd_type) {
203 CERROR("obd %d not typed\n", obd->obd_minor);
207 if (!obd->obd_type->typ_ops) {
208 CERROR("obd_check_conn: obd %d no operations\n",
216 #define OBT(dev) (dev)->obd_type
217 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
218 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
219 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
221 /* Ensure obd_setup: used for disconnect which might be called while
222 an obd is stopping. */
223 #define OBD_CHECK_SETUP(conn, exp) \
226 CERROR("NULL connection\n"); \
230 exp = class_conn2export(conn); \
232 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
236 if (!(exp)->exp_obd->obd_set_up) { \
237 CERROR("Device %d not setup\n", \
238 (exp)->exp_obd->obd_minor); \
239 class_export_put(exp); \
244 /* Ensure obd_setup and !obd_stopping. */
245 #define OBD_CHECK_ACTIVE(conn, exp) \
248 CERROR("NULL connection\n"); \
252 exp = class_conn2export(conn); \
254 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
258 if (!(exp)->exp_obd->obd_set_up || (exp)->exp_obd->obd_stopping) { \
259 CERROR("Device %d not setup\n", \
260 (exp)->exp_obd->obd_minor); \
261 class_export_put(exp); \
266 /* Ensure obd_setup: used for cleanup which must be called
267 while obd is stopping */
268 #define OBD_CHECK_DEV_STOPPING(obd) \
271 CERROR("NULL device\n"); \
275 if (!(obd)->obd_set_up) { \
276 CERROR("Device %d not setup\n", \
281 if (!(obd)->obd_stopping) { \
282 CERROR("Device %d not stopping\n", \
288 /* ensure obd_setup and !obd_stopping */
289 #define OBD_CHECK_DEV_ACTIVE(obd) \
292 CERROR("NULL device\n"); \
296 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
297 CERROR("Device %d not setup\n", \
305 #define OBD_COUNTER_OFFSET(op) \
306 ((offsetof(struct obd_ops, o_ ## op) - \
307 offsetof(struct obd_ops, o_iocontrol)) \
308 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
310 #define OBD_COUNTER_INCREMENT(obd, op) \
311 if ((obd)->obd_stats != NULL) { \
312 unsigned int coffset; \
313 coffset = (unsigned int)(obd)->obd_cntr_base + \
314 OBD_COUNTER_OFFSET(op); \
315 LASSERT(coffset < obd->obd_stats->ls_num); \
316 lprocfs_counter_incr(obd->obd_stats, coffset); \
318 /* FIXME: real accounting here */
319 #define MD_COUNTER_INCREMENT(obd, op)
321 #define OBD_COUNTER_OFFSET(op)
322 #define OBD_COUNTER_INCREMENT(obd, op)
323 #define MD_COUNTER_INCREMENT(obd, op)
326 #define OBD_CHECK_MD_OP(obd, op, err) \
328 if (!OBT(obd) || !MDP((obd), op)) {\
330 CERROR("obd_md" #op ": dev %d no operation\n", \
336 #define EXP_CHECK_MD_OP(exp, op) \
338 if ((exp) == NULL) { \
339 CERROR("obd_" #op ": NULL export\n"); \
340 portals_debug_dumplog(); \
343 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
344 CERROR("obd_" #op ": cleaned up obd\n"); \
345 RETURN(-EOPNOTSUPP); \
347 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
348 CERROR("obd_" #op ": dev %d no operation\n", \
349 (exp)->exp_obd->obd_minor); \
350 RETURN(-EOPNOTSUPP); \
354 #define OBD_CHECK_OP(obd, op, err) \
356 if (!OBT(obd) || !OBP((obd), op)) {\
358 CERROR("obd_" #op ": dev %d no operation\n", \
364 #define EXP_CHECK_OP(exp, op) \
366 if ((exp) == NULL) { \
367 CERROR("obd_" #op ": NULL export\n"); \
368 portals_debug_dumplog(); \
371 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
372 CERROR("obd_" #op ": cleaned up obd\n"); \
373 RETURN(-EOPNOTSUPP); \
375 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
376 CERROR("obd_" #op ": dev %d no operation\n", \
377 (exp)->exp_obd->obd_minor); \
378 RETURN(-EOPNOTSUPP); \
382 #define CTXT_CHECK_OP(ctxt, op, err) \
384 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
386 CERROR("lop_" #op ": dev %d no operation\n", \
387 ctxt->loc_obd->obd_minor); \
392 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
393 void *key, __u32 *vallen, void *val)
398 EXP_CHECK_OP(exp, get_info);
399 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
401 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
405 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
406 void *key, obd_count vallen, void *val)
411 EXP_CHECK_OP(exp, set_info);
412 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
414 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
418 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
423 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
424 OBD_COUNTER_INCREMENT(obd, setup);
426 rc = OBP(obd, setup)(obd, datalen, data);
430 static inline int obd_precleanup(struct obd_device *obd, int flags)
435 OBD_CHECK_OP(obd, precleanup, 0);
436 OBD_COUNTER_INCREMENT(obd, precleanup);
438 rc = OBP(obd, precleanup)(obd, flags);
442 static inline int obd_cleanup(struct obd_device *obd, int flags)
447 OBD_CHECK_DEV_STOPPING(obd);
448 OBD_CHECK_OP(obd, cleanup, 0);
449 OBD_COUNTER_INCREMENT(obd, cleanup);
451 rc = OBP(obd, cleanup)(obd, flags);
456 obd_process_config(struct obd_device *obd, int datalen, void *data)
461 OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
462 OBD_COUNTER_INCREMENT(obd, process_config);
464 rc = OBP(obd, process_config)(obd, datalen, data);
468 /* Pack an in-memory MD struct for storage on disk.
469 * Returns +ve size of packed MD (0 for free), or -ve error.
471 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
472 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
473 * If @*disk_tgt == NULL, it will be allocated
475 static inline int obd_packmd(struct obd_export *exp,
476 struct lov_mds_md **disk_tgt,
477 struct lov_stripe_md *mem_src)
482 EXP_CHECK_OP(exp, packmd);
483 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
485 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
489 static inline int obd_size_diskmd(struct obd_export *exp,
490 struct lov_stripe_md *mem_src)
492 return obd_packmd(exp, NULL, mem_src);
495 /* helper functions */
496 static inline int obd_alloc_diskmd(struct obd_export *exp,
497 struct lov_mds_md **disk_tgt)
500 LASSERT(*disk_tgt == NULL);
501 return obd_packmd(exp, disk_tgt, NULL);
504 static inline int obd_free_diskmd(struct obd_export *exp,
505 struct lov_mds_md **disk_tgt)
509 return obd_packmd(exp, disk_tgt, NULL);
512 /* Unpack an MD struct from disk to in-memory format.
513 * Returns +ve size of unpacked MD (0 for free), or -ve error.
515 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
516 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
517 * If @*mem_tgt == NULL, it will be allocated
519 static inline int obd_unpackmd(struct obd_export *exp,
520 struct lov_stripe_md **mem_tgt,
521 struct lov_mds_md *disk_src,
527 EXP_CHECK_OP(exp, unpackmd);
528 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
530 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
534 /* helper functions */
535 static inline int obd_alloc_memmd(struct obd_export *exp,
536 struct lov_stripe_md **mem_tgt)
539 LASSERT(*mem_tgt == NULL);
540 return obd_unpackmd(exp, mem_tgt, NULL, 0);
543 static inline int obd_free_memmd(struct obd_export *exp,
544 struct lov_stripe_md **mem_tgt)
548 return obd_unpackmd(exp, mem_tgt, NULL, 0);
551 static inline int obd_revalidate_md(struct obd_export *exp, struct obdo *obdo,
552 struct lov_stripe_md *ea,
553 struct obd_trans_info *oti)
558 EXP_CHECK_OP(exp, revalidate_md);
559 OBD_COUNTER_INCREMENT(exp->exp_obd, revalidate_md);
561 rc = OBP(exp->exp_obd, revalidate_md)(exp, obdo, ea, oti);
565 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
566 struct lov_stripe_md **ea,
567 struct obd_trans_info *oti)
572 EXP_CHECK_OP(exp, create);
573 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
575 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
579 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
580 struct lov_stripe_md *ea,
581 struct obd_trans_info *oti)
586 EXP_CHECK_OP(exp, destroy);
587 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
589 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
593 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
594 struct lov_stripe_md *ea)
599 EXP_CHECK_OP(exp, getattr);
600 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
602 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
606 static inline int obd_getattr_async(struct obd_export *exp,
607 struct obdo *obdo, struct lov_stripe_md *ea,
608 struct ptlrpc_request_set *set)
613 EXP_CHECK_OP(exp, getattr);
614 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
616 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
620 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
621 struct lov_stripe_md *ea,
622 struct obd_trans_info *oti)
627 EXP_CHECK_OP(exp, setattr);
628 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
630 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
633 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
636 struct obd_device *obd = imp->imp_obd;
640 OBD_CHECK_DEV_ACTIVE(obd);
641 OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
642 OBD_COUNTER_INCREMENT(obd, add_conn);
644 rc = OBP(obd, add_conn)(imp, uuid, priority);
648 static inline int obd_del_conn(struct obd_import *imp, struct obd_uuid *uuid)
650 struct obd_device *obd = imp->imp_obd;
654 OBD_CHECK_DEV_ACTIVE(obd);
655 OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
656 OBD_COUNTER_INCREMENT(obd, del_conn);
658 rc = OBP(obd, del_conn)(imp, uuid);
663 static inline int obd_connect(struct lustre_handle *conn,
664 struct obd_device *obd, struct obd_uuid *cluuid,
665 unsigned long connect_flags)
670 OBD_CHECK_DEV_ACTIVE(obd);
671 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
672 OBD_COUNTER_INCREMENT(obd, connect);
674 rc = OBP(obd, connect)(conn, obd, cluuid, connect_flags);
678 static inline int obd_connect_post(struct obd_export *exp, unsigned long flags)
683 OBD_CHECK_DEV_ACTIVE(exp->exp_obd);
684 if (!OBT(exp->exp_obd) || !OBP((exp->exp_obd), connect_post))
686 OBD_COUNTER_INCREMENT(exp->exp_obd, connect_post);
687 rc = OBP(exp->exp_obd, connect_post)(exp, flags);
691 static inline int obd_disconnect(struct obd_export *exp, int flags)
696 EXP_CHECK_OP(exp, disconnect);
697 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
699 rc = OBP(exp->exp_obd, disconnect)(exp, flags);
703 static inline int obd_getready(struct obd_export *exp)
708 if (!OBP(exp->exp_obd, getready))
710 rc = OBP(exp->exp_obd, getready)(exp);
714 static inline int obd_init_export(struct obd_export *exp)
719 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
720 OBP((exp)->exp_obd, init_export))
721 rc = OBP(exp->exp_obd, init_export)(exp);
725 static inline int obd_destroy_export(struct obd_export *exp)
728 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
729 OBP((exp)->exp_obd, destroy_export))
730 OBP(exp->exp_obd, destroy_export)(exp);
734 static inline struct dentry *
735 obd_lvfs_id2dentry(struct obd_export *exp, __u64 ino,
738 LASSERT(exp->exp_obd);
740 return lvfs_id2dentry(&exp->exp_obd->obd_lvfs_ctxt,
741 ino, gen, gr, exp->exp_obd);
745 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
748 /* @max_age is the oldest time in jiffies that we accept using a cached data.
749 * If the cache is older than @max_age we will get a new value from the
750 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
751 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
752 unsigned long max_age)
760 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
761 OBD_COUNTER_INCREMENT(obd, statfs);
763 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
764 if (time_before(obd->obd_osfs_age, max_age)) {
765 rc = OBP(obd, statfs)(obd, osfs, max_age);
767 spin_lock(&obd->obd_osfs_lock);
768 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
769 obd->obd_osfs_age = jiffies;
770 spin_unlock(&obd->obd_osfs_lock);
773 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
774 spin_lock(&obd->obd_osfs_lock);
775 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
776 spin_unlock(&obd->obd_osfs_lock);
781 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
782 struct lov_stripe_md *ea, obd_size start,
788 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
789 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
791 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
795 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
796 struct lov_stripe_md *ea, obd_size start,
797 obd_size end, struct obd_trans_info *oti)
802 EXP_CHECK_OP(exp, punch);
803 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
805 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
809 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
810 struct lov_stripe_md *ea, obd_count oa_bufs,
811 struct brw_page *pg, struct obd_trans_info *oti)
816 EXP_CHECK_OP(exp, brw);
817 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
819 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
820 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
821 "or OBD_BRW_CHECK\n");
825 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
829 static inline int obd_brw_async(int cmd, struct obd_export *exp,
830 struct obdo *oa, struct lov_stripe_md *ea,
831 obd_count oa_bufs, struct brw_page *pg,
832 struct ptlrpc_request_set *set,
833 struct obd_trans_info *oti)
838 EXP_CHECK_OP(exp, brw_async);
839 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
841 if (!(cmd & OBD_BRW_RWMASK)) {
842 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
846 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
851 static inline int obd_prep_async_page(struct obd_export *exp,
852 struct lov_stripe_md *lsm,
853 struct lov_oinfo *loi,
854 struct page *page, obd_off offset,
855 struct obd_async_page_ops *ops,
856 void *data, void **res)
861 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
862 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
864 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
869 static inline int obd_queue_async_io(struct obd_export *exp,
870 struct lov_stripe_md *lsm,
871 struct lov_oinfo *loi, void *cookie,
872 int cmd, obd_off off, int count,
873 obd_flag brw_flags, obd_flag async_flags)
878 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
879 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
880 LASSERT(cmd & OBD_BRW_RWMASK);
882 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
883 count, brw_flags, async_flags);
887 static inline int obd_set_async_flags(struct obd_export *exp,
888 struct lov_stripe_md *lsm,
889 struct lov_oinfo *loi, void *cookie,
890 obd_flag async_flags)
895 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
896 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
898 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
903 static inline int obd_queue_group_io(struct obd_export *exp,
904 struct lov_stripe_md *lsm,
905 struct lov_oinfo *loi,
906 struct obd_io_group *oig,
907 void *cookie, int cmd, obd_off off,
908 int count, obd_flag brw_flags,
909 obd_flag async_flags)
914 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
915 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
916 LASSERT(cmd & OBD_BRW_RWMASK);
918 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
919 cmd, off, count, brw_flags,
924 static inline int obd_trigger_group_io(struct obd_export *exp,
925 struct lov_stripe_md *lsm,
926 struct lov_oinfo *loi,
927 struct obd_io_group *oig)
932 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
933 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
935 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
939 static inline int obd_teardown_async_page(struct obd_export *exp,
940 struct lov_stripe_md *lsm,
941 struct lov_oinfo *loi, void *cookie)
946 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
947 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
949 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
953 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
954 int objcount, struct obd_ioobj *obj,
955 int niocount, struct niobuf_remote *remote,
956 struct niobuf_local *local,
957 struct obd_trans_info *oti)
962 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
963 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
965 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
970 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
971 int objcount, struct obd_ioobj *obj,
972 int niocount, struct niobuf_local *local,
973 struct obd_trans_info *oti, int rc)
977 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
978 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
980 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
985 static inline int obd_do_cow(struct obd_export *exp, struct obd_ioobj *obj,
986 int objcount,struct niobuf_remote *rnb)
991 /* there are cases when write_extents is not implemented. */
992 if (!OBP(exp->exp_obd, do_cow))
995 OBD_COUNTER_INCREMENT(exp->exp_obd, do_cow);
997 rc = OBP(exp->exp_obd, do_cow)(exp, obj, objcount, rnb);
1002 static inline int obd_write_extents(struct obd_export *exp,
1003 struct obd_ioobj *obj,
1004 int objcount, int niocount,
1005 struct niobuf_local *local,
1010 /* there are cases when write_extents is not implemented. */
1011 if (!OBP(exp->exp_obd, write_extents))
1014 OBD_COUNTER_INCREMENT(exp->exp_obd, write_extents);
1016 rc = OBP(exp->exp_obd, write_extents)(exp, obj, objcount, niocount,
1021 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
1022 int len, void *karg, void *uarg)
1027 EXP_CHECK_OP(exp, iocontrol);
1028 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
1030 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
1034 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
1035 __u32 type, ldlm_policy_data_t *policy,
1036 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
1037 void *gl_cb, void *data, __u32 lvb_len,
1038 void *lvb_swabber, struct lustre_handle *lockh)
1043 EXP_CHECK_OP(exp, enqueue);
1044 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1046 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
1047 bl_cb, cp_cb, gl_cb, data, lvb_len,
1048 lvb_swabber, lockh);
1052 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1053 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1054 int *flags, void *data, struct lustre_handle *lockh)
1059 EXP_CHECK_OP(exp, match);
1060 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1062 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1067 static inline int obd_change_cbdata(struct obd_export *exp,
1068 struct lov_stripe_md *lsm,
1069 ldlm_iterator_t it, void *data)
1074 EXP_CHECK_OP(exp, change_cbdata);
1075 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1077 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1081 static inline int obd_cancel(struct obd_export *exp,
1082 struct lov_stripe_md *ea, __u32 mode,
1083 struct lustre_handle *lockh)
1088 EXP_CHECK_OP(exp, cancel);
1089 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1091 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1095 static inline int obd_cancel_unused(struct obd_export *exp,
1096 struct lov_stripe_md *ea, int flags,
1102 EXP_CHECK_OP(exp, cancel_unused);
1103 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1105 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1110 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1112 int objcount, struct obd_ioobj *obj,
1113 int niocount, struct niobuf_remote *remote)
1117 EXP_CHECK_OP(exp, preprw);
1118 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1120 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1122 class_export_put(exp);
1126 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1127 int type, struct obd_client_handle *handle, int flag)
1131 EXP_CHECK_OP(exp, pin);
1132 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1134 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1138 static inline int obd_unpin(struct obd_export *exp,
1139 struct obd_client_handle *handle, int flag)
1143 EXP_CHECK_OP(exp, unpin);
1144 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1146 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1151 static inline void obd_import_event(struct obd_device *obd,
1152 struct obd_import *imp,
1153 enum obd_import_event event)
1155 if (obd->obd_set_up && OBP(obd, import_event)) {
1156 OBD_COUNTER_INCREMENT(obd, import_event);
1157 OBP(obd, import_event)(obd, imp, event);
1161 static inline int obd_llog_connect(struct obd_export *exp,
1162 struct llogd_conn_body *body)
1165 EXP_CHECK_OP(exp, llog_connect);
1166 return OBP(exp->exp_obd, llog_connect)(exp, body);
1169 static inline int obd_notify(struct obd_device *obd, struct obd_device *watched,
1170 int active, void *data)
1172 if (!obd->obd_set_up) {
1173 CERROR("obd %s not set up\n", obd->obd_name);
1177 if (!OBP(obd, notify)) {
1178 CERROR("obd %s has no notify handler\n", obd->obd_name);
1182 OBD_COUNTER_INCREMENT(obd, notify);
1183 return OBP(obd, notify)(obd, watched, active, data);
1186 static inline int obd_register_observer(struct obd_device *obd,
1187 struct obd_device *observer)
1190 if (obd->obd_observer && observer)
1192 obd->obd_observer = observer;
1196 static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
1200 LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
1201 OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1202 rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
1206 static inline int md_getstatus(struct obd_export *exp, struct lustre_id *id)
1210 EXP_CHECK_MD_OP(exp, getstatus);
1211 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1212 rc = MDP(exp->exp_obd, getstatus)(exp, id);
1216 /* this function notifies MDC, that inode described by @id gets removed from
1218 static inline int md_delete_object(struct obd_export *exp,
1219 struct lustre_id *id)
1224 /* as this method only notifies MDC that inode gets deleted, we can
1225 * return zero if method is not implemented, this means, that OBD does
1226 * not need such a notification. */
1227 if (MDP(exp->exp_obd, delete_object) == NULL)
1230 MD_COUNTER_INCREMENT(exp->exp_obd, delete_object);
1231 rc = MDP(exp->exp_obd, delete_object)(exp, id);
1235 static inline int md_getattr(struct obd_export *exp, struct lustre_id *id,
1236 unsigned long valid, unsigned int ea_size,
1237 struct ptlrpc_request **request)
1241 EXP_CHECK_MD_OP(exp, getattr);
1242 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1243 rc = MDP(exp->exp_obd, getattr)(exp, id, valid, ea_size, request);
1247 static inline int md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
1248 ldlm_iterator_t it, void *data)
1252 EXP_CHECK_MD_OP(exp, change_cbdata);
1253 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1254 rc = MDP(exp->exp_obd, change_cbdata)(exp, id, it, data);
1258 static inline int md_change_cbdata_name(struct obd_export *exp,
1259 struct lustre_id *id, char *name,
1260 int namelen, struct lustre_id *id2,
1261 ldlm_iterator_t it, void *data)
1265 /* this seem to be needed only for lmv. */
1266 if (!MDP(exp->exp_obd, change_cbdata_name))
1271 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
1272 rc = MDP(exp->exp_obd, change_cbdata_name)(exp, id, name, namelen,
1277 static inline int md_close(struct obd_export *exp, struct obdo *obdo,
1278 struct obd_client_handle *och,
1279 struct ptlrpc_request **request)
1283 EXP_CHECK_MD_OP(exp, close);
1284 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1285 rc = MDP(exp->exp_obd, close)(exp, obdo, och, request);
1289 static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1290 const void *data, int datalen, int mode,
1291 __u32 uid, __u32 gid, __u64 rdev,
1292 struct ptlrpc_request **request)
1296 EXP_CHECK_MD_OP(exp, create);
1297 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1298 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1299 uid, gid, rdev, request);
1303 static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
1307 EXP_CHECK_MD_OP(exp, done_writing);
1308 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1309 rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
1313 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1314 struct lookup_intent *it, int lock_mode,
1315 struct mdc_op_data *data,
1316 struct lustre_handle *lockh,
1317 void *lmm, int lmmsize,
1318 ldlm_completion_callback cb_completion,
1319 ldlm_blocking_callback cb_blocking,
1324 EXP_CHECK_MD_OP(exp, enqueue);
1325 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1326 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1327 data, lockh, lmm, lmmsize,
1328 cb_completion, cb_blocking,
1333 static inline int md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
1334 char *filename, int namelen,
1335 unsigned long valid, unsigned int ea_size,
1336 struct ptlrpc_request **request)
1340 EXP_CHECK_MD_OP(exp, getattr_lock);
1341 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_lock);
1342 rc = MDP(exp->exp_obd, getattr_lock)(exp, id, filename, namelen,
1343 valid, ea_size, request);
1347 static inline int md_intent_lock(struct obd_export *exp,
1348 struct lustre_id *pid, const char *name,
1349 int len, void *lmm, int lmmsize,
1350 struct lustre_id *cid, struct lookup_intent *it,
1351 int flags, struct ptlrpc_request **reqp,
1352 ldlm_blocking_callback cb_blocking)
1356 EXP_CHECK_MD_OP(exp, intent_lock);
1357 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1358 rc = MDP(exp->exp_obd, intent_lock)(exp, pid, name, len,
1359 lmm, lmmsize, cid, it, flags,
1364 static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
1365 struct ptlrpc_request **request)
1369 EXP_CHECK_MD_OP(exp, link);
1370 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1371 rc = MDP(exp->exp_obd, link)(exp, data, request);
1375 static inline int md_rename(struct obd_export *exp, struct mdc_op_data *data,
1376 const char *old, int oldlen,
1377 const char *new, int newlen,
1378 struct ptlrpc_request **request)
1382 EXP_CHECK_MD_OP(exp, rename);
1383 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1384 rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
1389 static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1390 struct iattr *iattr, void *ea, int ealen,
1391 void *ea2, int ea2len,
1392 struct ptlrpc_request **request)
1396 EXP_CHECK_MD_OP(exp, setattr);
1397 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1398 rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
1399 ea2, ea2len, request);
1403 static inline int md_sync(struct obd_export *exp, struct lustre_id *id,
1404 struct ptlrpc_request **request)
1408 EXP_CHECK_MD_OP(exp, sync);
1409 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1410 rc = MDP(exp->exp_obd, sync)(exp, id, request);
1414 static inline int md_readpage(struct obd_export *exp, struct lustre_id *id,
1415 __u64 offset, struct page *page,
1416 struct ptlrpc_request **request)
1420 EXP_CHECK_MD_OP(exp, readpage);
1421 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1422 rc = MDP(exp->exp_obd, readpage)(exp, id, offset, page, request);
1426 static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1427 struct ptlrpc_request **request)
1431 EXP_CHECK_MD_OP(exp, unlink);
1432 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1433 rc = MDP(exp->exp_obd, unlink)(exp, data, request);
1437 static inline struct obd_device *md_get_real_obd(struct obd_export *exp,
1438 char *name, int len)
1441 if (MDP(exp->exp_obd, get_real_obd) == NULL)
1442 return exp->exp_obd;
1443 MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
1444 return MDP(exp->exp_obd, get_real_obd)(exp, name, len);
1447 static inline int md_valid_attrs(struct obd_export *exp,
1448 struct lustre_id *id)
1451 EXP_CHECK_MD_OP(exp, valid_attrs);
1452 MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
1453 return MDP(exp->exp_obd, valid_attrs)(exp, id);
1456 static inline int md_req2lustre_md(struct obd_export *exp,
1457 struct ptlrpc_request *req,
1458 unsigned int offset,
1459 struct obd_export *osc_exp,
1460 struct lustre_md *md)
1463 EXP_CHECK_MD_OP(exp, req2lustre_md);
1464 MD_COUNTER_INCREMENT(exp->exp_obd, req2lustre_md);
1465 return MDP(exp->exp_obd, req2lustre_md)(exp, req, offset, osc_exp, md);
1468 static inline int md_set_open_replay_data(struct obd_export *exp,
1469 struct obd_client_handle *och,
1470 struct ptlrpc_request *open_req)
1473 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1474 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1475 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req);
1478 static inline int md_clear_open_replay_data(struct obd_export *exp,
1479 struct obd_client_handle *och)
1482 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1483 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1484 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1487 static inline int md_store_inode_generation(struct obd_export *exp,
1488 struct ptlrpc_request *req,
1489 int reqoff, int repoff)
1492 EXP_CHECK_MD_OP(exp, store_inode_generation);
1493 MD_COUNTER_INCREMENT(exp->exp_obd, store_inode_generation);
1494 return MDP(exp->exp_obd, store_inode_generation)(exp, req,
1498 static inline int md_set_lock_data(struct obd_export *exp, __u64 *l,
1502 EXP_CHECK_MD_OP(exp, set_lock_data);
1503 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1504 return MDP(exp->exp_obd, set_lock_data)(exp, l, data);
1507 /* OBD Metadata Support */
1509 extern int obd_init_caches(void);
1510 extern void obd_cleanup_caches(void);
1512 /* support routines */
1513 extern kmem_cache_t *obdo_cachep;
1514 static inline struct obdo *obdo_alloc(void)
1518 OBD_SLAB_ALLOC(oa, obdo_cachep, GFP_KERNEL,
1523 static inline void obdo_free(struct obdo *oa)
1527 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1530 static inline void obdo2id(struct lustre_id *id,
1534 id_ino(id) = oa->o_id;
1535 id_fid(id) = oa->o_fid;
1536 id_group(id) = oa->o_mds;
1537 id_gen(id) = oa->o_generation;
1540 static inline void id2obdo(struct obdo *oa,
1541 struct lustre_id *id)
1544 oa->o_id = id_ino(id);
1545 oa->o_fid = id_fid(id);
1546 oa->o_mds = id_group(id);
1547 oa->o_generation = id_gen(id);
1550 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1551 #define to_kdev_t(dev) dev
1552 #define kdev_t_to_nr(dev) dev
1555 /* I'm as embarrassed about this as you are.
1557 * <shaver> // XXX do not look into _superhack with remaining eye
1558 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1559 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1560 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1563 extern void obd_sysctl_init (void);
1564 extern void obd_sysctl_clean (void);
1567 typedef __u8 class_uuid_t[16];
1568 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1569 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1572 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1573 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1574 int class_del_uuid (char *uuid);
1575 void class_init_uuidlist(void);
1576 void class_exit_uuidlist(void);
1579 int mea_name2idx(struct mea *mea, char *name, int namelen);
1580 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1582 #endif /* __LINUX_OBD_CLASS_H */