Commit 84961539 authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: add a BTRFS_FS_ERROR helper

We have a few flags that are inconsistently used to describe the fs in
different states of failure.  As of 5963ffca ("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_ERROR and then convert all checkers of FS_STATE_ERROR to
use the helper.

The TRANS_ABORTED bit check was added in af722733 ("Btrfs: clean up
resources during umount after trans is aborted") but is not actually
specific.
Reviewed-by: default avatarAnand Jain <anand.jain@oracle.com>
Reviewed-by: default avatarNikolay Borisov <nborisov@suse.com>
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 9a35fc95
...@@ -3607,6 +3607,9 @@ do { \ ...@@ -3607,6 +3607,9 @@ do { \
(errno), fmt, ##args); \ (errno), fmt, ##args); \
} while (0) } while (0)
#define BTRFS_FS_ERROR(fs_info) (unlikely(test_bit(BTRFS_FS_STATE_ERROR, \
&(fs_info)->fs_state)))
__printf(5, 6) __printf(5, 6)
__cold __cold
void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function, void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,
......
...@@ -1954,8 +1954,7 @@ static int transaction_kthread(void *arg) ...@@ -1954,8 +1954,7 @@ static int transaction_kthread(void *arg)
wake_up_process(fs_info->cleaner_kthread); wake_up_process(fs_info->cleaner_kthread);
mutex_unlock(&fs_info->transaction_kthread_mutex); mutex_unlock(&fs_info->transaction_kthread_mutex);
if (unlikely(test_bit(BTRFS_FS_STATE_ERROR, if (BTRFS_FS_ERROR(fs_info))
&fs_info->fs_state)))
btrfs_cleanup_transaction(fs_info); btrfs_cleanup_transaction(fs_info);
if (!kthread_should_stop() && if (!kthread_should_stop() &&
(!btrfs_transaction_blocked(fs_info) || (!btrfs_transaction_blocked(fs_info) ||
...@@ -4232,7 +4231,7 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, ...@@ -4232,7 +4231,7 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
drop_ref = true; drop_ref = true;
spin_unlock(&fs_info->fs_roots_radix_lock); spin_unlock(&fs_info->fs_roots_radix_lock);
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { if (BTRFS_FS_ERROR(fs_info)) {
ASSERT(root->log_root == NULL); ASSERT(root->log_root == NULL);
if (root->reloc_root) { if (root->reloc_root) {
btrfs_put_root(root->reloc_root); btrfs_put_root(root->reloc_root);
...@@ -4383,8 +4382,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info) ...@@ -4383,8 +4382,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
btrfs_err(fs_info, "commit super ret %d", ret); btrfs_err(fs_info, "commit super ret %d", ret);
} }
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state) || if (BTRFS_FS_ERROR(fs_info))
test_bit(BTRFS_FS_STATE_TRANS_ABORTED, &fs_info->fs_state))
btrfs_error_commit_super(fs_info); btrfs_error_commit_super(fs_info);
kthread_stop(fs_info->transaction_kthread); kthread_stop(fs_info->transaction_kthread);
......
...@@ -4908,7 +4908,7 @@ int btree_write_cache_pages(struct address_space *mapping, ...@@ -4908,7 +4908,7 @@ int btree_write_cache_pages(struct address_space *mapping,
* extent io tree. Thus we don't want to submit such wild eb * extent io tree. Thus we don't want to submit such wild eb
* if the fs already has error. * if the fs already has error.
*/ */
if (!test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { if (!BTRFS_FS_ERROR(fs_info)) {
ret = flush_write_bio(&epd); ret = flush_write_bio(&epd);
} else { } else {
ret = -EROFS; ret = -EROFS;
......
...@@ -2018,7 +2018,7 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb, ...@@ -2018,7 +2018,7 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb,
* have opened a file as writable, we have to stop this write operation * have opened a file as writable, we have to stop this write operation
* to ensure consistency. * to ensure consistency.
*/ */
if (test_bit(BTRFS_FS_STATE_ERROR, &inode->root->fs_info->fs_state)) if (BTRFS_FS_ERROR(inode->root->fs_info))
return -EROFS; return -EROFS;
if (!(iocb->ki_flags & IOCB_DIRECT) && if (!(iocb->ki_flags & IOCB_DIRECT) &&
......
...@@ -4380,7 +4380,7 @@ static void btrfs_prune_dentries(struct btrfs_root *root) ...@@ -4380,7 +4380,7 @@ static void btrfs_prune_dentries(struct btrfs_root *root)
struct inode *inode; struct inode *inode;
u64 objectid = 0; u64 objectid = 0;
if (!test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) if (!BTRFS_FS_ERROR(fs_info))
WARN_ON(btrfs_root_refs(&root->root_item) != 0); WARN_ON(btrfs_root_refs(&root->root_item) != 0);
spin_lock(&root->inode_lock); spin_lock(&root->inode_lock);
...@@ -9998,7 +9998,7 @@ int btrfs_start_delalloc_snapshot(struct btrfs_root *root, bool in_reclaim_conte ...@@ -9998,7 +9998,7 @@ int btrfs_start_delalloc_snapshot(struct btrfs_root *root, bool in_reclaim_conte
}; };
struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_fs_info *fs_info = root->fs_info;
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) if (BTRFS_FS_ERROR(fs_info))
return -EROFS; return -EROFS;
return start_delalloc_inodes(root, &wbc, true, in_reclaim_context); return start_delalloc_inodes(root, &wbc, true, in_reclaim_context);
...@@ -10017,7 +10017,7 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr, ...@@ -10017,7 +10017,7 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,
struct list_head splice; struct list_head splice;
int ret; int ret;
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) if (BTRFS_FS_ERROR(fs_info))
return -EROFS; return -EROFS;
INIT_LIST_HEAD(&splice); INIT_LIST_HEAD(&splice);
......
...@@ -3955,7 +3955,7 @@ static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx, ...@@ -3955,7 +3955,7 @@ static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
int ret; int ret;
struct btrfs_fs_info *fs_info = sctx->fs_info; struct btrfs_fs_info *fs_info = sctx->fs_info;
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) if (BTRFS_FS_ERROR(fs_info))
return -EROFS; return -EROFS;
/* Seed devices of a new filesystem has their own generation. */ /* Seed devices of a new filesystem has their own generation. */
......
...@@ -2006,7 +2006,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data) ...@@ -2006,7 +2006,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
if (ret) if (ret)
goto restore; goto restore;
} else { } else {
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { if (BTRFS_FS_ERROR(fs_info)) {
btrfs_err(fs_info, btrfs_err(fs_info,
"Remounting read-write after error is not allowed"); "Remounting read-write after error is not allowed");
ret = -EINVAL; ret = -EINVAL;
......
...@@ -283,7 +283,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info, ...@@ -283,7 +283,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,
spin_lock(&fs_info->trans_lock); spin_lock(&fs_info->trans_lock);
loop: loop:
/* The file system has been taken offline. No new transactions. */ /* The file system has been taken offline. No new transactions. */
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { if (BTRFS_FS_ERROR(fs_info)) {
spin_unlock(&fs_info->trans_lock); spin_unlock(&fs_info->trans_lock);
return -EROFS; return -EROFS;
} }
...@@ -331,7 +331,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info, ...@@ -331,7 +331,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,
*/ */
kfree(cur_trans); kfree(cur_trans);
goto loop; goto loop;
} else if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { } else if (BTRFS_FS_ERROR(fs_info)) {
spin_unlock(&fs_info->trans_lock); spin_unlock(&fs_info->trans_lock);
kfree(cur_trans); kfree(cur_trans);
return -EROFS; return -EROFS;
...@@ -579,7 +579,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items, ...@@ -579,7 +579,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
bool do_chunk_alloc = false; bool do_chunk_alloc = false;
int ret; int ret;
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) if (BTRFS_FS_ERROR(fs_info))
return ERR_PTR(-EROFS); return ERR_PTR(-EROFS);
if (current->journal_info) { if (current->journal_info) {
...@@ -991,8 +991,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans, ...@@ -991,8 +991,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
if (throttle) if (throttle)
btrfs_run_delayed_iputs(info); btrfs_run_delayed_iputs(info);
if (TRANS_ABORTED(trans) || if (TRANS_ABORTED(trans) || BTRFS_FS_ERROR(info)) {
test_bit(BTRFS_FS_STATE_ERROR, &info->fs_state)) {
wake_up_process(info->transaction_kthread); wake_up_process(info->transaction_kthread);
if (TRANS_ABORTED(trans)) if (TRANS_ABORTED(trans))
err = trans->aborted; err = trans->aborted;
...@@ -2155,7 +2154,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans) ...@@ -2155,7 +2154,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
* abort to prevent writing a new superblock that reflects a * abort to prevent writing a new superblock that reflects a
* corrupt state (pointing to trees with unwritten nodes/leafs). * corrupt state (pointing to trees with unwritten nodes/leafs).
*/ */
if (test_bit(BTRFS_FS_STATE_TRANS_ABORTED, &fs_info->fs_state)) { if (BTRFS_FS_ERROR(fs_info)) {
ret = -EROFS; ret = -EROFS;
goto cleanup_transaction; goto cleanup_transaction;
} }
......
...@@ -3353,7 +3353,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans, ...@@ -3353,7 +3353,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
* writing the super here would result in transid mismatches. If there * writing the super here would result in transid mismatches. If there
* is an error here just bail. * is an error here just bail.
*/ */
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) { if (BTRFS_FS_ERROR(fs_info)) {
ret = -EIO; ret = -EIO;
btrfs_set_log_full_commit(trans); btrfs_set_log_full_commit(trans);
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment