Whamcloud - gitweb
b=1451
[fs/lustre-release.git] / lustre / include / linux / obd_class.h
index 2b66b1b..d7e847d 100644 (file)
@@ -1,7 +1,7 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- *  Copyright (C) 2001, 2002 Cluster File Systems, Inc.
+ *  Copyright (C) 2001-2003 Cluster File Systems, Inc.
  *
  *   This file is part of Lustre, http://www.lustre.org.
  *
 #define __LINUX_CLASS_OBD_H
 
 #ifndef __KERNEL__
-# include <stdint.h>
-# define __KERNEL__
-# include <linux/list.h>
-# undef __KERNEL__
+#include <sys/types.h>
+#include <portals/list.h>
 #else
 #include <asm/segment.h>
 #include <asm/uaccess.h>
 #include <linux/types.h>
 #include <linux/fs.h>
 #include <linux/time.h>
+#include <linux/timer.h>
+#endif
 
 #include <linux/obd_support.h>
+#include <linux/lustre_import.h>
+#include <linux/lustre_net.h>
 #include <linux/obd.h>
 #include <linux/lustre_lib.h>
 #include <linux/lustre_idl.h>
-#include <linux/lustre_mds.h>
-#include <linux/lustre_dlm.h>
-#endif
+#include <linux/lprocfs_status.h>
+#include <linux/lustre_log.h>
 
-
-/*
- *  ======== OBD Device Declarations ===========
- */
-#define MAX_OBD_DEVICES 128
+/* OBD Device Declarations */
+#define MAX_OBD_DEVICES 256
 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
 
-#define OBD_ATTACHED 0x1
-#define OBD_SET_UP   0x2
+/* OBD Operations Declarations */
+extern struct obd_device *class_conn2obd(struct lustre_handle *);
+extern struct obd_device *class_exp2obd(struct obd_export *);
 
-extern struct proc_dir_entry *
-proc_lustre_register_obd_device(struct obd_device *obd);
-extern void proc_lustre_release_obd_device(struct obd_device *obd);
-extern void proc_lustre_remove_obd_entry(const char* name,
-                                         struct obd_device *obd);
+/* genops.c */
+struct obd_export *class_conn2export(struct lustre_handle *);
+int class_register_type(struct obd_ops *ops, struct md_ops *md_ops,
+                        struct lprocfs_vars *, char *nm);
+int class_unregister_type(char *nm);
 
-/*
- *  ======== OBD Operations Declarations ===========
- */
+struct obd_device *class_newdev(int *dev);
+
+int class_name2dev(char *name);
+struct obd_device *class_name2obd(char *name);
+int class_uuid2dev(struct obd_uuid *uuid);
+struct obd_device *class_uuid2obd(struct obd_uuid *uuid);
+struct obd_device * class_find_client_obd(struct obd_uuid *tgt_uuid,
+                                          char * typ_name,
+                                          struct obd_uuid *grp_uuid);
+struct obd_device * class_devices_in_group(struct obd_uuid *grp_uuid,
+                                           int *next);
+
+int oig_init(struct obd_io_group **oig);
+void oig_add_one(struct obd_io_group *oig,
+                  struct oig_callback_context *occ);
+void oig_complete_one(struct obd_io_group *oig,
+                       struct oig_callback_context *occ, int rc);
+void oig_release(struct obd_io_group *oig);
+int oig_wait(struct obd_io_group *oig);
+
+/* obd_config.c */
+int class_process_config(struct lustre_cfg *lcfg);
+
+/* Passed as data param to class_config_parse_handler() */
+struct config_llog_instance {
+        char * cfg_instance;
+        struct obd_uuid cfg_uuid;
+        ptl_nid_t cfg_local_nid;
+};
+
+int class_config_process_llog(struct llog_ctxt *ctxt, char *name,
+                              struct config_llog_instance *cfg);
+int class_config_dump_llog(struct llog_ctxt *ctxt, char *name,
+                           struct config_llog_instance *cfg);
+
+struct lustre_profile {
+        struct list_head lp_list;
+        char * lp_profile;
+        char * lp_osc;
+        char * lp_mdc;
+};
+
+struct lustre_profile *class_get_profile(char * prof);
+void class_del_profile(char *prof);
+
+#define class_export_rpc_get(exp)                                       \
+({                                                                      \
+        atomic_inc(&(exp)->exp_rpc_count);                              \
+        CDEBUG(D_INFO, "RPC GETting export %p : new rpc_count %d\n",    \
+               (exp), atomic_read(&(exp)->exp_rpc_count));              \
+        class_export_get(exp);                                          \
+})
+
+#define class_export_rpc_put(exp)                                       \
+({                                                                      \
+        atomic_dec(&(exp)->exp_rpc_count);                              \
+        CDEBUG(D_INFO, "RPC PUTting export %p : new rpc_count %d\n",    \
+               (exp), atomic_read(&(exp)->exp_rpc_count));              \
+        class_export_put(exp);                                          \
+})
+
+#define class_export_get(exp)                                                  \
+({                                                                             \
+        struct obd_export *exp_ = exp;                                         \
+        atomic_inc(&exp_->exp_refcount);                                       \
+        CDEBUG(D_INFO, "GETting export %p : new refcount %d\n", exp_,          \
+               atomic_read(&exp_->exp_refcount));                              \
+        exp_;                                                                  \
+})
+
+#define class_export_put(exp)                                                  \
+do {                                                                           \
+        LASSERT((exp) != NULL);                                                \
+        CDEBUG(D_INFO, "PUTting export %p : new refcount %d\n", (exp),         \
+               atomic_read(&(exp)->exp_refcount) - 1);                         \
+        LASSERT(atomic_read(&(exp)->exp_refcount) > 0);                        \
+        LASSERT(atomic_read(&(exp)->exp_refcount) < 0x5a5a5a);                 \
+        __class_export_put(exp);                                               \
+} while (0)
+void __class_export_put(struct obd_export *);
+struct obd_export *class_new_export(struct obd_device *obddev);
+void class_unlink_export(struct obd_export *exp);
+
+struct obd_import *class_import_get(struct obd_import *);
+void class_import_put(struct obd_import *);
+struct obd_import *class_new_import(void);
+void class_destroy_import(struct obd_import *exp);
+
+struct obd_type *class_get_type(char *name);
+void class_put_type(struct obd_type *type);
+int class_connect(struct lustre_handle *conn, struct obd_device *obd,
+                  struct obd_uuid *cluuid);
+int class_disconnect(struct obd_export *exp, int failover);
+void class_disconnect_exports(struct obd_device *obddev, int failover);
+/* generic operations shared by various OBD types */
+int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
+int class_multi_cleanup(struct obd_device *obddev);
 
+/* obdo.c */
 #ifdef __KERNEL__
+void obdo_from_iattr(struct obdo *oa, struct iattr *attr, unsigned ia_valid);
+void iattr_from_obdo(struct iattr *attr, struct obdo *oa, obd_flag valid);
+void obdo_from_inode(struct obdo *dst, struct inode *src, obd_flag valid);
+void obdo_refresh_inode(struct inode *dst, struct obdo *src, obd_flag valid);
+void obdo_to_inode(struct inode *dst, struct obdo *src, obd_flag valid);
+#endif
+void obdo_cpy_md(struct obdo *dst, struct obdo *src, obd_flag valid);
+int obdo_cmp_md(struct obdo *dst, struct obdo *src, obd_flag compare);
+void obdo_to_ioobj(struct obdo *oa, struct obd_ioobj *ioobj);
+
 static inline int obd_check_conn(struct lustre_handle *conn)
 {
         struct obd_device *obd;
@@ -71,18 +175,19 @@ static inline int obd_check_conn(struct lustre_handle *conn)
                 CERROR("NULL conn\n");
                 RETURN(-ENOTCONN);
         }
+
         obd = class_conn2obd(conn);
         if (!obd) {
                 CERROR("NULL obd\n");
                 RETURN(-ENODEV);
         }
 
