Commit 602db5b7 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 928f45ef
...@@ -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,
...@@ -60,6 +61,12 @@ const struct address_space_operations afs_fs_aops = { ...@@ -60,6 +61,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,
};
/* /*
* open an AFS file or directory and attach a key to it * open an AFS file or directory and attach a key to it
*/ */
...@@ -543,3 +550,16 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags) ...@@ -543,3 +550,16 @@ static int afs_releasepage(struct page *page, gfp_t gfp_flags)
_leave(" = %d", cleared); _leave(" = %d", cleared);
return cleared; return cleared;
} }
/*
* 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;
}
...@@ -734,6 +734,8 @@ extern int afs_writeback_all(struct afs_vnode *); ...@@ -734,6 +734,8 @@ extern int afs_writeback_all(struct afs_vnode *);
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_launder_page(struct page *); extern int afs_launder_page(struct page *);
extern int afs_page_mkwrite(struct vm_fault *);
/*****************************************************************************/ /*****************************************************************************/
/* /*
......
...@@ -1033,21 +1033,57 @@ int afs_flush(struct file *file, fl_owner_t id) ...@@ -1033,21 +1033,57 @@ 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);
struct afs_writeback *candidate;
struct key *key = file->private_data;
int ret, vret;
_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);
candidate = afs_alloc_writeback(vnode, key, vmf->page->index, 0, PAGE_SIZE);
if (!candidate)
return VM_FAULT_OOM;
sb_start_pagefault(inode->i_sb);
retry:
/* wait for the page to be written to the cache before we allow it to /* wait for the page to be written to the cache before we allow it to
* be modified */ * be modified */
#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"); /* TODO: Get the key from vma->vm_file, flush any overlapping
return 0; * contradictory writeback record, set up new a writeback record if
* needed and remove the R/O check from afs_file_mmap().
*
* The code can probably be common with much of afs_write_begin().
*/
lock_page(vmf->page);
vret = VM_FAULT_LOCKED;
ret = afs_add_writeback(vnode, candidate, vmf->page);
switch (ret) {
case 0:
break;
case -EAGAIN:
goto retry;
case -ENOMEM:
vret |= VM_FAULT_OOM;
break;
default:
vret |= VM_FAULT_SIGBUS;
break;
}
sb_end_pagefault(inode->i_sb);
_leave(" = %d", vret);
return vret;
} }
/* /*
......
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