aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiao Xie <miaox@cn.fujitsu.com>2014-03-06 00:55:02 -0500
committerJosef Bacik <jbacik@fb.com>2014-03-10 15:17:28 -0400
commit31f3d255c677073f83daa1e0671bbf2157bf8edc (patch)
tree5a832934a4a886a7f62a21a4cfb1c678e3fab134
parent6c255e67cec1c38a0569c7f823eba63f9449ccf8 (diff)
Btrfs: split the global ordered extents mutex
When we create a snapshot, we just need wait the ordered extents in the source fs/file root, but because we use the global mutex to protect this ordered extents list of the source fs/file root to avoid accessing a empty list, if someone got the mutex to access the ordered extents list of the other fs/file root, we had to wait. This patch splits the above global mutex, now every fs/file root has its own mutex to protect its own list. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Josef Bacik <jbacik@fb.com>
-rw-r--r--fs/btrfs/ctree.h2
-rw-r--r--fs/btrfs/disk-io.c1
-rw-r--r--fs/btrfs/ordered-data.c17
3 files changed, 7 insertions, 13 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 5a800986f416..5f4921554f0a 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -1814,6 +1814,8 @@ struct btrfs_root {
1814 struct list_head delalloc_inodes; 1814 struct list_head delalloc_inodes;
1815 struct list_head delalloc_root; 1815 struct list_head delalloc_root;
1816 u64 nr_delalloc_inodes; 1816 u64 nr_delalloc_inodes;
1817
1818 struct mutex ordered_extent_mutex;
1817 /* 1819 /*
1818 * this is used by the balancing code to wait for all the pending 1820 * this is used by the balancing code to wait for all the pending
1819 * ordered extents 1821 * ordered extents
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 7d09ca48c347..237b5b5a2200 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1220,6 +1220,7 @@ static void __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize,
1220 spin_lock_init(&root->log_extents_lock[1]); 1220 spin_lock_init(&root->log_extents_lock[1]);
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 init_waitqueue_head(&root->log_writer_wait); 1224 init_waitqueue_head(&root->log_writer_wait);
1224 init_waitqueue_head(&root->log_commit_wait[0]); 1225 init_waitqueue_head(&root->log_commit_wait[0]);
1225 init_waitqueue_head(&root->log_commit_wait[1]); 1226 init_waitqueue_head(&root->log_commit_wait[1]);
diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index a75eaa286b8a..a94b05f72869 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -595,7 +595,7 @@ static void btrfs_run_ordered_extent_work(struct btrfs_work *work)
595 * wait for all the ordered extents in a root. This is done when balancing 595 * wait for all the ordered extents in a root. This is done when balancing
596 * space between drives. 596 * space between drives.
597 */ 597 */
598static int __btrfs_wait_ordered_extents(struct btrfs_root *root, int nr) 598int btrfs_wait_ordered_extents(struct btrfs_root *root, int nr)
599{ 599{
600 struct list_head splice, works; 600 struct list_head splice, works;
601 struct btrfs_ordered_extent *ordered, *next; 601 struct btrfs_ordered_extent *ordered, *next;
@@ -604,6 +604,7 @@ static int __btrfs_wait_ordered_extents(struct btrfs_root *root, int nr)
604 INIT_LIST_HEAD(&splice); 604 INIT_LIST_HEAD(&splice);
605 INIT_LIST_HEAD(&works); 605 INIT_LIST_HEAD(&works);
606 606
607 mutex_lock(&root->ordered_extent_mutex);
607 spin_lock(&root->ordered_extent_lock); 608 spin_lock(&root->ordered_extent_lock);
608 list_splice_init(&root->ordered_extents, &splice); 609 list_splice_init(&root->ordered_extents, &splice);
609 while (!list_empty(&splice) && nr) { 610 while (!list_empty(&splice) && nr) {
@@ -635,17 +636,7 @@ static int __btrfs_wait_ordered_extents(struct btrfs_root *root, int nr)
635 btrfs_put_ordered_extent(ordered); 636 btrfs_put_ordered_extent(ordered);
636 cond_resched(); 637 cond_resched();
637 } 638 }
638 639 mutex_unlock(&root->ordered_extent_mutex);
639 return count;
640}
641
642int btrfs_wait_ordered_extents(struct btrfs_root *root, int nr)
643{
644 int count;
645
646 mutex_lock(&root->fs_info->ordered_operations_mutex);
647 count = __btrfs_wait_ordered_extents(root, nr);
648 mutex_unlock(&root->fs_info->ordered_operations_mutex);
649 640
650 return count; 641 return count;
651} 642}
@@ -670,7 +661,7 @@ void btrfs_wait_ordered_roots(struct btrfs_fs_info *fs_info, int nr)
670 &fs_info->ordered_roots); 661 &fs_info->ordered_roots);
671 spin_unlock(&fs_info->ordered_root_lock); 662 spin_unlock(&fs_info->ordered_root_lock);
672 663
673 done = __btrfs_wait_ordered_extents(root, nr); 664 done = btrfs_wait_ordered_extents(root, nr);
674 btrfs_put_fs_root(root); 665 btrfs_put_fs_root(root);
675 666
676 spin_lock(&fs_info->ordered_root_lock); 667 spin_lock(&fs_info->ordered_root_lock);