Whamcloud - gitweb
LU-2809 llite: Do not return layout_gen for getxattr
authorJinshan Xiong <jinshan.xiong@intel.com>
Sat, 9 Mar 2013 01:07:13 +0000 (17:07 -0800)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 13 Mar 2013 20:40:15 +0000 (16:40 -0400)
The problem is that layout_gen and stripe_offset are sharing the
same field in lov_user_md{}. Layout gen would be wrongly interpreted
as stripe_offset when a backup is restored.

Signed-off-by: Jinshan Xiong <jinshan.xiong@intel.com>
Change-Id: If2c120bf861eeffd2db5f92e1d23cb1b9a2f5c63
Reviewed-on: http://review.whamcloud.com/5664
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: John Hammond <johnlockwoodhammond@gmail.com>
lustre/include/lustre/lustre_user.h
lustre/llite/xattr.c
lustre/lov/lov_pack.c
lustre/ptlrpc/pack_generic.c
lustre/utils/liblustreapi.c

index 500082c..bd03b57 100644 (file)
@@ -279,38 +279,37 @@ struct lov_user_ost_data_v1 {     /* per-stripe data structure */
 } __attribute__((packed));
 
 #define lov_user_md lov_user_md_v1
-#define lmm_stripe_offset u.lum_stripe_offset
 struct lov_user_md_v1 {           /* LOV EA user data (host-endian) */
-        __u32 lmm_magic;          /* magic number = LOV_USER_MAGIC_V1 */
-        __u32 lmm_pattern;        /* LOV_PATTERN_RAID0, LOV_PATTERN_RAID1 */
-        __u64 lmm_object_id;      /* LOV object ID */
-        __u64 lmm_object_seq;     /* LOV object seq */
-        __u32 lmm_stripe_size;    /* size of stripe in bytes */
-        __u16 lmm_stripe_count;   /* num stripes in use for this object */
-        union {
-                __u16 lum_stripe_offset;  /* starting stripe offset in
-                                           * lmm_objects, use when writing */
-                __u16 lum_layout_gen;     /* layout generation number
-                                           * used when reading */
-        } u;
-        struct lov_user_ost_data_v1 lmm_objects[0]; /* per-stripe data */
+       __u32 lmm_magic;          /* magic number = LOV_USER_MAGIC_V1 */
+       __u32 lmm_pattern;        /* LOV_PATTERN_RAID0, LOV_PATTERN_RAID1 */
+       __u64 lmm_object_id;      /* LOV object ID */
+       __u64 lmm_object_seq;     /* LOV object seq */
+       __u32 lmm_stripe_size;    /* size of stripe in bytes */
+       __u16 lmm_stripe_count;   /* num stripes in use for this object */
+       union {
+               __u16 lmm_stripe_offset;  /* starting stripe offset in
+                                          * lmm_objects, use when writing */
+               __u16 lmm_layout_gen;     /* layout generation number
+                                          * used when reading */
+       };
+       struct lov_user_ost_data_v1 lmm_objects[0]; /* per-stripe data */
 } __attribute__((packed,  __may_alias__));
 
 struct lov_user_md_v3 {           /* LOV EA user data (host-endian) */
-        __u32 lmm_magic;          /* magic number = LOV_USER_MAGIC_V3 */
-        __u32 lmm_pattern;        /* LOV_PATTERN_RAID0, LOV_PATTERN_RAID1 */
-        __u64 lmm_object_id;      /* LOV object ID */
-        __u64 lmm_object_seq;     /* LOV object seq */
-        __u32 lmm_stripe_size;    /* size of stripe in bytes */
-        __u16 lmm_stripe_count;   /* num stripes in use for this object */
-        union {
-                __u16 lum_stripe_offset;  /* starting stripe offset in
-                                           * lmm_objects, use when writing */
-                __u16 lum_layout_gen;     /* layout generation number
-                                           * used when reading */
-        } u;
-        char  lmm_pool_name[LOV_MAXPOOLNAME]; /* pool name */
-        struct lov_user_ost_data_v1 lmm_objects[0]; /* per-stripe data */
+       __u32 lmm_magic;          /* magic number = LOV_USER_MAGIC_V3 */
+       __u32 lmm_pattern;        /* LOV_PATTERN_RAID0, LOV_PATTERN_RAID1 */
+       __u64 lmm_object_id;      /* LOV object ID */
+       __u64 lmm_object_seq;     /* LOV object seq */
+       __u32 lmm_stripe_size;    /* size of stripe in bytes */
+       __u16 lmm_stripe_count;   /* num stripes in use for this object */
+       union {
+               __u16 lmm_stripe_offset;  /* starting stripe offset in
+                                          * lmm_objects, use when writing */
+               __u16 lmm_layout_gen;     /* layout generation number
+                                          * used when reading */
+       };
+       char  lmm_pool_name[LOV_MAXPOOLNAME]; /* pool name */
+       struct lov_user_ost_data_v1 lmm_objects[0]; /* per-stripe data */
 } __attribute__((packed));
 
 /* Compile with -D_LARGEFILE64_SOURCE or -D_GNU_SOURCE (or #define) to
index 1d9923e..24a89eb 100644 (file)
@@ -491,6 +491,10 @@ ssize_t ll_getxattr(struct dentry *dentry, const char *name,
 
                 lump = (struct lov_user_md *)buffer;
                 memcpy(lump, lmm, lmmsize);
+               /* do not return layout gen for getxattr otherwise it would
+                * confuse tar --xattr by recognizing layout gen as stripe
+                * offset when the file is restored. See LU-2809. */
+               lump->lmm_layout_gen = 0;
 
                 rc = lmmsize;
 out:
index c10d000..420acb4 100644 (file)
@@ -662,19 +662,19 @@ int lov_getstripe(struct obd_export *exp, struct lov_stripe_md *lsm,
                 lmm_size = lum_size;
         else if (lum.lmm_stripe_count < lmmk->lmm_stripe_count)
                 GOTO(out_set, rc = -EOVERFLOW);
-        /*
-         * Have a difference between lov_mds_md & lov_user_md.
-         * So we have to re-order the data before copy to user.
-         */
-        lum.lmm_stripe_count = lmmk->lmm_stripe_count;
-        lum.u.lum_layout_gen = lmmk->lmm_layout_gen;
-        ((struct lov_user_md*)lmmk)->u.lum_layout_gen = lum.u.lum_layout_gen;
-        ((struct lov_user_md*)lmmk)->lmm_stripe_count = lum.lmm_stripe_count;
-        if (cfs_copy_to_user(lump, lmmk, lmm_size))
-                rc = -EFAULT;
-
-        obd_free_diskmd(exp, &lmmk);
+       /*
+        * Have a difference between lov_mds_md & lov_user_md.
+        * So we have to re-order the data before copy to user.
+        */
+       lum.lmm_stripe_count = lmmk->lmm_stripe_count;
+       lum.lmm_layout_gen = lmmk->lmm_layout_gen;
+       ((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 (cfs_copy_to_user(lump, lmmk, lmm_size))
+               rc = -EFAULT;
+
+       obd_free_diskmd(exp, &lmmk);
 out_set:
-        set_fs(seg);
-        RETURN(rc);
+       set_fs(seg);
+       RETURN(rc);
 }
index 885f250..e72ee14 100644 (file)
@@ -2155,29 +2155,29 @@ EXPORT_SYMBOL(lustre_swab_lmv_user_md);
 
 static void print_lum (struct lov_user_md *lum)
 {
-        CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
-        CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
-        CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
-        CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
-        CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_seq);
-        CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
-        CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
-        CDEBUG(D_OTHER, "\tlmm_stripe_offset/lmm_layout_gen: %#x\n",
-               lum->u.lum_stripe_offset);
+       CDEBUG(D_OTHER, "lov_user_md %p:\n", lum);
+       CDEBUG(D_OTHER, "\tlmm_magic: %#x\n", lum->lmm_magic);
+       CDEBUG(D_OTHER, "\tlmm_pattern: %#x\n", lum->lmm_pattern);
+       CDEBUG(D_OTHER, "\tlmm_object_id: "LPU64"\n", lum->lmm_object_id);
+       CDEBUG(D_OTHER, "\tlmm_object_gr: "LPU64"\n", lum->lmm_object_seq);
+       CDEBUG(D_OTHER, "\tlmm_stripe_size: %#x\n", lum->lmm_stripe_size);
+       CDEBUG(D_OTHER, "\tlmm_stripe_count: %#x\n", lum->lmm_stripe_count);
+       CDEBUG(D_OTHER, "\tlmm_stripe_offset/lmm_layout_gen: %#x\n",
+                       lum->lmm_stripe_offset);
 }
 
 static void lustre_swab_lov_user_md_common(struct lov_user_md_v1 *lum)
 {
-        ENTRY;
-        __swab32s(&lum->lmm_magic);
-        __swab32s(&lum->lmm_pattern);
-        __swab64s(&lum->lmm_object_id);
-        __swab64s(&lum->lmm_object_seq);
-        __swab32s(&lum->lmm_stripe_size);
-        __swab16s(&lum->lmm_stripe_count);
-        __swab16s(&lum->u.lum_stripe_offset);
-        print_lum(lum);
-        EXIT;
+       ENTRY;
+       __swab32s(&lum->lmm_magic);
+       __swab32s(&lum->lmm_pattern);
+       __swab64s(&lum->lmm_object_id);
+       __swab64s(&lum->lmm_object_seq);
+       __swab32s(&lum->lmm_stripe_size);
+       __swab16s(&lum->lmm_stripe_count);
+       __swab16s(&lum->lmm_stripe_offset);
+       print_lum(lum);
+       EXIT;
 }
 
 void lustre_swab_lov_user_md_v1(struct lov_user_md_v1 *lum)
index 4067bd4..3b796de 100644 (file)
@@ -2099,7 +2099,7 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path,
                         llapi_printf(LLAPI_MSG_NORMAL, "%slayout_gen:     ",
                                      prefix);
                 llapi_printf(LLAPI_MSG_NORMAL, "%u%c",
-                             (int)lum->u.lum_layout_gen, nl);
+                               (int)lum->lmm_layout_gen, nl);
         }
 
         if (verbose & VERBOSE_OFFSET) {