Whamcloud - gitweb
Rename "export" with "exp" so it doesn't screw up my syntax highlighting
[fs/lustre-release.git] / lustre / include / linux / obd_class.h
index ae618f7..0a75ed7 100644 (file)
+/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
+ * vim:expandtab:shiftwidth=8:tabstop=8:
+ *
+ *  Copyright (C) 2001, 2002 Cluster File Systems, Inc.
+ *
+ *   This file is part of Lustre, http://www.lustre.org.
+ *
+ *   Lustre is free software; you can redistribute it and/or
+ *   modify it under the terms of version 2 of the GNU General Public
+ *   License as published by the Free Software Foundation.
+ *
+ *   Lustre is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with Lustre; if not, write to the Free Software
+ *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
 #ifndef __LINUX_CLASS_OBD_H
 #define __LINUX_CLASS_OBD_H
 
+#ifndef __KERNEL__
+# include <stdint.h>
+# define __KERNEL__
+# include <linux/list.h>
+# undef __KERNEL__
+#else
+#include <asm/segment.h>
+#include <asm/uaccess.h>
+#include <linux/types.h>
 #include <linux/fs.h>
-#include <linux/ext2_fs.h>
 #include <linux/time.h>
-#include <linux/obd.h>
-
-#include <linux/obd_ext2.h>
-#include <linux/obd_snap.h>
-/* #include <linux/obd_fc.h> */
-#include <linux/obd_raid1.h>
-#include <linux/obd_rpc.h>
-
-
-#define OBD_PSDEV_MAJOR 186
-#define MAX_OBD_DEVICES 8
-#define MAX_MULTI 16
-
-typedef unsigned long   objid;
-typedef struct inode obdattr;
-#if 0
-struct obdattr {
-       objid                   oa_id;
-       umode_t                 oa_mode;
-       nlink_t                 oa_nlink;
-       uid_t                   oa_uid;
-       gid_t                   oa_gid;
-       off_t                   oa_size;
-       time_t                  oa_atime;
-       time_t                  oa_mtime;
-       time_t                  oa_ctime;
-       unsigned long           oa_blksize;
-       unsigned long           oa_blocks;
-       char                    oa_data[116];
-       struct obd_ops         *oa_op;
-};
 
+#include <linux/obd_support.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
 
+
+/*
+ *  ======== OBD Device Declarations ===========
+ */
+#define MAX_OBD_DEVICES 128
 extern struct obd_device obd_dev[MAX_OBD_DEVICES];
 
-       
+#define OBD_ATTACHED 0x1
+#define OBD_SET_UP   0x2
 
+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);
 
+/*
+ *  ======== OBD Operations Declarations ===========
+ */
 
-#define OBD_ATTACHED 0x1
-#define OBD_SET_UP   0x2
+#ifdef __KERNEL__
+static inline int obd_check_conn(struct lustre_handle *conn)
+{
+        struct obd_device *obd;
+        if (!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 ) {
+                CERROR("obd %d not attached\n", obd->obd_minor);
+                RETURN(-ENODEV);
+        }
+
+        if (!obd->obd_flags & OBD_SET_UP) {
+                CERROR("obd %d not setup\n", obd->obd_minor);
+                RETURN(-ENODEV);
+        }
+
+        if (!obd->obd_type) {
+                CERROR("obd %d not typed\n", obd->obd_minor);
+                RETURN(-ENODEV);
+        }
+
+        if (!obd->obd_type->typ_ops) {
+                CERROR("obd_check_conn: obd %d no operations\n",
+                       obd->obd_minor);
+                RETURN(-EOPNOTSUPP);
+        }
+        return 0;
+}
 
-struct obd_conn {
-       struct obd_device *oc_dev;
-       unsigned int oc_id;
-};
 
