Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / utils / lfs.c
index c8fcc6e..6d2ac85 100644 (file)
@@ -133,9 +133,9 @@ command_t cmdlist[] = {
          "directory or recursively for all files in a directory tree.\n"
          "usage: getstripe [--obd|-O <uuid>] [--quiet | -q] [--verbose | -v]\n"
          "                 [--recursive | -r] <dir|file> ..."},
-        {"poollist", lfs_poollist, 0,
+        {"pool_list", lfs_poollist, 0,
          "List pools or pool OSTs\n"
-         "usage: poollist <fsname>[.<poolname>] | <pathname>\n"},
+         "usage: pool_list <fsname>[.<poolname>] | <pathname>\n"},
         {"find", lfs_find, 0,
          "To find files that match given parameters recursively in a directory tree.\n"
          "usage: find <dir|file> ... \n"
@@ -219,17 +219,20 @@ command_t cmdlist[] = {
          "Remote user list directory contents.\n"
          "usage: ls [OPTION]... [FILE]..."},
         {"changelog", lfs_changelog, 0,
-         "Show the metadata changes in a filesystem between two snapshot times."
-         "\nusage: changelog [--follow] <mdtname> [startrec [endrec]]"},
+         "Show the metadata changes on an MDT."
+         "\nusage: changelog [--follow] <mdtname> [startrec [endrec]]"
+         "\n(note: --follow is only valid when run on MDT node)"},
         {"changelog_clear", lfs_changelog_clear, 0,
-         "Purge old changelog records up to <endrec> to free up space.\n"
+         "Indicate that old changelog records up to <endrec> are no longer of "
+         "interest to consumer <id>, allowing the system to free up space.\n"
          "An <endrec> of 0 means all records.\n"
-         "usage: changelog_clear <mdtname> <endrec>"},
+         "usage: changelog_clear <mdtname> <id> <endrec>"},
         {"fid2path", lfs_fid2path, 0,
          "Resolve the full path to a given FID. For a specific hardlink "
          "specify link number <linkno>.\n"
          /* "For a historical name, specify changelog record <recno>.\n" */
-         "usage: fid2path <mdtname> <fid> [--link <linkno>]"/*[--rec <recno>]*/},
+         "usage: fid2path <fsname|rootpath> <fid> [--link <linkno>]"
+                /*[--rec <recno>]*/},
         {"path2fid", lfs_path2fid, 0, "Display the fid for a given path.\n"
          "usage: path2fid <path>"},
         {"help", Parser_help, 0, "help"},
@@ -1245,7 +1248,8 @@ static int lfs_check(int argc, char **argv)
                 return -1;
         }
 
-        rc = llapi_target_check(num_types, obd_types, mnt->mnt_dir);
+        rc = llapi_target_iterate(num_types, obd_types,
+                                  mnt->mnt_dir, llapi_ping_target);
 
         if (rc)
                 fprintf(stderr, "error: %s: %s status failed\n",
@@ -1395,7 +1399,7 @@ static int lfs_quotacheck(int argc, char **argv)
         qctl.qc_cmd = LUSTRE_Q_QUOTAOFF;
         qctl.qc_type = check_type;
         rc = llapi_quotactl(mnt, &qctl);
-        if (rc) {
+        if (rc && errno != EALREADY) {
                 fprintf(stderr, "quota off failed: %s\n", strerror(errno));
                 return rc;
         }
@@ -1419,7 +1423,7 @@ static int lfs_quotacheck(int argc, char **argv)
         qctl.qc_cmd = LUSTRE_Q_QUOTAON;
         qctl.qc_type = check_type;
         rc = llapi_quotactl(mnt, &qctl);
-        if (rc) {
+        if (rc && errno != EALREADY) {
                 if (*obd_type)
                         fprintf(stderr, "%s %s ", (char *)qctl.obd_type,
                                 obd_uuid2str(&qctl.obd_uuid));
@@ -1473,14 +1477,21 @@ static int lfs_quotaon(int argc, char **argv)
 
         rc = llapi_quotactl(mnt, &qctl);
         if (rc) {
-                if (*obd_type)
-                        fprintf(stderr, "%s %s ", obd_type,
-                                obd_uuid2str(&qctl.obd_uuid));
-                fprintf(stderr, "%s failed: %s\n", argv[0], strerror(errno));
-                return rc;
+                if (errno == EALREADY) {
+                        fprintf(stderr, "\n%s quotas are enabled already.\n",
+                                qctl.qc_type == 0x02 ? "user/group" :
+                                (qctl.qc_type == 0x00 ? "user" : "group"));
+                        rc = 0;
+                } else {
+                        if (*obd_type)
+                                fprintf(stderr, "%s %s ", obd_type,
+                                        obd_uuid2str(&qctl.obd_uuid));
+                        fprintf(stderr, "%s failed: %s\n", argv[0],
+                                strerror(errno));
+                }
         }
 
-        return 0;
+        return rc;
 }
 
 static int lfs_quotaoff(int argc, char **argv)
@@ -1521,20 +1532,22 @@ static int lfs_quotaoff(int argc, char **argv)
         mnt = argv[optind];
 
         rc = llapi_quotactl(mnt, &qctl);
-        if (rc == -1 && errno == ESRCH) {
-                fprintf(stderr, "\n%s quotas are not enabled.\n",
-                        qctl.qc_type == 0x00 ? "user" : "group");
-                return 0;
-        }
         if (rc) {
-                if (*obd_type)
-                        fprintf(stderr, "%s %s ", obd_type,
-                                obd_uuid2str(&qctl.obd_uuid));
-                fprintf(stderr, "quotaoff failed: %s\n", strerror(errno));
-                return rc;
+                if (errno == EALREADY) {
+                        fprintf(stderr, "\n%s quotas are disabled already.\n",
+                                qctl.qc_type == 0x02 ? "user/group" :
+                                (qctl.qc_type == 0x00 ? "user" : "group"));
+                        rc = 0;
+                } else {
+                        if (*obd_type)
+                                fprintf(stderr, "%s %s ", obd_type,
+                                        obd_uuid2str(&qctl.obd_uuid));
+                        fprintf(stderr, "quotaoff failed: %s\n",
+                                strerror(errno));
+                }
         }
 
-        return 0;
+        return rc;
 }
 
 static int lfs_quotainv(int argc, char **argv)
@@ -1834,6 +1847,11 @@ int lfs_setquota(int argc, char **argv)
                 return CMD_HELP;
         }
 
+        if (limit_mask == 0) {
+                fprintf(stderr, "error: at least one limit must be specified\n");
+                return CMD_HELP;
+        }
+
         if (optind != argc - 1) {
                 fprintf(stderr, "error: unexpected parameters encountered\n");
                 return CMD_HELP;
@@ -1940,7 +1958,7 @@ static void print_quota_title(char *name, struct if_quotactl *qctl)
                "files", "quota", "limit", "grace");
 }
 
