Re: [PATCH v3 1/3] btrfs: introduce BTRFS_EXCLOP_BALANCE_PAUSED exclusive state
From: David Sterba <hidden>
Date: 2021-11-25 15:38:09
On Thu, Nov 25, 2021 at 11:14:41AM +0200, Nikolay Borisov wrote:
quoted hunk ↗ jump to hunk
Current set of exclusive operation states is not sufficient to handle all practical use cases. In particular there is a need to be able to add a device to a filesystem that have paused balance. Currently there is no way to distinguish between a running and a paused balance. Fix this by introducing BTRFS_EXCLOP_BALANCE_PAUSED which is going to be set in 2 occasions: 1. When a filesystem is mounted with skip_balance and there is an unfinished balance it will now be into BALANCE_PAUSED instead of simply BALANCE state. 2. When a running balance is paused. Signed-off-by: Nikolay Borisov <redacted> --- fs/btrfs/ctree.h | 4 ++++ fs/btrfs/ioctl.c | 23 +++++++++++++++++++++++ fs/btrfs/volumes.c | 10 ++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-)diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 5e29f3fc527d..79a873c6d186 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h@@ -613,6 +613,7 @@ enum { */ enum btrfs_exclusive_operation { BTRFS_EXCLOP_NONE, + BTRFS_EXCLOP_BALANCE_PAUSED, BTRFS_EXCLOP_BALANCE, BTRFS_EXCLOP_DEV_ADD, BTRFS_EXCLOP_DEV_REMOVE,@@ -3316,6 +3317,9 @@ bool btrfs_exclop_start_try_lock(struct btrfs_fs_info *fs_info, enum btrfs_exclusive_operation type); void btrfs_exclop_start_unlock(struct btrfs_fs_info *fs_info); void btrfs_exclop_finish(struct btrfs_fs_info *fs_info); +void btrfs_exclop_balance(struct btrfs_fs_info *fs_info, + enum btrfs_exclusive_operation op); + /* file.c */ int __init btrfs_auto_defrag_init(void);diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 5263f991ffff..ffe33e853bfa 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c@@ -414,6 +414,28 @@ void btrfs_exclop_finish(struct btrfs_fs_info *fs_info) sysfs_notify(&fs_info->fs_devices->fsid_kobj, NULL, "exclusive_operation"); } +void btrfs_exclop_balance(struct btrfs_fs_info *fs_info, + enum btrfs_exclusive_operation op) +{ + switch (op) { + case BTRFS_EXCLOP_BALANCE_PAUSED: + spin_lock(&fs_info->super_lock); + ASSERT(fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE || + fs_info->exclusive_operation == BTRFS_EXCLOP_DEV_ADD); + fs_info->exclusive_operation = BTRFS_EXCLOP_BALANCE_PAUSED; + spin_unlock(&fs_info->super_lock); + break; + case BTRFS_EXCLOP_BALANCE: + spin_lock(&fs_info->super_lock); + ASSERT(fs_info->exclusive_operation == BTRFS_EXCLOP_BALANCE_PAUSED); + fs_info->exclusive_operation = BTRFS_EXCLOP_BALANCE; + spin_unlock(&fs_info->super_lock); + break; + default: + WARN(1, "BTRFS: invalid balance operation requested\n");
As the fs_info is available, this shoud use btrfs_warn because it also prints the uuid/device of the filesytem, otherwise the message is useless. Also it could contain the number of the operation. I'll fix that.