Whamcloud - gitweb
Branch HEAD
authoranserper <anserper>
Thu, 11 Oct 2007 07:05:46 +0000 (07:05 +0000)
committeranserper <anserper>
Thu, 11 Oct 2007 07:05:46 +0000 (07:05 +0000)
b=13377
i=yury
i=nikita

lustre/cmm/cmm_device.c
lustre/cmm/mdc_device.c
lustre/fid/fid_handler.c
lustre/fld/fld_handler.c
lustre/include/lu_object.h
lustre/mdd/mdd_device.c
lustre/mdt/mdt_handler.c
lustre/osd/osd_handler.c

index 05413d7..3dee060 100644 (file)
@@ -385,11 +385,7 @@ static void cmm_device_free(const struct lu_env *env, struct lu_device *d)
 /* context key constructor/destructor */
 LU_KEY_INIT_FINI(cmm, struct cmm_thread_info);
 
-static struct lu_context_key cmm_thread_key = {
-        .lct_tags = LCT_MD_THREAD,
-        .lct_init = cmm_key_init,
-        .lct_fini = cmm_key_fini
-};
+LU_CONTEXT_KEY_DEFINE(cmm, LCT_MD_THREAD);
 
 struct cmm_thread_info *cmm_env_info(const struct lu_env *env)
 {
@@ -400,16 +396,7 @@ struct cmm_thread_info *cmm_env_info(const struct lu_env *env)
         return info;
 }
 
-static int cmm_type_init(struct lu_device_type *t)
-{
-        LU_CONTEXT_KEY_INIT(&cmm_thread_key);
-        return lu_context_key_register(&cmm_thread_key);
-}
-
-static void cmm_type_fini(struct lu_device_type *t)
-{
-        lu_context_key_degister(&cmm_thread_key);
-}
+LU_TYPE_INIT_FINI(cmm, &cmm_thread_key);
 
 static int cmm_device_init(const struct lu_env *env, struct lu_device *d,
                            const char *name, struct lu_device *next)
index 8c0239d..6142f36 100644 (file)
@@ -292,22 +292,9 @@ void mdc_device_free(const struct lu_env *env, struct lu_device *ld)
 /* context key constructor/destructor */
 LU_KEY_INIT_FINI(mdc, struct mdc_thread_info);
 
-struct lu_context_key mdc_thread_key = {
-        .lct_tags = LCT_MD_THREAD|LCT_CL_THREAD,
-        .lct_init = mdc_key_init,
-        .lct_fini = mdc_key_fini
-};
-
-int mdc_type_init(struct lu_device_type *ldt)
-{
-        LU_CONTEXT_KEY_INIT(&mdc_thread_key);
-        return lu_context_key_register(&mdc_thread_key);
-}
+LU_CONTEXT_KEY_DEFINE(mdc, LCT_MD_THREAD|LCT_CL_THREAD);
 
