btrfs-progs: balance filter: add limit of processed chunks
authorDavid Sterba <dsterba@suse.cz>
Wed, 7 May 2014 15:38:00 +0000 (17:38 +0200)
committerDavid Sterba <dsterba@suse.cz>
Fri, 22 Aug 2014 12:55:26 +0000 (14:55 +0200)
Add more control to the balance behaviour.

Usage filter may not be finegrained enough and can lead to moving too
many chunks at once. Another example use is in connection with
drange+devid or vrange filters that allow to work with a specific chunk
or even with a chunk on a given device.

The limit filter applies last, the value of 0 means no limiting.

CC: Ilya Dryomov <idryomov@gmail.com>
CC: Hugo Mills <hugo@carfax.org.uk>
Signed-off-by: David Sterba <dsterba@suse.cz>
cmds-balance.c
ioctl.h
volumes.h

index 8a743ec..5de51bd 100644 (file)
@@ -218,6 +218,18 @@ static int parse_filters(char *filters, struct btrfs_balance_args *args)
                        args->flags |= BTRFS_BALANCE_ARGS_CONVERT;
                } else if (!strcmp(this_char, "soft")) {
                        args->flags |= BTRFS_BALANCE_ARGS_SOFT;
+               } else if (!strcmp(this_char, "limit")) {
+                       if (!value || !*value) {
+                               fprintf(stderr,
+                                       "the limit filter requires an argument\n");
+                               return 1;
+                       }
+                       if (parse_u64(value, &args->limit)) {
+                               fprintf(stderr, "Invalid limit argument: %s\n",
+                                      value);
+                               return 1;
+                       }
+                       args->flags |= BTRFS_BALANCE_ARGS_LIMIT;
                } else {
                        fprintf(stderr, "Unrecognized balance option '%s'\n",
                                this_char);
@@ -252,6 +264,8 @@ static void dump_balance_args(struct btrfs_balance_args *args)
                printf(", vrange=%llu..%llu",
                       (unsigned long long)args->vstart,
                       (unsigned long long)args->vend);
+       if (args->flags & BTRFS_BALANCE_ARGS_LIMIT)
+               printf(", limit=%llu", (unsigned long long)args->limit);
 
        printf("\n");
 }
diff --git a/ioctl.h b/ioctl.h
index 9627e8d..f0fc060 100644 (file)
--- a/ioctl.h
+++ b/ioctl.h
@@ -194,7 +194,9 @@ struct btrfs_balance_args {
 
        __u64 flags;
 
-       __u64 unused[8];
+       __u64 limit;
+
+       __u64 unused[7];
 } __attribute__ ((__packed__));
 
 struct btrfs_balance_progress {
index 2e960b5..c7e764b 100644 (file)
--- a/volumes.h
+++ b/volumes.h
@@ -130,6 +130,7 @@ struct map_lookup {
 #define BTRFS_BALANCE_ARGS_DEVID       (1ULL << 2)
 #define BTRFS_BALANCE_ARGS_DRANGE      (1ULL << 3)
 #define BTRFS_BALANCE_ARGS_VRANGE      (1ULL << 4)
+#define BTRFS_BALANCE_ARGS_LIMIT       (1ULL << 5)
 
 /*
  * Profile changing flags.  When SOFT is set we won't relocate chunk if