From: Wang Shilong Date: Sun, 9 Apr 2017 02:22:24 +0000 (+0800) Subject: LU-4017 quota: add project id support to lfs find X-Git-Tag: 2.9.57~13 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=3dad616e09fc2a89174900a4d4dbb60308650418 LU-4017 quota: add project id support to lfs find Project ID support is added into 'lfs find', which is needed for sanity-quota.sh etc to collect project id information if test failed Change-Id: I60cfc4f81bb8779db0a33a5c9bae7255e9d0100c Signed-off-by: Wang Shilong Reviewed-on: https://review.whamcloud.com/26464 Reviewed-by: Li Xi Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Niu Yawei Reviewed-by: Oleg Drokin --- diff --git a/lustre/include/lustre/lustreapi.h b/lustre/include/lustre/lustreapi.h index a79c321..cd06b47 100644 --- a/lustre/include/lustre/lustreapi.h +++ b/lustre/include/lustre/lustreapi.h @@ -206,6 +206,8 @@ struct find_param { fp_exclude_layout:1, fp_get_default_lmv:1, /* Get default LMV */ fp_migrate:1, + fp_check_projid:1, + fp_exclude_projid:1, fp_check_comp_count:1, fp_exclude_comp_count:1, fp_check_comp_flags:1, @@ -261,6 +263,7 @@ struct find_param { unsigned long long fp_comp_end; unsigned long long fp_comp_end_units; unsigned long long fp_mdt_count; + unsigned fp_projid; /* In-process parameters. */ unsigned long fp_got_uuids:1, diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index ac5f44b..b682d2d 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -246,6 +246,7 @@ command_t cmdlist[] = { " [[!] --stripe-size|-S [+-]N[kMGT]] [[!] --type|-t ]\n" " [[!] --gid|-g|--group|-G |]\n" " [[!] --uid|-u|--user|-U |] [[!] --pool ]\n" + " [[!] --projid ]\n" " [[!] --layout|-L released,raid0]\n" " [[!] --component-count [+-]]\n" " [[!] --component-start [+-]N[kMGTPE]]\n" @@ -1271,7 +1272,8 @@ enum { LFS_COMP_FLAGS_OPT, LFS_COMP_DEL_OPT, LFS_COMP_SET_OPT, - LFS_COMP_ADD_OPT + LFS_COMP_ADD_OPT, + LFS_PROJID_OPT, }; /* functions */ @@ -1848,9 +1850,10 @@ static int lfs_find(int argc, char **argv) {"obd", required_argument, 0, 'O'}, {"ost", required_argument, 0, 'O'}, /* no short option for pool, p/P already used */ - {"pool", required_argument, 0, LFS_POOL_OPT}, - {"print0", no_argument, 0, 'p'}, - {"print", no_argument, 0, 'P'}, + {"pool", required_argument, 0, LFS_POOL_OPT}, + {"print0", no_argument, 0, 'p'}, + {"print", no_argument, 0, 'P'}, + {"projid", required_argument, 0, LFS_PROJID_OPT}, {"size", required_argument, 0, 's'}, {"stripe-size", required_argument, 0, 'S'}, {"stripe_size", required_argument, 0, 'S'}, @@ -2161,17 +2164,32 @@ static int lfs_find(int argc, char **argv) strncpy(puuid->uuid, token, sizeof(puuid->uuid)); - } + } err_free: - if (buf) - free(buf); - break; - } - case 'p': + if (buf) + free(buf); + break; + } + case 'p': param.fp_zero_end = 1; - break; - case 'P': - break; + break; + case 'P': + break; + case LFS_PROJID_OPT: + rc = name2projid(¶m.fp_projid, optarg); + if (rc) { + param.fp_projid = strtoul(optarg, &endptr, 10); + if (*endptr != '\0') { + fprintf(stderr, + "Invalid project ID: %s", + optarg); + ret = -1; + goto err; + } + } + param.fp_exclude_projid = !!neg_opt; + param.fp_check_projid = 1; + break; case 's': if (optarg[0] == '+') { param.fp_size_sign = -1; diff --git a/lustre/utils/liblustreapi.c b/lustre/utils/liblustreapi.c index 22a312bb..2226112 100644 --- a/lustre/utils/liblustreapi.c +++ b/lustre/utils/liblustreapi.c @@ -3363,7 +3363,26 @@ static bool find_check_lmm_info(struct find_param *param) return param->fp_check_pool || param->fp_check_stripe_count || param->fp_check_stripe_size || param->fp_check_layout || param->fp_check_comp_count || param->fp_check_comp_end || - param->fp_check_comp_start || param->fp_check_comp_flags; + param->fp_check_comp_start || param->fp_check_comp_flags || + param->fp_check_projid; +} + +/* + * Get file/directory project id. + * by the open fd resides on. + * Return 0 and project id on success, or -ve errno. + */ +static int fget_projid(int fd, int *projid) +{ + struct fsxattr fsx; + int rc; + + rc = ioctl(fd, LL_IOC_FSGETXATTR, &fsx); + if (rc) + return -errno; + + *projid = fsx.fsx_projid; + return 0; } static int cb_find_init(char *path, DIR *parent, DIR **dirp, @@ -3377,6 +3396,7 @@ static int cb_find_init(char *path, DIR *parent, DIR **dirp, int checked_type = 0; int ret = 0; __u32 stripe_count = 0; + int fd = -2; if (parent == NULL && dir == NULL) return -EINVAL; @@ -3447,8 +3467,6 @@ static int cb_find_init(char *path, DIR *parent, DIR **dirp, ret = llapi_file_fget_mdtidx(dirfd(dir), ¶m->fp_file_mdt_index); } else if (S_ISREG(st->st_mode)) { - int fd; - /* FIXME: we could get the MDT index from the * file's FID in lmd->lmd_lmm.lmm_oi without * opening the file, once we are sure that @@ -3459,7 +3477,6 @@ static int cb_find_init(char *path, DIR *parent, DIR **dirp, if (fd > 0) { ret = llapi_file_fget_mdtidx(fd, ¶m->fp_file_mdt_index); - close(fd); } else { ret = -errno; } @@ -3476,7 +3493,7 @@ static int cb_find_init(char *path, DIR *parent, DIR **dirp, if (ret == -ENOENT) goto decided; - return ret; + goto out; } else { stripe_count = find_get_stripe_count(param); } @@ -3507,7 +3524,7 @@ static int cb_find_init(char *path, DIR *parent, DIR **dirp, ret = setup_target_indexes(dir ? dir : parent, path, param); if (ret) - return ret; + goto out; param->fp_dev = st->st_dev; } else if (!lustre_fs && param->fp_got_uuids) { @@ -3608,6 +3625,27 @@ obd_matches: } } + if (param->fp_check_projid) { + int projid = 0; + + if (fd == -2) + fd = open(path, O_RDONLY); + + if (fd > 0) + ret = fget_projid(fd, &projid); + else + ret = -errno; + if (ret) + goto out; + if (projid == param->fp_projid) { + if (param->fp_exclude_uid) + goto decided; + } else { + if (!param->fp_exclude_projid) + goto decided; + } + } + if (param->fp_check_pool) { decision = find_check_pool(param); if (decision == -1) @@ -3667,19 +3705,19 @@ obd_matches: __func__, path); goto decided; } else { - ret = -errno; - llapi_error(LLAPI_MSG_ERROR, ret, - "%s: IOC_LOV_GETINFO on %s failed", - __func__, path); - return ret; - } - } + ret = -errno; + llapi_error(LLAPI_MSG_ERROR, ret, + "%s: IOC_LOV_GETINFO on %s failed", + __func__, path); + goto out; + } + } - /* Check the time on osc. */ - decision = find_time_check(st, param, 0); - if (decision == -1) - goto decided; - } + /* Check the time on osc. */ + decision = find_time_check(st, param, 0); + if (decision == -1) + goto decided; + } if (param->fp_check_size) decision = find_value_cmp(st->st_size, param->fp_size, @@ -3687,22 +3725,26 @@ obd_matches: param->fp_exclude_size, param->fp_size_units, 0); - if (decision != -1) { - llapi_printf(LLAPI_MSG_NORMAL, "%s", path); + if (decision != -1) { + llapi_printf(LLAPI_MSG_NORMAL, "%s", path); if (param->fp_zero_end) - llapi_printf(LLAPI_MSG_NORMAL, "%c", '\0'); - else - llapi_printf(LLAPI_MSG_NORMAL, "\n"); - } + llapi_printf(LLAPI_MSG_NORMAL, "%c", '\0'); + else + llapi_printf(LLAPI_MSG_NORMAL, "\n"); + } decided: - /* Do not get down anymore? */ - if (param->fp_depth == param->fp_max_depth) - return 1; - + ret = 0; + /* Do not get down anymore? */ + if (param->fp_depth == param->fp_max_depth) { + ret = 1; + goto out; + } param->fp_depth++; - - return 0; +out: + if (fd > 0) + close(fd); + return ret; } static int cb_migrate_mdt_init(char *path, DIR *parent, DIR **dirp,