Skip to contentSkip to conversation

Btrfs: fix possible infinite loop in slow caching

PATCH New Josef Bacik 1 participant 1 message Apr 22, 2013 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: fix possible infinite loop in slow caching

So I noticed there is an infinite loop in the slow caching code. If we return 1 when we hit the end of the tree, so we could end up caching the last block group the slow way and suddenly we're looping forever because we just keep re-searching and trying again. Fix this by only doing btrfs_next_leaf() if we don't need_resched(). Thanks,

---
 fs/btrfs/extent-tree.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
fs/btrfs/extent-tree.c +7 -2
index 12c32f9..b441be3 100644
@@ -419,8 +419,7 @@ again:
 			if (ret)
 				break;
 
-			if (need_resched() ||
-			    btrfs_next_leaf(extent_root, path)) {
+			if (need_resched()) {
 				caching_ctl->progress = last;
 				btrfs_release_path(path);
 				up_read(&fs_info->extent_commit_sem);
@@ -428,6 +427,12 @@ again:
 				cond_resched();
 				goto again;
 			}
+
+			ret = btrfs_next_leaf(extent_root, path);
+			if (ret < 0)
+				goto err;
+			if (ret)
+				break;
 			leaf = path->nodes[0];
 			nritems = btrfs_header_nritems(leaf);
 			continue;
Signature · 1 line
1.7.7.6