Commit 1cf7a151 authored by David Howells's avatar David Howells

afs: Implement shared-writeable mmap

Implement shared-writeable mmap for AFS.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
parent 4343d008
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/task_io_accounting_ops.h> #include <linux/task_io_accounting_ops.h>
#include "internal.h" #include "internal.h"
static int afs_file_mmap(struct file *file, struct vm_area_struct *vma);
static int afs_readpage(struct file *file, struct page *page); static int afs_readpage(struct file *file, struct page *page);
static void afs_invalidatepage(struct page *page, unsigned int offset, static void afs_invalidatepage(struct page *page, unsigned int offset,
unsigned int length); unsigned int length);
...@@ -34,7 +35,7 @@ const struct file_operations afs_file_operations = { ...@@ -34,7 +35,7 @@ const struct file_operations afs_file_operations = {
.llseek = generic_file_llseek, .llseek = generic_file_llseek,
.read_iter = generic_file_read_iter, .read_iter = generic_file_read_iter,
.write_iter = afs_file_write, .write_iter = afs_file_write,
.mmap = generic_file_readonly_mmap, .mmap = afs_file_mmap,
.splice_read = generic_file_splice_read, .splice_read = generic_file_splice_read,
.fsync = afs_fsync, .fsync = afs_fsync,
.lock = afs_lock, .lock = afs_lock,
...@@ -61,6 +62,12 @@ const struct address_space_operations afs_fs_aops = { ...@@ -61,6 +62,12 @@ const struct address_space_operations afs_fs_aops = {
.writepages = afs_writepages, .writepages = afs_writepages,
}; };
static const struct vm_operations_struct afs_vm_ops = {
.fault = filemap_fault,
.map_pages = filemap_map_pages,
.page_mkwrite = afs_page_mkwrite,
};
/* /*
* Discard a pin on a writeback key. * Discard a pin on a writeback key.
*/ */
...@@ -629,3 +636,16 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags) ...@@ -629,3 +636,16 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)
_leave(" = T"); _leave(" = T");
return 1; return 1;
} }
/*
* Handle setting up a memory mapping on an AFS file.
*/
static int afs_file_mmap(struct file *file, struct vm_area_struct *vma)
{
int ret;
ret = generic_file_mmap(file, vma);
if (ret == 0)
vma->vm_ops = &afs_vm_ops;
return ret;
}
...@@ -886,6 +886,7 @@ extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *); ...@@ -886,6 +886,7 @@ extern void afs_pages_written_back(struct afs_vnode *, struct afs_call *);
extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *); extern ssize_t afs_file_write(struct kiocb *, struct iov_iter *);
extern int afs_flush(struct file *, fl_owner_t); extern int afs_flush(struct file *, fl_owner_t);
extern int afs_fsync(struct file *, loff_t, loff_t, int); extern int afs_fsync(struct file *, loff_t, loff_t, int);
extern int afs_page_mkwrite(struct vm_fault *);
extern void afs_prune_wb_keys(struct afs_vnode *); extern void afs_prune_wb_keys(struct afs_vnode *);
extern int afs_launder_page(struct page *); extern int afs_launder_page(struct page *);
......
...@@ -749,21 +749,45 @@ int afs_flush(struct file *file, fl_owner_t id) ...@@ -749,21 +749,45 @@ int afs_flush(struct file *file, fl_owner_t id)
* notification that a previously read-only page is about to become writable * notification that a previously read-only page is about to become writable
* - if it returns an error, the caller will deliver a bus error signal * - if it returns an error, the caller will deliver a bus error signal
*/ */
int afs_page_mkwrite(struct vm_area_struct *vma, struct page *page) int afs_page_mkwrite(struct vm_fault *vmf)
{ {
struct afs_vnode *vnode = AFS_FS_I(vma->vm_file->f_mapping->host); struct file *file = vmf->vma->vm_file;
struct inode *inode = file_inode(file);
struct afs_vnode *vnode = AFS_FS_I(inode);
unsigned long priv;
_enter("{{%x:%u}},{%lx}", _enter("{{%x:%u}},{%lx}",
vnode->fid.vid, vnode->fid.vnode, page->index); vnode->fid.vid, vnode->fid.vnode, vmf->page->index);
/* wait for the page to be written to the cache before we allow it to sb_start_pagefault(inode->i_sb);
* be modified */
/* Wait for the page to be written to the cache before we allow it to
* be modified. We then assume the entire page will need writing back.
*/
#ifdef CONFIG_AFS_FSCACHE #ifdef CONFIG_AFS_FSCACHE
fscache_wait_on_page_write(vnode->cache, page); fscache_wait_on_page_write(vnode->cache, vmf->page);
#endif #endif
_leave(" = 0"); if (PageWriteback(vmf->page) &&
return 0; wait_on_page_bit_killable(vmf->page, PG_writeback) < 0)
return VM_FAULT_RETRY;
if (lock_page_killable(vmf->page) < 0)
return VM_FAULT_RETRY;
/* We mustn't change page->private until writeback is complete as that
* details the portion of the page we need to write back and we might
* need to redirty the page if there's a problem.
*/
wait_on_page_writeback(vmf->page);
priv = (unsigned long)PAGE_SIZE << AFS_PRIV_SHIFT; /* To */
priv |= 0; /* From */
SetPagePrivate(vmf->page);
set_page_private(vmf->page, priv);
sb_end_pagefault(inode->i_sb);
return VM_FAULT_LOCKED;
} }
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment