]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
btrfs: add a btrfs_has_fs_error helper
authorJosef Bacik <josef@toxicpanda.com>
Thu, 20 May 2021 15:21:32 +0000 (11:21 -0400)
committerDavid Sterba <dsterba@suse.com>
Tue, 1 Jun 2021 18:59:51 +0000 (20:59 +0200)
We have a few flags that are inconsistently used to describe the fs in
different states of failure.  As of

btrfs: always abort the transaction if we abort a trans handle

we will always set BTRFS_FS_STATE_ERROR if we abort, so we don't have to
check both ABORTED and ERROR to see if things have gone wrong.  Add a
helper to check BTRFS_FS_STATE_HELPER and then convert all checkers of
FS_STATE_ERROR to use the helper.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/ctree.h
fs/btrfs/disk-io.c
fs/btrfs/extent_io.c
fs/btrfs/file.c
fs/btrfs/inode.c
fs/btrfs/scrub.c
fs/btrfs/super.c
fs/btrfs/transaction.c
fs/btrfs/tree-log.c

index 5d0398528a7aa569148b7e92ed2db181f8c4e8ff..8ce63273990890e9df083f2e549fbc1702e20a0e 100644 (file)
@@ -3551,6 +3551,11 @@ do {                                                             \
                          (errno), fmt, ##args);                \
 } while (0)
 
+static inline bool btrfs_has_fs_error(struct btrfs_fs_info *fs_info)
+{
+       return test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state);
+}
+
 __printf(5, 6)
 __cold
 void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
index d1d5091a838576d94d224996e4d0bee601863810..d075c70f73489f8b757f9f1415606a52eb5f56b5 100644 (file)
@@ -1969,8 +1969,7 @@ sleep:
                wake_up_process(fs_info->cleaner_kthread);
                mutex_unlock(&fs_info->transaction_kthread_mutex);
 
