From e7a884b7b06f99de7993245642be1b969887e92e Mon Sep 17 00:00:00 2001 From: Jinshan Xiong Date: Fri, 8 Mar 2013 17:07:13 -0800 Subject: [PATCH] LU-2809 llite: Do not return layout_gen for getxattr 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 Change-Id: If2c120bf861eeffd2db5f92e1d23cb1b9a2f5c63 Reviewed-on: http://review.whamcloud.com/5664 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Andreas Dilger Reviewed-by: John Hammond --- lustre/include/lustre/lustre_user.h | 55 ++++++++++++++++++------------------- lustre/llite/xattr.c | 4 +++ lustre/lov/lov_pack.c | 28 +++++++++---------- lustre/ptlrpc/pack_generic.c | 38 ++++++++++++------------- lustre/utils/liblustreapi.c | 2 +- 5 files changed, 65 insertions(+), 62 deletions(-) diff --git a/lustre/include/lustre/lustre_user.h b/lustre/include/lustre/lustre_user.h index 500082c..bd03b57 100644 --- a/lustre/include/lustre/lustre_user.h +++ b/lustre/include/lustre/lustre_user.h @@ -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 diff --git a/lustre/llite/xattr.c b/lustre/llite/xattr.c index 1d9923e..24a89eb 100644 --- a/lustre/llite/xattr.c +++ b/lustre/llite/xattr.c @@ -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: diff --git a/lustre/lov/lov_pack.c b/lustre/lov/lov_pack.c index c10d000..420acb4 100644 --- a/lustre/lov/lov_pack.c +++ b/lustre/lov/lov_pack.c @@ -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); } diff --git a/lustre/ptlrpc/pack_generic.c b/lustre/ptlrpc/pack_generic.c index 885f250..e72ee14 100644 --- a/lustre/ptlrpc/pack_generic.c +++ b/lustre/ptlrpc/pack_generic.c @@ -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) diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 4067bd4..3b796de 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -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) { -- 1.8.3.1