Whamcloud - gitweb
LU-6179 llite: Implement ladvise lockahead
[fs/lustre-release.git] / lustre / utils / lfs.c
index 5870cd8..dc07fb9 100644 (file)
@@ -65,8 +65,8 @@
 #include <libcfs/util/ioctl.h>
 #include <libcfs/util/parser.h>
 #include <lustre/lustreapi.h>
-#include <lustre_ver.h>
-#include <linux/lustre_param.h>
+#include <linux/lustre/lustre_ver.h>
+#include <linux/lustre/lustre_param.h>
 
 #ifndef ARRAY_SIZE
 # define ARRAY_SIZE(a) ((sizeof(a)) / (sizeof((a)[0])))
@@ -400,8 +400,9 @@ command_t cmdlist[] = {
        {"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"
+        "               [--background|-b] [--unset|-u]\n\n"
         "               {[--end|-e END[kMGT]] | [--length|-l LENGTH[kMGT]]}\n"
+        "               {[--mode|-m [READ,WRITE]}\n"
         "               <file> ...\n"},
        {"help", Parser_help, 0, "help"},
        {"exit", Parser_quit, 0, "quit"},
@@ -1009,23 +1010,6 @@ static int parse_targets(__u32 *osts, int size, int offset, char *arg)
        return rc < 0 ? rc : nr;
 }
 
-static int verify_pool_name(char *prog_name, char *pool_name)
-{
-       char *ptr;
-
-       if (pool_name == NULL)
-               return 0;
-
-       ptr = strchr(pool_name, '.');
-       if (ptr != NULL && ptr == pool_name) {
-               fprintf(stderr, "error: %s: fsname is empty in pool name '%s'\n",
-                       prog_name, pool_name);
-               return -EINVAL;
-       }
-
-       return 0;
-}
-
 struct lfs_setstripe_args {
        unsigned long long       lsa_comp_end;
        unsigned long long       lsa_stripe_size;
@@ -1171,17 +1155,11 @@ static int adjust_first_extent(char *fname, struct llapi_layout *layout)
                 * into a component-create. */
                llapi_layout_free(head);
                return -ENODATA;
-       } else {
-               /* Current component of 'head' should be tail of component
-                * list by default, but we do an extra move cursor operation
-                * here to test if the layout is non-composite. */
-               rc = llapi_layout_comp_use(head, LLAPI_LAYOUT_COMP_USE_LAST);
-               if (rc < 0) {
-                       fprintf(stderr, "'%s' isn't a composite file?\n",
-                               fname);
-                       llapi_layout_free(head);
-                       return rc;
-               }
+       } else if (!llapi_layout_is_composite(head)) {
+               fprintf(stderr, "'%s' isn't a composite file.\n",
+                       fname);
+               llapi_layout_free(head);
+               return -EINVAL;
        }
 
        rc = llapi_layout_comp_extent_get(head, &start, &prev_end);
@@ -1555,8 +1533,7 @@ static int lfs_setstripe(int argc, char **argv)
                                lsa.lsa_stripe_off = osts[0];
                        break;
                case 'p':
-                       result = verify_pool_name(argv[0], optarg);
-                       if (result)
+                       if (optarg == NULL)
                                goto error;
                        lsa.lsa_pool_name = optarg;
                        break;
