From: Bobi Jam Date: Tue, 18 Apr 2017 09:00:55 +0000 (+0800) Subject: LU-9324 lfs: output stripe info in YAML format X-Git-Tag: 2.9.58~49 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=8bbbd4ea4f10a6d907ff0885d6c8334dacd748a6;p=fs%2Flustre-release.git LU-9324 lfs: output stripe info in YAML format Add --yaml|-y for lfs getstripe to output plain/PFL layout file's stripe information in YAML format. Signed-off-by: Bobi Jam Change-Id: Ic6a3bf3572346f06ed90f75945acf374efd0fd96 Reviewed-on: https://review.whamcloud.com/26708 Reviewed-by: Andreas Dilger Reviewed-by: Niu Yawei Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/lustre/lustreapi.h b/lustre/include/lustre/lustreapi.h index 397abf6..d701f52 100644 --- a/lustre/include/lustre/lustreapi.h +++ b/lustre/include/lustre/lustreapi.h @@ -221,7 +221,8 @@ struct find_param { fp_check_mdt_count:1, fp_exclude_mdt_count:1, fp_check_hash_type:1, - fp_exclude_hash_type:1; + fp_exclude_hash_type:1, + fp_yaml:1; /* output layout in YAML */ int fp_verbose; int fp_quiet; diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index e8afb01..7406999 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -200,7 +200,7 @@ command_t cmdlist[] = { "usage: getstripe [--ost|-O ] [--quiet|-q] [--verbose|-v]\n" " [--stripe-count|-c] [--stripe-index|-i]\n" " [--pool|-p] [--stripe-size|-S] [--directory|-d]\n" - " [--mdt|-m] [--recursive|-r] [--raw|-R]\n" + " [--mdt|-m] [--recursive|-r] [--raw|-R] [--yaml|-y]\n" " [--layout|-L] [--fid|-F] [--generation|-g]\n" " [--component-id|-I [comp_id]]\n" " [--component-flags [comp_flags]]\n" @@ -217,8 +217,9 @@ command_t cmdlist[] = { "To list the striping info for a given directory\n" "or recursively for all directories in a directory tree.\n" "usage: getdirstripe [--obd|-O ] [--mdt-count|-c]\n" - " [--mdt-index|-i] [--mdt-hash|-H]\n" - " [--recursive|-r] [--default|-D] ..."}, + " [--mdt-index|-i] [--mdt-hash|-t]\n" + " [--recursive|-r] [--yaml|-y]\n" + " [--default|-D] ..."}, {"mkdir", lfs_setdirstripe, 0, "To create a striped directory on a specified MDT. This can only\n" "be done on MDT0 with the right of administrator.\n" @@ -2378,12 +2379,13 @@ static int lfs_getstripe_internal(int argc, char **argv, {"stripe_size", no_argument, 0, 'S'}, /* dirstripe {"mdt-count", required_argument, 0, 'T'}, */ {"verbose", no_argument, 0, 'v'}, + {"yaml", no_argument, 0, 'y'}, {0, 0, 0, 0} }; int c, rc; char *end, *tmp; - while ((c = getopt_long(argc, argv, "cdDE:FghiI:LmMoO:pqrRsSv", + while ((c = getopt_long(argc, argv, "cdDE:FghiI:LmMoO:pqrRsSvy", long_opts, NULL)) != -1) { switch (c) { case 'c': @@ -2571,6 +2573,9 @@ static int lfs_getstripe_internal(int argc, char **argv, case 'v': param->fp_verbose = VERBOSE_DEFAULT | VERBOSE_DETAIL; break; + case 'y': + param->fp_yaml = 1; + break; default: return CMD_HELP; } @@ -2662,6 +2667,7 @@ static int lfs_getdirstripe(int argc, char **argv) {"default", no_argument, 0, 'D'}, {"obd", required_argument, 0, 'O'}, {"mdt-count", no_argument, 0, 'T'}, + {"yaml", no_argument, 0, 'y'}, {0, 0, 0, 0} }; int c, rc; @@ -2669,7 +2675,7 @@ static int lfs_getdirstripe(int argc, char **argv) param.fp_get_lmv = 1; while ((c = getopt_long(argc, argv, - "cDHiO:rtT", long_opts, NULL)) != -1) + "cDHiO:rtTy", long_opts, NULL)) != -1) { switch (c) { case 'O': @@ -2706,6 +2712,9 @@ static int lfs_getdirstripe(int argc, char **argv) case 'r': param.fp_recursive = 1; break; + case 'y': + param.fp_yaml = 1; + break; default: return CMD_HELP; } diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 06d3702..8563c92 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -2196,6 +2196,7 @@ enum lov_dump_flags { LDF_IS_RAW = 0x0002, LDF_INDENT = 0x0004, LDF_SKIP_OBJS = 0x0008, + LDF_YAML = 0x0010, }; static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, @@ -2206,6 +2207,7 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, bool is_dir = flags & LDF_IS_DIR; bool is_raw = flags & LDF_IS_RAW; bool indent = flags & LDF_INDENT; + bool yaml = flags & LDF_YAML; bool skip_objs = flags & LDF_SKIP_OBJS; char *prefix = is_dir ? "" : "lmm_"; char *separator = ""; @@ -2218,7 +2220,8 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, llapi_printf(LLAPI_MSG_NORMAL, "%s(Default) ", space); } - if (!indent && depth && path && ((verbose != VERBOSE_OBJID) || !is_dir)) + if (!yaml && !indent && depth && path && + ((verbose != VERBOSE_OBJID) || !is_dir)) llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path); if ((verbose & VERBOSE_DETAIL) && !is_dir) { @@ -2232,6 +2235,10 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, (uintmax_t)lmm_oi_id(&lum->lmm_oi)); } if ((verbose & (VERBOSE_DETAIL | VERBOSE_DFID)) && !is_dir) { + __u64 seq; + __u32 oid; + __u32 ver; + if (verbose & ~VERBOSE_DFID) llapi_printf(LLAPI_MSG_NORMAL, "%slmm_fid: ", space); @@ -2252,13 +2259,17 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, * separate lmm_oi_seq() and lmm_oi_id() routines for this. * * For newer layout types hopefully this will be a real FID. */ - llapi_printf(LLAPI_MSG_NORMAL, DFID"\n", - lmm_oi_seq(&lum->lmm_oi) == 0 ? - lmm_oi_id(&lum->lmm_oi) : - lmm_oi_seq(&lum->lmm_oi), - lmm_oi_seq(&lum->lmm_oi) == 0 ? - 0 : (__u32)lmm_oi_id(&lum->lmm_oi), - (__u32)(lmm_oi_id(&lum->lmm_oi) >> 32)); + seq = lmm_oi_seq(&lum->lmm_oi) == 0 ? + lmm_oi_id(&lum->lmm_oi) : lmm_oi_seq(&lum->lmm_oi); + oid = lmm_oi_seq(&lum->lmm_oi) == 0 ? + 0 : (__u32)lmm_oi_id(&lum->lmm_oi); + ver = (__u32)(lmm_oi_id(&lum->lmm_oi) >> 32); + if (yaml) + llapi_printf(LLAPI_MSG_NORMAL, DFID_NOBRACE"\n", + seq, oid, ver); + else + llapi_printf(LLAPI_MSG_NORMAL, DFID"\n", + seq, oid, ver); } if (verbose & VERBOSE_COUNT) { @@ -2288,7 +2299,10 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, llapi_printf(LLAPI_MSG_NORMAL, "%hd", (__s16)lum->lmm_stripe_count); } - separator = is_dir ? " " : "\n"; + if (!yaml && is_dir) + separator = " "; + else + separator = "\n"; } if (verbose & VERBOSE_SIZE) { @@ -2310,7 +2324,10 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, llapi_printf(LLAPI_MSG_NORMAL, "%u", lum->lmm_stripe_size); } - separator = is_dir ? " " : "\n"; + if (!yaml && is_dir) + separator = " "; + else + separator = "\n"; } if ((verbose & VERBOSE_LAYOUT) && !is_dir) { @@ -2345,7 +2362,10 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, else llapi_printf(LLAPI_MSG_NORMAL, "%u", objects[0].l_ost_idx); - separator = is_dir ? " " : "\n"; + if (!yaml && is_dir) + separator = " "; + else + separator = "\n"; } if ((verbose & VERBOSE_POOL) && pool_name && (pool_name[0] != '\0')) { @@ -2354,7 +2374,10 @@ static void lov_dump_user_lmm_header(struct lov_user_md *lum, char *path, llapi_printf(LLAPI_MSG_NORMAL, "%s%spool: ", space, prefix); llapi_printf(LLAPI_MSG_NORMAL, "%s", pool_name); - separator = is_dir ? " " : "\n"; + if (!yaml && is_dir) + separator = " "; + else + separator = "\n"; } if (strlen(separator) != 0) @@ -2369,6 +2392,7 @@ void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name, bool is_dir = flags & LDF_IS_DIR; bool indent = flags & LDF_INDENT; bool skip_objs = flags & LDF_SKIP_OBJS; + bool yaml = flags & LDF_YAML; int i, obdstripe = (obdindex != OBD_NOT_FOUND) ? 0 : 1; if (!obdstripe) { @@ -2393,6 +2417,8 @@ void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name, if (indent) llapi_printf(LLAPI_MSG_NORMAL, "%6slmm_objects:\n", " "); + else if (yaml) + llapi_printf(LLAPI_MSG_NORMAL, "lmm_objects:\n"); else llapi_printf(LLAPI_MSG_NORMAL, "\tobdidx\t\t objid\t\t objid\t\t group\n"); @@ -2405,7 +2431,16 @@ void lov_dump_user_lmm_v1v3(struct lov_user_md *lum, char *pool_name, if (obdindex != OBD_NOT_FOUND && obdindex != idx) continue; - if (indent) { + if (yaml) { + struct lu_fid fid = { 0 }; + + ostid_to_fid(&fid, &objects[i].l_ost_oi, idx); + llapi_printf(LLAPI_MSG_NORMAL, + "%sl_ost_idx: %d\n", space, idx); + llapi_printf(LLAPI_MSG_NORMAL, + "%8sl_fid: "DFID_NOBRACE"\n", + " ", PFID(&fid)); + } else if (indent) { struct lu_fid fid = { 0 }; ostid_to_fid(&fid, &objects[i].l_ost_oi, idx); @@ -2429,12 +2464,14 @@ 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, int verbose, + enum lov_dump_flags flags) { struct lmv_user_mds_data *objects = lum->lum_objects; char *prefix = lum->lum_magic == LMV_USER_MAGIC ? "(Default)" : ""; int i, obdstripe = 0; char *separator = ""; + bool yaml = flags & LDF_YAML; if (obdindex != OBD_NOT_FOUND) { if (lum->lum_stripe_count == 0) { @@ -2476,7 +2513,7 @@ void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name, llapi_printf(LLAPI_MSG_NORMAL, "lmv_stripe_count: "); llapi_printf(LLAPI_MSG_NORMAL, "%u", (int)lum->lum_stripe_count); - if (verbose & VERBOSE_OFFSET) + if ((verbose & VERBOSE_OFFSET) && !yaml) separator = " "; else separator = "\n"; @@ -2488,7 +2525,7 @@ void lmv_dump_user_lmm(struct lmv_user_md *lum, char *pool_name, llapi_printf(LLAPI_MSG_NORMAL, "lmv_stripe_offset: "); llapi_printf(LLAPI_MSG_NORMAL, "%d", (int)lum->lum_stripe_offset); - if (verbose & VERBOSE_HASH_TYPE) + if (verbose & VERBOSE_HASH_TYPE && !yaml) separator = " "; else separator = "\n"; @@ -2546,9 +2583,10 @@ 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; + bool yaml = flags & LDF_YAML; if (depth && path && ((verbose != VERBOSE_OBJID) || - !(flags & LDF_IS_DIR))) + !(flags & LDF_IS_DIR)) && !yaml) llapi_printf(LLAPI_MSG_NORMAL, "%s\n", path); if (verbose & VERBOSE_DETAIL) { @@ -2576,7 +2614,7 @@ static void lov_dump_comp_v1_header(struct find_param *param, char *path, comp_v1->lcm_entry_count); } - if (verbose & VERBOSE_DETAIL) + if (verbose & VERBOSE_DETAIL && !yaml) llapi_printf(LLAPI_MSG_NORMAL, "components:\n"); } @@ -2587,11 +2625,15 @@ static void lov_dump_comp_v1_entry(struct find_param *param, struct lov_comp_md_entry_v1 *entry; char *separator = ""; int verbose = param->fp_verbose; + bool yaml = flags & LDF_YAML; entry = &comp_v1->lcm_entries[index]; + if (yaml) + llapi_printf(LLAPI_MSG_NORMAL, "%2scomponent%d:\n", " ", index); + if (verbose & VERBOSE_COMP_ID) { - if (verbose & VERBOSE_DETAIL) + if (verbose & VERBOSE_DETAIL && !yaml) llapi_printf(LLAPI_MSG_NORMAL, "%slcme_id: ", " - "); else if (verbose & ~VERBOSE_COMP_ID) @@ -2636,7 +2678,10 @@ static void lov_dump_comp_v1_entry(struct find_param *param, separator = "\n"; } - if (verbose & VERBOSE_DETAIL) { + if (yaml) { + llapi_printf(LLAPI_MSG_NORMAL, "%s", separator); + llapi_printf(LLAPI_MSG_NORMAL, "%4ssub_layout:\n", " "); + } else if (verbose & VERBOSE_DETAIL) { llapi_printf(LLAPI_MSG_NORMAL, "%s", separator); llapi_printf(LLAPI_MSG_NORMAL, "%4slcme_offset: %u\n", " ", entry->lcme_offset); @@ -2870,6 +2915,8 @@ static void llapi_lov_dump_user_lmm(struct find_param *param, char *path, if (param->fp_raw) flags |= LDF_IS_RAW; + if (param->fp_yaml) + flags |= LDF_YAML; switch (magic) { case LOV_USER_MAGIC_V1: @@ -2900,7 +2947,8 @@ static void llapi_lov_dump_user_lmm(struct find_param *param, char *path, lum = (struct lmv_user_md *)param->fp_lmv_md; strlcpy(pool_name, lum->lum_pool_name, sizeof(pool_name)); lmv_dump_user_lmm(lum, pool_name, path, param->fp_obd_index, - param->fp_max_depth, param->fp_verbose); + param->fp_max_depth, param->fp_verbose, + flags); break; } case LOV_USER_MAGIC_COMP_V1: