Whamcloud - gitweb
add lu_context everywhere. Mountability preserved.
authornikita <nikita>
Thu, 13 Apr 2006 22:58:28 +0000 (22:58 +0000)
committernikita <nikita>
Thu, 13 Apr 2006 22:58:28 +0000 (22:58 +0000)
lustre/cmm/cmm_internal.h
lustre/cmm/cmm_object.c
lustre/fid/fid_seq.c
lustre/include/linux/lu_object.h
lustre/include/linux/lustre_fid.h
lustre/include/linux/md_object.h
lustre/mdd/mdd_handler.c
lustre/mdt/mdt_handler.c
lustre/mdt/mdt_internal.h
lustre/obdclass/lu_object.c
lustre/osd/osd_handler.c

index d9c90b7..8f47b41 100644 (file)
@@ -86,21 +86,24 @@ static inline struct md_object *cmm2child_obj(struct cmm_object *o)
 
 /* cmm_object.c */
 int cmm_object_init(struct lu_context *ctxt, struct lu_object*);
-struct lu_object *cmm_object_alloc(struct lu_device *);
-void cmm_object_free(struct lu_object *o);
+struct lu_object *cmm_object_alloc(struct lu_context *ctx, struct lu_device *);
+void cmm_object_free(struct lu_context *ctx, struct lu_object *o);
 void cmm_object_release(struct lu_context *ctxt, struct lu_object *o);
 //int cmm_getattr(struct lu_object *o, struct lu_attr *a);
 //int cmm_setattr(struct lu_object *o, struct lu_attr *a);
-int cmm_object_print(struct seq_file *f, const struct lu_object *o);
+int cmm_object_print(struct lu_context *ctx,
+                     struct seq_file *f, const struct lu_object *o);
 
 /* cmm md operations */
