Whamcloud - gitweb
LU-8631 quota: better error message for 'lfs quota'
[fs/lustre-release.git] / lustre / utils / lfs.c
index 6969373..9ba0757 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -128,7 +124,7 @@ static int lfs_ladvise(int argc, char **argv);
        "                 [--stripe-index|-i <start_ost_idx>]\n"        \
        "                 [--stripe-size|-S <stripe_size>]\n"           \
        "                 [--pool|-p <pool_name>]\n"                    \
-       "                 [--ost-list|-o <ost_indices>]\n"
+       "                 [--ost|-o <ost_indices>]\n"
 
 #define SSM_HELP_COMMON \
        "\tstripe_size:  Number of bytes on each OST (0 filesystem default)\n" \
@@ -142,7 +138,7 @@ static int lfs_ladvise(int argc, char **argv);
        "\t                -o <ost_1>,<ost_i>-<ost_j>,<ost_n>\n"        \
        "\t              Or:\n"                                         \
        "\t                -o <ost_1> -o <ost_i>-<ost_j> -o <ost_n>\n"  \
-       "\t              If --pool is set with --ost-list, then the OSTs\n" \
+       "\t              If --pool is set with --ost, then the OSTs\n" \
        "\t              must be the members of the pool."
 
 #define SETSTRIPE_USAGE                                                \
@@ -160,6 +156,19 @@ static int lfs_ladvise(int argc, char **argv);
        "\tblock:        Block file access during data migration (default)\n" \
        "\tnon-block:    Abort migrations if concurrent access is detected\n" \
 
+#define SETDIRSTRIPE_USAGE                                     \
+       "               [--mdt-count|-c stripe_count>\n"        \
+       "               [--mdt-index|-i mdt_index]\n"           \
+       "               [--mdt-hash|-t mdt_hash]\n"             \
+       "               [--default_stripe|-D] [--mode|-m mode] <dir>\n" \
+       "\tstripe_count: stripe count of the striped directory\n"       \
+       "\tmdt_index: MDT index of first stripe\n"                      \
+       "\tmdt_hash:  hash type of the striped directory. mdt types:\n" \
+       "       fnv_1a_64 FNV-1a hash algorithm (default)\n"            \
+       "       all_char  sum of characters % MDT_COUNT (not recommended)\n" \
+       "\tdefault_stripe: set default dirstripe of the directory\n"    \
+       "\tmode: the mode of the directory\n"
+
 static const char      *progname;
 static bool             file_lease_supported = true;
 
@@ -175,25 +184,17 @@ command_t cmdlist[] = {
        {"getstripe", lfs_getstripe, 0,
         "To list the striping info for a given file or files in a\n"
         "directory or recursively for all files in a directory tree.\n"
-        "usage: getstripe [--ost|-O <uuid>] [--quiet | -q] [--verbose | -v]\n"
+        "usage: getstripe [--ost|-O <uuid>] [--quiet|-q] [--verbose|-v]\n"
         "                 [--stripe-count|-c] [--stripe-index|-i]\n"
         "                 [--pool|-p] [--stripe-size|-S] [--directory|-d]\n"
-        "                 [--mdt-index|-M] [--recursive|-r] [--raw|-R]\n"
-        "                 [--layout|-L]\n"
+        "                 [--mdt|-m] [--recursive|-r] [--raw|-R]\n"
+        "                 [--layout|-L] [--fid|-F] [--generation|-g]\n"
         "                 <directory|filename> ..."},
        {"setdirstripe", lfs_setdirstripe, 0,
         "To create a striped directory on a specified MDT. This can only\n"
         "be done on MDT0 with the right of administrator.\n"
-        "usage: setdirstripe <--count|-c stripe_count>\n"
-        "              [--index|-i mdt_index] [--hash-type|-t hash_type]\n"
-        "              [--default_stripe|-D ] [--mode|-m mode] <dir>\n"
-        "\tstripe_count: stripe count of the striped directory\n"
-        "\tmdt_index:  MDT index of first stripe\n"
-        "\thash_type:  hash type of the striped directory. Hash types:\n"
-        "      fnv_1a_64 FNV-1a hash algorithm (default)\n"
-        "      all_char  sum of characters % MDT_COUNT (not recommended)\n"
-        "\tdefault_stripe: set default dirstripe of the directory\n"
-        "\tmode: the mode of the directory\n"},
+        "usage: setdirstripe [OPTION] <directory>\n"
+        SETDIRSTRIPE_USAGE},
        {"getdirstripe", lfs_getdirstripe, 0,
         "To list the striping info for a given directory\n"
         "or recursively for all directories in a directory tree.\n"
@@ -203,16 +204,8 @@ command_t cmdlist[] = {
        {"mkdir", lfs_setdirstripe, 0,
         "To create a striped directory on a specified MDT. This can only\n"
         "be done on MDT0 with the right of administrator.\n"
-        "usage: mkdir <--count|-c stripe_count>\n"
-        "              [--index|-i mdt_index] [--hash-type|-t hash_type]\n"
-        "              [--default_stripe|-D ] [--mode|-m mode] <dir>\n"
-        "\tstripe_count: stripe count of the striped directory\n"
-        "\tmdt_index:  MDT index of first stripe\n"
-        "\thash_type:  hash type of the striped directory. Hash types:\n"
-        "      fnv_1a_64 FNV-1a hash algorithm (default)\n"
-        "      all_char  sum of characters % MDT_COUNT (not recommended)\n"
-        "\tdefault_stripe: set default dirstripe of the directory\n"
-        "\tmode: the mode of the directory\n"},
+        "usage: mkdir [OPTION] <directory>\n"
+        SETDIRSTRIPE_USAGE},
        {"rm_entry", lfs_rmentry, 0,
         "To remove the name entry of the remote directory. Note: This\n"
         "command will only delete the name entry, i.e. the remote directory\n"
@@ -954,12 +947,16 @@ static int lfs_setstripe(int argc, char **argv)
 #endif
                {"stripe-index", required_argument, 0, 'i'},
                {"stripe_index", required_argument, 0, 'i'},
+               {"mdt",          required_argument, 0, 'm'},
                {"mdt-index",    required_argument, 0, 'm'},
                {"mdt_index",    required_argument, 0, 'm'},
                /* --non-block is only valid in migrate mode */
                {"non-block",    no_argument,       0, 'n'},
+               {"ost",          required_argument, 0, 'o'},
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
                {"ost-list",     required_argument, 0, 'o'},
                {"ost_list",     required_argument, 0, 'o'},
+#endif
                {"pool",         required_argument, 0, 'p'},
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 53, 0)
                /* This formerly implied "--stripe-size", but was confusing
@@ -1228,7 +1225,7 @@ static int lfs_setstripe(int argc, char **argv)
                                argv[0], migrate_mode ? "migrate" : "create",
                                fname,
                                pool_name_arg != NULL && result == EINVAL ?
-                               "OST not in pool?" : strerror(result));
+                               "OST not in pool?" : strerror(errno));
                        continue;
                }
        }
@@ -1368,6 +1365,8 @@ static int lfs_find(int argc, char **argv)
                 {"stripe_index", required_argument, 0, 'i'},
                {"layout",       required_argument, 0, 'L'},
                 {"mdt",          required_argument, 0, 'm'},
+                {"mdt-index",    required_argument, 0, 'm'},
+                {"mdt_index",    required_argument, 0, 'm'},
                 {"mtime",        required_argument, 0, 'M'},
                 {"name",         required_argument, 0, 'n'},
      /* reserve {"or",           no_argument,     , 0, 'o'}, to match find(1) */
@@ -1738,6 +1737,7 @@ static int lfs_getstripe_internal(int argc, char **argv,
                {"stripe_count",        no_argument,            0, 'c'},
                {"directory",           no_argument,            0, 'd'},
                {"default",             no_argument,            0, 'D'},
+               {"fid",                 no_argument,            0, 'F'},
                {"generation",          no_argument,            0, 'g'},
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 53, 0)
                /* This formerly implied "stripe-index", but was explicitly
@@ -1748,8 +1748,13 @@ static int lfs_getstripe_internal(int argc, char **argv,
                {"stripe-index",        no_argument,            0, 'i'},
                {"stripe_index",        no_argument,            0, 'i'},
                {"layout",              no_argument,            0, 'L'},
+               {"mdt",                 no_argument,            0, 'm'},
+               {"mdt-index",           no_argument,            0, 'm'},
+               {"mdt_index",           no_argument,            0, 'm'},
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
                {"mdt-index",           no_argument,            0, 'M'},
                {"mdt_index",           no_argument,            0, 'M'},
+#endif
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 53, 0)
                /* This formerly implied "stripe-index", but was confusing
                 * with "file offset" (which will eventually be needed for
@@ -1775,7 +1780,7 @@ static int lfs_getstripe_internal(int argc, char **argv,
        };
        int c, rc;
 
-       while ((c = getopt_long(argc, argv, "cdDghiLMoO:pqrRsSv",
+       while ((c = getopt_long(argc, argv, "cdDFghiLmMoO:pqrRsSv",
                                long_opts, NULL)) != -1) {
                switch (c) {
                case 'O':
@@ -1796,11 +1801,17 @@ static int lfs_getstripe_internal(int argc, char **argv,
                case 'D':
                        param->fp_get_default_lmv = 1;
                        break;
+               case 'F':
+                       if (!(param->fp_verbose & VERBOSE_DETAIL)) {
+                               param->fp_verbose |= VERBOSE_DFID;
+                               param->fp_max_depth = 0;
+                       }
+                       break;
                case 'r':
                        param->fp_recursive = 1;
                        break;
                case 'v':
-                       param->fp_verbose = VERBOSE_ALL | VERBOSE_DETAIL;
+                       param->fp_verbose = VERBOSE_DEFAULT | VERBOSE_DETAIL;
                        break;
                case 'c':
 #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 6, 53, 0)
@@ -1860,7 +1871,14 @@ static int lfs_getstripe_internal(int argc, char **argv,
                                param->fp_max_depth = 0;
                        }
                        break;
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
                case 'M':
+#if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 11, 53, 0)
+                       fprintf(stderr, "warning: '-M' deprecated"
+                               ", use '-m' instead\n");
+#endif
+#endif
+               case 'm':
                        if (!(param->fp_verbose & VERBOSE_DETAIL))
                                param->fp_max_depth = 0;
                        param->fp_verbose |= VERBOSE_MDTINDEX;
@@ -1880,7 +1898,7 @@ static int lfs_getstripe_internal(int argc, char **argv,
                param->fp_max_depth = -1;
 
        if (!param->fp_verbose)
-               param->fp_verbose = VERBOSE_ALL;
+               param->fp_verbose = VERBOSE_DEFAULT;
        if (param->fp_quiet)
                param->fp_verbose = VERBOSE_OBJID;
 
@@ -1969,11 +1987,20 @@ static int lfs_setdirstripe(int argc, char **argv)
        bool                    delete = false;
 
        struct option long_opts[] = {
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
                {"count",       required_argument, 0, 'c'},
+#endif
+               {"mdt-count",   required_argument, 0, 'c'},
                {"delete",      no_argument, 0, 'd'},
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
                {"index",       required_argument, 0, 'i'},
+#endif
+               {"mdt-index",   required_argument, 0, 'i'},
                {"mode",        required_argument, 0, 'm'},
+#if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
                {"hash-type",   required_argument, 0, 't'},
+#endif
+               {"mdt-hash",    required_argument, 0, 't'},
                {"default_stripe", no_argument, 0, 'D'},
                {0, 0, 0, 0}
        };
@@ -1985,6 +2012,11 @@ static int lfs_setdirstripe(int argc, char **argv)
                        /* Long options. */
                        break;
                case 'c':
+#if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 11, 53, 0)
+                       if (strcmp(argv[optind - 1], "--count") == 0)
+                               fprintf(stderr, "warning: '--count' deprecated"
+                                       ", use '--mdt-count' instead\n");
+#endif
                        stripe_count_opt = optarg;
                        break;
                case 'd':
@@ -1995,12 +2027,23 @@ static int lfs_setdirstripe(int argc, char **argv)
                        default_stripe = true;
                        break;
                case 'i':
+#if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 11, 53, 0)
+                       if (strcmp(argv[optind - 1], "--index") == 0)
+                               fprintf(stderr, "warning: '--index' deprecated"
+                                       ", use '--mdt-index' instead\n");
+#endif
                        stripe_offset_opt = optarg;
                        break;
                case 'm':
                        mode_opt = optarg;
                        break;
                case 't':
+#if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 11, 53, 0)
+                       if (strcmp(argv[optind - 1], "--hash-type") == 0)
+                               fprintf(stderr, "warning: '--hash-type' "
+                                       "deprecated, use '--mdt-hash' "
+                                       "instead\n");
+#endif
                        stripe_hash_opt = optarg;
                        break;
                default:
@@ -3232,22 +3275,23 @@ ug_output:
         mnt = argv[optind];
 
         rc1 = llapi_quotactl(mnt, &qctl);
-        if (rc1 < 0) {
-                switch (rc1) {
-                case -ESRCH:
-                        fprintf(stderr, "%s quotas are not enabled.\n",
-                                qctl.qc_type == USRQUOTA ? "user" : "group");
-                        goto out;
-                case -EPERM:
-                        fprintf(stderr, "Permission denied.\n");
-                case -ENOENT:
-                        /* We already got a "No such file..." message. */
-                        goto out;
-                default:
-                        fprintf(stderr, "Unexpected quotactl error: %s\n",
-                                strerror(-rc1));
-                }
-        }
+       if (rc1 < 0) {
+               switch (rc1) {
+               case -ESRCH:
+                       fprintf(stderr, "%s quotas are not enabled.\n",
+                               qctl.qc_type == USRQUOTA ? "user" : "group");
+                       goto out;
+               case -EPERM:
+                       fprintf(stderr, "Permission denied.\n");
+               case -ENODEV:
+               case -ENOENT:
+                       /* We already got error message. */
+                       goto out;
+               default:
+                       fprintf(stderr, "Unexpected quotactl error: %s\n",
+                               strerror(-rc1));
+               }
+       }
 
        if (qctl.qc_cmd == LUSTRE_Q_GETQUOTA && !quiet)
                print_quota_title(name, &qctl, human_readable);