From: Andreas Dilger Date: Wed, 3 Oct 2018 22:41:56 +0000 (-0600) Subject: LU-11124 utils: add "lfs getstripe -N" option X-Git-Tag: 2.12.0-RC1~142 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=818340364d51ac9fb97151b0c244c4e2fd477715 LU-11124 utils: add "lfs getstripe -N" option Add an "lfs getstripe -N" option to print the number of mirrors on a file. The code for printing the mirror count was already in liblustreapi.c, but there was no option to request only this value to be printed. Move the VERBOSE_* flags into an enum and change the various functions and structures using these flags to use the enum. Rename a few of the constants to be more specific, but add compatibility definitions. Use "lfs getstripe -N" in sanity-flr and sanity-lfsck for mirror count instead of parsing the mirror count from the verbose layout. Signed-off-by: Andreas Dilger Change-Id: Iafd111c25e22d94153596f9bd4a16750548cab07 Reviewed-on: https://review.whamcloud.com/33280 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Jian Yu Reviewed-by: Emoly Liu Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/lustre/lustreapi.h b/lustre/include/lustre/lustreapi.h index 69b1d2e..7a29c13 100644 --- a/lustre/include/lustre/lustreapi.h +++ b/lustre/include/lustre/lustreapi.h @@ -149,32 +149,39 @@ int llapi_file_lookup(int dirfd, const char *name); void llapi_set_command_name(const char *cmd); void llapi_clear_command_name(void); -#define VERBOSE_COUNT 0x1 -#define VERBOSE_SIZE 0x2 -#define VERBOSE_OFFSET 0x4 -#define VERBOSE_POOL 0x8 -#define VERBOSE_DETAIL 0x10 -#define VERBOSE_OBJID 0x20 -#define VERBOSE_GENERATION 0x40 -#define VERBOSE_MDTINDEX 0x80 -#define VERBOSE_LAYOUT 0x100 -#define VERBOSE_COMP_COUNT 0x200 -#define VERBOSE_COMP_FLAGS 0x400 -#define VERBOSE_COMP_START 0x800 -#define VERBOSE_COMP_END 0x1000 -#define VERBOSE_COMP_ID 0x2000 -#define VERBOSE_DFID 0x4000 -#define VERBOSE_HASH_TYPE 0x8000 -#define VERBOSE_MIRROR_COUNT 0x10000 -#define VERBOSE_MIRROR_ID 0x20000 -#define VERBOSE_DEFAULT (VERBOSE_COUNT | VERBOSE_SIZE | \ - VERBOSE_OFFSET | VERBOSE_POOL | \ - VERBOSE_OBJID | VERBOSE_GENERATION | \ - VERBOSE_LAYOUT | VERBOSE_HASH_TYPE | \ - VERBOSE_COMP_COUNT | VERBOSE_COMP_FLAGS | \ - VERBOSE_COMP_START | VERBOSE_COMP_END | \ - VERBOSE_COMP_ID | VERBOSE_MIRROR_COUNT| \ - VERBOSE_MIRROR_ID) +enum llapi_layout_verbose { + VERBOSE_STRIPE_COUNT = 0x1, + VERBOSE_STRIPE_SIZE = 0x2, + VERBOSE_STRIPE_OFFSET = 0x4, + VERBOSE_POOL = 0x8, + VERBOSE_DETAIL = 0x10, + VERBOSE_OBJID = 0x20, + VERBOSE_GENERATION = 0x40, + VERBOSE_MDTINDEX = 0x80, + VERBOSE_PATTERN = 0x100, + VERBOSE_COMP_COUNT = 0x200, + VERBOSE_COMP_FLAGS = 0x400, + VERBOSE_COMP_START = 0x800, + VERBOSE_COMP_END = 0x1000, + VERBOSE_COMP_ID = 0x2000, + VERBOSE_DFID = 0x4000, + VERBOSE_HASH_TYPE = 0x8000, + VERBOSE_MIRROR_COUNT = 0x10000, + VERBOSE_MIRROR_ID = 0x20000, + VERBOSE_DEFAULT = VERBOSE_STRIPE_COUNT | VERBOSE_STRIPE_SIZE | + VERBOSE_STRIPE_OFFSET | VERBOSE_POOL | + VERBOSE_OBJID | VERBOSE_GENERATION | + VERBOSE_PATTERN | VERBOSE_HASH_TYPE | + VERBOSE_COMP_COUNT | VERBOSE_COMP_FLAGS | + VERBOSE_COMP_START | VERBOSE_COMP_END | + VERBOSE_COMP_ID | VERBOSE_MIRROR_COUNT | + VERBOSE_MIRROR_ID +}; +/* Compatibility with original names */ +#define VERBOSE_SIZE VERBOSE_STRIPE_SIZE +#define VERBOSE_COUNT VERBOSE_STRIPE_COUNT +#define VERBOSE_OFFSET VERBOSE_STRIPE_OFFSET +#define VERBOSE_LAYOUT VERBOSE_PATTERN struct find_param { unsigned int fp_max_depth; @@ -258,7 +265,7 @@ struct find_param { fp_check_blocks:1, fp_exclude_blocks:1; - int fp_verbose; + enum llapi_layout_verbose fp_verbose; int fp_quiet; /* regular expression */ diff --git a/lustre/tests/sanity-flr.sh b/lustre/tests/sanity-flr.sh index d48003b..60a154c 100644 --- a/lustre/tests/sanity-flr.sh +++ b/lustre/tests/sanity-flr.sh @@ -87,7 +87,7 @@ start_osts() { verify_mirror_count() { local tf=$1 local expected=$2 - local mirror_count=$(get_mirror_ids $tf) + local mirror_count=$($LFS getstripe -N $tf) [[ $mirror_count = $expected ]] || { $LFS getstripe -v $tf @@ -982,7 +982,7 @@ test_32() { error "extending mirrored file $DIR/$tfile failed" # make sure the mirrored file was created successfully - [ $(get_mirror_ids $DIR/$tfile) -eq 2 ] || + [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] || { $LFS getstripe $DIR/$tfile; error "expected 2 mirrors"; } drop_client_cache @@ -1031,7 +1031,7 @@ test_33() { "without verification failed" # make sure that $tfile has two mirrors and $tfile-2 does not exist - [ $(get_mirror_ids $DIR/$tfile) -eq 2 ] || + [ $($LFS getstripe -N $DIR/$tfile) -eq 2 ] || { $LFS getstripe $DIR/$tfile; error "expected count 2"; } [[ ! -e $DIR/$tfile-2 ]] || error "$DIR/$tfile-2 was not unlinked" @@ -1203,7 +1203,7 @@ test_36() { create_file_36 $tf $tf-2 $tf-3 - [ $(get_mirror_ids $tf) -gt 1 ] || error "wrong mirror count" + [ $($LFS getstripe -N $tf) -gt 1 ] || error "wrong mirror count" # test case 1 - check file write and verify layout version $MULTIOP $tf oO_WRONLY:c || @@ -1219,13 +1219,13 @@ test_36() { verify_ost_layout_version $tf # test case 2 - local mds_idx=mds$(($($LFS getstripe -m $tf-2) + 1)) + local mds_facet=mds$(($($LFS getstripe -m $tf-2) + 1)) local delay_sec=10 - do_facet $mds_idx $LCTL set_param fail_val=$delay_sec + do_facet $mds_facet $LCTL set_param fail_val=$delay_sec #define OBD_FAIL_FLR_LV_DELAY 0x1A01 - do_facet $mds_idx $LCTL set_param fail_loc=0x1A01 + do_facet $mds_facet $LCTL set_param fail_loc=0x1A01 # write should take at least $fail_loc seconds and succeed local st=$(date +%s) @@ -1237,19 +1237,19 @@ test_36() { # verify OST layout version verify_ost_layout_version $tf - do_facet $mds_idx $LCTL set_param fail_loc=0 + do_facet $mds_facet $LCTL set_param fail_loc=0 # test case 3 mds_idx=mds$(($($LFS getstripe -m $tf-3) + 1)) #define OBD_FAIL_FLR_LV_INC 0x1A02 - do_facet $mds_idx $LCTL set_param fail_loc=0x1A02 + do_facet $mds_facet $LCTL set_param fail_loc=0x1A02 # write open file should return error $MULTIOP $tf-3 oO_WRONLY:O_SYNC:w1024c && error "write a mirrored file succeeded" || true - do_facet $mds_idx $LCTL set_param fail_loc=0 + do_facet $mds_facet $LCTL set_param fail_loc=0 } run_test 36 "write to mirrored files" diff --git a/lustre/tests/sanity-lfsck.sh b/lustre/tests/sanity-lfsck.sh index 2edd765..468478c 100644 --- a/lustre/tests/sanity-lfsck.sh +++ b/lustre/tests/sanity-lfsck.sh @@ -5204,13 +5204,6 @@ test_35() } run_test 35 "LFSCK can rebuild the lost agent entry" -# It will be replaced by "lfs getstripe -N" via LU-11124. -get_mirrors_count() { - local mirrors=$($LFS getstripe $1 | - awk '/lcm_mirror_count/ { print $2 }') - echo $mirrors -} - test_36a() { [ $OSTCOUNT -lt 3 ] && skip "needs >= 3 OSTs" && return @@ -5280,11 +5273,11 @@ test_36a() { local mirrors - mirrors=$(get_mirrors_count $DIR/$tdir/f0) + mirrors=$($LFS getstripe -N $DIR/$tdir/f0) [ $mirrors -eq 2 ] || error "(18) $DIR/$tdir/f0 has $mirrors mirrors" - mirrors=$(get_mirrors_count $DIR/$tdir/f1) + mirrors=$($LFS getstripe -N $DIR/$tdir/f1) [ $mirrors -eq 2 ] || error "(19) $DIR/$tdir/f1 has $mirrors mirrors" - mirrors=$(get_mirrors_count $DIR/$tdir/f2) + mirrors=$($LFS getstripe -N $DIR/$tdir/f2) [ $mirrors -eq 2 ] || error "(20) $DIR/$tdir/f2 has $mirrors mirrors" echo "Trigger layout LFSCK on all devices to find out orphan OST-object" @@ -5314,11 +5307,11 @@ test_36a() { [ $repaired -eq 9 ] || error "(24) Expect 9 fixed on mds1, but got: $repaired" - mirrors=$(get_mirrors_count $DIR/$tdir/f0) + mirrors=$($LFS getstripe -N $DIR/$tdir/f0) [ $mirrors -eq 3 ] || error "(25) $DIR/$tdir/f0 has $mirrors mirrors" - mirrors=$(get_mirrors_count $DIR/$tdir/f1) + mirrors=$($LFS getstripe -N $DIR/$tdir/f1) [ $mirrors -eq 3 ] || error "(26) $DIR/$tdir/f1 has $mirrors mirrors" - mirrors=$(get_mirrors_count $DIR/$tdir/f2) + mirrors=$($LFS getstripe -N $DIR/$tdir/f2) [ $mirrors -eq 3 ] || error "(27) $DIR/$tdir/f2 has $mirrors mirrors" $LFS getstripe $DIR/$tdir/f0 | grep "lcme_mirror_id:.*1" || { @@ -5402,11 +5395,11 @@ test_36b() { [ $count -eq 9 ] || error "(8) Expect 9 fixed on mds1, but got: $count" local name=$MOUNT/.lustre/lost+found/MDT0000/${fid}-R-0 - count=$($LFS getstripe $name | awk '/lcm_mirror_count/ { print $2 }') + count=$($LFS getstripe --mirror-count $name) [ $count -eq 3 ] || error "(9) $DIR/$tdir/f0 has $count mirrors" - count=$($LFS getstripe $name | awk '/lcm_entry_count/ { print $2 }') - [ $count -eq 6 ] || error "(10) $DIR/$tdir/f0 has $count entries" + count=$($LFS getstripe --component-count $name) + [ $count -eq 6 ] || error "(10) $DIR/$tdir/f0 has $count components" $LFS getstripe $name | grep "lcme_mirror_id:.*1" || { $LFS getstripe $name @@ -5499,11 +5492,11 @@ test_36c() { [ $count -eq 6 ] || error "(7) Expect 9 fixed on mds1, but got: $count" local name=$MOUNT/.lustre/lost+found/MDT0000/${fid}-R-0 - count=$($LFS getstripe $name | awk '/lcm_mirror_count/ { print $2 }') + count=$($LFS getstripe --mirror-count $name) [ $count -eq 2 ] || error "(8) $DIR/$tdir/f0 has $count mirrors" - count=$($LFS getstripe $name | awk '/lcm_entry_count/ { print $2 }') - [ $count -eq 4 ] || error "(9) $DIR/$tdir/f0 has $count entries" + count=$($LFS getstripe --component-count $name) + [ $count -eq 4 ] || error "(9) $DIR/$tdir/f0 has $count components" local flags=$($LFS getstripe $name | head -n 10 | awk '/lcme_flags/ { print $2 }') diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 582685e..bf5d3ce 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -4128,6 +4128,7 @@ static int lfs_getstripe_internal(int argc, char **argv, { .val = 'm', .name = "mdt_index", .has_arg = no_argument }, /* find { .val = 'M', .name = "mtime", .has_arg = required_argument }*/ /* find { .val = 'n', .name = "name", .has_arg = required_argument }*/ + { .val = 'N', .name = "mirror-count", .has_arg = no_argument }, { .val = 'O', .name = "obd", .has_arg = required_argument }, { .val = 'O', .name = "ost", .has_arg = required_argument }, { .val = 'p', .name = "pool", .has_arg = no_argument }, @@ -4151,7 +4152,7 @@ static int lfs_getstripe_internal(int argc, char **argv, char *end, *tmp; while ((c = getopt_long(argc, argv, - "-cdDE::FghiI::LmMoO:pqrRsSvy", + "-cdDE::FghiI::LmMNoO:pqrRsSvy", long_opts, NULL)) != -1) { if (neg_opt) --neg_opt; @@ -4332,7 +4333,7 @@ static int lfs_getstripe_internal(int argc, char **argv, break; case 'i': if (!(param->fp_verbose & VERBOSE_DETAIL)) { - param->fp_verbose |= VERBOSE_OFFSET; + param->fp_verbose |= VERBOSE_STRIPE_OFFSET; param->fp_max_depth = 0; } break; @@ -4355,7 +4356,7 @@ static int lfs_getstripe_internal(int argc, char **argv, break; case 'L': if (!(param->fp_verbose & VERBOSE_DETAIL)) { - param->fp_verbose |= VERBOSE_LAYOUT; + param->fp_verbose |= VERBOSE_PATTERN; param->fp_max_depth = 0; } break; @@ -4369,6 +4370,12 @@ static int lfs_getstripe_internal(int argc, char **argv, param->fp_max_depth = 0; param->fp_verbose |= VERBOSE_MDTINDEX; break; + case 'N': + if (!(param->fp_verbose & VERBOSE_DETAIL)) { + param->fp_verbose |= VERBOSE_MIRROR_COUNT; + param->fp_max_depth = 0; + } + break; case 'O': if (param->fp_obd_uuid) { fprintf(stderr, @@ -4395,7 +4402,7 @@ static int lfs_getstripe_internal(int argc, char **argv, break; case 'S': if (!(param->fp_verbose & VERBOSE_DETAIL)) { - param->fp_verbose |= VERBOSE_SIZE; + param->fp_verbose |= VERBOSE_STRIPE_SIZE; param->fp_max_depth = 0; } break; @@ -4520,7 +4527,7 @@ static int lfs_getdirstripe(int argc, char **argv) break; case 'i': case 'm': - param.fp_verbose |= VERBOSE_OFFSET; + param.fp_verbose |= VERBOSE_STRIPE_OFFSET; break; #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0) case 't': diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index c17c68a..5f95d44 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -2484,7 +2484,8 @@ enum lov_dump_flags { static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, struct lov_user_ost_data_v1 *objects, - int verbose, int depth, char *pool_name, + enum llapi_layout_verbose verbose, + int depth, char *pool_name, enum lov_dump_flags flags) { bool is_dir = flags & LDF_IS_DIR; @@ -2555,8 +2556,8 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, seq, oid, ver); } - if (verbose & VERBOSE_COUNT) { - if (verbose & ~VERBOSE_COUNT) + if (verbose & VERBOSE_STRIPE_COUNT) { + if (verbose & ~VERBOSE_STRIPE_COUNT) llapi_printf(LLAPI_MSG_NORMAL, "%s%sstripe_count: ", space, prefix); if (is_dir) { @@ -2589,9 +2590,9 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, separator = "\n"; } - if (verbose & VERBOSE_SIZE) { + if (verbose & VERBOSE_STRIPE_SIZE) { llapi_printf(LLAPI_MSG_NORMAL, "%s", separator); - if (verbose & ~VERBOSE_SIZE) + if (verbose & ~VERBOSE_STRIPE_SIZE) llapi_printf(LLAPI_MSG_NORMAL, "%s%sstripe_size: ", space, prefix); if (is_dir && !is_raw && lum->lmm_stripe_size == 0) { @@ -2614,9 +2615,9 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, separator = "\n"; } - if ((verbose & VERBOSE_LAYOUT)) { + if ((verbose & VERBOSE_PATTERN)) { llapi_printf(LLAPI_MSG_NORMAL, "%s", separator); - if (verbose & ~VERBOSE_LAYOUT) + if (verbose & ~VERBOSE_PATTERN) llapi_printf(LLAPI_MSG_NORMAL, "%s%spattern: ", space, prefix); if (lov_pattern_supported(lum->lmm_pattern)) @@ -2637,9 +2638,9 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, separator = "\n"; } - if (verbose & VERBOSE_OFFSET) { + if (verbose & VERBOSE_STRIPE_OFFSET) { llapi_printf(LLAPI_MSG_NORMAL, "%s", separator); - if (verbose & ~VERBOSE_OFFSET) + if (verbose & ~VERBOSE_STRIPE_OFFSET) llapi_printf(LLAPI_MSG_NORMAL, "%s%sstripe_offset: ", space, prefix); if (is_dir || skip_objs) @@ -2677,7 +2678,8 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name, struct lov_user_ost_data_v1 *objects, char *path, int obdindex, int depth, - int header, enum lov_dump_flags flags) + enum llapi_layout_verbose verbose, + enum lov_dump_flags flags) { bool is_dir = flags & LDF_IS_DIR; bool indent = flags & LDF_INDENT; @@ -2698,10 +2700,10 @@ void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name, if (!obdstripe) return; - lov_dump_user_lmm_header(lum, path, objects, header, depth, pool_name, + lov_dump_user_lmm_header(lum, path, objects, verbose, depth, pool_name, flags); - if (!is_dir && !skip_objs && (header & VERBOSE_OBJID) && + if (!is_dir && !skip_objs && (verbose & VERBOSE_OBJID) && !(lum->lmm_pattern & LOV_PATTERN_F_RELEASED || lov_pattern(lum->lmm_pattern) == LOV_PATTERN_MDT)) { char *space = " - "; @@ -2756,7 +2758,8 @@ void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name, } void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name, - char *path, int obdindex, int depth, int verbose, + char *path, int obdindex, int depth, + enum llapi_layout_verbose verbose, enum lov_dump_flags flags) { struct lmv_user_mds_data *objects = lum->lum_objects; @@ -2791,8 +2794,8 @@ void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name, /* show all information default */ if (!verbose) { if (lum->lum_magic == LMV_USER_MAGIC) - verbose = VERBOSE_POOL | VERBOSE_COUNT | - VERBOSE_OFFSET | VERBOSE_HASH_TYPE; + verbose = VERBOSE_POOL | VERBOSE_STRIPE_COUNT | + VERBOSE_STRIPE_OFFSET | VERBOSE_HASH_TYPE; else verbose = VERBOSE_OBJID; } @@ -2800,21 +2803,21 @@ void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name, if (depth && path && ((verbose != VERBOSE_OBJID))) llapi_printf(LLAPI_MSG_NORMAL, "%s%s\n", prefix, path); - if (verbose & VERBOSE_COUNT) { + if (verbose & VERBOSE_STRIPE_COUNT) { llapi_printf(LLAPI_MSG_NORMAL, "%s", separator); - if (verbose & ~VERBOSE_COUNT) + if (verbose & ~VERBOSE_STRIPE_COUNT) llapi_printf(LLAPI_MSG_NORMAL, "lmv_stripe_count: "); llapi_printf(LLAPI_MSG_NORMAL, "%u", (int)lum->lum_stripe_count); - if ((verbose & VERBOSE_OFFSET) && !yaml) + if ((verbose & VERBOSE_STRIPE_OFFSET) && !yaml) separator = " "; else separator = "\n"; } - if (verbose & VERBOSE_OFFSET) { + if (verbose & VERBOSE_STRIPE_OFFSET) { llapi_printf(LLAPI_MSG_NORMAL, "%s", separator); - if (verbose & ~VERBOSE_OFFSET) + if (verbose & ~VERBOSE_STRIPE_OFFSET) llapi_printf(LLAPI_MSG_NORMAL, "lmv_stripe_offset: "); llapi_printf(LLAPI_MSG_NORMAL, "%d", (int)lum->lum_stripe_offset); @@ -2875,7 +2878,7 @@ static void lov_dump_comp_v1_header(struct find_param *param, char *path, { struct lov_comp_md_v1 *comp_v1 = (void *)¶m->fp_lmd->lmd_lmm; int depth = param->fp_max_depth; - int verbose = param->fp_verbose; + enum llapi_layout_verbose verbose = param->fp_verbose; bool yaml = flags & LDF_YAML; if (depth && path && ((verbose != VERBOSE_OBJID) || @@ -2960,7 +2963,7 @@ static void lov_dump_comp_v1_entry(struct find_param *param, struct lov_comp_md_v1 *comp_v1 = (void *)¶m->fp_lmd->lmd_lmm; struct lov_comp_md_entry_v1 *entry; char *separator = ""; - int verbose = param->fp_verbose; + enum llapi_layout_verbose verbose = param->fp_verbose; bool yaml = flags & LDF_YAML; entry = &comp_v1->lcm_entries[index]; @@ -3392,7 +3395,7 @@ static void lov_dump_comp_v1(struct find_param *param, char *path, static inline bool has_any_comp_options(struct find_param *param) { - int verbose = param->fp_verbose; + enum llapi_layout_verbose verbose = param->fp_verbose; if (param->fp_check_comp_id || param->fp_check_comp_count || param->fp_check_comp_start || param->fp_check_comp_end ||