Whamcloud - gitweb
LU-5814 lov: move LSM to LOV layer 96/13696/11
authorJohn L. Hammond <john.hammond@intel.com>
Thu, 26 Mar 2015 04:01:22 +0000 (21:01 -0700)
committerOleg Drokin <oleg.drokin@intel.com>
Fri, 5 Jun 2015 01:52:02 +0000 (01:52 +0000)
Move the definition of struct lov_stripe_md along with supporting
functions from obd.h to lov_internal.h. Remove the unused functions
obd_packmd() and obd_free_diskmd(). Simplify lov_obd_packmd()
according to the reduced use cases and rename it lov_packmd().

Signed-off-by: John L. Hammond <john.hammond@intel.com>
Change-Id: I873a08f20bcb2e0919695325e51d74b2b97f4f0c
Signed-off-by: Jinshan Xiong <jinshan.xiong@intel.com>
Reviewed-on: http://review.whamcloud.com/13696
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: James Simmons <uja.ornl@yahoo.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
lustre/include/lustre_lmv.h
lustre/include/obd.h
lustre/include/obd_class.h
lustre/llite/llite_internal.h
lustre/llite/vvp_internal.h
lustre/lmv/lmv_obd.c
lustre/lov/lov_internal.h
lustre/lov/lov_obd.c
lustre/lov/lov_pack.c
lustre/mdc/mdc_request.c
lustre/obdclass/lprocfs_status_server.c

index df39b72..7e23297 100644 (file)
@@ -78,8 +78,6 @@ lsm_md_eq(const struct lmv_stripe_md *lsm1, const struct lmv_stripe_md *lsm2)
 }
 union lmv_mds_md;
 
 }
 union lmv_mds_md;
 
-int lmv_pack_md(union lmv_mds_md **lmmp, const struct lmv_stripe_md *lsm,
-                      int stripe_count);
 int lmv_alloc_md(union lmv_mds_md **lmmp, int stripe_count);
 void lmv_free_md(union lmv_mds_md *lmm);
 int lmv_alloc_memmd(struct lmv_stripe_md **lsmp, int stripe_count);
 int lmv_alloc_md(union lmv_mds_md **lmmp, int stripe_count);
 void lmv_free_md(union lmv_mds_md *lmm);
 int lmv_alloc_memmd(struct lmv_stripe_md **lsmp, int stripe_count);
index 4cbce88..ee7873a 100644 (file)
@@ -84,50 +84,7 @@ static inline void loi_init(struct lov_oinfo *loi)
 {
 }
 
 {
 }
 
-/* If we are unable to get the maximum object size from the OST in
- * ocd_maxbytes using OBD_CONNECT_MAXBYTES, then we fall back to using
- * the old maximum object size from ext3. */
-#define LUSTRE_EXT3_STRIPE_MAXBYTES 0x1fffffff000ULL
-
-struct lov_stripe_md {
-       atomic_t        lsm_refc;
-       spinlock_t      lsm_lock;
-       pid_t           lsm_lock_owner; /* debugging */
-
-       /* maximum possible file size, might change as OSTs status changes,
-        * e.g. disconnected, deactivated */
-       loff_t          lsm_maxbytes;
-       struct ost_id   lsm_oi;
-       __u32           lsm_magic;
-       __u32           lsm_stripe_size;
-       __u32           lsm_pattern; /* RAID0, RAID1, released, ... */
-       __u16           lsm_stripe_count;
-       __u16           lsm_layout_gen;
-       char            lsm_pool_name[LOV_MAXPOOLNAME + 1];
-       struct lov_oinfo        *lsm_oinfo[0];
-};
-
-static inline bool lsm_is_released(struct lov_stripe_md *lsm)
-{
-       return !!(lsm->lsm_pattern & LOV_PATTERN_F_RELEASED);
-}
-
-static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
-{
-       if (lsm == NULL)
-               return false;
-       if (lsm_is_released(lsm))
-               return false;
-       return true;
-}
-
-static inline int lov_stripe_md_size(unsigned int stripe_count)
-{
-       struct lov_stripe_md lsm;
-
-       return sizeof(lsm) + stripe_count * sizeof(lsm.lsm_oinfo[0]);
-}
-
+struct lov_stripe_md;
 struct obd_info;
 
 typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
 struct obd_info;
 
 typedef int (*obd_enqueue_update_f)(void *cookie, int rc);
@@ -902,8 +859,6 @@ struct obd_ops {
                         struct obd_statfs *osfs, __u64 max_age, __u32 flags);
         int (*o_statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
                               __u64 max_age, struct ptlrpc_request_set *set);
                         struct obd_statfs *osfs, __u64 max_age, __u32 flags);
         int (*o_statfs_async)(struct obd_export *exp, struct obd_info *oinfo,
                               __u64 max_age, struct ptlrpc_request_set *set);
-        int (*o_packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt,
-                        struct lov_stripe_md *mem_src);
         int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
                           struct lov_mds_md *disk_src, int disk_len);
        int (*o_create)(const struct lu_env *env, struct obd_export *exp,
         int (*o_unpackmd)(struct obd_export *exp,struct lov_stripe_md **mem_tgt,
                           struct lov_mds_md *disk_src, int disk_len);
        int (*o_create)(const struct lu_env *env, struct obd_export *exp,
@@ -1120,33 +1075,6 @@ struct md_ops {
                                  struct lu_fid *fid);
 };
 
                                  struct lu_fid *fid);
 };
 
-struct lsm_operations {
-       void (*lsm_free)(struct lov_stripe_md *);
-       void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *,
-                                   loff_t *, loff_t *);
-       void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *,
-                                    loff_t *, loff_t *);
-        int (*lsm_lmm_verify) (struct lov_mds_md *lmm, int lmm_bytes,
-                               __u16 *stripe_count);
-        int (*lsm_unpackmd) (struct lov_obd *lov, struct lov_stripe_md *lsm,
-                             struct lov_mds_md *lmm);
-};
-
-extern const struct lsm_operations lsm_v1_ops;
-extern const struct lsm_operations lsm_v3_ops;
-static inline const struct lsm_operations *lsm_op_find(u32 magic)
-{
-        switch(magic) {
-        case LOV_MAGIC_V1:
-               return &lsm_v1_ops;
-        case LOV_MAGIC_V3:
-               return &lsm_v3_ops;
-        default:
-               CERROR("Cannot recognize lsm_magic %08x\n", magic);
-               return NULL;
-        }
-}
-
 static inline struct md_open_data *obd_mod_alloc(void)
 {
        struct md_open_data *mod;
 static inline struct md_open_data *obd_mod_alloc(void)
 {
        struct md_open_data *mod;
index 29f2a96..8c8a7c9 100644 (file)
@@ -686,45 +686,6 @@ obd_process_config(struct obd_device *obd, int datalen, void *data)
         RETURN(rc);
 }
 
         RETURN(rc);
 }
 
-/* Pack an in-memory MD struct for storage on disk.
- * Returns +ve size of packed MD (0 for free), or -ve error.
- *
- * If @disk_tgt == NULL, MD size is returned (max size if @mem_src == NULL).
- * If @*disk_tgt != NULL and @mem_src == NULL, @*disk_tgt will be freed.
- * If @*disk_tgt == NULL, it will be allocated
- */
-static inline int obd_packmd(struct obd_export *exp,
-                             struct lov_mds_md **disk_tgt,
-                             struct lov_stripe_md *mem_src)
-{
-        int rc;
-        ENTRY;
-
-        EXP_CHECK_DT_OP(exp, packmd);
-        EXP_COUNTER_INCREMENT(exp, packmd);
-
-        rc = OBP(exp->exp_obd, packmd)(exp, disk_tgt, mem_src);
-        RETURN(rc);
-}
-
-static inline int obd_free_diskmd(struct obd_export *exp,
-                                 struct lov_mds_md **disk_tgt)
-{
-       LASSERT(disk_tgt);
-       LASSERT(*disk_tgt);
-       /*
-        * LU-2590, for caller's convenience, *disk_tgt could be host
-        * endianness, it needs swab to LE if necessary, while just
-        * lov_mds_md header needs it for figuring out how much memory
-        * needs to be freed.
-        */
-       if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
-           (((*disk_tgt)->lmm_magic == LOV_MAGIC_V1) ||
-            ((*disk_tgt)->lmm_magic == LOV_MAGIC_V3)))
-               lustre_swab_lov_mds_md(*disk_tgt);
-       return obd_packmd(exp, disk_tgt, NULL);
-}
-
 /* Unpack an MD struct from disk to in-memory format.
  * Returns +ve size of unpacked MD (0 for free), or -ve error.
  *
 /* Unpack an MD struct from disk to in-memory format.
  * Returns +ve size of unpacked MD (0 for free), or -ve error.
  *
index a81b062..e680051 100644 (file)
@@ -656,8 +656,6 @@ struct ll_file_data {
        struct list_head fd_lccs; /* list of ll_cl_context */
 };
 
        struct list_head fd_lccs; /* list of ll_cl_context */
 };
 