@@ -1894,54 +1871,65 @@ static int lfs_find(int argc, char **argv)
 {
        int c, rc;
        int ret = 0;
-        time_t t;
+       time_t t;
        struct find_param param = {
                .fp_max_depth = -1,
                .fp_quiet = 1,
        };
         struct option long_opts[] = {
-               {"atime",        required_argument, 0, 'A'},
-               {"comp-count",   required_argument, 0, LFS_COMP_COUNT_OPT},
-               {"component-count", required_argument, 0, LFS_COMP_COUNT_OPT},
-               {"comp-flags",   required_argument, 0, LFS_COMP_FLAGS_OPT},
-               {"component-flags", required_argument, 0, LFS_COMP_FLAGS_OPT},
-               {"comp-start",   required_argument, 0, LFS_COMP_START_OPT},
-               {"component-start", required_argument, 0, LFS_COMP_START_OPT},
-               {"stripe-count", required_argument, 0, 'c'},
-               {"stripe_count", required_argument, 0, 'c'},
-               {"ctime",        required_argument, 0, 'C'},
-               {"maxdepth",     required_argument, 0, 'D'},
-               {"comp-end",     required_argument, 0, 'E'},
-               {"component-end", required_argument, 0, 'E'},
-               {"gid",          required_argument, 0, 'g'},
-               {"group",        required_argument, 0, 'G'},
-               {"mdt-hash",     required_argument, 0, 'H'},
-               {"stripe-index", required_argument, 0, 'i'},
-               {"stripe_index", required_argument, 0, 'i'},
-               /*{"component-id", 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'},
+       { .val = 'A',   .name = "atime",        .has_arg = required_argument },
+       { .val = LFS_COMP_COUNT_OPT,
+                       .name = "comp-count",   .has_arg = required_argument },
+       { .val = LFS_COMP_COUNT_OPT,
+                       .name = "component-count",
+                                               .has_arg = required_argument },
+       { .val = LFS_COMP_FLAGS_OPT,
+                       .name = "comp-flags",   .has_arg = required_argument },
+       { .val = LFS_COMP_FLAGS_OPT,
+                       .name = "component-flags",
+                                               .has_arg = required_argument },
+       { .val = LFS_COMP_START_OPT,
+                       .name = "comp-start",   .has_arg = required_argument },
+       { .val = LFS_COMP_START_OPT,
+                       .name = "component-start",
+                                               .has_arg = required_argument },
+       { .val = 'c',   .name = "stripe-count", .has_arg = required_argument },
+       { .val = 'c',   .name = "stripe_count", .has_arg = required_argument },
+       { .val = 'C',   .name = "ctime",        .has_arg = required_argument },
+       { .val = 'D',   .name = "maxdepth",     .has_arg = required_argument },
+       { .val = 'E',   .name = "comp-end",     .has_arg = required_argument },
+       { .val = 'E',   .name = "component-end",
+                                               .has_arg = required_argument },
+       { .val = 'g',   .name = "gid",          .has_arg = required_argument },
+       { .val = 'G',   .name = "group",        .has_arg = required_argument },
+       { .val = 'H',   .name = "mdt-hash",     .has_arg = required_argument },
+       { .val = 'i',   .name = "stripe-index", .has_arg = required_argument },
+       { .val = 'i',   .name = "stripe_index", .has_arg = required_argument },
+       /*{"component-id", required_argument, 0, 'I'},*/
+       { .val = 'L',   .name = "layout",       .has_arg = required_argument },
+       { .val = 'm',   .name = "mdt",          .has_arg = required_argument },
+       { .val = 'm',   .name = "mdt-index",    .has_arg = required_argument },
+       { .val = 'm',   .name = "mdt_index",    .has_arg = required_argument },
+       { .val = 'M',   .name = "mtime",        .has_arg = required_argument },
+       { .val = 'n',   .name = "name",         .has_arg = required_argument },
      /* reserve {"or",           no_argument,     , 0, 'o'}, to match find(1) */
-                {"obd",          required_argument, 0, 'O'},
-                {"ost",          required_argument, 0, 'O'},
-                /* no short option for pool, p/P already used */
-               {"pool",         required_argument, 0, LFS_POOL_OPT},
-               {"print0",       no_argument,       0, 'p'},
-               {"print",        no_argument,       0, 'P'},
-               {"projid",       required_argument, 0, LFS_PROJID_OPT},
-                {"size",         required_argument, 0, 's'},
-                {"stripe-size",  required_argument, 0, 'S'},
-                {"stripe_size",  required_argument, 0, 'S'},
-                {"type",         required_argument, 0, 't'},
-               {"mdt-count",    required_argument, 0, 'T'},
-                {"uid",          required_argument, 0, 'u'},
-                {"user",         required_argument, 0, 'U'},
-                {0, 0, 0, 0}
-        };
+       { .val = 'O',   .name = "obd",          .has_arg = required_argument },
+       { .val = 'O',   .name = "ost",          .has_arg = required_argument },
+       /* no short option for pool, p/P already used */
+       { .val = LFS_POOL_OPT,
+                       .name = "pool",         .has_arg = required_argument },
+       { .val = 'p',   .name = "print0",       .has_arg = no_argument },
+       { .val = 'P',   .name = "print",        .has_arg = no_argument },
+       { .val = LFS_PROJID_OPT,
+                       .name = "projid",       .has_arg = required_argument },
+       { .val = 's',   .name = "size",         .has_arg = required_argument },
+       { .val = 'S',   .name = "stripe-size",  .has_arg = required_argument },
+       { .val = 'S',   .name = "stripe_size",  .has_arg = required_argument },
+       { .val = 't',   .name = "type",         .has_arg = required_argument },
+       { .val = 'T',   .name = "mdt-count",    .has_arg = required_argument },
+       { .val = 'u',   .name = "uid",          .has_arg = required_argument },
+       { .val = 'U',   .name = "user",         .has_arg = required_argument },
+       { .name = NULL } };
         int pathstart = -1;
         int pathend = -1;
         int neg_opt = 0;
