@@ -1491,6 +1491,12 @@ __xfs_get_blocks(
if (imap.br_startblock != HOLESTARTBLOCK &&
imap.br_startblock != DELAYSTARTBLOCK &&
(create || !ISUNWRITTEN(&imap))) {
+ if (create && direct) {
+ error = xfs_reflink_redirect_directio_write(ip, &imap,
+ offset);
+ if (error)
+ return error;
+ }
xfs_map_buffer(inode, bh_result, &imap, offset);
if (ISUNWRITTEN(&imap))
set_buffer_unwritten(bh_result);
@@ -876,10 +876,18 @@ xfs_file_write_iter(
if (XFS_FORCED_SHUTDOWN(ip->i_mount))
return -EIO;
- if ((iocb->ki_flags & IOCB_DIRECT) || IS_DAX(inode))
+ /*
+ * Allow DIO to fall back to buffered *only* in the case that we're
+ * doing a reflink CoW.
+ */
+ if ((iocb->ki_flags & IOCB_DIRECT) || IS_DAX(inode)) {
ret = xfs_file_dio_aio_write(iocb, from);
- else
+ if (ret == -EREMCHG)
+ goto buffered;
+ } else {
+buffered:
ret = xfs_file_buffered_aio_write(iocb, from);
+ }
if (ret > 0) {
ssize_t err;
@@ -407,6 +407,40 @@ advloop:
}
/**
+ * xfs_reflink_redirect_directio_write() - bounce a directio write to a
+ * reflinked region down to buffered
+ * write mode.
+ *
+ * @ip: XFS inode object
+ * @imap: the fileoff:fsblock mapping that we might fork
+ * @offset: the file byte offset of the block we're examining
+ */
+int
+xfs_reflink_redirect_directio_write(
+ struct xfs_inode *ip,
+ struct xfs_bmbt_irec *imap,
+ xfs_off_t offset)
+{
+ bool type = false;
+ int error;
+
+ error = xfs_reflink_should_fork_block(ip, imap, offset, &type);
+ if (error)
+ return error;
+ if (!type)
+ return 0;
+
+ /*
+ * Are we doing a DIO write to a reflinked block? In the ideal world
+ * we at least would fork full blocks, but for now just fall back to
+ * buffered mode. Yuck. Use -EREMCHG ("remote address changed") to
+ * signal this, since in general XFS doesn't do this sort of fallback.
+ */
+ trace_xfs_reflink_bounce_direct_write(ip, imap);
+ return -EREMCHG;
+}
+
+/**
* xfs_reflink_write_fork_block() -- find a remapping object and redirect the
* write.
*
We hope that CoW writes will be rare and that directio CoW writes will be even more rare. Therefore, fall-back any such write to the buffered path. Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com> --- fs/xfs/xfs_aops.c | 6 ++++++ fs/xfs/xfs_file.c | 12 ++++++++++-- fs/xfs/xfs_reflink.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html