[PATCH 6/7] btrfs-progs: balance: enhance the limit fiter with range

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



We can do more with the balance filer. Enhance it so we can specify also
the minimum number of block groups to process. The 'limit' filter now
accepts a range (a..b, can be partial) and needs kernel support.

The 'limit=value' filter is equivalent to 'limit=..value' but works on
older kernels as well.

The min/max values are 32bit, unlike the single-value limit which is
64bit.

Signed-off-by: David Sterba <dsterba@xxxxxxxx>
---
 cmds-balance.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/cmds-balance.c b/cmds-balance.c
index 1eadba417abc..7aaf33d03630 100644
--- a/cmds-balance.c
+++ b/cmds-balance.c
@@ -301,12 +301,24 @@ static int parse_filters(char *filters, struct btrfs_balance_args *args)
 					"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;
+			/*
+			 * Try to parse the range first. A single value is not
+			 * a valid range
+			 */
+			if (parse_range_u32(value, &args->limit_min,
+					    &args->limit_max) == 0) {
+				args->flags &= ~BTRFS_BALANCE_ARGS_LIMIT;
+				args->flags |= BTRFS_BALANCE_ARGS_LIMITS;
+			} else {
+				if (parse_u64(value, &args->limit)) {
+					fprintf(stderr,
+						"Invalid limit argument: %s\n",
+					       value);
+					return 1;
+				}
+				args->flags &= ~BTRFS_BALANCE_ARGS_LIMITS;
+				args->flags |= BTRFS_BALANCE_ARGS_LIMIT;
 			}
-			args->flags |= BTRFS_BALANCE_ARGS_LIMIT;
 		} else {
 			fprintf(stderr, "Unrecognized balance option '%s'\n",
 				this_char);
-- 
2.6.1

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux