X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lustre%2Futils%2Flfs.c;h=1f0f905da1c680264b1df34cdea9a3e2b06212f8;hp=7d4e92920e778c513cde1ce98251eaa36f747a9e;hb=62ef9c949753;hpb=e968b612d13ded3734e51c5adaf1f9ab19782470 diff --git a/lustre/utils/lfs.c b/lustre/utils/lfs.c index 7d4e929..1f0f905 100644 --- a/lustre/utils/lfs.c +++ b/lustre/utils/lfs.c @@ -73,6 +73,7 @@ #include #include #include +#include #include #include "obdctl.h" @@ -143,8 +144,8 @@ command_t cmdlist[] = { " [[!] --atime|-A [+-]N] [[!] --mtime|-M [+-]N] [[!] --ctime|-C [+-]N]\n" " [--maxdepth|-D N] [[!] --name|-n ] [--print0|-P]\n" " [--print|-p] [--obd|-O ] [[!] --size|-s [+-]N[bkMGTP]]\n" - " [[!] --type|-t ] [[!] --gid|-g N] [[!] --group|-G ]\n" - " [[!] --uid|-u N] [[!] --user|-U ]\n" + " [[!] --type|-t ] [[!] --gid|-g|--group|-G |]\n" + " [[!] --uid|-u|--user|-U |]\n" " [[!] --pool ]\n" "\t !: used before an option indicates 'NOT' the requested attribute\n" "\t -: used before an value indicates 'AT MOST' the requested value\n" @@ -180,14 +181,16 @@ command_t cmdlist[] = { {"quotaoff", lfs_quotaoff, 0, "Turn filesystem quotas off.\n" "usage: quotaoff [ -ug ] "}, {"setquota", lfs_setquota, 0, "Set filesystem quotas.\n" - "usage: setquota [ -u | -g ] -b -B -i -I \n" - " setquota -t [ -u | -g ] \n" - " setquota [ -u | --user | -g | --group ] \n" + "usage: setquota <-u|-g> |||\n" + " -b -B \n" + " -i -I \n" + " setquota -t <-u|-g> \n" + " setquota <-u|--user|-g|--group> |||\n" " [--block-softlimit ]\n" " [--block-hardlimit ]\n" " [--inode-softlimit ]\n" " [--inode-hardlimit ] \n" - " setquota [-t] [ -u | --user | -g | --group ]\n" + " setquota [-t] <-u|--user|-g|--group>\n" " [--block-grace ]\n" " [--inode-grace ] \n" " -b can be used instead of --block-softlimit/--block-grace\n" @@ -195,7 +198,9 @@ command_t cmdlist[] = { " -i can be used instead of --inode-softlimit/--inode-grace\n" " -I can be used instead of --inode-hardlimit"}, {"quota", lfs_quota, 0, "Display disk usage and limits.\n" - "usage: quota [-v] [-o obd_uuid|-i mdt_idx|-I ost_idx] [{-u|-g }|-t] "}, + "usage: quota [-v] [-o obd_uuid|-i mdt_idx|-I ost_idx]\n" + " [<-u|-g> |||] \n" + " quota [-o obd_uuid|-i mdt_idx|-I ost_idx] -t <-u|-g> "}, {"quotainv", lfs_quotainv, 0, "Invalidate quota data.\n" "usage: quotainv [-u|-g] "}, #endif @@ -221,8 +226,7 @@ command_t cmdlist[] = { "usage: ls [OPTION]... [FILE]..."}, {"changelog", lfs_changelog, 0, "Show the metadata changes on an MDT." - "\nusage: changelog [--follow] [startrec [endrec]]" - "\n(note: --follow is only valid when run on MDT node)"}, + "\nusage: changelog [startrec [endrec]]"}, {"changelog_clear", lfs_changelog_clear, 0, "Indicate that old changelog records up to are no longer of " "interest to consumer , allowing the system to free up space.\n" @@ -611,45 +615,27 @@ static int lfs_find(int argc, char **argv) param.maxdepth = strtol(optarg, 0, 0); break; case 'g': - new_fashion = 1; - param.gid = strtol(optarg, &endptr, 10); - if (optarg == endptr) { - fprintf(stderr, "Bad gid: %s\n", optarg); - return CMD_HELP; - } - param.exclude_gid = !!neg_opt; - param.check_gid = 1; - break; case 'G': new_fashion = 1; - param.gid = strtol(optarg, &endptr, 10); - if (optarg == endptr) { - ret = name2id(¶m.gid, optarg, GROUP); - if (ret != 0) { + ret = name2id(¶m.gid, optarg, GROUP); + if (ret) { + param.gid = strtoul(optarg, &endptr, 10); + if (*endptr != '\0') { fprintf(stderr, "Group/GID: %s cannot " "be found.\n", optarg); return -1; } - } + } param.exclude_gid = !!neg_opt; param.check_gid = 1; break; case 'u': - new_fashion = 1; - param.uid = strtol(optarg, &endptr, 10); - if (optarg == endptr) { - fprintf(stderr, "Bad uid: %s\n", optarg); - return CMD_HELP; - } - param.exclude_uid = !!neg_opt; - param.check_uid = 1; - break; case 'U': new_fashion = 1; - param.uid = strtol(optarg, &endptr, 10); - if (optarg == endptr) { - ret = name2id(¶m.uid, optarg, USER); - if (ret != 0) { + ret = name2id(¶m.uid, optarg, USER); + if (ret) { + param.uid = strtoul(optarg, &endptr, 10); + if (*endptr != '\0') { fprintf(stderr, "User/UID: %s cannot " "be found.\n", optarg); return -1; @@ -1744,6 +1730,7 @@ int lfs_setquota(int argc, char **argv) {0, 0, 0, 0} }; unsigned limit_mask = 0; + char *endptr; if (has_times_option(argc, argv)) return lfs_setquota_times(argc, argv); @@ -1768,9 +1755,12 @@ int lfs_setquota(int argc, char **argv) rc = name2id(&qctl.qc_id, optarg, (qctl.qc_type == USRQUOTA) ? USER : GROUP); if (rc) { - fprintf(stderr, "error: unknown id %s\n", - optarg); - return CMD_HELP; + qctl.qc_id = strtoul(optarg, &endptr, 10); + if (*endptr != '\0') { + fprintf(stderr, "error: can't find id " + "for name %s\n", optarg); + return CMD_HELP; + } } break; case 'b': @@ -2070,6 +2060,7 @@ static int lfs_quota(int argc, char **argv) char *obd_type = (char *)qctl.obd_type; char *obd_uuid = (char *)qctl.obd_uuid.uuid; int rc, rc1 = 0, rc2 = 0, rc3 = 0, verbose = 0, pass = 0; + char *endptr; __u32 valid = QC_GENERAL, idx = 0; optind = 0; @@ -2145,9 +2136,12 @@ ug_output: rc = name2id(&qctl.qc_id, name, (qctl.qc_type == USRQUOTA) ? USER : GROUP); if (rc) { - fprintf(stderr,"error: can't find id for name %s: %s\n", - name, strerror(errno)); - return CMD_HELP; + qctl.qc_id = strtoul(name, &endptr, 10); + if (*endptr != '\0') { + fprintf(stderr, "error: can't find id for name " + "%s\n", name); + return CMD_HELP; + } } } else if (optind + 1 != argc || qctl.qc_type == UGQUOTA) { fprintf(stderr, "error: missing quota info argument(s)\n"); @@ -2231,8 +2225,13 @@ static int lfs_flushctx(int argc, char **argv) } } - if (kdestroy) - system("kdestroy > /dev/null"); + if (kdestroy) { + int rc; + if ((rc = system("kdestroy > /dev/null")) != 0) { + rc = WEXITSTATUS(rc); + fprintf(stderr, "error destroying tickets: %d, continuing\n", rc); + } + } if (optind >= argc) { /* flush for all mounted lustre fs. */ @@ -2316,7 +2315,7 @@ static int lfs_changelog(int argc, char **argv) void *changelog_priv; struct changelog_rec *rec; long long startrec = 0, endrec = 0; - char c, *mdd; + char *mdd; struct option long_opts[] = { {"follow", no_argument, 0, 'f'}, {0, 0, 0, 0} @@ -2325,9 +2324,9 @@ static int lfs_changelog(int argc, char **argv) int rc, follow = 0; optind = 0; - while ((c = getopt_long(argc, argv, short_opts, + while ((rc = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { - switch (c) { + switch (rc) { case 'f': follow++; break; @@ -2349,7 +2348,8 @@ static int lfs_changelog(int argc, char **argv) endrec = strtoll(argv[optind++], NULL, 10); rc = llapi_changelog_start(&changelog_priv, - follow ? CHANGELOG_FLAG_FOLLOW : 0, + CHANGELOG_FLAG_BLOCK | + (follow ? CHANGELOG_FLAG_FOLLOW : 0), mdd, startrec); if (rc < 0) { fprintf(stderr, "Can't start changelog: %s\n", @@ -2358,14 +2358,22 @@ static int lfs_changelog(int argc, char **argv) } while ((rc = llapi_changelog_recv(changelog_priv, &rec)) == 0) { + time_t secs; + struct tm ts; + if (endrec && rec->cr_index > endrec) break; if (rec->cr_index < startrec) continue; - printf(LPU64" %02d%-5s "LPU64" 0x%x t="DFID, - rec->cr_index, rec->cr_type, - changelog_type2str(rec->cr_type), rec->cr_time, + secs = rec->cr_time >> 30; + gmtime_r(&secs, &ts); + printf(LPU64" %02d%-5s %02d:%02d:%02d.%06d %04d.%02d.%02d " + "0x%x t="DFID, rec->cr_index, rec->cr_type, + changelog_type2str(rec->cr_type), + ts.tm_hour, ts.tm_min, ts.tm_sec, + (int)(rec->cr_time & ((1<<30) - 1)), + ts.tm_year+1900, ts.tm_mon+1, ts.tm_mday, rec->cr_flags & CLF_FLAGMASK, PFID(&rec->cr_tfid)); if (rec->cr_namelen) /* namespace rec includes parent and filename */ @@ -2373,11 +2381,15 @@ static int lfs_changelog(int argc, char **argv) rec->cr_namelen, rec->cr_name); else printf("\n"); + llapi_changelog_free(&rec); } llapi_changelog_fini(&changelog_priv); + if (rc < 0) + fprintf(stderr, "Changelog: %s\n", strerror(errno = -rc)); + return (rc == 1 ? 0 : rc); } @@ -2406,7 +2418,7 @@ static int lfs_fid2path(int argc, char **argv) {"rec", required_argument, 0, 'r'}, {0, 0, 0, 0} }; - char c, short_opts[] = "cl:r:"; + char short_opts[] = "cl:r:"; char *device, *fid, *path; long long recno = -1; int linkno = -1; @@ -2415,9 +2427,10 @@ static int lfs_fid2path(int argc, char **argv) int rc; optind = 0; - while ((c = getopt_long(argc, argv, short_opts, + + while ((rc = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { - switch (c) { + switch (rc) { case 'c': printcur++; break; @@ -2435,7 +2448,6 @@ static int lfs_fid2path(int argc, char **argv) return CMD_HELP; } } - device = argv[optind++]; fid = argv[optind++]; if (optind != argc)