Whamcloud - gitweb
patches related to bug 13377 (CMD small fixes), 2+4 patch and fid_unpack patch
authoranserper <anserper>
Mon, 24 Sep 2007 16:23:18 +0000 (16:23 +0000)
committeranserper <anserper>
Mon, 24 Sep 2007 16:23:18 +0000 (16:23 +0000)
18 files changed:
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/include/lustre/lustre_idl.h
lustre/include/lustre_mds.h
lustre/mdd/mdd_device.c
lustre/mdd/mdd_dir.c
lustre/mdd/mdd_lov.c
lustre/mdd/mdd_object.c
lustre/mds/mds_open.c
lustre/mdt/mdt_handler.c
lustre/mdt/mdt_open.c
lustre/obdclass/dt_object.c
lustre/obdclass/lu_object.c
lustre/obdclass/lu_time.c
lustre/osd/osd_handler.c

index 717271a..05413d7 100644 (file)
@@ -383,24 +383,7 @@ static void cmm_device_free(const struct lu_env *env, struct lu_device *d)
 }
 
 /* context key constructor/destructor */
 }
 
 /* context key constructor/destructor */
-static void *cmm_key_init(const struct lu_context *ctx,
-                          struct lu_context_key *key)
-{
-        struct cmm_thread_info *info;
-
-        CLASSERT(CFS_PAGE_SIZE >= sizeof *info);
-        OBD_ALLOC_PTR(info);
-        if (info == NULL)
-                info = ERR_PTR(-ENOMEM);
-        return info;
-}
-
-static void cmm_key_fini(const struct lu_context *ctx,
-                         struct lu_context_key *key, void *data)
-{
-        struct cmm_thread_info *info = data;
-        OBD_FREE_PTR(info);
-}
+LU_KEY_INIT_FINI(cmm, struct cmm_thread_info);
 
 static struct lu_context_key cmm_thread_key = {
         .lct_tags = LCT_MD_THREAD,
 
 static struct lu_context_key cmm_thread_key = {
         .lct_tags = LCT_MD_THREAD,
index 480a73a..8c0239d 100644 (file)
@@ -290,25 +290,7 @@ void mdc_device_free(const struct lu_env *env, struct lu_device *ld)
 }
 
 /* context key constructor/destructor */
 }
 
 /* context key constructor/destructor */
