Skip to content

Commit 69edf17

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 1923e05 commit 69edf17

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
@@ -3558,6 +3558,11 @@ do { \
35583558
(errno), fmt, ##args); \
35593559
} while (0)
35603560

3561+
static inline bool btrfs_has_fs_error(struct btrfs_fs_info *fs_info)
3562+
{
3563+
return test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state);
3564+
}
3565+
35613566
__printf(5, 6)
35623567
__cold
35633568
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
@@ -1956,8 +1956,7 @@ static int transaction_kthread(void *arg)
19561956
wake_up_process(fs_info->cleaner_kthread);
19571957
mutex_unlock(&fs_info->transaction_kthread_mutex);
19581958

1959-
if (unlikely(test_bit(BTRFS_FS_STATE_ERROR,
1960-
&fs_info->fs_state)))
1959+
if (unlikely(btrfs_has_fs_error(fs_info)))
19611960
btrfs_cleanup_transaction(fs_info);
19621961
if (!kthread_should_stop() &&
19631962
(!btrfs_transaction_blocked(fs_info) ||
@@ -4224,7 +4223,7 @@ void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
42244223
drop_ref = true;
42254224
spin_unlock(&fs_info->fs_roots_radix_lock);
42264225

4227-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
4226+
if (btrfs_has_fs_error(fs_info)) {
42284227
ASSERT(root->log_root == NULL);
42294228
if (root->reloc_root) {
42304229
btrfs_put_root(root->reloc_root);
@@ -4375,8 +4374,7 @@ void __cold close_ctree(struct btrfs_fs_info *fs_info)
43754374
btrfs_err(fs_info, "commit super ret %d", ret);
43764375
}
43774376

4378-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state) ||
4379-
test_bit(BTRFS_FS_STATE_TRANS_ABORTED, &fs_info->fs_state))
4377+
if (btrfs_has_fs_error(fs_info))
43804378
btrfs_error_commit_super(fs_info);
43814379

43824380
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
@@ -4871,7 +4871,7 @@ int btree_write_cache_pages(struct address_space *mapping,
48714871
* extent io tree. Thus we don't want to submit such wild eb
48724872
* if the fs already has error.
48734873
*/
4874-
if (!test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
4874+
if (!btrfs_has_fs_error(fs_info)) {
48754875
ret = flush_write_bio(&epd);
48764876
} else {
48774877
ret = -EROFS;

fs/btrfs/file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2013,7 +2013,7 @@ static ssize_t btrfs_file_write_iter(struct kiocb *iocb,
20132013
* have opened a file as writable, we have to stop this write operation
20142014
* to ensure consistency.
20152015
*/
2016-
if (test_bit(BTRFS_FS_STATE_ERROR, &inode->root->fs_info->fs_state))
2016+
if (btrfs_has_fs_error(inode->root->fs_info))
20172017
return -EROFS;
20182018

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

fs/btrfs/inode.c

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

4371-
if (!test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
4371+
if (!btrfs_has_fs_error(fs_info))
43724372
WARN_ON(btrfs_root_refs(&root->root_item) != 0);
43734373

43744374
spin_lock(&root->inode_lock);
@@ -9967,7 +9967,7 @@ int btrfs_start_delalloc_snapshot(struct btrfs_root *root, bool in_reclaim_conte
99679967
};
99689968
struct btrfs_fs_info *fs_info = root->fs_info;
99699969

9970-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
9970+
if (btrfs_has_fs_error(fs_info))
99719971
return -EROFS;
99729972

99739973
return start_delalloc_inodes(root, &wbc, true, in_reclaim_context);
@@ -9986,7 +9986,7 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, long nr,
99869986
struct list_head splice;
99879987
int ret;
99889988

9989-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
9989+
if (btrfs_has_fs_error(fs_info))
99909990
return -EROFS;
99919991

99929992
INIT_LIST_HEAD(&splice);

fs/btrfs/scrub.c

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

3959-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
3959+
if (btrfs_has_fs_error(fs_info))
39603960
return -EROFS;
39613961

39623962
/* 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
@@ -2020,7 +2020,7 @@ static int btrfs_remount(struct super_block *sb, int *flags, char *data)
20202020
if (ret)
20212021
goto restore;
20222022
} else {
2023-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
2023+
if (btrfs_has_fs_error(fs_info)) {
20242024
btrfs_err(fs_info,
20252025
"Remounting read-write after error is not allowed");
20262026
ret = -EINVAL;

fs/btrfs/transaction.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,
283283
spin_lock(&fs_info->trans_lock);
284284
loop:
285285
/* The file system has been taken offline. No new transactions. */
286-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
286+
if (btrfs_has_fs_error(fs_info)) {
287287
spin_unlock(&fs_info->trans_lock);
288288
return -EROFS;
289289
}
@@ -331,7 +331,7 @@ static noinline int join_transaction(struct btrfs_fs_info *fs_info,
331331
*/
332332
kfree(cur_trans);
333333
goto loop;
334-
} else if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state)) {
334+
} else if (btrfs_has_fs_error(fs_info)) {
335335
spin_unlock(&fs_info->trans_lock);
336336
kfree(cur_trans);
337337
return -EROFS;
@@ -579,7 +579,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
579579
bool do_chunk_alloc = false;
580580
int ret;
581581

582-
if (test_bit(BTRFS_FS_STATE_ERROR, &fs_info->fs_state))
582+
if (btrfs_has_fs_error(fs_info))
583583
return ERR_PTR(-EROFS);
584584

585585
if (current->journal_info) {
@@ -991,8 +991,7 @@ static int __btrfs_end_transaction(struct btrfs_trans_handle *trans,
991991
if (throttle)
992992
btrfs_run_delayed_iputs(info);
993993

994-
if (TRANS_ABORTED(trans) ||
995-
test_bit(BTRFS_FS_STATE_ERROR, &info->fs_state)) {
994+
if (TRANS_ABORTED(trans) || btrfs_has_fs_error(info)) {
996995
wake_up_process(info->transaction_kthread);
997996
if (TRANS_ABORTED(trans))
998997
err = trans->aborted;
@@ -2155,7 +2154,7 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans)
21552154
* abort to prevent writing a new superblock that reflects a
21562155
* corrupt state (pointing to trees with unwritten nodes/leafs).
21572156
*/
2158-
if (test_bit(BTRFS_FS_STATE_TRANS_ABORTED, &fs_info->fs_state)) {
2157+
if (btrfs_has_fs_error(fs_info)) {
21592158
ret = -EROFS;
21602159
goto cleanup_transaction;
21612160
}

fs/btrfs/tree-log.c

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

0 commit comments

Comments
 (0)