-/* corresponds to one of the obdx */
-struct obd_device {
-       struct obd_type *obd_type;
-       int obd_minor;
-       int obd_flags;
-       int obd_refcnt; 
-       int obd_multi_count;
-       struct obd_conn obd_multi_conn[MAX_MULTI];
-       unsigned int obd_gen_last_id;
-       unsigned long obd_gen_prealloc_quota;
-       struct list_head obd_gen_clients;
-       union {
-               struct ext2_obd ext2;
-               struct raid1_obd raid1;
-               struct snap_obd snap;
-               struct rpc_obd rpc;
-               /* struct fc_obd fc; */
-       } u;
-};
+#define OBT(dev)        (dev)->obd_type
+#define OBP(dev, op)    (dev)->obd_type->typ_ops->o_ ## op
+
+#define OBD_CHECK_SETUP(conn, exp)                              \
+do {                                                            \
+        if (!(conn)) {                                          \
+                CERROR("NULL connection\n");                    \
+                RETURN(-EINVAL);                                \
+        }                                                       \
+                                                                \
+        exp = class_conn2export(conn);                          \
+        if (!(exp)) {                                           \
+                CERROR("No export\n");                          \
+                RETURN(-EINVAL);                                \
+        }                                                       \
+                                                                \
+        if (!((exp)->exp_obd->obd_flags & OBD_SET_UP)) {        \
+                CERROR("Device %d not setup\n",                 \
+                       (exp)->exp_obd->obd_minor);              \
+                RETURN(-EINVAL);                                \
+        }                                                       \
+} while (0)
+
+#define OBD_CHECK_DEVSETUP(obd)                                 \
+do {                                                            \
+        if (!(obd)) {                                           \
+                CERROR("NULL device\n");                        \
+                RETURN(-EINVAL);                                \
+        }                                                       \
+                                                                \
+        if (!((obd)->obd_flags & OBD_SET_UP)) {                 \
+                CERROR("Device %d not setup\n",                 \
+                       (obd)->obd_minor);                       \
+                RETURN(-EINVAL);                                \
+        }                                                       \
+} while (0)
+
+#define OBD_CHECK_OP(obd, op)                                   \
+do {                                                            \
+        if (!OBP((obd), op)) {                                  \
+                CERROR("obd_" #op ": dev %d no operation\n",    \
+                       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)
+{
+        struct obd_export *exp;
+        int rc;
 
-struct obd_ops {
-       int (*o_attach)(struct obd_device *, int len, void *);
-       int (*o_detach)(struct obd_device *);
-       int (*o_format)(struct obd_device *, int len, void *);
-       int (*o_partition)(struct obd_device *, int len, void *);
-       int (*o_connect)(struct obd_conn *conn);
-       int (*o_disconnect)(struct obd_conn *);
-       int (*o_setup) (struct obd_device *dev, int len, void *data);
-       int (*o_cleanup)(struct obd_device *dev);
-       int (*o_setattr)(struct obd_conn *, obdattr *oa);
-       int (*o_getattr)(struct obd_conn *, obdattr *oa);
-       int (*o_statfs)(struct obd_conn *, struct statfs *statfs);
-       int (*o_create)(struct obd_conn *, int prealloc_obj, objid *id);
-       int (*o_destroy)(struct obd_conn *, obdattr *oa);
-       int (*o_read)(struct obd_conn *, obdattr *oa, char *buf, unsigned long *count, loff_t offset);
-       int (*o_read2)(struct obd_conn *, obdattr *oa, char *buf, unsigned long *count, loff_t offset);
-       int (*o_write)(struct obd_conn *, obdattr *oa, char *buf, unsigned long *count, loff_t offset);
-       int (*o_brw)(int rw, struct obd_conn * conn, obdattr *oa, struct page *page, int create);
-       int (*o_preallocate)(struct obd_conn *, unsigned long *req, long inodes[32]);
-       int (*o_get_info)(struct obd_conn *, int keylen, void *key, int *vallen, void **val);
-       int (*o_set_info)(struct obd_conn *, int keylen, void *key, int vallen, void *val);
-       int (*o_migrate)(struct obd_conn *, obdattr *dst, obdattr *src);
-       int (*o_copy)(struct obd_conn *dev, obdattr *dst, obdattr *src);
-       int (*o_iocontrol)(int cmd, struct obd_conn *, int len, void *karg, void *uarg);
-       int (*o_iterate)(struct obd_conn *, int (*)(objid, void *), objid, void *);
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, get_info);
 
-};
+        rc = OBP(exp->exp_obd, get_info)(conn, keylen, key, vallen, val);
+        RETURN(rc);
+}
 
-#define OBT(dev)       dev->obd_type->typ_ops
-#define OBP(dev,op)    dev->obd_type->typ_ops->o_ ## op
+static inline int obd_set_info(struct lustre_handle *conn, obd_count keylen,
+                               void *key, obd_count vallen, void *val)
+{
+        struct obd_export *exp;
+        int rc;
 
-int obd_register_type(struct obd_ops *ops, char *nm);
-int obd_unregister_type(char *nm);
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, set_info);
 
-struct obd_client {
-       struct list_head cli_chain;
-       struct obd_device *cli_obd;
-       unsigned int cli_id;
-       unsigned long cli_prealloc_quota;
-       struct list_head cli_prealloc_inodes;
-};
+        rc = OBP(exp->exp_obd, set_info)(conn, keylen, key, vallen, val);
+        RETURN(rc);
+}
 
