[PATCH 4/5] btrfs: walk waited ordered roots in place

Johannes Thumshirn <[email protected]>
Newsgroups org.kernel.vger.linux-btrfs
Message-ID <[email protected]>
Like the previous change for btrfs_wait_ordered_extents(), walk
fs_info->ordered_roots in place instead of splicing it onto a private list,
so the roots with pending ordered extents stay visible while we wait.

No functional change intended.

Signed-off-by: Johannes Thumshirn <[email protected]>
---
 fs/btrfs/ordered-data.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c
index 11aa7e8efe04..ddd21aa5c640 100644
--- a/fs/btrfs/ordered-data.c
+++ b/fs/btrfs/ordered-data.c
@@ -836,19 +836,22 @@ void btrfs_wait_ordered_roots(struct btrfs_fs_info *fs_info, u64 nr,
 			      const struct btrfs_block_group *bg)
 {
 	struct btrfs_root *root;
-	LIST_HEAD(splice);
 	u64 done;
+	u64 remaining;
 
 	mutex_lock(&fs_info->ordered_operations_mutex);
 	spin_lock(&fs_info->ordered_root_lock);
-	list_splice_init(&fs_info->ordered_roots, &splice);
-	while (!list_empty(&splice) && nr) {
-		root = list_first_entry(&splice, struct btrfs_root,
-					ordered_root);
+	remaining = 0;
+	list_for_each_entry(root, &fs_info->ordered_roots, ordered_root)
+		remaining++;
+	while (remaining && nr && !list_empty(&fs_info->ordered_roots)) {
+		remaining--;
+		root = list_first_entry(&fs_info->ordered_roots,
+					struct btrfs_root, ordered_root);
+		list_move_tail(&root->ordered_root, &fs_info->ordered_roots);
 		root = btrfs_grab_root(root);
-		BUG_ON(!root);
-		list_move_tail(&root->ordered_root,
-			       &fs_info->ordered_roots);
+		if (!root)
+			continue;
 		spin_unlock(&fs_info->ordered_root_lock);
 
 		done = btrfs_wait_ordered_extents(root, nr, bg);
@@ -859,7 +862,6 @@ void btrfs_wait_ordered_roots(struct btrfs_fs_info *fs_info, u64 nr,
 
 		spin_lock(&fs_info->ordered_root_lock);
 	}
-	list_splice_tail(&splice, &fs_info->ordered_roots);
 	spin_unlock(&fs_info->ordered_root_lock);
 	mutex_unlock(&fs_info->ordered_operations_mutex);
 }
-- 
2.54.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.