-        if (!obd->obd_flags & OBD_ATTACHED ) {
+        if (!obd->obd_attached) {
                 CERROR("obd %d not attached\n", obd->obd_minor);
                 RETURN(-ENODEV);
         }
 
-        if (!obd->obd_flags & OBD_SET_UP) {
+        if (!obd->obd_set_up) {
                 CERROR("obd %d not setup\n", obd->obd_minor);
                 RETURN(-ENODEV);
         }
@@ -103,680 +208,1304 @@ static inline int obd_check_conn(struct lustre_handle *conn)
 
 #define OBT(dev)        (dev)->obd_type
 #define OBP(dev, op)    (dev)->obd_type->typ_ops->o_ ## op
+#define MDP(dev, op)    (dev)->obd_type->typ_md_ops->m_ ## op
+#define CTXTP(ctxt, op) (ctxt)->loc_logops->lop_##op
+
+/* Ensure obd_setup: used for disconnect which might be called while
+   an obd is stopping. */
+#define OBD_CHECK_SETUP(conn, exp)                                      \
+do {                                                                    \
+        if (!(conn)) {                                                  \
+                CERROR("NULL connection\n");                            \
+                RETURN(-EINVAL);                                        \
+        }                                                               \
+                                                                        \
+        exp = class_conn2export(conn);                                  \
+        if (!(exp)) {                                                   \
+                CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
+                RETURN(-EINVAL);                                        \
+        }                                                               \
+                                                                        \
+        if (!(exp)->exp_obd->obd_set_up) {                              \
+                CERROR("Device %d not setup\n",                         \
+                       (exp)->exp_obd->obd_minor);                      \
+                class_export_put(exp);                                  \
+                RETURN(-EINVAL);                                        \
+        }                                                               \
+} while (0)
 
-#define OBD_CHECK_SETUP(conn, exp)                              \
+/* Ensure obd_setup and !obd_stopping. */
+#define OBD_CHECK_ACTIVE(conn, exp)                                     \
+do {                                                                    \
+        if (!(conn)) {                                                  \
+                CERROR("NULL connection\n");                            \
+                RETURN(-EINVAL);                                        \
+        }                                                               \
+                                                                        \
+        exp = class_conn2export(conn);                                  \
+        if (!(exp)) {                                                   \
+                CERROR("No export for conn "LPX64"\n", (conn)->cookie); \
+                RETURN(-EINVAL);                                        \
+        }                                                               \
+                                                                        \
+        if (!(exp)->exp_obd->obd_set_up || (exp)->exp_obd->obd_stopping) { \
+                CERROR("Device %d not setup\n",                         \
+                       (exp)->exp_obd->obd_minor);                      \
+                class_export_put(exp);                                  \
+                RETURN(-EINVAL);                                        \
+        }                                                               \
+} while (0)
+
+/* Ensure obd_setup: used for cleanup which must be called
+   while obd is stopping */
+#define OBD_CHECK_DEV_STOPPING(obd)                             \
 do {                                                            \
-        if (!(conn)) {                                          \
-                CERROR("NULL connection\n");                    \
-                RETURN(-EINVAL);                                \
+        if (!(obd)) {                                           \
+                CERROR("NULL device\n");                        \
+                RETURN(-ENODEV);                                \
         }                                                       \
                                                                 \
-        exp = class_conn2export(conn);                          \
-        if (!(exp)) {                                           \
-                CERROR("No export\n");                          \
-                RETURN(-EINVAL);                                \
+        if (!(obd)->obd_set_up) {                               \
+                CERROR("Device %d not setup\n",                 \
+                       (obd)->obd_minor);                       \
+                RETURN(-ENODEV);                                \
         }                                                       \
                                                                 \
-        if (!((exp)->exp_obd->obd_flags & OBD_SET_UP)) {        \
-                CERROR("Device %d not setup\n",                 \
-                       (exp)->exp_obd->obd_minor);              \
-                RETURN(-EINVAL);                                \
+        if (!(obd)->obd_stopping) {                             \
+                CERROR("Device %d not stopping\n",              \
+                       (obd)->obd_minor);                       \
+                RETURN(-ENODEV);                                \
         }                                                       \
 } while (0)
 
-#define OBD_CHECK_DEVSETUP(obd)                                 \
+/* ensure obd_setup and !obd_stopping */
+#define OBD_CHECK_DEV_ACTIVE(obd)                               \
 do {                                                            \
         if (!(obd)) {                                           \
                 CERROR("NULL device\n");                        \
-                RETURN(-EINVAL);                                \
+                RETURN(-ENODEV);                                \
         }                                                       \
                                                                 \
-        if (!((obd)->obd_flags & OBD_SET_UP)) {                 \
+        if (!(obd)->obd_set_up || (obd)->obd_stopping) {        \
                 CERROR("Device %d not setup\n",                 \
                        (obd)->obd_minor);                       \
-                RETURN(-EINVAL);                                \
+                RETURN(-ENODEV);                                \
+        }                                                       \
+} while (0)
+
+
+#ifdef LPROCFS
+#define OBD_COUNTER_OFFSET(op)                                  \
+        ((offsetof(struct obd_ops, o_ ## op) -                  \
+          offsetof(struct obd_ops, o_iocontrol))                \
+         / sizeof(((struct obd_ops *)(0))->o_iocontrol))
+
+#define OBD_COUNTER_INCREMENT(obd, op)                          \
+        if ((obd)->obd_stats != NULL) {                         \
+                unsigned int coffset;                           \
+                coffset = (unsigned int)(obd)->obd_cntr_base +  \
+                        OBD_COUNTER_OFFSET(op);                 \
+                LASSERT(coffset < obd->obd_stats->ls_num);      \
+                lprocfs_counter_incr(obd->obd_stats, coffset);  \
+        }
+/* FIXME: real accounting here */
+#define MD_COUNTER_INCREMENT(obd, op)
+#else
+#define OBD_COUNTER_OFFSET(op)
+#define OBD_COUNTER_INCREMENT(obd, op)
+#define MD_COUNTER_INCREMENT(obd, op)
+#endif
+
+#define OBD_CHECK_MD_OP(obd, op, err)                           \
+do {                                                            \
+        if (!OBT(obd) || !MDP((obd), op)) {\
+                if (err)                                        \
+                        CERROR("obd_md" #op ": dev %d no operation\n",    \
+                               obd->obd_minor);                 \
+                RETURN(err);                                    \
         }                                                       \
 } while (0)
 
-#define OBD_CHECK_OP(obd, op)                                   \
+#define EXP_CHECK_MD_OP(exp, op)                                \
 do {                                                            \
-        if (!OBP((obd), op)) {                                  \
+        if ((exp) == NULL) {                                    \
+                CERROR("obd_" #op ": NULL export\n");           \
+                RETURN(-ENODEV);                                \
+        }                                                       \
+        if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
+                CERROR("obd_" #op ": cleaned up obd\n");        \
+                RETURN(-EOPNOTSUPP);                            \
+        }                                                       \
+        if (!OBT((exp)->exp_obd) || !MDP((exp)->exp_obd, op)) { \
                 CERROR("obd_" #op ": dev %d no operation\n",    \
-                       obd->obd_minor);                         \
+                       (exp)->exp_obd->obd_minor);              \
                 RETURN(-EOPNOTSUPP);                            \
         }                                                       \
 } while (0)
 
-static inline int obd_get_info(struct lustre_handle *conn, obd_count keylen,
-                               void *key, obd_count *vallen, void **val)
+#define OBD_CHECK_OP(obd, op, err)                              \
+do {                                                            \
+        if (!OBT(obd) || !OBP((obd), op)) {\
+                if (err)                                        \
+                        CERROR("obd_" #op ": dev %d no operation\n",    \
+                               obd->obd_minor);                         \
+                RETURN(err);                                    \
+        }                                                       \
+} while (0)
+
+#define EXP_CHECK_OP(exp, op)                                   \
+do {                                                            \
+        if ((exp) == NULL) {                                    \
+                CERROR("obd_" #op ": NULL export\n");           \
+                RETURN(-ENODEV);                                \
+        }                                                       \
+        if ((exp)->exp_obd == NULL || !OBT((exp)->exp_obd)) {   \
+                CERROR("obd_" #op ": cleaned up obd\n");        \
+                RETURN(-EOPNOTSUPP);                            \
+        }                                                       \
+        if (!OBT((exp)->exp_obd) || !OBP((exp)->exp_obd, op)) { \
+                CERROR("obd_" #op ": dev %d no operation\n",    \
+                       (exp)->exp_obd->obd_minor);              \
+                RETURN(-EOPNOTSUPP);                            \
+        }                                                       \
+} while (0)
+
+#define CTXT_CHECK_OP(ctxt, op, err)                                         \
+do {                                                            \
+        if (!OBT(ctxt->loc_obd) || !CTXTP((ctxt), op)) {                     \
+                if (err)                                        \
+                        CERROR("lop_" #op ": dev %d no operation\n",    \
+                               ctxt->loc_obd->obd_minor);                         \
+                RETURN(err);                                    \
+        }                                                       \
+} while (0)
+
+static inline int obd_get_info(struct obd_export *exp, __u32 keylen,
+                               void *key, __u32 *vallen, void *val)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, get_info);
+        EXP_CHECK_OP(exp, get_info);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, get_info);
 
-        rc = OBP(exp->exp_obd, get_info)(conn, keylen, key, vallen, val);
+        rc = OBP(exp->exp_obd, get_info)(exp, keylen, key, vallen, val);
         RETURN(rc);
 }
 
-static inline int obd_set_info(struct lustre_handle *conn, obd_count keylen,
+static inline int obd_set_info(struct obd_export *exp, obd_count keylen,
                                void *key, obd_count vallen, void *val)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, set_info);
+        EXP_CHECK_OP(exp, set_info);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, set_info);
 
-        rc = OBP(exp->exp_obd, set_info)(conn, keylen, key, vallen, val);
+        rc = OBP(exp->exp_obd, set_info)(exp, keylen, key, vallen, val);
         RETURN(rc);
 }
 
 static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
 {
         int rc;
+        ENTRY;
 
-        OBD_CHECK_OP(obd, setup);
+        OBD_CHECK_OP(obd, setup, -EOPNOTSUPP);
+        OBD_COUNTER_INCREMENT(obd, setup);
 
         rc = OBP(obd, setup)(obd, datalen, data);
         RETURN(rc);
 }
 
-static inline int obd_cleanup(struct obd_device *obd)
+static inline int obd_precleanup(struct obd_device *obd, int flags)
 {
         int rc;
+        ENTRY;
 
-        OBD_CHECK_DEVSETUP(obd);
-        OBD_CHECK_OP(obd, cleanup);
+        OBD_CHECK_OP(obd, precleanup, 0);
+        OBD_COUNTER_INCREMENT(obd, precleanup);
 
-        rc = OBP(obd, cleanup)(obd);
+        rc = OBP(obd, precleanup)(obd, flags);
         RETURN(rc);
 }
 
-static inline int obd_create(struct lustre_handle *conn, struct obdo *obdo,
-                             struct lov_stripe_md **ea)
+static inline int obd_cleanup(struct obd_device *obd, int flags)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, create);
+        OBD_CHECK_DEV_STOPPING(obd);
+        OBD_CHECK_OP(obd, cleanup, 0);
+        OBD_COUNTER_INCREMENT(obd, cleanup);
 
-        rc = OBP(exp->exp_obd, create)(conn, obdo, ea);
+        rc = OBP(obd, cleanup)(obd, flags);
         RETURN(rc);
 }
 
-static inline int obd_destroy(struct lustre_handle *conn, struct obdo *obdo,
-                              struct lov_stripe_md *ea)
+static inline int
+obd_process_config(struct obd_device *obd, int datalen, void *data)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, destroy);
+        OBD_CHECK_OP(obd, process_config, -EOPNOTSUPP);
+        OBD_COUNTER_INCREMENT(obd, process_config);
 
-        rc = OBP(exp->exp_obd, destroy)(conn, obdo, ea);
+        rc = OBP(obd, process_config)(obd, datalen, data);
         RETURN(rc);
 }
 
-static inline int obd_getattr(struct lustre_handle *conn, struct obdo *obdo,
-                              struct lov_stripe_md *ea)
+/* Pack an in-memory MD struct for storage on disk.
+ * Returns +ve size of packed MD (0 for free), or -ve error.
+ *
+ * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
+ * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
+ * If @*disk_tgt == NULL, it will be allocated
+ */
+static inline int obd_packmd(struct obd_export *exp,
+                             struct lov_mds_md **disk_tgt,
+                             struct lov_stripe_md *mem_src)
+{
+        int rc;
+        ENTRY;
+
+        EXP_CHECK_OP(exp, packmd);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, packmd);
+
+        rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
+        RETURN(rc);
+}
+
+static inline int obd_size_diskmd(struct obd_export *exp,
+                                  struct lov_stripe_md *mem_src)
+{
+        return obd_packmd(exp, NULL, mem_src);
+}
+
+/* helper functions */
+static inline int obd_alloc_diskmd(struct obd_export *exp,
+                                   struct lov_mds_md **disk_tgt)
+{
+        LASSERT(disk_tgt);
+        LASSERT(*disk_tgt == NULL);
+        return obd_packmd(exp, disk_tgt, NULL);
+}
+
+static inline int obd_free_diskmd(struct obd_export *exp,
+                                  struct lov_mds_md **disk_tgt)
+{
+        LASSERT(disk_tgt);
+        LASSERT(*disk_tgt);
+        return obd_packmd(exp, disk_tgt, NULL);
+}
+
+/* Unpack an MD struct from disk to in-memory format.
+ * Returns +ve size of unpacked MD (0 for free), or -ve error.
+ *
+ * If @mem_tgt == NULL, MD size is returned (max size if @disk_src == NULL).
+ * If @*mem_tgt != NULL and @disk_src == NULL, @*mem_tgt will be freed.
+ * If @*mem_tgt == NULL, it will be allocated
+ */
+static inline int obd_unpackmd(struct obd_export *exp,
+                               struct lov_stripe_md **mem_tgt,
+                               struct lov_mds_md *disk_src,
+                               int disk_len)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, getattr);
+        EXP_CHECK_OP(exp, unpackmd);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, unpackmd);
 
