Whamcloud - gitweb
b=12797
[fs/lustre-release.git] / lustre / utils / lfs.c
index f249ab2..50ba49e 100644 (file)
@@ -23,7 +23,6 @@
  *
  */
 
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <getopt.h>
@@ -38,6 +37,8 @@
 #include <dirent.h>
 #include <time.h>
 #include <ctype.h>
+/* For dirname() */
+#include <libgen.h>
 
 #include <lnet/api-support.h>
 #include <lnet/lnetctl.h>
@@ -87,6 +88,7 @@ command_t cmdlist[] = {
          "       or \n"
          "       setstripe -d <dirname>   (to delete default striping)\n"
          "\tstripe_size:  Number of bytes on each OST (0 filesystem default)\n"
+         "\t              Can be specified with k, m or g (in KB, MB and GB respectively)\n"
          "\tstripe_index: OST index of first stripe (-1 filesystem default)\n"
          "\tstripe_count: Number of OSTs to stripe over (0 default, -1 all)"},
         {"getstripe", lfs_getstripe, 0,
@@ -140,7 +142,7 @@ command_t cmdlist[] = {
          "usage: setquota [ -u | -g ] <name> <block-softlimit> <block-hardlimit> <inode-softlimit> <inode-hardlimit> <filesystem>\n"
          "       setquota -t [ -u | -g ] <block-grace> <inode-grace> <filesystem>"},
         {"quota", lfs_quota, 0, "Display disk usage and limits.\n"
-         "usage: quota [ -o obd_uuid ] [ -u | -g ] [name] <filesystem>"},
+         "usage: quota [ -o obd_uuid ] [{-u|-g  <name>}|-t] <filesystem>"},
 #endif
         {"flushctx", lfs_flushctx, 0, "Flush security context for current user.\n"
          "usage: flushctx [-k] [mountpoint...]"},
@@ -161,7 +163,7 @@ static int lfs_setstripe(int argc, char **argv)
 {
         char *fname;
         int result;
-        long st_size;
+        unsigned long st_size;
         int  st_offset, st_count;
         char *end;
         int c;
@@ -253,11 +255,24 @@ static int lfs_setstripe(int argc, char **argv)
         if (stripe_size_arg != NULL) {
                 st_size = strtoul(stripe_size_arg, &end, 0);
                 if (*end != '\0') {
-                        fprintf(stderr, "error: %s: bad stripe size '%s'\n",
-                                argv[0], stripe_size_arg);
-                        return CMD_HELP;
+                        if ((*end == 'k' || *end == 'K') && 
+                            *(end+1) == '\0' &&
+                            (st_size & (~0UL << (32 - 10))) == 0) {
+                                st_size <<= 10;
+                        } else if ((*end == 'm' || *end == 'M') && 
+                                   *(end+1) == '\0' &&
+                                   (st_size & (~0UL << (32 - 20))) == 0) {
+                                st_size <<= 20;
+                        } else if ((*end == 'g' || *end == 'G') && 
+                                   *(end+1) == '\0' &&
+                                   (st_size & (~0UL << (32 - 30))) == 0) {
+                                st_size <<= 30;
+                        } else {
+                                fprintf(stderr, "error: %s: bad stripe size '%s'\n",
+                                        argv[0], stripe_size_arg);
+                                return CMD_HELP;
+                        }
                 }
-
         }
         /* get the stripe offset */
         if (stripe_off_arg != NULL) {
@@ -315,12 +330,8 @@ static int lfs_find(int argc, char **argv)
 {
         int new_fashion = 1;
         int c, ret;
-        int zeroend;
         time_t t;
-        unsigned int depth;
-        int quiet, verbose, recursive;
-        struct find_param param;
-        struct obd_uuid *obduuid = NULL;
+        struct find_param param = { .maxdepth = -1 };
         char timestr[1024];
         struct option long_opts[] = {
                 /* New find options. */
@@ -348,15 +359,9 @@ static int lfs_find(int argc, char **argv)
         int isoption;
 
         time(&t);
-        zeroend = 0;
-        depth = -1;
-        quiet = verbose = recursive = 0;
-
-        memset(&param, 0, sizeof(param));
 
-        while ((c = getopt_long_only(argc, argv, "-A:C:D:M:n:PpOqrv",
-                                     long_opts, NULL)) >= 0)
-        {
+        while ((c = getopt_long_only(argc, argv, "-A:C:D:M:n:PpO:qrv",
+                                     long_opts, NULL)) >= 0) {
                 xtime = NULL;
                 xsign = NULL;
                 if (neg_opt)
@@ -419,7 +424,7 @@ static int lfs_find(int argc, char **argv)
                                 *xsign = ret;
                         break;
                 case 'D':
-                        depth = strtol(optarg, 0, 0);
+                        param.maxdepth = strtol(optarg, 0, 0);
                         break;
                 case 'n':
                         new_fashion = 1;
@@ -430,32 +435,32 @@ static int lfs_find(int argc, char **argv)
                                 param.exclude_pattern = 0;
                         break;
                 case 'O':
-                        if (obduuid) {
+                        if (param.obduuid) {
                                 fprintf(stderr,
                                         "error: %s: only one obduuid allowed",
                                         argv[0]);
                                 return CMD_HELP;
                         }
-                        obduuid = (struct obd_uuid *)optarg;
+                        param.obduuid = (struct obd_uuid *)optarg;
                         break;
                 case 'p':
-                        zeroend = 1;
+                        param.zeroend = 1;
                         break;
                 case 'P':
                         break;
                 case 'q':
                         new_fashion = 0;
-                        quiet++;
-                        verbose = 0;
+                        param.quiet++;
+                        param.verbose = 0;
                         break;
                 case 'r':
                         new_fashion = 0;
-                        recursive = 1;
+                        param.recursive = 1;
                         break;
                 case 'v':
                         new_fashion = 0;
-                        verbose++;
-                        quiet = 0;
+                        param.verbose++;
+                        param.quiet = 0;
                         break;
                 case '?':
                         return CMD_HELP;
@@ -475,16 +480,11 @@ static int lfs_find(int argc, char **argv)
                 pathend = argc;
         }
 
-        param.obduuid = obduuid;
         if (new_fashion) {
-                param.maxdepth = depth;
-                param.zeroend = zeroend;
                 param.quiet = 1;
         } else {
-                param.recursive = recursive;
-                param.verbose = verbose;
-                param.quiet = quiet;
-                param.maxdepth = recursive ? -1 : 1;
+                if (!param.recursive && param.maxdepth == -1)
+                        param.maxdepth = 1;
         }
         
         do {
@@ -510,34 +510,32 @@ static int lfs_getstripe(int argc, char **argv)
                 {0, 0, 0, 0}
         };
         char short_opts[] = "hO:qrv";
-        int quiet, verbose, recursive, c, rc;
-        struct obd_uuid *obduuid = NULL;
-        struct find_param param;
+        int c, rc;
+        struct find_param param = { 0 };
 
         optind = 0;
-        quiet = verbose = recursive = 0;
         while ((c = getopt_long(argc, argv, short_opts,
                                 long_opts, NULL)) != -1) {
                 switch (c) {
                 case 'O':
-                        if (obduuid) {
+                        if (param.obduuid) {
                                 fprintf(stderr,
                                         "error: %s: only one obduuid allowed",
                                         argv[0]);
                                 return CMD_HELP;
                         }
-                        obduuid = (struct obd_uuid *)optarg;
+                        param.obduuid = (struct obd_uuid *)optarg;
                         break;
                 case 'q':
-                        quiet++;
-                        verbose = 0;
+                        param.quiet++;
+                        param.verbose = 0;
                         break;
                 case 'r':
-                        recursive = 1;
+                        param.recursive = 1;
                         break;
                 case 'v':
-                        verbose++;
-                        quiet = 0;
+                        param.verbose++;
+                        param.quiet = 0;
                         break;
                 case '?':
                         return CMD_HELP;
@@ -551,12 +549,7 @@ static int lfs_getstripe(int argc, char **argv)
         if (optind >= argc)
                 return CMD_HELP;
 
-        memset(&param, 0, sizeof(param));
-        param.recursive = recursive;
-        param.verbose = verbose;
-        param.quiet = quiet;
-        param.obduuid = obduuid;
-        param.maxdepth = recursive ? -1 : 1;
+        param.maxdepth = param.recursive ? -1 : 1;
 
         do {
                 rc = llapi_getstripe(argv[optind], &param);
@@ -1400,7 +1393,7 @@ static void print_quota_title(char *name, struct if_quotactl *qctl)
                *type2name(qctl->qc_type), qctl->qc_id);
         printf("%15s%8s %7s%8s%8s%8s %7s%8s%8s\n",
                "Filesystem",
-               "blocks", "quota", "limit", "grace",
+               "kbytes", "quota", "limit", "grace",
                "files", "quota", "limit", "grace");
 }
 
@@ -1543,22 +1536,20 @@ static int lfs_quota(int argc, char **argv)
 {
         int c;
         char *name = NULL, *mnt;
-        struct if_quotactl qctl;
+        struct if_quotactl qctl = { .qc_cmd = LUSTRE_Q_GETQUOTA,
+                                    .qc_type = 0x01 };
         char *obd_type = qctl.obd_type;
         char *obd_uuid = qctl.obd_uuid.uuid;
         int rc;
 
-        memset(&qctl, 0, sizeof(qctl));
-        qctl.qc_cmd = LUSTRE_Q_GETQUOTA;
-
         optind = 0;
         while ((c = getopt(argc, argv, "ugto:")) != -1) {
                 switch (c) {
                 case 'u':
-                        qctl.qc_type |= 0x01;
+                        qctl.qc_type = 0x01;
                         break;
                 case 'g':
-                        qctl.qc_type |= 0x02;
+                        qctl.qc_type = 0x02;
                         break;
                 case 't':
                         qctl.qc_cmd = LUSTRE_Q_GETINFO;
@@ -1576,25 +1567,23 @@ static int lfs_quota(int argc, char **argv)
         if (qctl.qc_type)
                 qctl.qc_type--;
 
-        if (qctl.qc_type == UGQUOTA) {
-                fprintf(stderr, "error: user or group can't be specified"
-                                "both\n");
-                return CMD_HELP;
-        }
 
         if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA) {
-                if (optind + 2 != argc)
+                if (optind + 2 != argc) {
+                        fprintf(stderr, "error: missing quota argument(s)\n");
                         return CMD_HELP;
+                }
 
                 name = argv[optind++];
                 rc = name2id(&qctl.qc_id, name, qctl.qc_type);
                 if (rc) {
-                        fprintf(stderr, "error: find id for name %s failed: %s\n",
+                        fprintf(stderr,"error: can't find id for name %s: %s\n",
                                 name, strerror(errno));
                         return CMD_HELP;
                 }
                 print_quota_title(name, &qctl);
         } else if (optind + 1 != argc) {
+                fprintf(stderr, "error: missing quota info argument(s)\n");
                 return CMD_HELP;
         }
 
@@ -1776,7 +1765,7 @@ static int acl_cmd_parse(int argc, char **argv, char *fname, char *cmd)
                 if (!mnt)
                         break;
 
-                if (!llapi_is_lustre_mnttype(mnt))
+                if (!llapi_is_lustre_mnttype(mnt->mnt_type))
                         continue;
 
                 if (!strncmp(mnt->mnt_dir, path, strlen(mnt->mnt_dir))) {