@@ -2403,70 +2391,78 @@ static int lfs_getstripe_internal(int argc, char **argv,
                                  struct find_param *param)
 {
        struct option long_opts[] = {
-               {"comp-count",          no_argument, 0, LFS_COMP_COUNT_OPT},
-               {"component-count",     no_argument, 0, LFS_COMP_COUNT_OPT},
-               {"comp-flags",      optional_argument, 0, LFS_COMP_FLAGS_OPT},
-               {"component-flags", optional_argument, 0, LFS_COMP_FLAGS_OPT},
-               {"comp-start",      optional_argument, 0, LFS_COMP_START_OPT},
-               {"component-start", optional_argument, 0, LFS_COMP_START_OPT},
+       { .val = LFS_COMP_COUNT_OPT,
+                       .name = "comp-count",   .has_arg = no_argument },
+       { .val = LFS_COMP_COUNT_OPT,
+               .name = "component-count",      .has_arg = no_argument },
+       { .val = LFS_COMP_FLAGS_OPT,
+                       .name = "comp-flags",   .has_arg = optional_argument },
+       { .val = LFS_COMP_FLAGS_OPT,
+               .name = "component-flags",      .has_arg = optional_argument },
+       { .val = LFS_COMP_START_OPT,
+                       .name = "comp-start",   .has_arg = optional_argument },
+       { .val = LFS_COMP_START_OPT,
+               .name = "component-start",      .has_arg = optional_argument },
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 59, 0)
-               /* This formerly implied "stripe-count", but was explicitly
-                * made "stripe-count" for consistency with other options,
-                * and to separate it from "mdt-count" when DNE arrives. */
-               {"count",               no_argument,            0, 'c'},
+       /* This formerly implied "stripe-count", but was explicitly
+        * made "stripe-count" for consistency with other options,
+        * and to separate it from "mdt-count" when DNE arrives. */
+       { .val = 'c',   .name = "count",        .has_arg = no_argument },
 #endif
-               {"stripe-count",        no_argument,            0, 'c'},
-               {"stripe_count",        no_argument,            0, 'c'},
-               {"directory",           no_argument,            0, 'd'},
-               {"default",             no_argument,            0, 'D'},
-               {"comp-end",            optional_argument,      0, 'E'},
-               {"component-end",       optional_argument,      0, 'E'},
-               {"fid",                 no_argument,            0, 'F'},
-               {"generation",          no_argument,            0, 'g'},
-               /* dirstripe {"mdt-hash",     required_argument, 0, 'H'}, */
+       { .val = 'c',   .name = "stripe-count", .has_arg = no_argument },
+       { .val = 'c',   .name = "stripe_count", .has_arg = no_argument },
+       { .val = 'd',   .name = "directory",    .has_arg = no_argument },
+       { .val = 'D',   .name = "default",      .has_arg = no_argument },
+       { .val = 'E',   .name = "comp-end",     .has_arg = optional_argument },
+       { .val = 'E',   .name = "component-end",
+                                               .has_arg = optional_argument },
+       { .val = 'F',   .name = "fid",          .has_arg = no_argument },
+       { .val = 'g',   .name = "generation",   .has_arg = no_argument },
+       /* dirstripe { .val = 'H',      .name = "mdt-hash",
+        *             .has_arg = required_argument }, */
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 59, 0)
-               /* This formerly implied "stripe-index", but was explicitly
-                * made "stripe-index" for consistency with other options,
-                * and to separate it from "mdt-index" when DNE arrives. */
-               {"index",               no_argument,            0, 'i'},
+       /* This formerly implied "stripe-index", but was explicitly
+        * made "stripe-index" for consistency with other options,
+        * and to separate it from "mdt-index" when DNE arrives. */
+       { .val = 'i',   .name = "index",        .has_arg = no_argument },
 #endif