-        rc = OBP(exp->exp_obd, getattr)(conn, obdo, ea);
+        rc = OBP(exp->exp_obd, unpackmd)(exp, mem_tgt, disk_src, disk_len);
         RETURN(rc);
 }
 
-static inline int obd_close(struct lustre_handle *conn, struct obdo *obdo,
-                            struct lov_stripe_md *ea)
+/* helper functions */
+static inline int obd_alloc_memmd(struct obd_export *exp,
+                                  struct lov_stripe_md **mem_tgt)
+{
+        LASSERT(mem_tgt);
+        LASSERT(*mem_tgt == NULL);
+        return obd_unpackmd(exp, mem_tgt, NULL, 0);
+}
+
+static inline int obd_free_memmd(struct obd_export *exp,
+                                 struct lov_stripe_md **mem_tgt)
+{
+        LASSERT(mem_tgt);
+        LASSERT(*mem_tgt);
+        return obd_unpackmd(exp, mem_tgt, NULL, 0);
+}
+
+static inline int obd_revalidate_md(struct obd_export *exp, struct obdo *obdo,
+                                    struct lov_stripe_md *ea,
+                                    struct obd_trans_info *oti)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, close);
+        EXP_CHECK_OP(exp, revalidate_md);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, revalidate_md);
 
-        rc = OBP(exp->exp_obd, close)(conn, obdo, ea);
+        rc = OBP(exp->exp_obd, revalidate_md)(exp, obdo, ea, oti);
         RETURN(rc);
 }
 
-static inline int obd_open(struct lustre_handle *conn, struct obdo *obdo,
-                           struct lov_stripe_md *ea)
+static inline int obd_create(struct obd_export *exp, struct obdo *obdo,
+                             struct lov_stripe_md **ea,
+                             struct obd_trans_info *oti)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, open);
+        EXP_CHECK_OP(exp, create);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, create);
 
-        rc = OBP(exp->exp_obd, open)(conn, obdo, ea);
+        rc = OBP(exp->exp_obd, create)(exp, obdo, ea, oti);
         RETURN(rc);
 }
 
-static inline int obd_setattr(struct lustre_handle *conn, struct obdo *obdo,
+static inline int obd_destroy(struct obd_export *exp, struct obdo *obdo,
+                              struct lov_stripe_md *ea,
+                              struct obd_trans_info *oti)
+{
+        int rc;
+        ENTRY;
+
+        EXP_CHECK_OP(exp, destroy);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, destroy);
+
+        rc = OBP(exp->exp_obd, destroy)(exp, obdo, ea, oti);
+        RETURN(rc);
+}
+
+static inline int obd_getattr(struct obd_export *exp, struct obdo *obdo,
                               struct lov_stripe_md *ea)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, setattr);
+        EXP_CHECK_OP(exp, getattr);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
 
-        rc = OBP(exp->exp_obd, setattr)(conn, obdo, ea);
+        rc = OBP(exp->exp_obd, getattr)(exp, obdo, ea);
+        RETURN(rc);
+}
+
+static inline int obd_getattr_async(struct obd_export *exp,
+                                    struct obdo *obdo, struct lov_stripe_md *ea,
+                                    struct ptlrpc_request_set *set)
+{
+        int rc;
+        ENTRY;
+
+        EXP_CHECK_OP(exp, getattr);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, getattr);
+
+        rc = OBP(exp->exp_obd, getattr_async)(exp, obdo, ea, set);
+        RETURN(rc);
+}
+
+static inline int obd_setattr(struct obd_export *exp, struct obdo *obdo,
+                              struct lov_stripe_md *ea,
+                              struct obd_trans_info *oti)
+{
+        int rc;
+        ENTRY;
+
+        EXP_CHECK_OP(exp, setattr);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, setattr);
+
+        rc = OBP(exp->exp_obd, setattr)(exp, obdo, ea, oti);
         RETURN(rc);
 }
 
 static inline int obd_connect(struct lustre_handle *conn,
-                              struct obd_device *obd, obd_uuid_t cluuid,
-                              struct recovd_obd *recovd,
-                              ptlrpc_recovery_cb_t recover)
+                              struct obd_device *obd, struct obd_uuid *cluuid)
 {
         int rc;
+        ENTRY;
 
-        OBD_CHECK_DEVSETUP(obd);
-        OBD_CHECK_OP(obd, connect);
+        OBD_CHECK_DEV_ACTIVE(obd);
+        OBD_CHECK_OP(obd, connect, -EOPNOTSUPP);
+        OBD_COUNTER_INCREMENT(obd, connect);
 
-        rc = OBP(obd, connect)(conn, obd, cluuid, recovd, recover);
+        rc = OBP(obd, connect)(conn, obd, cluuid);
         RETURN(rc);
 }
 
-static inline int obd_disconnect(struct lustre_handle *conn)
+static inline int obd_disconnect(struct obd_export *exp, int flags)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
+
+        EXP_CHECK_OP(exp, disconnect);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, disconnect);
+
+        rc = OBP(exp->exp_obd, disconnect)(exp, flags);
+        RETURN(rc);
+}
+
+static inline int obd_init_export(struct obd_export *exp)
+{
+        int rc = 0;
+
+        ENTRY;
+        if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
+            OBP((exp)->exp_obd, init_export))
+                rc = OBP(exp->exp_obd, init_export)(exp);
+        RETURN(rc);
+}
+
+static inline int obd_destroy_export(struct obd_export *exp)
+{
+        ENTRY;
+        if ((exp)->exp_obd != NULL && OBT((exp)->exp_obd) &&
+            OBP((exp)->exp_obd, destroy_export))
+                OBP(exp->exp_obd, destroy_export)(exp);
+        RETURN(0);
+}
+
+static inline struct dentry *
+obd_lvfs_fid2dentry(struct obd_export *exp, __u64 id_ino, __u32 gen, __u64 gr)
+{
+        LASSERT(exp->exp_obd);
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, disconnect);
+        return lvfs_fid2dentry(&exp->exp_obd->obd_lvfs_ctxt, id_ino, gen, gr,
+                               exp->exp_obd);
+}
+
+#ifndef time_before
+#define time_before(t1, t2) ((long)t2 - (long)t1 > 0)
+#endif
 