-static void print_quota(char *mnt, struct if_quotactl *qctl)
+static void print_quota(char *mnt, struct if_quotactl *qctl, int type, int rc)
 {
         time_t now;
 
@@ -1988,9 +2006,15 @@ static void print_quota(char *mnt, struct if_quotactl *qctl)
 
                         if (bover)
                                 diff2str(dqb->dqb_btime, timebuf, now);
-                        sprintf(numbuf[0], (dqb->dqb_valid & QIF_SPACE) ?
-                                LPU64 : "["LPU64"]", toqb(dqb->dqb_curspace));
-                        if (qctl->qc_valid == QC_GENERAL)
+                        if (rc == -1 && errno == EREMOTEIO)
+                                sprintf(numbuf[0], LPU64"*",
+                                        toqb(dqb->dqb_curspace));
+                        else
+                                sprintf(numbuf[0],
+                                        (dqb->dqb_valid & QIF_SPACE) ?
+                                        LPU64 : "["LPU64"]",
+                                        toqb(dqb->dqb_curspace));
+                        if (type == QC_GENERAL)
                                 sprintf(numbuf[1], (dqb->dqb_valid & QIF_BLIMITS)
                                         ? LPU64 : "["LPU64"]",
                                         dqb->dqb_bsoftlimit);
@@ -2007,7 +2031,7 @@ static void print_quota(char *mnt, struct if_quotactl *qctl)
 
                         sprintf(numbuf[0], (dqb->dqb_valid & QIF_INODES) ?
                                 LPU64 : "["LPU64"]", dqb->dqb_curinodes);
-                       if (qctl->qc_valid == QC_GENERAL)
+                       if (type == QC_GENERAL)
                                 sprintf(numbuf[1], (dqb->dqb_valid & QIF_ILIMITS)
                                         ? LPU64 : "["LPU64"]",
                                         dqb->dqb_isoftlimit);
@@ -2015,7 +2039,7 @@ static void print_quota(char *mnt, struct if_quotactl *qctl)
                                 sprintf(numbuf[1], "%s", "");
                         sprintf(numbuf[2], (dqb->dqb_valid & QIF_ILIMITS) ?
                                 LPU64 : "["LPU64"]", dqb->dqb_ihardlimit);
-                        if (qctl->qc_valid != QC_OSTIDX)
+                        if (type != QC_OSTIDX)
                                 printf(" %7s%c %6s %7s %7s",
                                        numbuf[0], iover ? '*' : ' ', numbuf[1],
                                        numbuf[2], iover > 1 ? timebuf : "");
@@ -2062,7 +2086,7 @@ static int print_obd_quota(char *mnt, struct if_quotactl *qctl, int is_mdt)
                         continue;
                 }
 
-                print_quota(obd_uuid2str(&qctl->obd_uuid), qctl);
+                print_quota(obd_uuid2str(&qctl->obd_uuid), qctl, qctl->qc_valid, 0);
         }
 
 out:
@@ -2142,8 +2166,10 @@ ug_output:
                              (qctl.qc_type == USRQUOTA) ? USER : GROUP);
                 if (rc)
                         name = "<unknown>";
+        /* lfs quota -u username /path/to/lustre/mount */
         } else if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA) {
-                if (optind + 2 != argc) {
+                /* options should be followed by u/g-name and mntpoint */
+                if (optind + 2 != argc || qctl.qc_type == UGQUOTA) {
                         fprintf(stderr, "error: missing quota argument(s)\n");
                         return CMD_HELP;
                 }
@@ -2156,7 +2182,7 @@ ug_output:
                                 name, strerror(errno));
                         return CMD_HELP;
                 }
-        } else if (optind + 1 != argc) {
+        } else if (optind + 1 != argc || qctl.qc_type == UGQUOTA) {
                 fprintf(stderr, "error: missing quota info argument(s)\n");
                 return CMD_HELP;
         }
@@ -2167,7 +2193,7 @@ ug_output:
         mnt = argv[optind];
 
         rc1 = llapi_quotactl(mnt, &qctl);