-               {"stripe-index",        no_argument,            0, 'i'},
-               {"stripe_index",        no_argument,            0, 'i'},
-               {"comp-id",             optional_argument,      0, 'I'},
-               {"component-id",        optional_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'},
+       { .val = 'i',   .name = "stripe-index", .has_arg = no_argument },
+       { .val = 'i',   .name = "stripe_index", .has_arg = no_argument },
+       { .val = 'I',   .name = "comp-id",      .has_arg = optional_argument },
+       { .val = 'I',   .name = "component-id", .has_arg = optional_argument },
+       { .val = 'L',   .name = "layout",       .has_arg = no_argument },
+       { .val = 'm',   .name = "mdt",          .has_arg = no_argument },
+       { .val = 'm',   .name = "mdt-index",    .has_arg = no_argument },
+       { .val = 'm',   .name = "mdt_index",    .has_arg = no_argument },
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
-               {"mdt-index",           no_argument,            0, 'M'},
-               {"mdt_index",           no_argument,            0, 'M'},
+       { .val = 'M',   .name = "mdt-index",    .has_arg = no_argument },
+       { .val = 'M',   .name = "mdt_index",    .has_arg = no_argument },
 #endif
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 59, 0)
-               /* This formerly implied "stripe-index", but was confusing
-                * with "file offset" (which will eventually be needed for
-                * with different layouts by offset), so deprecate it. */
-               {"offset",              no_argument,            0, 'o'},
+       /* This formerly implied "stripe-index", but was confusing
+        * with "file offset" (which will eventually be needed for
+        * with different layouts by offset), so deprecate it. */
+       { .val = 'o',   .name = "offset",       .has_arg = no_argument },
 #endif
-               {"obd",                 required_argument,      0, 'O'},
-               {"ost",                 required_argument,      0, 'O'},
-               {"pool",                no_argument,            0, 'p'},
-               {"quiet",               no_argument,            0, 'q'},
-               {"recursive",           no_argument,            0, 'r'},
-               {"raw",                 no_argument,            0, 'R'},
+       { .val = 'O',   .name = "obd",          .has_arg = required_argument },
+       { .val = 'O',   .name = "ost",          .has_arg = required_argument },
+       { .val = 'p',   .name = "pool",         .has_arg = no_argument },
+       { .val = 'q',   .name = "quiet",        .has_arg = no_argument },
+       { .val = 'r',   .name = "recursive",    .has_arg = no_argument },
+       { .val = 'R',   .name = "raw",          .has_arg = no_argument },
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(2, 9, 59, 0)
-               /* This formerly implied "--stripe-size", but was confusing
-                * with "lfs find --size|-s", which means "file size", so use
-                * the consistent "--stripe-size|-S" for all commands. */
-               {"size",                no_argument,            0, 's'},
+       /* This formerly implied "--stripe-size", but was confusing
+        * with "lfs find --size|-s", which means "file size", so use
+        * the consistent "--stripe-size|-S" for all commands. */
+       { .val = 's',   .name = "size",         .has_arg = no_argument },
 #endif
-               {"stripe-size",         no_argument,            0, 'S'},
-               {"stripe_size",         no_argument,            0, 'S'},
-               /* dirstripe {"mdt-count",    required_argument, 0, 'T'}, */
-               {"verbose",             no_argument,            0, 'v'},
-               {"yaml",                no_argument,            0, 'y'},
-               {0, 0, 0, 0}
-       };
+       { .val = 'S',   .name = "stripe-size",  .has_arg = no_argument },
+       { .val = 'S',   .name = "stripe_size",  .has_arg = no_argument },
+       /* dirstripe { .val = 'T',      .name = "mdt-count",
+        *             .has_arg = required_argument }, */
+       { .val = 'v',   .name = "verbose",      .has_arg = no_argument },
+       { .val = 'y',   .name = "yaml",         .has_arg = no_argument },
+       { .name = NULL } };
        int c, rc;
        char *end, *tmp;
 