-        rc = OBP(exp->exp_obd, disconnect)(conn);
+/* @max_age is the oldest time in jiffies that we accept using a cached data.
+ * If the cache is older than @max_age we will get a new value from the
+ * target.  Use a value of "jiffies + HZ" to guarantee freshness. */
+static inline int obd_statfs(struct obd_device *obd, struct obd_statfs *osfs,
+                             unsigned long max_age)
+{
+        int rc = 0;
+        ENTRY;
+
+        if (obd == NULL)
+                RETURN(-EINVAL);
+
+        OBD_CHECK_OP(obd, statfs, -EOPNOTSUPP);
+        OBD_COUNTER_INCREMENT(obd, statfs);
+
+        CDEBUG(D_SUPER, "osfs %lu, max_age %lu\n", obd->obd_osfs_age, max_age);
+        if (time_before(obd->obd_osfs_age, max_age)) {
+                rc = OBP(obd, statfs)(obd, osfs, max_age);
+                if (rc == 0) {
+                        spin_lock(&obd->obd_osfs_lock);
+                        memcpy(&obd->obd_osfs, osfs, sizeof(obd->obd_osfs));
+                        obd->obd_osfs_age = jiffies;
+                        spin_unlock(&obd->obd_osfs_lock);
+                }
+        } else {
+                CDEBUG(D_SUPER, "using cached obd_statfs data\n");
+                spin_lock(&obd->obd_osfs_lock);
+                memcpy(osfs, &obd->obd_osfs, sizeof(*osfs));
+                spin_unlock(&obd->obd_osfs_lock);
+        }
         RETURN(rc);
 }
 
-static inline int obd_statfs(struct lustre_handle *conn,struct obd_statfs *osfs)
+static inline int obd_sync(struct obd_export *exp, struct obdo *oa,
+                           struct lov_stripe_md *ea, obd_size start,
+                           obd_size end)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, statfs);
+        OBD_CHECK_OP(exp->exp_obd, sync, -EOPNOTSUPP);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, sync);
 
-        rc = OBP(exp->exp_obd, statfs)(conn, osfs);
+        rc = OBP(exp->exp_obd, sync)(exp, oa, ea, start, end);
         RETURN(rc);
 }
 
-static inline int obd_punch(struct lustre_handle *conn, struct obdo *oa,
-                            struct lov_stripe_md *ea,
-                            obd_size start, obd_size end)
+static inline int obd_punch(struct obd_export *exp, struct obdo *oa,
+                            struct lov_stripe_md *ea, obd_size start,
+                            obd_size end, struct obd_trans_info *oti)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, punch);
+        EXP_CHECK_OP(exp, punch);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, punch);
 
-        rc = OBP(exp->exp_obd, punch)(conn, oa, ea, start, end);
+        rc = OBP(exp->exp_obd, punch)(exp, oa, ea, start, end, oti);
         RETURN(rc);
 }
 
-static inline int obd_brw(int cmd, struct lustre_handle *conn,
+static inline int obd_brw(int cmd, struct obd_export *exp, struct obdo *oa,
                           struct lov_stripe_md *ea, obd_count oa_bufs,
-                          struct brw_page *pg,
-                          brw_callback_t callback, void *data)
+                          struct brw_page *pg, struct obd_trans_info *oti)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, brw);
+        EXP_CHECK_OP(exp, brw);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, brw);
+
+        if (!(cmd & (OBD_BRW_RWMASK | OBD_BRW_CHECK))) {
+                CERROR("obd_brw: cmd must be OBD_BRW_READ, OBD_BRW_WRITE, "
+                       "or OBD_BRW_CHECK\n");
+                LBUG();
+        }
+
+        rc = OBP(exp->exp_obd, brw)(cmd, exp, oa, ea, oa_bufs, pg, oti);
+        RETURN(rc);
+}
+
+static inline int obd_brw_async(int cmd, struct obd_export *exp,
+                                struct obdo *oa, struct lov_stripe_md *ea,
+                                obd_count oa_bufs, struct brw_page *pg,
+                                struct ptlrpc_request_set *set,
+                                struct obd_trans_info *oti)
+{
+        int rc;
+        ENTRY;
+
+        EXP_CHECK_OP(exp, brw_async);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, brw_async);
 
         if (!(cmd & OBD_BRW_RWMASK)) {
                 CERROR("obd_brw: cmd must be OBD_BRW_READ or OBD_BRW_WRITE\n");
                 LBUG();
         }
 
-        rc = OBP(exp->exp_obd, brw)(cmd, conn, ea, oa_bufs, pg, callback, data);
+        rc = OBP(exp->exp_obd, brw_async)(cmd, exp, oa, ea, oa_bufs, pg, set,
+                                          oti);
+        RETURN(rc);
+}
+
+static inline  int obd_prep_async_page(struct obd_export *exp,
+                                       struct lov_stripe_md *lsm,
+                                       struct lov_oinfo *loi,
+                                       struct page *page, obd_off offset,
+                                       struct obd_async_page_ops *ops,
+                                       void *data, void **res)
+{
+        int ret;
+        ENTRY;
+
+        OBD_CHECK_OP(exp->exp_obd, prep_async_page, -EOPNOTSUPP);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, prep_async_page);
+
+        ret = OBP(exp->exp_obd, prep_async_page)(exp, lsm, loi, page, offset,
+                                                 ops, data, res);
+        RETURN(ret);
+}
+
+static inline int obd_queue_async_io(struct obd_export *exp,
+                                     struct lov_stripe_md *lsm,
+                                     struct lov_oinfo *loi, void *cookie,
+                                     int cmd, obd_off off, int count,
+                                     obd_flag brw_flags, obd_flag async_flags)
+{
+        int rc;
+        ENTRY;
+
+        OBD_CHECK_OP(exp->exp_obd, queue_async_io, -EOPNOTSUPP);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, queue_async_io);
+        LASSERT(cmd & OBD_BRW_RWMASK);
+
+        rc = OBP(exp->exp_obd, queue_async_io)(exp, lsm, loi, cookie, cmd, off,
+                                               count, brw_flags, async_flags);
+        RETURN(rc);
+}
+
+static inline int obd_set_async_flags(struct obd_export *exp,
+                                      struct lov_stripe_md *lsm,
+                                      struct lov_oinfo *loi, void *cookie,
+                                      obd_flag async_flags)
+{
+        int rc;
+        ENTRY;
+
+        OBD_CHECK_OP(exp->exp_obd, set_async_flags, -EOPNOTSUPP);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, set_async_flags);
+
+        rc = OBP(exp->exp_obd, set_async_flags)(exp, lsm, loi, cookie,
+                                                async_flags);
+        RETURN(rc);
+}
+
+static inline int obd_queue_group_io(struct obd_export *exp,
+                                     struct lov_stripe_md *lsm,
+                                     struct lov_oinfo *loi,
+                                     struct obd_io_group *oig,
+                                     void *cookie, int cmd, obd_off off,
+                                     int count, obd_flag brw_flags,
+                                     obd_flag async_flags)
+{
+        int rc;
+        ENTRY;
+
+        OBD_CHECK_OP(exp->exp_obd, queue_group_io, -EOPNOTSUPP);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, queue_group_io);
+        LASSERT(cmd & OBD_BRW_RWMASK);
+
+        rc = OBP(exp->exp_obd, queue_group_io)(exp, lsm, loi, oig, cookie,
+                                               cmd, off, count, brw_flags,
+                                               async_flags);
+        RETURN(rc);
+}
+
+static inline int obd_trigger_group_io(struct obd_export *exp,
+                                       struct lov_stripe_md *lsm,
+                                       struct lov_oinfo *loi,
+                                       struct obd_io_group *oig)
+{
+        int rc;
+        ENTRY;
+
+        OBD_CHECK_OP(exp->exp_obd, trigger_group_io, -EOPNOTSUPP);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, trigger_group_io);
+
+        rc = OBP(exp->exp_obd, trigger_group_io)(exp, lsm, loi, oig);
+        RETURN(rc);
+}
+
+static inline int obd_teardown_async_page(struct obd_export *exp,
+                                          struct lov_stripe_md *lsm,
+                                          struct lov_oinfo *loi, void *cookie)
+{
+        int rc;
+        ENTRY;
+
+        OBD_CHECK_OP(exp->exp_obd, teardown_async_page, -EOPNOTSUPP);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, teardown_async_page);
+
+        rc = OBP(exp->exp_obd, teardown_async_page)(exp, lsm, loi, cookie);
         RETURN(rc);
 }
 
-static inline int obd_preprw(int cmd, struct lustre_handle *conn,
+static inline int obd_preprw(int cmd, struct obd_export *exp, struct obdo *oa,
                              int objcount, struct obd_ioobj *obj,
                              int niocount, struct niobuf_remote *remote,
-                             struct niobuf_local *local, void **desc_private)
+                             struct niobuf_local *local,
+                             struct obd_trans_info *oti)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, preprw);
+        OBD_CHECK_OP(exp->exp_obd, preprw, -EOPNOTSUPP);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
 
