Whamcloud - gitweb
LU-930 utils: fix --verbose option for lfs-migrate.1
[fs/lustre-release.git] / lustre / utils / lfs.c
index 63d4aa4..089284d 100644 (file)
@@ -234,15 +234,15 @@ static inline int lfs_mirror_split(int argc, char **argv)
 
 #define MIGRATE_USAGE                                                  \
        SSM_CMD_COMMON("migrate  ")                                     \
-       "                 [--block|-b]\n"                               \
-       "                 [--non-block|-n]\n"                           \
-       "                 [--non-direct|-D]\n"                          \
+       "                 [--block|-b] [--non-block|-n]\n"              \
+       "                 [--non-direct|-D] [--verbose|-v]\n"           \
        "                 <filename>\n"                                 \
        SSM_HELP_COMMON                                                 \
        "\n"                                                            \
        "\tblock:        Block file access during data migration (default)\n" \
        "\tnon-block:    Abort migrations if concurrent access is detected\n" \
-       "\tnon-direct:   Do not use direct I/O to copy file contents\n" \
+       "\tnon-direct:   Do not use direct I/O to copy file contents\n" \
+       "\tverbose:      Print each filename as it is migrated\n"       \
 
 #define SETDIRSTRIPE_USAGE                                             \
        "               [--mdt-count|-c stripe_count>\n"                \
@@ -625,9 +625,10 @@ static int check_hashtype(const char *hashtype)
 static const char *error_loc = "syserror";
 
 enum {
-       MIGRATION_NONBLOCK      = 1 << 0,
-       MIGRATION_MIRROR        = 1 << 1,
-       MIGRATION_NONDIRECT     = 1 << 2,
+       MIGRATION_NONBLOCK      = 0x0001,
+       MIGRATION_MIRROR        = 0x0002,
+       MIGRATION_NONDIRECT     = 0x0004,
+       MIGRATION_VERBOSE       = 0x0008,
 };
 
 static int lfs_component_create(char *fname, int open_flags, mode_t open_mode,
@@ -1129,6 +1130,9 @@ out:
        if (rc < 0)
                fprintf(stderr, "error: %s: %s: %s: %s\n",
                        progname, name, error_loc, strerror(-rc));
+       else if (migration_flags & MIGRATION_VERBOSE)
+               printf("%s\n", name);
+
        return rc;
 }
 
@@ -3024,6 +3028,7 @@ static int lfs_setstripe_internal(int argc, char **argv,
                                goto usage_error;
                        }
                        migrate_mdt_param.fp_verbose = VERBOSE_DETAIL;
+                       migration_flags = MIGRATION_VERBOSE;
                        break;
                case 'y':
                        from_yaml = true;
@@ -4606,16 +4611,22 @@ enum mntdf_flags {
 #define RSF     "%4s"
 #define RDF     "%3d%%"
 
-static inline int obd_statfs_ratio(const struct obd_statfs *st)
+static inline int obd_statfs_ratio(const struct obd_statfs *st, bool inodes)
 {
        double avail, used, ratio = 0;
 
-       avail = st->os_bavail;
-       used  = st->os_blocks - st->os_bfree;
+       if (inodes) {
+               avail = st->os_ffree;
+               used = st->os_files - st->os_ffree;
+       } else {
+               avail = st->os_bavail;
+               used = st->os_blocks - st->os_bfree;
+       }
        if (avail + used > 0)
-               ratio = used / (used + avail) * 100 + 0.5;
+               ratio = used / (used + avail) * 100;
 
-       return (int)ratio;
+       /* Round up to match df(1) usage percentage */
+       return (ratio - (int)ratio) > 0 ? (int)(ratio + 1) : (int)ratio;
 }
 
 static int showdf(char *mntdir, struct obd_statfs *stat,
@@ -4649,7 +4660,7 @@ static int showdf(char *mntdir, struct obd_statfs *stat,
                        total = (stat->os_blocks * stat->os_bsize) >> shift;
                }
 
-               ratio = obd_statfs_ratio(stat);
+               ratio = obd_statfs_ratio(stat, flags & MNTDF_INODES);
 
                if (flags & MNTDF_COOKED) {
                        int i;
@@ -4893,8 +4904,8 @@ static int ll_statfs_data_comp(const void *sd1, const void *sd2)
                                                sd_st;
        const struct obd_statfs *st2 = &((const struct ll_statfs_data *)sd2)->
                                                sd_st;
-       int r1 = obd_statfs_ratio(st1);
-       int r2 = obd_statfs_ratio(st2);
+       int r1 = obd_statfs_ratio(st1, false);
+       int r2 = obd_statfs_ratio(st2, false);
        int64_t result = r1 - r2;
 
        /* if both space usage are above 90, compare free inodes */
@@ -5174,8 +5185,8 @@ static int lfs_setdirstripe(int argc, char **argv)
 
                                /* don't use server whose usage is above 90% */
                                while (nr != param->lsp_stripe_count &&
-                                      obd_statfs_ratio(&lsb->sb_buf[nr].sd_st)
-                                      > 90)
+                                      obd_statfs_ratio(&lsb->sb_buf[nr].sd_st,
+                                                       false) > 90)
                                        nr = MAX(param->lsp_stripe_count,
                                                 nr / 2);