diff mbox series

[08/15] dax: add dax_iomap_cow to copy a mmap page before writing

Message ID 20190326190301.32365-9-rgoldwyn@suse.de (mailing list archive)
State New, archived
Headers show
Series [01/15] btrfs: create a mount option for dax | expand

Commit Message

Goldwyn Rodrigues March 26, 2019, 7:02 p.m. UTC
From: Goldwyn Rodrigues <rgoldwyn@suse.com>

dax_iomap_cow copies a page before presenting for mmap.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
 fs/dax.c | 33 ++++++++++++++++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

Comments

Darrick J. Wong March 28, 2019, 3:41 p.m. UTC | #1
On Tue, Mar 26, 2019 at 02:02:54PM -0500, Goldwyn Rodrigues wrote:
> From: Goldwyn Rodrigues <rgoldwyn@suse.com>
> 
> dax_iomap_cow copies a page before presenting for mmap.
> 
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
> ---
>  fs/dax.c | 33 ++++++++++++++++++++++++++++++++-
>  1 file changed, 32 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/dax.c b/fs/dax.c
> index e254535dd830..21ee3df6f02c 100644
> --- a/fs/dax.c
> +++ b/fs/dax.c
> @@ -1269,6 +1269,33 @@ static bool dax_fault_is_synchronous(unsigned long flags,
>  		&& (iomap->flags & IOMAP_F_DIRTY);
>  }
>  
> +static int dax_iomap_cow(struct iomap *iomap, loff_t pos, pfn_t *pfn)
> +{
> +	void *daddr;
> +	pgoff_t pgoff;
> +	long rc;
> +	int id;
> +	sector_t sector;
> +
> +	pos = round_down(pos, PAGE_SIZE);
> +
> +	sector = round_down(iomap->addr + iomap->offset - pos, PAGE_SIZE) >> 9;
> +	rc = bdev_dax_pgoff(iomap->bdev, sector, PAGE_SIZE, &pgoff);
> +	if (rc)
> +		return rc;
> +
> +	id = dax_read_lock();
> +	rc = dax_direct_access(iomap->dax_dev, pgoff, 1, &daddr, pfn);
> +	if (rc < 0)
> +		goto out;
> +
> +	dax_to_dax_copy(iomap, pos, daddr, PAGE_SIZE);
> +
> +out:
> +	dax_read_unlock(id);
> +	return rc;
> +}
> +
>  static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,
>  			       int *iomap_errp, const struct iomap_ops *ops)
>  {
> @@ -1372,7 +1399,11 @@ 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 (iomap.flags & IOMAP_F_COW)
> +			error = dax_iomap_cow(&iomap, pos, &pfn);

Why wouldn't dax_iomap_cow also apply to dax_iomap_pmd_fault?

--D

> +		else
> +			error = dax_iomap_pfn(&iomap, pos, PAGE_SIZE, &pfn);
>  		if (error < 0)
>  			goto error_finish_iomap;
>  
> -- 
> 2.16.4
>
diff mbox series

Patch

diff --git a/fs/dax.c b/fs/dax.c
index e254535dd830..21ee3df6f02c 100644
--- a/fs/dax.c
+++ b/fs/dax.c
@@ -1269,6 +1269,33 @@  static bool dax_fault_is_synchronous(unsigned long flags,
 		&& (iomap->flags & IOMAP_F_DIRTY);
 }
 
+static int dax_iomap_cow(struct iomap *iomap, loff_t pos, pfn_t *pfn)
+{
+	void *daddr;
+	pgoff_t pgoff;
+	long rc;
+	int id;
+	sector_t sector;
+
+	pos = round_down(pos, PAGE_SIZE);
+
+	sector = round_down(iomap->addr + iomap->offset - pos, PAGE_SIZE) >> 9;
+	rc = bdev_dax_pgoff(iomap->bdev, sector, PAGE_SIZE, &pgoff);
+	if (rc)
+		return rc;
+
+	id = dax_read_lock();
+	rc = dax_direct_access(iomap->dax_dev, pgoff, 1, &daddr, pfn);
+	if (rc < 0)
+		goto out;
+
+	dax_to_dax_copy(iomap, pos, daddr, PAGE_SIZE);
+
+out:
+	dax_read_unlock(id);
+	return rc;
+}
+
 static vm_fault_t dax_iomap_pte_fault(struct vm_fault *vmf, pfn_t *pfnp,
 			       int *iomap_errp, const struct iomap_ops *ops)
 {
@@ -1372,7 +1399,11 @@  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 (iomap.flags & IOMAP_F_COW)
+			error = dax_iomap_cow(&iomap, pos, &pfn);
+		else
+			error = dax_iomap_pfn(&iomap, pos, PAGE_SIZE, &pfn);
 		if (error < 0)
 			goto error_finish_iomap;