btrfs-progs: make device add and paused balance work together

Kernel commit efc0e69c2fea ("btrfs: introduce exclusive operation
BALANCE_PAUSED state") allows to start a device add when there's a
paused balance, eg. to let the balance finish when there's not enough
chunk space. Add the support for that, though this needs an updated
kernel to export the 'balance paused' in sysfs.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2022-05-03 22:48:14 +02:00
parent 851ef59b2c
commit e278e0755f
2 changed files with 11 additions and 0 deletions

View File

@ -1477,6 +1477,7 @@ int sysfs_read_file(int fd, char *buf, size_t size)
static const char exclop_def[][16] = {
[BTRFS_EXCLOP_NONE] = "none",
[BTRFS_EXCLOP_BALANCE] = "balance",
[BTRFS_EXCLOP_BALANCE_PAUSED] = "balance paused",
[BTRFS_EXCLOP_DEV_ADD] = "device add",
[BTRFS_EXCLOP_DEV_REMOVE] = "device remove",
[BTRFS_EXCLOP_DEV_REPLACE] = "device replace",
@ -1554,6 +1555,15 @@ int check_running_fs_exclop(int fd, enum exclusive_operation start, bool enqueue
goto out;
}
/*
* Some combinations are compatible:
* - start device add when balance is paused (kernel 5.17)
*/
if (start == BTRFS_EXCLOP_DEV_ADD && exclop == BTRFS_EXCLOP_BALANCE_PAUSED) {
ret = 0;
goto out;
}
if (!enqueue) {
error(
"unable to start %s, another exclusive operation '%s' in progress",

View File

@ -33,6 +33,7 @@
enum exclusive_operation {
BTRFS_EXCLOP_NONE,
BTRFS_EXCLOP_BALANCE,
BTRFS_EXCLOP_BALANCE_PAUSED,
BTRFS_EXCLOP_DEV_ADD,
BTRFS_EXCLOP_DEV_REMOVE,
BTRFS_EXCLOP_DEV_REPLACE,