Skip to content

Commit 7841cb2

Browse files
kdavechrismason-xx
authored andcommitted
btrfs: add helper for fs_info->closing
wrap checking of filesystem 'closing' flag and fix a few missing memory barriers. Signed-off-by: David Sterba <dsterba@suse.cz>
1 parent 4b9465c commit 7841cb2

File tree

8 files changed

+20
-16
lines changed

8 files changed

+20
-16
lines changed

fs/btrfs/ctree.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2354,6 +2354,15 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
23542354
struct btrfs_root *root,
23552355
struct extent_buffer *node,
23562356
struct extent_buffer *parent);
2357+
static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info)
2358+
{
2359+
/*
2360+
* Get synced with close_ctree()
2361+
*/
2362+
smp_mb();
2363+
return fs_info->closing;
2364+
}
2365+
23572366
/* root-item.c */
23582367
int btrfs_find_root_ref(struct btrfs_root *tree_root,
23592368
struct btrfs_path *path,

fs/btrfs/extent-tree.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,7 @@ static int caching_kthread(void *data)
366366
nritems = btrfs_header_nritems(leaf);
367367

368368
while (1) {
369-
smp_mb();
370-
if (fs_info->closing > 1) {
369+
if (btrfs_fs_closing(fs_info) > 1) {
371370
last = (u64)-1;
372371
break;
373372
}

fs/btrfs/file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
129129
if (!btrfs_test_opt(root, AUTO_DEFRAG))
130130
return 0;
131131

132-
if (root->fs_info->closing)
132+
if (btrfs_fs_closing(root->fs_info))
133133
return 0;
134134

135135
if (BTRFS_I(inode)->in_defrag)
@@ -229,7 +229,7 @@ int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info)
229229
first_ino = defrag->ino + 1;
230230
rb_erase(&defrag->rb_node, &fs_info->defrag_inodes);
231231

232-
if (fs_info->closing)
232+
if (btrfs_fs_closing(fs_info))
233233
goto next_free;
234234

235235
spin_unlock(&fs_info->defrag_inodes_lock);

fs/btrfs/free-space-cache.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct inode *lookup_free_space_inode(struct btrfs_root *root,
9898
return inode;
9999

100100
spin_lock(&block_group->lock);
101-
if (!root->fs_info->closing) {
101+
if (!btrfs_fs_closing(root->fs_info)) {
102102
block_group->inode = igrab(inode);
103103
block_group->iref = 1;
104104
}
@@ -493,8 +493,7 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info,
493493
* If we're unmounting then just return, since this does a search on the
494494
* normal root and not the commit root and we could deadlock.
495495
*/
496-
smp_mb();
497-
if (fs_info->closing)
496+
if (btrfs_fs_closing(fs_info))
498497
return 0;
499498

500499
/*
@@ -2513,7 +2512,7 @@ struct inode *lookup_free_ino_inode(struct btrfs_root *root,
25132512
return inode;
25142513

25152514
spin_lock(&root->cache_lock);
2516-
if (!root->fs_info->closing)
2515+
if (!btrfs_fs_closing(root->fs_info))
25172516
root->cache_inode = igrab(inode);
25182517
spin_unlock(&root->cache_lock);
25192518

@@ -2543,8 +2542,7 @@ int load_free_ino_cache(struct btrfs_fs_info *fs_info, struct btrfs_root *root)
25432542
* If we're unmounting then just return, since this does a search on the
25442543
* normal root and not the commit root and we could deadlock.
25452544
*/
2546-
smp_mb();
2547-
if (fs_info->closing)
2545+
if (btrfs_fs_closing(fs_info))
25482546
return 0;
25492547

25502548
path = btrfs_alloc_path();

fs/btrfs/inode-map.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ static int caching_kthread(void *data)
6262
goto out;
6363

6464
while (1) {
65-
smp_mb();
66-
if (fs_info->closing)
65+
if (btrfs_fs_closing(fs_info))
6766
goto out;
6867

6968
leaf = path->nodes[0];

fs/btrfs/inode.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4266,8 +4266,7 @@ int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc)
42664266
if (BTRFS_I(inode)->dummy_inode)
42674267
return 0;
42684268

4269-
smp_mb();
4270-
if (root->fs_info->closing && is_free_space_inode(root, inode))
4269+
if (btrfs_fs_closing(root->fs_info) && is_free_space_inode(root, inode))
42714270
nolock = true;
42724271

42734272
if (wbc->sync_mode == WB_SYNC_ALL) {

fs/btrfs/scrub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ int btrfs_scrub_dev(struct btrfs_root *root, u64 devid, u64 start, u64 end,
11831183
int ret;
11841184
struct btrfs_device *dev;
11851185

1186-
if (root->fs_info->closing)
1186+
if (btrfs_fs_closing(root->fs_info))
11871187
return -EINVAL;
11881188

11891189
/*

fs/btrfs/transaction.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ int btrfs_defrag_root(struct btrfs_root *root, int cacheonly)
817817
btrfs_btree_balance_dirty(info->tree_root, nr);
818818
cond_resched();
819819

820-
if (root->fs_info->closing || ret != -EAGAIN)
820+
if (btrfs_fs_closing(root->fs_info) || ret != -EAGAIN)
821821
break;
822822
}
823823
root->defrag_running = 0;

0 commit comments

Comments
 (0)