X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=lustre%2Futils%2Flfs.c;h=079d2a04b533cac6574775fc4936445e78a48697;hb=c1d0a355a6a6;hp=a701711f06f45abd917679ee012d131240c9e218;hpb=b380a1f9a1daa1683593d0ee4a508da859277164;p=fs%2Flustre-release.git diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index a701711..079d2a0 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -147,6 +147,7 @@ enum setstripe_origin { SO_MIRROR_CREATE, SO_MIRROR_EXTEND, SO_MIRROR_SPLIT, + SO_MIRROR_DELETE, }; static int lfs_setstripe_internal(int argc, char **argv, enum setstripe_origin opc); @@ -171,6 +172,10 @@ static inline int lfs_mirror_split(int argc, char **argv) { return lfs_setstripe_internal(argc, argv, SO_MIRROR_SPLIT); } +static inline int lfs_mirror_delete(int argc, char **argv) +{ + return lfs_setstripe_internal(argc, argv, SO_MIRROR_DELETE); +} /* Setstripe and migrate share mostly the same parameters */ #define SSM_CMD_COMMON(cmd) \ @@ -288,19 +293,23 @@ command_t mirror_cmdlist[] = { .pc_help = "Create a mirrored file.\n" "usage: lfs mirror create " "<--mirror-count|-N[mirror_count]> " - "[setstripe options] ... \n" + "[setstripe options] ... ...\n" MIRROR_CREATE_HELP }, + { .pc_name = "delete", .pc_func = lfs_mirror_delete, + .pc_help = "delete a mirror from a file.\n" + "usage: lfs mirror delete {--comp-id|-I |-p } ...\n" + }, { .pc_name = "extend", .pc_func = lfs_mirror_extend, .pc_help = "Extend a mirrored file.\n" "usage: lfs mirror extend " "<--mirror-count|-N[mirror_count]> [--no-verify] " - "[setstripe options|-f ] ... \n" + "[setstripe options|-f ] ... ...\n" MIRROR_EXTEND_HELP }, { .pc_name = "split", .pc_func = lfs_mirror_split, .pc_help = "Split a mirrored file.\n" "usage: lfs mirror split <--mirror-id |\n" "\t <--component-id|-I |-p > [--destroy|-d]\n" - "\t [-f ] \n" + "\t [-f ] ...\n" "\tmirror_id: The numerical unique identifier for a mirror. It\n" "\t can be fetched by lfs getstripe command.\n" "\tcomp_id: Unique component ID within a mirror.\n" @@ -557,9 +566,7 @@ command_t cmdlist[] = { {"fid2path", lfs_fid2path, 0, "Resolve the full path(s) for given FID(s). For a specific hardlink " "specify link number .\n" - /* "For a historical link name, specify changelog record .\n" */ - "usage: fid2path [--link ] ..." - /* [ --rec ] */ }, + "usage: fid2path [-c] [--link|-l ] ..."}, {"path2fid", lfs_path2fid, 0, "Display the fid(s) for a given path(s).\n" "usage: path2fid [--parents] ..."}, {"rmfid", lfs_rmfid, 0, "Remove file(s) by FID(s)\n" @@ -703,9 +710,6 @@ static int check_hashtype(const char *hashtype) if (strcmp(hashtype, mdt_hash_name[i]) == 0) return i; - if (!strcmp(hashtype, LMV_HASH_NAME_SPACE)) - return LMV_HASH_TYPE_DEFAULT | LMV_HASH_FLAG_SPACE; - return 0; } @@ -2426,14 +2430,14 @@ new_comp: if (lsa->lsa_stripe_count != LLAPI_LAYOUT_DEFAULT) { fprintf(stderr, "Option 'stripe-count' can't be " "specified with Data-on-MDT component: %lld\n", - (long long)lsa->lsa_stripe_count); + lsa->lsa_stripe_count); errno = EINVAL; return -1; } if (lsa->lsa_stripe_size != LLAPI_LAYOUT_DEFAULT) { fprintf(stderr, "Option 'stripe-size' can't be " "specified with Data-on-MDT component: %llu\n", - (unsigned long long)lsa->lsa_stripe_size); + lsa->lsa_stripe_size); errno = EINVAL; return -1; } @@ -2447,7 +2451,7 @@ new_comp: if (lsa->lsa_stripe_off != LLAPI_LAYOUT_DEFAULT) { fprintf(stderr, "Option 'stripe-offset' can't be " "specified with Data-on-MDT component: %lld\n", - (long long)lsa->lsa_stripe_off); + lsa->lsa_stripe_off); errno = EINVAL; return -1; } @@ -2462,7 +2466,7 @@ new_comp: rc = llapi_layout_pattern_set(layout, lsa->lsa_pattern); if (rc) { fprintf(stderr, "Set stripe pattern %#llx failed. %s\n", - (unsigned long long)lsa->lsa_pattern, + lsa->lsa_pattern, strerror(errno)); return rc; } @@ -2472,7 +2476,7 @@ new_comp: rc = llapi_layout_pattern_set(layout, lsa->lsa_pattern); if (rc) { fprintf(stderr, "Set stripe pattern %#llx failed. %s\n", - (unsigned long long)lsa->lsa_pattern, + lsa->lsa_pattern, strerror(errno)); return rc; } @@ -2495,7 +2499,7 @@ new_comp: rc = llapi_layout_stripe_count_set(layout, lsa->lsa_stripe_count); if (rc) { fprintf(stderr, "Set stripe count %lld failed: %s\n", - (long long)lsa->lsa_stripe_count, strerror(errno)); + lsa->lsa_stripe_count, strerror(errno)); return rc; } @@ -2521,7 +2525,7 @@ new_comp: lsa->lsa_stripe_count != LLAPI_LAYOUT_WIDE && lsa->lsa_nr_tgts != lsa->lsa_stripe_count) { fprintf(stderr, "stripe_count(%lld) != nr_tgts(%d)\n", - (long long)lsa->lsa_stripe_count, + lsa->lsa_stripe_count, lsa->lsa_nr_tgts); errno = EINVAL; return -1; @@ -3078,6 +3082,7 @@ static int lfs_setstripe_internal(int argc, char **argv, { .val = 'i', .name = "stripe_index", .has_arg = required_argument}, { .val = 'I', .name = "comp-id", .has_arg = required_argument}, { .val = 'I', .name = "component-id", .has_arg = required_argument}, +/* find { .val = 'l', .name = "lazy", .has_arg = no_argument }, */ { .val = 'L', .name = "layout", .has_arg = required_argument }, { .val = 'm', .name = "mdt", .has_arg = required_argument}, { .val = 'm', .name = "mdt-index", .has_arg = required_argument}, @@ -3114,6 +3119,10 @@ static int lfs_setstripe_internal(int argc, char **argv, migrate_mode = (opc == SO_MIGRATE); mirror_mode = (opc == SO_MIRROR_CREATE || opc == SO_MIRROR_EXTEND); setstripe_mode = (opc == SO_SETSTRIPE); + if (opc == SO_MIRROR_DELETE) { + delete = 1; + mirror_flags = MF_DESTROY; + } snprintf(cmd, sizeof(cmd), "%s %s", progname, argv[0]); progname = cmd; @@ -3716,11 +3725,11 @@ static int lfs_setstripe_internal(int argc, char **argv, goto usage_error; } - if (!comp_del && !comp_set && (opc != SO_MIRROR_SPLIT) && - comp_id != 0) { + if (!comp_del && !comp_set && opc != SO_MIRROR_SPLIT && + opc != SO_MIRROR_DELETE && comp_id != 0) { fprintf(stderr, - "%s %s: option -I can only be used with --component-del or --component-set or lfs mirror split\n", - progname, argv[0]); + "%s: option -I can only be used with --component-del or --component-set or lfs mirror split\n", + progname); goto usage_error; } @@ -3764,8 +3773,7 @@ static int lfs_setstripe_internal(int argc, char **argv, lsa.lsa_stripe_count != lsa.lsa_nr_tgts) { fprintf(stderr, "error: %s: stripe count %lld doesn't match the number of MDTs: %d\n", - progname, - (long long)lsa.lsa_stripe_count, + progname, lsa.lsa_stripe_count, lsa.lsa_nr_tgts); free(lmu); goto usage_error; @@ -3822,8 +3830,7 @@ static int lfs_setstripe_internal(int argc, char **argv, lsa.lsa_nr_tgts != lsa.lsa_stripe_count) { fprintf(stderr, "error: %s: stripe count %lld doesn't match the number of OSTs: %d\n", - argv[0], - (long long)lsa.lsa_stripe_count, + argv[0], lsa.lsa_stripe_count, lsa.lsa_nr_tgts); free(param); goto usage_error; @@ -3877,11 +3884,11 @@ static int lfs_setstripe_internal(int argc, char **argv, } else if (opc == SO_MIRROR_EXTEND) { result = mirror_extend(fname, mirror_list, mirror_flags); - } else if (opc == SO_MIRROR_SPLIT) { + } else if (opc == SO_MIRROR_SPLIT || opc == SO_MIRROR_DELETE) { if (!mirror_id && !comp_id && !lsa.lsa_pool_name) { fprintf(stderr, - "%s %s: no mirror id or component id or pool name" - " is specified\n", progname, argv[0]); + "%s: no mirror specified to delete from '%s'\n", + progname, fname); goto usage_error; } if (lsa.lsa_pool_name) @@ -4135,6 +4142,7 @@ static int lfs_find(int argc, char **argv) { .val = 'i', .name = "stripe-index", .has_arg = required_argument }, { .val = 'i', .name = "stripe_index", .has_arg = required_argument }, /* getstripe { .val = 'I', .name = "comp-id", .has_arg = required_argument }*/ + { .val = 'l', .name = "lazy", .has_arg = no_argument }, { .val = 'L', .name = "layout", .has_arg = required_argument }, { .val = 'm', .name = "mdt", .has_arg = required_argument }, { .val = 'm', .name = "mdt-index", .has_arg = required_argument }, @@ -4430,6 +4438,9 @@ static int lfs_find(int argc, char **argv) param.fp_check_hash_type = 1; param.fp_exclude_hash_type = !!neg_opt; break; + case 'l': + param.fp_lazy = 1; + break; case 'L': ret = name2layout(¶m.fp_layout, optarg); if (ret) @@ -4706,22 +4717,21 @@ err_free: param.fp_check_ext_size = 1; param.fp_exclude_ext_size = !!neg_opt; break; + default: + ret = CMD_HELP; + goto err; + }; + } - default: - ret = CMD_HELP; - goto err; - }; - } - - if (pathstart == -1) { - fprintf(stderr, "error: %s: no filename|pathname\n", - argv[0]); - ret = CMD_HELP; - goto err; - } else if (pathend == -1) { - /* no options */ - pathend = argc; - } + if (pathstart == -1) { + fprintf(stderr, "error: %s: no filename|pathname\n", + argv[0]); + ret = CMD_HELP; + goto err; + } else if (pathend == -1) { + /* no options */ + pathend = argc; + } do { rc = llapi_find(argv[pathstart], ¶m); @@ -4782,6 +4792,7 @@ static int lfs_getstripe_internal(int argc, char **argv, { .val = 'i', .name = "stripe_index", .has_arg = no_argument }, { .val = 'I', .name = "comp-id", .has_arg = optional_argument }, { .val = 'I', .name = "component-id", .has_arg = optional_argument }, +/* find { .val = 'l', .name = "lazy", .has_arg = no_argument }, */ { .val = 'L', .name = "layout", .has_arg = no_argument }, { .val = 'm', .name = "mdt", .has_arg = no_argument }, { .val = 'm', .name = "mdt-index", .has_arg = no_argument }, @@ -5578,28 +5589,6 @@ static int mntdf(char *mntdir, char *fsname, char *pool, enum mntdf_flags flags, return rc; } -static int ll_statfs_data_comp(const void *sd1, const void *sd2) -{ - const struct obd_statfs *st1 = &((const struct ll_statfs_data *)sd1)-> - sd_st; - const struct obd_statfs *st2 = &((const struct ll_statfs_data *)sd2)-> - sd_st; - int r1 = obd_statfs_ratio(st1, false); - int r2 = obd_statfs_ratio(st2, false); - int64_t result = r1 - r2; - - /* if both space usage are above 90, compare free inodes */ - if (r1 > 90 && r2 > 90) - result = st2->os_ffree - st1->os_ffree; - - if (result < 0) - return -1; - else if (result == 0) - return 0; - else - return 1; -} - /* functions */ static int lfs_setdirstripe(int argc, char **argv) { @@ -5612,12 +5601,9 @@ static int lfs_setdirstripe(int argc, char **argv) char *mode_opt = NULL; bool default_stripe = false; bool delete = false; - bool auto_distributed = false; bool foreign_mode = false; mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO; mode_t previous_mode = 0; - struct ll_statfs_buf *lsb = NULL; - char mntdir[PATH_MAX] = ""; char *xattr = NULL; __u32 type = LU_FOREIGN_TYPE_DAOS, flags = 0; struct option long_opts[] = { @@ -5635,6 +5621,7 @@ static int lfs_setdirstripe(int argc, char **argv) { .val = 'i', .name = "mdt-index", .has_arg = required_argument }, { .val = 'i', .name = "mdt", .has_arg = required_argument }, #else +/* find { .val = 'l', .name = "lazy", .has_arg = no_argument }, */ { .val = 'm', .name = "mdt-index", .has_arg = required_argument }, { .val = 'm', .name = "mdt", .has_arg = required_argument }, #endif @@ -5866,7 +5853,7 @@ static int lfs_setdirstripe(int argc, char **argv) lsa.lsa_stripe_count != lsa.lsa_nr_tgts) { fprintf(stderr, "error: %s: stripe count %lld doesn't match the number of MDTs: %d\n", - argv[0], (long long)lsa.lsa_stripe_count, + argv[0], lsa.lsa_stripe_count, lsa.lsa_nr_tgts); free(param); return CMD_HELP; @@ -5877,21 +5864,6 @@ static int lfs_setdirstripe(int argc, char **argv) memcpy(param->lsp_tgts, mdts, sizeof(*mdts) * lsa.lsa_nr_tgts); } - if (!default_stripe && (lsa.lsa_pattern & LMV_HASH_FLAG_SPACE)) { - fprintf(stderr, "%s %s: can only specify -H space with -D\n", - progname, argv[0]); - free(param); - return CMD_HELP; - } - - if (param->lsp_stripe_offset != -1 && - lsa.lsa_pattern & LMV_HASH_FLAG_SPACE) { - fprintf(stderr, "%s %s: can only specify -H space with -i -1\n", - progname, argv[0]); - free(param); - return CMD_HELP; - } - dname = argv[optind]; do { if (default_stripe) { @@ -5903,100 +5875,6 @@ static int lfs_setdirstripe(int argc, char **argv) continue; } - /* - * if current \a dname isn't under the same \a mntdir as the - * last one, and the last one was auto-distributed, restore - * \a param. - */ - if (mntdir[0] != '\0' && - strncmp(dname, mntdir, strlen(mntdir)) && - auto_distributed) { - param->lsp_is_specific = false; - param->lsp_stripe_offset = -1; - auto_distributed = false; - } - - /* - * TODO: when MDT can allocate object with QoS (LU-9435), below - * code should be removed, instead we should let LMV to allocate - * the starting MDT object, and then let LOD allocate other MDT - * objects. - */ - if (!param->lsp_is_specific && param->lsp_stripe_offset == -1) { - char path[PATH_MAX] = ""; - - if (!lsb) { - lsb = malloc(sizeof(*lsb)); - if (!lsb) { - result = -ENOMEM; - break; - } - } - lsb->sb_count = 0; - - /* use mntdir for dirname() temporarily */ - strncpy(mntdir, dname, sizeof(mntdir) - 1); - if (!realpath(dirname(mntdir), path)) { - result = -errno; - fprintf(stderr, - "error: invalid path '%s': %s\n", - argv[optind], strerror(errno)); - break; - } - mntdir[0] = '\0'; - - result = llapi_search_mounts(path, 0, mntdir, NULL); - if (result < 0 || mntdir[0] == '\0') { - fprintf(stderr, - "No suitable Lustre mount found\n"); - break; - } - - result = mntdf(mntdir, NULL, NULL, 0, LL_STATFS_LMV, - lsb); - if (result < 0) - break; - - if (param->lsp_stripe_count > lsb->sb_count) { - fprintf(stderr, - "error: stripe count %d is too big\n", - param->lsp_stripe_count); - result = -ERANGE; - break; - } - - qsort(lsb->sb_buf, lsb->sb_count, - sizeof(struct ll_statfs_data), - ll_statfs_data_comp); - - auto_distributed = true; - } - - if (auto_distributed) { - int r; - int nr = MAX(param->lsp_stripe_count, - lsb->sb_count / 2); - - /* don't use server whose usage is above 90% */ - while (nr != param->lsp_stripe_count && - obd_statfs_ratio(&lsb->sb_buf[nr].sd_st, false) > - 90) - nr = MAX(param->lsp_stripe_count, nr / 2); - - /* get \a r between [0, nr) */ - r = rand() % nr; - - param->lsp_stripe_offset = lsb->sb_buf[r].sd_index; - if (param->lsp_stripe_count > 1) { - int i = 0; - - param->lsp_is_specific = true; - for (; i < param->lsp_stripe_count; i++) - param->lsp_tgts[(i + r) % nr] = - lsb->sb_buf[i].sd_index; - } - } - result = llapi_dir_create(dname, mode, param); if (result) fprintf(stderr, @@ -6007,7 +5885,6 @@ static int lfs_setdirstripe(int argc, char **argv) if (mode_opt != NULL) umask(previous_mode); - free(lsb); free(param); return result; } @@ -6080,7 +5957,7 @@ static int lfs_mv(int argc, char **argv) } } - if (lmu.lum_stripe_offset == -1) { + if (lmu.lum_stripe_offset == LMV_OFFSET_DEFAULT) { fprintf(stderr, "%s mv: MDT index must be specified\n", progname); return CMD_HELP;