1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Copyright (C) 2001-2003 Cluster File Systems, Inc.
6 * This file is part of Lustre, http://www.lustre.org.
8 * Lustre is free software; you can redistribute it and/or
9 * modify it under the terms of version 2 of the GNU General Public
10 * License as published by the Free Software Foundation.
12 * Lustre is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Lustre; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #ifndef __LINUX_CLASS_OBD_H
24 #define __LINUX_CLASS_OBD_H
27 #include <sys/types.h>
28 #include <portals/list.h>
30 #include <asm/segment.h>
31 #include <asm/uaccess.h>
32 #include <linux/types.h>
34 #include <linux/time.h>
35 #include <linux/timer.h>
38 #include <linux/obd_support.h>
39 #include <linux/lustre_import.h>
40 #include <linux/lustre_net.h>
41 #include <linux/obd.h>
42 #include <linux/lustre_lib.h>
43 #include <linux/lustre_idl.h>
44 #include <linux/lprocfs_status.h>
45 #include <linux/lustre_log.h>
47 /* OBD Device Declarations */
48 #define MAX_OBD_DEVICES 256
49 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
51 /* OBD Operations Declarations */
52 extern struct obd_device *class_conn2obd(struct lustre_handle *);
53 extern struct obd_device *class_exp2obd(struct obd_export *);
56 struct obd_export *class_conn2export(struct lustre_handle *);
57 int class_register_type(struct obd_ops *ops, struct md_ops *md_ops,
58 struct lprocfs_vars *, char *nm);
59 int class_unregister_type(char *nm);
61 struct obd_device *class_newdev(int *dev);
63 int class_name2dev(char *name);
64 struct obd_device *class_name2obd(char *name);
65 int class_uuid2dev(struct obd_uuid *uuid);
66 struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
67 struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
69 struct obd_uuid *grp_uuid);
70 struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
73 int oig_init(struct obd_io_group **oig);
74 void oig_add_one(struct obd_io_group *oig,
75 struct oig_callback_context *occ);
76 void oig_complete_one(struct obd_io_group *oig,
77 struct oig_callback_context *occ, int rc);
78 void oig_release(struct obd_io_group *oig);
79 int oig_wait(struct obd_io_group *oig);
82 int class_process_config(struct lustre_cfg *lcfg);
84 /* Passed as data param to class_config_parse_handler() */
85 struct config_llog_instance {
87 struct obd_uuid cfg_uuid;
88 ptl_nid_t cfg_local_nid;
91 int class_config_process_llog(struct llog_ctxt *ctxt, char *name,
92 struct config_llog_instance *cfg);
93 int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
94 struct config_llog_instance *cfg);
96 struct lustre_profile {
97 struct list_head lp_list;
103 struct lustre_profile *class_get_profile(char * prof);
104 void class_del_profile(char *prof);
106 #define class_export_get(exp) \
108 struct obd_export *exp_ = exp; \
109 atomic_inc(&exp_->exp_refcount); \
110 CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_, \
111 atomic_read(&exp_->exp_refcount)); \
115 #define class_export_put(exp) \
117 LASSERT((exp) != NULL); \
118 CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp), \
119 atomic_read(&(exp)->exp_refcount) - 1); \
120 LASSERT(atomic_read(&(exp)->exp_refcount) > 0); \
121 LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a); \
122 __class_export_put(exp); \
124 void __class_export_put(struct obd_export *);
125 struct obd_export *class_new_export(struct obd_device *obddev);
126 void class_unlink_export(struct obd_export *exp);
128 struct obd_import *class_import_get(struct obd_import *);
129 void class_import_put(struct obd_import *);
130 struct obd_import *class_new_import(void);
131 void class_destroy_import(struct obd_import *exp);
133 struct obd_type *class_get_type(char *name);
134 void class_put_type(struct obd_type *type);
135 int class_connect(struct lustre_handle *conn, struct obd_device *obd,
136 struct obd_uuid *cluuid);
137 int class_disconnect(struct obd_export *exp, int failover);
138 void class_disconnect_exports(struct obd_device *obddev, int failover);
139 /* generic operations shared by various OBD types */
140 int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
141 int class_multi_cleanup(struct obd_device *obddev);
145 void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
146 void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
147 void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
148 void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
149 void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
151 void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
152 int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
153 void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
155 static inline int obd_check_conn(struct lustre_handle *conn)
157 struct obd_device *obd;
159 CERROR("NULL conn\n");
163 obd = class_conn2obd(conn);
165 CERROR("NULL obd\n");
169 if (!obd->obd_attached) {
170 CERROR("obd %d not attached\n", obd->obd_minor);
174 if (!obd->obd_set_up) {
175 CERROR("obd %d not setup\n", obd->obd_minor);
179 if (!obd->obd_type) {
180 CERROR("obd %d not typed\n", obd->obd_minor);
184 if (!obd->obd_type->typ_ops) {
185 CERROR("obd_check_conn: obd %d no operations\n",
193 #define OBT(dev) (dev)->obd_type
194 #define OBP(dev, op) (dev)->obd_type->typ_ops->o_ ## op
195 #define MDP(dev, op) (dev)->obd_type->typ_md_ops->m_ ## op
196 #define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
198 /* Ensure obd_setup: used for disconnect which might be called while
199 an obd is stopping. */
200 #define OBD_CHECK_SETUP(conn, exp) \
203 CERROR("NULL connection\n"); \
207 exp = class_conn2export(conn); \
209 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
213 if (!(exp)->exp_obd->obd_set_up) { \
214 CERROR("Device %d not setup\n", \
215 (exp)->exp_obd->obd_minor); \
216 class_export_put(exp); \
221 /* Ensure obd_setup and !obd_stopping. */
222 #define OBD_CHECK_ACTIVE(conn, exp) \
225 CERROR("NULL connection\n"); \
229 exp = class_conn2export(conn); \
231 CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
235 if (!(exp)->exp_obd->obd_set_up || (exp)->exp_obd->obd_stopping) { \
236 CERROR("Device %d not setup\n", \
237 (exp)->exp_obd->obd_minor); \
238 class_export_put(exp); \
243 /* Ensure obd_setup: used for cleanup which must be called
244 while obd is stopping */
245 #define OBD_CHECK_DEV_STOPPING(obd) \
248 CERROR("NULL device\n"); \
252 if (!(obd)->obd_set_up) { \
253 CERROR("Device %d not setup\n", \
258 if (!(obd)->obd_stopping) { \
259 CERROR("Device %d not stopping\n", \
265 /* ensure obd_setup and !obd_stopping */
266 #define OBD_CHECK_DEV_ACTIVE(obd) \
269 CERROR("NULL device\n"); \
273 if (!(obd)->obd_set_up || (obd)->obd_stopping) { \
274 CERROR("Device %d not setup\n", \
282 #define OBD_COUNTER_OFFSET(op) \
283 ((offsetof(struct obd_ops, o_ ## op) - \
284 offsetof(struct obd_ops, o_iocontrol)) \
285 / sizeof(((struct obd_ops *)(0))->o_iocontrol))
287 #define OBD_COUNTER_INCREMENT(obd, op) \
288 if ((obd)->obd_stats != NULL) { \
289 unsigned int coffset; \
290 coffset = (unsigned int)(obd)->obd_cntr_base + \
291 OBD_COUNTER_OFFSET(op); \
292 LASSERT(coffset < obd->obd_stats->ls_num); \
293 lprocfs_counter_incr(obd->obd_stats, coffset); \
295 /* FIXME: real accounting here */
296 #define MD_COUNTER_INCREMENT(obd, op)
298 #define OBD_COUNTER_OFFSET(op)
299 #define OBD_COUNTER_INCREMENT(obd, op)
300 #define MD_COUNTER_INCREMENT(obd, op)
303 #define OBD_CHECK_MD_OP(obd, op, err) \
305 if (!OBT(obd) || !MDP((obd), op)) {\
307 CERROR("obd_md" #op ": dev %d no operation\n", \
313 #define EXP_CHECK_MD_OP(exp, op) \
315 if ((exp) == NULL) { \
316 CERROR("obd_" #op ": NULL export\n"); \
319 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
320 CERROR("obd_" #op ": cleaned up obd\n"); \
321 RETURN(-EOPNOTSUPP); \
323 if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
324 CERROR("obd_" #op ": dev %d no operation\n", \
325 (exp)->exp_obd->obd_minor); \
326 RETURN(-EOPNOTSUPP); \
330 #define OBD_CHECK_OP(obd, op, err) \
332 if (!OBT(obd) || !OBP((obd), op)) {\
334 CERROR("obd_" #op ": dev %d no operation\n", \
340 #define EXP_CHECK_OP(exp, op) \
342 if ((exp) == NULL) { \
343 CERROR("obd_" #op ": NULL export\n"); \
346 if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) { \
347 CERROR("obd_" #op ": cleaned up obd\n"); \
348 RETURN(-EOPNOTSUPP); \
350 if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
351 CERROR("obd_" #op ": dev %d no operation\n", \
352 (exp)->exp_obd->obd_minor); \
353 RETURN(-EOPNOTSUPP); \
357 #define CTXT_CHECK_OP(ctxt, op, err) \
359 if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) { \
361 CERROR("lop_" #op ": dev %d no operation\n", \
362 ctxt->loc_obd->obd_minor); \
367 static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
368 void *key, __u32 *vallen, void *val)
373 EXP_CHECK_OP(exp, get_info);
374 OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
376 rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
380 static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
381 void *key, obd_count vallen, void *val)
386 EXP_CHECK_OP(exp, set_info);
387 OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
389 rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
393 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
398 OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
399 OBD_COUNTER_INCREMENT(obd, setup);
401 rc = OBP(obd, setup)(obd, datalen, data);
405 static inline int obd_precleanup(struct obd_device *obd, int flags)
410 OBD_CHECK_OP(obd, precleanup, 0);
411 OBD_COUNTER_INCREMENT(obd, precleanup);
413 rc = OBP(obd, precleanup)(obd, flags);
417 static inline int obd_cleanup(struct obd_device *obd, int flags)
422 OBD_CHECK_DEV_STOPPING(obd);
423 OBD_CHECK_OP(obd, cleanup, 0);
424 OBD_COUNTER_INCREMENT(obd, cleanup);
426 rc = OBP(obd, cleanup)(obd, flags);
431 obd_process_config(struct obd_device *obd, int datalen, void *data)
436 OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
437 OBD_COUNTER_INCREMENT(obd, process_config);
439 rc = OBP(obd, process_config)(obd, datalen, data);
443 /* Pack an in-memory MD struct for storage on disk.
444 * Returns +ve size of packed MD (0 for free), or -ve error.
446 * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
447 * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
448 * If @*disk_tgt == NULL, it will be allocated
450 static inline int obd_packmd(struct obd_export *exp,
451 struct lov_mds_md **disk_tgt,
452 struct lov_stripe_md *mem_src)
457 EXP_CHECK_OP(exp, packmd);
458 OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
460 rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
464 static inline int obd_size_diskmd(struct obd_export *exp,
465 struct lov_stripe_md *mem_src)
467 return obd_packmd(exp, NULL, mem_src);
470 /* helper functions */
471 static inline int obd_alloc_diskmd(struct obd_export *exp,
472 struct lov_mds_md **disk_tgt)
475 LASSERT(*disk_tgt == NULL);
476 return obd_packmd(exp, disk_tgt, NULL);
479 static inline int obd_free_diskmd(struct obd_export *exp,
480 struct lov_mds_md **disk_tgt)
484 return obd_packmd(exp, disk_tgt, NULL);
487 /* Unpack an MD struct from disk to in-memory format.
488 * Returns +ve size of unpacked MD (0 for free), or -ve error.
490 * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
491 * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
492 * If @*mem_tgt == NULL, it will be allocated
494 static inline int obd_unpackmd(struct obd_export *exp,
495 struct lov_stripe_md **mem_tgt,
496 struct lov_mds_md *disk_src,
502 EXP_CHECK_OP(exp, unpackmd);
503 OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
505 rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
509 /* helper functions */
510 static inline int obd_alloc_memmd(struct obd_export *exp,
511 struct lov_stripe_md **mem_tgt)
514 LASSERT(*mem_tgt == NULL);
515 return obd_unpackmd(exp, mem_tgt, NULL, 0);
518 static inline int obd_free_memmd(struct obd_export *exp,
519 struct lov_stripe_md **mem_tgt)
523 return obd_unpackmd(exp, mem_tgt, NULL, 0);
526 static inline int obd_revalidate_md(struct obd_export *exp, struct obdo *obdo,
527 struct lov_stripe_md *ea,
528 struct obd_trans_info *oti)
533 EXP_CHECK_OP(exp, revalidate_md);
534 OBD_COUNTER_INCREMENT(exp->exp_obd, revalidate_md);
536 rc = OBP(exp->exp_obd, revalidate_md)(exp, obdo, ea, oti);
540 static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
541 struct lov_stripe_md **ea,
542 struct obd_trans_info *oti)
547 EXP_CHECK_OP(exp, create);
548 OBD_COUNTER_INCREMENT(exp->exp_obd, create);
550 rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
554 static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
555 struct lov_stripe_md *ea,
556 struct obd_trans_info *oti)
561 EXP_CHECK_OP(exp, destroy);
562 OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
564 rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
568 static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
569 struct lov_stripe_md *ea)
574 EXP_CHECK_OP(exp, getattr);
575 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
577 rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
581 static inline int obd_getattr_async(struct obd_export *exp,
582 struct obdo *obdo, struct lov_stripe_md *ea,
583 struct ptlrpc_request_set *set)
588 EXP_CHECK_OP(exp, getattr);
589 OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
591 rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
595 static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
596 struct lov_stripe_md *ea,
597 struct obd_trans_info *oti)
602 EXP_CHECK_OP(exp, setattr);
603 OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
605 rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
609 static inline int obd_connect(struct lustre_handle *conn,
610 struct obd_device *obd, struct obd_uuid *cluuid)
615 OBD_CHECK_DEV_ACTIVE(obd);
616 OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
617 OBD_COUNTER_INCREMENT(obd, connect);
619 rc = OBP(obd, connect)(conn, obd, cluuid);
623 static inline int obd_disconnect(struct obd_export *exp, int flags)
628 EXP_CHECK_OP(exp, disconnect);
629 OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
631 rc = OBP(exp->exp_obd, disconnect)(exp, flags);
635 static inline int obd_init_export(struct obd_export *exp)
640 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
641 OBP((exp)->exp_obd, init_export))
642 rc = OBP(exp->exp_obd, init_export)(exp);
646 static inline int obd_destroy_export(struct obd_export *exp)
649 if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
650 OBP((exp)->exp_obd, destroy_export))
651 OBP(exp->exp_obd, destroy_export)(exp);
655 static inline struct dentry *
656 obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
658 LASSERT(exp->exp_obd);
660 return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
665 #define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
668 /* @max_age is the oldest time in jiffies that we accept using a cached data.
669 * If the cache is older than @max_age we will get a new value from the
670 * target. Use a value of "jiffies + HZ" to guarantee freshness. */
671 static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
672 unsigned long max_age)
680 OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
681 OBD_COUNTER_INCREMENT(obd, statfs);
683 CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
684 if (time_before(obd->obd_osfs_age, max_age)) {
685 rc = OBP(obd, statfs)(obd, osfs, max_age);
687 spin_lock(&obd->obd_osfs_lock);
688 memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
689 obd->obd_osfs_age = jiffies;
690 spin_unlock(&obd->obd_osfs_lock);
693 CDEBUG(D_SUPER, "using cached obd_statfs data\n");
694 spin_lock(&obd->obd_osfs_lock);
695 memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
696 spin_unlock(&obd->obd_osfs_lock);
701 static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
702 struct lov_stripe_md *ea, obd_size start,
708 OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
709 OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
711 rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
715 static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
716 struct lov_stripe_md *ea, obd_size start,
717 obd_size end, struct obd_trans_info *oti)
722 EXP_CHECK_OP(exp, punch);
723 OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
725 rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
729 static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
730 struct lov_stripe_md *ea, obd_count oa_bufs,
731 struct brw_page *pg, struct obd_trans_info *oti)
736 EXP_CHECK_OP(exp, brw);
737 OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
739 if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
740 CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
741 "or OBD_BRW_CHECK\n");
745 rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
749 static inline int obd_brw_async(int cmd, struct obd_export *exp,
750 struct obdo *oa, struct lov_stripe_md *ea,
751 obd_count oa_bufs, struct brw_page *pg,
752 struct ptlrpc_request_set *set,
753 struct obd_trans_info *oti)
758 EXP_CHECK_OP(exp, brw_async);
759 OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
761 if (!(cmd & OBD_BRW_RWMASK)) {
762 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
766 rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
771 static inline int obd_prep_async_page(struct obd_export *exp,
772 struct lov_stripe_md *lsm,
773 struct lov_oinfo *loi,
774 struct page *page, obd_off offset,
775 struct obd_async_page_ops *ops,
776 void *data, void **res)
781 OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
782 OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
784 ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
789 static inline int obd_queue_async_io(struct obd_export *exp,
790 struct lov_stripe_md *lsm,
791 struct lov_oinfo *loi, void *cookie,
792 int cmd, obd_off off, int count,
793 obd_flag brw_flags, obd_flag async_flags)
798 OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
799 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
800 LASSERT(cmd & OBD_BRW_RWMASK);
802 rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
803 count, brw_flags, async_flags);
807 static inline int obd_set_async_flags(struct obd_export *exp,
808 struct lov_stripe_md *lsm,
809 struct lov_oinfo *loi, void *cookie,
810 obd_flag async_flags)
815 OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
816 OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
818 rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
823 static inline int obd_queue_group_io(struct obd_export *exp,
824 struct lov_stripe_md *lsm,
825 struct lov_oinfo *loi,
826 struct obd_io_group *oig,
827 void *cookie, int cmd, obd_off off,
828 int count, obd_flag brw_flags,
829 obd_flag async_flags)
834 OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
835 OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
836 LASSERT(cmd & OBD_BRW_RWMASK);
838 rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
839 cmd, off, count, brw_flags,
844 static inline int obd_trigger_group_io(struct obd_export *exp,
845 struct lov_stripe_md *lsm,
846 struct lov_oinfo *loi,
847 struct obd_io_group *oig)
852 OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
853 OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
855 rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
859 static inline int obd_teardown_async_page(struct obd_export *exp,
860 struct lov_stripe_md *lsm,
861 struct lov_oinfo *loi, void *cookie)
866 OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
867 OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
869 rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
873 static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
874 int objcount, struct obd_ioobj *obj,
875 int niocount, struct niobuf_remote *remote,
876 struct niobuf_local *local,
877 struct obd_trans_info *oti)
882 OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
883 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
885 rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
890 static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
891 int objcount, struct obd_ioobj *obj,
892 int niocount, struct niobuf_local *local,
893 struct obd_trans_info *oti, int rc)
897 OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
898 OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
900 rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
905 static inline int obd_write_extents(struct obd_export *exp, struct obd_ioobj *obj,
906 int niocount, struct niobuf_local *local, int rc)
910 /* there are cases when write_extents is not implemented. */
911 if (!OBP(exp->exp_obd, write_extents))
914 OBD_COUNTER_INCREMENT(exp->exp_obd, write_extents);
916 rc = OBP(exp->exp_obd, write_extents)(exp, obj, niocount, local, rc);
920 static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
921 int len, void *karg, void *uarg)
926 EXP_CHECK_OP(exp, iocontrol);
927 OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
929 rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
933 static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
934 __u32 type, ldlm_policy_data_t *policy,
935 __u32 mode, int *flags, void *bl_cb, void *cp_cb,
936 void *gl_cb, void *data, __u32 lvb_len,
937 void *lvb_swabber, struct lustre_handle *lockh)
942 EXP_CHECK_OP(exp, enqueue);
943 OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
945 rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
946 bl_cb, cp_cb, gl_cb, data, lvb_len,
951 static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
952 __u32 type, ldlm_policy_data_t *policy, __u32 mode,
953 int *flags, void *data, struct lustre_handle *lockh)
958 EXP_CHECK_OP(exp, match);
959 OBD_COUNTER_INCREMENT(exp->exp_obd, match);
961 rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
966 static inline int obd_change_cbdata(struct obd_export *exp,
967 struct lov_stripe_md *lsm,
968 ldlm_iterator_t it, void *data)
973 EXP_CHECK_OP(exp, change_cbdata);
974 OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
976 rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
980 static inline int obd_cancel(struct obd_export *exp,
981 struct lov_stripe_md *ea, __u32 mode,
982 struct lustre_handle *lockh)
987 EXP_CHECK_OP(exp, cancel);
988 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
990 rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
994 static inline int obd_cancel_unused(struct obd_export *exp,
995 struct lov_stripe_md *ea, int flags,
1001 EXP_CHECK_OP(exp, cancel_unused);
1002 OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
1004 rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
1009 static inline int obd_san_preprw(int cmd, struct obd_export *exp,
1011 int objcount, struct obd_ioobj *obj,
1012 int niocount, struct niobuf_remote *remote)
1016 EXP_CHECK_OP(exp, preprw);
1017 OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
1019 rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
1021 class_export_put(exp);
1025 static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
1026 int type, struct obd_client_handle *handle, int flag)
1030 EXP_CHECK_OP(exp, pin);
1031 OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
1033 rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
1037 static inline int obd_unpin(struct obd_export *exp,
1038 struct obd_client_handle *handle, int flag)
1042 EXP_CHECK_OP(exp, unpin);
1043 OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
1045 rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
1050 static inline void obd_import_event(struct obd_device *obd,
1051 struct obd_import *imp,
1052 enum obd_import_event event)
1054 if (obd->obd_set_up && OBP(obd, import_event)) {
1055 OBD_COUNTER_INCREMENT(obd, import_event);
1056 OBP(obd, import_event)(obd, imp, event);
1060 static inline int obd_llog_connect(struct obd_device *obd,
1061 struct llogd_conn_body *body)
1064 if (!obd->obd_set_up) {
1065 CERROR("obd %s not set up\n", obd->obd_name);
1069 if (!OBP(obd, llog_connect)) {
1070 CERROR("obd %s has no llog_connect handler\n", obd->obd_name);
1074 return OBP(obd, llog_connect)(obd, body);
1077 static inline int obd_notify(struct obd_device *obd,
1078 struct obd_device *watched,
1081 if (!obd->obd_set_up) {
1082 CERROR("obd %s not set up\n", obd->obd_name);
1086 if (!OBP(obd, notify)) {
1087 CERROR("obd %s has no notify handler\n", obd->obd_name);
1091 OBD_COUNTER_INCREMENT(obd, notify);
1092 return OBP(obd, notify)(obd, watched, active);
1095 static inline int obd_register_observer(struct obd_device *obd,
1096 struct obd_device *observer)
1099 if (obd->obd_observer && observer)
1101 obd->obd_observer = observer;
1105 static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
1109 LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
1110 OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
1111 rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
1115 static inline int md_getstatus(struct obd_export *exp, struct ll_fid *fid)
1119 EXP_CHECK_MD_OP(exp, getstatus);
1120 MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
1121 rc = MDP(exp->exp_obd, getstatus)(exp, fid);
1125 static inline int md_getattr(struct obd_export *exp, struct ll_fid *fid,
1126 unsigned long valid, unsigned int ea_size,
1127 struct ptlrpc_request **request)
1130 EXP_CHECK_MD_OP(exp, getattr);
1131 MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
1132 rc = MDP(exp->exp_obd, getattr)(exp, fid, valid, ea_size, request);
1136 static inline int md_change_cbdata(struct obd_export *exp, struct ll_fid *fid,
1137 ldlm_iterator_t it, void *data)
1141 EXP_CHECK_MD_OP(exp, change_cbdata);
1142 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
1143 rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
1147 static inline int md_change_cbdata_name(struct obd_export *exp,
1148 struct ll_fid *fid, char *name,
1149 int namelen, struct ll_fid *fid2,
1150 ldlm_iterator_t it, void *data)
1154 /* this seem to be needed only for lmv. */
1155 if (!MDP(exp->exp_obd, change_cbdata_name))
1160 MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
1161 rc = MDP(exp->exp_obd, change_cbdata_name)(exp, fid, name, namelen,
1166 static inline int md_close(struct obd_export *exp, struct obdo *obdo,
1167 struct obd_client_handle *och,
1168 struct ptlrpc_request **request)
1172 EXP_CHECK_MD_OP(exp, close);
1173 MD_COUNTER_INCREMENT(exp->exp_obd, close);
1174 rc = MDP(exp->exp_obd, close)(exp, obdo, och, request);
1178 static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
1179 const void *data, int datalen, int mode,
1180 __u32 uid, __u32 gid, __u64 rdev,
1181 struct ptlrpc_request **request)
1185 EXP_CHECK_MD_OP(exp, create);
1186 MD_COUNTER_INCREMENT(exp->exp_obd, create);
1187 rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
1188 uid, gid, rdev, request);
1192 static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
1196 EXP_CHECK_MD_OP(exp, done_writing);
1197 MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
1198 rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
1202 static inline int md_enqueue(struct obd_export *exp, int lock_type,
1203 struct lookup_intent *it, int lock_mode,
1204 struct mdc_op_data *data,
1205 struct lustre_handle *lockh,
1206 void *lmm, int lmmsize,
1207 ldlm_completion_callback cb_completion,
1208 ldlm_blocking_callback cb_blocking,
1213 EXP_CHECK_MD_OP(exp, enqueue);
1214 MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
1215 rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
1216 data, lockh, lmm, lmmsize,
1217 cb_completion, cb_blocking,
1222 static inline int md_getattr_name(struct obd_export *exp, struct ll_fid *fid,
1223 char *filename, int namelen,
1224 unsigned long valid, unsigned int ea_size,
1225 struct ptlrpc_request **request)
1229 EXP_CHECK_MD_OP(exp, getattr_name);
1230 MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
1231 rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
1232 valid, ea_size, request);
1236 static inline int md_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
1237 struct ll_fid *pfid, const char *name,
1238 int len, void *lmm, int lmmsize,
1239 struct ll_fid *cfid, struct lookup_intent *it,
1240 int flags, struct ptlrpc_request **reqp,
1241 ldlm_blocking_callback cb_blocking)
1245 EXP_CHECK_MD_OP(exp, intent_lock);
1246 MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
1247 rc = MDP(exp->exp_obd, intent_lock)(exp, uctxt, pfid, name, len,
1248 lmm, lmmsize, cfid, it, flags,
1253 static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
1254 struct ptlrpc_request **request)
1258 EXP_CHECK_MD_OP(exp, link);
1259 MD_COUNTER_INCREMENT(exp->exp_obd, link);
1260 rc = MDP(exp->exp_obd, link)(exp, data, request);
1264 static inline int md_rename(struct obd_export *exp, struct mdc_op_data *data,
1265 const char *old, int oldlen,
1266 const char *new, int newlen,
1267 struct ptlrpc_request **request)
1271 EXP_CHECK_MD_OP(exp, rename);
1272 MD_COUNTER_INCREMENT(exp->exp_obd, rename);
1273 rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
1278 static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
1279 struct iattr *iattr, void *ea, int ealen,
1280 void *ea2, int ea2len,
1281 struct ptlrpc_request **request)
1285 EXP_CHECK_MD_OP(exp, setattr);
1286 MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
1287 rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
1288 ea2, ea2len, request);
1292 static inline int md_sync(struct obd_export *exp, struct ll_fid *fid,
1293 struct ptlrpc_request **request)
1297 EXP_CHECK_MD_OP(exp, sync);
1298 MD_COUNTER_INCREMENT(exp->exp_obd, sync);
1299 rc = MDP(exp->exp_obd, sync)(exp, fid, request);
1303 static inline int md_readpage(struct obd_export *exp, struct ll_fid *fid,
1304 __u64 offset, struct page *page,
1305 struct ptlrpc_request **request)
1309 EXP_CHECK_MD_OP(exp, readpage);
1310 MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
1311 rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
1315 static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
1316 struct ptlrpc_request **request)
1320 EXP_CHECK_MD_OP(exp, unlink);
1321 MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
1322 rc = MDP(exp->exp_obd, unlink)(exp, data, request);
1326 static inline struct obd_device * md_get_real_obd(struct obd_export *exp,
1327 char *name, int len)
1330 if (MDP(exp->exp_obd, get_real_obd) == NULL)
1331 return exp->exp_obd;
1332 MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
1333 return MDP(exp->exp_obd, get_real_obd)(exp, name, len);
1336 static inline int md_valid_attrs(struct obd_export *exp, struct ll_fid *fid)
1339 EXP_CHECK_MD_OP(exp, valid_attrs);
1340 MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
1341 return MDP(exp->exp_obd, valid_attrs)(exp, fid);
1344 static inline int md_req2lustre_md(struct obd_export *exp,
1345 struct ptlrpc_request *req,
1346 unsigned int offset,
1347 struct obd_export *osc_exp,
1348 struct lustre_md *md)
1351 EXP_CHECK_MD_OP(exp, req2lustre_md);
1352 MD_COUNTER_INCREMENT(exp->exp_obd, req2lustre_md);
1353 return MDP(exp->exp_obd, req2lustre_md)(exp, req, offset, osc_exp, md);
1356 static inline int md_set_open_replay_data(struct obd_export *exp,
1357 struct obd_client_handle *och,
1358 struct ptlrpc_request *open_req)
1361 EXP_CHECK_MD_OP(exp, set_open_replay_data);
1362 MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
1363 return MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req);
1366 static inline int md_clear_open_replay_data(struct obd_export *exp,
1367 struct obd_client_handle *och)
1370 EXP_CHECK_MD_OP(exp, clear_open_replay_data);
1371 MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
1372 return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
1375 static inline int md_store_inode_generation(struct obd_export *exp,
1376 struct ptlrpc_request *req,
1377 int reqoff, int repoff)
1380 EXP_CHECK_MD_OP(exp, store_inode_generation);
1381 MD_COUNTER_INCREMENT(exp->exp_obd, store_inode_generation);
1382 return MDP(exp->exp_obd, store_inode_generation)(exp, req,
1386 static inline int md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
1389 EXP_CHECK_MD_OP(exp, set_lock_data);
1390 MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
1391 return MDP(exp->exp_obd, set_lock_data)(exp, l, data);
1394 /* OBD Metadata Support */
1396 extern int obd_init_caches(void);
1397 extern void obd_cleanup_caches(void);
1399 /* support routines */
1400 extern kmem_cache_t *obdo_cachep;
1401 static inline struct obdo *obdo_alloc(void)
1405 oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
1408 CDEBUG(D_MALLOC, "kmem_cache_alloced oa at %p\n", oa);
1409 memset(oa, 0, sizeof (*oa));
1414 static inline void obdo_free(struct obdo *oa)
1418 CDEBUG(D_MALLOC, "kmem_cache_freed oa at %p\n", oa);
1419 kmem_cache_free(obdo_cachep, oa);
1422 #if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1423 #define to_kdev_t(dev) dev
1424 #define kdev_t_to_nr(dev) dev
1427 /* I'm as embarrassed about this as you are.
1429 * <shaver> // XXX do not look into _superhack with remaining eye
1430 * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
1431 extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
1432 extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
1435 extern void obd_sysctl_init (void);
1436 extern void obd_sysctl_clean (void);
1439 typedef __u8 class_uuid_t[16];
1440 //int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
1441 void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
1444 int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
1445 int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
1446 int class_del_uuid (char *uuid);
1447 void class_init_uuidlist(void);
1448 void class_exit_uuidlist(void);
1451 int mea_name2idx(struct mea *mea, char *name, int namelen);
1452 int raw_name2idx(int count, const char *name, int namelen);
1454 #endif /* __LINUX_OBD_CLASS_H */