* [RFC PATCH 0/4] xfs: add handle for reflink in dax
@ 2019-04-17 1:27 Shiyang Ruan
2019-04-17 1:27 ` [RFC PATCH 1/4] fs/iomap: Introduce src_addr for COW in fsdax mode Shiyang Ruan
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Shiyang Ruan @ 2019-04-17 1:27 UTC (permalink / raw)
To: linux-xfs, linux-nvdimm
In XFS (under fsdax mode), reflink did not work correctly because xfs
iomap operators did not handle the inode with both reflink and dax flag.
This patchset aims to take care of this issue to make COW operation work
correctly in XFS.
XFS uses iomap to do read/write/mmap operations:
vfs interface xfs:
iomap_bengin(); --> xfs_iomap_begin();
actor(); --> dax_iomap_actor() / mmap actor function
iomap_end(); --> xfs_iomap_end();
In xfs_iomap_begin(), COW operation is detected but not told to actor
function. To resolve this, a new field 'src_addr' is added into
'struct iomap' to pass this COW info. It means the start address of
source blocks in a COW operation, for actor functions to copy data
before writing.
In actor functions, the value of iomap->src_addr determines if it is a
COW operation. If it is, copy data from source blocks to destination
blocks first, and then write user data.
After the COW operation, it is supposed to update the metadata of the
inode. Added in xfs_iomap_end().
Shiyang Ruan (4):
fs/iomap: Introduce src_addr for COW in fsdax mode.
fs/xfs: iomap: add handle for reflink in fsdax mode
fs/dax: copy source blocks before writing when COW
fs/xfs: iomap: update the extent list after a COW
fs/dax.c | 70 +++++++++++++++++++++++++++++++++++++++++++
fs/xfs/xfs_iomap.c | 23 +++++++++++---
include/linux/iomap.h | 4 +++
3 files changed, 93 insertions(+), 4 deletions(-)
--
2.17.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC PATCH 1/4] fs/iomap: Introduce src_addr for COW in fsdax mode.
2019-04-17 1:27 [RFC PATCH 0/4] xfs: add handle for reflink in dax Shiyang Ruan
@ 2019-04-17 1:27 ` Shiyang Ruan
2019-04-17 1:27 ` [RFC PATCH 2/4] fs/xfs: iomap: add handle for reflink " Shiyang Ruan
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Shiyang Ruan @ 2019-04-17 1:27 UTC (permalink / raw)
To: linux-xfs, linux-nvdimm
When using reflink, coping the source blocks before writing data
into new allocated blocks is required. In fsdax mode, we need a source
blocks' start address to handle the COW operation.
Signed-off-by: Shiyang Ruan <ruansy.fnst@cn.fujitsu.com>
---
include/linux/iomap.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/include/linux/iomap.h b/include/linux/iomap.h
index 0fefb5455bda..3b3aec2311c5 100644
--- a/include/linux/iomap.h
+++ b/include/linux/iomap.h
@@ -61,6 +61,10 @@ struct iomap {
u16 flags; /* flags for mapping */
struct block_device *bdev; /* block device for I/O */
struct dax_device *dax_dev; /* dax_dev for dax operations */
+ u64 src_addr; /* disk offset of mapping, bytes,
+ * the source blocks' start address
+ * for cow in dax
+ */
void *inline_data;
void *private; /* filesystem private */
--
2.17.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH 2/4] fs/xfs: iomap: add handle for reflink in fsdax mode
2019-04-17 1:27 [RFC PATCH 0/4] xfs: add handle for reflink in dax Shiyang Ruan
2019-04-17 1:27 ` [RFC PATCH 1/4] fs/iomap: Introduce src_addr for COW in fsdax mode Shiyang Ruan
@ 2019-04-17 1:27 ` Shiyang Ruan
2019-04-17 1:27 ` [RFC PATCH 3/4] fs/dax: copy source blocks before writing when COW Shiyang Ruan
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Shiyang Ruan @ 2019-04-17 1:27 UTC (permalink / raw)
To: linux-xfs, linux-nvdimm
xfs_file_iomap_begin() is supposed to allocate new extents for reflinked
inode and pass the source blocks' start address to the actor functions.
Signed-off-by: Shiyang Ruan <ruansy.fnst@cn.fujitsu.com>
---
fs/xfs/xfs_iomap.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index 63d323916bba..a45b4e5a1d87 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -255,7 +255,11 @@ xfs_iomap_write_direct(
* left but we need to do unwritten extent conversion.
*/
if (IS_DAX(VFS_I(ip))) {
- bmapi_flags = XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO;
+ if (xfs_is_cow_inode(ip))
+ /* we need to allocate new extents for reflink */
+ bmapi_flags = XFS_BMAPI_COWFORK;
+ else
+ bmapi_flags = XFS_BMAPI_CONVERT | XFS_BMAPI_ZERO;
if (imap->br_state == XFS_EXT_UNWRITTEN) {
tflags |= XFS_TRANS_RESERVE;
resblks = XFS_DIOSTRAT_SPACE_RES(mp, 0) << 1;
@@ -983,7 +987,8 @@ xfs_file_iomap_begin(
*/
if (xfs_is_cow_inode(ip)) {
struct xfs_bmbt_irec cmap;
- bool directio = (flags & IOMAP_DIRECT);
+ bool convert = (flags & IOMAP_DIRECT)
+ || IS_DAX(inode);
/* if zeroing doesn't need COW allocation, then we are done. */
if ((flags & IOMAP_ZERO) &&
@@ -993,10 +998,16 @@ xfs_file_iomap_begin(
/* may drop and re-acquire the ilock */
cmap = imap;
error = xfs_reflink_allocate_cow(ip, &cmap, &shared, &lockmode,
- directio);
+ convert);
if (error)
goto out_unlock;
+ if (shared && IS_DAX(inode)) {
+ /* get source address and pass it to actor functions */
+ iomap->src_addr = BBTOB(xfs_fsb_to_db(ip,
+ imap.br_startblock));
+ }
+
/*
* For buffered writes we need to report the address of the
* previous block (if there was any) so that the higher level
@@ -1005,8 +1016,9 @@ xfs_file_iomap_begin(
* 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.
+ * If is DAX, we need to allocate new address.
*/
- if (directio || imap.br_startblock == HOLESTARTBLOCK)
+ if (convert || imap.br_startblock == HOLESTARTBLOCK)
imap = cmap;
end_fsb = imap.br_startoff + imap.br_blockcount;
--
2.17.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH 3/4] fs/dax: copy source blocks before writing when COW
2019-04-17 1:27 [RFC PATCH 0/4] xfs: add handle for reflink in dax Shiyang Ruan
2019-04-17 1:27 ` [RFC PATCH 1/4] fs/iomap: Introduce src_addr for COW in fsdax mode Shiyang Ruan
2019-04-17 1:27 ` [RFC PATCH 2/4] fs/xfs: iomap: add handle for reflink " Shiyang Ruan
@ 2019-04-17 1:27 ` Shiyang Ruan
2019-04-17 1:27 ` [RFC PATCH 4/4] fs/xfs: iomap: update the extent list after a COW Shiyang Ruan
2019-04-17 1:34 ` [RFC PATCH 0/4] xfs: add handle for reflink in dax Darrick J. Wong
4 siblings, 0 replies; 7+ messages in thread
From: Shiyang Ruan @ 2019-04-17 1:27 UTC (permalink / raw)
To: linux-xfs, linux-nvdimm
The actor functions get the source blocks' start address from
iomap->src_addr, and then copy these blocks to the new allocated
blocks before writing the user data.
Signed-off-by: Shiyang Ruan <ruansy.fnst@cn.fujitsu.com>
cc: linux-nvdimm@lists.01.org
---
fs/dax.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/fs/dax.c b/fs/dax.c
index ca0671d55aa6..28519bdecf7c 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -982,6 +982,11 @@ static sector_t dax_iomap_sector(struct iomap *iomap, loff_t pos)
return (iomap->addr + (pos & PAGE_MASK) - iomap->offset) >> 9;
}
+static sector_t dax_iomap_src_sector(struct iomap *iomap, loff_t pos)
+{
+ return (iomap->src_addr + (pos & PAGE_MASK) - iomap->offset) >> 9;
+}
+
static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size,
pfn_t *pfnp)
{
@@ -1014,6 +1019,51 @@ static int dax_iomap_pfn(struct iomap *iomap, loff_t pos, size_t size,
return rc;
}
+static int dax_iomap_addr(struct iomap *iomap, sector_t sector, size_t size,
+ void **kaddr)
+{
+ pgoff_t pgoff;
+ int id, rc;
+ long length;
+
+ rc = bdev_dax_pgoff(iomap->bdev, sector, size, &pgoff);
+ if (rc)
+ return rc;
+
+ id = dax_read_lock();
+ length = dax_direct_access(iomap->dax_dev, pgoff, PHYS_PFN(size),
+ kaddr, NULL);
+ if (length < 0)
+ rc = length;
+ if (!*kaddr)
+ rc = -EFAULT;
+
+ dax_read_unlock(id);
+ return rc;
+}
+
+static int dax_iomap_cow_copy(struct iomap *iomap, loff_t pos, size_t size)
+{
+ void *kaddr = 0, *src_kaddr = 0;
+ int error = 0;
+ const sector_t src_sector = dax_iomap_src_sector(iomap, pos);
+ const sector_t sector = dax_iomap_sector(iomap, pos);
+
+ error = dax_iomap_addr(iomap, src_sector, size, &src_kaddr);
+ if (error < 0)
+ return error;
+ error = dax_iomap_addr(iomap, sector, size, &kaddr);
+ if (error < 0)
+ return error;
+
+ /*
+ * Copy data from source blocks to the new allocated blocks before
+ * writing user data.
+ */
+ memcpy(kaddr, src_kaddr, size);
+ return 0;
+}
+
/*
* The user has performed a load from a hole in the file. Allocating a new
* page in the file would cause excessive storage usage for workloads with
@@ -1149,6 +1199,12 @@ dax_iomap_actor(struct inode *inode, loff_t pos, loff_t length, void *data,
if (map_len > end - pos)
map_len = end - pos;
+ if (iomap->src_addr) {
+ ret = dax_iomap_cow_copy(iomap, pos, size);
+ if (ret < 0)
+ break;
+ }
+
/*
* The userspace address for the memory copy has already been
* validated via access_ok() in either vfs_read() or
@@ -1336,6 +1392,7 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,
count_memcg_event_mm(vma->vm_mm, PGMAJFAULT);
major = VM_FAULT_MAJOR;
}
+
error = dax_iomap_pfn(&iomap, pos, PAGE_SIZE, &pfn);
if (error < 0)
goto error_finish_iomap;
@@ -1358,6 +1415,13 @@ static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,
ret = VM_FAULT_NEEDDSYNC | major;
goto finish_iomap;
}
+
+ if (iomap.src_addr) {
+ error = dax_iomap_cow_copy(&iomap, pos, PAGE_SIZE);
+ if (error < 0)
+ goto error_finish_iomap;
+ }
+
trace_dax_insert_mapping(inode, vmf, entry);
if (write)
ret = vmf_insert_mixed_mkwrite(vma, vaddr, pfn);
@@ -1559,6 +1623,12 @@ static vm_fault_t dax_iomap_pmd_fault(struct vm_fault *vmf, pfn_t *pfnp,
goto finish_iomap;
}
+ if (iomap.src_addr) {
+ error = dax_iomap_cow_copy(&iomap, pos, PMD_SIZE);
+ if (error < 0)
+ goto finish_iomap;
+ }
+
trace_dax_pmd_insert_mapping(inode, vmf, PMD_SIZE, pfn, entry);
result = vmf_insert_pfn_pmd(vma, vmf->address, vmf->pmd, pfn,
write);
--
2.17.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH 4/4] fs/xfs: iomap: update the extent list after a COW
2019-04-17 1:27 [RFC PATCH 0/4] xfs: add handle for reflink in dax Shiyang Ruan
` (2 preceding siblings ...)
2019-04-17 1:27 ` [RFC PATCH 3/4] fs/dax: copy source blocks before writing when COW Shiyang Ruan
@ 2019-04-17 1:27 ` Shiyang Ruan
2019-04-17 1:34 ` [RFC PATCH 0/4] xfs: add handle for reflink in dax Darrick J. Wong
4 siblings, 0 replies; 7+ messages in thread
From: Shiyang Ruan @ 2019-04-17 1:27 UTC (permalink / raw)
To: linux-xfs, linux-nvdimm
COW allocated new extents, which are new part of the inode, So we
need to update the metadata.
Signed-off-by: Shiyang Ruan <ruansy.fnst@cn.fujitsu.com>
---
fs/xfs/xfs_iomap.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/xfs/xfs_iomap.c b/fs/xfs/xfs_iomap.c
index a45b4e5a1d87..5c05c11e0cb2 100644
--- a/fs/xfs/xfs_iomap.c
+++ b/fs/xfs/xfs_iomap.c
@@ -1146,6 +1146,9 @@ 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);
+ /* update the extent list after a COW operation */
+ if (iomap->flags & IOMAP_F_SHARED && iomap->src_addr)
+ return xfs_reflink_end_cow(XFS_I(inode), offset, length);
return 0;
}
--
2.17.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 0/4] xfs: add handle for reflink in dax
2019-04-17 1:27 [RFC PATCH 0/4] xfs: add handle for reflink in dax Shiyang Ruan
` (3 preceding siblings ...)
2019-04-17 1:27 ` [RFC PATCH 4/4] fs/xfs: iomap: update the extent list after a COW Shiyang Ruan
@ 2019-04-17 1:34 ` Darrick J. Wong
2019-04-17 2:06 ` Shiyang Ruan
4 siblings, 1 reply; 7+ messages in thread
From: Darrick J. Wong @ 2019-04-17 1:34 UTC (permalink / raw)
To: Shiyang Ruan; +Cc: linux-xfs, linux-nvdimm
On Wed, Apr 18, 2019 at 09:27:11AM +0800, Shiyang Ruan wrote:
> In XFS (under fsdax mode), reflink did not work correctly because xfs
> iomap operators did not handle the inode with both reflink and dax flag.
>
> This patchset aims to take care of this issue to make COW operation work
> correctly in XFS.
>
> XFS uses iomap to do read/write/mmap operations:
> vfs interface xfs:
> iomap_bengin(); --> xfs_iomap_begin();
> actor(); --> dax_iomap_actor() / mmap actor function
> iomap_end(); --> xfs_iomap_end();
>
> In xfs_iomap_begin(), COW operation is detected but not told to actor
> function. To resolve this, a new field 'src_addr' is added into
> 'struct iomap' to pass this COW info. It means the start address of
> source blocks in a COW operation, for actor functions to copy data
> before writing.
>
> In actor functions, the value of iomap->src_addr determines if it is a
> COW operation. If it is, copy data from source blocks to destination
> blocks first, and then write user data.
>
> After the COW operation, it is supposed to update the metadata of the
> inode. Added in xfs_iomap_end().
How do the fs/iomap.c changes in your series compare with Goldwyn's
"btrfs dax support" series that he put out today?
Also, there are a few things missing:
1. A DAX-compatible file contents comparison function for the dedupe
ioctl.
2. Checks that we aren't trying to reflink or dedupe between S_DAX and
!S_DAX files.
3. Do we need to make changes to the hairy
xfs_iolock_two_inodes_and_break_layout function to handle DAX? Seeing
as it doesn't call xfs_break_dax_layouts...
--D
>
>
> Shiyang Ruan (4):
> fs/iomap: Introduce src_addr for COW in fsdax mode.
> fs/xfs: iomap: add handle for reflink in fsdax mode
> fs/dax: copy source blocks before writing when COW
> fs/xfs: iomap: update the extent list after a COW
>
> fs/dax.c | 70 +++++++++++++++++++++++++++++++++++++++++++
> fs/xfs/xfs_iomap.c | 23 +++++++++++---
> include/linux/iomap.h | 4 +++
> 3 files changed, 93 insertions(+), 4 deletions(-)
>
> --
> 2.17.0
>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 0/4] xfs: add handle for reflink in dax
2019-04-17 1:34 ` [RFC PATCH 0/4] xfs: add handle for reflink in dax Darrick J. Wong
@ 2019-04-17 2:06 ` Shiyang Ruan
0 siblings, 0 replies; 7+ messages in thread
From: Shiyang Ruan @ 2019-04-17 2:06 UTC (permalink / raw)
To: Darrick J. Wong; +Cc: linux-xfs, linux-nvdimm
On 4/17/19 9:34 AM, Darrick J. Wong wrote:
> On Wed, Apr 18, 2019 at 09:27:11AM +0800, Shiyang Ruan wrote:
>> In XFS (under fsdax mode), reflink did not work correctly because xfs
>> iomap operators did not handle the inode with both reflink and dax flag.
>>
>> This patchset aims to take care of this issue to make COW operation work
>> correctly in XFS.
>>
>> XFS uses iomap to do read/write/mmap operations:
>> vfs interface xfs:
>> iomap_bengin(); --> xfs_iomap_begin();
>> actor(); --> dax_iomap_actor() / mmap actor function
>> iomap_end(); --> xfs_iomap_end();
>>
>> In xfs_iomap_begin(), COW operation is detected but not told to actor
>> function. To resolve this, a new field 'src_addr' is added into
>> 'struct iomap' to pass this COW info. It means the start address of
>> source blocks in a COW operation, for actor functions to copy data
>> before writing.
>>
>> In actor functions, the value of iomap->src_addr determines if it is a
>> COW operation. If it is, copy data from source blocks to destination
>> blocks first, and then write user data.
>>
>> After the COW operation, it is supposed to update the metadata of the
>> inode. Added in xfs_iomap_end().
>
> How do the fs/iomap.c changes in your series compare with Goldwyn's
> "btrfs dax support" series that he put out today?
Sorry, I think I missed his series. Will check it right now.
>
> Also, there are a few things missing:
>
> 1. A DAX-compatible file contents comparison function for the dedupe
> ioctl.
>
> 2. Checks that we aren't trying to reflink or dedupe between S_DAX and
> !S_DAX files.
>
> 3. Do we need to make changes to the hairy
> xfs_iolock_two_inodes_and_break_layout function to handle DAX? Seeing
> as it doesn't call xfs_break_dax_layouts...
Thanks for your comments. I did not think carefully about 'dedupe'.
Will take this into consideration.
--
Thanks,
Shiyang Ruan.
>
> --D
>
>>
>>
>> Shiyang Ruan (4):
>> fs/iomap: Introduce src_addr for COW in fsdax mode.
>> fs/xfs: iomap: add handle for reflink in fsdax mode
>> fs/dax: copy source blocks before writing when COW
>> fs/xfs: iomap: update the extent list after a COW
>>
>> fs/dax.c | 70 +++++++++++++++++++++++++++++++++++++++++++
>> fs/xfs/xfs_iomap.c | 23 +++++++++++---
>> include/linux/iomap.h | 4 +++
>> 3 files changed, 93 insertions(+), 4 deletions(-)
>>
>> --
>> 2.17.0
>>
>>
>>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-04-17 2:06 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-17 1:27 [RFC PATCH 0/4] xfs: add handle for reflink in dax Shiyang Ruan
2019-04-17 1:27 ` [RFC PATCH 1/4] fs/iomap: Introduce src_addr for COW in fsdax mode Shiyang Ruan
2019-04-17 1:27 ` [RFC PATCH 2/4] fs/xfs: iomap: add handle for reflink " Shiyang Ruan
2019-04-17 1:27 ` [RFC PATCH 3/4] fs/dax: copy source blocks before writing when COW Shiyang Ruan
2019-04-17 1:27 ` [RFC PATCH 4/4] fs/xfs: iomap: update the extent list after a COW Shiyang Ruan
2019-04-17 1:34 ` [RFC PATCH 0/4] xfs: add handle for reflink in dax Darrick J. Wong
2019-04-17 2:06 ` Shiyang Ruan
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox