OSDN Git Service

btrfs: fix error handling in commit_fs_roots
authorJosef Bacik <josef@toxicpanda.com>
Tue, 1 Dec 2020 14:53:23 +0000 (09:53 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 7 Mar 2021 11:18:59 +0000 (12:18 +0100)
commitc9ad913622cc0d9d5f3254a8ad7625707847f3b4
treec63d64fb6440bb4b921ebbe34408c2dfd05bba42
parent7bfc5a344ad0afd4b0601a1ee0e7d037d6c92569
btrfs: fix error handling in commit_fs_roots

[ Upstream commit 4f4317c13a40194940acf4a71670179c4faca2b5 ]

While doing error injection I would sometimes get a corrupt file system.
This is because I was injecting errors at btrfs_search_slot, but would
only do it one time per stack.  This uncovered a problem in
commit_fs_roots, where if we get an error we would just break.  However
we're in a nested loop, the first loop being a loop to find all the
dirty fs roots, and then subsequent root updates would succeed clearing
the error value.

This isn't likely to happen in real scenarios, however we could
potentially get a random ENOMEM once and then not again, and we'd end up
with a corrupted file system.  Fix this by moving the error checking
around a bit to the main loop, as this is the only place where something
will fail, and return the error as soon as it occurs.

With this patch my reproducer no longer corrupts the file system.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/transaction.c