From 521a697f68de50125e21c90fa5d05ea59e4f0827 Mon Sep 17 00:00:00 2001 From: Jinshan Xiong Date: Sat, 14 Oct 2017 00:55:23 -0700 Subject: [PATCH] LU-9771 flr: inherit mirror options from directory This patch checks and verifies directory inheritance from parent works both for regular files and directories. Test-Parameters: testlist=sanity-flr Signed-off-by: Jinshan Xiong Change-Id: Ief58805ca736acb9a53fd9ad8fb2bb460d46b748 Reviewed-on: https://review.whamcloud.com/29576 Reviewed-by: Jian Yu Reviewed-by: Andreas Dilger Tested-by: Jenkins Tested-by: Maloo --- lustre/include/lustre/lustreapi.h | 16 +++++++++++++++- lustre/lod/lod_object.c | 2 ++ lustre/tests/sanity-flr.sh | 32 ++++++++++++++++++++++++++++++++ lustre/utils/liblustreapi.c | 27 +++++++++------------------ 4 files changed, 58 insertions(+), 19 deletions(-) diff --git a/lustre/include/lustre/lustreapi.h b/lustre/include/lustre/lustreapi.h index f711ac0..ab87e15 100644 --- a/lustre/include/lustre/lustreapi.h +++ b/lustre/include/lustre/lustreapi.h @@ -450,7 +450,21 @@ int llapi_ladvise(int fd, unsigned long long flags, int num_advise, /* llapi_layout user interface */ -extern char *lcm_flags_string(__u16 flags); +static inline const char *lcm_flags_string(__u16 flags) +{ + switch (flags & LCM_FL_FLR_MASK) { + case LCM_FL_NOT_FLR: + return "not_flr"; + case LCM_FL_RDONLY: + return "ro"; + case LCM_FL_WRITE_PENDING: + return "wp"; + case LCM_FL_SYNC_PENDING: + return "sp"; + default: + return ""; + } +} /** * An array element storing component info to be resynced during mirror diff --git a/lustre/lod/lod_object.c b/lustre/lod/lod_object.c index 8d1622b..d9a09ae 100644 --- a/lustre/lod/lod_object.c +++ b/lustre/lod/lod_object.c @@ -3987,6 +3987,8 @@ static void lod_striping_from_default(struct lod_object *lo, return; lo->ldo_is_composite = lds->lds_def_striping_is_composite; + if (lds->lds_def_mirror_cnt > 1) + lo->ldo_flr_state = LCM_FL_RDONLY; for (i = 0; i < lo->ldo_comp_cnt; i++) { struct lod_layout_component *obj_comp = diff --git a/lustre/tests/sanity-flr.sh b/lustre/tests/sanity-flr.sh index b2e6ae8..56eb391 100644 --- a/lustre/tests/sanity-flr.sh +++ b/lustre/tests/sanity-flr.sh @@ -617,6 +617,38 @@ test_3() { } run_test 3 "create components from files located on different MDTs" +test_4() { + local tf=$DIR/$tdir/$tfile + local ids=() + + test_mkdir $DIR/$tdir + + # set mirror with setstripe options to directory + $LFS mirror create -N2 -E 1M -E eof $DIR/$tdir || + error "set mirror to directory error" + + [ x$($LFS getstripe -v $DIR/$tdir | awk '/lcm_flags/{print $2}') = \ + x"mirrored" ] || error "failed to create mirrored dir" + + touch $tf + verify_mirror_count $tf 2 + + ids=($($LFS getstripe $tf | awk '/lcme_id/{print $2}' | tr '\n' ' ')) + verify_comp_extent $tf ${ids[0]} 0 1048576 + verify_comp_extent $tf ${ids[1]} 1048576 EOF + + # sub directory should inherit mirror setting from parent + test_mkdir $DIR/$tdir/td + [ x$($LFS getstripe -v $DIR/$tdir/td | awk '/lcm_flags/{print $2}') = \ + x"mirrored" ] || error "failed to inherit mirror from parent" + + # mirror extend won't be applied to directory + $LFS mirror extend -N2 $DIR/$tdir && + error "expecting mirror extend failure" + true +} +run_test 4 "Make sure mirror attributes can be inhertied from directory" + test_21() { local tf=$DIR/$tfile local tf2=$DIR/$tfile-2 diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index ecac4c3..dde4ed1 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -2593,22 +2593,6 @@ void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name, llapi_printf(LLAPI_MSG_NORMAL, "\n"); } -char *lcm_flags_string(__u16 flags) -{ - switch (flags & LCM_FL_FLR_MASK) { - case LCM_FL_NOT_FLR: - return "not_flr"; - case LCM_FL_RDONLY: - return "ro"; - case LCM_FL_WRITE_PENDING: - return "wp"; - case LCM_FL_SYNC_PENDING: - return "sp"; - default: - return ""; - } -} - static void lov_dump_comp_v1_header(struct find_param *param, char *path, enum lov_dump_flags flags) { @@ -2627,8 +2611,15 @@ static void lov_dump_comp_v1_header(struct find_param *param, char *path, " ", comp_v1->lcm_magic); llapi_printf(LLAPI_MSG_NORMAL, "%2slcm_size: %u\n", " ", comp_v1->lcm_size); - llapi_printf(LLAPI_MSG_NORMAL, "%2slcm_flags: %s\n", - " ", lcm_flags_string(comp_v1->lcm_flags)); + if (flags & LDF_IS_DIR) + llapi_printf(LLAPI_MSG_NORMAL, + "%2slcm_flags: %s\n", " ", + comp_v1->lcm_mirror_count > 0 ? + "mirrored" : ""); + else + llapi_printf(LLAPI_MSG_NORMAL, + "%2slcm_flags: %s\n", + " ", lcm_flags_string(comp_v1->lcm_flags)); } if (verbose & VERBOSE_GENERATION) { -- 1.8.3.1