Whamcloud - gitweb
add 2.6.27 kernel support
[fs/lustre-release.git] / lustre / utils / lfs.c
index 7d4e929..1f0f905 100644 (file)
@@ -73,6 +73,7 @@
 #include <lustre/lustre_idl.h>
 #include <lustre/liblustreapi.h>
 #include <lustre/lustre_user.h>
+#include <lustre_quota.h>
 
 #include <libcfs/libcfsutil.h>
 #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 <pattern>] [--print0|-P]\n"
          "     [--print|-p] [--obd|-O <uuid[s]>] [[!] --size|-s [+-]N[bkMGTP]]\n"
-         "     [[!] --type|-t <filetype>] [[!] --gid|-g N] [[!] --group|-G <name>]\n"
-         "     [[!] --uid|-u N] [[!] --user|-U <name>]\n"
+         "     [[!] --type|-t <filetype>] [[!] --gid|-g|--group|-G <gid>|<gname>]\n"
+         "     [[!] --uid|-u|--user|-U <uid>|<uname>]\n"
          "     [[!] --pool <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 ] <filesystem>"},
         {"setquota", lfs_setquota, 0, "Set filesystem quotas.\n"
-         "usage: setquota [ -u | -g ] <name> -b <block-softlimit> -B <block-hardlimit> -i <inode-softlimit> -I <inode-hardlimit> <filesystem>\n"
-         "       setquota -t [ -u | -g ] <block-grace> <inode-grace> <filesystem>\n"
-         "       setquota [ -u | --user | -g | --group ] <name>\n"
+         "usage: setquota <-u|-g> <uname>|<uid>|<gname>|<gid>\n"
+         "                -b <block-softlimit> -B <block-hardlimit>\n"
+         "                -i <inode-softlimit> -I <inode-hardlimit> <filesystem>\n"
+         "       setquota -t <-u|-g> <block-grace> <inode-grace> <filesystem>\n"
+         "       setquota <-u|--user|-g|--group> <uname>|<uid>|<gname>|<gid>\n"
          "                [--block-softlimit <block-softlimit>]\n"
          "                [--block-hardlimit <block-hardlimit>]\n"
          "                [--inode-softlimit <inode-softlimit>]\n"
          "                [--inode-hardlimit <inode-hardlimit>] <filesystem>\n"
-         "       setquota [-t] [ -u | --user | -g | --group ]\n"
+         "       setquota [-t] <-u|--user|-g|--group>\n"
          "                [--block-grace <block-grace>]\n"
          "                [--inode-grace <inode-grace>] <filesystem>\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 <name>}|-t] <filesystem>"},
+         "usage: quota [-v] [-o obd_uuid|-i mdt_idx|-I ost_idx]\n" 
+         "             [<-u|-g> <uname>|<uid>|<gname>|<gid>] <filesystem>\n"
+         "       quota [-o obd_uuid|-i mdt_idx|-I ost_idx] -t <-u|-g> <filesystem>"},
         {"quotainv", lfs_quotainv, 0, "Invalidate quota data.\n"
          "usage: quotainv [-u|-g] <filesystem>"},
 #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] <mdtname> [startrec [endrec]]"
-         "\n(note: --follow is only valid when run on MDT node)"},
+         "\nusage: changelog <mdtname> [startrec [endrec]]"},
         {"changelog_clear", lfs_changelog_clear, 0,
          "Indicate that old changelog records up to <endrec> are no longer of "
          "interest to consumer <id>, 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(&param.gid, optarg, GROUP);
-                                if (ret != 0) {
+                        ret = name2id(&param.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(&param.uid, optarg, USER);
-                                if (ret != 0) {
+                        ret = name2id(&param.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)