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 <libcfs/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;
93 int class_config_process_llog(struct llog_ctxt *ctxt, char *name,
94 struct config_llog_instance *cfg);
95 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
96 struct config_llog_instance *cfg);
98 struct lustre_profile {
99 struct list_head lp_list;
105 struct lustre_profile *class_get_profile(char * prof);
106 void class_del_profile(char *prof);
108 #define class_export_rpc_get(exp) \
110 atomic_inc(&(exp)->exp_rpc_count); \
111 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
112 (exp), atomic_read(&(exp)->exp_rpc_count)); \
113 class_export_get(exp); \
116 #define class_export_rpc_put(exp) \
118 atomic_dec(&(exp)->exp_rpc_count); \
119 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
120 (exp), atomic_read(&(exp)->exp_rpc_count)); \
121 class_export_put(exp); \
124 #define class_export_get(exp) \
126 struct obd_export *exp_ = exp; \
127 atomic_inc(&exp_->exp_refcount); \
128 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
129 atomic_read(&exp_->exp_refcount)); \
133 #define class_export_put(exp) \
135 LASSERT((exp) != NULL); \
136 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
137 atomic_read(&(exp)->exp_refcount) - 1); \
138 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
139 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
140 __class_export_put(exp); \
143 void __class_export_put(struct obd_export *);
144 struct obd_export *class_new_export(struct obd_device *obddev);
145 void class_unlink_export(struct obd_export *exp);
147 struct obd_import *class_import_get(struct obd_import *);
148 void class_import_put(struct obd_import *);
149 struct obd_import *class_new_import(void);
150 void class_destroy_import(struct obd_import *exp);
152 struct obd_type *class_get_type(char *name);
153 void class_put_type(struct obd_type *type);
154 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
155 struct obd_uuid *cluuid);
156 int class_disconnect(struct obd_export *exp, unsigned long flags);
157 void class_disconnect_exports(struct obd_device *, unsigned long);
158 int class_disconnect_stale_exports(struct obd_device *,
159 int (*test_export)(struct obd_export *),
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_valid valid);
170 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_valid valid);
171 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_valid valid);
172 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_valid valid);
174 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_valid valid);
175 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_valid compare);
176 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
178 #define OBT(dev) (dev)->obd_type
179 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
180 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
181 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
183 /* Ensure obd_setup: used for cleanup which must be called
184 while obd is stopping */
185 #define OBD_CHECK_DEV(obd) \
188 CERROR("NULL device\n"); \
193 #define OBD_CHECK_DEV_STOPPING(obd) \
195 OBD_CHECK_DEV(obd); \
196 if (!(obd)->obd_set_up) { \
197 CERROR("Device %d not setup\n", \
202 if (!(obd)->obd_stopping) { \
203 CERROR("Device %d not stopping\n", \
209 /* ensure obd_setup and !obd_stopping */
210 #define OBD_CHECK_DEV_ACTIVE(obd) \
212 OBD_CHECK_DEV(obd); \
213 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
214 CERROR("Device %d not setup\n", \
222 #define OBD_COUNTER_OFFSET(op) \
223 ((offsetof(struct obd_ops, o_ ## op) - \
224 offsetof(struct obd_ops, o_iocontrol)) \
225 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
227 #define OBD_COUNTER_INCREMENT(obd, op) \
228 if ((obd)->obd_stats != NULL) { \
229 unsigned int coffset; \
230 coffset = (unsigned int)(obd)->obd_cntr_base + \
231 OBD_COUNTER_OFFSET(op); \
232 LASSERT(coffset < (obd)->obd_stats->ls_num); \
233 lprocfs_counter_incr((obd)->obd_stats, coffset);\
236 #define MD_COUNTER_OFFSET(op) \
237 ((offsetof(struct md_ops, m_ ## op) - \
238 offsetof(struct md_ops, m_getstatus)) \
239 / sizeof(((struct md_ops *)(0))->m_getstatus))
241 #define MD_COUNTER_INCREMENT(obd, op) \
242 if ((obd)->md_stats != NULL) { \
243 unsigned int coffset; \
244 coffset = (unsigned int)(obd)->md_cntr_base + \
245 MD_COUNTER_OFFSET(op); \
246 LASSERT(coffset < (obd)->md_stats->ls_num); \
247 lprocfs_counter_incr((obd)->md_stats, coffset); \
251 #define OBD_COUNTER_OFFSET(op)
252 #define OBD_COUNTER_INCREMENT(obd, op)
253 #define MD_COUNTER_INCREMENT(obd, op)
256 #define OBD_CHECK_MD_OP(obd, op, err) \
258 if (!OBT(obd) || !MDP((obd), op)) {\
260 CERROR("md_" #op ": dev %s/%d no operation\n", \
261 obd->obd_name, obd->obd_minor); \
266 #define EXP_CHECK_MD_OP(exp, op) \
268 if ((exp) == NULL) { \
269 CERROR("obd_" #op ": NULL export\n"); \
270 portals_debug_dumplog(); \
273 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
274 CERROR("obd_" #op ": cleaned up obd\n"); \
275 RETURN(-EOPNOTSUPP); \
277 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
278 CERROR("obd_" #op ": dev %s/%d no operation\n", \
279 (exp)->exp_obd->obd_name, \
280 (exp)->exp_obd->obd_minor); \
281 RETURN(-EOPNOTSUPP); \
285 #define OBD_CHECK_OP(obd, op, err) \
287 if (!OBT(obd) || !OBP((obd), op)) {\
289 CERROR("obd_" #op ": dev %s/%d no operation\n", \
290 obd->obd_name, obd->obd_minor); \
295 #define EXP_CHECK_OP(exp, op) \
297 if ((exp) == NULL) { \
298 CERROR("obd_" #op ": NULL export\n"); \
299 portals_debug_dumplog(); \
302 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
303 CERROR("obd_" #op ": cleaned up obd\n"); \
304 RETURN(-EOPNOTSUPP); \
306 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
307 CERROR("obd_" #op ": dev %s/%d no operation\n", \
308 (exp)->exp_obd->obd_name, \
309 (exp)->exp_obd->obd_minor); \
310 RETURN(-EOPNOTSUPP); \
314 #define CTXT_CHECK_OP(ctxt, op, err) \
316 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
318 CERROR("lop_" #op ": dev %d no operation\n", \
319 ctxt->loc_obd->obd_minor); \
324 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
325 void *key, __u32 *vallen, void *val)
330 EXP_CHECK_OP(exp, get_info);
331 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
333 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
337 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
338 void *key, obd_count vallen, void *val)
343 EXP_CHECK_OP(exp, set_info);
344 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
346 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
350 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
355 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
356 OBD_COUNTER_INCREMENT(obd, setup);
358 rc = OBP(obd, setup)(obd, datalen, data);
362 static inline int obd_precleanup(struct obd_device *obd, int flags)
367 OBD_CHECK_OP(obd, precleanup, 0);
368 OBD_COUNTER_INCREMENT(obd, precleanup);
370 rc = OBP(obd, precleanup)(obd, flags);
374 static inline int obd_cleanup(struct obd_device *obd, int flags)
379 OBD_CHECK_DEV_STOPPING(obd);
380 OBD_CHECK_OP(obd, cleanup, 0);
381 OBD_COUNTER_INCREMENT(obd, cleanup);
383 rc = OBP(obd, cleanup)(obd, flags);
388 obd_process_config(struct obd_device *obd, int datalen, void *data)
393 OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
394 OBD_COUNTER_INCREMENT(obd, process_config);
396 rc = OBP(obd, process_config)(obd, datalen, data);
400 /* Pack an in-memory MD struct for storage on disk.
401 * Returns +ve size of packed MD (0 for free), or -ve error.
403 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
404 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
405 * If @*disk_tgt == NULL, it will be allocated
407 static inline int obd_packmd(struct obd_export *exp,
408 struct lov_mds_md **disk_tgt,
409 struct lov_stripe_md *mem_src)
414 EXP_CHECK_OP(exp, packmd);
415 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
417 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
421 static inline int obd_size_diskmd(struct obd_export *exp,
422 struct lov_stripe_md *mem_src)
424 return obd_packmd(exp, NULL, mem_src);
427 /* helper functions */
428 static inline int obd_alloc_diskmd(struct obd_export *exp,
429 struct lov_mds_md **disk_tgt)
432 LASSERT(*disk_tgt == NULL);
433 return obd_packmd(exp, disk_tgt, NULL);
436 static inline int obd_free_diskmd(struct obd_export *exp,
437 struct lov_mds_md **disk_tgt)
441 return obd_packmd(exp, disk_tgt, NULL);
444 /* Unpack an MD struct from disk to in-memory format.
445 * Returns +ve size of unpacked MD (0 for free), or -ve error.
447 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
448 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
449 * If @*mem_tgt == NULL, it will be allocated
451 static inline int obd_unpackmd(struct obd_export *exp,
452 struct lov_stripe_md **mem_tgt,
453 struct lov_mds_md *disk_src,
459 EXP_CHECK_OP(exp, unpackmd);
460 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
462 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
466 /* helper functions */
467 static inline int obd_alloc_memmd(struct obd_export *exp,
468 struct lov_stripe_md **mem_tgt)
471 LASSERT(*mem_tgt == NULL);
472 return obd_unpackmd(exp, mem_tgt, NULL, 0);
475 static inline int obd_free_memmd(struct obd_export *exp,
476 struct lov_stripe_md **mem_tgt)
480 return obd_unpackmd(exp, mem_tgt, NULL, 0);
483 static inline int obd_revalidate_md(struct obd_export *exp, struct obdo *obdo,
484 struct lov_stripe_md *ea,
485 struct obd_trans_info *oti)
490 EXP_CHECK_OP(exp, revalidate_md);
491 OBD_COUNTER_INCREMENT(exp->exp_obd, revalidate_md);
493 rc = OBP(exp->exp_obd, revalidate_md)(exp, obdo, ea, oti);
497 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
498 struct lov_stripe_md **ea,
499 struct obd_trans_info *oti)
504 EXP_CHECK_OP(exp, create);
505 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
507 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
511 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
512 struct lov_stripe_md *ea,
513 struct obd_trans_info *oti)
518 EXP_CHECK_OP(exp, destroy);
519 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
521 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
525 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
526 struct lov_stripe_md *ea)
531 EXP_CHECK_OP(exp, getattr);
532 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
534 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
538 static inline int obd_getattr_async(struct obd_export *exp,
539 struct obdo *obdo, struct lov_stripe_md *ea,
540 struct ptlrpc_request_set *set)
545 EXP_CHECK_OP(exp, getattr);
546 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
548 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
552 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
553 struct lov_stripe_md *ea,
554 struct obd_trans_info *oti)
559 EXP_CHECK_OP(exp, setattr);
560 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
562 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
565 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
568 struct obd_device *obd = imp->imp_obd;
572 OBD_CHECK_DEV_ACTIVE(obd);
573 OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
574 OBD_COUNTER_INCREMENT(obd, add_conn);
576 rc = OBP(obd, add_conn)(imp, uuid, priority);
580 static inline int obd_del_conn(struct obd_import *imp,
581 struct obd_uuid *uuid)
583 struct obd_device *obd = imp->imp_obd;
587 OBD_CHECK_DEV_ACTIVE(obd);
588 OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
589 OBD_COUNTER_INCREMENT(obd, del_conn);
591 rc = OBP(obd, del_conn)(imp, uuid);
596 static inline int obd_connect(struct lustre_handle *conn,
597 struct obd_device *obd,
598 struct obd_uuid *cluuid,
599 struct obd_connect_data *data,
605 OBD_CHECK_DEV_ACTIVE(obd);
606 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
607 OBD_COUNTER_INCREMENT(obd, connect);
609 rc = OBP(obd, connect)(conn, obd, cluuid, data, flags);
613 static inline int obd_connect_post(struct obd_export *exp,
620 OBD_CHECK_DEV_ACTIVE(exp->exp_obd);
621 if (!OBT(exp->exp_obd) || !OBP((exp->exp_obd), connect_post))
623 OBD_COUNTER_INCREMENT(exp->exp_obd, connect_post);
624 rc = OBP(exp->exp_obd, connect_post)(exp, initial, flags);
628 static inline int obd_disconnect(struct obd_export *exp,
634 EXP_CHECK_OP(exp, disconnect);
635 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
637 rc = OBP(exp->exp_obd, disconnect)(exp, flags);
641 static inline int obd_getready(struct obd_export *exp)
646 if (!OBP(exp->exp_obd, getready))
648 rc = OBP(exp->exp_obd, getready)(exp);
652 static inline int obd_init_export(struct obd_export *exp)
657 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
658 OBP((exp)->exp_obd, init_export))
659 rc = OBP(exp->exp_obd, init_export)(exp);
663 static inline int obd_destroy_export(struct obd_export *exp)
666 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
667 OBP((exp)->exp_obd, destroy_export))
668 OBP(exp->exp_obd, destroy_export)(exp);
672 static inline struct dentry *
673 obd_lvfs_id2dentry(struct obd_export *exp, __u64 ino,
676 LASSERT(exp->exp_obd);
678 return lvfs_id2dentry(&exp->exp_obd->obd_lvfs_ctxt,
679 ino, gen, gr, exp->exp_obd);
683 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
686 /* @max_age is the oldest time in jiffies that we accept using a cached data.
687 * If the cache is older than @max_age we will get a new value from the
688 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
689 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
690 unsigned long max_age)
698 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
699 OBD_COUNTER_INCREMENT(obd, statfs);
701 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
702 if (time_before(obd->obd_osfs_age, max_age)) {
703 rc = OBP(obd, statfs)(obd, osfs, max_age);
705 spin_lock(&obd->obd_osfs_lock);
706 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
707 obd->obd_osfs_age = jiffies;
708 spin_unlock(&obd->obd_osfs_lock);
711 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
712 spin_lock(&obd->obd_osfs_lock);
713 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
714 spin_unlock(&obd->obd_osfs_lock);
719 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
720 struct lov_stripe_md *ea, obd_size start,
726 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
727 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
729 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
733 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
734 struct lov_stripe_md *ea, obd_size start,
735 obd_size end, struct obd_trans_info *oti)
740 EXP_CHECK_OP(exp, punch);
741 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
743 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
747 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
748 struct lov_stripe_md *ea, obd_count oa_bufs,
749 struct brw_page *pg, struct obd_trans_info *oti)
754 EXP_CHECK_OP(exp, brw);
755 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
757 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
758 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
759 "or OBD_BRW_CHECK\n");
763 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
767 static inline int obd_brw_async(int cmd, struct obd_export *exp,
768 struct obdo *oa, struct lov_stripe_md *ea,
769 obd_count oa_bufs, struct brw_page *pg,
770 struct ptlrpc_request_set *set,
771 struct obd_trans_info *oti)
776 EXP_CHECK_OP(exp, brw_async);
777 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
779 if (!(cmd & OBD_BRW_RWMASK)) {
780 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
784 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
789 static inline int obd_prep_async_page(struct obd_export *exp,
790 struct lov_stripe_md *lsm,
791 struct lov_oinfo *loi,
792 struct page *page, obd_off offset,
793 struct obd_async_page_ops *ops,
794 void *data, void **res)
799 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
800 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
802 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
807 static inline int obd_queue_async_io(struct obd_export *exp,
808 struct lov_stripe_md *lsm,
809 struct lov_oinfo *loi, void *cookie,
810 int cmd, obd_off off, int count,
811 obd_flags brw_flags, obd_flags async_flags)
816 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
817 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
818 LASSERT(cmd & OBD_BRW_RWMASK);
820 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
821 count, brw_flags, async_flags);
825 static inline int obd_set_async_flags(struct obd_export *exp,
826 struct lov_stripe_md *lsm,
827 struct lov_oinfo *loi, void *cookie,
828 obd_flags async_flags)
833 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
834 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
836 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
841 static inline int obd_queue_group_io(struct obd_export *exp,
842 struct lov_stripe_md *lsm,
843 struct lov_oinfo *loi,
844 struct obd_io_group *oig,
845 void *cookie, int cmd, obd_off off,
846 int count, obd_flags brw_flags,
847 obd_flags async_flags)
852 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
853 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
854 LASSERT(cmd & OBD_BRW_RWMASK);
856 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
857 cmd, off, count, brw_flags,
862 static inline int obd_trigger_group_io(struct obd_export *exp,
863 struct lov_stripe_md *lsm,
864 struct lov_oinfo *loi,
865 struct obd_io_group *oig)
870 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
871 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
873 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
877 static inline int obd_teardown_async_page(struct obd_export *exp,
878 struct lov_stripe_md *lsm,
879 struct lov_oinfo *loi, void *cookie)
884 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
885 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
887 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
891 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
892 int objcount, struct obd_ioobj *obj,
893 int niocount, struct niobuf_remote *remote,
894 struct niobuf_local *local,
895 struct obd_trans_info *oti)
900 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
901 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
903 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
908 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
909 int objcount, struct obd_ioobj *obj,
910 int niocount, struct niobuf_local *local,
911 struct obd_trans_info *oti, int rc)
915 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
916 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
918 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
923 static inline int obd_do_cow(struct obd_export *exp, struct obd_ioobj *obj,
924 int objcount,struct niobuf_remote *rnb)
929 /* there are cases when write_extents is not implemented. */
930 if (!OBP(exp->exp_obd, do_cow))
933 OBD_COUNTER_INCREMENT(exp->exp_obd, do_cow);
935 rc = OBP(exp->exp_obd, do_cow)(exp, obj, objcount, rnb);
940 static inline int obd_write_extents(struct obd_export *exp,
941 struct obd_ioobj *obj,
942 int objcount, int niocount,
943 struct niobuf_local *local,
948 /* there are cases when write_extents is not implemented. */
949 if (!OBP(exp->exp_obd, write_extents))
952 OBD_COUNTER_INCREMENT(exp->exp_obd, write_extents);
954 rc = OBP(exp->exp_obd, write_extents)(exp, obj, objcount, niocount,
959 static inline int obd_adjust_kms(struct obd_export *exp,
960 struct lov_stripe_md *lsm,
961 obd_off size, int shrink)
966 OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
967 OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
969 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
973 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
974 int len, void *karg, void *uarg)
979 EXP_CHECK_OP(exp, iocontrol);
980 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
982 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
986 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
987 __u32 type, ldlm_policy_data_t *policy,
988 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
989 void *gl_cb, void *data, __u32 lvb_len,
990 void *lvb_swabber, struct lustre_handle *lockh)
995 EXP_CHECK_OP(exp, enqueue);
996 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
998 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
999 bl_cb, cp_cb, gl_cb, data, lvb_len,
1000 lvb_swabber, lockh);
1004 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
1005 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
1006 int *flags, void *data, struct lustre_handle *lockh)
1011 EXP_CHECK_OP(exp, match);
1012 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1014 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1019 static inline int obd_change_cbdata(struct obd_export *exp,
1020 struct lov_stripe_md *lsm,
1021 ldlm_iterator_t it, void *data)
1026 EXP_CHECK_OP(exp, change_cbdata);
1027 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1029 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1033 static inline int obd_cancel(struct obd_export *exp,
1034 struct lov_stripe_md *ea, __u32 mode,
1035 struct lustre_handle *lockh)
1040 EXP_CHECK_OP(exp, cancel);
1041 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1043 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1047 static inline int obd_cancel_unused(struct obd_export *exp,
1048 struct lov_stripe_md *ea, int flags,
1054 EXP_CHECK_OP(exp, cancel_unused);
1055 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1057 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1062 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1064 int objcount, struct obd_ioobj *obj,
1065 int niocount, struct niobuf_remote *remote)
1069 EXP_CHECK_OP(exp, preprw);
1070 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1072 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1074 class_export_put(exp);
1078 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1079 int type, struct obd_client_handle *handle, int flag)
1083 EXP_CHECK_OP(exp, pin);
1084 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1086 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1090 static inline int obd_unpin(struct obd_export *exp,
1091 struct obd_client_handle *handle, int flag)
1095 EXP_CHECK_OP(exp, unpin);
1096 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1098 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1103 static inline void obd_import_event(struct obd_device *obd,
1104 struct obd_import *imp,
1105 enum obd_import_event event)
1108 CERROR("NULL device\n");
1112 if (obd->obd_set_up && OBP(obd, import_event)) {
1113 OBD_COUNTER_INCREMENT(obd, import_event);
1114 OBP(obd, import_event)(obd, imp, event);
1118 static inline int obd_llog_connect(struct obd_export *exp,
1119 struct llogd_conn_body *body)
1122 EXP_CHECK_OP(exp, llog_connect);
1123 return OBP(exp->exp_obd, llog_connect)(exp, body);
1126 static inline int obd_notify(struct obd_device *obd, struct obd_device *watched,
1127 int active, void *data)
1130 if (!obd->obd_set_up) {
1131 CERROR("obd %s not set up\n", obd->obd_name);
1135 if (!OBP(obd, notify)) {
1136 CERROR("obd %s has no notify handler\n", obd->obd_name);
1140 OBD_COUNTER_INCREMENT(obd, notify);
1141 return OBP(obd, notify)(obd, watched, active, data);
1144 static inline int obd_register_observer(struct obd_device *obd,
1145 struct obd_device *observer)
1149 if (obd->obd_observer && observer)
1151 obd->obd_observer = observer;
1155 static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
1159 LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
1160 OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1161 rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
1165 static inline int md_getstatus(struct obd_export *exp, struct lustre_id *id)
1169 EXP_CHECK_MD_OP(exp, getstatus);
1170 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1171 rc = MDP(exp->exp_obd, getstatus)(exp, id);
1175 static inline int md_delete_inode(struct obd_export *exp,
1176 struct lustre_id *id)
1181 if (MDP(exp->exp_obd, delete_inode) == NULL)
1184 MD_COUNTER_INCREMENT(exp->exp_obd, delete_inode);
1185 rc = MDP(exp->exp_obd, delete_inode)(exp, id);
1189 static inline int md_getattr(struct obd_export *exp, struct lustre_id *id,
1190 __u64 valid, const char *ea_name, int ea_namelen,
1191 unsigned int ea_size, struct ptlrpc_request **request)
1195 EXP_CHECK_MD_OP(exp, getattr);
1196 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1197 rc = MDP(exp->exp_obd, getattr)(exp, id, valid, ea_name, ea_namelen, ea_size, request);
1201 static inline int md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
1202 ldlm_iterator_t it, void *data)
1206 EXP_CHECK_MD_OP(exp, change_cbdata);
1207 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1208 rc = MDP(exp->exp_obd, change_cbdata)(exp, id, it, data);
1212 static inline int md_change_cbdata_name(struct obd_export *exp,
1213 struct lustre_id *id, char *name,
1214 int namelen, struct lustre_id *id2,
1215 ldlm_iterator_t it, void *data)
1219 /* this seem to be needed only for lmv. */
1220 if (!MDP(exp->exp_obd, change_cbdata_name))
1225 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
1226 rc = MDP(exp->exp_obd, change_cbdata_name)(exp, id, name, namelen,
1231 static inline int md_close(struct obd_export *exp, struct obdo *obdo,
1232 struct obd_client_handle *och,
1233 struct ptlrpc_request **request)
1237 EXP_CHECK_MD_OP(exp, close);
1238 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1239 rc = MDP(exp->exp_obd, close)(exp, obdo, och, request);
1243 static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1244 const void *data, int datalen, int mode,
1245 __u32 uid, __u32 gid, __u64 rdev,
1246 struct ptlrpc_request **request)
1250 EXP_CHECK_MD_OP(exp, create);
1251 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1252 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1253 uid, gid, rdev, request);
1257 static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
1261 EXP_CHECK_MD_OP(exp, done_writing);
1262 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1263 rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
1267 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1268 struct lookup_intent *it, int lock_mode,
1269 struct mdc_op_data *data,
1270 struct lustre_handle *lockh,
1271 void *lmm, int lmmsize,
1272 ldlm_completion_callback cb_completion,
1273 ldlm_blocking_callback cb_blocking,
1278 EXP_CHECK_MD_OP(exp, enqueue);
1279 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1280 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1281 data, lockh, lmm, lmmsize,
1282 cb_completion, cb_blocking,
1287 static inline int md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
1288 char *filename, int namelen,
1289 __u64 valid, unsigned int ea_size,
1290 struct ptlrpc_request **request)
1294 EXP_CHECK_MD_OP(exp, getattr_lock);
1295 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_lock);
1296 rc = MDP(exp->exp_obd, getattr_lock)(exp, id, filename, namelen,
1297 valid, ea_size, request);
1301 static inline int md_intent_lock(struct obd_export *exp,
1302 struct lustre_id *pid, const char *name,
1303 int len, void *lmm, int lmmsize,
1304 struct lustre_id *cid, struct lookup_intent *it,
1305 int flags, struct ptlrpc_request **reqp,
1306 ldlm_blocking_callback cb_blocking)
1310 EXP_CHECK_MD_OP(exp, intent_lock);
1311 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1312 rc = MDP(exp->exp_obd, intent_lock)(exp, pid, name, len,
1313 lmm, lmmsize, cid, it, flags,
1318 static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
1319 struct ptlrpc_request **request)
1323 EXP_CHECK_MD_OP(exp, link);
1324 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1325 rc = MDP(exp->exp_obd, link)(exp, data, request);
1329 static inline int md_rename(struct obd_export *exp, struct mdc_op_data *data,
1330 const char *old, int oldlen,
1331 const char *new, int newlen,
1332 struct ptlrpc_request **request)
1336 EXP_CHECK_MD_OP(exp, rename);
1337 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1338 rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
1343 static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1344 struct iattr *iattr, void *ea, int ealen,
1345 void *ea2, int ea2len,
1346 struct ptlrpc_request **request)
1350 EXP_CHECK_MD_OP(exp, setattr);
1351 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1352 rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
1353 ea2, ea2len, request);
1357 static inline int md_sync(struct obd_export *exp, struct lustre_id *id,
1358 struct ptlrpc_request **request)
1362 EXP_CHECK_MD_OP(exp, sync);
1363 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1364 rc = MDP(exp->exp_obd, sync)(exp, id, request);
1368 static inline int md_readpage(struct obd_export *exp, struct lustre_id *id,
1369 __u64 offset, struct page *page,
1370 struct ptlrpc_request **request)
1374 EXP_CHECK_MD_OP(exp, readpage);
1375 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1376 rc = MDP(exp->exp_obd, readpage)(exp, id, offset, page, request);
1380 static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1381 struct ptlrpc_request **request)
1385 EXP_CHECK_MD_OP(exp, unlink);
1386 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1387 rc = MDP(exp->exp_obd, unlink)(exp, data, request);
1391 static inline struct obd_device *md_get_real_obd(struct obd_export *exp,
1392 struct lustre_id *fid)
1395 if (MDP(exp->exp_obd, get_real_obd) == NULL)
1396 return exp->exp_obd;
1397 MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
1398 return MDP(exp->exp_obd, get_real_obd)(exp, fid);
1401 static inline int md_valid_attrs(struct obd_export *exp,
1402 struct lustre_id *id)
1405 EXP_CHECK_MD_OP(exp, valid_attrs);
1406 MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
1407 return MDP(exp->exp_obd, valid_attrs)(exp, id);
1410 static inline int md_req2lustre_md(struct obd_export *exp,
1411 struct ptlrpc_request *req,
1412 unsigned int offset,
1413 struct obd_export *osc_exp,
1414 struct lustre_md *md)
1417 EXP_CHECK_MD_OP(exp, req2lustre_md);
1418 MD_COUNTER_INCREMENT(exp->exp_obd, req2lustre_md);
1419 return MDP(exp->exp_obd, req2lustre_md)(exp, req, offset, osc_exp, md);
1422 static inline int md_set_open_replay_data(struct obd_export *exp,
1423 struct obd_client_handle *och,
1424 struct ptlrpc_request *open_req)
1427 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1428 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1429 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req);
1432 static inline int md_clear_open_replay_data(struct obd_export *exp,
1433 struct obd_client_handle *och)
1436 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1437 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1438 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1441 static inline int md_store_inode_generation(struct obd_export *exp,
1442 struct ptlrpc_request *req,
1443 int reqoff, int repoff)
1446 EXP_CHECK_MD_OP(exp, store_inode_generation);
1447 MD_COUNTER_INCREMENT(exp->exp_obd, store_inode_generation);
1448 return MDP(exp->exp_obd, store_inode_generation)(exp, req,
1452 static inline int md_set_lock_data(struct obd_export *exp, __u64 *l,
1456 EXP_CHECK_MD_OP(exp, set_lock_data);
1457 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1458 return MDP(exp->exp_obd, set_lock_data)(exp, l, data);
1461 /* OBD Metadata Support */
1463 extern int obd_init_caches(void);
1464 extern void obd_cleanup_caches(void);
1466 /* support routines */
1467 extern kmem_cache_t *obdo_cachep;
1468 static inline struct obdo *obdo_alloc(void)
1472 OBD_SLAB_ALLOC(oa, obdo_cachep, GFP_KERNEL,
1477 static inline void obdo_free(struct obdo *oa)
1479 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1482 static inline void obdo2id(struct lustre_id *id,
1486 id_ino(id) = oa->o_id;
1487 id_fid(id) = oa->o_fid;
1488 id_group(id) = oa->o_mds;
1489 id_gen(id) = oa->o_generation;
1492 static inline void id2obdo(struct obdo *oa,
1493 struct lustre_id *id)
1496 oa->o_id = id_ino(id);
1497 oa->o_fid = id_fid(id);
1498 oa->o_mds = id_group(id);
1499 oa->o_generation = id_gen(id);
1502 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1503 #define to_kdev_t(dev) dev
1504 #define kdev_t_to_nr(dev) dev
1507 /* I'm as embarrassed about this as you are.
1509 * <shaver> // XXX do not look into _superhack with remaining eye
1510 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1511 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1512 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1515 extern void obd_sysctl_init (void);
1516 extern void obd_sysctl_clean (void);
1519 typedef __u8 class_uuid_t[16];
1520 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1521 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1524 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1525 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1526 int class_del_uuid (char *uuid);
1527 void class_init_uuidlist(void);
1528 void class_exit_uuidlist(void);
1531 int mea_name2idx(struct mea *mea, char *name, int namelen);
1532 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1534 #endif /* __LINUX_OBD_CLASS_H */