From: Luis Chamberlain <mcgrof@kernel.org>
To: linux-xfs@vger.kernel.org, gregkh@linuxfoundation.org,
Alexander.Levin@microsoft.com
Cc: amir73il@gmail.com, hch@infradead.org,
Brian Foster <bfoster@redhat.com>,
"Darrick J . Wong" <darrick.wong@oracle.com>,
Luis Chamberlain <mcgrof@kernel.org>
Subject: [PATCH 05/10] xfs: fix shared extent data corruption due to missing cow reservation
Date: Thu, 31 Jan 2019 10:09:14 -0800 [thread overview]
Message-ID: <20190131180919.2500-6-mcgrof@kernel.org> (raw)
In-Reply-To: <20190131180919.2500-1-mcgrof@kernel.org>
From: Brian Foster <bfoster@redhat.com>
Page writeback indirectly handles shared extents via the existence
of overlapping COW fork blocks. If COW fork blocks exist, writeback
always performs the associated copy-on-write regardless if the
underlying blocks are actually shared. If the blocks are shared,
then overlapping COW fork blocks must always exist.
fstests shared/010 reproduces a case where a buffered write occurs
over a shared block without performing the requisite COW fork
reservation. This ultimately causes writeback to the shared extent
and data corruption that is detected across md5 checks of the
filesystem across a mount cycle.
The problem occurs when a buffered write lands over a shared extent
that crosses an extent size hint boundary and that also happens to
have a partial COW reservation that doesn't cover the start and end
blocks of the data fork extent.
For example, a buffered write occurs across the file offset (in FSB
units) range of [29, 57]. A shared extent exists at blocks [29, 35]
and COW reservation already exists at blocks [32, 34]. After
accommodating a COW extent size hint of 32 blocks and the existing
reservation at offset 32, xfs_reflink_reserve_cow() allocates 32
blocks of reservation at offset 0 and returns with COW reservation
across the range of [0, 34]. The associated data fork extent is
still [29, 35], however, which isn't fully covered by the COW
reservation.
This leads to a buffered write at file offset 35 over a shared
extent without associated COW reservation. Writeback eventually
kicks in, performs an overwrite of the underlying shared block and
causes the associated data corruption.
Update xfs_reflink_reserve_cow() to accommodate the fact that a
delalloc allocation request may not fully cover the extent in the
data fork. Trim the data fork extent appropriately, just as is done
for shared extent boundaries and/or existing COW reservations that
happen to overlap the start of the data fork extent. This prevents
shared/010 failures due to data corruption on reflink enabled
filesystems.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Luis Chamberlain <mcgrof@kernel.org>
---
fs/xfs/xfs_reflink.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index 42ea7bab9144..7088f44c0c59 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -302,6 +302,7 @@ xfs_reflink_reserve_cow(
if (error)
return error;
+ xfs_trim_extent(imap, got.br_startoff, got.br_blockcount);
trace_xfs_reflink_cow_alloc(ip, &got);
return 0;
}
--
2.18.0
next prev parent reply other threads:[~2019-01-31 18:09 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-31 18:09 [PATCH 00/10] xfs: stable fixes for v4.19.y Luis Chamberlain
2019-01-31 18:09 ` [PATCH 01/10] xfs: Fix xqmstats offsets in /proc/fs/xfs/xqmstat Luis Chamberlain
2019-01-31 18:19 ` Greg KH
2019-01-31 18:26 ` Luis Chamberlain
2019-01-31 18:09 ` [PATCH 02/10] xfs: cancel COW blocks before swapext Luis Chamberlain
2019-01-31 18:09 ` [PATCH 03/10] xfs: Fix error code in 'xfs_ioc_getbmap()' Luis Chamberlain
2019-01-31 18:09 ` [PATCH 04/10] xfs: fix overflow in xfs_attr3_leaf_verify Luis Chamberlain
2019-01-31 18:09 ` Luis Chamberlain [this message]
2019-01-31 18:09 ` [PATCH 06/10] xfs: fix transient reference count error in xfs_buf_resubmit_failed_buffers Luis Chamberlain
2019-01-31 18:09 ` [PATCH 07/10] xfs: delalloc -> unwritten COW fork allocation can go wrong Luis Chamberlain
2019-01-31 18:09 ` [PATCH 08/10] fs/xfs: fix f_ffree value for statfs when project quota is set Luis Chamberlain
2019-01-31 18:09 ` [PATCH 09/10] xfs: fix PAGE_MASK usage in xfs_free_file_space Luis Chamberlain
2019-01-31 18:09 ` [PATCH 10/10] xfs: fix inverted return from xfs_btree_sblock_verify_crc Luis Chamberlain
2019-01-31 18:20 ` [PATCH 00/10] xfs: stable fixes for v4.19.y Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190131180919.2500-6-mcgrof@kernel.org \
--to=mcgrof@kernel.org \
--cc=Alexander.Levin@microsoft.com \
--cc=amir73il@gmail.com \
--cc=bfoster@redhat.com \
--cc=darrick.wong@oracle.com \
--cc=gregkh@linuxfoundation.org \
--cc=hch@infradead.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).