-        rc = OBP(exp->exp_obd, preprw)(cmd, conn, objcount, obj, niocount,
-                                       remote, local, desc_private);
+        rc = OBP(exp->exp_obd, preprw)(cmd, exp, oa, objcount, obj, niocount,
+                                       remote, local, oti);
         RETURN(rc);
 }
 
-static inline int obd_commitrw(int cmd, struct lustre_handle *conn,
+static inline int obd_commitrw(int cmd, struct obd_export *exp, struct obdo *oa,
                                int objcount, struct obd_ioobj *obj,
                                int niocount, struct niobuf_local *local,
-                               void *desc_private)
+                               struct obd_trans_info *oti, int rc)
+{
+        ENTRY;
+
+        OBD_CHECK_OP(exp->exp_obd, commitrw, -EOPNOTSUPP);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, commitrw);
+
+        rc = OBP(exp->exp_obd, commitrw)(cmd, exp, oa, objcount, obj, niocount,
+                                         local, oti, rc);
+        RETURN(rc);
+}
+
+static inline int obd_do_cow(struct obd_export *exp, struct obd_ioobj *obj,
+                            int objcount,struct niobuf_remote *rnb)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
+
+        /* there are cases when write_extents is not implemented. */
+        if (!OBP(exp->exp_obd, do_cow))
+                RETURN(0);
+                
+        OBD_COUNTER_INCREMENT(exp->exp_obd, do_cow);
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, commitrw);
+        rc = OBP(exp->exp_obd, do_cow)(exp, obj, objcount, rnb);
 
-        rc = OBP(exp->exp_obd, commitrw)(cmd, conn, objcount, obj, niocount,
-                                         local, desc_private);
         RETURN(rc);
 }
 
-static inline int obd_iocontrol(int cmd, struct lustre_handle *conn,
+static inline int obd_write_extents(struct obd_export *exp, 
+                                    struct obd_ioobj *obj,
+                                    int objcount, int niocount,  
+                                    struct niobuf_local *local, 
+                                    int rc)
+{
+        ENTRY;
+
+        /* there are cases when write_extents is not implemented. */
+        if (!OBP(exp->exp_obd, write_extents))
+                RETURN(0);
+                
+        OBD_COUNTER_INCREMENT(exp->exp_obd, write_extents);
+
+        rc = OBP(exp->exp_obd, write_extents)(exp, obj, objcount, niocount, 
+                                              local, rc);
+        RETURN(rc);
+}
+
+static inline int obd_iocontrol(unsigned int cmd, struct obd_export *exp,
                                 int len, void *karg, void *uarg)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, iocontrol);
+        EXP_CHECK_OP(exp, iocontrol);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, iocontrol);
 
-        rc = OBP(exp->exp_obd, iocontrol)(cmd, conn, len, karg, uarg);
+        rc = OBP(exp->exp_obd, iocontrol)(cmd, exp, len, karg, uarg);
         RETURN(rc);
 }
 
-static inline int obd_enqueue(struct lustre_handle *conn,
-                              struct lov_stripe_md *ea,
-                              struct lustre_handle *parent_lock,
-                              __u32 type, void *cookie, int cookielen,
-                              __u32 mode, int *flags, void *cb, void *data,
-                              int datalen, struct lustre_handle *lockh)
+static inline int obd_enqueue(struct obd_export *exp, struct lov_stripe_md *ea,
+                              __u32 type, ldlm_policy_data_t *policy,
+                              __u32 mode, int *flags, void *bl_cb, void *cp_cb,
+                              void *gl_cb, void *data, __u32 lvb_len,
+                              void *lvb_swabber, struct lustre_handle *lockh)
+{
+        int rc;
+        ENTRY;
+
+        EXP_CHECK_OP(exp, enqueue);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
+
+        rc = OBP(exp->exp_obd, enqueue)(exp, ea, type, policy, mode, flags,
+                                        bl_cb, cp_cb, gl_cb, data, lvb_len,
+                                        lvb_swabber, lockh);
+        RETURN(rc);
+}
+
+static inline int obd_match(struct obd_export *exp, struct lov_stripe_md *ea,
+                            __u32 type, ldlm_policy_data_t *policy, __u32 mode,
+                            int *flags, void *data, struct lustre_handle *lockh)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, enqueue);
+        EXP_CHECK_OP(exp, match);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, match);
 
-        rc = OBP(exp->exp_obd, enqueue)(conn, ea, parent_lock, type,
-                                        cookie, cookielen, mode, flags, cb,
-                                        data, datalen, lockh);
+        rc = OBP(exp->exp_obd, match)(exp, ea, type, policy, mode, flags, data,
+                                      lockh);
         RETURN(rc);
 }
 
-static inline int obd_cancel(struct lustre_handle *conn,
+static inline int obd_change_cbdata(struct obd_export *exp,
+                                    struct lov_stripe_md *lsm,
+                                    ldlm_iterator_t it, void *data)
+{
+        int rc;
+        ENTRY;
+
+        EXP_CHECK_OP(exp, change_cbdata);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
+
+        rc = OBP(exp->exp_obd, change_cbdata)(exp, lsm, it, data);
+        RETURN(rc);
+}
+
+static inline int obd_cancel(struct obd_export *exp,
                              struct lov_stripe_md *ea, __u32 mode,
                              struct lustre_handle *lockh)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, cancel);
+        EXP_CHECK_OP(exp, cancel);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, cancel);
 
-        rc = OBP(exp->exp_obd, cancel)(conn, ea, mode, lockh);
+        rc = OBP(exp->exp_obd, cancel)(exp, ea, mode, lockh);
         RETURN(rc);
 }
 
-static inline int obd_cancel_unused(struct lustre_handle *conn,
-                                    struct lov_stripe_md *ea, int local)
+static inline int obd_cancel_unused(struct obd_export *exp,
+                                    struct lov_stripe_md *ea, int flags,
+                                    void *opaque)
 {
-        struct obd_export *exp;
         int rc;
+        ENTRY;
 
-        OBD_CHECK_SETUP(conn, exp);
-        OBD_CHECK_OP(exp->exp_obd, cancel_unused);
+        EXP_CHECK_OP(exp, cancel_unused);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, cancel_unused);
 
-        rc = OBP(exp->exp_obd, cancel_unused)(conn, ea, local);
+        rc = OBP(exp->exp_obd, cancel_unused)(exp, ea, flags, opaque);
         RETURN(rc);
 }
 
-#endif
 
-/*
- *  ======== OBD Metadata Support  ===========
- */
+static inline int obd_san_preprw(int cmd, struct obd_export *exp,
+                                 struct obdo *oa,
+                                 int objcount, struct obd_ioobj *obj,
+                                 int niocount, struct niobuf_remote *remote)
+{
+        int rc;
 
-extern int obd_init_caches(void);
-extern void obd_cleanup_caches(void);
+        EXP_CHECK_OP(exp, preprw);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, preprw);
+
+        rc = OBP(exp->exp_obd, san_preprw)(cmd, exp, oa, objcount, obj,
+                                           niocount, remote);
+        class_export_put(exp);
+        return(rc);
+}
 
-static inline struct lustre_handle *obdo_handle(struct obdo *oa)
+static inline int obd_pin(struct obd_export *exp, obd_id ino, __u32 gen,
+                          int type, struct obd_client_handle *handle, int flag)
 {
-        return (struct lustre_handle *)&oa->o_inline;
+        int rc;
+
+        EXP_CHECK_OP(exp, pin);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, pin);
+
+        rc = OBP(exp->exp_obd, pin)(exp, ino, gen, type, handle, flag);
+        return(rc);
 }
 
