summaryrefslogtreecommitdiffstats
path: root/fs/xfs/libxfs/xfs_bmap.c
diff options
context:
space:
mode:
authorBrian Foster2019-02-01 18:14:23 +0100
committerDarrick J. Wong2019-02-12 01:07:01 +0100
commit627209fbcc2f0d658a5417645859a1d3053ddb59 (patch)
tree64c10bff55a217b3d5882326670fc7ad31edcb99 /fs/xfs/libxfs/xfs_bmap.c
parentxfs: remove superfluous writeback mapping eof trimming (diff)
downloadkernel-qcow2-linux-627209fbcc2f0d658a5417645859a1d3053ddb59.tar.gz
kernel-qcow2-linux-627209fbcc2f0d658a5417645859a1d3053ddb59.tar.xz
kernel-qcow2-linux-627209fbcc2f0d658a5417645859a1d3053ddb59.zip
xfs: create delalloc bmapi wrapper for full extent allocation
The writeback delalloc conversion code is racy with respect to changes in the currently cached file mapping. This stems from the fact that the bmapi allocation code requires a file range to allocate and the writeback conversion code assumes the range of the currently cached mapping is still valid with respect to the fork. It may not be valid, however, because the ilock is cycled (potentially multiple times) between the time the cached mapping was populated and the delalloc conversion occurs. To facilitate a solution to this problem, create a new xfs_bmapi_delalloc() wrapper to xfs_bmapi_write() that takes a file (FSB) offset and attempts to allocate whatever delalloc extent backs the offset. Use a new bmapi flag to cause xfs_bmapi_write() to set the range based on the extent backing the bno parameter unless bno lands in a hole. If bno does land in a hole, fall back to the current behavior (which may result in an error or quietly skipping holes in the specified range depending on other parameters). This patch does not change behavior. 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>
Diffstat (limited to 'fs/xfs/libxfs/xfs_bmap.c')
-rw-r--r--fs/xfs/libxfs/xfs_bmap.c59
1 files changed, 55 insertions, 4 deletions
diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
index 4c73927819c2..c629004d9a4c 100644
--- a/fs/xfs/libxfs/xfs_bmap.c
+++ b/fs/xfs/libxfs/xfs_bmap.c
@@ -4286,10 +4286,6 @@ xfs_bmapi_write(
goto error0;
}
- n = 0;
- end = bno + len;
- obno = bno;
-
if (!xfs_iext_lookup_extent(ip, ifp, bno, &bma.icur, &bma.got))
eof = true;
if (!xfs_iext_peek_prev_extent(ifp, &bma.icur, &bma.prev))
@@ -4299,6 +4295,26 @@ xfs_bmapi_write(
bma.total = total;
bma.datatype = 0;
+ /*
+ * The reval flag means the caller wants to allocate the entire delalloc
+ * extent backing bno where bno may not necessarily match the startoff.
+ * Now that we've looked up the extent, reset the range to map based on
+ * the extent in the file. If we're in a hole, this may be an error so
+ * don't adjust anything.
+ */
+ if ((flags & XFS_BMAPI_REVALRANGE) &&
+ !eof && bno >= bma.got.br_startoff) {
+ ASSERT(flags & XFS_BMAPI_DELALLOC);
+ bno = bma.got.br_startoff;
+ len = bma.got.br_blockcount;
+#ifdef DEBUG
+ orig_bno = bno;
+ orig_len = len;
+#endif
+ }
+ n = 0;
+ end = bno + len;
+ obno = bno;
while (bno < end && n < *nmap) {
bool need_alloc = false, wasdelay = false;
@@ -4455,6 +4471,41 @@ error0:
return error;
}
+/*
+ * Convert an existing delalloc extent to real blocks based on file offset. This
+ * attempts to allocate the entire delalloc extent and may require multiple
+ * invocations to allocate the target offset if a large enough physical extent
+ * is not available.
+ */
+int
+xfs_bmapi_convert_delalloc(
+ struct xfs_trans *tp,
+ struct xfs_inode *ip,
+ xfs_fileoff_t offset_fsb,
+ int whichfork,
+ struct xfs_bmbt_irec *imap)
+{
+ int flags = XFS_BMAPI_DELALLOC;
+ int nimaps = 1;
+ int error;
+ int total = XFS_EXTENTADD_SPACE_RES(ip->i_mount,
+ XFS_DATA_FORK);
+
+ if (whichfork == XFS_COW_FORK)
+ flags |= XFS_BMAPI_COWFORK | XFS_BMAPI_PREALLOC;
+
+ /*
+ * The reval flag means to allocate the entire extent; pass a dummy
+ * length of 1.
+ */
+ flags |= XFS_BMAPI_REVALRANGE;
+ error = xfs_bmapi_write(tp, ip, offset_fsb, 1, flags, total, imap,
+ &nimaps);
+ if (!error && !nimaps)
+ error = -EFSCORRUPTED;
+ return error;
+}
+
int
xfs_bmapi_remap(
struct xfs_trans *tp,