Whamcloud - gitweb
LU-8631 quota: better error message for 'lfs quota'
[fs/lustre-release.git] / lustre / utils / lfs.c
index 71952b6..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
  */
 #include <lustre_ver.h>
 #include <lustre_param.h>
 
+#ifndef ARRAY_SIZE
+# define ARRAY_SIZE(a) ((sizeof(a)) / (sizeof((a)[0])))
+#endif /* !ARRAY_SIZE */
+
 /* all functions */
 static int lfs_setstripe(int argc, char **argv);
 static int lfs_find(int argc, char **argv);
@@ -116,6 +116,7 @@ static int lfs_hsm_remove(int argc, char **argv);
 static int lfs_hsm_cancel(int argc, char **argv);
 static int lfs_swap_layouts(int argc, char **argv);
 static int lfs_mv(int argc, char **argv);
+static int lfs_ladvise(int argc, char **argv);
 
 /* Setstripe and migrate share mostly the same parameters */
 #define SSM_CMD_COMMON(cmd) \
@@ -123,7 +124,7 @@ static int lfs_mv(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" \
@@ -137,7 +138,7 @@ static int lfs_mv(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                                                \
@@ -155,6 +156,19 @@ static int lfs_mv(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;
 
@@ -170,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"
@@ -198,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"
@@ -356,17 +354,40 @@ command_t cmdlist[] = {
        {"swap_layouts", lfs_swap_layouts, 0, "Swap layouts between 2 files.\n"
         "usage: swap_layouts <path1> <path2>"},
        {"migrate", lfs_setstripe, 0,
-        "migrate file/directory between MDTs, or migrate file from one OST "
+        "migrate a directory between MDTs.\n"
+        "usage: migrate --mdt-index <mdt_idx> [--verbose|-v] "
+        "<directory>\n"
+        "\tmdt_idx:      index of the destination MDT\n"
+        "\n"
+        "migrate file objects from one OST "
         "layout\nto another (may be not safe with concurent writes).\n"
-        "usage: migrate   [--mdt-index|-m <mdt_idx>] <directory|filename>]\n"
-        "\tmdt_idx:      MDT index to migrate to\n"
-        " or\n"
-        MIGRATE_USAGE},
+        "usage: migrate  "
+        "[--stripe-count|-c] <stripe_count>\n"
+        "              [--stripe-index|-i] <start_ost_index>\n"
+        "              [--stripe-size|-S] <stripe_size>\n"
+        "              [--pool|-p] <pool_name>\n"
+        "              [--ost-list|-o] <ost_indices>\n"
+        "              [--block|-b]\n"
+        "              [--non-block|-n]\n"
+        "              <file|directory>\n"
+        "\tstripe_count:     number of OSTs to stripe a file over\n"
+        "\tstripe_ost_index: index of the first OST to stripe a file over\n"
+        "\tstripe_size:      number of bytes to store before moving to the next OST\n"
+        "\tpool_name:        name of the predefined pool of OSTs\n"
+        "\tost_indices:      OSTs to stripe over, in order\n"
+        "\tblock:            wait for the operation to return before continuing\n"
+        "\tnon-block:        do not wait for the operation to return.\n"},
        {"mv", lfs_mv, 0,
         "To move directories between MDTs. This command is deprecated, "
         "use \"migrate\" instead.\n"
         "usage: mv <directory|filename> [--mdt-index|-M] <mdt_index> "
         "[--verbose|-v]\n"},
+       {"ladvise", lfs_ladvise, 0,
+        "Provide servers with advice about access patterns for a file.\n"
+        "usage: ladvise [--advice|-a ADVICE] [--start|-s START[kMGT]]\n"
+        "               [--background|-b]\n"
+        "               {[--end|-e END[kMGT]] | [--length|-l LENGTH[kMGT]]}\n"
+        "               <file> ..."},
        {"help", Parser_help, 0, "help"},
        {"exit", Parser_quit, 0, "quit"},
        {"quit", Parser_quit, 0, "quit"},
@@ -926,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
@@ -941,6 +966,8 @@ static int lfs_setstripe(int argc, char **argv)
 #endif
                {"stripe-size",  required_argument, 0, 'S'},
                {"stripe_size",  required_argument, 0, 'S'},
+               /* --verbose is only valid in migrate mode */
+               {"verbose",      no_argument,       0, 'v'},
                {0, 0, 0, 0}
        };
 
