Commit 7841cb28 authored by David Sterba's avatar David Sterba Committed by Chris Mason

btrfs: add helper for fs_info->closing

wrap checking of filesystem 'closing' flag and fix a few missing memory
barriers.
Signed-off-by: default avatarDavid Sterba <dsterba@suse.cz>
parent 4b9465cb
...@@ -2354,6 +2354,15 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans, ...@@ -2354,6 +2354,15 @@ int btrfs_drop_subtree(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
struct extent_buffer *node, struct extent_buffer *node,
struct extent_buffer *parent); struct extent_buffer *parent);
static inline int btrfs_fs_closing(struct btrfs_fs_info *fs_info)
{
/*
* Get synced with close_ctree()
*/
smp_mb();
return fs_info->closing;
}
/* root-item.c */ /* root-item.c */
int btrfs_find_root_ref(struct btrfs_root *tree_root, int btrfs_find_root_ref(struct btrfs_root *tree_root,
struct btrfs_path *path, struct btrfs_path *path,
......
...@@ -366,8 +366,7 @@ static int caching_kthread(void *data) ...@@ -366,8 +366,7 @@ static int caching_kthread(void *data)
nritems = btrfs_header_nritems(leaf); nritems = btrfs_header_nritems(leaf);
while (1) { while (1) {
smp_mb(); if (btrfs_fs_closing(fs_info) > 1) {
if (fs_info->closing > 1) {
last = (u64)-1; last = (u64)-1;
break; break;
} }
......
...@@ -129,7 +129,7 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans, ...@@ -129,7 +129,7 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
if (!btrfs_test_opt(root, AUTO_DEFRAG)) if (!btrfs_test_opt(root, AUTO_DEFRAG))
return 0; return 0;
if (root->fs_info->closing) if (btrfs_fs_closing(root->fs_info))
return 0; return 0;
if (BTRFS_I(inode)->in_defrag) if (BTRFS_I(inode)->in_defrag)
...@@ -229,7 +229,7 @@ int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info) ...@@ -229,7 +229,7 @@ int btrfs_run_defrag_inodes(struct btrfs_fs_info *fs_info)
first_ino = defrag->ino + 1; first_ino = defrag->ino + 1;
rb_erase(&defrag->rb_node, &fs_info->defrag_inodes); rb_erase(&defrag->rb_node, &fs_info->defrag_inodes);
if (fs_info->closing) if (btrfs_fs_closing(fs_info))
goto next_free; goto next_free;
spin_unlock(&fs_info->defrag_inodes_lock); spin_unlock(&fs_info->defrag_inodes_lock);
......
...@@ -98,7 +98,7 @@ struct inode *lookup_free_space_inode(struct btrfs_root *root, ...@@ -98,7 +98,7 @@ struct inode *lookup_free_space_inode(struct btrfs_root *root,
return inode; return inode;
spin_lock(&block_group->lock); spin_lock(&block_group->lock);
if (!root->fs_info->closing) { if (!btrfs_fs_closing(root->fs_info)) {
block_group->inode = igrab(inode); block_group->inode = igrab(inode);
block_group->iref = 1; block_group->iref = 1;
} }
...@@ -493,8 +493,7 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info, ...@@ -493,8 +493,7 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info,
* If we're unmounting then just return, since this does a search on the * If we're unmounting then just return, since this does a search on the
* normal root and not the commit root and we could deadlock. * normal root and not the commit root and we could deadlock.
*/ */
smp_mb(); if (btrfs_fs_closing(fs_info))
if (fs_info->closing)
return 0; return 0;
/* /*
...@@ -2513,7 +2512,7 @@ struct inode *lookup_free_ino_inode(struct btrfs_root *root, ...@@ -2513,7 +2512,7 @@ struct inode *lookup_free_ino_inode(struct btrfs_root *root,
return inode; return inode;
spin_lock(&root->cache_lock); spin_lock(&root->cache_lock);
if (!root->fs_info->closing) if (!btrfs_fs_closing(root->fs_info))
root->cache_inode = igrab(inode); root->cache_inode = igrab(inode);
spin_unlock(&root->cache_lock); spin_unlock(&root->cache_lock);
...@@ -2543,8 +2542,7 @@ int load_free_ino_cache(struct btrfs_fs_info *fs_info, struct btrfs_root *root) ...@@ -2543,8 +2542,7 @@ int load_free_ino_cache(struct btrfs_fs_info *fs_info, struct btrfs_root *root)
* If we're unmounting then just return, since this does a search on the * If we're unmounting then just return, since this does a search on the
* normal root and not the commit root and we could deadlock. * normal root and not the commit root and we could deadlock.
*/ */
smp_mb(); if (btrfs_fs_closing(fs_info))
if (fs_info->closing)
return 0; return 0;
path = btrfs_alloc_path(); path = btrfs_alloc_path();
......
...@@ -62,8 +62,7 @@ static int caching_kthread(void *data) ...@@ -62,8 +62,7 @@ static int caching_kthread(void *data)
goto out; goto out;
while (1) { while (1) {
smp_mb(); if (btrfs_fs_closing(fs_info))
if (fs_info->closing)
goto out; goto out;
leaf = path->nodes[0]; leaf = path->nodes[0];
......
...@@ -4266,8 +4266,7 @@ int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc) ...@@ -4266,8 +4266,7 @@ int btrfs_write_inode(struct inode *inode, struct writeback_control *wbc)
if (BTRFS_I(inode)->dummy_inode) if (BTRFS_I(inode)->dummy_inode)
return 0; return 0;
smp_mb(); if (btrfs_fs_closing(root->fs_info) && is_free_space_inode(root, inode))
if (root->fs_info->closing && is_free_space_inode(root, inode))
nolock = true; nolock = true;
if (wbc->sync_mode == WB_SYNC_ALL) { if (wbc->sync_mode == WB_SYNC_ALL) {
......
...@@ -1183,7 +1183,7 @@ int btrfs_scrub_dev(struct btrfs_root *root, u64 devid, u64 start, u64 end, ...@@ -1183,7 +1183,7 @@ int btrfs_scrub_dev(struct btrfs_root *root, u64 devid, u64 start, u64 end,
int ret; int ret;
struct btrfs_device *dev; struct btrfs_device *dev;
if (root->fs_info->closing) if (btrfs_fs_closing(root->fs_info))
return -EINVAL; return -EINVAL;
/* /*
......
...@@ -817,7 +817,7 @@ int btrfs_defrag_root(struct btrfs_root *root, int cacheonly) ...@@ -817,7 +817,7 @@ int btrfs_defrag_root(struct btrfs_root *root, int cacheonly)
btrfs_btree_balance_dirty(info->tree_root, nr); btrfs_btree_balance_dirty(info->tree_root, nr);
cond_resched(); cond_resched();
if (root->fs_info->closing || ret != -EAGAIN) if (btrfs_fs_closing(root->fs_info) || ret != -EAGAIN)
break; break;
} }
root->defrag_running = 0; root->defrag_running = 0;
......
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