-static inline void obd_oa2handle(struct lustre_handle *handle, struct obdo *oa)
+static inline int obd_unpin(struct obd_export *exp,
+                            struct obd_client_handle *handle, int flag)
+{
+        int rc;
+
+        EXP_CHECK_OP(exp, unpin);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, unpin);
+
+        rc = OBP(exp->exp_obd, unpin)(exp, handle, flag);
+        return(rc);
+}
+
+
+static inline void obd_import_event(struct obd_device *obd,
+                                    struct obd_import *imp,
+                                    enum obd_import_event event)
 {
-        if (oa->o_valid |= OBD_MD_FLHANDLE) {
-                struct lustre_handle *oa_handle = obdo_handle(oa);
-                memcpy(handle, oa_handle, sizeof(*handle));
+        if (obd->obd_set_up && OBP(obd, import_event)) {
+                OBD_COUNTER_INCREMENT(obd, import_event);
+                OBP(obd, import_event)(obd, imp, event);
         }
 }
 
-static inline void obd_handle2oa(struct obdo *oa, struct lustre_handle *handle)
+static inline int obd_llog_connect(struct obd_device *obd,
+                                        struct llogd_conn_body *body)
 {
-        if (handle->addr) {
-                struct lustre_handle *oa_handle = obdo_handle(oa);
-                memcpy(oa_handle, handle, sizeof(*handle));
-                oa->o_valid |= OBD_MD_FLHANDLE;
+        ENTRY;
+        if (!obd->obd_set_up) {
+                CERROR("obd %s not set up\n", obd->obd_name);
+                return -EINVAL;
         }
+
+        if (!OBP(obd, llog_connect)) {
+                CERROR("obd %s has no llog_connect handler\n", obd->obd_name);
+                return -ENOSYS;
+        }
+
+        return OBP(obd, llog_connect)(obd, body);
 }
 
-#ifdef __KERNEL__
-/* support routines */
-extern kmem_cache_t *obdo_cachep;
-static inline struct obdo *obdo_alloc(void)
+static inline int obd_notify(struct obd_device *obd,
+                             struct obd_device *watched,
+                             int active)
 {
-        struct obdo *oa;
+        if (!obd->obd_set_up) {
+                CERROR("obd %s not set up\n", obd->obd_name);
+                return -EINVAL;
+        }
 
-        oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
-        if (oa == NULL)
-                LBUG();
-        memset(oa, 0, sizeof (*oa));
+        if (!OBP(obd, notify)) {
+                CERROR("obd %s has no notify handler\n", obd->obd_name);
+                return -ENOSYS;
+        }
 
-        return oa;
+        OBD_COUNTER_INCREMENT(obd, notify);
+        return OBP(obd, notify)(obd, watched, active);
 }
 
-static inline void obdo_free(struct obdo *oa)
+static inline int obd_register_observer(struct obd_device *obd,
+                                        struct obd_device *observer)
 {
-        if (!oa)
-                return;
-        kmem_cache_free(obdo_cachep, oa);
+        ENTRY;
+        if (obd->obd_observer && observer)
+                RETURN(-EALREADY);
+        obd->obd_observer = observer;
+        RETURN(0);
 }
 
-static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
+static inline int obd_init_ea_size(struct obd_export *exp, int size, int size2)
 {
-        unsigned int ia_valid = attr->ia_valid;
+        int rc;
+        ENTRY;
+        LASSERT(OBP(exp->exp_obd, init_ea_size) != NULL);
+        OBD_COUNTER_INCREMENT(exp->exp_obd, init_ea_size);
+        rc = OBP(exp->exp_obd, init_ea_size)(exp, size, size2);
+        RETURN(rc);
+}
 
-        if (ia_valid & ATTR_ATIME) {
-                oa->o_atime = attr->ia_atime;
-                oa->o_valid |= OBD_MD_FLATIME;
-        }
-        if (ia_valid & ATTR_MTIME) {
-                oa->o_mtime = attr->ia_mtime;
-                oa->o_valid |= OBD_MD_FLMTIME;
-        }
-        if (ia_valid & ATTR_CTIME) {
-                oa->o_ctime = attr->ia_ctime;
-                oa->o_valid |= OBD_MD_FLCTIME;
-        }
-        if (ia_valid & ATTR_SIZE) {
-                oa->o_size = attr->ia_size;
-                oa->o_valid |= OBD_MD_FLSIZE;
-        }
-        if (ia_valid & ATTR_MODE) {
-                oa->o_mode = attr->ia_mode;
-                oa->o_valid |= OBD_MD_FLTYPE | OBD_MD_FLMODE;
-                if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
-                        oa->o_mode &= ~S_ISGID;
-        }
-        if (ia_valid & ATTR_UID) {
-                oa->o_uid = attr->ia_uid;
-                oa->o_valid |= OBD_MD_FLUID;
-        }
-        if (ia_valid & ATTR_GID) {
-                oa->o_gid = attr->ia_gid;
-                oa->o_valid |= OBD_MD_FLGID;
-        }
+static inline int md_getstatus(struct obd_export *exp, struct ll_fid *fid)
+{
+        int rc;
+
+        EXP_CHECK_MD_OP(exp, getstatus);
+        MD_COUNTER_INCREMENT(exp->exp_obd, getstatus);
+        rc = MDP(exp->exp_obd, getstatus)(exp, fid);
+        RETURN(rc);
 }
 
+/* this function notifies MDC, that inode described by @fid gets removed from
+ * memory.*/
+static inline int md_delete_object(struct obd_export *exp,
+                                   struct ll_fid *fid)
+{
+        int rc;
+        ENTRY;
+
+        /* as this method only notifies MDC that inode gets deleted, we can
+         * return zero if method is not implemented, this means, that OBD does
+         * not need such a notification. */
+        if (MDP(exp->exp_obd, delete_object) == NULL)
+                RETURN(0);
+        
+        MD_COUNTER_INCREMENT(exp->exp_obd, delete_object);
+        rc = MDP(exp->exp_obd, delete_object)(exp, fid);
+        RETURN(rc);
+}
 
-static inline void iattr_from_obdo(struct iattr *attr, struct obdo *oa,
-                                   obd_flag valid)
+static inline int md_getattr(struct obd_export *exp, struct ll_fid *fid,
+                             unsigned long valid, unsigned int ea_size,
+                             struct ptlrpc_request **request)
 {
-        memset(attr, 0, sizeof(*attr));
-        if (valid & OBD_MD_FLATIME) {
-                attr->ia_atime = oa->o_atime;
-                attr->ia_valid |= ATTR_ATIME;
-        }
-        if (valid & OBD_MD_FLMTIME) {
-                attr->ia_mtime = oa->o_mtime;
-                attr->ia_valid |= ATTR_MTIME;
-        }
-        if (valid & OBD_MD_FLCTIME) {
-                attr->ia_ctime = oa->o_ctime;
-                attr->ia_valid |= ATTR_CTIME;
-        }
-        if (valid & OBD_MD_FLSIZE) {
-                attr->ia_size = oa->o_size;
-                attr->ia_valid |= ATTR_SIZE;
-        }
-        if (valid & OBD_MD_FLTYPE) {
-                attr->ia_mode = (attr->ia_mode & ~S_IFMT)|(oa->o_mode & S_IFMT);
-                attr->ia_valid |= ATTR_MODE;
-        }
-        if (valid & OBD_MD_FLMODE) {
-                attr->ia_mode = (attr->ia_mode & S_IFMT)|(oa->o_mode & ~S_IFMT);
-                attr->ia_valid |= ATTR_MODE;
-                if (!in_group_p(oa->o_gid) && !capable(CAP_FSETID))
-                        attr->ia_mode &= ~S_ISGID;
-        }
-        if (valid & OBD_MD_FLUID)
-        {
-                attr->ia_uid = oa->o_uid;
-                attr->ia_valid |= ATTR_UID;
-        }
-        if (valid & OBD_MD_FLGID) {
-                attr->ia_gid = oa->o_gid;
-                attr->ia_valid |= ATTR_GID;
-        }
+        int rc;
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, getattr);
+        MD_COUNTER_INCREMENT(exp->exp_obd, getattr);
+        rc = MDP(exp->exp_obd, getattr)(exp, fid, valid, ea_size, request);
+        RETURN(rc);
 }
 
+static inline int md_change_cbdata(struct obd_export *exp, struct ll_fid *fid,
+                                   ldlm_iterator_t it, void *data)
+{
+        int rc;
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, change_cbdata);
+        MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata);
+        rc = MDP(exp->exp_obd, change_cbdata)(exp, fid, it, data);
+        RETURN(rc);
+}
 
-/* WARNING: the file systems must take care not to tinker with
-   attributes they don't manage (such as blocks). */
+static inline int md_change_cbdata_name(struct obd_export *exp,
+                                        struct ll_fid *fid, char *name,
+                                        int namelen, struct ll_fid *fid2,
+                                        ldlm_iterator_t it, void *data)
+{
+        int rc;
+        
+        /* this seem to be needed only for lmv. */
+        if (!MDP(exp->exp_obd, change_cbdata_name))
+                return 0;
+        
+        ENTRY;
+                
+        MD_COUNTER_INCREMENT(exp->exp_obd, change_cbdata_name);
+        rc = MDP(exp->exp_obd, change_cbdata_name)(exp, fid, name, namelen,
+                                                   fid2, it, data);
+        RETURN(rc);
+}
 
-#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
-#define to_kdev_t(dev) dev
-#define kdev_t_to_nr(dev) dev
-#endif
+static inline int md_close(struct obd_export *exp, struct obdo *obdo,
+                           struct obd_client_handle *och,
+                           struct ptlrpc_request **request)
+{
+        int rc;
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, close);
+        MD_COUNTER_INCREMENT(exp->exp_obd, close);
+        rc = MDP(exp->exp_obd, close)(exp, obdo, och, request);
+        RETURN(rc);
+}
 