+static inline int obd_setup(struct obd_device *obd, int datalen, void *data)
+{
+        int rc;
 
-struct obd_prealloc_inode {
-       struct list_head obd_prealloc_chain;
-       unsigned long inode;
-};
+        OBD_CHECK_OP(obd, setup);
 
-/* generic operations shared by various OBD types */
-int gen_connect (struct obd_conn *conn);
-int gen_disconnect(struct obd_conn *conn);
-int gen_multi_setup(struct obd_device *obddev, int len, void *data);
-int gen_multi_cleanup(struct obd_device *obddev);
-int gen_multi_attach(struct obd_device *obddev, int len, void *data);
-struct obd_client *gen_client(struct obd_conn *);
-int gen_multi_detach(struct obd_device *obddev);
-int gen_cleanup(struct obd_device *obddev);
-int gen_copy_data(struct obd_conn *, obdattr *source, obdattr *target);
+        rc = OBP(obd, setup)(obd, datalen, data);
+        RETURN(rc);
+}
 
+static inline int obd_cleanup(struct obd_device *obd)
+{
+        int rc;
 
+        OBD_CHECK_DEVSETUP(obd);
+        OBD_CHECK_OP(obd, cleanup);
 
-/*
- * ioctl commands
- */
-struct oic_generic {
-       int  att_connid;
-       int  att_typelen;
-       void *att_type;
-       int  att_datalen;
-       void *att_data;
-};
+        rc = OBP(obd, cleanup)(obd);
+        RETURN(rc);
+}
 
-struct oic_prealloc_s {
-       unsigned long cli_id;
-       unsigned long alloc; /* user sets it to the number of inodes requesting
-                    * to be preallocated.  kernel sets it to the actual number
-                    * of succesfully preallocated inodes */
-       long inodes[32]; /* actual inode numbers */
-};
+static inline int obd_create(struct lustre_handle *conn, struct obdo *obdo,
+                             struct lov_stripe_md **ea)
+{
+        struct obd_export *exp;
+        int rc;
 
-struct oic_create_s {
-       unsigned int conn_id;
-       unsigned long prealloc;
-};
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, create);
 
-struct oic_attr_s {
-       unsigned int conn_id;
-       unsigned long ino;
-       struct iattr iattr;
-};
+        rc = OBP(exp->exp_obd, create)(conn, obdo, ea);
+        RETURN(rc);
+}
 
-struct ioc_mv_s {
-       unsigned int conn_id;
-       objid  src;
-       objid  dst;
-};
+static inline int obd_destroy(struct lustre_handle *conn, struct obdo *obdo,
+                              struct lov_stripe_md *ea)
+{
+        struct obd_export *exp;
+        int rc;
 
-struct oic_rw_s {
-       unsigned int conn_id;
-       unsigned long id;
-       char * buf;
-       unsigned long count;
-       loff_t offset;
-};
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, destroy);
 