-int cmm_config(struct md_device *md, const char *name,
+int cmm_config(struct lu_context *ctx, struct md_device *md, const char *name,
                void *buf, int size, int mode);
-int cmm_root_get(struct md_device *m, struct lu_fid *f);
-int cmm_statfs(struct md_device *m, struct kstatfs *sfs);
+int cmm_root_get(struct lu_context *ctx, struct md_device *m, struct lu_fid *f);
+int cmm_statfs(struct lu_context *ctx,
+               struct md_device *m, struct kstatfs *sfs);
 int cmm_mkdir(struct lu_context *ctxt, struct md_object *o, const char *name,
               struct md_object *child);
-int cmm_attr_get(struct lu_context *ctxt, struct md_object *obj, void *buf, int size,
+int cmm_attr_get(struct lu_context *ctxt,
+                 struct md_object *obj, void *buf, int size,
                  const char *name, struct md_params *);
 
 #endif /* __KERNEL__ */
index 95ba5bf..42f6060 100644 (file)
@@ -36,7 +36,7 @@
 
 static struct md_object_operations cmm_mo_ops;
 
-struct lu_object *cmm_object_alloc(struct lu_device *d)
+struct lu_object *cmm_object_alloc(struct lu_context *ctx, struct lu_device *d)
 {
        struct cmm_object *mo;
         ENTRY;
@@ -61,7 +61,7 @@ int cmm_object_init(struct lu_context *ctxt, struct lu_object *o)
         ENTRY;
 
        under = &d->cmm_child->md_lu_dev;
-       below = under->ld_ops->ldo_object_alloc(under);
+       below = under->ld_ops->ldo_object_alloc(ctxt, under);
        if (below != NULL) {
                lu_object_add(o, below);
                RETURN(0);
@@ -69,7 +69,7 @@ int cmm_object_init(struct lu_context *ctxt, struct lu_object *o)
                RETURN(-ENOMEM);
 }
 
-void cmm_object_free(struct lu_object *o)
+void cmm_object_free(struct lu_context *ctx, struct lu_object *o)
 {
        lu_object_fini(o);
 }
@@ -79,57 +79,65 @@ void cmm_object_release(struct lu_context *ctxt, struct lu_object *o)
         return;
 }
 
-int cmm_object_print(struct seq_file *f, const struct lu_object *o)
+int cmm_object_print(struct lu_context *ctx,
+                     struct seq_file *f, const struct lu_object *o)
 {
        return seq_printf(f, LUSTRE_CMM0_NAME"-object@%p", o);
 }
 
 /* Locking API */
 #if 0
-static void cmm_lock(struct md_object *obj, __u32 mode)
+static void cmm_lock(struct lu_context *ctxt, struct md_object *obj, __u32 mode)
 {
         struct cmm_object *cmm_obj = md2cmm_obj(obj);
         struct cmm_device *cmm_dev = cmm_obj2dev(cmm_obj);
+        struct md_object  *next    = cmm2child_obj(cmm_obj);
 
-        CMM_DO_CHILD(cmm_dev)->ldo_lock_obj(cmm2child_obj(cmm_obj), mode);
-        return;
+        next->mo_ops->moo_object_lock(ctxt, next, mode);
 }
 
-static void cmm_unlock(struct md_object *obj, __u32 mode)
+static void cmm_unlock(struct lu_context *ctxt,
+                       struct md_object *obj, __u32 mode)
 {
         struct cmm_object *cmm_obj = md2cmm_obj(obj);
         struct cmm_device *cmm_dev = cmm_obj2dev(cmm_obj);
+        struct md_object  *next    = cmm2child_obj(cmm_obj);
 
-        CMM_DO_CHILD(cmm_dev)->ldo_unlock_obj(cmm2child_obj(cmm_obj), mode);
-        return;
+        next->mo_ops->moo_object_unlock(ctxt, next, mode);
 }
 #endif
 /* Llog API */
 /* Object API */
 /* Metadata API */
-int cmm_root_get(struct md_device *md, struct lu_fid *fid) {
+int cmm_root_get(struct lu_context *ctx,
+                 struct md_device *md, struct lu_fid *fid)
+{
         struct cmm_device *cmm_dev = md2cmm_dev(md);
 
-        return cmm_child_ops(cmm_dev)->mdo_root_get(cmm_dev->cmm_child, fid);
+        return cmm_child_ops(cmm_dev)->mdo_root_get(ctx,
+                                                    cmm_dev->cmm_child, fid);
 }
 
-int cmm_config(struct md_device *md, const char *name,
+int cmm_config(struct lu_context *ctxt,
+               struct md_device *md, const char *name,
                void *buf, int size, int mode)
 {
         struct cmm_device *cmm_dev = md2cmm_dev(md);
         int result;
         ENTRY;
-        result = cmm_child_ops(cmm_dev)->mdo_config(cmm_dev->cmm_child,
+        result = cmm_child_ops(cmm_dev)->mdo_config(ctxt, cmm_dev->cmm_child,
                                                     name, buf, size, mode);
         RETURN(result);
 }
 
-int cmm_statfs(struct md_device *md, struct kstatfs *sfs) {
+int cmm_statfs(struct lu_context *ctxt,
+               struct md_device *md, struct kstatfs *sfs) {
         struct cmm_device *cmm_dev = md2cmm_dev(md);
        int result;
 
         ENTRY;
-        result = cmm_child_ops(cmm_dev)->mdo_statfs(cmm_dev->cmm_child, sfs);
+        result = cmm_child_ops(cmm_dev)->mdo_statfs(ctxt,
+                                                    cmm_dev->cmm_child, sfs);
         RETURN (result);
 }
 
index a54c468..4e319f5 100644 (file)
@@ -38,7 +38,7 @@ struct lu_seq_mgr *seq_mgr_init(struct lu_seq_mgr_ops *ops,
 {
         struct lu_seq_mgr *mgr;
         ENTRY;
-        
+
         OBD_ALLOC_PTR(mgr);
         if (!mgr)
                 RETURN(NULL);
@@ -57,32 +57,22 @@ void seq_mgr_fini(struct lu_seq_mgr *mgr)
 }
 EXPORT_SYMBOL(seq_mgr_fini);
 
-int seq_mgr_write(struct lu_seq_mgr *mgr)
+int seq_mgr_write(struct lu_context *ctx, struct lu_seq_mgr *mgr)
 {
-        int rc = -ENOTSUPP;
         ENTRY;
-
-        if (mgr->m_ops->smo_write)
-                rc = mgr->m_ops->smo_write(mgr->m_opaque, &mgr->m_seq);
-
-        RETURN(rc);
+        RETURN(mgr->m_ops->smo_write(ctx, mgr->m_opaque, &mgr->m_seq));
 }
 EXPORT_SYMBOL(seq_mgr_write);
 
-int seq_mgr_read(struct lu_seq_mgr *mgr)
+int seq_mgr_read(struct lu_context *ctx, struct lu_seq_mgr *mgr)
 {
-        int rc = -ENOTSUPP;
         ENTRY;
-
-        if (mgr->m_ops->smo_read)
-                rc = mgr->m_ops->smo_read(mgr->m_opaque, &mgr->m_seq);
-
-        RETURN(rc);
+        RETURN(mgr->m_ops->smo_read(ctx, mgr->m_opaque, &mgr->m_seq));
 }
 EXPORT_SYMBOL(seq_mgr_read);
 
 /* manager functinality stuff */
-int seq_mgr_alloc(struct lu_seq_mgr *mgr, __u64 *seq)
+int seq_mgr_alloc(struct lu_context *ctx, struct lu_seq_mgr *mgr, __u64 *seq)
 {
         int rc = 0;
         ENTRY;
@@ -94,13 +84,8 @@ int seq_mgr_alloc(struct lu_seq_mgr *mgr, __u64 *seq)
         mgr->m_seq += 1;
         *seq = mgr->m_seq;
 
-        rc = seq_mgr_write(mgr);
-        if (rc == -ENOTSUPP) {
-                CERROR("Seq manager ->write() method "
-                       "is no defined.\n");
-                rc = 0;
-        }
-        
+        rc = seq_mgr_write(ctx, mgr);
+
         up(&mgr->m_seq_sem);
         RETURN(rc);
 }
@@ -109,7 +94,7 @@ EXPORT_SYMBOL(seq_mgr_alloc);
 /* initialize meta-sequence. First of all try to get it from lower layer,
  * falling down to back store one. In the case this is first run and there is
  * not meta-sequence initialized yet - store it to backstore. */
-int seq_mgr_setup(struct lu_seq_mgr *mgr)
+int seq_mgr_setup(struct lu_context *ctx, struct lu_seq_mgr *mgr)
 {
         int rc = 0;
         ENTRY;
@@ -117,27 +102,15 @@ int seq_mgr_setup(struct lu_seq_mgr *mgr)
         /* allocate next seq after root one */
         mgr->m_seq = LUSTRE_ROOT_FID_SEQ + 1;
 
-        rc = seq_mgr_read(mgr);
-        if (rc == -EOPNOTSUPP) {
-                /* provide zero error and let continue with default value of
-                 * sequence. */
-                GOTO(out, rc = 0);
-        } else if (rc == -ENODATA) {
+        rc = seq_mgr_read(ctx, mgr);
+        if (rc == -ENODATA) {
                 CWARN("initialize sequence by defaut ["LPU64"]\n", mgr->m_seq);
 
                 /* initialize new sequence config as it is not yet created. */
-                rc = seq_mgr_write(mgr);
-                if (rc == -EOPNOTSUPP) {
-                        /* provide zero error and let continue with default
-                         * value of sequence. */
-                        CERROR("can't update save initial sequence. "
-                               "No method defined\n");
-                        GOTO(out, rc = 0);
-                }
+                rc = seq_mgr_write(ctx, mgr);
         }
 
         EXIT;
-out:
         if (rc == 0)
                 CWARN("using start sequence: ["LPU64"]\n", mgr->m_seq);
         return rc;
index 097980e..eb8f36c 100644 (file)
@@ -143,30 +143,32 @@ struct lu_device_operations {
         * parts). This is called by ->ldo_object_init() from the parent
         * layer.
         */
-       struct lu_object *(*ldo_object_alloc)(struct lu_device *);
+       struct lu_object *(*ldo_object_alloc)(struct lu_context *,
+                                              struct lu_device *);
 
        /*
         * Called before ->ldo_object_free() to signal that object is being
         * destroyed.
         */
-       void (*ldo_object_delete)(struct lu_object *o);
+       void (*ldo_object_delete)(struct lu_context *ctx, struct lu_object *o);
 
        /*
         * Dual to ->ldo_object_alloc(). Called when object is removed from
         * memory.
         */
-       void (*ldo_object_free)(struct lu_object *o);
+       void (*ldo_object_free)(struct lu_context *ctx, struct lu_object *o);
 
        /*
         * Called when last active reference to the object is released (and
         * object returns to the cache).
         */
-       void (*ldo_object_release)(struct lu_context *ctxt, struct lu_object *o);
+       void (*ldo_object_release)(struct lu_context *ctx, struct lu_object *o);
 
        /*
         * Debugging helper. Print given object.
         */
-       int (*ldo_object_print)(struct seq_file *f, const struct lu_object *o);
+       int (*ldo_object_print)(struct lu_context *ctx,
+                                struct seq_file *f, const struct lu_object *o);
 };
 
 /*
@@ -250,11 +252,6 @@ struct lu_attr {
         __u32          la_nlink;
 };
 
-/* the context of the ops*/
-struct lu_context {
-        struct lu_attr lc_attr;
-};
-
 /*
  * Layer in the layered object.
  */
@@ -436,8 +433,9 @@ static inline int lu_object_is_dying(struct lu_object_header *h)
 }
 
 void lu_object_put(struct lu_context *ctxt, struct lu_object *o);
-void lu_site_purge(struct lu_site *s, int nr);
-int lu_object_print(struct seq_file *f, const struct lu_object *o);
+void lu_site_purge(struct lu_context *ctx, struct lu_site *s, int nr);
+int lu_object_print(struct lu_context *ctxt,
+                    struct seq_file *f, const struct lu_object *o);
 struct lu_object *lu_object_find(struct lu_context *ctxt,
                                  struct lu_site *s, const struct lu_fid *f);
 
@@ -462,6 +460,32 @@ void lu_object_header_fini(struct lu_object_header *h);
 struct lu_object *lu_object_locate(struct lu_object_header *h,
                                    struct lu_device_type *dtype);
 
+/*
+ * lu_context. Execution context for lu_object methods. Currently associated
+ * with thread.
+ */
+struct lu_context {
+        __u32                  lc_tags;
+        struct lu_attr         lc_attr;
+        struct ptlrpc_thread  *lc_thread;
+        void                 **lc_value;
+};
+
+
+struct lu_context_key {
+        void  *(*lct_init)(struct lu_context *ctx);
+        void   (*lct_fini)(struct lu_context *ctx, void *data);
+        int      lct_index;
+};
+
+int   lu_context_key_register(struct lu_context_key *key);
+void *lu_context_key_get(struct lu_context *ctx, struct lu_context_key *key);
+
+int  lu_context_init(struct lu_context *ctx);
+void lu_context_fini(struct lu_context *ctx);
+
+void lu_context_enter(struct lu_context *ctx);
+void lu_context_exit(struct lu_context *ctx);
 
 /*
  * DT device interface. XXX Probably should go elsewhere.
@@ -480,18 +504,24 @@ enum dt_lock_mode {
 struct dt_device_operations {
         /* method for getting/setting device wide back stored config data, like
          * last used meta-sequence, etc. */
-        int (*dt_config) (struct dt_device *dev, const char *name,
+        int (*dt_config) (struct lu_context *ctx,
+                          struct dt_device *dev, const char *name,
                           void *buf, int size, int mode);
-        int   (*dt_statfs)(struct dt_device *dev, struct kstatfs *sfs);
-        struct thandle *(*dt_trans_start)(struct dt_device *dev,
+        int   (*dt_statfs)(struct lu_context *ctx,
+                           struct dt_device *dev, struct kstatfs *sfs);
+        struct thandle *(*dt_trans_start)(struct lu_context *ctx,
+                                          struct dt_device *dev,
                                           struct txn_param *param);
-        void  (*dt_trans_stop)(struct thandle *th);
-        int   (*dt_root_get)(struct dt_device *dev, struct lu_fid *f);
+        void  (*dt_trans_stop)(struct lu_context *ctx, struct thandle *th);
+        int   (*dt_root_get)(struct lu_context *ctx,
+                             struct dt_device *dev, struct lu_fid *f);
 };
 
 struct dt_object_operations {
-        void  (*do_object_lock)(struct dt_object *dt, enum dt_lock_mode mode);
-        void  (*do_object_unlock)(struct dt_object *dt, enum dt_lock_mode mode);
+        void  (*do_object_lock)(struct lu_context *ctx,
+                                struct dt_object *dt, enum dt_lock_mode mode);
+        void  (*do_object_unlock)(struct lu_context *ctx,
+                                  struct dt_object *dt, enum dt_lock_mode mode);
 
         int   (*do_object_create)(struct lu_context *ctxt,
                                   struct dt_object *dt,
index 8612234..14db4c1 100644 (file)
 #include <libcfs/list.h>
 #include <libcfs/kp30.h>
 
+struct lu_context;
 struct lu_seq_mgr_ops {
-        int (*smo_read) (void *opaque, __u64 *);
-        int (*smo_write) (void *opaque, __u64 *);
+        int (*smo_read) (struct lu_context *, void *opaque, __u64 *);
+        int (*smo_write) (struct lu_context *, void *opaque, __u64 *);
 };
 
 struct lu_seq_mgr {
@@ -51,9 +52,9 @@ struct lu_seq_mgr *seq_mgr_init(struct lu_seq_mgr_ops *, void *);
 void seq_mgr_fini(struct lu_seq_mgr *);
 
 /* seq management methods */
-int seq_mgr_setup(struct lu_seq_mgr *);
-int seq_mgr_read(struct lu_seq_mgr *);
-int seq_mgr_write(struct lu_seq_mgr *);
-int seq_mgr_alloc(struct lu_seq_mgr *, __u64 *);
+int seq_mgr_setup(struct lu_context *, struct lu_seq_mgr *);
+int seq_mgr_read(struct lu_context *, struct lu_seq_mgr *);
+int seq_mgr_write(struct lu_context *, struct lu_seq_mgr *);
+int seq_mgr_alloc(struct lu_context *, struct lu_seq_mgr *, __u64 *);
 
 #endif /* __LINUX_OBD_CLASS_H */
index 4a96c8a..9abe2a9 100644 (file)
@@ -75,12 +75,15 @@ struct md_object_operations {
 struct md_device_operations {
         /* method for getting/setting device wide back stored config data, like
          * last used meta-sequence, etc. */
-        int (*mdo_config) (struct md_device *m, const char *name,
+        int (*mdo_config) (struct lu_context *ctx,
+                           struct md_device *m, const char *name,
                            void *buf, int size, int mode);
 
         /* meta-data device related handlers. */
-        int (*mdo_root_get)(struct md_device *m, struct lu_fid *f);
-        int (*mdo_statfs)(struct md_device *m, struct kstatfs *sfs);
+        int (*mdo_root_get)(struct lu_context *ctx,
+                            struct md_device *m, struct lu_fid *f);
+        int (*mdo_statfs)(struct lu_context *ctx,
+                          struct md_device *m, struct kstatfs *sfs);
 };
 
 struct md_device {
index 0c3d11c..4975055 100644 (file)
 #include "mdd_internal.h"
 
 
-static struct thandle* mdd_trans_start(struct mdd_device *, struct txn_param *);
-static void mdd_trans_stop(struct mdd_device *mdd, struct thandle *handle);
+static struct thandle* mdd_trans_start(struct lu_context *ctxt,
+                                       struct mdd_device *, struct txn_param *);
+static void mdd_trans_stop(struct lu_context *ctxt,
+                           struct mdd_device *mdd, struct thandle *handle);
 static struct dt_object* mdd_object_child(struct mdd_object *o);
 static struct lu_device_operations mdd_lu_ops;
-static void mdd_lock(struct mdd_object *obj, enum dt_lock_mode mode);
-static void mdd_unlock(struct mdd_object *obj, enum dt_lock_mode mode);
+static void mdd_lock(struct lu_context *ctx,
+                     struct mdd_object *obj, enum dt_lock_mode mode);
+static void mdd_unlock(struct lu_context *ctx,
+                       struct mdd_object *obj, enum dt_lock_mode mode);
 
 static struct md_object_operations mdd_obj_ops;
 
@@ -94,7 +98,8 @@ static inline struct dt_device_operations *mdd_child_ops(struct mdd_device *d)
         return d->mdd_child->dd_ops;
 }
 
-static struct lu_object *mdd_object_alloc(struct lu_device *d)
+static struct lu_object *mdd_object_alloc(struct lu_context *ctxt,
+                                          struct lu_device *d)
 {
         struct mdd_object *mdo;
         ENTRY;
@@ -119,7 +124,7 @@ static int mdd_object_init(struct lu_context *ctxt, struct lu_object *o)
         ENTRY;
 
        under = &d->mdd_child->dd_lu_dev;
-       below = under->ld_ops->ldo_object_alloc(under);
+       below = under->ld_ops->ldo_object_alloc(ctxt, under);
 
         if (below == NULL)
                RETURN(-ENOMEM);
@@ -128,7 +133,7 @@ static int mdd_object_init(struct lu_context *ctxt, struct lu_object *o)
         RETURN(0);
 }
 
-static void mdd_object_free(struct lu_object *o)
+static void mdd_object_free(struct lu_context *ctxt, struct lu_object *o)
 {
        struct lu_object_header *h;
         struct mdd_object *mdd = mdd_obj(o);
@@ -211,11 +216,12 @@ mdd_object_destroy(struct lu_context *ctxt, struct md_object *obj)
         int rc ;
         ENTRY;
 
-        handle = mdd_trans_start(mdd, &TXN_PARAM(MDD_OBJECT_DESTROY_CREDITS));
+        handle = mdd_trans_start(ctxt, mdd,
+                                 &TXN_PARAM(MDD_OBJECT_DESTROY_CREDITS));
         if (IS_ERR(handle))
                 RETURN(PTR_ERR(handle));
 
-        mdd_lock(mdd_obj, DT_WRITE_LOCK);
+        mdd_lock(ctxt, mdd_obj, DT_WRITE_LOCK);
         if (open_orphan(mdd_obj))
                 rc = mdd_add_orphan(mdd, mdd_obj, handle);
         else {
@@ -225,8 +231,8 @@ mdd_object_destroy(struct lu_context *ctxt, struct md_object *obj)
                         rc = mdd_add_unlink_log(mdd, mdd_obj, handle);
         }
 
-        mdd_unlock(mdd_obj, DT_WRITE_LOCK);
-        mdd_trans_stop(mdd, handle);
+        mdd_unlock(ctxt, mdd_obj, DT_WRITE_LOCK);
+        mdd_trans_stop(ctxt, mdd, handle);
         RETURN(rc);
 }
 
@@ -246,7 +252,8 @@ static void mdd_object_release(struct lu_context *ctxt, struct lu_object *o)
                 CERROR("Failed to get nlink: %d. Pretending nonzero.\n", rc);
 }
 
-static int mdd_object_print(struct seq_file *f, const struct lu_object *o)
+static int mdd_object_print(struct lu_context *ctxt,
+                            struct seq_file *f, const struct lu_object *o)
 {
         return seq_printf(f, LUSTRE_MDD0_NAME"-object@%p", o);
 }
@@ -313,41 +320,47 @@ static struct dt_object* mdd_object_child(struct mdd_object *o)
                             struct dt_object, do_lu);
 }
 
-static void mdd_lock(struct mdd_object *obj, enum dt_lock_mode mode)
+static void mdd_lock(struct lu_context *ctxt,
+                     struct mdd_object *obj, enum dt_lock_mode mode)
 {
         struct dt_object  *next = mdd_object_child(obj);
 
-        next->do_ops->do_object_lock(next, mode);
+        next->do_ops->do_object_lock(ctxt, next, mode);
 }
 
-static void mdd_unlock(struct mdd_object *obj, enum dt_lock_mode mode)
+static void mdd_unlock(struct lu_context *ctxt,
+                       struct mdd_object *obj, enum dt_lock_mode mode)
 {
         struct dt_object  *next = mdd_object_child(obj);
 
-        next->do_ops->do_object_unlock(next, mode);
+        next->do_ops->do_object_unlock(ctxt, next, mode);
 }
 
-static void mdd_lock2(struct mdd_object *o0, struct mdd_object *o1)
+static void mdd_lock2(struct lu_context *ctxt,
+                      struct mdd_object *o0, struct mdd_object *o1)
 {
-        mdd_lock(o0, DT_WRITE_LOCK);
-        mdd_lock(o1, DT_WRITE_LOCK);
+        mdd_lock(ctxt, o0, DT_WRITE_LOCK);
+        mdd_lock(ctxt, o1, DT_WRITE_LOCK);
 }
 
-static void mdd_unlock2(struct mdd_object *o0, struct mdd_object *o1)
+static void mdd_unlock2(struct lu_context *ctxt,
+                        struct mdd_object *o0, struct mdd_object *o1)
 {
-        mdd_unlock(o0, DT_WRITE_LOCK);
-        mdd_unlock(o1, DT_WRITE_LOCK);
+        mdd_unlock(ctxt, o0, DT_WRITE_LOCK);
+        mdd_unlock(ctxt, o1, DT_WRITE_LOCK);
 }
 
-static struct thandle* mdd_trans_start(struct mdd_device *mdd,
+static struct thandle* mdd_trans_start(struct lu_context *ctxt,
+                                       struct mdd_device *mdd,
                                        struct txn_param *p)
 {
-        return mdd_child_ops(mdd)->dt_trans_start(mdd->mdd_child, p);
+        return mdd_child_ops(mdd)->dt_trans_start(ctxt, mdd->mdd_child, p);
 }
 
-static void mdd_trans_stop(struct mdd_device *mdd, struct thandle *handle)
+static void mdd_trans_stop(struct lu_context *ctxt,
+                           struct mdd_device *mdd, struct thandle *handle)
 {
-        mdd_child_ops(mdd)->dt_trans_stop(handle);
+        mdd_child_ops(mdd)->dt_trans_stop(ctxt, handle);
 }
 
 static int
@@ -377,13 +390,14 @@ mdd_object_create(struct lu_context *ctxt, struct md_object *pobj,
         int rc;
         ENTRY;
 
-        handle = mdd_trans_start(mdd, &TXN_PARAM(MDD_OBJECT_CREATE_CREDITS));
+        handle = mdd_trans_start(ctxt, mdd,
+                                 &TXN_PARAM(MDD_OBJECT_CREATE_CREDITS));
         if (IS_ERR(handle))
                 RETURN(PTR_ERR(handle));
 
         rc = __mdd_object_create(ctxt, mdd, mdd_pobj, mdd_child, arg, handle);
 
-        mdd_trans_stop(mdd, handle);
+        mdd_trans_stop(ctxt, mdd, handle);
 
         RETURN(rc);
 }
@@ -408,14 +422,14 @@ mdd_attr_set(struct lu_context *ctxt, struct md_object *obj, void *buf,
         int  rc;
         ENTRY;
 
-        handle = mdd_trans_start(mdd, &TXN_PARAM(MDD_ATTR_SET_CREDITS));
+        handle = mdd_trans_start(ctxt, mdd, &TXN_PARAM(MDD_ATTR_SET_CREDITS));
         if (!handle)
                 RETURN(-ENOMEM);
 
         rc = __mdd_attr_set(ctxt, mdd, mdo2mddo(obj), buf, buf_len, name,
                             arg, handle);
 
-        mdd_trans_stop(mdd, handle);
+        mdd_trans_stop(ctxt, mdd, handle);
 
         RETURN(rc);
 }
@@ -435,11 +449,11 @@ __mdd_index_insert(struct lu_context *ctxt, struct mdd_device *mdd,
         struct dt_object *next = mdd_object_child(pobj);
         ENTRY;
 
-        mdd_lock2(pobj, obj);
+        mdd_lock2(ctxt, pobj, obj);
 
-        rc = next->do_ops->do_index_insert(ctxt, next, mdd_object_getfid(obj), name,
-                                           arg, handle);
-        mdd_unlock2(pobj, obj);
+        rc = next->do_ops->do_index_insert(ctxt, next, mdd_object_getfid(obj),
+                                           name, arg, handle);
+        mdd_unlock2(ctxt, pobj, obj);
 
         RETURN(rc);
 }
@@ -454,14 +468,15 @@ mdd_index_insert(struct lu_context *ctxt, struct md_object *pobj,
         struct thandle *handle;
         ENTRY;
 
-        handle = mdd_trans_start(mdd, &TXN_PARAM(MDD_INDEX_INSERT_CREDITS));
+        handle = mdd_trans_start(ctxt, mdd,
+                                 &TXN_PARAM(MDD_INDEX_INSERT_CREDITS));
         if (IS_ERR(handle))
                 RETURN(PTR_ERR(handle));
 
         rc = __mdd_index_insert(ctxt, mdd, mdo2mddo(pobj), mdo2mddo(obj),
                                 name, arg, handle);
 
-        mdd_trans_stop(mdd, handle);
+        mdd_trans_stop(ctxt, mdd, handle);
         RETURN(rc);
 }
 
@@ -475,11 +490,11 @@ __mdd_index_delete(struct lu_context *ctxt, struct mdd_device *mdd,
         struct dt_object *next = mdd_object_child(pobj);
         ENTRY;
 
-        mdd_lock2(pobj, obj);
+        mdd_lock2(ctxt, pobj, obj);
 
         rc = next->do_ops->do_index_delete(ctxt, next, mdd_object_getfid(obj),
                                            name, arg, handle);
-        mdd_unlock2(pobj, obj);
+        mdd_unlock2(ctxt, pobj, obj);
 
         RETURN(rc);
 }
@@ -496,14 +511,15 @@ mdd_index_delete(struct lu_context *ctxt, struct md_object *pobj,
         int rc;
         ENTRY;
 
-        handle = mdd_trans_start(mdd, &TXN_PARAM(MDD_INDEX_DELETE_CREDITS));
+        handle = mdd_trans_start(ctxt, mdd,
+                                 &TXN_PARAM(MDD_INDEX_DELETE_CREDITS));
         if (IS_ERR(handle))
                 RETURN(PTR_ERR(handle));
 
         rc = __mdd_index_delete(ctxt, mdd, mdd_pobj, mdd_obj, name, arg,
                                 handle);
 
-        mdd_trans_stop(mdd, handle);
+        mdd_trans_stop(ctxt, mdd, handle);
 
         RETURN(rc);
 }
@@ -520,11 +536,11 @@ mdd_link(struct lu_context *ctxt, struct md_object *tgt_obj,
         int rc, nlink;
         ENTRY;
 
-        handle = mdd_trans_start(mdd, &TXN_PARAM(MDD_LINK_CREDITS));
+        handle = mdd_trans_start(ctxt, mdd, &TXN_PARAM(MDD_LINK_CREDITS));
         if (IS_ERR(handle))
                 RETURN(PTR_ERR(handle));
 
-        mdd_lock2(mdd_tobj, mdd_sobj);
+        mdd_lock2(ctxt, mdd_tobj, mdd_sobj);
 
         rc = __mdd_index_insert(ctxt, mdd, mdd_tobj, mdd_sobj, name, arg,
                                 handle);
@@ -537,9 +553,9 @@ mdd_link(struct lu_context *ctxt, struct md_object *tgt_obj,
         rc = __mdd_attr_set(ctxt, mdd, mdd_sobj, &nlink, sizeof(nlink), "NLINK",
                             arg, handle);
 exit:
-        mdd_unlock2(mdd_tobj, mdd_sobj);
+        mdd_unlock2(ctxt, mdd_tobj, mdd_sobj);
 
-        mdd_trans_stop(mdd, handle);
+        mdd_trans_stop(ctxt, mdd, handle);
         RETURN(rc);
 }
 
@@ -571,7 +587,7 @@ mdd_rename(struct lu_context *ctxt, struct md_object *src_pobj,
         int rc;
         struct thandle *handle;
 
-        handle = mdd_trans_start(mdd, &TXN_PARAM(MDD_RENAME_CREDITS));
+        handle = mdd_trans_start(ctxt, mdd, &TXN_PARAM(MDD_RENAME_CREDITS));
         if (IS_ERR(handle))
                 RETURN(PTR_ERR(handle));
 
@@ -597,7 +613,7 @@ mdd_rename(struct lu_context *ctxt, struct md_object *src_pobj,
                 GOTO(cleanup, rc);
 cleanup:
         mdd_rename_unlock(mdd, mdd_spobj, mdd_tpobj, mdd_sobj, mdd_tobj);
-        mdd_trans_stop(mdd, handle);
+        mdd_trans_stop(ctxt, mdd, handle);
         RETURN(rc);
 }
 
@@ -610,11 +626,11 @@ mdd_mkdir(struct lu_context *ctxt, struct md_object *pobj,
         int rc = 0;
         ENTRY;
 
-        handle = mdd_trans_start(mdd, &TXN_PARAM(MDD_MKDIR_CREDITS));
+        handle = mdd_trans_start(ctxt, mdd, &TXN_PARAM(MDD_MKDIR_CREDITS));
         if (IS_ERR(handle))
                 RETURN(PTR_ERR(handle));
 
-        mdd_lock(mdo2mddo(pobj), DT_WRITE_LOCK);
+        mdd_lock(ctxt, mdo2mddo(pobj), DT_WRITE_LOCK);
 
         rc = __mdd_object_create(ctxt, mdd, mdo2mddo(pobj), mdo2mddo(child),
                                  NULL, handle);
@@ -626,38 +642,40 @@ mdd_mkdir(struct lu_context *ctxt, struct md_object *pobj,
         if (rc)
                 GOTO(cleanup, rc);
 cleanup:
-        mdd_unlock(mdo2mddo(pobj), DT_WRITE_LOCK);
-        mdd_trans_stop(mdd, handle);
+        mdd_unlock(ctxt, mdo2mddo(pobj), DT_WRITE_LOCK);
+        mdd_trans_stop(ctxt, mdd, handle);
         RETURN(rc);
 }
 
-static int mdd_root_get(struct md_device *m, struct lu_fid *f)
+static int mdd_root_get(struct lu_context *ctx,
+                        struct md_device *m, struct lu_fid *f)
 {
         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
 
         ENTRY;
-        RETURN(mdd_child_ops(mdd)->dt_root_get(mdd->mdd_child, f));
+        RETURN(mdd_child_ops(mdd)->dt_root_get(ctx, mdd->mdd_child, f));
 }
 
-static int mdd_config(struct md_device *m, const char *name,
-                      void *buf, int size, int mode)
+static int mdd_config(struct lu_context *ctx, struct md_device *m,
+                      const char *name, void *buf, int size, int mode)
 {
         struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
         int rc;
         ENTRY;
 
-        rc = mdd_child_ops(mdd)->dt_config(mdd->mdd_child,
+        rc = mdd_child_ops(mdd)->dt_config(ctx, mdd->mdd_child,
                                            name, buf, size, mode);
         RETURN(rc);
 }
 
-static int mdd_statfs(struct md_device *m, struct kstatfs *sfs) {
+static int mdd_statfs(struct lu_context *ctx,
+                      struct md_device *m, struct kstatfs *sfs) {
        struct mdd_device *mdd = lu2mdd_dev(&m->md_lu_dev);
         int rc;
 
         ENTRY;
 
-        rc = mdd_child_ops(mdd)->dt_statfs(mdd->mdd_child, sfs);
+        rc = mdd_child_ops(mdd)->dt_statfs(ctx, mdd->mdd_child, sfs);
 
         RETURN(rc);
 }
index ffce553..1f87715 100644 (file)
@@ -85,7 +85,7 @@ static int mdt_md_mkdir(struct mdt_thread_info *info, struct mdt_device *d,
         if (!IS_ERR(child)) {
                 struct md_object *next = mdt_object_child(o);
 
-                result = next->mo_ops->moo_mkdir(next, name,
+                result = next->mo_ops->moo_mkdir(&info->mti_ctxt, next, name,
                                                  mdt_object_child(child));
                 mdt_object_put(child);
         } else
@@ -131,7 +131,8 @@ static int mdt_getstatus(struct mdt_thread_info *info,
                 result = -ENOMEM;
         else {
                 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof *body);
-                result = next->md_ops->mdo_root_get(next, &body->fid1);
+                result = next->md_ops->mdo_root_get(&info->mti_ctxt,
+                                                    next, &body->fid1);
         }
 
         /* the last_committed and last_xid fields are filled in for all
@@ -161,7 +162,7 @@ static int mdt_statfs(struct mdt_thread_info *info,
         } else {
                 osfs = lustre_msg_buf(req->rq_repmsg, 0, size);
                 /* XXX max_age optimisation is needed here. See mds_statfs */
-                result = next->md_ops->mdo_statfs(next, &sfs);
+                result = next->md_ops->mdo_statfs(&info->mti_ctxt, next, &sfs);
                 statfs_pack(osfs, &sfs);
         }
 
@@ -224,7 +225,19 @@ static int mdt_getattr(struct mdt_thread_info *info,
 static int mdt_connect(struct mdt_thread_info *info,
                        struct ptlrpc_request *req, int offset)
 {
-        return target_handle_connect(req, mdt_handle);
+        int result;
+
+        result = target_handle_connect(req, mdt_handle);
+        if (result == 0) {
+                struct obd_connect_data *data;
+                struct mdt_device *mdt;
+
+                mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
+                data = lustre_msg_buf(req->rq_repmsg, 0, sizeof *data);
+                result = seq_mgr_alloc(&info->mti_ctxt,
+                                       mdt->mdt_seq_mgr, &data->ocd_seq);
+        }
+        return result;
 }
 
 static int mdt_disconnect(struct mdt_thread_info *info,
@@ -599,7 +612,8 @@ static int mdt_req_handle(struct mdt_thread_info *info,
                         lustre_swab_reqbuf(req, off, sizeof *info->mti_body,
                                            lustre_swab_mdt_body);
                 if (body != NULL) {
-                        info->mti_object = mdt_object_find(&info->mti_ctxt, info->mti_mdt,
+                        info->mti_object = mdt_object_find(&info->mti_ctxt,
+                                                           info->mti_mdt,
                                                            &body->fid1);
                         if (IS_ERR(info->mti_object))
                                 result = PTR_ERR(info->mti_object);
@@ -669,7 +683,6 @@ static void mdt_thread_info_init(struct mdt_thread_info *info)
 {
         int i;
 
-        memset(info, 0, sizeof *info);
         info->mti_fail_id = OBD_FAIL_MDS_ALL_REPLY_NET;
         /*
          * Poison size array.
@@ -679,12 +692,14 @@ static void mdt_thread_info_init(struct mdt_thread_info *info)
         info->mti_rep_buf_nr = i;
         for (i = 0; i < ARRAY_SIZE(info->mti_lh); i++)
                 mdt_lock_handle_init(&info->mti_lh[i]);
+        lu_context_enter(&info->mti_ctxt);
 }
 
 static void mdt_thread_info_fini(struct mdt_thread_info *info)
 {
         int i;
 
+        lu_context_exit(&info->mti_ctxt);
         if (info->mti_object != NULL) {
                 mdt_object_put(&info->mti_ctxt, info->mti_object);
                 info->mti_object = NULL;
@@ -925,6 +940,7 @@ static int mdt_handle(struct ptlrpc_request *req)
         /* it can be NULL while CONNECT */
         if (req->rq_export)
                 info->mti_mdt = mdt_dev(req->rq_export->exp_obd->obd_lu_dev);
+        info->mti_ctxt.lc_thread = req->rq_svc_thread;
 
         result = mdt_handle0(req, info);
         mdt_thread_info_fini(info);
@@ -952,47 +968,41 @@ struct ptlrpc_service *ptlrpc_init_svc_conf(struct ptlrpc_service_conf *c,
                                prntfn, c->psc_num_threads);
 }
 
-static int mdt_config(struct mdt_device *m, const char *name,
-                      void *buf, int size, int mode)
+static int mdt_config(struct lu_context *ctx, struct mdt_device *m,
+                      const char *name, void *buf, int size, int mode)
 {
         struct md_device *child = m->mdt_child;
-        int rc;
         ENTRY;
-
-        if (!child->md_ops->mdo_config)
-                RETURN(-EOPNOTSUPP);
-
-        rc = child->md_ops->mdo_config(child, name, buf, size, mode);
-        RETURN(rc);
+        RETURN(child->md_ops->mdo_config(ctx, child, name, buf, size, mode));
 }
 
-static int mdt_seq_mgr_hpr(void *opaque, __u64 *seq,
+static int mdt_seq_mgr_hpr(struct lu_context *ctx, void *opaque, __u64 *seq,
                            int mode)
 {
         struct mdt_device *m = opaque;
         int rc;
         ENTRY;
 
-        rc = mdt_config(m, LUSTRE_CONFIG_METASEQ,
+        rc = mdt_config(ctx, m, LUSTRE_CONFIG_METASEQ,
                         seq, sizeof(*seq),
                         mode);
         RETURN(rc);
 }
 
-static int mdt_seq_mgr_read(void *opaque, __u64 *seq)
+static int mdt_seq_mgr_read(struct lu_context *ctx, void *opaque, __u64 *seq)
 {
         ENTRY;
-        RETURN(mdt_seq_mgr_hpr(opaque, seq, LUSTRE_CONFIG_GET));
+        RETURN(mdt_seq_mgr_hpr(ctx, opaque, seq, LUSTRE_CONFIG_GET));
 }
 
-static int mdt_seq_mgr_write(void *opaque, __u64 *seq)
+static int mdt_seq_mgr_write(struct lu_context *ctx, void *opaque, __u64 *seq)
 {
         ENTRY;
-        RETURN(mdt_seq_mgr_hpr(opaque, seq, LUSTRE_CONFIG_SET));
+        RETURN(mdt_seq_mgr_hpr(ctx, opaque, seq, LUSTRE_CONFIG_SET));
 }
 
 struct lu_seq_mgr_ops seq_mgr_ops = {
-        .smo_read = mdt_seq_mgr_read,
+        .smo_read  = mdt_seq_mgr_read,
         .smo_write = mdt_seq_mgr_write
 };
 
@@ -1038,6 +1048,7 @@ static int mdt_init0(struct mdt_device *m,
         struct lu_device  *mdt_child;
         const char *top   = lustre_cfg_string(cfg, 0);
         const char *child = lustre_cfg_string(cfg, 1);
+        struct lu_context ctx;
 
         ENTRY;
 
@@ -1106,17 +1117,26 @@ static int mdt_init0(struct mdt_device *m,
                 GOTO(err_fini_child, rc);
         }
 
+        rc = lu_context_init(&ctx);
+        if (rc != 0)
+                GOTO(err_fini_mgr, rc);
+
+        lu_context_enter(&ctx);
         /* init sequence info after device stack is initialized. */
-        rc = seq_mgr_setup(m->mdt_seq_mgr);
+        rc = seq_mgr_setup(&ctx, m->mdt_seq_mgr);
+        lu_context_exit(&ctx);
         if (rc)
-                GOTO(err_fini_mgr, rc);
+                GOTO(err_fini_ctx, rc);
 
         rc = ptlrpc_start_threads(NULL, m->mdt_service, LUSTRE_MDT0_NAME);
         if (rc)
-                GOTO(err_fini_mgr, rc);
+                GOTO(err_fini_ctx, rc);
 
+        lu_context_fini(&ctx);
         RETURN(0);
 
+err_fini_ctx:
+        lu_context_fini(&ctx);
 err_fini_mgr:
         seq_mgr_fini(m->mdt_seq_mgr);
         m->mdt_seq_mgr = NULL;
@@ -1134,7 +1154,8 @@ err_fini_site:
         RETURN(rc);
 }
 
-static struct lu_object *mdt_object_alloc(struct lu_device *d)
+static struct lu_object *mdt_object_alloc(struct lu_context *ctxt,
+                                          struct lu_device *d)
 {
         struct mdt_object *mo;
 
@@ -1160,7 +1181,7 @@ static int mdt_object_init(struct lu_context *ctxt, struct lu_object *o)
         struct lu_object  *below;
 
         under = &d->mdt_child->md_lu_dev;
-        below = under->ld_ops->ldo_object_alloc(under);
+        below = under->ld_ops->ldo_object_alloc(ctxt, under);
         if (below != NULL) {
                 lu_object_add(o, below);
                 return 0;
@@ -1168,7 +1189,7 @@ static int mdt_object_init(struct lu_context *ctxt, struct lu_object *o)
                 return -ENOMEM;
 }
 
-static void mdt_object_free(struct lu_object *o)
+static void mdt_object_free(struct lu_context *ctxt, struct lu_object *o)
 {
         struct lu_object_header *h;
 
@@ -1181,7 +1202,8 @@ static void mdt_object_release(struct lu_context *ctxt, struct lu_object *o)
 {
 }
 
-static int mdt_object_print(struct seq_file *f, const struct lu_object *o)
+static int mdt_object_print(struct lu_context *ctxt,
+                            struct seq_file *f, const struct lu_object *o)
 {
         return seq_printf(f, LUSTRE_MDT0_NAME"-object@%p", o);
 }
@@ -1196,7 +1218,8 @@ static struct lu_device_operations mdt_lu_ops = {
 
 /* mds_connect copy */
 static int mdt_obd_connect(struct lustre_handle *conn, struct obd_device *obd,
-                           struct obd_uuid *cluuid, struct obd_connect_data *data)
+                           struct obd_uuid *cluuid,
+                           struct obd_connect_data *data)
 {
         struct obd_export *exp;
         int rc, abort_recovery;
@@ -1242,9 +1265,6 @@ static int mdt_obd_connect(struct lustre_handle *conn, struct obd_device *obd,
         memcpy(mcd->mcd_uuid, cluuid, sizeof(mcd->mcd_uuid));
         med->med_mcd = mcd;
 
-        rc = seq_mgr_alloc(mdt->mdt_seq_mgr, &data->ocd_seq);
-        if (rc)
-                GOTO(out, rc);
 out:
         if (rc) {
                 if (mcd) {
@@ -1297,13 +1317,22 @@ static void mdt_device_free(struct lu_device *d)
 static void *mdt_thread_init(struct ptlrpc_thread *t)
 {
         struct mdt_thread_info *info;
+        int result;
 
-        return OBD_ALLOC_PTR(info) ? : ERR_PTR(-ENOMEM);
+        OBD_ALLOC_PTR(info);
+        if (info != NULL)
+                result = lu_context_init(&info->mti_ctxt);
+        else
+                result = -ENOMEM;
+        if (result != 0)
+                info = ERR_PTR(result);
+        return info;
 }
 
 static void mdt_thread_fini(struct ptlrpc_thread *t, void *data)
 {
         struct mdt_thread_info *info = data;
+        lu_context_fini(&info->mti_ctxt);
         OBD_FREE_PTR(info);
 }
 
index fe54661..84037b4 100644 (file)
@@ -134,7 +134,7 @@ enum {
  * reduce stack consumption.
  */
 struct mdt_thread_info {
-        struct lu_context     mti_ctxt;
+        struct lu_context      mti_ctxt;
         struct mdt_device     *mti_mdt;
         /*
          * number of buffers in reply message.
index 562b4de..a0ea5c1 100644 (file)
@@ -39,7 +39,7 @@
 
 #include <libcfs/list.h>
 
-static void lu_object_free(struct lu_object *o);
+static void lu_object_free(struct lu_context *ctx, struct lu_object *o);
 
 void lu_object_put(struct lu_context *ctxt, struct lu_object *o)
 {
@@ -66,7 +66,7 @@ void lu_object_put(struct lu_context *ctxt, struct lu_object *o)
                  * Object was already removed from hash and lru above, can
                  * kill it.
                  */
-                lu_object_free(o);
+                lu_object_free(ctxt, o);
 }
 EXPORT_SYMBOL(lu_object_put);
 
@@ -78,7 +78,7 @@ struct lu_object *lu_object_alloc(struct lu_context *ctxt,
         int clean;
         int result;
 
-        top = s->ls_top_dev->ld_ops->ldo_object_alloc(s->ls_top_dev);
+        top = s->ls_top_dev->ld_ops->ldo_object_alloc(ctxt, s->ls_top_dev);
         if (IS_ERR(top))
                 RETURN(top);
         *lu_object_fid(top) = *f;
@@ -90,9 +90,10 @@ struct lu_object *lu_object_alloc(struct lu_context *ctxt,
                                 continue;
                         clean = 0;
                         scan->lo_header = top->lo_header;
-                        result = lu_object_ops(scan)->ldo_object_init(ctxt, scan);
+                        result = lu_object_ops(scan)->ldo_object_init(ctxt,
+                                                                      scan);
                         if (result != 0) {
-                                lu_object_free(top);
+                                lu_object_free(ctxt, top);
                                 RETURN(ERR_PTR(result));
                         }
                         scan->lo_flags |= LU_OBJECT_ALLOCATED;
@@ -102,7 +103,7 @@ struct lu_object *lu_object_alloc(struct lu_context *ctxt,
         RETURN(top);
 }
 
-static void lu_object_free(struct lu_object *o)
+static void lu_object_free(struct lu_context *ctx, struct lu_object *o)
 {
         struct list_head splice;
         struct lu_object *scan;
@@ -110,7 +111,7 @@ static void lu_object_free(struct lu_object *o)
         list_for_each_entry_reverse(scan,
                                     &o->lo_header->loh_layers, lo_linkage) {
                 if (lu_object_ops(scan)->ldo_object_delete != NULL)
-                        lu_object_ops(scan)->ldo_object_delete(scan);
+                        lu_object_ops(scan)->ldo_object_delete(ctx, scan);
         }
         -- o->lo_dev->ld_site->ls_total;
         INIT_LIST_HEAD(&splice);
@@ -119,11 +120,11 @@ static void lu_object_free(struct lu_object *o)
                 o = container_of(splice.next, struct lu_object, lo_linkage);
                 list_del_init(&o->lo_linkage);
                 LASSERT(lu_object_ops(o)->ldo_object_free != NULL);
-                lu_object_ops(o)->ldo_object_free(o);
+                lu_object_ops(o)->ldo_object_free(ctx, o);
         }
 }
 
-void lu_site_purge(struct lu_site *s, int nr)
+void lu_site_purge(struct lu_context *ctx, struct lu_site *s, int nr)
 {
         struct list_head         dispose;
         struct lu_object_header *h;
@@ -144,13 +145,14 @@ void lu_site_purge(struct lu_site *s, int nr)
                 h = container_of(dispose.next,
                                  struct lu_object_header, loh_lru);
                 list_del_init(&h->loh_lru);
-                lu_object_free(lu_object_top(h));
+                lu_object_free(ctx, lu_object_top(h));
                 s->ls_stats.s_lru_purged ++;
         }
 }
 EXPORT_SYMBOL(lu_site_purge);
 
-int lu_object_print(struct seq_file *f, const struct lu_object *o)
+int lu_object_print(struct lu_context *ctx,
+                    struct seq_file *f, const struct lu_object *o)
 {
         static char ruler[] = "........................................";
         const struct lu_object *scan;
@@ -165,7 +167,7 @@ int lu_object_print(struct seq_file *f, const struct lu_object *o)
                         break;
                 LASSERT(lu_object_ops(scan)->ldo_object_print != NULL);
                 nob += seq_printf(f, "%*.*s", depth, depth, ruler);
-                nob += lu_object_ops(scan)->ldo_object_print(f, scan);
+                nob += lu_object_ops(scan)->ldo_object_print(ctx, f, scan);
                 nob += seq_printf(f, "\n");
         }
         return nob;
@@ -234,7 +236,7 @@ struct lu_object *lu_object_find(struct lu_context *ctxt, struct lu_site *s,
                 s->ls_stats.s_cache_race ++;
         spin_unlock(&s->ls_guard);
         if (o != NULL)
-                lu_object_free(o);
+                lu_object_free(ctxt, o);
         return shadow;
 }
 EXPORT_SYMBOL(lu_object_find);
@@ -382,3 +384,117 @@ struct lu_object *lu_object_locate(struct lu_object_header *h,
         return NULL;
 }
 EXPORT_SYMBOL(lu_object_locate);
+
+enum {
+        /*
+         * Maximal number of tld slots.
+         */
+        LU_CONTEXT_KEY_NR = 16
+};
+
+static struct lu_context_key *keys[LU_CONTEXT_KEY_NR] = { NULL, };
+
+static int keys_nr = 0;
+static spinlock_t keys_guard = SPIN_LOCK_UNLOCKED;
+static int key_registration_over = 0;
+
+int lu_context_key_register(struct lu_context_key *key)
+{
+        int result;
+
+        if (!key_registration_over) {
+                spin_lock(&keys_guard);
+                if (keys_nr < ARRAY_SIZE(keys)) {
+                        key->lct_index = keys_nr;
+                        keys[keys_nr] = key;
+                        keys_nr++;
+                        result = 0;
+                } else
+                        result = -ENFILE;
+                spin_unlock(&keys_guard);
+        } else {
+                CERROR("Too late to register a key.\n");
+                result = -EBUSY;
+        }
+        return result;
+}
+EXPORT_SYMBOL(lu_context_key_register);
+
+void *lu_context_key_get(struct lu_context *ctx, struct lu_context_key *key)
+{
+        return ctx->lc_value[key->lct_index];
+}
+EXPORT_SYMBOL(lu_context_key_get);
+
+static void keys_fini(struct lu_context *ctx)
+{
+        int i;
+
+        if (ctx->lc_value != NULL) {
+                for (i = 0; i < keys_nr; ++i) {
+                        if (ctx->lc_value[i] != NULL) {
+                                LASSERT(keys[i] != NULL);
+                                LASSERT(keys[i]->lct_fini != NULL);
+
+                                keys[i]->lct_fini(ctx, ctx->lc_value[i]);
+                                ctx->lc_value[i] = NULL;
+                        }
+                }
+                OBD_FREE(ctx->lc_value, keys_nr * sizeof ctx->lc_value[0]);
+                ctx->lc_value = NULL;
+        }
+}
+
+static int keys_init(struct lu_context *ctx)
+{
+        int i;
+        int result;
+
+        key_registration_over = 1;
+
+        OBD_ALLOC(ctx->lc_value, keys_nr * sizeof ctx->lc_value[0]);
+        if (ctx->lc_value != NULL) {
+                for (i = 0; i < ARRAY_SIZE(keys); ++i) {
+                        if (keys[i] != NULL) {
+                                void *value;
+
+                                LASSERT(keys[i]->lct_init != NULL);
+                                LASSERT(keys[i]->lct_index == i);
+
+                                value = keys[i]->lct_init(ctx);
+                                if (IS_ERR(value)) {
+                                        keys_fini(ctx);
+                                        return PTR_ERR(value);
+                                }
+                                ctx->lc_value[i] = value;
+                        }
+                }
+                result = 0;
+        } else
+                result = -ENOMEM;
+        return result;
+}
+
+int lu_context_init(struct lu_context *ctx)
+{
+        memset(ctx, 0, sizeof *ctx);
+        keys_init(ctx);
+        return 0;
+}
+EXPORT_SYMBOL(lu_context_init);
+
+void lu_context_fini(struct lu_context *ctx)
+{
+        keys_fini(ctx);
+}
+EXPORT_SYMBOL(lu_context_fini);
+
+void lu_context_enter(struct lu_context *ctx)
+{
+}
+EXPORT_SYMBOL(lu_context_enter);
+
+void lu_context_exit(struct lu_context *ctx)
+{
+}
+EXPORT_SYMBOL(lu_context_exit);
index 4823ea3..eb324cb 100644 (file)
 
 #include "osd_internal.h"
 
-static int   osd_root_get      (struct dt_device *dev, struct lu_fid *f);
-static int   osd_statfs        (struct dt_device *dev, struct kstatfs *sfs);
+static int   osd_root_get      (struct lu_context *ctxt,
+                                struct dt_device *dev, struct lu_fid *f);
+static int   osd_statfs        (struct lu_context *ctxt,
+                                struct dt_device *dev, struct kstatfs *sfs);
 
 static int   lu_device_is_osd  (const struct lu_device *d);
 static void  osd_mod_exit      (void) __exit;
 static int   osd_mod_init      (void) __init;
-static void *osd_thread_init   (struct ptlrpc_thread *t);
-static void  osd_thread_fini   (struct ptlrpc_thread *t, void *data);
 static int   osd_type_init     (struct lu_device_type *t);
 static void  osd_type_fini     (struct lu_device_type *t);
 static int   osd_object_init   (struct lu_context *ctxt, struct lu_object *l);
 static void  osd_object_release(struct lu_context *ctxt, struct lu_object *l);
-static int   osd_object_print  (struct seq_file *f, const struct lu_object *o);
+static int   osd_object_print  (struct lu_context *ctx,
+                                struct seq_file *f, const struct lu_object *o);
 static void  osd_device_free   (struct lu_device *m);
 static void  osd_device_fini   (struct lu_device *d);
 static int   osd_device_init   (struct lu_device *d, const char *conf);
 
-static struct lu_object  *osd_object_alloc(struct lu_device *d);
 static struct osd_object *osd_obj         (const struct lu_object *o);
 static struct osd_device *osd_dev         (const struct lu_device *d);
 static struct osd_device *osd_dt_dev      (const struct dt_device *d);
 static struct lu_device  *osd_device_alloc(struct lu_device_type *t,
                                            struct lustre_cfg *cfg);
+static struct lu_object  *osd_object_alloc(struct lu_context *ctx,
+                                           struct lu_device *d);
 
 
 static struct lu_device_type_operations osd_device_type_ops;
 static struct lu_device_type            osd_device_type;
-static struct ptlrpc_thread_key         osd_thread_key;
 static struct obd_ops                   osd_obd_device_ops;
 static struct lprocfs_vars              lprocfs_osd_module_vars[];
 static struct lprocfs_vars              lprocfs_osd_obd_vars[];
@@ -97,7 +98,8 @@ static struct lu_fid *lu_inode_get_fid(const struct inode *inode)
 /*
  * DT methods.
  */
-static int osd_root_get(struct dt_device *dev, struct lu_fid *f)
+static int osd_root_get(struct lu_context *ctx,
+                        struct dt_device *dev, struct lu_fid *f)
 {
         struct osd_device *od = osd_dt_dev(dev);
 
@@ -110,7 +112,8 @@ static int osd_root_get(struct dt_device *dev, struct lu_fid *f)
  * OSD object methods.
  */
 
-static struct lu_object *osd_object_alloc(struct lu_device *d)
+static struct lu_object *osd_object_alloc(struct lu_context *ctx,
+                                          struct lu_device *d)
 {
         struct osd_object *mo;
 
@@ -125,7 +128,8 @@ static struct lu_object *osd_object_alloc(struct lu_device *d)
                 return NULL;
 }
 
-static int osd_getattr(struct inode *inode, struct lu_attr *attr)
+static int osd_getattr(struct lu_context *ctx,
+                       struct inode *inode, struct lu_attr *attr)
 {
         //attr->la_atime      = inode->i_atime;
         //attr->la_mtime      = inode->i_mtime;
@@ -148,7 +152,8 @@ static int osd_object_init(struct lu_context *ctxt, struct lu_object *l)
 
         /* fill lu_attr in ctxt */
         //XXX temporary hack for proto only
-        osd_getattr(d->od_mount->lmi_sb->s_root->d_inode, &ctxt->lc_attr);
+        osd_getattr(ctxt,
+                    d->od_mount->lmi_sb->s_root->d_inode, &ctxt->lc_attr);
 
         /*
          * use object index to locate dentry/inode by fid.
@@ -156,7 +161,7 @@ static int osd_object_init(struct lu_context *ctxt, struct lu_object *l)
         return 0;
 }
 
-static void osd_object_free(struct lu_object *l)
+static void osd_object_free(struct lu_context *ctx, struct lu_object *l)
 {
         struct osd_object  *o = osd_obj(l);
 
@@ -164,7 +169,7 @@ static void osd_object_free(struct lu_object *l)
                 dput(o->oo_dentry);
 }
 
-static void osd_object_delete(struct lu_object *l)
+static void osd_object_delete(struct lu_context *ctx, struct lu_object *l)
 {
 }
 
@@ -181,7 +186,8 @@ static void osd_object_release(struct lu_context *ctxt, struct lu_object *l)
                 set_bit(LU_OBJECT_HEARD_BANSHEE, &l->lo_header->loh_flags);
 }
 
-static int osd_object_print(struct seq_file *f, const struct lu_object *l)
+static int osd_object_print(struct lu_context *ctx,
+                            struct seq_file *f, const struct lu_object *l)
 {
         struct osd_object  *o = osd_obj(l);
 
@@ -189,32 +195,8 @@ static int osd_object_print(struct seq_file *f, const struct lu_object *l)
                           o, o->oo_dentry);
 }
 
-struct osd_thread_info {
-};
-
-/*
- * ptlrpc_key call-backs.
- */
-static void *osd_thread_init(struct ptlrpc_thread *t)
-{
-        struct osd_thread_info *info;
-
-        return OBD_ALLOC_PTR(info) ? : ERR_PTR(-ENOMEM);
-}
-
-static void osd_thread_fini(struct ptlrpc_thread *t, void *data)
-{
-        struct osd_thread_info *info = data;
-        OBD_FREE_PTR(info);
-}
-
-
-static struct ptlrpc_thread_key osd_thread_key = {
-        .ptk_init = osd_thread_init,
-        .ptk_fini = osd_thread_fini
-};
-
-static int osd_config(struct dt_device *d, const char *name,
+static int osd_config(struct lu_context *ctx,
+                      struct dt_device *d, const char *name,
                       void *buf, int size, int mode)
 {
        struct osd_device *osd = dt2osd_dev(d);
@@ -234,7 +216,8 @@ static int osd_config(struct dt_device *d, const char *name,
         RETURN (result);
 }
 
-static int osd_statfs(struct dt_device *d, struct kstatfs *sfs)
+static int osd_statfs(struct lu_context *ctx,
+                      struct dt_device *d, struct kstatfs *sfs)
 {
        struct osd_device *osd = dt2osd_dev(d);
         struct super_block *sb = osd->od_mount->lmi_sb;
@@ -277,7 +260,7 @@ static struct dt_device_operations osd_dt_ops = {
  */
 static int osd_type_init(struct lu_device_type *t)
 {
-        return ptlrpc_thread_key_register(&osd_thread_key);
+        return 0;
 }
 
 static void osd_type_fini(struct lu_device_type *t)