Whamcloud - gitweb
LU-3363 api: HSM import uses new released pattern
[fs/lustre-release.git] / lustre / utils / lfs.c
index 0030e63..9e85a66 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2011, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -72,6 +72,8 @@
 #include <lustre/lustreapi.h>
 
 #include <libcfs/libcfsutil.h>
+#include <obd.h>
+#include <obd_lov.h>
 #include "obdctl.h"
 
 /* all functions */
@@ -118,32 +120,38 @@ 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);
 
+#define SETSTRIPE_USAGE(_cmd, _tgt) \
+       "usage: "_cmd" [--stripe-count|-c <stripe_count>]\n"\
+       "                 [--stripe-index|-i <start_ost_idx>]\n"\
+       "                 [--stripe-size|-S <stripe_size>]\n"\
+       "                 [--pool|-p <pool_name>]\n"\
+       "                 [--block|-b] "_tgt"\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\n"\
+       "\t              respectively)\n"\
+       "\tstart_ost_idx: OST index of first stripe (-1 default)\n"\
+       "\tstripe_count: Number of OSTs to stripe over (0 default, -1 all)\n"\
+       "\tpool_name:    Name of OST pool to use (default none)\n"\
+       "\tblock:        Block file access during data migration"
+
 /* all avaialable commands */
 command_t cmdlist[] = {
-        {"setstripe", lfs_setstripe, 0,
-         "Create a new file with a specific striping pattern or\n"
-         "set the default striping pattern on an existing directory or\n"
-         "delete the default striping pattern from an existing directory\n"
-         "usage: setstripe [--stripe-count|-c <stripe_count>]\n"
-         "                 [--stripe-index|-i <start_ost_idx>]\n"
-         "                 [--stripe-size|-S <stripe_size>]\n"
-         "                 [--pool|-p <pool_name>] <directory|filename>\n"
-         " or\n"
-         "       setstripe -d <directory>   (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\n"
-         "\t              respectively)\n"
-         "\tstart_ost_idx: OST index of first stripe (-1 default)\n"
-         "\tstripe_count: Number of OSTs to stripe over (0 default, -1 all)\n"
-         "\tpool_name:    Name of OST pool to use (default none)"},
-        {"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"
-         "                 [--stripe-count|-c] [--stripe-index|-i]\n"
-         "                 [--pool|-p] [--stripe-size|-S] [--directory|-d]\n"
-         "                 [--mdt-index|-M] [--recursive|-r] [--raw|-R]\n"
-         "                 <directory|filename> ..."},
+       {"setstripe", lfs_setstripe, 0,
+        "Create a new file with a specific striping pattern or\n"
+        "set the default striping pattern on an existing directory or\n"
+        "delete the default striping pattern from an existing directory\n"
+        "usage: setstripe -d <directory>   (to delete default striping)\n"\
+        " or\n"
+        SETSTRIPE_USAGE("setstripe", "<directory|filename>")},
+       {"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"
+        "                 [--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"
+        "                 <directory|filename> ..."},
        {"setdirstripe", lfs_setdirstripe, 0,
         "To create a remote directory on a specified MDT.\n"
         "usage: setdirstripe <--index|-i mdt_index> <dir>\n"
@@ -181,6 +189,7 @@ command_t cmdlist[] = {
          "     [[!] --stripe-size|-S [+-]N[kMGT]] [[!] --type|-t <filetype>]\n"
          "     [[!] --gid|-g|--group|-G <gid>|<gname>]\n"
          "     [[!] --uid|-u|--user|-U <uid>|<uname>] [[!] --pool <pool>]\n"
+        "     [[!] --layout|-L released,raid0]\n"
          "\t !: used before an option indicates 'NOT' requested attribute\n"
          "\t -: used before a value indicates 'AT MOST' requested value\n"
          "\t +: used before a value indicates 'AT LEAST' requested value\n"},
@@ -228,7 +237,14 @@ command_t cmdlist[] = {
          "       -b can be used instead of --block-softlimit/--block-grace\n"
          "       -B can be used instead of --block-hardlimit\n"
          "       -i can be used instead of --inode-softlimit/--inode-grace\n"
-         "       -I can be used instead of --inode-hardlimit"},
+        "       -I can be used instead of --inode-hardlimit\n\n"
+        "Note: The total quota space will be split into many qunits and\n"
+        "      balanced over all server targets, the minimal qunit size is\n"
+        "      1M bytes for block space and 1K inodes for inode space.\n\n"
+        "      Quota space rebalancing process will stop when this mininum\n"
+        "      value is reached. As a result, quota exceeded can be returned\n"
+        "      while many targets still have 1MB or 1K inodes of spare\n"
+        "      quota space."},
         {"quota", lfs_quota, 0, "Display disk usage and limits.\n"
          "usage: quota [-q] [-v] [-o <obd_uuid>|-i <mdt_idx>|-I <ost_idx>]\n"
          "             [<-u|-g> <uname>|<uid>|<gname>|<gid>] <filesystem>\n"
@@ -262,16 +278,16 @@ command_t cmdlist[] = {
          "interest to consumer <id>, allowing the system to free up space.\n"
          "An <endrec> of 0 means all records.\n"
          "usage: changelog_clear <mdtname> <id> <endrec>"},
-        {"fid2path", lfs_fid2path, 0,
-         "Resolve the full path to a given FID. For a specific hardlink "
-         "specify link number <linkno>.\n"
-         /* "For a historical name, specify changelog record <recno>.\n" */
-         "usage: fid2path <fsname|rootpath> <fid> [--link <linkno>]"
-                /*[--rec <recno>]*/},
-        {"path2fid", lfs_path2fid, 0, "Display the fid for a given path.\n"
-         "usage: path2fid <path>"},
-        {"data_version", lfs_data_version, 0, "Display file data version for "
-         "a given path.\n" "usage: data_version [-n] <path>"},
+       {"fid2path", lfs_fid2path, 0,
+        "Resolve the full path(s) for given FID(s). For a specific hardlink "
+        "specify link number <linkno>.\n"
+       /* "For a historical link name, specify changelog record <recno>.\n" */
+        "usage: fid2path [--link <linkno>] <fsname|rootpath> <fid> ..."
+               /* [ --rec <recno> ] */ },
+       {"path2fid", lfs_path2fid, 0, "Display the fid(s) for a given path(s).\n"
+        "usage: path2fid <path> ..."},
+       {"data_version", lfs_data_version, 0, "Display file data version for "
+        "a given path.\n" "usage: data_version [-n] <path>"},
        {"hsm_state", lfs_hsm_state, 0, "Display the HSM information (states, "
         "undergoing actions) for given files.\n usage: hsm_state <file> ..."},
        {"hsm_set", lfs_hsm_set, 0, "Set HSM user flag on specified files.\n"
@@ -301,6 +317,9 @@ command_t cmdlist[] = {
         "usage: hsm_cancel [--filelist FILELIST] [--data DATA] <file> ..."},
        {"swap_layouts", lfs_swap_layouts, 0, "Swap layouts between 2 files.\n"
         "usage: swap_layouts <path1> <path2>"},
+       {"migrate", lfs_setstripe, 0, "migrate file from one layout to "
+        "another (may be not safe with concurent writes).\n"
+        SETSTRIPE_USAGE("migrate  ", "<filename>")},
         {"help", Parser_help, 0, "help"},
         {"exit", Parser_quit, 0, "quit"},
         {"quit", Parser_quit, 0, "quit"},
@@ -322,70 +341,292 @@ static int isnumber(const char *str)
         return 1;
 }
 
+#define MIGRATION_BLOCKS 1
+
+static int lfs_migrate(char *name, unsigned long long stripe_size,
+                      int stripe_offset, int stripe_count,
+                      int stripe_pattern, char *pool_name,
+                      __u64 migration_flags)
+{
+       int                      fd, fdv;
+       char                     volatile_file[PATH_MAX];
+       char                     parent[PATH_MAX];
+       char                    *ptr;
+       int                      rc;
+       __u64                    dv1;
+       struct lov_user_md      *lum = NULL;
+       int                      lumsz;
+       int                      bufsz;
+       void                    *buf = NULL;
+       int                      rsize, wsize;
+       __u64                    rpos, wpos, bufoff;
+       int                      gid = 0, sz;
+       int                      have_gl = 0;
+
+       /* find the right size for the IO and allocate the buffer */
+       lumsz = lov_user_md_size(LOV_MAX_STRIPE_COUNT, LOV_USER_MAGIC_V3);
+       lum = malloc(lumsz);
+       if (lum == NULL) {
+               rc = -ENOMEM;
+               goto free;
+       }
+
+       rc = llapi_file_get_stripe(name, lum);
+       /* failure can come from may case and some may be not real error
+        * (eg: no stripe)
+        * in case of a real error, a later call will failed with a better
+        * error management */
+       if (rc < 0)
+               bufsz = 1024*1024;
+       else
+               bufsz = lum->lmm_stripe_size;
+       rc = posix_memalign(&buf, getpagesize(), bufsz);
+       if (rc != 0) {
+               rc = -rc;
+               goto free;
+       }
+
+       if (migration_flags & MIGRATION_BLOCKS) {
+               /* generate a random id for the grouplock */
+               fd = open("/dev/urandom", O_RDONLY);
+               if (fd == -1) {
+                       rc = -errno;
+                       fprintf(stderr, "cannot open /dev/urandom (%s)\n",
+                               strerror(-rc));
+                       goto free;
+               }
+               sz = sizeof(gid);
+               rc = read(fd, &gid, sz);
+               close(fd);
+               if (rc < sz) {
+                       rc = -errno;
+                       fprintf(stderr, "cannot read %d bytes from"
+                               " /dev/urandom (%s)\n", sz, strerror(-rc));
+                       goto free;
+               }
+       }
+
+       /* search for file directory pathname */
+       strcpy(parent, name);
+       ptr = strrchr(parent, '/');
+       if (ptr == NULL) {
+               if (getcwd(parent, sizeof(parent)) == NULL) {
+                       rc = -errno;
+                       goto free;
+               }
+       } else {
+               if (ptr == parent)
+                       strcpy(parent, "/");
+               else
+                       *ptr = '\0';
+       }
+       sprintf(volatile_file, "%s/%s::", parent, LUSTRE_VOLATILE_HDR);
+
+       /* create, open a volatile file, use caching (ie no directio) */
+       /* exclusive create is not needed because volatile files cannot
+        * conflict on name by construction */
+       fdv = llapi_file_open_pool(volatile_file, O_CREAT | O_WRONLY,
+                                  0644, stripe_size, stripe_offset,
+                                  stripe_count, stripe_pattern, pool_name);
+       if (fdv < 0) {
+               rc = fdv;
+               fprintf(stderr, "cannot create volatile file in %s (%s)\n",
+                       parent, strerror(-rc));
+               goto free;
+       }
+
+       /* open file, direct io */
+       /* even if the file is only read, WR mode is nedeed to allow
+        * layout swap on fd */
+       fd = open(name, O_RDWR | O_DIRECT);
+       if (fd == -1) {
+               rc = -errno;
+               fprintf(stderr, "cannot open %s (%s)\n", name, strerror(-rc));
+               close(fdv);
+               goto free;
+       }
+
+       /* get file data version */
+       rc = llapi_get_data_version(fd, &dv1, 0);
+       if (rc != 0) {
+               fprintf(stderr, "cannot get dataversion on %s (%s)\n",
+                       name, strerror(-rc));
+               goto error;
+       }
+
+       if (migration_flags & MIGRATION_BLOCKS) {
+               /* take group lock to limit concurent access
+                * this will be no more needed when exclusive access will
+                * be implemented (see LU-2919) */
+               /* group lock is taken after data version read because it
+                * blocks data version call */
+               if (ioctl(fd, LL_IOC_GROUP_LOCK, gid) == -1) {
+                       rc = -errno;
+                       fprintf(stderr, "cannot get group lock on %s (%s)\n",
+                               name, strerror(-rc));
+                       goto error;
+               }
+               have_gl = 1;
+       }
+
+       /* copy data */
+       rpos = 0;
+       wpos = 0;
+       bufoff = 0;
+       rsize = -1;
+       do {
+               /* read new data only if we have written all
+                * previously read data */
+               if (wpos == rpos) {
+                       rsize = read(fd, buf, bufsz);
+                       if (rsize < 0) {
+                               rc = -errno;
+                               fprintf(stderr, "read failed on %s"
+                                       " (%s)\n", name,
+                                       strerror(-rc));
+                               goto error;
+                       }
+                       rpos += rsize;
+                       bufoff = 0;
+               }
+               /* eof ? */
+               if (rsize == 0)
+                       break;
+               wsize = write(fdv, buf + bufoff, rpos - wpos);
+               if (wsize < 0) {
+                       rc = -errno;
+                       fprintf(stderr, "write failed on volatile"
+                               " for %s (%s)\n", name, strerror(-rc));
+                       goto error;
+               }
+               wpos += wsize;
+               bufoff += wsize;
+       } while (1);
+
+       /* flush data */
+       fsync(fdv);
+
+       if (migration_flags & MIGRATION_BLOCKS) {
+               /* give back group lock */
+               if (ioctl(fd, LL_IOC_GROUP_UNLOCK, gid) == -1) {
+                       rc = -errno;
+                       fprintf(stderr, "cannot put group lock on %s (%s)\n",
+                               name, strerror(-rc));
+               }
+               have_gl = 0;
+       }
+
+       /* swap layouts
+        * for a migration we need to:
+        * - check data version on file did not change
+        * - keep file mtime
+        * - keep file atime
+        */
+       rc = llapi_fswap_layouts(fd, fdv, dv1, 0,
+                                SWAP_LAYOUTS_CHECK_DV1 |
+                                SWAP_LAYOUTS_KEEP_MTIME |
+                                SWAP_LAYOUTS_KEEP_ATIME);
+       if (rc == -EAGAIN) {
+               fprintf(stderr, "file dataversion for %s has changed"
+                               " during copy, migration is aborted\n",
+                       name);
+               goto error;
+       }
+       if (rc != 0)
+               fprintf(stderr, "cannot swap layouts between %s and "
+                       "a volatile file (%s)\n",
+                       name, strerror(-rc));
+
+error:
+       /* give back group lock */
+       if ((migration_flags & MIGRATION_BLOCKS) && have_gl &&
+           (ioctl(fd, LL_IOC_GROUP_UNLOCK, gid) == -1)) {
+               /* we keep in rc the original error */
+               fprintf(stderr, "cannot put group lock on %s (%s)\n",
+                       name, strerror(-errno));
+       }
+
+       close(fdv);
+       close(fd);
+free:
+       if (lum)
+               free(lum);
+       if (buf)
+               free(buf);
+       return rc;
+}
+
 /* functions */
 static int lfs_setstripe(int argc, char **argv)
 {
-        char *fname;
-        int result;
-        unsigned long long st_size;
-        int  st_offset, st_count;
-        char *end;
-        int c;
-        int delete = 0;
-        char *stripe_size_arg = NULL;
-        char *stripe_off_arg = NULL;
-        char *stripe_count_arg = NULL;
-        char *pool_name_arg = NULL;
-        unsigned long long size_units = 1;
+       char                    *fname;
+       int                      result;
+       unsigned long long       st_size;
+       int                      st_offset, st_count;
+       char                    *end;
+       int                      c;
+       int                      delete = 0;
+       char                    *stripe_size_arg = NULL;
+       char                    *stripe_off_arg = NULL;
+       char                    *stripe_count_arg = NULL;
+       char                    *pool_name_arg = NULL;
+       unsigned long long       size_units = 1;
+       int                      migrate_mode = 0;
+       __u64                    migration_flags = 0;
 
-        struct option long_opts[] = {
+       struct option            long_opts[] = {
+               /* valid only in migrate mode */
+               {"block",        no_argument,       0, 'b'},
 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
 #warning "remove deprecated --count option"
 #else
-                /* 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",        required_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. */
+               {"count",        required_argument, 0, 'c'},
 #endif
-                {"stripe-count", required_argument, 0, 'c'},
-                {"stripe_count", required_argument, 0, 'c'},
-                {"delete",       no_argument,       0, 'd'},
+               {"stripe-count", required_argument, 0, 'c'},
+               {"stripe_count", required_argument, 0, 'c'},
+               {"delete",       no_argument,       0, 'd'},
 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
 #warning "remove deprecated --index option"
 #else
-                /* 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",        required_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. */
+               {"index",        required_argument, 0, 'i'},
 #endif
-                {"stripe-index", required_argument, 0, 'i'},
-                {"stripe_index", required_argument, 0, 'i'},
+               {"stripe-index", required_argument, 0, 'i'},
+               {"stripe_index", required_argument, 0, 'i'},
 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
 #warning "remove deprecated --offset option"
 #else
-                /* 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",       required_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. */
+               {"offset",       required_argument, 0, 'o'},
 #endif
-                {"pool",         required_argument, 0, 'p'},
+               {"pool",         required_argument, 0, 'p'},
 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
 #warning "remove deprecated --size option"
 #else
-                /* 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",         required_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. */
+               {"size",         required_argument, 0, 's'},
 #endif
-                {"stripe-size",  required_argument, 0, 'S'},
-                {"stripe_size",  required_argument, 0, 'S'},
-                {0, 0, 0, 0}
-        };
+               {"stripe-size",  required_argument, 0, 'S'},
+               {"stripe_size",  required_argument, 0, 'S'},
+               {0, 0, 0, 0}
+       };
 
         st_size = 0;
         st_offset = -1;
         st_count = 0;
 
+       if (strcmp(argv[0], "migrate") == 0)
+               migrate_mode = 1;
+
 #if LUSTRE_VERSION < OBD_OCD_VERSION(2,4,50,0)
         if (argc == 5 && argv[1][0] != '-' &&
             isnumber(argv[2]) && isnumber(argv[3]) && isnumber(argv[4])) {
@@ -404,6 +645,14 @@ static int lfs_setstripe(int argc, char **argv)
                 case 0:
                         /* Long options. */
                         break;
+               case 'b':
+                       if (migrate_mode == 0) {
+                               fprintf(stderr, "--block is valid only for"
+                                               " migrate mode");
+                               return CMD_HELP;
+                       }
+                       migration_flags |= MIGRATION_BLOCKS;
+                       break;
                 case 'c':
 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
 #warning "remove deprecated --count option"
@@ -502,18 +751,26 @@ static int lfs_setstripe(int argc, char **argv)
                 }
         }
 
-        do {
-                result = llapi_file_create_pool(fname, st_size, st_offset,
-                                                st_count, 0, pool_name_arg);
-                if (result) {
-                        fprintf(stderr,"error: %s: create stripe file '%s' "
-                                "failed\n", argv[0], fname);
-                        break;
-                }
-                fname = argv[++optind];
-        } while (fname != NULL);
+       do {
+               if (migrate_mode)
+                       result = lfs_migrate(fname, st_size, st_offset,
+                                            st_count, 0, pool_name_arg,
+                                            migration_flags);
+               else
+                       result = llapi_file_create_pool(fname, st_size,
+                                                       st_offset, st_count,
+                                                       0, pool_name_arg);
+               if (result) {
+                       fprintf(stderr,
+                               "error: %s: %s stripe file '%s' failed\n",
+                               argv[0], migrate_mode ? "migrate" : "create",
+                               fname);
+                       break;
+               }
+               fname = argv[++optind];
+       } while (fname != NULL);
 
-        return result;
+       return result;
 }
 
 static int lfs_poollist(int argc, char **argv)
@@ -606,6 +863,25 @@ static int id2name(char **name, unsigned int id, int type)
         return 0;
 }
 