-struct oic_partition {
-       int partition;
-       unsigned int size;
-};
+        rc = OBP(exp->exp_obd, destroy)(conn, obdo, ea);
+        RETURN(rc);
+}
 
+static inline int obd_getattr(struct lustre_handle *conn, struct obdo *obdo,
+                              struct lov_stripe_md *ea)
+{
+        struct obd_export *exp;
+        int rc;
 
-#define OBD_IOC_CREATE                 _IOR ('f',  3, long)
-#define OBD_IOC_SETUP                  _IOW ('f',  4, long)
-#define OBD_IOC_CLEANUP                _IO  ('f',  5      )
-#define OBD_IOC_DESTROY                _IOW ('f',  6, long)
-#define OBD_IOC_PREALLOCATE            _IOWR('f',  7, long)
-#define OBD_IOC_DEC_USE_COUNT          _IO  ('f',  8      )
-#define OBD_IOC_SETATTR                _IOW ('f',  9, long)
-#define OBD_IOC_GETATTR                _IOR ('f', 10, long)
-#define OBD_IOC_READ                   _IOWR('f', 11, long)
-#define OBD_IOC_WRITE                  _IOWR('f', 12, long)
-#define OBD_IOC_CONNECT                _IOR ('f', 13, long)
-#define OBD_IOC_DISCONNECT             _IOW ('f', 14, long)
-#define OBD_IOC_STATFS                 _IOWR('f', 15, long)
-#define OBD_IOC_SYNC                   _IOR ('f',  16, long)
-#define OBD_IOC_READ2                  _IOWR('f', 17, long)
-#define OBD_IOC_FORMAT                 _IOWR('f', 18, long)
-#define OBD_IOC_PARTITION              _IOWR('f', 19, long)
-#define OBD_IOC_ATTACH                 _IOWR('f', 20, long)
-#define OBD_IOC_DETACH                 _IOWR('f', 21, long)
-#define OBD_IOC_COPY                   _IOWR('f', 22, long)
-#define OBD_IOC_MIGR                   _IOWR('f', 23, long)
-
-#define OBD_IOC_DEC_FS_USE_COUNT       _IO  ('f', 32      )
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, getattr);
 
+        rc = OBP(exp->exp_obd, getattr)(conn, obdo, ea);
+        RETURN(rc);
+}
 
-/* sysctl.c */
-extern void obd_sysctl_init (void);
-extern void obd_sysctl_clean (void);
+static inline int obd_close(struct lustre_handle *conn, struct obdo *obdo,
+                            struct lov_stripe_md *ea)
+{
+        struct obd_export *exp;
+        int rc;
+
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, close);
+
+        rc = OBP(exp->exp_obd, close)(conn, obdo, ea);
+        RETURN(rc);
+}
+
+static inline int obd_open(struct lustre_handle *conn, struct obdo *obdo,
+                           struct lov_stripe_md *ea)
+{
+        struct obd_export *exp;
+        int rc;
+
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, open);
+
+        rc = OBP(exp->exp_obd, open)(conn, obdo, ea);
+        RETURN(rc);
+}
+
+static inline int obd_setattr(struct lustre_handle *conn, struct obdo *obdo,
+                              struct lov_stripe_md *ea)
+{
+        struct obd_export *exp;
+        int rc;
+
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, setattr);
+
+        rc = OBP(exp->exp_obd, setattr)(conn, obdo, ea);
+        RETURN(rc);
+}
+
+static inline int obd_connect(struct lustre_handle *conn,
+                              struct obd_device *obd, obd_uuid_t cluuid)
+{
+        int rc;
 
-#define CHKCONN(conn)  do { if (!gen_client(conn)) {\
-               printk("%s %d invalid client %u\n", __FILE__, __LINE__, \
-                      conn->oc_id);\
-               return -EINVAL; }} while (0) 
+        OBD_CHECK_DEVSETUP(obd);
+        OBD_CHECK_OP(obd, connect);
+
+        rc = OBP(obd, connect)(conn, obd, cluuid);
+        RETURN(rc);
+}
 