-static inline void obdo_from_inode(struct obdo *dst, struct inode *src,
-                                   obd_flag valid)
-{
-//        if (valid & OBD_MD_FLID)
-//                dst->o_id = src->i_ino;
-        if (valid & OBD_MD_FLATIME)
-                dst->o_atime = src->i_atime;
-        if (valid & OBD_MD_FLMTIME)
-                dst->o_mtime = src->i_mtime;
-        if (valid & OBD_MD_FLCTIME)
-                dst->o_ctime = src->i_ctime;
-        if (valid & OBD_MD_FLSIZE)
-                dst->o_size = src->i_size;
-        if (valid & OBD_MD_FLBLOCKS)   /* allocation of space */
-                dst->o_blocks = src->i_blocks;
-        if (valid & OBD_MD_FLBLKSZ)
-                dst->o_blksize = src->i_blksize;
-        if (valid & OBD_MD_FLTYPE)
-                dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->i_mode & S_IFMT);
-        if (valid & OBD_MD_FLMODE)
-                dst->o_mode = (dst->o_mode & S_IFMT) | (src->i_mode & ~S_IFMT);
-        if (valid & OBD_MD_FLUID)
-                dst->o_uid = src->i_uid;
-        if (valid & OBD_MD_FLGID)
-                dst->o_gid = src->i_gid;
-        if (valid & OBD_MD_FLFLAGS)
-                dst->o_flags = src->i_flags;
-        if (valid & OBD_MD_FLNLINK)
-                dst->o_nlink = src->i_nlink;
-        if (valid & OBD_MD_FLGENER)
-                dst->o_generation = src->i_generation;
-        if (valid & OBD_MD_FLRDEV)
-                dst->o_rdev = (__u32)kdev_t_to_nr(src->i_rdev);
-
-        dst->o_valid |= (valid & ~OBD_MD_FLID);
-}
-
-static inline void obdo_to_inode(struct inode *dst, struct obdo *src,
-                                 obd_flag valid)
-{
-//        if (valid & OBD_MD_FLID)
-//                dst->i_ino = src->o_id;
-        if (valid & OBD_MD_FLATIME)
-                dst->i_atime = src->o_atime;
-        if (valid & OBD_MD_FLMTIME)
-                dst->i_mtime = src->o_mtime;
-        if (valid & OBD_MD_FLCTIME)
-                dst->i_ctime = src->o_ctime;
-        if (valid & OBD_MD_FLSIZE)
-                dst->i_size = src->o_size;
-        if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
-                dst->i_blocks = src->o_blocks;
-        if (valid & OBD_MD_FLBLKSZ)
-                dst->i_blksize = src->o_blksize;
-        if (valid & OBD_MD_FLTYPE)
-                dst->i_mode = (dst->i_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
-        if (valid & OBD_MD_FLMODE)
-                dst->i_mode = (dst->i_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
-        if (valid & OBD_MD_FLUID)
-                dst->i_uid = src->o_uid;
-        if (valid & OBD_MD_FLGID)
-                dst->i_gid = src->o_gid;
-        if (valid & OBD_MD_FLFLAGS)
-                dst->i_flags = src->o_flags;
-        if (valid & OBD_MD_FLNLINK)
-                dst->i_nlink = src->o_nlink;
-        if (valid & OBD_MD_FLGENER)
-                dst->i_generation = src->o_generation;
-        if (valid & OBD_MD_FLRDEV)
-                dst->i_rdev = to_kdev_t(src->o_rdev);
+static inline int md_create(struct obd_export *exp, struct mdc_op_data *op_data,
+                            const void *data, int datalen, int mode,
+                            __u32 uid, __u32 gid, __u64 rdev,
+                            struct ptlrpc_request **request)
+{
+        int rc;
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, create);
+        MD_COUNTER_INCREMENT(exp->exp_obd, create);
+        rc = MDP(exp->exp_obd, create)(exp, op_data, data, datalen, mode,
+                                       uid, gid, rdev, request);
+        RETURN(rc);
 }
-#endif
 
-static inline void obdo_cpy_md(struct obdo *dst, struct obdo *src,
-                               obd_flag valid)
+static inline int md_done_writing(struct obd_export *exp, struct obdo *obdo)
 {
-#ifdef __KERNEL__
-        CDEBUG(D_INODE, "src obdo %Ld valid 0x%x, dst obdo %Ld\n",
-               (unsigned long long)src->o_id, src->o_valid,
-               (unsigned long long)dst->o_id);
-#endif
-        if (valid & OBD_MD_FLATIME)
-                dst->o_atime = src->o_atime;
-        if (valid & OBD_MD_FLMTIME)
-                dst->o_mtime = src->o_mtime;
-        if (valid & OBD_MD_FLCTIME)
-                dst->o_ctime = src->o_ctime;
-        if (valid & OBD_MD_FLSIZE)
-                dst->o_size = src->o_size;
-        if (valid & OBD_MD_FLBLOCKS) /* allocation of space */
-                dst->o_blocks = src->o_blocks;
-        if (valid & OBD_MD_FLBLKSZ)
-                dst->o_blksize = src->o_blksize;
-        if (valid & OBD_MD_FLTYPE)
-                dst->o_mode = (dst->o_mode & ~S_IFMT) | (src->o_mode & S_IFMT);
-        if (valid & OBD_MD_FLMODE)
-                dst->o_mode = (dst->o_mode & S_IFMT) | (src->o_mode & ~S_IFMT);
-        if (valid & OBD_MD_FLUID)
-                dst->o_uid = src->o_uid;
-        if (valid & OBD_MD_FLGID)
-                dst->o_gid = src->o_gid;
-        if (valid & OBD_MD_FLFLAGS)
-                dst->o_flags = src->o_flags;
-        /*
-        if (valid & OBD_MD_FLOBDFLG)
-                dst->o_obdflags = src->o_obdflags;
-        */
-        if (valid & OBD_MD_FLNLINK)
-                dst->o_nlink = src->o_nlink;
-        if (valid & OBD_MD_FLGENER)
-                dst->o_generation = src->o_generation;
-        if (valid & OBD_MD_FLRDEV)
-                dst->o_rdev = src->o_rdev;
-        if (valid & OBD_MD_FLINLINE &&
-             src->o_obdflags & OBD_FL_INLINEDATA) {
-                memcpy(dst->o_inline, src->o_inline, sizeof(src->o_inline));
-                dst->o_obdflags |= OBD_FL_INLINEDATA;
-        }
+        int rc;
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, done_writing);
+        MD_COUNTER_INCREMENT(exp->exp_obd, done_writing);
+        rc = MDP(exp->exp_obd, done_writing)(exp, obdo);
+        RETURN(rc);
+}
 
-        dst->o_valid |= valid;
-}
-
-
-/* returns FALSE if comparison (by flags) is same, TRUE if changed */
-static inline int obdo_cmp_md(struct obdo *dst, struct obdo *src,
-                              obd_flag compare)
-{
-        int res = 0;
-
-        if ( compare & OBD_MD_FLATIME )
-                res = (res || (dst->o_atime != src->o_atime));
-        if ( compare & OBD_MD_FLMTIME )
-                res = (res || (dst->o_mtime != src->o_mtime));
-        if ( compare & OBD_MD_FLCTIME )
-                res = (res || (dst->o_ctime != src->o_ctime));
-        if ( compare & OBD_MD_FLSIZE )
-                res = (res || (dst->o_size != src->o_size));
-        if ( compare & OBD_MD_FLBLOCKS ) /* allocation of space */
-                res = (res || (dst->o_blocks != src->o_blocks));
-        if ( compare & OBD_MD_FLBLKSZ )
-                res = (res || (dst->o_blksize != src->o_blksize));
-        if ( compare & OBD_MD_FLTYPE )
-                res = (res || (((dst->o_mode ^ src->o_mode) & S_IFMT) != 0));
-        if ( compare & OBD_MD_FLMODE )
-                res = (res || (((dst->o_mode ^ src->o_mode) & ~S_IFMT) != 0));
-        if ( compare & OBD_MD_FLUID )
-                res = (res || (dst->o_uid != src->o_uid));
-        if ( compare & OBD_MD_FLGID )
-                res = (res || (dst->o_gid != src->o_gid));
-        if ( compare & OBD_MD_FLFLAGS )
-                res = (res || (dst->o_flags != src->o_flags));
-        if ( compare & OBD_MD_FLNLINK )
-                res = (res || (dst->o_nlink != src->o_nlink));
-        if ( compare & OBD_MD_FLGENER )
-                res = (res || (dst->o_generation != src->o_generation));
-        /* XXX Don't know if thses should be included here - wasn't previously
-        if ( compare & OBD_MD_FLINLINE )
-                res = (res || memcmp(dst->o_inline, src->o_inline));
-        */
-        return res;
+static inline int md_enqueue(struct obd_export *exp, int lock_type,
+                             struct lookup_intent *it, int lock_mode,
+                             struct mdc_op_data *data,
+                             struct lustre_handle *lockh,
+                             void *lmm, int lmmsize,
+                             ldlm_completion_callback cb_completion,
+                             ldlm_blocking_callback cb_blocking,
+                             void *cb_data)
+{
+        int rc;
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, enqueue);
+        MD_COUNTER_INCREMENT(exp->exp_obd, enqueue);
+        rc = MDP(exp->exp_obd, enqueue)(exp, lock_type, it, lock_mode,
+                                        data, lockh, lmm, lmmsize,
+                                        cb_completion, cb_blocking,
+                                        cb_data);
+        RETURN(rc);
 }
 
+static inline int md_getattr_name(struct obd_export *exp, struct ll_fid *fid,
+                                  char *filename, int namelen,
+                                  unsigned long valid, unsigned int ea_size,
+                                  struct ptlrpc_request **request)
+{
+        int rc;
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, getattr_name);
+        MD_COUNTER_INCREMENT(exp->exp_obd, getattr_name);
+        rc = MDP(exp->exp_obd, getattr_name)(exp, fid, filename, namelen,
+                                             valid, ea_size, request);
+        RETURN(rc);
+}
 