+static int name2layout(__u32 *layout, char *name)
+{
+       char *ptr, *lyt;
+
+       *layout = 0;
+       for (ptr = name; ; ptr = NULL) {
+               lyt = strtok(ptr, ",");
+               if (lyt == NULL)
+                       break;
+               if (strcmp(lyt, "released") == 0)
+                       *layout |= LOV_PATTERN_F_RELEASED;
+               else if (strcmp(lyt, "raid0") == 0)
+                       *layout |= LOV_PATTERN_RAID0;
+               else
+                       return -1;
+       }
+       return 0;
+}
+
 #define FIND_POOL_OPT 3
 static int lfs_find(int argc, char **argv)
 {
@@ -622,6 +898,7 @@ static int lfs_find(int argc, char **argv)
                 {"group",        required_argument, 0, 'G'},
                 {"stripe-index", required_argument, 0, 'i'},
                 {"stripe_index", required_argument, 0, 'i'},
+               {"layout",       required_argument, 0, 'L'},
                 {"mdt",          required_argument, 0, 'm'},
                 {"mtime",        required_argument, 0, 'M'},
                 {"name",         required_argument, 0, 'n'},
@@ -650,11 +927,11 @@ static int lfs_find(int argc, char **argv)
 
         time(&t);
 
-        optind = 0;
-        /* when getopt_long_only() hits '!' it returns 1, puts "!" in optarg */
-        while ((c = getopt_long_only(argc, argv,
-                                     "-A:c:C:D:g:G:i:m:M:n:O:Ppqrs:S:t:u:U:v",
-                                     long_opts, NULL)) >= 0) {
+       optind = 0;
+       /* when getopt_long_only() hits '!' it returns 1, puts "!" in optarg */
+       while ((c = getopt_long_only(argc, argv,
+                                    "-A:c:C:D:g:G:i:L:m:M:n:O:Ppqrs:S:t:u:U:v",
+                                    long_opts, NULL)) >= 0) {
                 xtime = NULL;
                 xsign = NULL;
                 if (neg_opt)
@@ -752,6 +1029,13 @@ static int lfs_find(int argc, char **argv)
                         param.exclude_gid = !!neg_opt;
                         param.check_gid = 1;
                         break;
+               case 'L':
+                       ret = name2layout(&param.layout, optarg);
+                       if (ret)
+                               goto err;
+                       param.exclude_layout = !!neg_opt;
+                       param.check_layout = 1;
+                       break;
                 case 'u':
                 case 'U':
                         ret = name2id(&param.uid, optarg, USER);
@@ -948,63 +1232,64 @@ err:
 static int lfs_getstripe_internal(int argc, char **argv,
                                  struct find_param *param)
 {
-        struct option long_opts[] = {
+       struct option long_opts[] = {
 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
 #warning "remove deprecated --count option"
 #else
-                /* 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. */
+               {"count",               no_argument,            0, 'c'},
 #endif
-                {"stripe-count", no_argument,       0, 'c'},
-                {"stripe_count", no_argument,       0, 'c'},
-                {"directory",    no_argument,       0, 'd'},
-                {"generation",   no_argument,       0, 'g'},
+               {"stripe-count",        no_argument,            0, 'c'},
+               {"stripe_count",        no_argument,            0, 'c'},
+               {"directory",           no_argument,            0, 'd'},
+               {"generation",          no_argument,            0, 'g'},
 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
 #warning "remove deprecated --index option"
 #else
-                /* 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. */
+               {"index",               no_argument,            0, 'i'},
 #endif
-                {"stripe-index", no_argument,       0, 'i'},
-                {"stripe_index", no_argument,       0, 'i'},
-                {"mdt-index",    no_argument,       0, 'M'},
-                {"mdt_index",    no_argument,       0, 'M'},
+               {"stripe-index",        no_argument,            0, 'i'},
+               {"stripe_index",        no_argument,            0, 'i'},
+               {"layout",              no_argument,            0, 'L'},
+               {"mdt-index",           no_argument,            0, 'M'},
+               {"mdt_index",           no_argument,            0, 'M'},
 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
 #warning "remove deprecated --offset option"
 #else
-                /* 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. */
+               {"offset",              no_argument,            0, 'o'},
 #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'},
+               {"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'},
 #if LUSTRE_VERSION >= OBD_OCD_VERSION(2,9,50,0)
 #warning "remove deprecated --size option"
 #else
-                /* 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. */
+               {"size",                no_argument,            0, 's'},
 #endif
-                {"stripe-size",  no_argument,       0, 'S'},
-                {"stripe_size",  no_argument,       0, 'S'},
-                {"verbose",      no_argument,       0, 'v'},
-                {0, 0, 0, 0}
-        };
-        int c, rc;
+               {"stripe-size",         no_argument,            0, 'S'},
+               {"stripe_size",         no_argument,            0, 'S'},
+               {"verbose",             no_argument,            0, 'v'},
+               {0, 0, 0, 0}
+       };
+       int c, rc;
 
        param->maxdepth = 1;
        optind = 0;
-       while ((c = getopt_long(argc, argv, "cdghiMoO:pqrRsSv",
+       while ((c = getopt_long(argc, argv, "cdghiLMoO:pqrRsSv",
                                long_opts, NULL)) != -1) {
                switch (c) {
                case 'O':
@@ -1089,6 +1374,12 @@ static int lfs_getstripe_internal(int argc, char **argv,
                                param->maxdepth = 0;
                        }
                        break;
+               case 'L':
+                       if (!(param->verbose & VERBOSE_DETAIL)) {
+                               param->verbose |= VERBOSE_LAYOUT;
+                               param->maxdepth = 0;
+                       }
+                       break;
                case 'M':
                        if (!(param->verbose & VERBOSE_DETAIL))
                                param->maxdepth = 0;
@@ -2048,19 +2339,43 @@ int lfs_setquota(int argc, char **argv)
                         ARG2ULL(dqb->dqb_bsoftlimit, optarg, 1024);
                         dqb->dqb_bsoftlimit >>= 10;
                         limit_mask |= BSLIMIT;
+                       if (dqb->dqb_bsoftlimit &&
+                           dqb->dqb_bsoftlimit <= 1024) /* <= 1M? */
+                               fprintf(stderr, "warning: block softlimit is "
+                                       "smaller than the miminal qunit size, "
+                                       "please see the help of setquota or "
+                                       "Lustre manual for details.\n");
                         break;
                 case 'B':
                         ARG2ULL(dqb->dqb_bhardlimit, optarg, 1024);
                         dqb->dqb_bhardlimit >>= 10;
                         limit_mask |= BHLIMIT;
+                       if (dqb->dqb_bhardlimit &&
+                           dqb->dqb_bhardlimit <= 1024) /* <= 1M? */
+                               fprintf(stderr, "warning: block hardlimit is "
+                                       "smaller than the miminal qunit size, "
+                                       "please see the help of setquota or "
+                                       "Lustre manual for details.\n");
                         break;
                 case 'i':
                         ARG2ULL(dqb->dqb_isoftlimit, optarg, 1);
                         limit_mask |= ISLIMIT;
+                       if (dqb->dqb_isoftlimit &&
+                           dqb->dqb_isoftlimit <= 1024) /* <= 1K inodes? */
+                               fprintf(stderr, "warning: inode softlimit is "
+                                       "smaller than the miminal qunit size, "
+                                       "please see the help of setquota or "
+                                       "Lustre manual for details.\n");
                         break;
                 case 'I':
                         ARG2ULL(dqb->dqb_ihardlimit, optarg, 1);
                         limit_mask |= IHLIMIT;
+                       if (dqb->dqb_ihardlimit &&
+                           dqb->dqb_ihardlimit <= 1024) /* <= 1K inodes? */
+                               fprintf(stderr, "warning: inode hardlimit is "
+                                       "smaller than the miminal qunit size, "
+                                       "please see the help of setquota or "
+                                       "Lustre manual for details.\n");
                         break;
                 default: /* getopt prints error message for us when opterr != 0 */
                         return CMD_HELP;
@@ -2236,11 +2551,11 @@ static void print_quota(char *mnt, struct if_quotactl *qctl, int type, int rc)
                     dqb->dqb_curinodes >= dqb->dqb_ihardlimit) {
                         iover = 1;
                 } else if (dqb->dqb_isoftlimit && dqb->dqb_itime) {
-                        if (dqb->dqb_btime > now) {
-                                iover = 2;
-                        } else {
-                                iover = 3;
-                        }
+                       if (dqb->dqb_itime > now) {
+                               iover = 2;
+                       } else {
+                               iover = 3;
+                       }
                 }
 
 #if 0           /* XXX: always print quotas even when no usages */
@@ -2751,7 +3066,7 @@ static int lfs_fid2path(int argc, char **argv)
         int linkno = -1;
         int lnktmp;
         int printcur = 0;
-        int rc;
+       int rc = 0;
 
         optind = 0;
 
@@ -2775,68 +3090,88 @@ static int lfs_fid2path(int argc, char **argv)
                         return CMD_HELP;
                 }
         }
-        device = argv[optind++];
-        fid = argv[optind++];
-        if (optind != argc)
-                return CMD_HELP;
 
-        path = calloc(1, PATH_MAX);
+       if (argc < 3)
+               return CMD_HELP;
 
-        lnktmp = (linkno >= 0) ? linkno : 0;
-        while (1) {
-                int oldtmp = lnktmp;
-                long long rectmp = recno;
-                rc = llapi_fid2path(device, fid, path, PATH_MAX, &rectmp,
-                                    &lnktmp);
-                if (rc < 0) {
-                        fprintf(stderr, "%s error: %s\n", argv[0],
-                                strerror(errno = -rc));
-                        break;
-                }
+       device = argv[optind++];
+       path = calloc(1, PATH_MAX);
 
-                if (printcur)
-                        fprintf(stdout, "%lld ", rectmp);
-                if (device[0] == '/') {
-                        fprintf(stdout, "%s", device);
-                        if (device[strlen(device) - 1] != '/')
-                                fprintf(stdout, "/");
-                } else if (path[0] == '\0') {
-                        fprintf(stdout, "/");
-                }
-                fprintf(stdout, "%s\n", path);
+       rc = 0;
+       while (optind < argc) {
+               fid = argv[optind++];
+
+               lnktmp = (linkno >= 0) ? linkno : 0;
+               while (1) {
+                       int oldtmp = lnktmp;
+                       long long rectmp = recno;
+                       int rc2;
+                       rc2 = llapi_fid2path(device, fid, path, PATH_MAX,
+                                            &rectmp, &lnktmp);
+                       if (rc2 < 0) {
+                               fprintf(stderr, "%s: error on FID %s: %s\n",
+                                       argv[0], fid, strerror(errno = -rc2));
+                               if (rc == 0)
+                                       rc = rc2;
+                               break;
+                       }
 
-                if (linkno >= 0)
-                        /* specified linkno */
-                        break;
-                if (oldtmp == lnktmp)
-                        /* no more links */
-                        break;
-        }
+                       if (printcur)
+                               fprintf(stdout, "%lld ", rectmp);
+                       if (device[0] == '/') {
+                               fprintf(stdout, "%s", device);
+                               if (device[strlen(device) - 1] != '/')
+                                       fprintf(stdout, "/");
+                       } else if (path[0] == '\0') {
+                               fprintf(stdout, "/");
+                       }
+                       fprintf(stdout, "%s\n", path);
+
+                       if (linkno >= 0)
+                               /* specified linkno */
+                               break;
+                       if (oldtmp == lnktmp)
+                               /* no more links */
+                               break;
+               }
+       }
 
-        free(path);
-        return rc;
+       free(path);
+       return rc;
 }
 
 static int lfs_path2fid(int argc, char **argv)
 {
-        char *path;
-        lustre_fid fid;
-        int rc;
-
-        if (argc != 2)
-                return CMD_HELP;
-
-        path = argv[1];
-        rc = llapi_path2fid(path, &fid);
-        if (rc) {
-                fprintf(stderr, "can't get fid for %s: %s\n", path,
-                        strerror(errno = -rc));
-                return rc;
-        }
+       char **path;
+       const char *sep = "";
+       lustre_fid fid;
+       int rc = 0;
 
-        printf(DFID"\n", PFID(&fid));
+       if (argc < 2)
+               return CMD_HELP;
+       else if (argc > 2)
+               sep = ": ";
+
+       path = argv + 1;
+       while (*path != NULL) {
+               int err = llapi_path2fid(*path, &fid);
+
+               if (err) {
+                       fprintf(stderr, "%s: can't get fid for %s: %s\n",
+                               argv[0], *path, strerror(-err));
+                       if (rc == 0) {
+                               rc = err;
+                               errno = -err;
+                       }
+                       goto out;
+               }
+               printf("%s%s"DFID"\n", *sep != '\0' ? *path : "", sep,
+                      PFID(&fid));
+out:
+               path++;
+       }
 
-        return 0;
+       return rc;
 }
 
 static int lfs_data_version(int argc, char **argv)
@@ -3093,7 +3428,7 @@ static int lfs_hsm_prepare_file(char *file, struct lu_fid *fid,
 
        rc = lstat(file, &st);
        if (rc) {
-               fprintf(stderr, "Cannot stat %s: %s\n", file, strerror(-errno));
+               fprintf(stderr, "Cannot stat %s: %s\n", file, strerror(errno));
                return -errno;
        }
        /* A request should be ... */
@@ -3315,7 +3650,9 @@ static int lfs_swap_layouts(int argc, char **argv)
        if (argc != 3)
                return CMD_HELP;
 
-       return llapi_swap_layouts(argv[1], argv[2]);
+       return llapi_swap_layouts(argv[1], argv[2], 0, 0,
+                                 SWAP_LAYOUTS_KEEP_MTIME |
+                                 SWAP_LAYOUTS_KEEP_ATIME);
 }
 
 int main(int argc, char **argv)