-               if (unlikely(test_bit(BTRFS_FS_STATE_ERROR,
-                                     &fs_info->fs_state)))
+               if (unlikely(btrfs_has_fs_error(fs_info)))
                        btrfs_cleanup_transaction(fs_info);
                if (!kthread_should_stop() &&
                                (!btrfs_transaction_blocked(fs_info) ||
@@ -4232,7 +4231,7 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
                drop_ref = true;
        spin_unlock(&fs_info->fs_roots_radix_lock);
 
-       if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
+       if (btrfs_has_fs_error(fs_info)) {
                ASSERT(root->log_root == NULL);
                if (root->reloc_root) {
                        btrfs_put_root(root->reloc_root);
@@ -4383,8 +4382,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
                        btrfs_err(fs_info, "commit super ret %d", ret);
        }
 
-       if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state) ||
-           test_bit(BTRFS_FS_STATE_TRANS_ABORTED, &fs_info->fs_state))
+       if (btrfs_has_fs_error(fs_info))
                btrfs_error_commit_super(fs_info);
 
        kthread_stop(fs_info->transaction_kthread);
index 954d28df887a27ecfe38ce1482d35c0bcc8e6fc6..b6965fb3312b0a099870e8e41ad9cc706240d2da 100644 (file)
@@ -4670,7 +4670,7 @@ retry:
         *   extent io tree. Thus we don't want to submit such wild eb
         *   if the fs already has error.
         */
-       if (!test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
+       if (!btrfs_has_fs_error(fs_info)) {
                ret = flush_write_bio(&epd);
        } else {
                ret = -EROFS;
index a56a13999bd66e9be3f1649045585e785efb606a..1ec9988a9894bc6394890c2119350a87cb3724ad 100644 (file)
@@ -1999,7 +1999,7 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb,
         * have opened a file as writable, we have to stop this write operation
         * to ensure consistency.
         */
-       if (test_bit(BTRFS_FS_STATE_ERROR, &inode->root->fs_info->fs_state))
+       if (btrfs_has_fs_error(inode->root->fs_info))
                return -EROFS;
 
        if (!(iocb->ki_flags & IOCB_DIRECT) &&
index 8ba4b194cd3e414b61429d82bfe91250e0a0cbed..d8c3918e70494230c14740dd955198594107fbf7 100644 (file)
@@ -4210,7 +4210,7 @@ static void btrfs_prune_dentries(struct btrfs_root *root)
        struct inode *inode;
        u64 objectid = 0;
 
-       if (!test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
+       if (!btrfs_has_fs_error(fs_info))
                WARN_ON(btrfs_root_refs(&root->root_item) != 0);
 
        spin_lock(&root->inode_lock);
@@ -9720,7 +9720,7 @@ int btrfs_start_delalloc_snapshot(struct btrfs_root *root, bool in_reclaim_conte
        };
        struct btrfs_fs_info *fs_info = root->fs_info;
 
-       if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
+       if (btrfs_has_fs_error(fs_info))
                return -EROFS;
 
        return start_delalloc_inodes(root, &wbc, true, in_reclaim_context);
@@ -9739,7 +9739,7 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,
        struct list_head splice;
        int ret;
 
-       if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
+       if (btrfs_has_fs_error(fs_info))
                return -EROFS;
 
        INIT_LIST_HEAD(&splice);
index b60466db5654ec9c75c751698d410a94afcbe0e6..6f38ad98724a1112a74247604c52edba8d77065a 100644 (file)
@@ -3956,7 +3956,7 @@ static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
        int     ret;
        struct btrfs_fs_info *fs_info = sctx->fs_info;
 
-       if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
+       if (btrfs_has_fs_error(fs_info))
                return -EROFS;
 
        /* Seed devices of a new filesystem has their own generation. */
index bc613218c8c5bd23b62d96417c333f9cab479b51..eb6a48f0b2369d3e0f10b197c1641c6e8b263e21 100644 (file)
@@ -2018,7 +2018,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
                if (ret)
                        goto restore;
        } else {
-               if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
+               if (btrfs_has_fs_error(fs_info)) {
                        btrfs_err(fs_info,
                                "Remounting read-write after error is not allowed");
                        ret = -EINVAL;
index 22951621363f0169005efd87d9984eda0b3af606..00c713d258865b31967c157e065e45228b45bf7d 100644 (file)
@@ -285,7 +285,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,
        spin_lock(&fs_info->trans_lock);
 loop:
        /* The file system has been taken offline. No new transactions. */
-       if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
+       if (btrfs_has_fs_error(fs_info)) {
                spin_unlock(&fs_info->trans_lock);
                return -EROFS;
        }
@@ -333,7 +333,7 @@ loop:
                 */
                kfree(cur_trans);
                goto loop;
-       } else if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
+       } else if (btrfs_has_fs_error(fs_info)) {
                spin_unlock(&fs_info->trans_lock);
                kfree(cur_trans);
                return -EROFS;
@@ -586,7 +586,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
        /* Send isn't supposed to start transactions. */
        ASSERT(current->journal_info != BTRFS_SEND_TRANS_STUB);
 
-       if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
+       if (btrfs_has_fs_error(fs_info))
                return ERR_PTR(-EROFS);
 
        if (current->journal_info) {
@@ -999,8 +999,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
        if (throttle)
                btrfs_run_delayed_iputs(info);
 
-       if (TRANS_ABORTED(trans) ||
-           test_bit(BTRFS_FS_STATE_ERROR, &info->fs_state)) {
+       if (TRANS_ABORTED(trans) || btrfs_has_fs_error(info)) {
                wake_up_process(info->transaction_kthread);
                if (TRANS_ABORTED(trans))
                        err = trans->aborted;
@@ -2189,7 +2188,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
                 * abort to prevent writing a new superblock that reflects a
                 * corrupt state (pointing to trees with unwritten nodes/leafs).
                 */
-               if (test_bit(BTRFS_FS_STATE_TRANS_ABORTED, &fs_info->fs_state)) {
+               if (btrfs_has_fs_error(fs_info)) {
                        ret = -EROFS;
                        goto cleanup_transaction;
                }
index cab451d19547ae6033a0d02edd86b18b75d26649..ca597958c3ee3d3368798d2e852e10405fdb17ad 100644 (file)
@@ -3310,7 +3310,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
         * writing the super here would result in transid mismatches.  If there
         * is an error here just bail.
         */
-       if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
+       if (btrfs_has_fs_error(fs_info)) {
                ret = -EIO;
                btrfs_set_log_full_commit(trans);
                btrfs_abort_transaction(trans, ret);