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;
106 struct lustre_profile *class_get_profile(char * prof);
107 void class_del_profile(char *prof);
109 #define class_export_rpc_get(exp) \
111 atomic_inc(&(exp)->exp_rpc_count); \
112 CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n", \
113 (exp), atomic_read(&(exp)->exp_rpc_count)); \
114 class_export_get(exp); \
117 #define class_export_rpc_put(exp) \
119 atomic_dec(&(exp)->exp_rpc_count); \
120 CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n", \
121 (exp), atomic_read(&(exp)->exp_rpc_count)); \
122 class_export_put(exp); \
125 #define class_export_get(exp) \
127 struct obd_export *exp_ = exp; \
128 atomic_inc(&exp_->exp_refcount); \
129 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
130 atomic_read(&exp_->exp_refcount)); \
134 #define class_export_put(exp) \
136 LASSERT((exp) != NULL); \
137 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
138 atomic_read(&(exp)->exp_refcount) - 1); \
139 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
140 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
141 __class_export_put(exp); \
144 void __class_export_put(struct obd_export *);
145 struct obd_export *class_new_export(struct obd_device *obddev);
146 void class_unlink_export(struct obd_export *exp);
148 struct obd_import *class_import_get(struct obd_import *);
149 void class_import_put(struct obd_import *);
150 struct obd_import *class_new_import(void);
151 void class_destroy_import(struct obd_import *exp);
153 struct obd_type *class_get_type(char *name);
154 void class_put_type(struct obd_type *type);
155 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
156 struct obd_uuid *cluuid);
157 int class_disconnect(struct obd_export *exp, unsigned long flags);
158 void class_disconnect_exports(struct obd_device *, unsigned long);
159 int class_disconnect_stale_exports(struct obd_device *,
160 int (*test_export)(struct obd_export *),
163 /* generic operations shared by various OBD types */
164 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
165 int class_multi_cleanup(struct obd_device *obddev);
169 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
170 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_valid valid);
171 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_valid valid);
172 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_valid valid);
173 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_valid valid);
175 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_valid valid);
176 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_valid compare);
177 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
179 #define OBT(dev) (dev)->obd_type
180 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
181 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
182 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
184 /* Ensure obd_setup: used for cleanup which must be called
185 while obd is stopping */
186 #define OBD_CHECK_DEV(obd) \
189 CERROR("NULL device\n"); \
194 #define OBD_CHECK_DEV_STOPPING(obd) \
196 OBD_CHECK_DEV(obd); \
197 if (!(obd)->obd_set_up) { \
198 CERROR("Device %d not setup\n", \
203 if (!(obd)->obd_stopping) { \
204 CERROR("Device %d not stopping\n", \
210 /* ensure obd_setup and !obd_stopping */
211 #define OBD_CHECK_DEV_ACTIVE(obd) \
213 OBD_CHECK_DEV(obd); \
214 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
215 CERROR("Device %d not setup\n", \
223 #define OBD_COUNTER_OFFSET(op) \
224 ((offsetof(struct obd_ops, o_ ## op) - \
225 offsetof(struct obd_ops, o_iocontrol)) \
226 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
228 #define OBD_COUNTER_INCREMENT(obd, op) \
229 if ((obd)->obd_stats != NULL) { \
230 unsigned int coffset; \
231 coffset = (unsigned int)(obd)->obd_cntr_base + \
232 OBD_COUNTER_OFFSET(op); \
233 LASSERT(coffset < (obd)->obd_stats->ls_num); \
234 lprocfs_counter_incr((obd)->obd_stats, coffset);\
237 #define MD_COUNTER_OFFSET(op) \
238 ((offsetof(struct md_ops, m_ ## op) - \
239 offsetof(struct md_ops, m_getstatus)) \
240 / sizeof(((struct md_ops *)(0))->m_getstatus))
242 #define MD_COUNTER_INCREMENT(obd, op) \
243 if ((obd)->md_stats != NULL) { \
244 unsigned int coffset; \
245 coffset = (unsigned int)(obd)->md_cntr_base + \
246 MD_COUNTER_OFFSET(op); \
247 LASSERT(coffset < (obd)->md_stats->ls_num); \
248 lprocfs_counter_incr((obd)->md_stats, coffset); \
252 #define OBD_COUNTER_OFFSET(op)
253 #define OBD_COUNTER_INCREMENT(obd, op)
254 #define MD_COUNTER_INCREMENT(obd, op)
257 #define OBD_CHECK_MD_OP(obd, op, err) \
259 if (!OBT(obd) || !MDP((obd), op)) {\
261 CERROR("md_" #op ": dev %s/%d no operation\n", \
262 obd->obd_name, obd->obd_minor); \
267 #define EXP_CHECK_MD_OP(exp, op) \
269 if ((exp) == NULL) { \
270 CERROR("obd_" #op ": NULL export\n"); \
271 portals_debug_dumplog(); \
274 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
275 CERROR("obd_" #op ": cleaned up obd\n"); \
276 RETURN(-EOPNOTSUPP); \
278 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
279 CERROR("obd_" #op ": dev %s/%d no operation\n", \
280 (exp)->exp_obd->obd_name, \
281 (exp)->exp_obd->obd_minor); \
282 RETURN(-EOPNOTSUPP); \
286 #define OBD_CHECK_OP(obd, op, err) \
288 if (!OBT(obd) || !OBP((obd), op)) {\
290 CERROR("obd_" #op ": dev %s/%d no operation\n", \
291 obd->obd_name, obd->obd_minor); \
296 #define EXP_CHECK_OP(exp, op) \
298 if ((exp) == NULL) { \
299 CERROR("obd_" #op ": NULL export\n"); \
300 portals_debug_dumplog(); \
303 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
304 CERROR("obd_" #op ": cleaned up obd\n"); \
305 RETURN(-EOPNOTSUPP); \
307 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
308 CERROR("obd_" #op ": dev %s/%d no operation\n", \
309 (exp)->exp_obd->obd_name, \
310 (exp)->exp_obd->obd_minor); \
311 RETURN(-EOPNOTSUPP); \
315 #define CTXT_CHECK_OP(ctxt, op, err) \
317 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
319 CERROR("lop_" #op ": dev %d no operation\n", \
320 ctxt->loc_obd->obd_minor); \
325 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
326 void *key, __u32 *vallen, void *val)
331 EXP_CHECK_OP(exp, get_info);
332 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
334 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
338 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
339 void *key, obd_count vallen, void *val)
344 EXP_CHECK_OP(exp, set_info);
345 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
347 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
351 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
356 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
357 OBD_COUNTER_INCREMENT(obd, setup);
359 rc = OBP(obd, setup)(obd, datalen, data);
363 static inline int obd_precleanup(struct obd_device *obd, int flags)
368 OBD_CHECK_OP(obd, precleanup, 0);
369 OBD_COUNTER_INCREMENT(obd, precleanup);
371 rc = OBP(obd, precleanup)(obd, flags);
375 static inline int obd_cleanup(struct obd_device *obd, int flags)
380 OBD_CHECK_DEV_STOPPING(obd);
381 OBD_CHECK_OP(obd, cleanup, 0);
382 OBD_COUNTER_INCREMENT(obd, cleanup);
384 rc = OBP(obd, cleanup)(obd, flags);
389 obd_process_config(struct obd_device *obd, int datalen, void *data)
394 OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
395 OBD_COUNTER_INCREMENT(obd, process_config);
397 rc = OBP(obd, process_config)(obd, datalen, data);
401 /* Pack an in-memory MD struct for storage on disk.
402 * Returns +ve size of packed MD (0 for free), or -ve error.
404 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
405 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
406 * If @*disk_tgt == NULL, it will be allocated
408 static inline int obd_packmd(struct obd_export *exp,
409 struct lov_mds_md **disk_tgt,
410 struct lov_stripe_md *mem_src)
415 EXP_CHECK_OP(exp, packmd);
416 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
418 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
422 static inline int obd_size_diskmd(struct obd_export *exp,
423 struct lov_stripe_md *mem_src)
425 return obd_packmd(exp, NULL, mem_src);
428 /* helper functions */
429 static inline int obd_alloc_diskmd(struct obd_export *exp,
430 struct lov_mds_md **disk_tgt)
433 LASSERT(*disk_tgt == NULL);
434 return obd_packmd(exp, disk_tgt, NULL);
437 static inline int obd_free_diskmd(struct obd_export *exp,
438 struct lov_mds_md **disk_tgt)
442 return obd_packmd(exp, disk_tgt, NULL);
445 /* Unpack an MD struct from disk to in-memory format.
446 * Returns +ve size of unpacked MD (0 for free), or -ve error.
448 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
449 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
450 * If @*mem_tgt == NULL, it will be allocated
452 static inline int obd_unpackmd(struct obd_export *exp,
453 struct lov_stripe_md **mem_tgt,
454 struct lov_mds_md *disk_src,
460 EXP_CHECK_OP(exp, unpackmd);
461 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
463 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
467 /* helper functions */
468 static inline int obd_alloc_memmd(struct obd_export *exp,
469 struct lov_stripe_md **mem_tgt)
472 LASSERT(*mem_tgt == NULL);
473 return obd_unpackmd(exp, mem_tgt, NULL, 0);
476 static inline int obd_free_memmd(struct obd_export *exp,
477 struct lov_stripe_md **mem_tgt)
481 return obd_unpackmd(exp, mem_tgt, NULL, 0);
484 static inline int obd_revalidate_md(struct obd_export *exp, struct obdo *obdo,
485 struct lov_stripe_md *ea,
486 struct obd_trans_info *oti)
491 EXP_CHECK_OP(exp, revalidate_md);
492 OBD_COUNTER_INCREMENT(exp->exp_obd, revalidate_md);
494 rc = OBP(exp->exp_obd, revalidate_md)(exp, obdo, ea, oti);
498 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
499 void *acl, int acl_size,
500 struct lov_stripe_md **ea,
501 struct obd_trans_info *oti)
506 EXP_CHECK_OP(exp, create);
507 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
509 rc = OBP(exp->exp_obd, create)(exp, obdo, acl, acl_size, ea, oti);
513 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
514 struct lov_stripe_md *ea,
515 struct obd_trans_info *oti)
520 EXP_CHECK_OP(exp, destroy);
521 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
523 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
527 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
528 struct lov_stripe_md *ea)
533 EXP_CHECK_OP(exp, getattr);
534 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
536 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
540 static inline int obd_getattr_async(struct obd_export *exp,
541 struct obdo *obdo, struct lov_stripe_md *ea,
542 struct ptlrpc_request_set *set)
547 EXP_CHECK_OP(exp, getattr);
548 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
550 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
554 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
555 struct lov_stripe_md *ea,
556 struct obd_trans_info *oti)
561 EXP_CHECK_OP(exp, setattr);
562 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
564 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
567 static inline int obd_add_conn(struct obd_import *imp, struct obd_uuid *uuid,
570 struct obd_device *obd = imp->imp_obd;
574 OBD_CHECK_DEV_ACTIVE(obd);
575 OBD_CHECK_OP(obd, add_conn, -EOPNOTSUPP);
576 OBD_COUNTER_INCREMENT(obd, add_conn);
578 rc = OBP(obd, add_conn)(imp, uuid, priority);
582 static inline int obd_del_conn(struct obd_import *imp,
583 struct obd_uuid *uuid)
585 struct obd_device *obd = imp->imp_obd;
589 OBD_CHECK_DEV_ACTIVE(obd);
590 OBD_CHECK_OP(obd, del_conn, -EOPNOTSUPP);
591 OBD_COUNTER_INCREMENT(obd, del_conn);
593 rc = OBP(obd, del_conn)(imp, uuid);
598 static inline int obd_connect(struct lustre_handle *conn,
599 struct obd_device *obd,
600 struct obd_uuid *cluuid,
601 struct obd_connect_data *data,
607 OBD_CHECK_DEV_ACTIVE(obd);
608 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
609 OBD_COUNTER_INCREMENT(obd, connect);
611 rc = OBP(obd, connect)(conn, obd, cluuid, data, flags);
615 static inline int obd_connect_post(struct obd_export *exp,
622 OBD_CHECK_DEV_ACTIVE(exp->exp_obd);
623 if (!OBT(exp->exp_obd) || !OBP((exp->exp_obd), connect_post))
625 OBD_COUNTER_INCREMENT(exp->exp_obd, connect_post);
626 rc = OBP(exp->exp_obd, connect_post)(exp, initial, flags);
630 static inline int obd_disconnect(struct obd_export *exp,
636 EXP_CHECK_OP(exp, disconnect);
637 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
639 rc = OBP(exp->exp_obd, disconnect)(exp, flags);
643 static inline int obd_init_export(struct obd_export *exp)
648 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
649 OBP((exp)->exp_obd, init_export))
650 rc = OBP(exp->exp_obd, init_export)(exp);
654 static inline int obd_destroy_export(struct obd_export *exp)
657 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
658 OBP((exp)->exp_obd, destroy_export))
659 OBP(exp->exp_obd, destroy_export)(exp);
663 static inline struct dentry *
664 obd_lvfs_id2dentry(struct obd_export *exp, __u64 ino,
667 LASSERT(exp->exp_obd);
669 return lvfs_id2dentry(&exp->exp_obd->obd_lvfs_ctxt,
670 ino, gen, gr, exp->exp_obd);
674 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
677 /* @max_age is the oldest time in jiffies that we accept using a cached data.
678 * If the cache is older than @max_age we will get a new value from the
679 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
680 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
681 unsigned long max_age)
689 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
690 OBD_COUNTER_INCREMENT(obd, statfs);
692 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
693 if (time_before(obd->obd_osfs_age, max_age)) {
694 rc = OBP(obd, statfs)(obd, osfs, max_age);
696 spin_lock(&obd->obd_osfs_lock);
697 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
698 obd->obd_osfs_age = jiffies;
699 spin_unlock(&obd->obd_osfs_lock);
702 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
703 spin_lock(&obd->obd_osfs_lock);
704 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
705 spin_unlock(&obd->obd_osfs_lock);
710 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
711 struct lov_stripe_md *ea, obd_size start,
717 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
718 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
720 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
724 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
725 struct lov_stripe_md *ea, obd_size start,
726 obd_size end, struct obd_trans_info *oti)
731 EXP_CHECK_OP(exp, punch);
732 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
734 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
738 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
739 struct lov_stripe_md *ea, obd_count oa_bufs,
740 struct brw_page *pg, struct obd_trans_info *oti)
745 EXP_CHECK_OP(exp, brw);
746 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
748 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
749 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
750 "or OBD_BRW_CHECK\n");
754 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
758 static inline int obd_brw_async(int cmd, struct obd_export *exp,
759 struct obdo *oa, struct lov_stripe_md *ea,
760 obd_count oa_bufs, struct brw_page *pg,
761 struct ptlrpc_request_set *set,
762 struct obd_trans_info *oti)
767 EXP_CHECK_OP(exp, brw_async);
768 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
770 if (!(cmd & OBD_BRW_RWMASK)) {
771 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
775 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
780 static inline int obd_prep_async_page(struct obd_export *exp,
781 struct lov_stripe_md *lsm,
782 struct lov_oinfo *loi,
783 struct page *page, obd_off offset,
784 struct obd_async_page_ops *ops,
785 void *data, void **res)
790 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
791 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
793 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
798 static inline int obd_queue_async_io(struct obd_export *exp,
799 struct lov_stripe_md *lsm,
800 struct lov_oinfo *loi, void *cookie,
801 int cmd, obd_off off, int count,
802 obd_flags brw_flags, obd_flags async_flags)
807 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
808 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
809 LASSERT(cmd & OBD_BRW_RWMASK);
811 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
812 count, brw_flags, async_flags);
816 static inline int obd_set_async_flags(struct obd_export *exp,
817 struct lov_stripe_md *lsm,
818 struct lov_oinfo *loi, void *cookie,
819 obd_flags async_flags)
824 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
825 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
827 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
832 static inline int obd_queue_group_io(struct obd_export *exp,
833 struct lov_stripe_md *lsm,
834 struct lov_oinfo *loi,
835 struct obd_io_group *oig,
836 void *cookie, int cmd, obd_off off,
837 int count, obd_flags brw_flags,
838 obd_flags async_flags)
843 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
844 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
845 LASSERT(cmd & OBD_BRW_RWMASK);
847 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
848 cmd, off, count, brw_flags,
853 static inline int obd_trigger_group_io(struct obd_export *exp,
854 struct lov_stripe_md *lsm,
855 struct lov_oinfo *loi,
856 struct obd_io_group *oig)
861 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
862 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
864 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
868 static inline int obd_teardown_async_page(struct obd_export *exp,
869 struct lov_stripe_md *lsm,
870 struct lov_oinfo *loi, void *cookie)
875 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
876 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
878 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
882 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
883 int objcount, struct obd_ioobj *obj,
884 int niocount, struct niobuf_remote *remote,
885 struct niobuf_local *local,
886 struct obd_trans_info *oti)
891 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
892 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
894 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
899 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
900 int objcount, struct obd_ioobj *obj,
901 int niocount, struct niobuf_local *local,
902 struct obd_trans_info *oti, int rc)
906 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
907 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
909 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
914 static inline int obd_do_cow(struct obd_export *exp, struct obd_ioobj *obj,
915 int objcount,struct niobuf_remote *rnb)
920 /* there are cases when write_extents is not implemented. */
921 if (!OBP(exp->exp_obd, do_cow))
924 OBD_COUNTER_INCREMENT(exp->exp_obd, do_cow);
926 rc = OBP(exp->exp_obd, do_cow)(exp, obj, objcount, rnb);
931 static inline int obd_write_extents(struct obd_export *exp,
932 struct obd_ioobj *obj,
933 int objcount, int niocount,
934 struct niobuf_local *local,
939 /* there are cases when write_extents is not implemented. */
940 if (!OBP(exp->exp_obd, write_extents))
943 OBD_COUNTER_INCREMENT(exp->exp_obd, write_extents);
945 rc = OBP(exp->exp_obd, write_extents)(exp, obj, objcount, niocount,
950 static inline int obd_adjust_kms(struct obd_export *exp,
951 struct lov_stripe_md *lsm,
952 obd_off size, int shrink)
957 OBD_CHECK_OP(exp->exp_obd, adjust_kms, -EOPNOTSUPP);
958 OBD_COUNTER_INCREMENT(exp->exp_obd, adjust_kms);
960 rc = OBP(exp->exp_obd, adjust_kms)(exp, lsm, size, shrink);
964 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
965 int len, void *karg, void *uarg)
970 EXP_CHECK_OP(exp, iocontrol);
971 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
973 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
977 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
978 __u32 type, ldlm_policy_data_t *policy,
979 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
980 void *gl_cb, void *data, __u32 lvb_len,
981 void *lvb_swabber, struct lustre_handle *lockh)
986 EXP_CHECK_OP(exp, enqueue);
987 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
989 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
990 bl_cb, cp_cb, gl_cb, data, lvb_len,
995 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
996 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
997 int *flags, void *data, struct lustre_handle *lockh)
1002 EXP_CHECK_OP(exp, match);
1003 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
1005 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
1010 static inline int obd_change_cbdata(struct obd_export *exp,
1011 struct lov_stripe_md *lsm,
1012 ldlm_iterator_t it, void *data)
1017 EXP_CHECK_OP(exp, change_cbdata);
1018 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1020 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
1024 static inline int obd_cancel(struct obd_export *exp,
1025 struct lov_stripe_md *ea, __u32 mode,
1026 struct lustre_handle *lockh)
1031 EXP_CHECK_OP(exp, cancel);
1032 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
1034 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
1038 static inline int obd_cancel_unused(struct obd_export *exp,
1039 struct lov_stripe_md *ea, int flags,
1045 EXP_CHECK_OP(exp, cancel_unused);
1046 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1048 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1053 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1055 int objcount, struct obd_ioobj *obj,
1056 int niocount, struct niobuf_remote *remote)
1060 EXP_CHECK_OP(exp, preprw);
1061 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1063 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1065 class_export_put(exp);
1069 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1070 int type, struct obd_client_handle *handle, int flag)
1074 EXP_CHECK_OP(exp, pin);
1075 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1077 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1081 static inline int obd_unpin(struct obd_export *exp,
1082 struct obd_client_handle *handle, int flag)
1086 EXP_CHECK_OP(exp, unpin);
1087 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1089 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1094 static inline void obd_import_event(struct obd_device *obd,
1095 struct obd_import *imp,
1096 enum obd_import_event event)
1099 CERROR("NULL device\n");
1103 if (obd->obd_set_up && OBP(obd, import_event)) {
1104 OBD_COUNTER_INCREMENT(obd, import_event);
1105 OBP(obd, import_event)(obd, imp, event);
1109 static inline int obd_llog_connect(struct obd_export *exp,
1110 struct llogd_conn_body *body)
1113 EXP_CHECK_OP(exp, llog_connect);
1114 return OBP(exp->exp_obd, llog_connect)(exp, body);
1117 static inline int obd_notify(struct obd_device *obd, struct obd_device *watched,
1118 int active, void *data)
1121 if (!obd->obd_set_up) {
1122 CERROR("obd %s not set up\n", obd->obd_name);
1126 if (!OBP(obd, notify)) {
1127 CERROR("obd %s has no notify handler\n", obd->obd_name);
1131 OBD_COUNTER_INCREMENT(obd, notify);
1132 return OBP(obd, notify)(obd, watched, active, data);
1135 static inline int obd_register_observer(struct obd_device *obd,
1136 struct obd_device *observer)
1140 if (obd->obd_observer && observer)
1142 obd->obd_observer = observer;
1146 static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
1150 LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
1151 OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1152 rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
1156 static inline int md_getstatus(struct obd_export *exp, struct lustre_id *id)
1160 EXP_CHECK_MD_OP(exp, getstatus);
1161 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1162 rc = MDP(exp->exp_obd, getstatus)(exp, id);
1166 static inline int md_delete_inode(struct obd_export *exp,
1167 struct lustre_id *id)
1172 if (MDP(exp->exp_obd, delete_inode) == NULL)
1175 MD_COUNTER_INCREMENT(exp->exp_obd, delete_inode);
1176 rc = MDP(exp->exp_obd, delete_inode)(exp, id);
1180 static inline int md_getattr(struct obd_export *exp, struct lustre_id *id,
1181 __u64 valid, const char *xattr_name,
1182 const void *xattr_data, unsigned int xattr_datalen,
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,
1191 xattr_data, xattr_datalen,
1196 static inline int md_access_check(struct obd_export *exp, struct lustre_id *id,
1197 struct ptlrpc_request **request)
1201 EXP_CHECK_MD_OP(exp, access_check);
1202 MD_COUNTER_INCREMENT(exp->exp_obd, access_check);
1203 rc = MDP(exp->exp_obd, access_check)(exp, id, request);
1207 static inline int md_change_cbdata(struct obd_export *exp, struct lustre_id *id,
1208 ldlm_iterator_t it, void *data)
1212 EXP_CHECK_MD_OP(exp, change_cbdata);
1213 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1214 rc = MDP(exp->exp_obd, change_cbdata)(exp, id, it, data);
1218 static inline int md_change_cbdata_name(struct obd_export *exp,
1219 struct lustre_id *id, char *name,
1220 int namelen, struct lustre_id *id2,
1221 ldlm_iterator_t it, void *data)
1225 /* this seem to be needed only for lmv. */
1226 if (!MDP(exp->exp_obd, change_cbdata_name))
1231 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
1232 rc = MDP(exp->exp_obd, change_cbdata_name)(exp, id, name, namelen,
1237 static inline int md_close(struct obd_export *exp, struct obdo *obdo,
1238 struct obd_client_handle *och,
1239 struct ptlrpc_request **request)
1243 EXP_CHECK_MD_OP(exp, close);
1244 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1245 rc = MDP(exp->exp_obd, close)(exp, obdo, och, request);
1249 static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1250 const void *data, int datalen, int mode,
1251 __u32 uid, __u32 gid, __u64 rdev,
1252 struct ptlrpc_request **request)
1256 EXP_CHECK_MD_OP(exp, create);
1257 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1258 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1259 uid, gid, rdev, request);
1263 static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
1267 EXP_CHECK_MD_OP(exp, done_writing);
1268 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1269 rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
1273 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1274 struct lookup_intent *it, int lock_mode,
1275 struct mdc_op_data *data,
1276 struct lustre_handle *lockh,
1277 void *lmm, int lmmsize,
1278 ldlm_completion_callback cb_completion,
1279 ldlm_blocking_callback cb_blocking,
1284 EXP_CHECK_MD_OP(exp, enqueue);
1285 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1286 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1287 data, lockh, lmm, lmmsize,
1288 cb_completion, cb_blocking,
1293 static inline int md_getattr_lock(struct obd_export *exp, struct lustre_id *id,
1294 char *filename, int namelen,
1295 __u64 valid, unsigned int ea_size,
1296 struct ptlrpc_request **request)
1300 EXP_CHECK_MD_OP(exp, getattr_lock);
1301 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_lock);
1302 rc = MDP(exp->exp_obd, getattr_lock)(exp, id, filename, namelen,
1303 valid, ea_size, request);
1307 static inline int md_intent_lock(struct obd_export *exp,
1308 struct lustre_id *pid, const char *name,
1309 int len, void *lmm, int lmmsize,
1310 struct lustre_id *cid, struct lookup_intent *it,
1311 int flags, struct ptlrpc_request **reqp,
1312 ldlm_blocking_callback cb_blocking)
1316 EXP_CHECK_MD_OP(exp, intent_lock);
1317 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1318 rc = MDP(exp->exp_obd, intent_lock)(exp, pid, name, len,
1319 lmm, lmmsize, cid, it, flags,
1324 static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
1325 struct ptlrpc_request **request)
1329 EXP_CHECK_MD_OP(exp, link);
1330 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1331 rc = MDP(exp->exp_obd, link)(exp, data, request);
1335 static inline int md_rename(struct obd_export *exp, struct mdc_op_data *data,
1336 const char *old, int oldlen,
1337 const char *new, int newlen,
1338 struct ptlrpc_request **request)
1342 EXP_CHECK_MD_OP(exp, rename);
1343 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1344 rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
1349 static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1350 struct iattr *iattr, void *ea, int ealen,
1351 void *ea2, int ea2len, void *ea3, int ea3len,
1352 struct ptlrpc_request **request)
1356 EXP_CHECK_MD_OP(exp, setattr);
1357 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1358 rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
1359 ea2, ea2len, ea3, ea3len, request);
1363 static inline int md_sync(struct obd_export *exp, struct lustre_id *id,
1364 struct ptlrpc_request **request)
1368 EXP_CHECK_MD_OP(exp, sync);
1369 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1370 rc = MDP(exp->exp_obd, sync)(exp, id, request);
1374 static inline int md_readpage(struct obd_export *exp, struct lustre_id *id,
1375 __u64 offset, struct page *page,
1376 struct ptlrpc_request **request)
1380 EXP_CHECK_MD_OP(exp, readpage);
1381 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1382 rc = MDP(exp->exp_obd, readpage)(exp, id, offset, page, request);
1386 static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1387 struct ptlrpc_request **request)
1391 EXP_CHECK_MD_OP(exp, unlink);
1392 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1393 rc = MDP(exp->exp_obd, unlink)(exp, data, request);
1397 static inline struct obd_device *md_get_real_obd(struct obd_export *exp,
1398 struct lustre_id *fid)
1401 if (MDP(exp->exp_obd, get_real_obd) == NULL)
1402 return exp->exp_obd;
1403 MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
1404 return MDP(exp->exp_obd, get_real_obd)(exp, fid);
1407 static inline int md_valid_attrs(struct obd_export *exp,
1408 struct lustre_id *id)
1411 EXP_CHECK_MD_OP(exp, valid_attrs);
1412 MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
1413 return MDP(exp->exp_obd, valid_attrs)(exp, id);
1416 static inline int md_req2lustre_md(struct obd_export *exp,
1417 struct ptlrpc_request *req,
1418 unsigned int offset,
1419 struct obd_export *osc_exp,
1420 struct lustre_md *md)
1423 EXP_CHECK_MD_OP(exp, req2lustre_md);
1424 MD_COUNTER_INCREMENT(exp->exp_obd, req2lustre_md);
1425 return MDP(exp->exp_obd, req2lustre_md)(exp, req, offset, osc_exp, md);
1428 static inline int md_set_open_replay_data(struct obd_export *exp,
1429 struct obd_client_handle *och,
1430 struct ptlrpc_request *open_req)
1433 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1434 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1435 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req);
1438 static inline int md_clear_open_replay_data(struct obd_export *exp,
1439 struct obd_client_handle *och)
1442 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1443 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1444 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1447 static inline int md_store_inode_generation(struct obd_export *exp,
1448 struct ptlrpc_request *req,
1449 int reqoff, int repoff)
1452 EXP_CHECK_MD_OP(exp, store_inode_generation);
1453 MD_COUNTER_INCREMENT(exp->exp_obd, store_inode_generation);
1454 return MDP(exp->exp_obd, store_inode_generation)(exp, req,
1458 static inline int md_set_lock_data(struct obd_export *exp, __u64 *l,
1462 EXP_CHECK_MD_OP(exp, set_lock_data);
1463 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1464 return MDP(exp->exp_obd, set_lock_data)(exp, l, data);
1467 /* OBD Metadata Support */
1469 extern int obd_init_caches(void);
1470 extern void obd_cleanup_caches(void);
1472 /* support routines */
1473 extern kmem_cache_t *obdo_cachep;
1474 static inline struct obdo *obdo_alloc(void)
1478 OBD_SLAB_ALLOC(oa, obdo_cachep, GFP_KERNEL,
1483 static inline void obdo_free(struct obdo *oa)
1485 OBD_SLAB_FREE(oa, obdo_cachep, sizeof(*oa));
1488 static inline void obdo2id(struct lustre_id *id,
1492 id_ino(id) = oa->o_id;
1493 id_fid(id) = oa->o_fid;
1494 id_group(id) = oa->o_mds;
1495 id_gen(id) = oa->o_generation;
1498 static inline void id2obdo(struct obdo *oa,
1499 struct lustre_id *id)
1502 oa->o_id = id_ino(id);
1503 oa->o_fid = id_fid(id);
1504 oa->o_mds = id_group(id);
1505 oa->o_generation = id_gen(id);
1508 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1509 #define to_kdev_t(dev) dev
1510 #define kdev_t_to_nr(dev) dev
1513 /* I'm as embarrassed about this as you are.
1515 * <shaver> // XXX do not look into _superhack with remaining eye
1516 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1517 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1518 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1521 extern void obd_sysctl_init (void);
1522 extern void obd_sysctl_clean (void);
1525 typedef __u8 class_uuid_t[16];
1526 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1527 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1530 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1531 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1532 int class_del_uuid (char *uuid);
1533 void class_init_uuidlist(void);
1534 void class_exit_uuidlist(void);
1537 int mea_name2idx(struct mea *mea, char *name, int namelen);
1538 int raw_name2idx(int hashtype, int count, const char *name, int namelen);
1540 #endif /* __LINUX_OBD_CLASS_H */