-struct lov_stripe_md;
-
 extern spinlock_t inode_lock;
 
 extern struct proc_dir_entry *proc_lustre_fs_root;
 extern spinlock_t inode_lock;
 
 extern struct proc_dir_entry *proc_lustre_fs_root;
index 4bd6554..bb5ce79 100644 (file)
@@ -46,7 +46,6 @@
 
 enum obd_notify_event;
 struct inode;
 
 enum obd_notify_event;
 struct inode;
-struct lov_stripe_md;
 struct lustre_md;
 struct obd_capa;
 struct obd_device;
 struct lustre_md;
 struct obd_capa;
 struct obd_device;
index 5f16b32..300710d 100644 (file)
@@ -2867,89 +2867,6 @@ int lmv_set_info_async(const struct lu_env *env, struct obd_export *exp,
        RETURN(-EINVAL);
 }
 
        RETURN(-EINVAL);
 }
 
-static int lmv_pack_md_v1(const struct lmv_stripe_md *lsm,
-                         struct lmv_mds_md_v1 *lmm1)
-{
-       int     cplen;
-       int     i;
-
-       lmm1->lmv_magic = cpu_to_le32(lsm->lsm_md_magic);
-       lmm1->lmv_stripe_count = cpu_to_le32(lsm->lsm_md_stripe_count);
-       lmm1->lmv_master_mdt_index = cpu_to_le32(lsm->lsm_md_master_mdt_index);
-       lmm1->lmv_hash_type = cpu_to_le32(lsm->lsm_md_hash_type);
-       cplen = strlcpy(lmm1->lmv_pool_name, lsm->lsm_md_pool_name,
-                       sizeof(lmm1->lmv_pool_name));
-       if (cplen >= sizeof(lmm1->lmv_pool_name))
-               return -E2BIG;
-
-       for (i = 0; i < lsm->lsm_md_stripe_count; i++)
-               fid_cpu_to_le(&lmm1->lmv_stripe_fids[i],
-                             &lsm->lsm_md_oinfo[i].lmo_fid);
-       return 0;
-}
-
-int lmv_pack_md(union lmv_mds_md **lmmp, const struct lmv_stripe_md *lsm,
-               int stripe_count)
-{
-       int     lmm_size = 0;
-       bool    allocated = false;
-       int     rc = 0;
-       ENTRY;
-
-       LASSERT(lmmp != NULL);
-       /* Free lmm */
-       if (*lmmp != NULL && lsm == NULL) {
-               int stripe_count;
-
-               stripe_count = lmv_mds_md_stripe_count_get(*lmmp);
-               lmm_size = lmv_mds_md_size(stripe_count,
-                                          le32_to_cpu((*lmmp)->lmv_magic));
-               if (lmm_size == 0)
-                       RETURN(-EINVAL);
-               OBD_FREE(*lmmp, lmm_size);
-               *lmmp = NULL;
-               RETURN(0);
-       }
-
-       /* Alloc lmm */
-       if (*lmmp == NULL && lsm == NULL) {
-               lmm_size = lmv_mds_md_size(stripe_count, LMV_MAGIC);
-               LASSERT(lmm_size > 0);
-               OBD_ALLOC(*lmmp, lmm_size);
-               if (*lmmp == NULL)
-                       RETURN(-ENOMEM);
-               lmv_mds_md_stripe_count_set(*lmmp, stripe_count);
-               (*lmmp)->lmv_magic = cpu_to_le32(LMV_MAGIC);
-               RETURN(lmm_size);
-       }
-
-       /* pack lmm */
-       LASSERT(lsm != NULL);
-       lmm_size = lmv_mds_md_size(lsm->lsm_md_stripe_count, lsm->lsm_md_magic);
-       if (*lmmp == NULL) {
-               OBD_ALLOC(*lmmp, lmm_size);
-               if (*lmmp == NULL)
-                       RETURN(-ENOMEM);
-               allocated = true;
-       }
-
-       switch (lsm->lsm_md_magic) {
-       case LMV_MAGIC_V1:
-               rc = lmv_pack_md_v1(lsm, &(*lmmp)->lmv_md_v1);
-               break;
-       default:
-               rc = -EINVAL;
-               break;
-       }
-
-       if (rc != 0 && allocated) {
-               OBD_FREE(*lmmp, lmm_size);
-               *lmmp = NULL;
-       }
-
-       RETURN(lmm_size);
-}
-
 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
                            const struct lmv_mds_md_v1 *lmm1)
 {
 static int lmv_unpack_md_v1(struct obd_export *exp, struct lmv_stripe_md *lsm,
                            const struct lmv_mds_md_v1 *lmm1)
 {
@@ -3101,26 +3018,6 @@ int lmv_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
                             (union lmv_mds_md *)lmm, disk_len);
 }
 
                             (union lmv_mds_md *)lmm, disk_len);
 }
 