-void mdc_type_fini(struct lu_device_type *ldt)
-{
-        lu_context_key_degister(&mdc_thread_key);
-}
+LU_TYPE_INIT_FINI(mdc, &mdc_thread_key);
 
 static struct lu_device_type_operations mdc_device_type_ops = {
         .ldto_init = mdc_type_init,
index 45e1ebb..0522eb8 100644 (file)
@@ -358,11 +358,7 @@ static int seq_req_handle(struct ptlrpc_request *req,
 
 LU_KEY_INIT_FINI(seq, struct seq_thread_info);
 
-struct lu_context_key seq_thread_key = {
-        .lct_tags = LCT_MD_THREAD,
-        .lct_init = seq_key_init,
-        .lct_fini = seq_key_fini
-};
+LU_CONTEXT_KEY_DEFINE(seq, LCT_MD_THREAD);
 
 static void seq_thread_info_init(struct ptlrpc_request *req,
                                  struct seq_thread_info *info)
index 5f902d2..ec52b5c 100644 (file)
 
 LU_KEY_INIT_FINI(fld, struct fld_thread_info);
 
-struct lu_context_key fld_thread_key = {
-        .lct_tags = LCT_MD_THREAD|LCT_DT_THREAD,
-        .lct_init = fld_key_init,
-        .lct_fini = fld_key_fini
-};
+LU_CONTEXT_KEY_DEFINE(fld, LCT_MD_THREAD|LCT_DT_THREAD);
 
 cfs_proc_dir_entry_t *fld_type_proc_dir = NULL;
 
index 43947a6..698caf1 100644 (file)
@@ -23,6 +23,8 @@
 #ifndef __LUSTRE_LU_OBJECT_H
 #define __LUSTRE_LU_OBJECT_H
 
+#include <stdarg.h>
+
 /*
  * struct lu_fid
  */
@@ -996,12 +998,19 @@ struct lu_context_key {
         LU_KEY_INIT(mod,type);        \
         LU_KEY_FINI(mod,type)
 
+#define LU_CONTEXT_KEY_DEFINE(mod, tags)                \
+        struct lu_context_key mod##_thread_key = {      \
+                .lct_tags = tags,                       \
+                .lct_init = mod##_key_init,             \
+                .lct_fini = mod##_key_fini              \
+        }
 
 #define LU_CONTEXT_KEY_INIT(key)                        \
 do {                                                    \
         (key)->lct_owner = THIS_MODULE;                 \
 } while (0)
 
+
 /*
  * Register new key.
  */
@@ -1010,6 +1019,73 @@ int   lu_context_key_register(struct lu_context_key *key);
  * Deregister key.
  */
 void  lu_context_key_degister(struct lu_context_key *key);
+
+#define LU_KEY_REGISTER_GENERIC(mod)                                             \
+        static int mod##_key_register_generic(struct lu_context_key *k, ...)     \
+        {                                                                        \
+                struct lu_context_key* key = k;                                  \
+                va_list args;                                                    \
+                int result;                                                      \
+                                                                                 \
+                va_start(args, k);                                               \
+                                                                                 \
+                do {                                                             \
+                        LU_CONTEXT_KEY_INIT(key);                                \
+                        result = lu_context_key_register(key);                   \
+                        if (result)                                              \
+                                break;                                           \
+                        key = va_arg(args, struct lu_context_key*);              \
+                } while (key != NULL);                                           \
+                                                                                 \
+                va_end(args);                                                    \
+                                                                                 \
+                if (result) {                                                    \
+                        va_start(args, k);                                       \
+                        while (k != key) {                                       \
+                                lu_context_key_degister(k);                      \
+                                k = va_arg(args, struct lu_context_key*);        \
+                        }                                                        \
+                        va_end(args);                                            \
+                }                                                                \
+                                                                                 \
+                return result;                                                   \
+        }
+
+#define LU_KEY_DEGISTER_GENERIC(mod)                                             \
+        static void mod##_key_degister_generic(struct lu_context_key *k, ...)    \
+        {                                                                        \
+                va_list args;                                                    \
+                                                                                 \
+                va_start(args, k);                                               \
+                                                                                 \
+                do {                                                             \
+                        lu_context_key_degister(k);                              \
+                        k = va_arg(args, struct lu_context_key*);                \
+                } while (k != NULL);                                             \
+                                                                                 \
+                va_end(args);                                                    \
+        }
+
+#define LU_TYPE_INIT(mod, ...)                                         \
+        LU_KEY_REGISTER_GENERIC(mod)                                   \
+        static int mod##_type_init(struct lu_device_type *t)           \
+        {                                                              \
+                return mod##_key_register_generic(__VA_ARGS__, NULL);  \
+        }                                                              \
+        struct __##mod##_dummy_type_init {;}
+
+#define LU_TYPE_FINI(mod, ...)                                         \
+        LU_KEY_DEGISTER_GENERIC(mod)                                   \
+        static void mod##_type_fini(struct lu_device_type *t)          \
+        {                                                              \
+                mod##_key_degister_generic(__VA_ARGS__, NULL);         \
+        }                                                              \
+        struct __##mod##_dummy_type_fini {;}
+
+#define LU_TYPE_INIT_FINI(mod, ...)                                 \
+        LU_TYPE_INIT(mod, __VA_ARGS__);                             \
+        LU_TYPE_FINI(mod, __VA_ARGS__)
+
 /*
  * Return value associated with key @key in context @ctx.
  */
index 7f776ce..f7ba9e7 100644 (file)
@@ -361,29 +361,7 @@ struct md_capainfo *md_capainfo(const struct lu_env *env)
 }
 EXPORT_SYMBOL(md_capainfo);
 
-static int mdd_type_init(struct lu_device_type *t)
-{
-        int result;
-
-        LU_CONTEXT_KEY_INIT(&mdd_thread_key);
-        result = lu_context_key_register(&mdd_thread_key);
-        if (result == 0) {
-                LU_CONTEXT_KEY_INIT(&mdd_ucred_key);
-                result = lu_context_key_register(&mdd_ucred_key);
-        }
-        if (result == 0) {
-                LU_CONTEXT_KEY_INIT(&mdd_capainfo_key);
-                result = lu_context_key_register(&mdd_capainfo_key);
-        }
-        return result;
-}
-
-static void mdd_type_fini(struct lu_device_type *t)
-{
-        lu_context_key_degister(&mdd_capainfo_key);
-        lu_context_key_degister(&mdd_ucred_key);
-        lu_context_key_degister(&mdd_thread_key);
-}
+LU_TYPE_INIT_FINI(mdd, &mdd_thread_key, &mdd_ucred_key, &mdd_capainfo_key);
 
 struct md_device_operations mdd_ops = {
         .mdo_statfs         = mdd_statfs,
@@ -424,11 +402,7 @@ static void mdd_key_fini(const struct lu_context *ctx,
         OBD_FREE_PTR(info);
 }
 
-struct lu_context_key mdd_thread_key = {
-        .lct_tags = LCT_MD_THREAD,
-        .lct_init = mdd_key_init,
-        .lct_fini = mdd_key_fini
-};
+LU_CONTEXT_KEY_DEFINE(mdd, LCT_MD_THREAD);
 
 struct lprocfs_vars lprocfs_mdd_obd_vars[] = {
         { 0 }
index 4b781f6..54fd4ab 100644 (file)
@@ -4545,11 +4545,7 @@ static struct lu_device *mdt_device_alloc(const struct lu_env *env,
  */
 LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
 
-struct lu_context_key mdt_thread_key = {
-        .lct_tags = LCT_MD_THREAD,
-        .lct_init = mdt_key_init,
-        .lct_fini = mdt_key_fini
-};
+LU_CONTEXT_KEY_DEFINE(mdt, LCT_MD_THREAD);
 
 LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info);
 
@@ -4564,24 +4560,7 @@ struct md_ucred *mdt_ucred(const struct mdt_thread_info *info)
         return md_ucred(info->mti_env);
 }
 
-static int mdt_type_init(struct lu_device_type *t)
-{
-        int rc;
-
-        LU_CONTEXT_KEY_INIT(&mdt_thread_key);
-        rc = lu_context_key_register(&mdt_thread_key);
-        if (rc == 0) {
-                LU_CONTEXT_KEY_INIT(&mdt_txn_key);
-                rc = lu_context_key_register(&mdt_txn_key);
-        }
-        return rc;
-}
-
-static void mdt_type_fini(struct lu_device_type *t)
-{
-        lu_context_key_degister(&mdt_thread_key);
-        lu_context_key_degister(&mdt_txn_key);
-}
+LU_TYPE_INIT_FINI(mdt, &mdt_thread_key, &mdt_txn_key);
 
 static struct lu_device_type_operations mdt_device_type_ops = {
         .ldto_init = mdt_type_init,
index 39ac11b..8361deb 100644 (file)
@@ -2207,16 +2207,8 @@ static struct dt_index_operations osd_index_compat_ops = {
 /*
  * OSD device type methods
  */
-static int osd_type_init(struct lu_device_type *t)
-{
-        LU_CONTEXT_KEY_INIT(&osd_key);
-        return lu_context_key_register(&osd_key);
-}
-
-static void osd_type_fini(struct lu_device_type *t)
-{
-        lu_context_key_degister(&osd_key);
-}
+LU_TYPE_INIT_FINI(osd, &osd_key);
 
 static struct lu_context_key osd_key = {
         .lct_tags = LCT_DT_THREAD | LCT_MD_THREAD,