]> git.hungrycats.org Git - linux/commit
Btrfs: fix data corruption after fast fsync and writeback error
authorFilipe Manana <fdmanana@suse.com>
Fri, 5 Sep 2014 14:14:39 +0000 (15:14 +0100)
committerZygo Blaxell <zblaxell@serenity.furryterror.org>
Wed, 3 Dec 2014 15:15:51 +0000 (10:15 -0500)
commite59430c8bf4aeef800db3f2f3ec4704e86c9393c
treea26217a35f90a9cfb2f30d7a45c6f2dcf3c71f7a
parentf0796a026654a2217730b81086ecaf99d641c91c
Btrfs: fix data corruption after fast fsync and writeback error

When we do a fast fsync, we start all ordered operations and then while
they're running in parallel we visit the list of modified extent maps
and construct their matching file extent items and write them to the
log btree. After that, in btrfs_sync_log() we wait for all the ordered
operations to finish (via btrfs_wait_logged_extents).

The problem with this is that we were completely ignoring errors that
can happen in the extent write path, such as -ENOSPC, a temporary -ENOMEM
or -EIO errors for example. When such error happens, it means we have parts
of the on disk extent that weren't written to, and so we end up logging
file extent items that point to these extents that contain garbage/random
data - so after a crash/reboot plus log replay, we get our inode's metadata
pointing to those extents.

This worked in contrast with the full (non-fast) fsync path, where we
start all ordered operations, wait for them to finish and then write
to the log btree. In this path, after each ordered operation completes
we check if it's flagged with an error (BTRFS_ORDERED_IOERR) and return
-EIO if so (via btrfs_wait_ordered_range).

So if an error happens with any ordered operation, just return a -EIO
error to userspace, so that it knows that not all of its previous writes
were durably persisted and the application can take proper action (like
redo the writes for e.g.) - and definitely not leave any file extent items
in the log refer to non fully written extents.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
(cherry picked from commit 8407f553268a4611f2542ed90677f0edfaa2c9c4)
fs/btrfs/file.c
fs/btrfs/tree-log.c
fs/btrfs/tree-log.h