@@ -2754,20 +2750,19 @@ static int lfs_getdirstripe(int argc, char **argv)
        struct find_param param = { 0 };
        struct option long_opts[] = {
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
-               {"mdt-count",   no_argument,            0, 'c'},
+       { .val = 'c',   .name = "mdt-count",    .has_arg = no_argument },
 #endif
-               {"mdt-hash",    no_argument,            0, 'H'},
-               {"mdt-index",   no_argument,            0, 'i'},
-               {"recursive",   no_argument,            0, 'r'},
+       { .val = 'D',   .name = "default",      .has_arg = no_argument },
+       { .val = 'H',   .name = "mdt-hash",     .has_arg = no_argument },
+       { .val = 'i',   .name = "mdt-index",    .has_arg = no_argument },
+       { .val = 'O',   .name = "obd",          .has_arg = required_argument },
+       { .val = 'r',   .name = "recursive",    .has_arg = no_argument },
 #if LUSTRE_VERSION_CODE < OBD_OCD_VERSION(3, 0, 53, 0)
-               {"mdt-hash",    no_argument,            0, 't'},
+       { .val = 't',   .name = "mdt-hash",     .has_arg = no_argument },
 #endif
-               {"default",     no_argument,            0, 'D'},
-               {"obd",         required_argument,      0, 'O'},
-               {"mdt-count",   no_argument,            0, 'T'},
-               {"yaml",        no_argument,            0, 'y'},
-               {0, 0, 0, 0}
-       };
+       { .val = 'T',   .name = "mdt-count",    .has_arg = no_argument },
+       { .val = 'y',   .name = "yaml",         .has_arg = no_argument },
+       { .name = NULL } };
        int c, rc;
 
        param.fp_get_lmv = 1;
@@ -2888,8 +2883,9 @@ static int lfs_setdirstripe(int argc, char **argv)
                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");
+                               fprintf(stderr,
+                                       "%s %s: warning: '--count' deprecated, use '--mdt-count' instead\n",
+                                       progname, argv[0]);
 #endif
                        stripe_count_opt = optarg;
                        break;
@@ -2903,8 +2899,9 @@ static int lfs_setdirstripe(int argc, char **argv)
                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");
+                               fprintf(stderr,
+                                       "%s %s: warning: '--index' deprecated, use '--mdt-index' instead\n",
+                                       progname, argv[0]);
 #endif
                        stripe_offset_opt = optarg;
                        break;
@@ -2917,29 +2914,29 @@ static int lfs_setdirstripe(int argc, char **argv)
                case 'H':
 #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");
+                               fprintf(stderr,
+                                       "%s %s: warning: '--hash-type' deprecated, use '--mdt-hash' instead\n",
+                                       progname, argv[0]);
 #endif
                        stripe_hash_opt = optarg;
                        break;
                default:
-                       fprintf(stderr, "error: %s: option '%s' "
-                                       "unrecognized\n",
-                                       argv[0], argv[optind - 1]);
+                       fprintf(stderr, "%s %s: unrecognized option '%s'\n",
+                               progname, argv[0], argv[optind - 1]);
                        return CMD_HELP;
                }
        }
 
        if (optind == argc) {
-               fprintf(stderr, "error: %s: missing dirname\n",
-                       argv[0]);
+               fprintf(stderr, "%s %s: DIR must be specified\n",
+                       progname, argv[0]);
                return CMD_HELP;
        }
 
        if (!delete && stripe_offset_opt == NULL && stripe_count_opt == NULL) {
-               fprintf(stderr, "error: %s: missing stripe offset and count.\n",
-                       argv[0]);
+               fprintf(stderr,
+                       "%s %s: stripe offset and count must be specified\n",
+                       progname, argv[0]);
                return CMD_HELP;
        }
 
@@ -2947,16 +2944,18 @@ static int lfs_setdirstripe(int argc, char **argv)
                /* get the stripe offset */
                stripe_offset = strtoul(stripe_offset_opt, &end, 0);
                if (*end != '\0') {
-                       fprintf(stderr, "error: %s: bad stripe offset '%s'\n",
-                               argv[0], stripe_offset_opt);
+                       fprintf(stderr,
+                               "%s %s: bad stripe offset '%s'\n",
+                               progname, argv[0], stripe_offset_opt);
                        return CMD_HELP;
                }
        }
 
        if (delete) {
                if (stripe_offset_opt != NULL || stripe_count_opt != NULL) {
-                       fprintf(stderr, "error: %s: cannot specify -d with -s,"
-                               " or -i options.\n", argv[0]);
+                       fprintf(stderr,
+                               "%s %s: cannot specify -d with -c or -i options\n",
+                               progname, argv[0]);
                        return CMD_HELP;
                } else {
                        stripe_count = 0;
@@ -2967,8 +2966,9 @@ static int lfs_setdirstripe(int argc, char **argv)
        if (mode_opt != NULL) {
                mode = strtoul(mode_opt, &end, 8);
                if (*end != '\0') {
-                       fprintf(stderr, "error: %s: bad mode '%s'\n",
-                               argv[0], mode_opt);
+                       fprintf(stderr,
+                               "%s %s: bad MODE '%s'\n",
+                               progname, argv[0], mode_opt);
                        return CMD_HELP;
                }
                previous_mode = umask(0);
@@ -2979,9 +2979,8 @@ static int lfs_setdirstripe(int argc, char **argv)
        } else {
                hash_type = check_hashtype(stripe_hash_opt);
                if (hash_type == 0) {
-                       fprintf(stderr,
-                               "error: %s: bad stripe hash type '%s'\n",
-                               argv[0], stripe_hash_opt);
+                       fprintf(stderr, "%s %s: bad stripe hash type '%s'\n",
+                               progname, argv[0], stripe_hash_opt);
                        return CMD_HELP;
                }
        }
@@ -2990,8 +2989,9 @@ static int lfs_setdirstripe(int argc, char **argv)
        if (stripe_count_opt != NULL) {
                stripe_count = strtoul(stripe_count_opt, &end, 0);
                if (*end != '\0') {
-                       fprintf(stderr, "error: %s: bad stripe count '%s'\n",
-                               argv[0], stripe_count_opt);
+                       fprintf(stderr,
+                               "%s %s: bad stripe count '%s'\n",
+                               progname, argv[0], stripe_count_opt);
                        return CMD_HELP;
                }
        }
@@ -3010,8 +3010,9 @@ static int lfs_setdirstripe(int argc, char **argv)
                }
 
                if (result) {
-                       fprintf(stderr, "error: %s: create stripe dir '%s' "
-                               "failed\n", argv[0], dname);
+                       fprintf(stderr,
+                               "%s setdirstripe: cannot create stripe dir '%s': %s\n",
+                               progname, dname, strerror(-result));
                        break;
                }
                dname = argv[++optind];
@@ -3060,10 +3061,9 @@ static int lfs_mv(int argc, char **argv)
        int     c;
        int     rc = 0;
        struct option long_opts[] = {
-               {"mdt-index", required_argument, 0, 'M'},
-               {"verbose",     no_argument,       0, 'v'},
-               {0, 0, 0, 0}
-       };
+       { .val = 'M',   .name = "mdt-index",    .has_arg = required_argument },
+       { .val = 'v',   .name = "verbose",      .has_arg = no_argument },
+       { .name = NULL } };
 
        while ((c = getopt_long(argc, argv, "M:v", long_opts, NULL)) != -1) {
                switch (c) {
@@ -3254,9 +3254,10 @@ static int mntdf(char *mntdir, char *fsname, char *pool, enum mntdf_flags flags)
        struct obd_statfs stat_buf, sum = { .os_bsize = 1 };
        struct obd_uuid uuid_buf;
        char *poolname = NULL;
-       struct ll_stat_type types[] = { { LL_STATFS_LMV, "MDT" },
-                                       { LL_STATFS_LOV, "OST" },
-                                       { 0, NULL } };
+       struct ll_stat_type types[] = {
+               { .st_op = LL_STATFS_LMV,       .st_name = "MDT" },
+               { .st_op = LL_STATFS_LOV,       .st_name = "OST" },
+               { .st_name = NULL } };
        struct ll_stat_type *tp;
        __u64 ost_ffree = 0;
        __u32 index;
@@ -3696,15 +3697,18 @@ int lfs_setquota(int argc, char **argv)
         char *mnt, *obd_type = (char *)qctl.obd_type;
         struct obd_dqblk *dqb = &qctl.qc_dqblk;
         struct option long_opts[] = {
-                {"block-softlimit", required_argument, 0, 'b'},
-                {"block-hardlimit", required_argument, 0, 'B'},
-                {"group",           required_argument, 0, 'g'},
-                {"inode-softlimit", required_argument, 0, 'i'},
-                {"inode-hardlimit", required_argument, 0, 'I'},
-                {"user",            required_argument, 0, 'u'},
-               {"projid",         required_argument, 0, 'p'},
-                {0, 0, 0, 0}
-        };
+       { .val = 'b',   .name = "block-softlimit",
+                                               .has_arg = required_argument },
+       { .val = 'B',   .name = "block-hardlimit",
+                                               .has_arg = required_argument },
+       { .val = 'g',   .name = "group",        .has_arg = required_argument },
+       { .val = 'i',   .name = "inode-softlimit",
+                                               .has_arg = required_argument },
+       { .val = 'I',   .name = "inode-hardlimit",
+                                               .has_arg = required_argument },
+       { .val = 'p',   .name = "projid",       .has_arg = required_argument },
+       { .val = 'u',   .name = "user",         .has_arg = required_argument },
+       { .name = NULL } };
         unsigned limit_mask = 0;
         char *endptr;
        int qtype;
@@ -4369,19 +4373,18 @@ static int lfs_ls(int argc, char **argv)
 
 static int lfs_changelog(int argc, char **argv)
 {
-        void *changelog_priv;
+       void *changelog_priv;
        struct changelog_rec *rec;
-        long long startrec = 0, endrec = 0;
-        char *mdd;
-        struct option long_opts[] = {
-                {"follow", no_argument, 0, 'f'},
-                {0, 0, 0, 0}
-        };
-        char short_opts[] = "f";
-        int rc, follow = 0;
-
-        while ((rc = getopt_long(argc, argv, short_opts,
-                                long_opts, NULL)) != -1) {
+       long long startrec = 0, endrec = 0;
+       char *mdd;
+       struct option long_opts[] = {
+               { .val = 'f', .name = "follow", .has_arg = no_argument },
+               { .name = NULL } };
+       char short_opts[] = "f";
+       int rc, follow = 0;
+
+       while ((rc = getopt_long(argc, argv, short_opts,
+               long_opts, NULL)) != -1) {
                 switch (rc) {
                 case 'f':
                         follow++;
@@ -4592,10 +4595,9 @@ static int lfs_fid2path(int argc, char **argv)
 
 static int lfs_path2fid(int argc, char **argv)
 {
-       struct option     long_opts[] = {
-               {"parents", no_argument, 0, 'p'},
-               {0, 0, 0, 0}
-       };
+       struct option long_opts[] = {
+               { .val = 'p', .name = "parents", .has_arg = no_argument },
+               { .name = NULL } };
        char            **path;
        const char        short_opts[] = "p";
        const char       *sep = "";
@@ -4770,14 +4772,13 @@ static int lfs_hsm_state(int argc, char **argv)
 static int lfs_hsm_change_flags(int argc, char **argv, int mode)
 {
        struct option long_opts[] = {
-               {"lost", 0, 0, 'l'},
-               {"norelease", 0, 0, 'r'},
-               {"noarchive", 0, 0, 'a'},
-               {"archived", 0, 0, 'A'},
-               {"dirty", 0, 0, 'd'},
-               {"exists", 0, 0, 'e'},
-               {0, 0, 0, 0}
-       };
+       { .val = 'A',   .name = "archived",     .has_arg = no_argument },
+       { .val = 'a',   .name = "noarchive",    .has_arg = no_argument },
+       { .val = 'd',   .name = "dirty",        .has_arg = no_argument },
+       { .val = 'e',   .name = "exists",       .has_arg = no_argument },
+       { .val = 'l',   .name = "lost",         .has_arg = no_argument },
+       { .val = 'r',   .name = "norelease",    .has_arg = no_argument },
+       { .name = NULL } };
        char short_opts[] = "lraAde";
        __u64 mask = 0;
        int c, rc;
@@ -4995,13 +4996,12 @@ static int fill_hur_item(struct hsm_user_request *hur, unsigned int idx,
 
 static int lfs_hsm_request(int argc, char **argv, int action)
 {
-       struct option            long_opts[] = {
-               {"filelist", 1, 0, 'l'},
-               {"data", 1, 0, 'D'},
-               {"archive", 1, 0, 'a'},
-               {"mntpath", 1, 0, 'm'},
-               {0, 0, 0, 0}
-       };
+       struct option long_opts[] = {
+       { .val = 'a',   .name = "archive",      .has_arg = required_argument },
+       { .val = 'D',   .name = "data",         .has_arg = required_argument },
+       { .val = 'l',   .name = "filelist",     .has_arg = required_argument },
+       { .val = 'm',   .name = "mntpath",      .has_arg = required_argument },
+       { .name = NULL } };
        dev_t                    last_dev = 0;
        char                     short_opts[] = "l:D:a:m:";
        struct hsm_user_request *hur, *oldhur;
@@ -5219,6 +5219,28 @@ static int lfs_swap_layouts(int argc, char **argv)
 
 static const char *const ladvise_names[] = LU_LADVISE_NAMES;
 
+static const char *const lock_mode_names[] = LOCK_MODE_NAMES;
+
+static const char *const lockahead_results[] = {
+       [LLA_RESULT_SENT] = "Lock request sent",
+       [LLA_RESULT_DIFFERENT] = "Different matching lock found",
+       [LLA_RESULT_SAME] = "Matching lock on identical extent found",
+};
+
+int lfs_get_mode(const char *string)
+{
+       enum lock_mode_user mode;
+
+       for (mode = 0; mode < ARRAY_SIZE(lock_mode_names); mode++) {
+               if (lock_mode_names[mode] == NULL)
+                       continue;
+               if (strcmp(string, lock_mode_names[mode]) == 0)
+                       return mode;
+       }
+
+       return -EINVAL;
+}
+
 static enum lu_ladvise_type lfs_get_ladvice(const char *string)
 {
        enum lu_ladvise_type advice;
@@ -5236,15 +5258,16 @@ static enum lu_ladvise_type lfs_get_ladvice(const char *string)
 
 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:";
+       struct option long_opts[] = {
+       { .val = 'a',   .name = "advice",       .has_arg = required_argument },
+       { .val = 'b',   .name = "background",   .has_arg = no_argument },
+       { .val = 'e',   .name = "end",          .has_arg = required_argument },
+       { .val = 'l',   .name = "length",       .has_arg = required_argument },
+       { .val = 'm',   .name = "mode",         .has_arg = required_argument },
+       { .val = 's',   .name = "start",        .has_arg = required_argument },
+       { .val = 'u',   .name = "unset",        .has_arg = no_argument },
+       { .name = NULL } };
+       char                     short_opts[] = "a:be:l:m:s:u";
        int                      c;
        int                      rc = 0;
        const char              *path;
@@ -5256,6 +5279,7 @@ static int lfs_ladvise(int argc, char **argv)
        unsigned long long       length = 0;
        unsigned long long       size_units;
        unsigned long long       flags = 0;
+       int                      mode = 0;
 
        optind = 0;
        while ((c = getopt_long(argc, argv, short_opts,
@@ -5284,6 +5308,9 @@ static int lfs_ladvise(int argc, char **argv)
                case 'b':
                        flags |= LF_ASYNC;
                        break;
+               case 'u':
+                       flags |= LF_UNSET;
+                       break;
                case 'e':
                        size_units = 1;
                        rc = llapi_parse_size(optarg, &end,
@@ -5314,6 +5341,15 @@ static int lfs_ladvise(int argc, char **argv)
                                return CMD_HELP;
                        }
                        break;
+               case 'm':
+                       mode = lfs_get_mode(optarg);
+                       if (mode < 0) {
+                               fprintf(stderr, "%s: bad mode '%s', valid "
+                                                "modes are READ or WRITE\n",
+                                       argv[0], optarg);
+                               return CMD_HELP;
+                       }
+                       break;
                case '?':
                        return CMD_HELP;
                default:
@@ -5336,6 +5372,13 @@ static int lfs_ladvise(int argc, char **argv)
                return CMD_HELP;
        }
 
+       if (advice_type == LU_LADVISE_LOCKNOEXPAND) {
+               fprintf(stderr, "%s: Lock no expand advice is a per file "
+                                "descriptor advice, so when called from lfs, "
+                                "it does nothing.\n", argv[0]);
+               return CMD_HELP;
+       }
+
        if (argc <= optind) {
                fprintf(stderr, "%s: please give one or more file names\n",
                        argv[0]);
@@ -5357,6 +5400,18 @@ static int lfs_ladvise(int argc, char **argv)
                return CMD_HELP;
        }
 
+       if (advice_type != LU_LADVISE_LOCKAHEAD && mode != 0) {
+               fprintf(stderr, "%s: mode is only valid with lockahead\n",
+                       argv[0]);
+               return CMD_HELP;
+       }
+
+       if (advice_type == LU_LADVISE_LOCKAHEAD && mode == 0) {
+               fprintf(stderr, "%s: mode is required with lockahead\n",
+                       argv[0]);
+               return CMD_HELP;
+       }
+
        while (optind < argc) {
                int rc2;
 
@@ -5377,6 +5432,11 @@ static int lfs_ladvise(int argc, char **argv)
                advice.lla_value2 = 0;
                advice.lla_value3 = 0;
                advice.lla_value4 = 0;
+               if (advice_type == LU_LADVISE_LOCKAHEAD) {
+                       advice.lla_lockahead_mode = mode;
+                       advice.lla_peradvice_flags = flags;
+               }
+
                rc2 = llapi_ladvise(fd, flags, 1, &advice);
                close(fd);
                if (rc2 < 0) {
@@ -5384,7 +5444,10 @@ static int lfs_ladvise(int argc, char **argv)
                                "'%s': %s\n", argv[0],
                                ladvise_names[advice_type],
                                path, strerror(errno));
+
+                       goto next;
                }
+
 next:
                if (rc == 0 && rc2 < 0)
                        rc = rc2;