+static inline int obd_disconnect(struct lustre_handle *conn)
+{
+        struct obd_export *exp;
+        int rc;
+
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, disconnect);
+
+        rc = OBP(exp->exp_obd, disconnect)(conn);
+        RETURN(rc);
+}
+
+static inline int obd_statfs(struct lustre_handle *conn,struct obd_statfs *osfs)
+{
+        struct obd_export *exp;
+        int rc;
+
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, statfs);
+
+        rc = OBP(exp->exp_obd, statfs)(conn, osfs);
+        RETURN(rc);
+}
 
+static inline int obd_punch(struct lustre_handle *conn, struct obdo *oa,
+                            struct lov_stripe_md *ea,
+                            obd_size count, obd_off offset)
+{
+        struct obd_export *exp;
+        int rc;
+
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, punch);
+
+        rc = OBP(exp->exp_obd, punch)(conn, oa, ea, count, offset);
+        RETURN(rc);
+}
+
+static inline int obd_brw(int cmd, struct lustre_handle *conn,
+                          struct lov_stripe_md *ea, obd_count oa_bufs,
+                          struct brw_page *pg,
+                          brw_callback_t callback, void *data)
+{
+        struct obd_export *exp;
+        int rc;
+
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, brw);
+
+        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);
+        RETURN(rc);
+}
+
+static inline int obd_preprw(int cmd, struct lustre_handle *conn,
+                             int objcount, struct obd_ioobj *obj,
+                             int niocount, struct niobuf_remote *remote,
+                             struct niobuf_local *local, void **desc_private)
+{
+        struct obd_export *exp;
+        int rc;
+
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, preprw);
+
+        rc = OBP(exp->exp_obd, preprw)(cmd, conn, objcount, obj, niocount,
+                                       remote, local, desc_private);
+        RETURN(rc);
+}
+
+static inline int obd_commitrw(int cmd, struct lustre_handle *conn,
+                               int objcount, struct obd_ioobj *obj,
+                               int niocount, struct niobuf_local *local,
+                               void *desc_private)
+{
+        struct obd_export *exp;
+        int rc;
+
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, commitrw);
+
+        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,
+                                int len, void *karg, void *uarg)
+{
+        struct obd_export *exp;
+        int rc;
+
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, iocontrol);
+
+        rc = OBP(exp->exp_obd, iocontrol)(cmd, conn, 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)
+{
+        struct obd_export *exp;
+        int rc;
+
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, enqueue);
+
+        rc = OBP(exp->exp_obd, enqueue)(conn, ea, parent_lock, type,
+                                        cookie, cookielen, mode, flags, cb,
+                                        data, datalen, lockh);
+        RETURN(rc);
+}
+
+static inline int obd_cancel(struct lustre_handle *conn,
+                             struct lov_stripe_md *ea, __u32 mode,
+                             struct lustre_handle *lockh)
+{
+        struct obd_export *exp;
+        int rc;
+
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, cancel);
+
+        rc = OBP(exp->exp_obd, cancel)(conn, ea, mode, lockh);
+        RETURN(rc);
+}
+
+static inline int obd_cancel_unused(struct lustre_handle *conn,
+                                    struct lov_stripe_md *ea, int local)
+{
+        struct obd_export *exp;
+        int rc;
+
+        OBD_CHECK_SETUP(conn, exp);
+        OBD_CHECK_OP(exp->exp_obd, cancel_unused);
+
+        rc = OBP(exp->exp_obd, cancel_unused)(conn, ea, local);
+        RETURN(rc);
+}
+
+#endif
+
+/*
+ *  ======== OBD Metadata Support  ===========
+ */
+
+extern int obd_init_caches(void);
+extern void obd_cleanup_caches(void);
+
+static inline int obdo_has_inline(struct obdo *obdo)
+{
+        return (obdo->o_valid & OBD_MD_FLINLINE &&
+                obdo->o_obdflags & OBD_FL_INLINEDATA);
+};
+
+#ifdef __KERNEL__
 /* support routines */
