]> git.hungrycats.org Git - linux/commitdiff
btrfs: relocation: Introduce error injection points for cancelling balance
authorQu Wenruo <wqu@suse.com>
Tue, 3 Dec 2019 06:42:51 +0000 (14:42 +0800)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Mon, 9 Dec 2019 16:14:15 +0000 (11:14 -0500)
Introduce a new error injection point, should_cancel_balance().

It's just a wrapper of atomic_read(&fs_info->balance_cancel_req), but
allows us to override the return value.

Currently there are only one locations using this function:
- btrfs_balance()
  It checks cancel before each block group.

There are other locations checking fs_info->balance_cancel_req, but they
are not used as an indicator to exit, so there is no need to use the
wrapper.

But there will be more locations coming, and some locations can cause
kernel panic if not handled properly.

So introduce this error injection to provide better test interface.

Signed-off-by: Qu Wenruo <wqu@suse.com>
(cherry picked from commit 6d2751364569f885ca795e37882690a78ac9f149)
(cherry picked from commit 2b39bbf4fbde34813d13de1f10da7fcd28bd252e)
(cherry picked from commit a8a7fd9a26ef3fc044f8e18287e5bbe9bb149164)
(cherry picked from commit be37be4252bf8815a115a823d869498746179a2b)

fs/btrfs/ctree.h
fs/btrfs/relocation.c
fs/btrfs/volumes.c

index 9019265a2bf9bf9789095ce939e5a9a352ba2880..84dd1495a798dac5ce022ce99995c7046c0e75db 100644 (file)
@@ -3734,6 +3734,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 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,
index a93b0f143d063554dc4cc31e3ca9a6be112d94fd..eeecaa6d2f79c162c7a7ba2f343a248d3f751e6e 100644 (file)
@@ -9,6 +9,7 @@
 #include <linux/blkdev.h>
 #include <linux/rbtree.h>
 #include <linux/slab.h>
+#include <linux/error-injection.h>
 #include "ctree.h"
 #include "disk-io.h"
 #include "transaction.h"
@@ -3132,6 +3133,16 @@ int setup_extent_mapping(struct inode *inode, u64 start, u64 end,
        return ret;
 }
 
+/*
+ * This wrapper is to allow error injection to fully test all cancel
+ * call sites.
+ */
+int should_cancel_balance(struct btrfs_fs_info *fs_info)
+{
+       return atomic_read(&fs_info->balance_cancel_req);
+}
+ALLOW_ERROR_INJECTION(should_cancel_balance, TRUE);
+
 static int relocate_file_extent_cluster(struct inode *inode,
                                        struct file_extent_cluster *cluster)
 {
index 77e9d0482445743b1010199368bfd8c2d7a05e5e..f0fdd267bcb63560ca8082b98d96e1cd3b19f563 100644 (file)
@@ -4100,7 +4100,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)) {
+           should_cancel_balance(fs_info)) {
                ret = -EINVAL;
                goto out;
        }