-#ifdef __KERNEL__
-/* I'm as embarrassed about this as you are.
- *
- * <shaver> // XXX do not look into _superhack with remaining eye
- * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */ 
-extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
+static inline int md_intent_lock(struct obd_export *exp, struct ll_uctxt *uctxt,
+                                 struct ll_fid *pfid, const char *name,
+                                 int len, void *lmm, int lmmsize,
+                                 struct ll_fid *cfid, struct lookup_intent *it,
+                                 int flags, struct ptlrpc_request **reqp,
+                                 ldlm_blocking_callback cb_blocking)
+{
+        int rc;
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, intent_lock);
+        MD_COUNTER_INCREMENT(exp->exp_obd, intent_lock);
+        rc = MDP(exp->exp_obd, intent_lock)(exp, uctxt, pfid, name, len,
+                                            lmm, lmmsize, cfid, it, flags,
+                                            reqp, cb_blocking);
+        RETURN(rc);
+}
 
-int class_register_type(struct obd_ops *ops, char *nm);
-int class_unregister_type(char *nm);
-int class_name2dev(char *name);
-int class_uuid2dev(char *uuid);
-struct obd_device *class_uuid2obd(char *uuid);
-struct obd_export *class_new_export(struct obd_device *obddev);
-void class_destroy_export(struct obd_export *exp);
-int class_connect(struct lustre_handle *conn, struct obd_device *obd,
-                  obd_uuid_t cluuid);
-int class_disconnect(struct lustre_handle *conn);
-void class_disconnect_all(struct obd_device *obddev);
+static inline int md_link(struct obd_export *exp, struct mdc_op_data *data,
+                          struct ptlrpc_request **request)
+{
+        int rc;
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, link);
+        MD_COUNTER_INCREMENT(exp->exp_obd, link);
+        rc = MDP(exp->exp_obd, link)(exp, data, request);
+        RETURN(rc);
+}
 
-/* generic operations shared by various OBD types */
-int class_multi_setup(struct obd_device *obddev, uint32_t len, void *data);
-int class_multi_cleanup(struct obd_device *obddev);
+static inline int md_rename(struct obd_export *exp, struct mdc_op_data *data,
+                            const char *old, int oldlen,
+                            const char *new, int newlen,
+                            struct ptlrpc_request **request)
+{
+        int rc;
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, rename);
+        MD_COUNTER_INCREMENT(exp->exp_obd, rename);
+        rc = MDP(exp->exp_obd, rename)(exp, data, old, oldlen, new,
+                                       newlen, request);
+        RETURN(rc);
+}
+
+static inline int md_setattr(struct obd_export *exp, struct mdc_op_data *data,
+                             struct iattr *iattr, void *ea, int ealen,
+                             void *ea2, int ea2len,
+                             struct ptlrpc_request **request)
+{
+        int rc;
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, setattr);
+        MD_COUNTER_INCREMENT(exp->exp_obd, setattr);
+        rc = MDP(exp->exp_obd, setattr)(exp, data, iattr, ea, ealen,
+                                        ea2, ea2len, request);
+        RETURN(rc);
+}
+
+static inline int md_sync(struct obd_export *exp, struct ll_fid *fid,
+                               struct ptlrpc_request **request)
+{
+        int rc;
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, sync);
+        MD_COUNTER_INCREMENT(exp->exp_obd, sync);
+        rc = MDP(exp->exp_obd, sync)(exp, fid, request);
+        RETURN(rc);
+}
+
+static inline int md_readpage(struct obd_export *exp, struct ll_fid *fid,
+                              __u64 offset, struct page *page,
+                              struct ptlrpc_request **request)
+{
+        int rc;
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, readpage);
+        MD_COUNTER_INCREMENT(exp->exp_obd, readpage);
+        rc = MDP(exp->exp_obd, readpage)(exp, fid, offset, page, request);
+        RETURN(rc);
+}
+
+static inline int md_unlink(struct obd_export *exp, struct mdc_op_data *data,
+                            struct ptlrpc_request **request)
+{
+        int rc;
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, unlink);
+        MD_COUNTER_INCREMENT(exp->exp_obd, unlink);
+        rc = MDP(exp->exp_obd, unlink)(exp, data, request);
+        RETURN(rc);
+}
+
+static inline struct obd_device *md_get_real_obd(struct obd_export *exp,
+                                                 char *name, int len)
+{
+        ENTRY;
+        if (MDP(exp->exp_obd, get_real_obd) == NULL)
+                return exp->exp_obd;
+        MD_COUNTER_INCREMENT(exp->exp_obd, get_real_obd);
+        return MDP(exp->exp_obd, get_real_obd)(exp, name, len);
+}
+
+static inline int md_valid_attrs(struct obd_export *exp, struct ll_fid *fid)
+{
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, valid_attrs);
+        MD_COUNTER_INCREMENT(exp->exp_obd, valid_attrs);
+        return MDP(exp->exp_obd, valid_attrs)(exp, fid);
+}
+
+static inline int md_req2lustre_md(struct obd_export *exp,
+                                   struct ptlrpc_request *req,
+                                   unsigned int offset,
+                                   struct obd_export *osc_exp,
+                                   struct lustre_md *md)
+{
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, req2lustre_md);
+        MD_COUNTER_INCREMENT(exp->exp_obd, req2lustre_md);
+        return MDP(exp->exp_obd, req2lustre_md)(exp, req, offset, osc_exp, md);
+}
+
+static inline int md_set_open_replay_data(struct obd_export *exp,
+                                          struct obd_client_handle *och,
+                                          struct ptlrpc_request *open_req)
+{
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, set_open_replay_data);
+        MD_COUNTER_INCREMENT(exp->exp_obd, set_open_replay_data);
+        return MDP(exp->exp_obd, set_open_replay_data)(exp, och, open_req);
+}
+
+static inline int md_clear_open_replay_data(struct obd_export *exp,
+                                            struct obd_client_handle *och)
+{
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, clear_open_replay_data);
+        MD_COUNTER_INCREMENT(exp->exp_obd, clear_open_replay_data);
+        return MDP(exp->exp_obd, clear_open_replay_data)(exp, och);
+}
+
+static inline int md_store_inode_generation(struct obd_export *exp,
+                                            struct ptlrpc_request *req,
+                                            int reqoff, int repoff)
+{
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, store_inode_generation);
+        MD_COUNTER_INCREMENT(exp->exp_obd, store_inode_generation);
+        return MDP(exp->exp_obd, store_inode_generation)(exp, req,
+                   reqoff, repoff);
+}
+
+static inline int md_set_lock_data(struct obd_export *exp, __u64 *l, void *data)
+{
+        ENTRY;
+        EXP_CHECK_MD_OP(exp, set_lock_data);
+        MD_COUNTER_INCREMENT(exp->exp_obd, set_lock_data);
+        return MDP(exp->exp_obd, set_lock_data)(exp, l, data);
+}
+
+/* OBD Metadata Support */
+
+extern int obd_init_caches(void);
+extern void obd_cleanup_caches(void);
+
+/* support routines */
+extern kmem_cache_t *obdo_cachep;
+static inline struct obdo *obdo_alloc(void)
+{
+        struct obdo *oa;
 
-extern void (*class_signal_connection_failure)(struct ptlrpc_connection *);
+        oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
+        if (oa == NULL)
+                LBUG();
+        CDEBUG(D_MALLOC, "kmem_cache_alloced oa at %p\n", oa);
+        memset(oa, 0, sizeof (*oa));
+
+        return oa;
+}
 
-static inline struct ptlrpc_connection *class_rd2conn(struct recovd_data *rd)
+static inline void obdo_free(struct obdo *oa)
 {
-        /* reuse list_entry's member-pointer offset stuff */
-        return list_entry(rd, struct ptlrpc_connection, c_recovd_data);
+        if (!oa)
+                return;
+        CDEBUG(D_MALLOC, "kmem_cache_freed oa at %p\n", oa);
+        kmem_cache_free(obdo_cachep, oa);
 }
 
+#if !defined(__KERNEL__) || (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
+#define to_kdev_t(dev) dev
+#define kdev_t_to_nr(dev) dev
 #endif
 
+/* I'm as embarrassed about this as you are.
+ *
+ * <shaver> // XXX do not look into _superhack with remaining eye
+ * <shaver> // XXX if this were any uglier, I'd get my own show on MTV */
+extern int (*ptlrpc_put_connection_superhack)(struct ptlrpc_connection *c);
+extern void (*ptlrpc_abort_inflight_superhack)(struct obd_import *imp);
+
 /* sysctl.c */
 extern void obd_sysctl_init (void);
 extern void obd_sysctl_clean (void);
 
 /* uuid.c  */
 typedef __u8 class_uuid_t[16];
-//int class_uuid_parse(obd_uuid_t in, class_uuid_t out);
-void class_uuid_unparse(class_uuid_t in, obd_uuid_t out);
-#endif /* __LINUX_CLASS_OBD_H */
+//int class_uuid_parse(struct obd_uuid in, class_uuid_t out);
+void class_uuid_unparse(class_uuid_t in, struct obd_uuid *out);
+
+/* lustre_peer.c    */
+int lustre_uuid_to_peer(char *uuid, __u32 *peer_nal, ptl_nid_t *peer_nid);
+int class_add_uuid(char *uuid, __u64 nid, __u32 nal);
+int class_del_uuid (char *uuid);
+void class_init_uuidlist(void);
+void class_exit_uuidlist(void);
+
+/* mea.c */
+int mea_name2idx(struct mea *mea, char *name, int namelen);
+int raw_name2idx(int count, const char *name, int namelen);
+
+#endif /* __LINUX_OBD_CLASS_H */