@@ -951,7 +978,7 @@ static int lfs_setstripe(int argc, char **argv)
        if (strcmp(argv[0], "migrate") == 0)
                migrate_mode = true;
 
-       while ((c = getopt_long(argc, argv, "bc:di:m:no:p:s:S:",
+       while ((c = getopt_long(argc, argv, "bc:di:m:no:p:s:S:v",
                                long_opts, NULL)) >= 0) {
                switch (c) {
                case 0:
@@ -1028,6 +1055,14 @@ static int lfs_setstripe(int argc, char **argv)
                case 'p':
                        pool_name_arg = optarg;
                        break;
+               case 'v':
+                       if (!migrate_mode) {
+                               fprintf(stderr, "--verbose is valid only for"
+                                               " migrate mode\n");
+                               return CMD_HELP;
+                       }
+                       migrate_mdt_param.fp_verbose = VERBOSE_DETAIL;
+                       break;
                default:
                        return CMD_HELP;
                }
@@ -1186,10 +1221,11 @@ static int lfs_setstripe(int argc, char **argv)
                        /* Save the first error encountered. */
                        if (result2 == 0)
                                result2 = result;
-                       fprintf(stderr,
-                               "error: %s: %s file '%s' failed\n",
+                       fprintf(stderr, "error: %s: %s file '%s' failed: %s\n",
                                argv[0], migrate_mode ? "migrate" : "create",
-                               fname);
+                               fname,
+                               pool_name_arg != NULL && result == EINVAL ?
+                               "OST not in pool?" : strerror(errno));
                        continue;
                }
        }
@@ -1329,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) */
@@ -1699,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
@@ -1709,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
@@ -1736,8 +1780,7 @@ static int lfs_getstripe_internal(int argc, char **argv,
        };
        int c, rc;
 
-       param->fp_max_depth = 1;
-       while ((c = getopt_long(argc, argv, "cdDghiLMoO:pqrRsSv",
+       while ((c = getopt_long(argc, argv, "cdDFghiLmMoO:pqrRsSv",
                                long_opts, NULL)) != -1) {
                switch (c) {
                case 'O':
@@ -1758,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)
@@ -1822,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;
@@ -1842,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;
 
@@ -1897,6 +1953,8 @@ static int lfs_tgts(int argc, char **argv)
 static int lfs_getstripe(int argc, char **argv)
 {
        struct find_param param = { 0 };
+
+       param.fp_max_depth = 1;
        return lfs_getstripe_internal(argc, argv, &param);
 }
 
@@ -1929,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}
        };
@@ -1945,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':
@@ -1955,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:
@@ -2917,22 +3000,29 @@ static void print_quota_title(char *name, struct if_quotactl *qctl,
               "files", "quota", "limit", "grace");
 }
 
-static void kbytes2str(__u64 num, char *buf, bool h)
+static void kbytes2str(__u64 num, char *buf, int buflen, bool h)
 {
        if (!h) {
-               sprintf(buf, LPU64, num);
+               snprintf(buf, buflen, "%ju", (uintmax_t)num);
        } else {
-               if (num >> 30)
-                       sprintf(buf, "%5.4gT", (double)num / (1 << 30));
+               if (num >> 40)
+                       snprintf(buf, buflen, "%5.4gP",
+                                (double)num / ((__u64)1 << 40));
+               else if (num >> 30)
+                       snprintf(buf, buflen, "%5.4gT",
+                                (double)num / (1 << 30));
                else if (num >> 20)
-                       sprintf(buf, "%5.4gG", (double)num / (1 << 20));
+                       snprintf(buf, buflen, "%5.4gG",
+                                (double)num / (1 << 20));
                else if (num >> 10)
-                       sprintf(buf, "%5.4gM", (double)num / (1 << 10));
+                       snprintf(buf, buflen, "%5.4gM",
+                                (double)num / (1 << 10));
                else
-                       sprintf(buf, LPU64"%s", num, "k");
+                       snprintf(buf, buflen, "%ju%s", (uintmax_t)num, "k");
        }
 }
 
+#define STRBUF_LEN     32
 static void print_quota(char *mnt, struct if_quotactl *qctl, int type,
                        int rc, bool h)
 {
@@ -2943,9 +3033,9 @@ static void print_quota(char *mnt, struct if_quotactl *qctl, int type,
         if (qctl->qc_cmd == LUSTRE_Q_GETQUOTA || qctl->qc_cmd == Q_GETOQUOTA) {
                int bover = 0, iover = 0;
                struct obd_dqblk *dqb = &qctl->qc_dqblk;
-               char numbuf[3][32];
+               char numbuf[3][STRBUF_LEN];
                char timebuf[40];
-               char strbuf[32];
+               char strbuf[STRBUF_LEN];
 
                 if (dqb->dqb_bhardlimit &&
                    lustre_stoqb(dqb->dqb_curspace) >= dqb->dqb_bhardlimit) {
@@ -2978,21 +3068,22 @@ static void print_quota(char *mnt, struct if_quotactl *qctl, int type,
                if (bover)
                        diff2str(dqb->dqb_btime, timebuf, now);
 
-               kbytes2str(lustre_stoqb(dqb->dqb_curspace), strbuf, h);
+               kbytes2str(lustre_stoqb(dqb->dqb_curspace),
+                          strbuf, sizeof(strbuf), h);
                if (rc == -EREMOTEIO)
                        sprintf(numbuf[0], "%s*", strbuf);
                else
                        sprintf(numbuf[0], (dqb->dqb_valid & QIF_SPACE) ?
                                "%s" : "[%s]", strbuf);
 
-               kbytes2str(dqb->dqb_bsoftlimit, strbuf, h);
+               kbytes2str(dqb->dqb_bsoftlimit, strbuf, sizeof(strbuf), h);
                if (type == QC_GENERAL)
                        sprintf(numbuf[1], (dqb->dqb_valid & QIF_BLIMITS) ?
                                "%s" : "[%s]", strbuf);
                else
                        sprintf(numbuf[1], "%s", "-");
 
-               kbytes2str(dqb->dqb_bhardlimit, strbuf, h);
+               kbytes2str(dqb->dqb_bhardlimit, strbuf, sizeof(strbuf), h);
                sprintf(numbuf[2], (dqb->dqb_valid & QIF_BLIMITS) ?
                        "%s" : "[%s]", strbuf);
 
@@ -3004,16 +3095,17 @@ static void print_quota(char *mnt, struct if_quotactl *qctl, int type,
                        diff2str(dqb->dqb_itime, timebuf, now);
 
                sprintf(numbuf[0], (dqb->dqb_valid & QIF_INODES) ?
-                       LPU64 : "["LPU64"]", dqb->dqb_curinodes);
+                       "%ju" : "[%ju]", (uintmax_t)dqb->dqb_curinodes);
 
                if (type == QC_GENERAL)
                        sprintf(numbuf[1], (dqb->dqb_valid & QIF_ILIMITS) ?
-                               LPU64 : "["LPU64"]", dqb->dqb_isoftlimit);
+                               "%ju" : "[%ju]",
+                               (uintmax_t)dqb->dqb_isoftlimit);
                else
                        sprintf(numbuf[1], "%s", "-");
 
                sprintf(numbuf[2], (dqb->dqb_valid & QIF_ILIMITS) ?
-                       LPU64 : "["LPU64"]", dqb->dqb_ihardlimit);
+                       "%ju" : "[%ju]", (uintmax_t)dqb->dqb_ihardlimit);
 
                if (type != QC_OSTIDX)
                        printf(" %7s%c %6s %7s %7s",
@@ -3183,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);
@@ -3217,15 +3310,17 @@ ug_output:
 
        if (qctl.qc_valid == QC_GENERAL && qctl.qc_cmd != LUSTRE_Q_GETINFO &&
            verbose) {
-               char strbuf[32];
+               char strbuf[STRBUF_LEN];
 
                rc2 = print_obd_quota(mnt, &qctl, 1, human_readable,
                                      &total_ialloc);
                rc3 = print_obd_quota(mnt, &qctl, 0, human_readable,
                                      &total_balloc);
-               kbytes2str(total_balloc, strbuf, human_readable);
-               printf("Total allocated inode limit: "LPU64", total "
-                      "allocated block limit: %s\n", total_ialloc, strbuf);
+               kbytes2str(total_balloc, strbuf, sizeof(strbuf),
+                          human_readable);
+               printf("Total allocated inode limit: %ju, total "
+                      "allocated block limit: %s\n", (uintmax_t)total_ialloc,
+                      strbuf);
        }
 
         if (rc1 || rc2 || rc3 || inacc)
@@ -3311,36 +3406,44 @@ static int lfs_flushctx(int argc, char **argv)
 
 static int lfs_lsetfacl(int argc, char **argv)
 {
-        argv[0]++;
-        return(llapi_lsetfacl(argc, argv));
+       fprintf(stderr, "local client sets facl for remote client.\n"
+               "obsolete, does not support it anymore.\n");
+       return 0;
 }
 
 static int lfs_lgetfacl(int argc, char **argv)
 {
-        argv[0]++;
-        return(llapi_lgetfacl(argc, argv));
+       fprintf(stderr, "local client gets facl for remote client.\n"
+               "obsolete, does not support it anymore.\n");
+       return 0;
 }
 
 static int lfs_rsetfacl(int argc, char **argv)
 {
-        argv[0]++;
-        return(llapi_rsetfacl(argc, argv));
+       fprintf(stderr, "remote client sets facl for remote client.\n"
+               "obsolete, does not support it anymore.\n");
+       return 0;
 }
 
 static int lfs_rgetfacl(int argc, char **argv)
 {
-        argv[0]++;
-        return(llapi_rgetfacl(argc, argv));
+       fprintf(stderr, "remote client gets facl for remote client.\n"
+               "obsolete, does not support it anymore.\n");
+       return 0;
 }
 
 static int lfs_cp(int argc, char **argv)
 {
-        return(llapi_cp(argc, argv));
+       fprintf(stderr, "remote client copy file(s).\n"
+               "obsolete, does not support it anymore.\n");
+       return 0;
 }
 
 static int lfs_ls(int argc, char **argv)
 {
-        return(llapi_ls(argc, argv));
+       fprintf(stderr, "remote client lists directory contents.\n"
+               "obsolete, does not support it anymore.\n");
+       return 0;
 }
 
 static int lfs_changelog(int argc, char **argv)
@@ -3405,8 +3508,8 @@ static int lfs_changelog(int argc, char **argv)
 
                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,
+               printf("%ju %02d%-5s %02d:%02d:%02d.%06d %04d.%02d.%02d "
+                      "0x%x t="DFID, (uintmax_t) 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)),
@@ -3670,7 +3773,7 @@ static int lfs_data_version(int argc, char **argv)
        if (rc < 0)
                err(errno, "cannot get version for %s", path);
        else
-               printf(LPU64 "\n", data_version);
+               printf("%ju" "\n", (uintmax_t)data_version);
 
        close(fd);
        return rc;
@@ -4183,6 +4286,181 @@ static int lfs_swap_layouts(int argc, char **argv)
                                  SWAP_LAYOUTS_KEEP_ATIME);
 }
 
+static const char *const ladvise_names[] = LU_LADVISE_NAMES;
+
+static enum lu_ladvise_type lfs_get_ladvice(const char *string)
+{
+       enum lu_ladvise_type advice;
+
+       for (advice = 0;
+            advice < ARRAY_SIZE(ladvise_names); advice++) {
+               if (ladvise_names[advice] == NULL)
+                       continue;
+               if (strcmp(string, ladvise_names[advice]) == 0)
+                       return advice;
+       }
+
+       return LU_LADVISE_INVALID;
+}
+
+static int lfs_ladvise(int argc, char **argv)
+{
+       struct option            long_opts[] = {
+               {"advice",      required_argument,      0, 'a'},
+               {"background",  no_argument,            0, 'b'},
+               {"end",         required_argument,      0, 'e'},
+               {"start",       required_argument,      0, 's'},
+               {"length",      required_argument,      0, 'l'},
+               {0, 0, 0, 0}
+       };
+       char                     short_opts[] = "a:be:l:s:";
+       int                      c;
+       int                      rc = 0;
+       const char              *path;
+       int                      fd;
+       struct llapi_lu_ladvise  advice;
+       enum lu_ladvise_type     advice_type = LU_LADVISE_INVALID;
+       unsigned long long       start = 0;
+       unsigned long long       end = LUSTRE_EOF;
+       unsigned long long       length = 0;
+       unsigned long long       size_units;
+       unsigned long long       flags = 0;
+
+       optind = 0;
+       while ((c = getopt_long(argc, argv, short_opts,
+                               long_opts, NULL)) != -1) {
+               switch (c) {
+               case 'a':
+                       advice_type = lfs_get_ladvice(optarg);
+                       if (advice_type == LU_LADVISE_INVALID) {
+                               fprintf(stderr, "%s: invalid advice type "
+                                       "'%s'\n", argv[0], optarg);
+                               fprintf(stderr, "Valid types:");
+
+                               for (advice_type = 0;
+                                    advice_type < ARRAY_SIZE(ladvise_names);
+                                    advice_type++) {
+                                       if (ladvise_names[advice_type] == NULL)
+                                               continue;
+                                       fprintf(stderr, " %s",
+                                               ladvise_names[advice_type]);
+                               }
+                               fprintf(stderr, "\n");
+
+                               return CMD_HELP;
+                       }
+                       break;
+               case 'b':
+                       flags |= LF_ASYNC;
+                       break;
+               case 'e':
+                       size_units = 1;
+                       rc = llapi_parse_size(optarg, &end,
+                                             &size_units, 0);
+                       if (rc) {
+                               fprintf(stderr, "%s: bad end offset '%s'\n",
+                                       argv[0], optarg);
+                               return CMD_HELP;
+                       }
+                       break;
+               case 's':
+                       size_units = 1;
+                       rc = llapi_parse_size(optarg, &start,
+                                             &size_units, 0);
+                       if (rc) {
+                               fprintf(stderr, "%s: bad start offset "
+                                       "'%s'\n", argv[0], optarg);
+                               return CMD_HELP;
+                       }
+                       break;
+               case 'l':
+                       size_units = 1;
+                       rc = llapi_parse_size(optarg, &length,
+                                             &size_units, 0);
+                       if (rc) {
+                               fprintf(stderr, "%s: bad length '%s'\n",
+                                       argv[0], optarg);
+                               return CMD_HELP;
+                       }
+                       break;
+               case '?':
+                       return CMD_HELP;
+               default:
+                       fprintf(stderr, "%s: option '%s' unrecognized\n",
+                               argv[0], argv[optind - 1]);
+                       return CMD_HELP;
+               }
+       }
+
+       if (advice_type == LU_LADVISE_INVALID) {
+               fprintf(stderr, "%s: please give an advice type\n", argv[0]);
+               fprintf(stderr, "Valid types:");
+               for (advice_type = 0; advice_type < ARRAY_SIZE(ladvise_names);
+                    advice_type++) {
+                       if (ladvise_names[advice_type] == NULL)
+                               continue;
+                       fprintf(stderr, " %s", ladvise_names[advice_type]);
+               }
+               fprintf(stderr, "\n");
+               return CMD_HELP;
+       }
+
+       if (argc <= optind) {
+               fprintf(stderr, "%s: please give one or more file names\n",
+                       argv[0]);
+               return CMD_HELP;
+       }
+
+       if (end != LUSTRE_EOF && length != 0 && end != start + length) {
+               fprintf(stderr, "%s: conflicting arguments of -l and -e\n",
+                       argv[0]);
+               return CMD_HELP;
+       }
+
+       if (end == LUSTRE_EOF && length != 0)
+               end = start + length;
+
+       if (end <= start) {
+               fprintf(stderr, "%s: range [%llu, %llu] is invalid\n",
+                       argv[0], start, end);
+               return CMD_HELP;
+       }
+
+       while (optind < argc) {
+               int rc2;
+
+               path = argv[optind++];
+
+               fd = open(path, O_RDONLY);
+               if (fd < 0) {
+                       fprintf(stderr, "%s: cannot open file '%s': %s\n",
+                               argv[0], path, strerror(errno));
+                       rc2 = -errno;
+                       goto next;
+               }
+
+               advice.lla_start = start;
+               advice.lla_end = end;
+               advice.lla_advice = advice_type;
+               advice.lla_value1 = 0;
+               advice.lla_value2 = 0;
+               advice.lla_value3 = 0;
+               advice.lla_value4 = 0;
+               rc2 = llapi_ladvise(fd, flags, 1, &advice);
+               close(fd);
+               if (rc2 < 0) {
+                       fprintf(stderr, "%s: cannot give advice '%s' to file "
+                               "'%s': %s\n", argv[0],
+                               ladvise_names[advice_type],
+                               path, strerror(errno));
+               }
+next:
+               if (rc == 0 && rc2 < 0)
+                       rc = rc2;
+       }
+       return rc;
+}
+
 int main(int argc, char **argv)
 {
         int rc;