diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index ecd016f7dab15caf1a5894479c094fc0734d9bbe..e490cfd70bbaab0b15876b6ac5a502a66108bb02 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h @@ -3378,6 +3378,7 @@ void btrfs_reloc_pre_snapshot(struct btrfs_pending_snapshot *pending, u64 *bytes_to_reserve); int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans, struct btrfs_pending_snapshot *pending); +int btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info); /* scrub.c */ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c index ba39f6969a7232251cc077a264f79075c53a4ddd..0238801e6408af1d4e3aa7ce1923dac2f533f902 100644 --- a/fs/btrfs/relocation.c +++ b/fs/btrfs/relocation.c @@ -9,6 +9,7 @@ #include #include #include +#include #include "ctree.h" #include "disk-io.h" #include "transaction.h" @@ -3314,6 +3315,15 @@ int setup_extent_mapping(struct inode *inode, u64 start, u64 end, return ret; } +/* + * Allow error injection to test balance cancellation + */ +int btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info) +{ + return atomic_read(&fs_info->balance_cancel_req); +} +ALLOW_ERROR_INJECTION(btrfs_should_cancel_balance, TRUE); + static int relocate_file_extent_cluster(struct inode *inode, struct file_extent_cluster *cluster) { diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 74c34c388098d523274f9acd98066d6bbef081e3..c1909e5f4506835f7741c5003c51ac65982a3a29 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -3994,7 +3994,7 @@ int btrfs_balance(struct btrfs_fs_info *fs_info, if (btrfs_fs_closing(fs_info) || atomic_read(&fs_info->balance_pause_req) || - atomic_read(&fs_info->balance_cancel_req)) { + btrfs_should_cancel_balance(fs_info)) { ret = -EINVAL; goto out; }