From: Goldwyn Rodrigues <rgoldwyn@suse.de>
To: linux-btrfs@vger.kernel.org
Cc: Goldwyn Rodrigues <rgoldwyn@suse.com>
Subject: [PATCH 08/10] btrfs: dax add read mmap path
Date: Wed, 5 Dec 2018 06:28:33 -0600 [thread overview]
Message-ID: <20181205122835.19290-9-rgoldwyn@suse.de> (raw)
In-Reply-To: <20181205122835.19290-1-rgoldwyn@suse.de>
From: Goldwyn Rodrigues <rgoldwyn@suse.com>
Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
fs/btrfs/ctree.h | 1 +
fs/btrfs/dax.c | 43 +++++++++++++++++++++++++++++++++++++++++++
fs/btrfs/file.c | 12 +++++++++++-
3 files changed, 55 insertions(+), 1 deletion(-)
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index d91ff283a966..33648121ca52 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -3694,6 +3694,7 @@ int btree_readahead_hook(struct extent_buffer *eb, int err);
/* dax.c */
ssize_t btrfs_file_dax_read(struct kiocb *iocb, struct iov_iter *to);
ssize_t btrfs_file_dax_write(struct kiocb *iocb, struct iov_iter *from);
+vm_fault_t btrfs_dax_fault(struct vm_fault *vmf);
#endif /* CONFIG_FS_DAX */
static inline int is_fstree(u64 rootid)
diff --git a/fs/btrfs/dax.c b/fs/btrfs/dax.c
index 4000259a426c..88017f8799d1 100644
--- a/fs/btrfs/dax.c
+++ b/fs/btrfs/dax.c
@@ -190,5 +190,48 @@ ssize_t btrfs_file_dax_write(struct kiocb *iocb, struct iov_iter *from)
count - done, true);
extent_changeset_free(data_reserved);
return done ? done : ret;
+}
+
+/* As copied from dax_iomap_pte_fault() */
+vm_fault_t btrfs_dax_fault(struct vm_fault *vmf)
+{
+ pfn_t pfn;
+ struct address_space *mapping = vmf->vma->vm_file->f_mapping;
+ XA_STATE(xas, &mapping->i_pages, vmf->pgoff);
+ struct inode *inode = mapping->host;
+ loff_t pos = (loff_t)vmf->pgoff << PAGE_SHIFT;
+ void *entry = NULL;
+ vm_fault_t ret = 0;
+
+ if (pos > i_size_read(inode)) {
+ ret = VM_FAULT_SIGBUS;
+ goto out;
+ }
+ entry = grab_mapping_entry(&xas, mapping, 0);
+ if (IS_ERR(entry)) {
+ ret = dax_fault_return(PTR_ERR(entry));
+ goto out;
+ }
+
+ if (!vmf->cow_page) {
+ sector_t sector;
+ struct extent_map *em;
+ em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, pos, PAGE_SIZE, 0);
+ if (em->block_start == EXTENT_MAP_HOLE) {
+ ret = dax_load_hole(&xas, mapping, entry, vmf);
+ goto out;
+ }
+ sector = ((get_start_sect(em->bdev) << 9) +
+ (em->block_start + (pos - em->start))) >> 9;
+ ret = dax_pfn(fs_dax_get_by_bdev(em->bdev), em->bdev, sector, PAGE_SIZE, &pfn);
+ if (ret)
+ goto out;
+ dax_insert_entry(&xas, mapping, vmf, entry, pfn, 0, false);
+ ret = vmf_insert_mixed(vmf->vma, vmf->address, pfn);
+ }
+out:
+ if (entry)
+ dax_unlock_entry(&xas, entry);
+ return ret;
}
diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c
index 29a3b12e6660..38b494686fb2 100644
--- a/fs/btrfs/file.c
+++ b/fs/btrfs/file.c
@@ -2227,8 +2227,18 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
return ret > 0 ? -EIO : ret;
}
+static vm_fault_t btrfs_fault(struct vm_fault *vmf)
+{
+ struct inode *inode = vmf->vma->vm_file->f_mapping->host;
+#ifdef CONFIG_FS_DAX
+ if (IS_DAX(inode))
+ return btrfs_dax_fault(vmf);
+#endif
+ return filemap_fault(vmf);
+}
+
static const struct vm_operations_struct btrfs_file_vm_ops = {
- .fault = filemap_fault,
+ .fault = btrfs_fault,
.map_pages = filemap_map_pages,
.page_mkwrite = btrfs_page_mkwrite,
};
--
2.16.4
next prev parent reply other threads:[~2018-12-05 12:29 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-05 12:28 [PATCH 00/10] btrfs: Support for DAX devices Goldwyn Rodrigues
2018-12-05 12:28 ` [PATCH 01/10] btrfs: create a mount option for dax Goldwyn Rodrigues
2018-12-05 12:42 ` Johannes Thumshirn
2018-12-05 12:43 ` Nikolay Borisov
2018-12-05 14:59 ` Adam Borowski
2018-12-05 12:28 ` [PATCH 02/10] btrfs: basic dax read Goldwyn Rodrigues
2018-12-05 13:11 ` Nikolay Borisov
2018-12-05 13:22 ` Johannes Thumshirn
2018-12-05 12:28 ` [PATCH 03/10] btrfs: dax: read zeros from holes Goldwyn Rodrigues
2018-12-05 13:26 ` Nikolay Borisov
2018-12-05 12:28 ` [PATCH 04/10] Rename __endio_write_update_ordered() to btrfs_update_ordered_extent() Goldwyn Rodrigues
2018-12-05 13:35 ` Nikolay Borisov
2018-12-05 12:28 ` [PATCH 05/10] btrfs: Carve out btrfs_get_extent_map_write() out of btrfs_get_blocks_write() Goldwyn Rodrigues
2018-12-05 12:28 ` [PATCH 06/10] btrfs: dax write support Goldwyn Rodrigues
2018-12-05 13:56 ` Johannes Thumshirn
2018-12-05 12:28 ` [PATCH 07/10] dax: export functions for use with btrfs Goldwyn Rodrigues
2018-12-05 13:59 ` Johannes Thumshirn
2018-12-05 14:52 ` Christoph Hellwig
2018-12-06 11:46 ` Goldwyn Rodrigues
2018-12-12 8:07 ` Christoph Hellwig
2019-03-26 19:36 ` Dan Williams
2019-03-27 11:10 ` Goldwyn Rodrigues
2018-12-05 12:28 ` Goldwyn Rodrigues [this message]
2018-12-05 12:28 ` [PATCH 09/10] btrfs: dax support for cow_page/mmap_private and shared Goldwyn Rodrigues
2018-12-05 12:28 ` [PATCH 10/10] btrfs: dax mmap write Goldwyn Rodrigues
2018-12-05 13:03 ` [PATCH 00/10] btrfs: Support for DAX devices Qu Wenruo
2018-12-05 21:36 ` Jeff Mahoney
2018-12-05 13:57 ` Adam Borowski
2018-12-05 21:37 ` Jeff Mahoney
2018-12-06 7:40 ` Robert White
2018-12-06 10:07 ` Johannes Thumshirn
2018-12-06 11:47 ` Goldwyn Rodrigues
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=20181205122835.19290-9-rgoldwyn@suse.de \
--to=rgoldwyn@suse.de \
--cc=linux-btrfs@vger.kernel.org \
--cc=rgoldwyn@suse.com \
/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).