-
-static void *mdc_key_init(const struct lu_context *ctx,
-                          struct lu_context_key *key)
-{
-        struct mdc_thread_info *info;
-
-        CLASSERT(CFS_PAGE_SIZE >= sizeof *info);
-        OBD_ALLOC_PTR(info);
-        if (info == NULL)
-                info = ERR_PTR(-ENOMEM);
-        return info;
-}
-
-static void mdc_key_fini(const struct lu_context *ctx,
-                         struct lu_context_key *key, void *data)
-{
-        struct mdc_thread_info *info = data;
-        OBD_FREE_PTR(info);
-}
+LU_KEY_INIT_FINI(mdc, struct mdc_thread_info);
 
 struct lu_context_key mdc_thread_key = {
         .lct_tags = LCT_MD_THREAD|LCT_CL_THREAD,
 
 struct lu_context_key mdc_thread_key = {
         .lct_tags = LCT_MD_THREAD|LCT_CL_THREAD,
index 0aa64b2..45e1ebb 100644 (file)
@@ -356,27 +356,7 @@ static int seq_req_handle(struct ptlrpc_request *req,
         RETURN(rc);
 }
 
         RETURN(rc);
 }
 
-static void *seq_key_init(const struct lu_context *ctx,
-                          struct lu_context_key *key)
-{
-        struct seq_thread_info *info;
-
-        /*
-         * check that no high order allocations are incurred.
-         */
-        CLASSERT(CFS_PAGE_SIZE >= sizeof *info);
-        OBD_ALLOC_PTR(info);
-        if (info == NULL)
-                info = ERR_PTR(-ENOMEM);
-        return info;
-}
-
-static void seq_key_fini(const struct lu_context *ctx,
-                         struct lu_context_key *key, void *data)
-{
-        struct seq_thread_info *info = data;
-        OBD_FREE_PTR(info);
-}
+LU_KEY_INIT_FINI(seq, struct seq_thread_info);
 
 struct lu_context_key seq_thread_key = {
         .lct_tags = LCT_MD_THREAD,
 
 struct lu_context_key seq_thread_key = {
         .lct_tags = LCT_MD_THREAD,
index d34ec0c..5f902d2 100644 (file)
 #include "fld_internal.h"
 
 #ifdef __KERNEL__
 #include "fld_internal.h"
 
 #ifdef __KERNEL__
-static void *fld_key_init(const struct lu_context *ctx,
-                          struct lu_context_key *key)
-{
-        struct fld_thread_info *info;
-        ENTRY;
-
-        OBD_ALLOC_PTR(info);
-        if (info == NULL)
-                info = ERR_PTR(-ENOMEM);
-        RETURN(info);
-}
 
 
-static void fld_key_fini(const struct lu_context *ctx,
-                         struct lu_context_key *key, void *data)
-{
-        struct fld_thread_info *info = data;
-        ENTRY;
-        OBD_FREE_PTR(info);
-        EXIT;
-}
+LU_KEY_INIT_FINI(fld, struct fld_thread_info);
 
 struct lu_context_key fld_thread_key = {
         .lct_tags = LCT_MD_THREAD|LCT_DT_THREAD,
 
 struct lu_context_key fld_thread_key = {
         .lct_tags = LCT_MD_THREAD|LCT_DT_THREAD,
index e9761de..e07dfbb 100644 (file)
@@ -966,6 +966,37 @@ struct lu_context_key {
         struct module *lct_owner;
 };
 
         struct module *lct_owner;
 };
 
+#define LU_KEY_INIT(mod, type)                                    \
+        static void* mod##_key_init(const struct lu_context *ctx, \
+                                    struct lu_context_key *key)   \
+        {                                                         \
+                type *value;                                      \
+                                                                  \
+                CLASSERT(CFS_PAGE_SIZE >= sizeof (*value));       \
+                                                                  \
+                OBD_ALLOC_PTR(value);                             \
+                if (value == NULL)                                \
+                        value = ERR_PTR(-ENOMEM);                 \
+                                                                  \
+                return value;                                     \
+        }                                                         \
+       struct __##mod##__dummy_init {;} /* semicolon catcher */
+
+#define LU_KEY_FINI(mod, type)                                              \
+        static void mod##_key_fini(const struct lu_context *ctx,            \
+                                    struct lu_context_key *key, void* data) \
+        {                                                                   \
+               type *info = data;                                          \
+                                                                            \
+               OBD_FREE_PTR(info);                                         \
+       }                                                                   \
+       struct __##mod##__dummy_fini {;} /* semicolon catcher */
+
+#define LU_KEY_INIT_FINI(mod, type)   \
+       LU_KEY_INIT(mod,type);        \
+       LU_KEY_FINI(mod,type);
+
+
 #define LU_CONTEXT_KEY_INIT(key)                        \
 do {                                                    \
         (key)->lct_owner = THIS_MODULE;                 \
 #define LU_CONTEXT_KEY_INIT(key)                        \
 do {                                                    \
         (key)->lct_owner = THIS_MODULE;                 \
index 93cd4b8..bc2cfd2 100644 (file)
@@ -289,7 +289,7 @@ struct lu_fid_pack {
 
 void fid_pack(struct lu_fid_pack *pack, const struct lu_fid *fid,
               struct lu_fid *befider);
 
 void fid_pack(struct lu_fid_pack *pack, const struct lu_fid *fid,
               struct lu_fid *befider);
-void fid_unpack(const struct lu_fid_pack *pack, struct lu_fid *fid);
+int  fid_unpack(const struct lu_fid_pack *pack, struct lu_fid *fid);
 
 /* __KERNEL__ */
 #endif
 
 /* __KERNEL__ */
 #endif
index b051786..e388fb8 100644 (file)
@@ -115,4 +115,10 @@ void mds_objids_from_lmm(obd_id *, struct lov_mds_md *, struct lov_desc *);
 #define MDD_OBD_TYPE    "mds"
 #define MDD_OBD_PROFILE "lustre-MDT0000"
 
 #define MDD_OBD_TYPE    "mds"
 #define MDD_OBD_PROFILE "lustre-MDT0000"
 
+static inline int md_should_create(__u32 flags)
+{
+       return !(flags & MDS_OPEN_DELAY_CREATE ||
+               !(flags & FMODE_WRITE));
+}
+
 #endif
 #endif
index 0ad9650..7f776ce 100644 (file)
@@ -329,24 +329,7 @@ static struct obd_ops mdd_obd_device_ops = {
         .o_owner = THIS_MODULE
 };
 
         .o_owner = THIS_MODULE
 };
 
-static void *mdd_ucred_key_init(const struct lu_context *ctx,
-                                struct lu_context_key *key)
-{
-        struct md_ucred *uc;
-
-        OBD_ALLOC_PTR(uc);
-        if (uc == NULL)
-                uc = ERR_PTR(-ENOMEM);
-        return uc;
-}
-
-static void mdd_ucred_key_fini(const struct lu_context *ctx,
-                             struct lu_context_key *key, void *data)
-{
-        struct md_ucred *uc = data;
-        if (!IS_ERR(uc))
-                OBD_FREE_PTR(uc);
-}
+LU_KEY_INIT_FINI(mdd_ucred, struct md_ucred);
 
 static struct lu_context_key mdd_ucred_key = {
         .lct_tags = LCT_SESSION,
 
 static struct lu_context_key mdd_ucred_key = {
         .lct_tags = LCT_SESSION,
@@ -361,24 +344,7 @@ struct md_ucred *md_ucred(const struct lu_env *env)
 }
 EXPORT_SYMBOL(md_ucred);
 
 }
 EXPORT_SYMBOL(md_ucred);
 
-static void *mdd_capainfo_key_init(const struct lu_context *ctx,
-                                   struct lu_context_key *key)
-{
-        struct md_capainfo *ci;
-
-        OBD_ALLOC_PTR(ci);
-        if (ci == NULL)
-                ci = ERR_PTR(-ENOMEM);
-        return ci;
-}
-
-static void mdd_capainfo_key_fini(const struct lu_context *ctx,
-                                  struct lu_context_key *key, void *data)
-{
-        struct md_capainfo *ci = data;
-        if (!IS_ERR(ci))
-                OBD_FREE_PTR(ci);
-}
+LU_KEY_INIT_FINI(mdd_capainfo, struct md_capainfo);
 
 struct lu_context_key mdd_capainfo_key = {
         .lct_tags = LCT_SESSION,
 
 struct lu_context_key mdd_capainfo_key = {
         .lct_tags = LCT_SESSION,
@@ -445,16 +411,7 @@ static struct lu_device_type mdd_device_type = {
         .ldt_ctx_tags = LCT_MD_THREAD
 };
 
         .ldt_ctx_tags = LCT_MD_THREAD
 };
 
-static void *mdd_key_init(const struct lu_context *ctx,
-                          struct lu_context_key *key)
-{
-        struct mdd_thread_info *info;
-
-        OBD_ALLOC_PTR(info);
-        if (info == NULL)
-                info = ERR_PTR(-ENOMEM);
-        return info;
-}
+LU_KEY_INIT(mdd, struct mdd_thread_info);
 
 static void mdd_key_fini(const struct lu_context *ctx,
                          struct lu_context_key *key, void *data)
 
 static void mdd_key_fini(const struct lu_context *ctx,
                          struct lu_context_key *key, void *data)
index b20bb9c..dc24003 100644 (file)
@@ -979,8 +979,7 @@ static int mdd_create_data(const struct lu_env *env, struct md_object *pobj,
         if (rc)
                 RETURN(rc);
 
         if (rc)
                 RETURN(rc);
 
-        if (spec->sp_cr_flags & MDS_OPEN_DELAY_CREATE ||
-            !(spec->sp_cr_flags & FMODE_WRITE))
+        if (!md_should_create(spec->sp_cr_flags))
                 RETURN(0);
 
         rc = mdd_lov_create(env, mdd, mdd_pobj, son, &lmm, &lmm_size,
                 RETURN(0);
 
         rc = mdd_lov_create(env, mdd, mdd_pobj, son, &lmm, &lmm_size,
@@ -1064,7 +1063,7 @@ __mdd_lookup(const struct lu_env *env, struct md_object *pobj,
                                                  (struct dt_rec *)pack, key,
                                                  mdd_object_capa(env, mdd_obj));
                 if (rc == 0)
                                                  (struct dt_rec *)pack, key,
                                                  mdd_object_capa(env, mdd_obj));
                 if (rc == 0)
-                        fid_unpack(pack, fid);
+                        rc = fid_unpack(pack, fid);
         } else
                 rc = -ENOTDIR;
 
         } else
                 rc = -ENOTDIR;
 
index 98e9018..687137a 100644 (file)
@@ -409,8 +409,7 @@ int mdd_lov_create(const struct lu_env *env, struct mdd_device *mdd,
         int                    rc = 0;
         ENTRY;
 
         int                    rc = 0;
         ENTRY;
 
-        if (create_flags & MDS_OPEN_DELAY_CREATE ||
-            !(create_flags & FMODE_WRITE))
+        if (!md_should_create(create_flags))
                 RETURN(0);
 
         oti_init(oti, NULL);
                 RETURN(0);
 
         oti_init(oti, NULL);
index b45d37b..be12358 100644 (file)
@@ -1314,7 +1314,9 @@ static int mdd_dir_page_build(const struct lu_env *env, int first,
                 len  = iops->key_size(env, it);
 
                 pack = (struct lu_fid_pack *)iops->rec(env, it);
                 len  = iops->key_size(env, it);
 
                 pack = (struct lu_fid_pack *)iops->rec(env, it);
-                fid_unpack(pack, fid);
+                result = fid_unpack(pack, fid);
+                if (result != 0)
+                        break;
 
                 recsize = (sizeof(*ent) + len + 3) & ~3;
                 hash = iops->store(env, it);
 
                 recsize = (sizeof(*ent) + len + 3) & ~3;
                 hash = iops->store(env, it);
index 73da5aa..5136883 100644 (file)
@@ -320,8 +320,7 @@ static int mds_create_objects(struct ptlrpc_request *req, int offset,
 
         if (!S_ISREG(inode->i_mode))
                 RETURN(0);
 
         if (!S_ISREG(inode->i_mode))
                 RETURN(0);
-        if (rec->ur_flags & MDS_OPEN_DELAY_CREATE ||
-            !(rec->ur_flags & FMODE_WRITE))
+        if (!md_should_create(rec->ur_flags))
                 RETURN(0);
 
         body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body));
                 RETURN(0);
 
         body = lustre_msg_buf(req->rq_repmsg, DLM_REPLY_REC_OFF, sizeof(*body));
index f4c80ee..b6f9649 100644 (file)
@@ -4542,27 +4542,7 @@ static struct lu_device *mdt_device_alloc(const struct lu_env *env,
 /*
  * context key constructor/destructor
  */
 /*
  * context key constructor/destructor
  */
-static void *mdt_key_init(const struct lu_context *ctx,
-                          struct lu_context_key *key)
-{
-        struct mdt_thread_info *info;
-
-        /*
-         * check that no high order allocations are incurred.
-         */
-        CLASSERT(CFS_PAGE_SIZE >= sizeof *info);
-        OBD_ALLOC_PTR(info);
-        if (info == NULL)
-                info = ERR_PTR(-ENOMEM);
-        return info;
-}
-
-static void mdt_key_fini(const struct lu_context *ctx,
-                         struct lu_context_key *key, void *data)
-{
-        struct mdt_thread_info *info = data;
-        OBD_FREE_PTR(info);
-}
+LU_KEY_INIT_FINI(mdt, struct mdt_thread_info);
 
 struct lu_context_key mdt_thread_key = {
         .lct_tags = LCT_MD_THREAD,
 
 struct lu_context_key mdt_thread_key = {
         .lct_tags = LCT_MD_THREAD,
@@ -4570,28 +4550,7 @@ struct lu_context_key mdt_thread_key = {
         .lct_fini = mdt_key_fini
 };
 
         .lct_fini = mdt_key_fini
 };
 
-static void *mdt_txn_key_init(const struct lu_context *ctx,
-                              struct lu_context_key *key)
-{
-        struct mdt_txn_info *txi;
-
-        /*
-         * check that no high order allocations are incurred.
-         */
-        CLASSERT(CFS_PAGE_SIZE >= sizeof *txi);
-        OBD_ALLOC_PTR(txi);
-        if (txi == NULL)
-                txi = ERR_PTR(-ENOMEM);
-        memset(txi, 0, sizeof(*txi));
-        return txi;
-}
-
-static void mdt_txn_key_fini(const struct lu_context *ctx,
-                             struct lu_context_key *key, void *data)
-{
-        struct mdt_txn_info *txi = data;
-        OBD_FREE_PTR(txi);
-}
+LU_KEY_INIT_FINI(mdt_txn, struct mdt_txn_info);
 
 struct lu_context_key mdt_txn_key = {
         .lct_tags = LCT_TX_HANDLE,
 
 struct lu_context_key mdt_txn_key = {
         .lct_tags = LCT_TX_HANDLE,
index 0507d97..872bd1b 100644 (file)
@@ -98,8 +98,7 @@ static int mdt_create_data(struct mdt_thread_info *info,
         int rc;
         ENTRY;
 
         int rc;
         ENTRY;
 
-        if ((spec->sp_cr_flags & MDS_OPEN_DELAY_CREATE) ||
-            !(spec->sp_cr_flags & FMODE_WRITE))
+        if (!md_should_create(spec->sp_cr_flags))
                 RETURN(0);
 
         ma->ma_need = MA_INODE | MA_LOV;
                 RETURN(0);
 
         ma->ma_need = MA_INODE | MA_LOV;
index 07ea54b..404b29e 100644 (file)
@@ -157,7 +157,8 @@ static int dt_lookup(const struct lu_env *env, struct dt_object *dir,
         if (dt_try_as_dir(env, dir)) {
                 result = dir->do_index_ops->dio_lookup(env, dir, rec, key,
                                                        BYPASS_CAPA);
         if (dt_try_as_dir(env, dir)) {
                 result = dir->do_index_ops->dio_lookup(env, dir, rec, key,
                                                        BYPASS_CAPA);
-                fid_unpack(pack, fid);
+                if (result == 0)
+                        result = fid_unpack(pack, fid);
         } else
                 result = -ENOTDIR;
         return result;
         } else
                 result = -ENOTDIR;
         return result;
index ba17f7d..387f0f2 100644 (file)
@@ -290,23 +290,7 @@ struct lu_cdebug_data {
         struct lu_fid_pack lck_pack;
 };
 
         struct lu_fid_pack lck_pack;
 };
 
-static void *lu_global_key_init(const struct lu_context *ctx,
-                                struct lu_context_key *key)
-{
-        struct lu_cdebug_data *value;
-
-        OBD_ALLOC_PTR(value);
-        if (value == NULL)
-                value = ERR_PTR(-ENOMEM);
-        return value;
-}
-
-static void lu_global_key_fini(const struct lu_context *ctx,
-                               struct lu_context_key *key, void *data)
-{
-        struct lu_cdebug_data *value = data;
-        OBD_FREE_PTR(value);
-}
+LU_KEY_INIT_FINI(lu_global, struct lu_cdebug_data);
 
 /*
  * Key, holding temporary buffer. This key is registered very early by
 
 /*
  * Key, holding temporary buffer. This key is registered very early by
@@ -1183,8 +1167,11 @@ void fid_pack(struct lu_fid_pack *pack, const struct lu_fid *fid,
 }
 EXPORT_SYMBOL(fid_pack);
 
 }
 EXPORT_SYMBOL(fid_pack);
 
-void fid_unpack(const struct lu_fid_pack *pack, struct lu_fid *fid)
+int fid_unpack(const struct lu_fid_pack *pack, struct lu_fid *fid)
 {
 {
+        int result;
+
+        result = 0;
         switch (pack->fp_len) {
         case sizeof *fid + 1:
                 memcpy(fid, pack->fp_area, sizeof *fid);
         switch (pack->fp_len) {
         case sizeof *fid + 1:
                 memcpy(fid, pack->fp_area, sizeof *fid);
@@ -1201,8 +1188,9 @@ void fid_unpack(const struct lu_fid_pack *pack, struct lu_fid *fid)
         }
         default:
                 CERROR("Unexpected packed fid size: %d\n", pack->fp_len);
         }
         default:
                 CERROR("Unexpected packed fid size: %d\n", pack->fp_len);
-                LBUG();
+                result = -EIO;
         }
         }
+        return result;
 }
 EXPORT_SYMBOL(fid_unpack);
 
 }
 EXPORT_SYMBOL(fid_unpack);
 
index e51b7af..1eed2e2 100644 (file)
@@ -48,23 +48,7 @@ struct lu_time_data {
         unsigned long long ltd_timestamp[LU_TIME_DEPTH_MAX];
 };
 
         unsigned long long ltd_timestamp[LU_TIME_DEPTH_MAX];
 };
 
-static void *lu_time_key_init(const struct lu_context *ctx,
-                              struct lu_context_key *key)
-{
-        struct lu_time_data *value;
-
-        OBD_ALLOC_PTR(value);
-        if (value == NULL)
-                value = ERR_PTR(-ENOMEM);
-        return value;
-}
-
-static void lu_time_key_fini(const struct lu_context *ctx,
-                             struct lu_context_key *key, void *data)
-{
-        struct lu_time_data *value = data;
-        OBD_FREE_PTR(value);
-}
+LU_KEY_INIT_FINI(lu_time, struct lu_time_data);
 
 void lu_time_key_exit(const struct lu_context *ctx,
                       struct lu_context_key *key, void *data)
 
 void lu_time_key_exit(const struct lu_context *ctx,
                       struct lu_context_key *key, void *data)
index ea283e2..39ac11b 100644 (file)
@@ -2166,7 +2166,10 @@ static int osd_index_compat_insert(const struct lu_env *env,
         if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
                 return -EACCES;
 
         if (osd_object_auth(env, dt, capa, CAPA_OPC_INDEX_INSERT))
                 return -EACCES;
 
-        fid_unpack(pack, fid);
+        result = fid_unpack(pack, fid);
+        if (result != 0)
+                return result;
+
         luch = lu_object_find(env, ludev->ld_site, fid);
         if (!IS_ERR(luch)) {
                 if (lu_object_exists(luch)) {
         luch = lu_object_find(env, ludev->ld_site, fid);
         if (!IS_ERR(luch)) {
                 if (lu_object_exists(luch)) {
@@ -2235,12 +2238,7 @@ static void *osd_key_init(const struct lu_context *ctx,
         return info;
 }
 
         return info;
 }
 
-static void osd_key_fini(const struct lu_context *ctx,
-                         struct lu_context_key *key, void *data)
-{
-        struct osd_thread_info *info = data;
-        OBD_FREE_PTR(info);
-}
+LU_KEY_FINI(osd, struct osd_thread_info);
 
 static void osd_key_exit(const struct lu_context *ctx,
                          struct lu_context_key *key, void *data)
 
 static void osd_key_exit(const struct lu_context *ctx,
                          struct lu_context_key *key, void *data)