Skip to content

Commit c76ac8d

Browse files
josefbacikkdave
authored andcommitted
btrfs: add a btrfs_has_fs_error helper
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 <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent a16c4c3 commit c76ac8d

File tree

9 files changed

+21
-19
lines changed

9 files changed

+21
-19
lines changed

fs/btrfs/ctree.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3531,6 +3531,11 @@ do { \
35313531
(errno), fmt, ##args); \
35323532
} while (0)
35333533

3534+
static inline bool btrfs_has_fs_error(struct btrfs_fs_info *fs_info)
3535+
{
3536+
return test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state);
3537+
}
3538+
35343539
__printf(5, 6)
35353540
__cold
35363541
void __btrfs_panic(struct btrfs_fs_info *fs_info, const char *function,

fs/btrfs/disk-io.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,8 +1969,7 @@ static int transaction_kthread(void *arg)
19691969
wake_up_process(fs_info->cleaner_kthread);
19701970
mutex_unlock(&fs_info->transaction_kthread_mutex);
19711971

1972-
if (unlikely(test_bit(BTRFS_FS_STATE_ERROR,
1973-
&fs_info->fs_state)))
1972+
if (unlikely(btrfs_has_fs_error(fs_info)))
19741973
btrfs_cleanup_transaction(fs_info);
19751974
if (!kthread_should_stop() &&
19761975
(!btrfs_transaction_blocked(fs_info) ||
@@ -4221,7 +4220,7 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
42214220
drop_ref = true;
42224221
spin_unlock(&fs_info->fs_roots_radix_lock);
42234222

4224-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
4223+
if (btrfs_has_fs_error(fs_info)) {
42254224
ASSERT(root->log_root == NULL);
42264225
if (root->reloc_root) {
42274226
btrfs_put_root(root->reloc_root);
@@ -4372,8 +4371,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
43724371
btrfs_err(fs_info, "commit super ret %d", ret);
43734372
}
43744373

4375-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state) ||
4376-
test_bit(BTRFS_FS_STATE_TRANS_ABORTED, &fs_info->fs_state))
4374+
if (btrfs_has_fs_error(fs_info))
43774375
btrfs_error_commit_super(fs_info);
43784376

43794377
kthread_stop(fs_info->transaction_kthread);

fs/btrfs/extent_io.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4607,7 +4607,7 @@ int btree_write_cache_pages(struct address_space *mapping,
46074607
* extent io tree. Thus we don't want to submit such wild eb
46084608
* if the fs already has error.
46094609
*/
4610-
if (!test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
4610+
if (!btrfs_has_fs_error(fs_info)) {
46114611
ret = flush_write_bio(&epd);
46124612
} else {
46134613
ret = -EROFS;

fs/btrfs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1999,7 +1999,7 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb,
19991999
* have opened a file as writable, we have to stop this write operation
20002000
* to ensure consistency.
20012001
*/
2002-
if (test_bit(BTRFS_FS_STATE_ERROR, &inode->root->fs_info->fs_state))
2002+
if (btrfs_has_fs_error(inode->root->fs_info))
20032003
return -EROFS;
20042004

20052005
if (!(iocb->ki_flags & IOCB_DIRECT) &&

fs/btrfs/inode.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4230,7 +4230,7 @@ static void btrfs_prune_dentries(struct btrfs_root *root)
42304230
struct inode *inode;
42314231
u64 objectid = 0;
42324232

4233-
if (!test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
4233+
if (!btrfs_has_fs_error(fs_info))
42344234
WARN_ON(btrfs_root_refs(&root->root_item) != 0);
42354235

42364236
spin_lock(&root->inode_lock);
@@ -9741,7 +9741,7 @@ int btrfs_start_delalloc_snapshot(struct btrfs_root *root, bool in_reclaim_conte
97419741
};
97429742
struct btrfs_fs_info *fs_info = root->fs_info;
97439743

9744-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
9744+
if (btrfs_has_fs_error(fs_info))
97459745
return -EROFS;
97469746

97479747
return start_delalloc_inodes(root, &wbc, true, in_reclaim_context);
@@ -9760,7 +9760,7 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,
97609760
struct list_head splice;
97619761
int ret;
97629762

9763-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
9763+
if (btrfs_has_fs_error(fs_info))
97649764
return -EROFS;
97659765

97669766
INIT_LIST_HEAD(&splice);

fs/btrfs/scrub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3959,7 +3959,7 @@ static noinline_for_stack int scrub_supers(struct scrub_ctx *sctx,
39593959
int ret;
39603960
struct btrfs_fs_info *fs_info = sctx->fs_info;
39613961

3962-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
3962+
if (btrfs_has_fs_error(fs_info))
39633963
return -EROFS;
39643964

39653965
/* Seed devices of a new filesystem has their own generation. */

fs/btrfs/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2018,7 +2018,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
20182018
if (ret)
20192019
goto restore;
20202020
} else {
2021-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
2021+
if (btrfs_has_fs_error(fs_info)) {
20222022
btrfs_err(fs_info,
20232023
"Remounting read-write after error is not allowed");
20242024
ret = -EINVAL;

fs/btrfs/transaction.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,
285285
spin_lock(&fs_info->trans_lock);
286286
loop:
287287
/* The file system has been taken offline. No new transactions. */
288-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
288+
if (btrfs_has_fs_error(fs_info)) {
289289
spin_unlock(&fs_info->trans_lock);
290290
return -EROFS;
291291
}
@@ -333,7 +333,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,
333333
*/
334334
kfree(cur_trans);
335335
goto loop;
336-
} else if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
336+
} else if (btrfs_has_fs_error(fs_info)) {
337337
spin_unlock(&fs_info->trans_lock);
338338
kfree(cur_trans);
339339
return -EROFS;
@@ -586,7 +586,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
586586
/* Send isn't supposed to start transactions. */
587587
ASSERT(current->journal_info != BTRFS_SEND_TRANS_STUB);
588588

589-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
589+
if (btrfs_has_fs_error(fs_info))
590590
return ERR_PTR(-EROFS);
591591

592592
if (current->journal_info) {
@@ -999,8 +999,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
999999
if (throttle)
10001000
btrfs_run_delayed_iputs(info);
10011001

1002-
if (TRANS_ABORTED(trans) ||
1003-
test_bit(BTRFS_FS_STATE_ERROR, &info->fs_state)) {
1002+
if (TRANS_ABORTED(trans) || btrfs_has_fs_error(info)) {
10041003
wake_up_process(info->transaction_kthread);
10051004
if (TRANS_ABORTED(trans))
10061005
err = trans->aborted;
@@ -2187,7 +2186,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
21872186
* abort to prevent writing a new superblock that reflects a
21882187
* corrupt state (pointing to trees with unwritten nodes/leafs).
21892188
*/
2190-
if (test_bit(BTRFS_FS_STATE_TRANS_ABORTED, &fs_info->fs_state)) {
2189+
if (btrfs_has_fs_error(fs_info)) {
21912190
ret = -EROFS;
21922191
goto cleanup_transaction;
21932192
}

fs/btrfs/tree-log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3310,7 +3310,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
33103310
* writing the super here would result in transid mismatches. If there
33113311
* is an error here just bail.
33123312
*/
3313-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
3313+
if (btrfs_has_fs_error(fs_info)) {
33143314
ret = -EIO;
33153315
btrfs_set_log_full_commit(trans);
33163316
btrfs_abort_transaction(trans, ret);

0 commit comments

Comments
 (0)