diff mbox series

[5/7] btrfs: drop root refs properly when orphan cleanup fails

Message ID b9dd48e9449bc86abe3d05d3edde41636dd61106.1675787102.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series Error handling fixes | expand

Commit Message

Josef Bacik Feb. 7, 2023, 4:57 p.m. UTC
When we mount the file system we do something like this

while (1) {
	lookup fs roots;

	for (i = 0; i < num_roots; i++) {
		ret = btrfs_orphan_cleanup(roots[i]);
		if (ret)
			break;
		btrfs_put_root(roots[i]);
	}
}

for (; i < num_roots; i++)
	btrfs_put_root(roots[i]);

As you can see if we break in that inner loop we just go back to the
outer loop and lose the fact that we have to drop references on the
remaining roots we looked up.  Fix this by making an out label and
jumping to that on error so we don't leak a reference to the roots we
looked up.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/disk-io.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Johannes Thumshirn Feb. 8, 2023, 9:42 a.m. UTC | #1
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
diff mbox series

Patch

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index b9a02163a891..c828bd987c23 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -4380,12 +4380,12 @@  int btrfs_cleanup_fs_roots(struct btrfs_fs_info *fs_info)
 			root_objectid = gang[i]->root_key.objectid;
 			err = btrfs_orphan_cleanup(gang[i]);
 			if (err)
-				break;
+				goto out;
 			btrfs_put_root(gang[i]);
 		}
 		root_objectid++;
 	}
-
+out:
 	/* release the uncleaned roots due to error */
 	for (; i < ret; i++) {
 		if (gang[i])