diff options
author | Miao Xie <miaox@cn.fujitsu.com> | 2014-03-06 00:55:03 -0500 |
---|---|---|
committer | Josef Bacik <jbacik@fb.com> | 2014-03-10 15:17:29 -0400 |
commit | 573bfb72f7608eb7097d2dd036a714a6ab20cffe (patch) | |
tree | 5434c2e82299cf22af4470fef31d3890d209a0b9 /fs/btrfs | |
parent | 31f3d255c677073f83daa1e0671bbf2157bf8edc (diff) |
Btrfs: fix possible empty list access when flushing the delalloc inodes
We didn't have a lock to protect the access to the delalloc inodes list, that is
we might access a empty delalloc inodes list if someone start flushing delalloc
inodes because the delalloc inodes were moved into a other list temporarily.
Fix it by wrapping the access with a lock.
Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: Josef Bacik <jbacik@fb.com>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/ctree.h | 2 | ||||
-rw-r--r-- | fs/btrfs/disk-io.c | 2 | ||||
-rw-r--r-- | fs/btrfs/inode.c | 4 |
3 files changed, 8 insertions, 0 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index 5f4921554f0a..2a9d32e193a5 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -1490,6 +1490,7 @@ struct btrfs_fs_info { | |||
1490 | */ | 1490 | */ |
1491 | struct list_head ordered_roots; | 1491 | struct list_head ordered_roots; |
1492 | 1492 | ||
1493 | struct mutex delalloc_root_mutex; | ||
1493 | spinlock_t delalloc_root_lock; | 1494 | spinlock_t delalloc_root_lock; |
1494 | /* all fs/file tree roots that have delalloc inodes. */ | 1495 | /* all fs/file tree roots that have delalloc inodes. */ |
1495 | struct list_head delalloc_roots; | 1496 | struct list_head delalloc_roots; |
@@ -1805,6 +1806,7 @@ struct btrfs_root { | |||
1805 | spinlock_t root_item_lock; | 1806 | spinlock_t root_item_lock; |
1806 | atomic_t refs; | 1807 | atomic_t refs; |
1807 | 1808 | ||
1809 | struct mutex delalloc_mutex; | ||
1808 | spinlock_t delalloc_lock; | 1810 | spinlock_t delalloc_lock; |
1809 | /* | 1811 | /* |
1810 | * all of the inodes that have delalloc bytes. It is possible for | 1812 | * all of the inodes that have delalloc bytes. It is possible for |
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 237b5b5a2200..d9698fda2d12 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c | |||
@@ -1221,6 +1221,7 @@ static void __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, | |||
1221 | mutex_init(&root->objectid_mutex); | 1221 | mutex_init(&root->objectid_mutex); |
1222 | mutex_init(&root->log_mutex); | 1222 | mutex_init(&root->log_mutex); |
1223 | mutex_init(&root->ordered_extent_mutex); | 1223 | mutex_init(&root->ordered_extent_mutex); |
1224 | mutex_init(&root->delalloc_mutex); | ||
1224 | init_waitqueue_head(&root->log_writer_wait); | 1225 | init_waitqueue_head(&root->log_writer_wait); |
1225 | init_waitqueue_head(&root->log_commit_wait[0]); | 1226 | init_waitqueue_head(&root->log_commit_wait[0]); |
1226 | init_waitqueue_head(&root->log_commit_wait[1]); | 1227 | init_waitqueue_head(&root->log_commit_wait[1]); |
@@ -2209,6 +2210,7 @@ int open_ctree(struct super_block *sb, | |||
2209 | spin_lock_init(&fs_info->buffer_lock); | 2210 | spin_lock_init(&fs_info->buffer_lock); |
2210 | rwlock_init(&fs_info->tree_mod_log_lock); | 2211 | rwlock_init(&fs_info->tree_mod_log_lock); |
2211 | mutex_init(&fs_info->reloc_mutex); | 2212 | mutex_init(&fs_info->reloc_mutex); |
2213 | mutex_init(&fs_info->delalloc_root_mutex); | ||
2212 | seqlock_init(&fs_info->profiles_lock); | 2214 | seqlock_init(&fs_info->profiles_lock); |
2213 | 2215 | ||
2214 | init_completion(&fs_info->kobj_unregister); | 2216 | init_completion(&fs_info->kobj_unregister); |
diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index fbaf1ac3941b..0ec876657923 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c | |||
@@ -8450,6 +8450,7 @@ static int __start_delalloc_inodes(struct btrfs_root *root, int delay_iput, | |||
8450 | INIT_LIST_HEAD(&works); | 8450 | INIT_LIST_HEAD(&works); |
8451 | INIT_LIST_HEAD(&splice); | 8451 | INIT_LIST_HEAD(&splice); |
8452 | 8452 | ||
8453 | mutex_lock(&root->delalloc_mutex); | ||
8453 | spin_lock(&root->delalloc_lock); | 8454 | spin_lock(&root->delalloc_lock); |
8454 | list_splice_init(&root->delalloc_inodes, &splice); | 8455 | list_splice_init(&root->delalloc_inodes, &splice); |
8455 | while (!list_empty(&splice)) { | 8456 | while (!list_empty(&splice)) { |
@@ -8495,6 +8496,7 @@ static int __start_delalloc_inodes(struct btrfs_root *root, int delay_iput, | |||
8495 | list_splice_tail(&splice, &root->delalloc_inodes); | 8496 | list_splice_tail(&splice, &root->delalloc_inodes); |
8496 | spin_unlock(&root->delalloc_lock); | 8497 | spin_unlock(&root->delalloc_lock); |
8497 | } | 8498 | } |
8499 | mutex_unlock(&root->delalloc_mutex); | ||
8498 | return ret; | 8500 | return ret; |
8499 | } | 8501 | } |
8500 | 8502 | ||
@@ -8536,6 +8538,7 @@ int btrfs_start_delalloc_roots(struct btrfs_fs_info *fs_info, int delay_iput, | |||
8536 | 8538 | ||
8537 | INIT_LIST_HEAD(&splice); | 8539 | INIT_LIST_HEAD(&splice); |
8538 | 8540 | ||
8541 | mutex_lock(&fs_info->delalloc_root_mutex); | ||
8539 | spin_lock(&fs_info->delalloc_root_lock); | 8542 | spin_lock(&fs_info->delalloc_root_lock); |
8540 | list_splice_init(&fs_info->delalloc_roots, &splice); | 8543 | list_splice_init(&fs_info->delalloc_roots, &splice); |
8541 | while (!list_empty(&splice) && nr) { | 8544 | while (!list_empty(&splice) && nr) { |
@@ -8575,6 +8578,7 @@ out: | |||
8575 | list_splice_tail(&splice, &fs_info->delalloc_roots); | 8578 | list_splice_tail(&splice, &fs_info->delalloc_roots); |
8576 | spin_unlock(&fs_info->delalloc_root_lock); | 8579 | spin_unlock(&fs_info->delalloc_root_lock); |
8577 | } | 8580 | } |
8581 | mutex_unlock(&fs_info->delalloc_root_mutex); | ||
8578 | return ret; | 8582 | return ret; |
8579 | } | 8583 | } |
8580 | 8584 | ||