]> git.hungrycats.org Git - linux/commitdiff
btrfs: add balance filter for stripes
authorGabríel Arthúr Pétursson <gabriel@system.is>
Mon, 28 Sep 2015 22:32:41 +0000 (22:32 +0000)
committerZygo Blaxell <zblaxell@serenity.furryterror.org>
Thu, 29 Oct 2015 21:53:40 +0000 (17:53 -0400)
Balance block groups which have the given number of stripes, defined by
a range min..max. This is useful to selectively rebalance only chunks
that do not span enough devices, applies to RAID0/10/5/6.

Signed-off-by: Gabríel Arthúr Pétursson <gabriel@system.is>
[ renamed bargs members, added to the UAPI, wrote the changelog ]
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
(cherry picked from commit dee32d0ac3719ef8d640efaf0884111df444730f)
(cherry picked from commit e76350616c0962782aac193ba5574160bb76769b)

fs/btrfs/ctree.h
fs/btrfs/volumes.c
fs/btrfs/volumes.h
include/uapi/linux/btrfs.h

index 67c4e68dd66ab2c312dd66d7d3472ab70134e73d..991df764da0172e48455d6fe48b45eaa06d57057 100644 (file)
@@ -859,7 +859,14 @@ struct btrfs_disk_balance_args {
                };
        };
 
-       __le64 unused[7];
+       /*
+        * Process chunks that cross stripes_min..stripes_max devices,
+        * BTRFS_BALANCE_ARGS_STRIPES_RANGE
+        */
+       __le32 stripes_min;
+       __le32 stripes_max;
+
+       __le64 unused[6];
 } __attribute__ ((__packed__));
 
 /*
index cd5eaec4a68d957f577d0d7e854324eaacbf7315..c9bca5db3a916d27eb5a7ef3a821b2d55431f88c 100644 (file)
@@ -3157,6 +3157,19 @@ static int chunk_vrange_filter(struct extent_buffer *leaf,
        return 1;
 }
 
+static int chunk_stripes_range_filter(struct extent_buffer *leaf,
+                              struct btrfs_chunk *chunk,
+                              struct btrfs_balance_args *bargs)
+{
+       int num_stripes = btrfs_chunk_num_stripes(leaf, chunk);
+
+       if (bargs->stripes_min <= num_stripes
+                       && num_stripes <= bargs->stripes_max)
+               return 0;
+
+       return 1;
+}
+
 static int chunk_soft_convert_filter(u64 chunk_type,
                                     struct btrfs_balance_args *bargs)
 {
@@ -3223,6 +3236,12 @@ static int should_balance_chunk(struct btrfs_root *root,
                return 0;
        }
 
+       /* stripes filter */
+       if ((bargs->flags & BTRFS_BALANCE_ARGS_STRIPES_RANGE) &&
+           chunk_stripes_range_filter(leaf, chunk, bargs)) {
+               return 0;
+       }
+
        /* soft profile changing mode */
        if ((bargs->flags & BTRFS_BALANCE_ARGS_SOFT) &&
            chunk_soft_convert_filter(chunk_type, bargs)) {
index 9b9f50c2fb4b9af2324298b53dc77f9accd337fb..d7c2ce99c1e93d6db4c55d413c6dff45880bd4d4 100644 (file)
@@ -376,6 +376,7 @@ struct map_lookup {
 #define BTRFS_BALANCE_ARGS_VRANGE      (1ULL << 4)
 #define BTRFS_BALANCE_ARGS_LIMIT       (1ULL << 5)
 #define BTRFS_BALANCE_ARGS_LIMIT_RANGE (1ULL << 6)
+#define BTRFS_BALANCE_ARGS_STRIPES_RANGE (1ULL << 7)
 
 #define BTRFS_BALANCE_ARGS_MASK                        \
        (BTRFS_BALANCE_ARGS_PROFILES |          \
index 11f13108b78b2222b093419a66bc12b8e135be07..17a94704b1832c519f020ad45ccb0e5f39cc6603 100644 (file)
@@ -229,7 +229,15 @@ struct btrfs_balance_args {
                        __u32 limit_max;
                };
        };
-       __u64 unused[7];
+
+       /*
+        * Process chunks that cross stripes_min..stripes_max devices,
+        * BTRFS_BALANCE_ARGS_STRIPES_RANGE
+        */
+       __le32 stripes_min;
+       __le32 stripes_max;
+
+       __u64 unused[6];
 } __attribute__ ((__packed__));
 
 /* report balance progress to userspace */