-int lmv_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
-               struct lov_stripe_md *lsm)
-{
-       struct obd_device               *obd = exp->exp_obd;
-       struct lmv_obd                  *lmv_obd = &obd->u.lmv;
-       const struct lmv_stripe_md      *lmv = (struct lmv_stripe_md *)lsm;
-       int                             stripe_count;
-
-       if (lmmp == NULL) {
-               if (lsm != NULL)
-                       stripe_count = lmv->lsm_md_stripe_count;
-               else
-                       stripe_count = lmv_obd->desc.ld_tgt_count;
-
-               return lmv_mds_md_size(stripe_count, LMV_MAGIC_V1);
-       }
-
-       return lmv_pack_md((union lmv_mds_md **)lmmp, lmv, 0);
-}
-
 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
                              ldlm_policy_data_t *policy, ldlm_mode_t mode,
                              ldlm_cancel_flags_t flags, void *opaque)
 static int lmv_cancel_unused(struct obd_export *exp, const struct lu_fid *fid,
                              ldlm_policy_data_t *policy, ldlm_mode_t mode,
                              ldlm_cancel_flags_t flags, void *opaque)
@@ -3487,7 +3384,6 @@ struct obd_ops lmv_obd_ops = {
         .o_statfs               = lmv_statfs,
         .o_get_info             = lmv_get_info,
         .o_set_info_async       = lmv_set_info_async,
         .o_statfs               = lmv_statfs,
         .o_get_info             = lmv_get_info,
         .o_set_info_async       = lmv_set_info_async,
-        .o_packmd               = lmv_packmd,
         .o_unpackmd             = lmv_unpackmd,
         .o_notify               = lmv_notify,
         .o_get_uuid             = lmv_get_uuid,
         .o_unpackmd             = lmv_unpackmd,
         .o_notify               = lmv_notify,
         .o_get_uuid             = lmv_get_uuid,
index ddb71fa..2bd1547 100644 (file)
 #include <obd_class.h>
 #include <lustre/lustre_user.h>
 
 #include <obd_class.h>
 #include <lustre/lustre_user.h>
 
+/* If we are unable to get the maximum object size from the OST in
+ * ocd_maxbytes using OBD_CONNECT_MAXBYTES, then we fall back to using
+ * the old maximum object size from ext3. */
+#define LUSTRE_EXT3_STRIPE_MAXBYTES 0x1fffffff000ULL
+
+struct lov_stripe_md {
+       atomic_t        lsm_refc;
+       spinlock_t      lsm_lock;
+       pid_t           lsm_lock_owner; /* debugging */
+
+       /* maximum possible file size, might change as OSTs status changes,
+        * e.g. disconnected, deactivated */
+       loff_t          lsm_maxbytes;
+       struct ost_id   lsm_oi;
+       u32             lsm_magic;
+       u32             lsm_stripe_size;
+       u32             lsm_pattern; /* RAID0, RAID1, released, ... */
+       u16             lsm_stripe_count;
+       u16             lsm_layout_gen;
+       char            lsm_pool_name[LOV_MAXPOOLNAME + 1];
+       struct lov_oinfo        *lsm_oinfo[0];
+};
+
+static inline bool lsm_is_released(struct lov_stripe_md *lsm)
+{
+       return !!(lsm->lsm_pattern & LOV_PATTERN_F_RELEASED);
+}
+
+static inline bool lsm_has_objects(struct lov_stripe_md *lsm)
+{
+       if (lsm == NULL)
+               return false;
+
+       if (lsm_is_released(lsm))
+               return false;
+
+       return true;
+}
+
+static inline int lov_stripe_md_size(unsigned int stripe_count)
+{
+       struct lov_stripe_md lsm;
+
+       return sizeof(lsm) + stripe_count * sizeof(lsm.lsm_oinfo[0]);
+}
+
+struct lsm_operations {
+       void (*lsm_free)(struct lov_stripe_md *);
+       void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, loff_t *,
+                                   loff_t *);
+       void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, loff_t *,
+                                    loff_t *);
+       int (*lsm_lmm_verify)(struct lov_mds_md *lmm, int lmm_bytes,
+                             u16 *stripe_count);
+       int (*lsm_unpackmd)(struct lov_obd *lov, struct lov_stripe_md *lsm,
+                           struct lov_mds_md *lmm);
+};
+
+extern const struct lsm_operations lsm_v1_ops;
+extern const struct lsm_operations lsm_v3_ops;
+static inline const struct lsm_operations *lsm_op_find(int magic)
+{
+       switch (magic) {
+       case LOV_MAGIC_V1:
+               return &lsm_v1_ops;
+       case LOV_MAGIC_V3:
+               return &lsm_v3_ops;
+       default:
+               CERROR("unrecognized lsm_magic %08x\n", magic);
+               return NULL;
+       }
+}
+
 /* lov_do_div64(a, b) returns a % b, and a = a / b.
  * The 32-bit code is LOV-specific due to knowing about stripe limits in
  * order to reduce the divisor to a 32-bit number.  If the divisor is
 /* lov_do_div64(a, b) returns a % b, and a = a / b.
  * The 32-bit code is LOV-specific due to knowing about stripe limits in
  * order to reduce the divisor to a 32-bit number.  If the divisor is
@@ -178,8 +251,6 @@ int lov_del_target(struct obd_device *obd, __u32 index,
 /* lov_pack.c */
 ssize_t lov_lsm_pack(const struct lov_stripe_md *lsm, void *buf,
                     size_t buf_size);
 /* lov_pack.c */
 ssize_t lov_lsm_pack(const struct lov_stripe_md *lsm, void *buf,
                     size_t buf_size);