-        if (rc1 == -1 && errno == ESRCH) {
+        if (rc1 == -1 && errno == EALREADY) {
                 fprintf(stderr, "\n%s quotas are not enabled.\n",
                         qctl.qc_type == USRQUOTA ? "user" : "group");
                 goto out;
@@ -2176,9 +2202,9 @@ ug_output:
                 fprintf(stderr, "%s %s ", obd_type, obd_uuid);
 
         if (qctl.qc_valid != QC_GENERAL)
-                mnt = obd_uuid2str(&qctl.obd_uuid);
+                mnt = "";
 
-        print_quota(mnt, &qctl);
+        print_quota(mnt, &qctl, QC_GENERAL, rc1);
 
         if (qctl.qc_valid == QC_GENERAL && qctl.qc_cmd != LUSTRE_Q_GETINFO && verbose) {
                 rc2 = print_obd_quota(mnt, &qctl, 1);
@@ -2365,7 +2391,7 @@ static int lfs_changelog(int argc, char **argv)
         int fd, len;
         char c, *mdd, *ptr = NULL;
         struct option long_opts[] = {
-                {"follow", 0, 0, 'f'},
+                {"follow", no_argument, 0, 'f'},
                 {0, 0, 0, 0}
         };
         char short_opts[] = "f";
@@ -2396,8 +2422,11 @@ static int lfs_changelog(int argc, char **argv)
                 endrec = strtoll(argv[optind++], NULL, 10);
 
         fd = llapi_changelog_open(mdd, startrec);
-        if (fd < 0)
+        if (fd < 0) {
+                fprintf(stderr, "%s Can't open changelog: %s\n", argv[0],
+                        strerror(errno = -fd));
                 return fd;
+        }
 
         while ((len = get_next_full_line(fd, &ptr)) >= 0) {
                 if (len == 0) {
@@ -2425,7 +2454,7 @@ static int lfs_changelog(int argc, char **argv)
         close(fd);
 
         if (len < 0) {
-                printf("read err %d\n", errno);
+                fprintf(stderr, "read err %d\n", errno);
                 return -errno;
         }
 
@@ -2435,33 +2464,43 @@ static int lfs_changelog(int argc, char **argv)
 static int lfs_changelog_clear(int argc, char **argv)
 {
         long long endrec;
+        int rc;
 
-        if (argc != 3)
+        if (argc != 4)
                 return CMD_HELP;
 
-        endrec = strtoll(argv[2], NULL, 10);
+        endrec = strtoll(argv[3], NULL, 10);
 
-        return(llapi_changelog_clear(argv[1], endrec));
+        rc = llapi_changelog_clear(argv[1], argv[2], endrec);
+        if (rc)
+                fprintf(stderr, "%s error: %s\n", argv[0],
+                        strerror(errno = -rc));
+        return rc;
 }
 
 static int lfs_fid2path(int argc, char **argv)
 {
         struct option long_opts[] = {
-                {"link", 1, 0, 'l'},
-                {"rec", 1, 0, 'r'},
+                {"cur", no_argument, 0, 'c'},
+                {"link", required_argument, 0, 'l'},
+                {"rec", required_argument, 0, 'r'},
                 {0, 0, 0, 0}
         };
-        char c, short_opts[] = "l:r:";
+        char c, short_opts[] = "cl:r:";
         char *device, *fid, *path;
         long long recno = -1;
         int linkno = -1;
         int lnktmp;
+        int printcur = 0;
         int rc;
 
         optind = 0;
         while ((c = getopt_long(argc, argv, short_opts,
                                 long_opts, NULL)) != -1) {
                 switch (c) {
+                case 'c':
+                        printcur++;
+                        break;
                 case 'l':
                         linkno = strtol(optarg, NULL, 10);
                         break;
@@ -2487,15 +2526,20 @@ static int lfs_fid2path(int argc, char **argv)
         lnktmp = (linkno >= 0) ? linkno : 0;
         while (1) {
                 int oldtmp = lnktmp;
-                rc = llapi_fid2path(device, fid, path, PATH_MAX, recno,
+                long long rectmp = recno;
+                rc = llapi_fid2path(device, fid, path, PATH_MAX, &rectmp,
                                     &lnktmp);
                 if (rc < 0) {
                         fprintf(stderr, "%s error: %s\n", argv[0],
                                 strerror(errno = -rc));
                         break;
-                } else {
-                        fprintf(stdout, "%s\n", path);
                 }
+
+                if (printcur)
+                        fprintf(stdout, "%lld %s\n", rectmp, path);
+                else
+                        fprintf(stdout, "%s\n", path);
+
                 if (linkno >= 0)
                         /* specified linkno */
                         break;
@@ -2511,22 +2555,21 @@ static int lfs_fid2path(int argc, char **argv)
 static int lfs_path2fid(int argc, char **argv)
 {
         char *path;
-        unsigned long long seq;
-        unsigned long oid, ver;
+        lustre_fid fid;
         int rc;
 
         if (argc != 2)
                 return CMD_HELP;
 
         path = argv[1];
-        rc = llapi_path2fid(path, &seq, &oid, &ver);
+        rc = llapi_path2fid(path, &fid);
         if (rc) {
                 fprintf(stderr, "can't get fid for %s: %s\n", path,
                         strerror(errno = -rc));
                 return rc;
         }
 
-        printf(DFID"\n", seq, (unsigned int)oid, (unsigned int)ver);
+        printf(DFID"\n", PFID(&fid));
 
         return 0;
 }