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 #define OBD_CONF_DEVICENAME "confobd"
49 /* OBD Device Declarations */
50 #define MAX_OBD_DEVICES 256
51 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
52 extern spinlock_t obd_dev_lock;
54 /* OBD Operations Declarations */
55 extern struct obd_device *class_conn2obd(struct lustre_handle *);
56 extern struct obd_device *class_exp2obd(struct obd_export *);
59 struct obd_export *class_conn2export(struct lustre_handle *);
60 int class_register_type(struct obd_ops *ops, struct md_ops *md_ops,
61 struct lprocfs_vars *, char *nm);
62 int class_unregister_type(char *nm);
64 struct obd_device *class_newdev(struct obd_type *type);
65 void class_release_dev(struct obd_device *obd);
67 int class_name2dev(char *name);
68 struct obd_device *class_name2obd(char *name);
69 int class_uuid2dev(struct obd_uuid *uuid);
70 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
71 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
73 struct obd_uuid *grp_uuid);
74 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
77 int oig_init(struct obd_io_group **oig);
78 void oig_add_one(struct obd_io_group *oig,
79 struct oig_callback_context *occ);
80 void oig_complete_one(struct obd_io_group *oig,
81 struct oig_callback_context *occ, int rc);
82 void oig_release(struct obd_io_group *oig);
83 int oig_wait(struct obd_io_group *oig);
86 int class_process_config(struct lustre_cfg *lcfg);
88 /* Passed as data param to class_config_parse_handler() */
89 struct config_llog_instance {
91 struct obd_uuid cfg_uuid;
92 ptl_nid_t cfg_local_nid;
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, unsigned long flags);
159 void class_disconnect_exports(struct obd_device *, unsigned long);
160 int class_disconnect_stale_exports(struct obd_device *,
161 int (*test_export)(struct obd_export *),
164 /* generic operations shared by various OBD types */
165 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
166 int class_multi_cleanup(struct obd_device *obddev);
170 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
171 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_valid valid);
172 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_valid valid);
173 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_valid valid);
174 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_valid valid);
176 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_valid valid);
177 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_valid compare);
178 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
180 #define OBT(dev) (dev)->obd_type
181 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
182 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
183 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
185 /* Ensure obd_setup: used for cleanup which must be called
186 while obd is stopping */
187 #define OBD_CHECK_DEV(obd) \
190 CERROR("NULL device\n"); \
195 #define OBD_CHECK_DEV_STOPPING(obd) \
197 OBD_CHECK_DEV(obd); \
198 if (!(obd)->obd_set_up) { \
199 CERROR("Device %d not setup\n", \
204 if (!(obd)->obd_stopping) { \
205 CERROR("Device %d not stopping\n", \
211 /* ensure obd_setup and !obd_stopping */
212 #define OBD_CHECK_DEV_ACTIVE(obd) \
214 OBD_CHECK_DEV(obd); \
215 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
216 CERROR("Device %d not setup\n", \
224 #define OBD_COUNTER_OFFSET(op) \
225 ((offsetof(struct obd_ops, o_ ## op) - \
226 offsetof(struct obd_ops, o_iocontrol)) \
227 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
229 #define OBD_COUNTER_INCREMENT(obd, op) \
230 if ((obd)->obd_stats != NULL) { \
231 unsigned int coffset; \
232 coffset = (unsigned int)(obd)->obd_cntr_base + \
233 OBD_COUNTER_OFFSET(op); \
234 LASSERT(coffset < (obd)->obd_stats->ls_num); \
235 lprocfs_counter_incr((obd)->obd_stats, coffset);\
238 #define MD_COUNTER_OFFSET(op) \
239 ((offsetof(struct md_ops, m_ ## op) - \
240 offsetof(struct md_ops, m_getstatus)) \
241 / sizeof(((struct md_ops *)(0))->m_getstatus))
243 #define MD_COUNTER_INCREMENT(obd, op) \
244 if ((obd)->md_stats != NULL) { \
245 unsigned int coffset; \
246 coffset = (unsigned int)(obd)->md_cntr_base + \
247 MD_COUNTER_OFFSET(op); \
248 LASSERT(coffset < (obd)->md_stats->ls_num); \
249 lprocfs_counter_incr((obd)->md_stats, coffset); \
253 #define OBD_COUNTER_OFFSET(op)
254 #define OBD_COUNTER_INCREMENT(obd, op)
255 #define MD_COUNTER_INCREMENT(obd, op)
258 #define OBD_CHECK_MD_OP(obd, op, err) \
260 if (!OBT(obd) || !MDP((obd), op)) {\
262 CERROR("md_" #op ": dev %s/%d no operation\n", \
263 obd->obd_name, obd->obd_minor); \
268 #define EXP_CHECK_MD_OP(exp, op) \
270 if ((exp) == NULL) { \
271 CERROR("obd_" #op ": NULL export\n"); \
272 portals_debug_dumplog(); \
275 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
276 CERROR("obd_" #op ": cleaned up obd\n"); \
277 RETURN(-EOPNOTSUPP); \
279 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
280 CERROR("obd_" #op ": dev %s/%d no operation\n", \
281 (exp)->exp_obd->obd_name, \
282 (exp)->exp_obd->obd_minor); \
283 RETURN(-EOPNOTSUPP); \
287 #define OBD_CHECK_OP(obd, op, err) \
289 if (!OBT(obd) || !OBP((obd), op)) {\
291 CERROR("obd_" #op ": dev %s/%d no operation\n", \
292 obd->obd_name, obd->obd_minor); \
297 #define EXP_CHECK_OP(exp, op) \
299 if ((exp) == NULL) { \
300 CERROR("obd_" #op ": NULL export\n"); \
301 portals_debug_dumplog(); \
304 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
305 CERROR("obd_" #op ": cleaned up obd\n"); \
306 RETURN(-EOPNOTSUPP); \
308 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
309 CERROR("obd_" #op ": dev %s/%d no operation\n", \
310 (exp)->exp_obd->obd_name, \
311 (exp)->exp_obd->obd_minor); \
312 RETURN(-EOPNOTSUPP); \
316 #define CTXT_CHECK_OP(ctxt, op, err) \
318 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
320 CERROR("lop_" #op ": dev %d no operation\n", \
321 ctxt->loc_obd->obd_minor); \
326 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
327 void *key, __u32 *vallen, void *val)
332 EXP_CHECK_OP(exp, get_info);
333 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
335 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
339 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
340 void *key, obd_count vallen, void *val)
345 EXP_CHECK_OP(exp, set_info);
346 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
348 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
352 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
357 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
358 OBD_COUNTER_INCREMENT(obd, setup);
360 rc = OBP(obd, setup)(obd, datalen, data);
364 static inline int obd_precleanup(struct obd_device *obd, int flags)
369 OBD_CHECK_OP(obd, precleanup, 0);
370 OBD_COUNTER_INCREMENT(obd, precleanup);
372 rc = OBP(obd, precleanup)(obd, flags);
376 static inline int obd_cleanup(struct obd_device *obd, int flags)
381 OBD_CHECK_DEV_STOPPING(obd);
382 OBD_CHECK_OP(obd, cleanup, 0);
383 OBD_COUNTER_INCREMENT(obd, cleanup);
385 rc = OBP(obd, cleanup)(obd, flags);
390 obd_process_config(struct obd_device *obd, int datalen, void *data)
395 OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
396 OBD_COUNTER_INCREMENT(obd, process_config);
398 rc = OBP(obd, process_config)(obd, datalen, data);
402 /* Pack an in-memory MD struct for storage on disk.
403 * Returns +ve size of packed MD (0 for free), or -ve error.
405 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
406 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
407 * If @*disk_tgt == NULL, it will be allocated
409 static inline int obd_packmd(struct obd_export *exp,
410 struct lov_mds_md **disk_tgt,
411 struct lov_stripe_md *mem_src)
416 EXP_CHECK_OP(exp, packmd);
417 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
419 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
423 static inline int obd_size_diskmd(struct obd_export *exp,
424 struct lov_stripe_md *mem_src)
426 return obd_packmd(exp, NULL, mem_src);
429 /* helper functions */
430 static inline int obd_alloc_diskmd(struct obd_export *exp,
431 struct lov_mds_md **disk_tgt)
434 LASSERT(*disk_tgt == NULL);
435 return obd_packmd(exp, disk_tgt, NULL);
438 static inline int obd_free_diskmd(struct obd_export *exp,
439 struct lov_mds_md **disk_tgt)
443 return obd_packmd(exp, disk_tgt, NULL);
446 /* Unpack an MD struct from disk to in-memory format.
447 * Returns +ve size of unpacked MD (0 for free), or -ve error.
449 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
450 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
451 * If @*mem_tgt == NULL, it will be allocated
453 static inline int obd_unpackmd(struct obd_export *exp,
454 struct lov_stripe_md **mem_tgt,
455 struct lov_mds_md *disk_src,
461 EXP_CHECK_OP(exp, unpackmd);
462 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
464 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
468 /* helper functions */
469 static inline int obd_alloc_memmd(struct obd_export *exp,
470 struct lov_stripe_md **mem_tgt)
473 LASSERT(*mem_tgt == NULL);
474 return obd_unpackmd(exp, mem_tgt, NULL, 0);
477 static inline int obd_free_memmd(struct obd_export *exp,
478 struct lov_stripe_md **mem_tgt)
482 return obd_unpackmd(exp, mem_tgt, NULL, 0);
485 static inline int obd_revalidate_md(struct obd_export *exp, struct obdo *obdo,
486 struct lov_stripe_md *ea,
487 struct obd_trans_info *oti)
492 EXP_CHECK_OP(exp, revalidate_md);
493 OBD_COUNTER_INCREMENT(exp->exp_obd, revalidate_md);
495 rc = OBP(exp->exp_obd, revalidate_md)(exp, obdo, ea, oti);
499 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
500 void *acl, int acl_size,
501 struct lov_stripe_md **ea,
502 struct obd_trans_info *oti)
507 EXP_CHECK_OP(exp, create);
508 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
510 rc = OBP(exp->exp_obd, create)(exp, obdo, acl, acl_size, ea, oti);
514 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
515 struct lov_stripe_md *ea,
516 struct obd_trans_info *oti)
521 EXP_CHECK_OP(exp, destroy);
522 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
524 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
528 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
529 struct lov_stripe_md *ea)
534 EXP_CHECK_OP(exp, getattr);
535 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
537 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
541 static inline int obd_getattr_async(struct obd_export *exp,
542 struct obdo *obdo, struct lov_stripe_md *ea,
543 struct ptlrpc_request_set *set)
548 EXP_CHECK_OP(exp, getattr);
549 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
551 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
555 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
556 struct lov_stripe_md *ea,
557 struct obd_trans_info *oti)
562 EXP_CHECK_OP(exp, setattr);
563 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
565 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
568 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
571 struct obd_device *obd = imp->imp_obd;
575 OBD_CHECK_DEV_ACTIVE(obd);
576 OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
577 OBD_COUNTER_INCREMENT(obd, add_conn);
579 rc = OBP(obd, add_conn)(imp, uuid, priority);
583 static inline int obd_del_conn(struct obd_import *imp,
584 struct obd_uuid *uuid)
586 struct obd_device *obd = imp->imp_obd;
590 OBD_CHECK_DEV_ACTIVE(obd);
591 OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
592 OBD_COUNTER_INCREMENT(obd, del_conn);
594 rc = OBP(obd, del_conn)(imp, uuid);
599 static inline int obd_connect(struct lustre_handle *conn,
600 struct obd_device *obd,
601 struct obd_uuid *cluuid,
602 struct obd_connect_data *data,
608 OBD_CHECK_DEV_ACTIVE(obd);
609 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
610 OBD_COUNTER_INCREMENT(obd, connect);
612 rc = OBP(obd, connect)(conn, obd, cluuid, data, flags);
616 static inline int obd_connect_post(struct obd_export *exp,
623 OBD_CHECK_DEV_ACTIVE(exp->exp_obd);
624 if (!OBT(exp->exp_obd) || !OBP((exp->exp_obd), connect_post))
626 OBD_COUNTER_INCREMENT(exp->exp_obd, connect_post);
627 rc = OBP(exp->exp_obd, connect_post)(exp, initial, flags);
631 static inline int obd_disconnect(struct obd_export *exp,
637 EXP_CHECK_OP(exp, disconnect);
638 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
640 rc = OBP(exp->exp_obd, disconnect)(exp, flags);
644 static inline int obd_init_export(struct obd_export *exp)
649 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
650 OBP((exp)->exp_obd, init_export))
651 rc = OBP(exp->exp_obd, init_export)(exp);
655 static inline int obd_destroy_export(struct obd_export *exp)
658 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
659 OBP((exp)->exp_obd, destroy_export))
660 OBP(exp->exp_obd, destroy_export)(exp);
664 static inline struct dentry *
665 obd_lvfs_id2dentry(struct obd_export *exp, __u64 ino,
668 LASSERT(exp->exp_obd);
670 return lvfs_id2dentry(&exp->exp_obd->obd_lvfs_ctxt,
671 ino, gen, gr, exp->exp_obd);
675 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
678 /* @max_age is the oldest time in jiffies that we accept using a cached data.
679 * If the cache is older than @max_age we will get a new value from the
680 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
681 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
682 unsigned long max_age)
690 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
691 OBD_COUNTER_INCREMENT(obd, statfs);
693 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
694 if (time_before(obd->obd_osfs_age, max_age)) {
695 rc = OBP(obd, statfs)(obd, osfs, max_age);
697 spin_lock(&obd->obd_osfs_lock);
698 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
699 obd->obd_osfs_age = jiffies;
700 spin_unlock(&obd->obd_osfs_lock);
703 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
704 spin_lock(&obd->obd_osfs_lock);
705 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
706 spin_unlock(&obd->obd_osfs_lock);
711 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
712 struct lov_stripe_md *ea, obd_size start,
718 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
719 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
721 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
725 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
726 struct lov_stripe_md *ea, obd_size start,
727 obd_size end, struct obd_trans_info *oti)
732 EXP_CHECK_OP(exp, punch);
733 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
735 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
739 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
740 struct lov_stripe_md *ea, obd_count oa_bufs,
741 struct brw_page *pg, struct obd_trans_info *oti)
746 EXP_CHECK_OP(exp, brw);
747 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
749 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
750 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
751 "or OBD_BRW_CHECK\n");
755 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
759 static inline int obd_brw_async(int cmd, struct obd_export *exp,
760 struct obdo *oa, struct lov_stripe_md *ea,
761 obd_count oa_bufs, struct brw_page *pg,
762 struct ptlrpc_request_set *set,
763 struct obd_trans_info *oti)
768 EXP_CHECK_OP(exp, brw_async);
769 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
771 if (!(cmd & OBD_BRW_RWMASK)) {
772 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
776 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
781 static inline int obd_prep_async_page(struct obd_export *exp,
782 struct lov_stripe_md *lsm,
783 struct lov_oinfo *loi,
784 struct page *page, obd_off offset,
785 struct obd_async_page_ops *ops,
786 void *data, void **res)
791 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
792 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
794 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
799 static inline int obd_queue_async_io(struct obd_export *exp,
800 struct lov_stripe_md *lsm,
801 struct lov_oinfo *loi, void *cookie,
802 int cmd, obd_off off, int count,
803 obd_flags brw_flags, obd_flags async_flags)
808 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
809 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
810 LASSERT(cmd & OBD_BRW_RWMASK);
812 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
813 count, brw_flags, async_flags);
817 static inline int obd_set_async_flags(struct obd_export *exp,
818 struct lov_stripe_md *lsm,
819 struct lov_oinfo *loi, void *cookie,
820 obd_flags async_flags)
825 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
826 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
828 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
833 static inline int obd_queue_group_io(struct obd_export *exp,
834 struct lov_stripe_md *lsm,
835 struct lov_oinfo *loi,
836 struct obd_io_group *oig,
837 void *cookie, int cmd, obd_off off,
838 int count, obd_flags brw_flags,
839 obd_flags async_flags)
844 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
845 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
846 LASSERT(cmd & OBD_BRW_RWMASK);
848 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
849 cmd, off, count, brw_flags,
854 static inline int obd_trigger_group_io(struct obd_export *exp,
855 struct lov_stripe_md *lsm,
856 struct lov_oinfo *loi,
857 struct obd_io_group *oig)
862 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
863 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
865 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
869 static inline int obd_teardown_async_page(struct obd_export *exp,
870 struct lov_stripe_md *lsm,
871 struct lov_oinfo *loi, void *cookie)
876 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
877 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
879 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
883 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
884 int objcount, struct obd_ioobj *obj,
885 int niocount, struct niobuf_remote *remote,
886 struct niobuf_local *local,
887 struct obd_trans_info *oti)
892 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
893 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
895 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
900 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
901 int objcount, struct obd_ioobj *obj,
902 int niocount, struct niobuf_local *local,
903 struct obd_trans_info *oti, int rc)
907 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
908 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
910 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
915 static inline int obd_do_cow(struct obd_export *exp, struct obd_ioobj *obj,
916 int objcount,struct niobuf_remote *rnb)
921 /* there are cases when write_extents is not implemented. */
922 if (!OBP(exp->exp_obd, do_cow))
925 OBD_COUNTER_INCREMENT(exp->exp_obd, do_cow);
927 rc = OBP(exp->exp_obd, do_cow)(exp, obj, objcount, rnb);
932 static inline int obd_write_extents(struct obd_export *exp,
933 struct obd_ioobj *obj,
934 int objcount, int niocount,
935 struct niobuf_local *local,
940 /* there are cases when write_extents is not implemented. */
941 if (!OBP(exp->exp_obd, write_extents))
944 OBD_COUNTER_INCREMENT(exp->exp_obd, write_extents);
946 rc = OBP(exp->exp_obd, write_extents)(exp, obj, objcount, niocount,
951 static inline int obd_adjust_kms(struct obd_export *exp,
952 struct lov_stripe_md *lsm,
953 obd_off size, int shrink)
958 OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
959 OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
961 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
965 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
966 int len, void *karg, void *uarg)
971 EXP_CHECK_OP(exp, iocontrol);
972 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
974 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
978 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
979 __u32 type, ldlm_policy_data_t *policy,
980 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
981 void *gl_cb, void *data, __u32 lvb_len,
982 void *lvb_swabber, struct lustre_handle *lockh)
987 EXP_CHECK_OP(exp, enqueue);
988 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
990 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
991 bl_cb, cp_cb, gl_cb, data, lvb_len,
996 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
997 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
998 int *flags, void *data, struct lustre_handle *lockh)
1003 EXP_CHECK_OP(exp, match);
1004 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1006 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1011 static inline int obd_change_cbdata(struct obd_export *exp,
1012 struct lov_stripe_md *lsm,
1013 ldlm_iterator_t it, void *data)
1018 EXP_CHECK_OP(exp, change_cbdata);
1019 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1021 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1025 static inline int obd_cancel(struct obd_export *exp,
1026 struct lov_stripe_md *ea, __u32 mode,
1027 struct lustre_handle *lockh)
1032 EXP_CHECK_OP(exp, cancel);
1033 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1035 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1039 static inline int obd_cancel_unused(struct obd_export *exp,
1040 struct lov_stripe_md *ea, int flags,
1046 EXP_CHECK_OP(exp, cancel_unused);
1047 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1049 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1054 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1056 int objcount, struct obd_ioobj *obj,
1057 int niocount, struct niobuf_remote *remote)
1061 EXP_CHECK_OP(exp, preprw);
1062 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1064 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1066 class_export_put(exp);
1070 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1071 int type, struct obd_client_handle *handle, int flag)
1075 EXP_CHECK_OP(exp, pin);
1076 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1078 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1082 static inline int obd_unpin(struct obd_export *exp,
1083 struct obd_client_handle *handle, int flag)
1087 EXP_CHECK_OP(exp, unpin);
1088 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1090 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1095 static inline void obd_import_event(struct obd_device *obd,
1096 struct obd_import *imp,
1097 enum obd_import_event event)
1100 CERROR("NULL device\n");
1104 if (obd->obd_set_up && OBP(obd, import_event)) {
1105 OBD_COUNTER_INCREMENT(obd, import_event);
1106 OBP(obd, import_event)(obd, imp, event);
1110 static inline int obd_llog_connect(struct obd_export *exp,
1111 struct llogd_conn_body *body)
1114 EXP_CHECK_OP(exp, llog_connect);
1115 return OBP(exp->exp_obd, llog_connect)(exp, body);
1118 static inline int obd_notify(struct obd_device *obd, struct obd_device *watched,
1119 int active, void *data)
1122 if (!obd->obd_set_up) {
1123 CERROR("obd %s not set up\n", obd->obd_name);
1127 if (!OBP(obd, notify)) {
1128 CERROR("obd %s has no notify handler\n", obd->obd_name);
1132 OBD_COUNTER_INCREMENT(obd, notify);
1133 return OBP(obd, notify)(obd, watched, active, data);
1136 static inline int obd_register_observer(struct obd_device *obd,
1137 struct obd_device *observer)
1141 if (obd->obd_observer && observer)
1143 obd->obd_observer = observer;
1147 static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
1151 LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
1152 OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1153 rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
1157 static inline int md_getstatus(struct obd_export *exp, struct lustre_id *id)
1161 EXP_CHECK_MD_OP(exp, getstatus);
1162 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1163 rc = MDP(exp->exp_obd, getstatus)(exp, id);
1167 static inline int md_delete_inode(struct obd_export *exp,
1168 struct lustre_id *id)
1173 if (MDP(exp->exp_obd, delete_inode) == NULL)
1176 MD_COUNTER_INCREMENT(exp->exp_obd, delete_inode);
1177 rc = MDP(exp->exp_obd, delete_inode)(exp, id);
1181 static inline int md_getattr(struct obd_export *exp, struct lustre_id *id,
1182 __u64 valid, const char *xattr_name,
1183 unsigned int ea_size,
1184 struct ptlrpc_request **request)
1188 EXP_CHECK_MD_OP(exp, getattr);
1189 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1190 rc = MDP(exp->exp_obd, getattr)(exp, id, valid, xattr_name,
1195 static inline int md_access_check(struct obd_export *exp, struct lustre_id *id,
1196 struct ptlrpc_request **request)
1200 EXP_CHECK_MD_OP(exp, access_check);
1201 MD_COUNTER_INCREMENT(exp->exp_obd, access_check);
1202 rc = MDP(exp->exp_obd, access_check)(exp, id, request);
1206 static inline int md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
1207 ldlm_iterator_t it, void *data)
1211 EXP_CHECK_MD_OP(exp, change_cbdata);
1212 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1213 rc = MDP(exp->exp_obd, change_cbdata)(exp, id, it, data);
1217 static inline int md_change_cbdata_name(struct obd_export *exp,
1218 struct lustre_id *id, char *name,
1219 int namelen, struct lustre_id *id2,
1220 ldlm_iterator_t it, void *data)
1224 /* this seem to be needed only for lmv. */
1225 if (!MDP(exp->exp_obd, change_cbdata_name))
1230 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
1231 rc = MDP(exp->exp_obd, change_cbdata_name)(exp, id, name, namelen,
1236 static inline int md_close(struct obd_export *exp, struct obdo *obdo,
1237 struct obd_client_handle *och,
1238 struct ptlrpc_request **request)
1242 EXP_CHECK_MD_OP(exp, close);
1243 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1244 rc = MDP(exp->exp_obd, close)(exp, obdo, och, request);
1248 static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1249 const void *data, int datalen, int mode,
1250 __u32 uid, __u32 gid, __u64 rdev,
1251 struct ptlrpc_request **request)
1255 EXP_CHECK_MD_OP(exp, create);
1256 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1257 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1258 uid, gid, rdev, request);
1262 static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
1266 EXP_CHECK_MD_OP(exp, done_writing);
1267 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1268 rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
1272 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1273 struct lookup_intent *it, int lock_mode,
1274 struct mdc_op_data *data,
1275 struct lustre_handle *lockh,
1276 void *lmm, int lmmsize,
1277 ldlm_completion_callback cb_completion,
1278 ldlm_blocking_callback cb_blocking,
1283 EXP_CHECK_MD_OP(exp, enqueue);
1284 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1285 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1286 data, lockh, lmm, lmmsize,
1287 cb_completion, cb_blocking,
1292 static inline int md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
1293 char *filename, int namelen,
1294 __u64 valid, unsigned int ea_size,
1295 struct ptlrpc_request **request)
1299 EXP_CHECK_MD_OP(exp, getattr_lock);
1300 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_lock);
1301 rc = MDP(exp->exp_obd, getattr_lock)(exp, id, filename, namelen,
1302 valid, ea_size, request);
1306 static inline int md_intent_lock(struct obd_export *exp,
1307 struct lustre_id *pid, const char *name,
1308 int len, void *lmm, int lmmsize,
1309 struct lustre_id *cid, struct lookup_intent *it,
1310 int flags, struct ptlrpc_request **reqp,
1311 ldlm_blocking_callback cb_blocking)
1315 EXP_CHECK_MD_OP(exp, intent_lock);
1316 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1317 rc = MDP(exp->exp_obd, intent_lock)(exp, pid, name, len,
1318 lmm, lmmsize, cid, it, flags,
1323 static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
1324 struct ptlrpc_request **request)
1328 EXP_CHECK_MD_OP(exp, link);
1329 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1330 rc = MDP(exp->exp_obd, link)(exp, data, request);
1334 static inline int md_rename(struct obd_export *exp, struct mdc_op_data *data,
1335 const char *old, int oldlen,
1336 const char *new, int newlen,
1337 struct ptlrpc_request **request)
1341 EXP_CHECK_MD_OP(exp, rename);
1342 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1343 rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
1348 static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1349 struct iattr *iattr, void *ea, int ealen,
1350 void *ea2, int ea2len,
1351 struct ptlrpc_request **request)
1355 EXP_CHECK_MD_OP(exp, setattr);
1356 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1357 rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
1358 ea2, ea2len, request);
1362 static inline int md_sync(struct obd_export *exp, struct lustre_id *id,
1363 struct ptlrpc_request **request)
1367 EXP_CHECK_MD_OP(exp, sync);
1368 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1369 rc = MDP(exp->exp_obd, sync)(exp, id, request);
1373 static inline int md_readpage(struct obd_export *exp, struct lustre_id *id,
1374 __u64 offset, struct page *page,
1375 struct ptlrpc_request **request)
1379 EXP_CHECK_MD_OP(exp, readpage);
1380 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1381 rc = MDP(exp->exp_obd, readpage)(exp, id, offset, page, request);
1385 static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1386 struct ptlrpc_request **request)
1390 EXP_CHECK_MD_OP(exp, unlink);
1391 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1392 rc = MDP(exp->exp_obd, unlink)(exp, data, request);
1396 static inline struct obd_device *md_get_real_obd(struct obd_export *exp,
1397 struct lustre_id *fid)
1400 if (MDP(exp->exp_obd, get_real_obd) == NULL)
1401 return exp->exp_obd;
1402 MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
1403 return MDP(exp->exp_obd, get_real_obd)(exp, fid);
1406 static inline int md_valid_attrs(struct obd_export *exp,
1407 struct lustre_id *id)
1410 EXP_CHECK_MD_OP(exp, valid_attrs);
1411 MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
1412 return MDP(exp->exp_obd, valid_attrs)(exp, id);
1415 static inline int md_req2lustre_md(struct obd_export *exp,
1416 struct ptlrpc_request *req,
1417 unsigned int offset,
1418 struct obd_export *osc_exp,
1419 struct lustre_md *md)
1422 EXP_CHECK_MD_OP(exp, req2lustre_md);
1423 MD_COUNTER_INCREMENT(exp->exp_obd, req2lustre_md);
1424 return MDP(exp->exp_obd, req2lustre_md)(exp, req, offset, osc_exp, md);
1427 static inline int md_set_open_replay_data(struct obd_export *exp,
1428 struct obd_client_handle *och,
1429 struct ptlrpc_request *open_req)
1432 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1433 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1434 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req);
1437 static inline int md_clear_open_replay_data(struct obd_export *exp,
1438 struct obd_client_handle *och)
1441 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1442 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1443 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1446 static inline int md_store_inode_generation(struct obd_export *exp,
1447 struct ptlrpc_request *req,
1448 int reqoff, int repoff)
1451 EXP_CHECK_MD_OP(exp, store_inode_generation);
1452 MD_COUNTER_INCREMENT(exp->exp_obd, store_inode_generation);
1453 return MDP(exp->exp_obd, store_inode_generation)(exp, req,
1457 static inline int md_set_lock_data(struct obd_export *exp, __u64 *l,
1461 EXP_CHECK_MD_OP(exp, set_lock_data);
1462 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1463 return MDP(exp->exp_obd, set_lock_data)(exp, l, data);
1466 /* OBD Metadata Support */
1468 extern int obd_init_caches(void);
1469 extern void obd_cleanup_caches(void);
1471 /* support routines */
1472 extern kmem_cache_t *obdo_cachep;
1473 static inline struct obdo *obdo_alloc(void)
1477 OBD_SLAB_ALLOC(oa, obdo_cachep, GFP_KERNEL,
1482 static inline void obdo_free(struct obdo *oa)
1484 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1487 static inline void obdo2id(struct lustre_id *id,
1491 id_ino(id) = oa->o_id;
1492 id_fid(id) = oa->o_fid;
1493 id_group(id) = oa->o_mds;
1494 id_gen(id) = oa->o_generation;
1497 static inline void id2obdo(struct obdo *oa,
1498 struct lustre_id *id)
1501 oa->o_id = id_ino(id);
1502 oa->o_fid = id_fid(id);
1503 oa->o_mds = id_group(id);
1504 oa->o_generation = id_gen(id);
1507 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1508 #define to_kdev_t(dev) dev
1509 #define kdev_t_to_nr(dev) dev
1512 /* I'm as embarrassed about this as you are.
1514 * <shaver> // XXX do not look into _superhack with remaining eye
1515 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1516 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1517 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1520 extern void obd_sysctl_init (void);
1521 extern void obd_sysctl_clean (void);
1524 typedef __u8 class_uuid_t[16];
1525 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1526 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1529 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1530 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1531 int class_del_uuid (char *uuid);
1532 void class_init_uuidlist(void);
1533 void class_exit_uuidlist(void);
1536 int mea_name2idx(struct mea *mea, char *name, int namelen);
1537 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1539 #endif /* __LINUX_OBD_CLASS_H */