-static __inline__ obdattr *obd_empty_oa(void)
+extern kmem_cache_t *obdo_cachep;
+static inline struct obdo *obdo_alloc(void)
 {
-       obdattr *res = NULL;
-       OBD_ALLOC(res, obdattr *, sizeof(*res));
-       memset(res, 0, sizeof (*res));
-       return res;
+        struct obdo *oa = NULL;
+
+        oa = kmem_cache_alloc(obdo_cachep, SLAB_KERNEL);
+        if (oa == NULL)
+                LBUG();
+        memset(oa, 0, sizeof (*oa));
+
+        return oa;
 }
+static inline void obdo_free(struct obdo *oa)
+{
+        if (!oa)
+                return;
+        kmem_cache_free(obdo_cachep, oa);
+}
+
 
-static __inline__ void obd_free_oa(obdattr *oa)
+static inline void obdo_from_iattr(struct obdo *oa, struct iattr *attr)
 {
-       if ( !oa ) 
-               return;
-       OBD_FREE(oa,sizeof(*oa));
+        unsigned int ia_valid = attr->ia_valid;
+
+        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 void iattr_from_obdo(struct iattr *attr, struct obdo *oa,
+                                   obd_flag valid)
+{
+        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;
+        }
+}
 
-static __inline__ obdattr *obd_oa_fromid(struct obd_conn *conn,  objid id)
+
+/* WARNING: the file systems must take care not to tinker with
+   attributes they don't manage (such as blocks). */
+
+static inline void obdo_from_inode(struct obdo *dst, struct inode *src,
+                                   obd_flag valid)
 {
-       obdattr *res = NULL;
+//        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 = src->i_rdev;
+
+        dst->o_valid |= (valid & ~OBD_MD_FLID);
+}
 
-       OBD_ALLOC(res, obdattr *, sizeof(*res));
-       if ( !res ) {
-               EXIT;
-               return NULL;
-       }
-       memset(res, 0, sizeof(*res));
-       res->i_ino = id;
-       if (conn->oc_dev->obd_type->typ_ops->o_getattr(conn, res)) {
-               OBD_FREE(res, sizeof(*res));
-               EXIT;
-               return NULL;
-       }
-       EXIT;
-       return res;
+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 = src->o_rdev;
 }
+#endif
 