-int lov_packmd(struct obd_export *exp, struct lov_mds_md **lmm,
-               struct lov_stripe_md *lsm);
 int lov_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
                  struct lov_mds_md *lmm, int lmm_bytes);
 int lov_alloc_memmd(struct lov_stripe_md **lsmp, __u16 stripe_count,
 int lov_unpackmd(struct obd_export *exp, struct lov_stripe_md **lsmp,
                  struct lov_mds_md *lmm, int lmm_bytes);
 int lov_alloc_memmd(struct lov_stripe_md **lsmp, __u16 stripe_count,
index 9afa7aa..7a654f0 100644 (file)
@@ -1021,14 +1021,6 @@ out:
         RETURN(rc);
 }
 
         RETURN(rc);
 }
 
-#define ASSERT_LSM_MAGIC(lsmp)                                                  \
-do {                                                                            \
-        LASSERT((lsmp) != NULL);                                                \
-        LASSERTF(((lsmp)->lsm_magic == LOV_MAGIC_V1 ||                          \
-                 (lsmp)->lsm_magic == LOV_MAGIC_V3),                            \
-                 "%p->lsm_magic=%x\n", (lsmp), (lsmp)->lsm_magic);              \
-} while (0)
-
 int lov_statfs_interpret(struct ptlrpc_request_set *rqset, void *data, int rc)
 {
        struct lov_request_set *lovset = (struct lov_request_set *)data;
 int lov_statfs_interpret(struct ptlrpc_request_set *rqset, void *data, int rc)
 {
        struct lov_request_set *lovset = (struct lov_request_set *)data;
@@ -1477,7 +1469,6 @@ static struct obd_ops lov_obd_ops = {
        .o_disconnect           = lov_disconnect,
        .o_statfs               = lov_statfs,
        .o_statfs_async         = lov_statfs_async,
        .o_disconnect           = lov_disconnect,
        .o_statfs               = lov_statfs,
        .o_statfs_async         = lov_statfs_async,
-       .o_packmd               = lov_packmd,
        .o_unpackmd             = lov_unpackmd,
        .o_iocontrol            = lov_iocontrol,
        .o_get_info             = lov_get_info,
        .o_unpackmd             = lov_unpackmd,
        .o_iocontrol            = lov_iocontrol,
        .o_get_info             = lov_get_info,
index 34f872e..7e95b3c 100644 (file)
@@ -177,95 +177,6 @@ ssize_t lov_lsm_pack(const struct lov_stripe_md *lsm, void *buf,
        RETURN(lmm_size);
 }
 
        RETURN(lmm_size);
 }
 
-/* Pack LOV object metadata for disk storage.  It is packed in LE byte
- * order and is opaque to the networking layer.
- *
- * XXX In the future, this will be enhanced to get the EA size from the
- *     underlying OSC device(s) to get their EA sizes so we can stack
- *     LOVs properly.  For now lov_mds_md_size() just assumes one obd_id
- *     per stripe.
- */
-static int lov_obd_packmd(struct lov_obd *lov, struct lov_mds_md **lmmp,
-                         struct lov_stripe_md *lsm)
-{
-       __u16 stripe_count;
-       int lmm_size, lmm_magic;
-        ENTRY;
-
-        if (lsm) {
-                lmm_magic = lsm->lsm_magic;
-        } else {
-                if (lmmp && *lmmp)
-                        lmm_magic = le32_to_cpu((*lmmp)->lmm_magic);
-                else
-                        /* lsm == NULL and lmmp == NULL */
-                        lmm_magic = LOV_MAGIC;
-        }
-
-        if ((lmm_magic != LOV_MAGIC_V1) &&
-            (lmm_magic != LOV_MAGIC_V3)) {
-                CERROR("bad mem LOV MAGIC: 0x%08X != 0x%08X nor 0x%08X\n",
-                        lmm_magic, LOV_MAGIC_V1, LOV_MAGIC_V3);
-                RETURN(-EINVAL);
-
-        }
-
-        if (lsm) {
-                /* If we are just sizing the EA, limit the stripe count
-                 * to the actual number of OSTs in this filesystem. */
-               if (!lmmp) {
-                       stripe_count = lov_get_stripecnt(lov, lmm_magic,
-                                                       lsm->lsm_stripe_count);
-                       lsm->lsm_stripe_count = stripe_count;
-               } else if (!lsm_is_released(lsm)) {
-                       stripe_count = lsm->lsm_stripe_count;
-               } else {
-                       stripe_count = 0;
-               }
-       } else {
-               /* To calculate maximum easize by active targets at present,
-                * which is exactly the maximum easize to be seen by LOV */
-               stripe_count = lov->desc.ld_active_tgt_count;
-       }
-
-        /* XXX LOV STACKING call into osc for sizes */
-        lmm_size = lov_mds_md_size(stripe_count, lmm_magic);
-
-        if (!lmmp)
-                RETURN(lmm_size);
-
-        if (*lmmp && !lsm) {
-                stripe_count = le16_to_cpu((*lmmp)->lmm_stripe_count);
-                lmm_size = lov_mds_md_size(stripe_count, lmm_magic);
-                OBD_FREE_LARGE(*lmmp, lmm_size);
-                *lmmp = NULL;
-                RETURN(0);
-        }
-
-        if (!*lmmp) {
-                OBD_ALLOC_LARGE(*lmmp, lmm_size);
-                if (!*lmmp)
-                        RETURN(-ENOMEM);
-        }
-
-       CDEBUG(D_INFO, "lov_packmd: LOV_MAGIC 0x%08X, lmm_size = %d\n",
-              lmm_magic, lmm_size);
-
-       if (!lsm)
-               RETURN(lmm_size);
-
-       RETURN(lov_lsm_pack(lsm, *lmmp, lmm_size));
-}
-
-int lov_packmd(struct obd_export *exp, struct lov_mds_md **lmmp,
-              struct lov_stripe_md *lsm)
-{
-       struct obd_device *obd = class_exp2obd(exp);
-       struct lov_obd *lov = &obd->u.lov;
-
-       return lov_obd_packmd(lov, lmmp, lsm);
-}
-
 /* Find the max stripecount we should use */
 __u16 lov_get_stripecnt(struct lov_obd *lov, __u32 magic, __u16 stripe_count)
 {
 /* Find the max stripecount we should use */
 __u16 lov_get_stripecnt(struct lov_obd *lov, __u32 magic, __u16 stripe_count)
 {
@@ -366,7 +277,6 @@ int lov_free_memmd(struct lov_stripe_md **lsmp)
        return refc;
 }
 
        return refc;
 }
 
-
 /* Unpack LOV object metadata from disk storage.  It is packed in LE byte
  * order and is opaque to the networking layer.
  */
 /* Unpack LOV object metadata from disk storage.  It is packed in LE byte
  * order and is opaque to the networking layer.
  */
@@ -433,19 +343,27 @@ int lov_unpackmd(struct obd_export *exp,  struct lov_stripe_md **lsmp,
 int lov_getstripe(struct lov_object *obj, struct lov_stripe_md *lsm,
                  struct lov_user_md __user *lump)
 {
 int lov_getstripe(struct lov_object *obj, struct lov_stripe_md *lsm,
                  struct lov_user_md __user *lump)
 {
-       /*
-        * XXX huge struct allocated on stack.
-        */
        /* we use lov_user_md_v3 because it is larger than lov_user_md_v1 */
        /* we use lov_user_md_v3 because it is larger than lov_user_md_v1 */
-       struct lov_obd          *lov;
-       struct lov_mds_md       *lmmk = NULL;
+       struct lov_mds_md       *lmmk;
        struct lov_user_md_v3   lum;
        struct lov_user_md_v3   lum;
+       u32                     stripe_count;
+       size_t                  lum_size;
+       size_t                  lmmk_size;
+       ssize_t                 lmm_size;
        int                     rc;
        int                     rc;
-       int                     lmmk_size;
-       int                     lmm_size;
-       int                     lum_size;
        ENTRY;
 
        ENTRY;
 
+       if (lsm->lsm_magic != LOV_MAGIC_V1 && lsm->lsm_magic != LOV_MAGIC_V3) {
+               CERROR("bad LSM MAGIC: 0x%08X != 0x%08X nor 0x%08X\n",
+                      lsm->lsm_magic, LOV_MAGIC_V1, LOV_MAGIC_V3);
+               GOTO(out, rc = -EIO);
+       }
+
+       if (!lsm_is_released(lsm))
+               stripe_count = lsm->lsm_stripe_count;
+       else
+               stripe_count = 0;
+
        /* we only need the header part from user space to get lmm_magic and
         * lmm_stripe_count, (the header part is common to v1 and v3) */
        lum_size = sizeof(struct lov_user_md_v1);
        /* we only need the header part from user space to get lmm_magic and
         * lmm_stripe_count, (the header part is common to v1 and v3) */
        lum_size = sizeof(struct lov_user_md_v1);
@@ -457,33 +375,37 @@ int lov_getstripe(struct lov_object *obj, struct lov_stripe_md *lsm,
            lum.lmm_magic != LOV_USER_MAGIC_SPECIFIC)
                GOTO(out, rc = -EINVAL);
 
            lum.lmm_magic != LOV_USER_MAGIC_SPECIFIC)
                GOTO(out, rc = -EINVAL);
 
-       if (lum.lmm_stripe_count &&
-           (lum.lmm_stripe_count < lsm->lsm_stripe_count)) {
+       if (lum.lmm_stripe_count != 0 && lum.lmm_stripe_count < stripe_count) {
                /* Return right size of stripe to user */
                /* Return right size of stripe to user */
-               lum.lmm_stripe_count = lsm->lsm_stripe_count;
+               lum.lmm_stripe_count = stripe_count;
                rc = copy_to_user(lump, &lum, lum_size);
                GOTO(out, rc = -EOVERFLOW);
        }
                rc = copy_to_user(lump, &lum, lum_size);
                GOTO(out, rc = -EOVERFLOW);
        }
-       lov = lu2lov_dev(obj->lo_cl.co_lu.lo_dev)->ld_lov;
-       rc = lov_obd_packmd(lov, &lmmk, lsm);
-       if (rc < 0)
-               GOTO(out, rc);
-       lmmk_size = lmm_size = rc;
-       rc = 0;
+
+       lmmk_size = lov_mds_md_size(stripe_count, lsm->lsm_magic);
+
+       OBD_ALLOC_LARGE(lmmk, lmmk_size);
+       if (lmmk == NULL)
+               GOTO(out, rc = -ENOMEM);
+
+       lmm_size = lov_lsm_pack(lsm, lmmk, lmmk_size);
+       if (lmm_size < 0)
+               GOTO(out_free, rc = lmm_size);
 
        /* FIXME: Bug 1185 - copy fields properly when structs change */
        /* struct lov_user_md_v3 and struct lov_mds_md_v3 must be the same */
        CLASSERT(sizeof(lum) == sizeof(struct lov_mds_md_v3));
 
        /* FIXME: Bug 1185 - copy fields properly when structs change */
        /* struct lov_user_md_v3 and struct lov_mds_md_v3 must be the same */
        CLASSERT(sizeof(lum) == sizeof(struct lov_mds_md_v3));
-       CLASSERT(sizeof lum.lmm_objects[0] == sizeof lmmk->lmm_objects[0]);
+       CLASSERT(sizeof(lum.lmm_objects[0]) == sizeof(lmmk->lmm_objects[0]));
 
 
-       if ((cpu_to_le32(LOV_MAGIC) != LOV_MAGIC) &&
-           ((lmmk->lmm_magic == cpu_to_le32(LOV_MAGIC_V1)) ||
-           (lmmk->lmm_magic == cpu_to_le32(LOV_MAGIC_V3)))) {
+       if (cpu_to_le32(LOV_MAGIC) != LOV_MAGIC &&
+           (lmmk->lmm_magic == cpu_to_le32(LOV_MAGIC_V1) ||
+            lmmk->lmm_magic == cpu_to_le32(LOV_MAGIC_V3))) {
                lustre_swab_lov_mds_md(lmmk);
                lustre_swab_lov_user_md_objects(
                                (struct lov_user_ost_data *)lmmk->lmm_objects,
                                lmmk->lmm_stripe_count);
        }
                lustre_swab_lov_mds_md(lmmk);
                lustre_swab_lov_user_md_objects(
                                (struct lov_user_ost_data *)lmmk->lmm_objects,
                                lmmk->lmm_stripe_count);
        }
+
        if (lum.lmm_magic == LOV_USER_MAGIC) {
                /* User request for v1, we need skip lmm_pool_name */
                if (lmmk->lmm_magic == LOV_MAGIC_V3) {
        if (lum.lmm_magic == LOV_USER_MAGIC) {
                /* User request for v1, we need skip lmm_pool_name */
                if (lmmk->lmm_magic == LOV_MAGIC_V3) {
@@ -512,10 +434,11 @@ int lov_getstripe(struct lov_object *obj, struct lov_stripe_md *lsm,
        ((struct lov_user_md *)lmmk)->lmm_layout_gen = lum.lmm_layout_gen;
        ((struct lov_user_md *)lmmk)->lmm_stripe_count = lum.lmm_stripe_count;
        if (copy_to_user(lump, lmmk, lmm_size))
        ((struct lov_user_md *)lmmk)->lmm_layout_gen = lum.lmm_layout_gen;
        ((struct lov_user_md *)lmmk)->lmm_stripe_count = lum.lmm_stripe_count;
        if (copy_to_user(lump, lmmk, lmm_size))
-               rc = -EFAULT;
+               GOTO(out_free, rc = -EFAULT);
 
 
+       GOTO(out_free, rc = 0);
 out_free:
        OBD_FREE_LARGE(lmmk, lmmk_size);
 out:
 out_free:
        OBD_FREE_LARGE(lmmk, lmmk_size);
 out:
-       RETURN(rc);
+       return rc;
 }
 }
index 999e81a..ce1ebbb 100644 (file)
@@ -528,14 +528,6 @@ int mdc_get_lustre_md(struct obd_export *exp, struct ptlrpc_request *req,
                 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
                 if (rc < 0)
                         GOTO(out, rc);
                 rc = obd_unpackmd(dt_exp, &md->lsm, lmm, lmmsize);
                 if (rc < 0)
                         GOTO(out, rc);
-
-               if (rc < (typeof(rc))sizeof(*md->lsm)) {
-                        CDEBUG(D_INFO, "lsm size too small: "
-                               "rc < sizeof (*md->lsm) (%d < %d)\n",
-                               rc, (int)sizeof(*md->lsm));
-                        GOTO(out, rc = -EPROTO);
-                }
-
        } else if (md->body->mbo_valid & OBD_MD_FLDIREA) {
                int lmvsize;
                struct lov_mds_md *lmv;
        } else if (md->body->mbo_valid & OBD_MD_FLDIREA) {
                int lmvsize;
                struct lov_mds_md *lmv;
index 4b8ea8c..4917fe6 100644 (file)
@@ -432,7 +432,6 @@ void lprocfs_init_ops_stats(int num_private_stats, struct lprocfs_stats *stats)
        LPROCFS_OBD_OP_INIT(num_private_stats, stats, fid_alloc);
        LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs);
        LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs_async);
        LPROCFS_OBD_OP_INIT(num_private_stats, stats, fid_alloc);
        LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs);
        LPROCFS_OBD_OP_INIT(num_private_stats, stats, statfs_async);
-       LPROCFS_OBD_OP_INIT(num_private_stats, stats, packmd);
        LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpackmd);
        LPROCFS_OBD_OP_INIT(num_private_stats, stats, create);
        LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy);
        LPROCFS_OBD_OP_INIT(num_private_stats, stats, unpackmd);
        LPROCFS_OBD_OP_INIT(num_private_stats, stats, create);
        LPROCFS_OBD_OP_INIT(num_private_stats, stats, destroy);