From: Shiyang Ruan <ruansy.fnst@cn.fujitsu.com>
To: linux-xfs@vger.kernel.org, linux-nvdimm@lists.01.org,
darrick.wong@oracle.com
Cc: qi.fuli@fujitsu.com, gujx@cn.fujitsu.com, rgoldwyn@suse.de,
david@fromorbit.com, linux-kernel@vger.kernel.org
Subject: [RFC PATCH 6/7] xfs: Add COW handle for fsdax.
Date: Wed, 31 Jul 2019 19:49:34 +0800 [thread overview]
Message-ID: <20190731114935.11030-7-ruansy.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <20190731114935.11030-1-ruansy.fnst@cn.fujitsu.com>
WRITE and ZERO on a shared extent need to perform COW. For direct io in
dax mode, it is handled like WRITE, but with block aligned. So COW
seems a bit redundant for it.
Because of COW, new extent has been allocated. The extent list needs to
be updated at the end.
Signed-off-by: Shiyang Ruan <ruansy.fnst@cn.fujitsu.com>
---
fs/xfs/xfs_iomap.c | 42 +++++++++++++++++++++++++-----------------
fs/xfs/xfs_reflink.c | 1 +
2 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 6116a75f03da..ae3b9bf5d784 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -930,10 +930,10 @@ xfs_file_iomap_begin(
{
struct xfs_inode *ip = XFS_I(inode);
struct xfs_mount *mp = ip->i_mount;
- struct xfs_bmbt_irec imap;
+ struct xfs_bmbt_irec imap = { 0 }, cmap = { 0 };
xfs_fileoff_t offset_fsb, end_fsb;
int nimaps = 1, error = 0;
- bool shared = false;
+ bool shared = false, need_cow = false;
unsigned lockmode;
if (XFS_FORCED_SHUTDOWN(mp))
@@ -967,6 +967,8 @@ xfs_file_iomap_begin(
if (error)
goto out_unlock;
+ cmap = imap;
+
if (flags & IOMAP_REPORT) {
/* Trim the mapping to the nearest shared extent boundary. */
error = xfs_reflink_trim_around_shared(ip, &imap, &shared);
@@ -983,8 +985,7 @@ xfs_file_iomap_begin(
* been done up front, so we don't need to do them here.
*/
if (xfs_is_cow_inode(ip)) {
- struct xfs_bmbt_irec cmap;
- bool directio = (flags & IOMAP_DIRECT);
+ bool directio = flags & IOMAP_DIRECT;
/* if zeroing doesn't need COW allocation, then we are done. */
if ((flags & IOMAP_ZERO) &&
@@ -992,23 +993,21 @@ xfs_file_iomap_begin(
goto out_found;
/* may drop and re-acquire the ilock */
- cmap = imap;
error = xfs_reflink_allocate_cow(ip, &cmap, &shared, &lockmode,
- directio);
+ directio || IS_DAX(inode));
if (error)
goto out_unlock;
/*
- * For buffered writes we need to report the address of the
- * previous block (if there was any) so that the higher level
- * write code can perform read-modify-write operations; we
- * won't need the CoW fork mapping until writeback. For direct
- * I/O, which must be block aligned, we need to report the
- * newly allocated address. If the data fork has a hole, copy
- * the COW fork mapping to avoid allocating to the data fork.
+ * WRITE and ZERO on a shared extent under dax mode need to
+ * perform COW, source address will be reported in srcmap.
*/
- if (directio || imap.br_startblock == HOLESTARTBLOCK)
+ if (imap.br_startblock != HOLESTARTBLOCK && IS_DAX(inode) &&
+ shared) {
+ need_cow = true;
+ } else {
imap = cmap;
+ }
end_fsb = imap.br_startoff + imap.br_blockcount;
length = XFS_FSB_TO_B(mp, end_fsb) - offset;
@@ -1044,8 +1043,7 @@ xfs_file_iomap_begin(
*/
if (lockmode == XFS_ILOCK_EXCL)
xfs_ilock_demote(ip, lockmode);
- error = xfs_iomap_write_direct(ip, offset, length, &imap,
- nimaps);
+ error = xfs_iomap_write_direct(ip, offset, length, &imap, nimaps);
if (error)
return error;
@@ -1053,7 +1051,15 @@ xfs_file_iomap_begin(
trace_xfs_iomap_alloc(ip, offset, length, XFS_DATA_FORK, &imap);
out_finish:
- return xfs_bmbt_to_iomap(ip, iomap, &imap, shared);
+ if (need_cow) {
+ error = xfs_bmbt_to_iomap(ip, iomap, &cmap, shared);
+ if (error)
+ return error;
+ iomap->flags |= IOMAP_F_NEW;
+ iomap->type = IOMAP_COW;
+ return xfs_bmbt_to_iomap(ip, srcmap, &imap, shared);
+ } else
+ return xfs_bmbt_to_iomap(ip, iomap, &imap, shared);
out_found:
ASSERT(nimaps);
@@ -1135,6 +1141,8 @@ xfs_file_iomap_end(
if ((flags & IOMAP_WRITE) && iomap->type == IOMAP_DELALLOC)
return xfs_file_iomap_end_delalloc(XFS_I(inode), offset,
length, written, iomap);
+ else if (iomap->type == IOMAP_COW && written)
+ return xfs_reflink_end_cow(XFS_I(inode), offset, length);
return 0;
}
diff --git a/fs/xfs/xfs_reflink.c b/fs/xfs/xfs_reflink.c
index 68e4257cebb0..a1b000be3699 100644
--- a/fs/xfs/xfs_reflink.c
+++ b/fs/xfs/xfs_reflink.c
@@ -446,6 +446,7 @@ xfs_reflink_allocate_cow(
*/
if (!convert_now || imap->br_state == XFS_EXT_NORM)
return 0;
+ imap->br_state = XFS_EXT_NORM;
trace_xfs_reflink_convert_cow(ip, imap);
return xfs_reflink_convert_cow_locked(ip, offset_fsb, count_fsb);
--
2.17.0
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm
next prev parent reply other threads:[~2019-07-31 11:52 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-31 11:49 [RFC PATCH 0/7] xfs: add reflink & dedupe support for fsdax Shiyang Ruan
2019-07-31 11:49 ` [RFC PATCH 1/7] dax: Introduce dax_copy_edges() for COW Shiyang Ruan
2019-07-31 11:49 ` [RFC PATCH 2/7] dax: copy data before write Shiyang Ruan
2019-07-31 11:49 ` [RFC PATCH 3/7] dax: replace mmap entry in case of CoW Shiyang Ruan
2019-07-31 11:49 ` [RFC PATCH 4/7] fs: dedup file range to use a compare function Shiyang Ruan
2019-07-31 11:49 ` [RFC PATCH 5/7] dax: memcpy before zeroing range Shiyang Ruan
2019-07-31 11:49 ` Shiyang Ruan [this message]
2019-07-31 11:49 ` [RFC PATCH 7/7] xfs: Add dedupe support for fsdax Shiyang Ruan
2019-07-31 20:33 ` [RFC PATCH 0/7] xfs: add reflink & " Goldwyn Rodrigues
2019-08-01 1:37 ` Shiyang Ruan
2019-08-05 0:21 ` Dave Chinner
2019-10-09 6:31 ` Christoph Hellwig
2019-10-09 17:11 ` Darrick J. Wong
2019-10-10 7:30 ` Dave Chinner
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=20190731114935.11030-7-ruansy.fnst@cn.fujitsu.com \
--to=ruansy.fnst@cn.fujitsu.com \
--cc=darrick.wong@oracle.com \
--cc=david@fromorbit.com \
--cc=gujx@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvdimm@lists.01.org \
--cc=linux-xfs@vger.kernel.org \
--cc=qi.fuli@fujitsu.com \
--cc=rgoldwyn@suse.de \
/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).