-#define OBD_MD_NO      (1UL)       /* negates meaning of all flags */
-#define OBD_MD_ALL     (OBD_MD_NO) /* passing NO with no other flags == ALL */
-#define OBD_MD_FLMODE  (1UL<<1)
-#define OBD_MD_FLUID   (1UL<<2)
-#define OBD_MD_FLGID   (1UL<<3)
-#define OBD_MD_FLSIZE  (1UL<<4)
-#define OBD_MD_FLATIME (1UL<<5)
-#define OBD_MD_FLMTIME (1UL<<6)
-#define OBD_MD_FLCTIME (1UL<<7)
-#define OBD_MD_FLFLAGS (1UL<<8)
-#define OBD_MD_FLBLOCKS        (1UL<<9)
-#define OBD_MD_FLOBDMD (1UL<<10)
-
-
-static __inline__ void obdo_cpy_md(obdattr *dst, obdattr *src, int mask)
-{
-       /* If the OBD_MD_NO flag is set, then we copy all EXCEPT those
-        * fields given by the flags.  The default is to copy the field
-        * given by the flags.
-        */
-       if (mask & OBD_MD_NO)
-               mask = ~mask;
-
-       CDEBUG(D_INODE, "flags %x\n", mask);
-       if ( mask & OBD_MD_FLMODE ) 
-               dst->i_mode = src->i_mode;
-       if ( mask & OBD_MD_FLUID ) 
-               dst->i_uid = src->i_uid;
-       if ( mask & OBD_MD_FLGID ) 
-               dst->i_gid = src->i_gid;
-       if ( mask & OBD_MD_FLSIZE ) 
-               dst->i_size = src->i_size;
-       if ( mask & OBD_MD_FLATIME ) 
-               dst->i_atime = src->i_atime;
-       if ( mask & OBD_MD_FLMTIME ) 
-               dst->i_mtime = src->i_mtime;
-       if ( mask & OBD_MD_FLCTIME ) 
-               dst->i_ctime = src->i_ctime;
-       if ( mask & OBD_MD_FLFLAGS ) 
-               dst->i_flags = src->i_flags;
-       /* allocation of space */
-       if ( mask & OBD_MD_FLBLOCKS ) 
-               dst->i_blocks = src->i_blocks;
-       if ( mask & OBD_MD_FLOBDMD  &&  src->i_blocks == 0 ) {
-               CDEBUG(D_IOCTL, "copying inline data: ino %ld\n", dst->i_ino);
-               memcpy(&dst->u.ext2_i.i_data, &src->u.ext2_i.i_data, 
-                      sizeof(src->u.ext2_i.i_data));
-       } else {
-               CDEBUG(D_INODE, "XXXX cpy_obdmd: ino %ld iblocks not 0!\n",
-                      src->i_ino);
-       }
+static inline void obdo_cpy_md(struct obdo *dst, struct obdo *src,
+                               obd_flag valid)
+{
+#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;
+        }
+
+        dst->o_valid |= valid;
 }
 
 
-static __inline__ int obdo_cmp_md(obdattr *dst, obdattr *src, int mask)
-{
-       int res = 1;
-
-       /* If the OBD_MD_NO flag is set, then we copy all EXCEPT those
-        * fields given by the flags.  The default is to copy the field
-        * given by the flags.
-        */
-       if (mask & OBD_MD_NO)
-               mask = ~mask;
-
-       if ( mask & OBD_MD_FLMODE )
-               res = (res && (dst->i_mode == src->i_mode));
-       if ( mask & OBD_MD_FLUID )
-               res = (res && (dst->i_uid == src->i_uid));
-       if ( mask & OBD_MD_FLGID )
-               res = (res && (dst->i_gid == src->i_gid));
-       if ( mask & OBD_MD_FLSIZE )
-               res = (res && (dst->i_size == src->i_size));
-       if ( mask & OBD_MD_FLATIME )
-               res = (res && (dst->i_atime == src->i_atime));
-       if ( mask & OBD_MD_FLMTIME )
-               res = (res && (dst->i_mtime == src->i_mtime));
-       if ( mask & OBD_MD_FLCTIME )
-               res = (res && (dst->i_ctime == src->i_ctime));
-       if ( mask & OBD_MD_FLFLAGS )
-               res = (res && (dst->i_flags == src->i_flags));
-       /* allocation of space */
-       if ( mask & OBD_MD_FLBLOCKS )
-               res = (res && (dst->i_blocks == src->i_blocks));
-       return res;
+/* 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__ void obd_cpy_appmd(obdattr *dst, obdattr *src)
+#ifdef __KERNEL__
+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);
+
+/* 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);
+
+extern void (*class_signal_connection_failure)(struct ptlrpc_connection *);
+
+static inline struct ptlrpc_connection *class_rd2conn(struct recovd_data *rd)
 {
-       dst->i_mode = src->i_mode;
-       dst->i_uid = src->i_uid;
-       dst->i_gid = src->i_gid;
-       dst->i_size = src->i_size;
-       dst->i_atime = src->i_atime;
-       dst->i_mtime = src->i_mtime;
-       dst->i_ctime = src->i_ctime;
-       dst->i_flags = src->i_flags;
-       /* allocation of space */
-       dst->i_blocks = src->i_blocks;
+        /* reuse list_entry's member-pointer offset stuff */
+        return list_entry(rd, struct ptlrpc_connection, c_recovd_data);
 }
 
+#endif
+
+/* 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 */