History

btrfs: add balance filter for stripes

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>

Gabríel Arthúr Pétursson committed 11 years ago

Commit dee32d01 parent 12907fc4 files · +37 −2Browse files

Unified · Split

4 files
  1. fs/btrfs/ctree.h +8 −1
  2. fs/btrfs/volumes.c +19 −0
  3. fs/btrfs/volumes.h +1 −0
  4. include/uapi/linux/btrfs.h +9 −1
fs/btrfs/ctree.h+8−1
@@ -859,7 +859,14 @@ struct btrfs_disk_balance_args { · 858 unmodified lines
859859 };
860860 };
861861
862− __le64 unused[7];
862+ /*
863+ * Process chunks that cross stripes_min..stripes_max devices,
864+ * BTRFS_BALANCE_ARGS_STRIPES_RANGE
865+ */
866+ __le32 stripes_min;
867+ __le32 stripes_max;
868+
869+ __le64 unused[6];
863870 } __attribute__ ((__packed__));
864871
865872 /*
fs/btrfs/volumes.c+19−0
@@ -3220,6 +3220,19 @@ static int chunk_vrange_filter(struct extent_buffer *leaf, · 3219 unmodified lines
32203220 return 1;
32213221 }
32223222
3223+static int chunk_stripes_range_filter(struct extent_buffer *leaf,
3224+ struct btrfs_chunk *chunk,
3225+ struct btrfs_balance_args *bargs)
3226+{
3227+ int num_stripes = btrfs_chunk_num_stripes(leaf, chunk);
3228+
3229+ if (bargs->stripes_min <= num_stripes
3230+ && num_stripes <= bargs->stripes_max)
3231+ return 0;
3232+
3233+ return 1;
3234+}
3235+
32233236 static int chunk_soft_convert_filter(u64 chunk_type,
32243237 struct btrfs_balance_args *bargs)
32253238 {
@@ -3286,6 +3299,12 @@ static int should_balance_chunk(struct btrfs_root *root, · 60 unmodified lines
32863299 return 0;
32873300 }
32883301
3302+ /* stripes filter */
3303+ if ((bargs->flags & BTRFS_BALANCE_ARGS_STRIPES_RANGE) &&
3304+ chunk_stripes_range_filter(leaf, chunk, bargs)) {
3305+ return 0;
3306+ }
3307+
32893308 /* soft profile changing mode */
32903309 if ((bargs->flags & BTRFS_BALANCE_ARGS_SOFT) &&
32913310 chunk_soft_convert_filter(chunk_type, bargs)) {
fs/btrfs/volumes.h+1−0
@@ -381,6 +381,7 @@ struct map_lookup { · 380 unmodified lines
381381 #define BTRFS_BALANCE_ARGS_VRANGE (1ULL << 4)
382382 #define BTRFS_BALANCE_ARGS_LIMIT (1ULL << 5)
383383 #define BTRFS_BALANCE_ARGS_LIMIT_RANGE (1ULL << 6)
384+#define BTRFS_BALANCE_ARGS_STRIPES_RANGE (1ULL << 7)
384385
385386 #define BTRFS_BALANCE_ARGS_MASK \
386387 (BTRFS_BALANCE_ARGS_PROFILES | \
include/uapi/linux/btrfs.h+9−1
@@ -229,7 +229,15 @@ struct btrfs_balance_args { · 228 unmodified lines
229229 __u32 limit_max;
230230 };
231231 };
232− __u64 unused[7];
232+
233+ /*
234+ * Process chunks that cross stripes_min..stripes_max devices,
235+ * BTRFS_BALANCE_ARGS_STRIPES_RANGE
236+ */
237+ __le32 stripes_min;
238+ __le32 stripes_max;
239+
240+ __u64 unused[6];
233241 } __attribute__ ((__packed__));
234242
235243 /* report balance progress to userspace */