summaryrefslogtreecommitdiffstats
path: root/fs/coda/file.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-07-17 11:58:04 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-17 11:58:04 -0400
commit57a8ec387e1441ea5e1232bc0749fb99a8cba7e7 (patch)
treeb5fb03fc6bc5754de8b5b1f8b0e4f36d67c8315c /fs/coda/file.c
parent0a8ad0ffa4d80a544f6cbff703bf6394339afcdf (diff)
parent43e11fa2d1d3b6e35629fa556eb7d571edba2010 (diff)
Merge branch 'akpm' (patches from Andrew)
Merge more updates from Andrew Morton: "VM: - z3fold fixes and enhancements by Henry Burns and Vitaly Wool - more accurate reclaimed slab caches calculations by Yafang Shao - fix MAP_UNINITIALIZED UAPI symbol to not depend on config, by Christoph Hellwig - !CONFIG_MMU fixes by Christoph Hellwig - new novmcoredd parameter to omit device dumps from vmcore, by Kairui Song - new test_meminit module for testing heap and pagealloc initialization, by Alexander Potapenko - ioremap improvements for huge mappings, by Anshuman Khandual - generalize kprobe page fault handling, by Anshuman Khandual - device-dax hotplug fixes and improvements, by Pavel Tatashin - enable synchronous DAX fault on powerpc, by Aneesh Kumar K.V - add pte_devmap() support for arm64, by Robin Murphy - unify locked_vm accounting with a helper, by Daniel Jordan - several misc fixes core/lib: - new typeof_member() macro including some users, by Alexey Dobriyan - make BIT() and GENMASK() available in asm, by Masahiro Yamada - changed LIST_POISON2 on x86_64 to 0xdead000000000122 for better code generation, by Alexey Dobriyan - rbtree code size optimizations, by Michel Lespinasse - convert struct pid count to refcount_t, by Joel Fernandes get_maintainer.pl: - add --no-moderated switch to skip moderated ML's, by Joe Perches misc: - ptrace PTRACE_GET_SYSCALL_INFO interface - coda updates - gdb scripts, various" [ Using merge message suggestion from Vlastimil Babka, with some editing - Linus ] * emailed patches from Andrew Morton <akpm@linux-foundation.org>: (100 commits) fs/select.c: use struct_size() in kmalloc() mm: add account_locked_vm utility function arm64: mm: implement pte_devmap support mm: introduce ARCH_HAS_PTE_DEVMAP mm: clean up is_device_*_page() definitions mm/mmap: move common defines to mman-common.h mm: move MAP_SYNC to asm-generic/mman-common.h device-dax: "Hotremove" persistent memory that is used like normal RAM mm/hotplug: make remove_memory() interface usable device-dax: fix memory and resource leak if hotplug fails include/linux/lz4.h: fix spelling and copy-paste errors in documentation ipc/mqueue.c: only perform resource calculation if user valid include/asm-generic/bug.h: fix "cut here" for WARN_ON for __WARN_TAINT architectures scripts/gdb: add helpers to find and list devices scripts/gdb: add lx-genpd-summary command drivers/pps/pps.c: clear offset flags in PPS_SETPARAMS ioctl kernel/pid.c: convert struct pid count to refcount_t drivers/rapidio/devices/rio_mport_cdev.c: NUL terminate some strings select: shift restore_saved_sigmask_unless() into poll_select_copy_remaining() select: change do_poll() to return -ERESTARTNOHAND rather than -EINTR ...
Diffstat (limited to 'fs/coda/file.c')
-rw-r--r--fs/coda/file.c143
1 files changed, 119 insertions, 24 deletions
diff --git a/fs/coda/file.c b/fs/coda/file.c
index 1cbc1f2298ee..128d63df5bfb 100644
--- a/fs/coda/file.c
+++ b/fs/coda/file.c
@@ -20,22 +20,43 @@
20#include <linux/string.h> 20#include <linux/string.h>
21#include <linux/slab.h> 21#include <linux/slab.h>
22#include <linux/uaccess.h> 22#include <linux/uaccess.h>
23#include <linux/uio.h>
23 24
24#include <linux/coda.h> 25#include <linux/coda.h>
25#include <linux/coda_psdev.h> 26#include "coda_psdev.h"
26
27#include "coda_linux.h" 27#include "coda_linux.h"
28#include "coda_int.h" 28#include "coda_int.h"
29 29
30struct coda_vm_ops {
31 atomic_t refcnt;
32 struct file *coda_file;
33 const struct vm_operations_struct *host_vm_ops;
34 struct vm_operations_struct vm_ops;
35};
36
30static ssize_t 37static ssize_t
31coda_file_read_iter(struct kiocb *iocb, struct iov_iter *to) 38coda_file_read_iter(struct kiocb *iocb, struct iov_iter *to)
32{ 39{
33 struct file *coda_file = iocb->ki_filp; 40 struct file *coda_file = iocb->ki_filp;
34 struct coda_file_info *cfi = CODA_FTOC(coda_file); 41 struct inode *coda_inode = file_inode(coda_file);
42 struct coda_file_info *cfi = coda_ftoc(coda_file);
43 loff_t ki_pos = iocb->ki_pos;
44 size_t count = iov_iter_count(to);
45 ssize_t ret;
35 46
36 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); 47 ret = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
48 &cfi->cfi_access_intent,
49 count, ki_pos, CODA_ACCESS_TYPE_READ);
50 if (ret)
51 goto finish_read;
37 52
38 return vfs_iter_read(cfi->cfi_container, to, &iocb->ki_pos, 0); 53 ret = vfs_iter_read(cfi->cfi_container, to, &iocb->ki_pos, 0);
54
55finish_read:
56 venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
57 &cfi->cfi_access_intent,
58 count, ki_pos, CODA_ACCESS_TYPE_READ_FINISH);
59 return ret;
39} 60}
40 61
41static ssize_t 62static ssize_t
@@ -43,13 +64,18 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to)
43{ 64{
44 struct file *coda_file = iocb->ki_filp; 65 struct file *coda_file = iocb->ki_filp;
45 struct inode *coda_inode = file_inode(coda_file); 66 struct inode *coda_inode = file_inode(coda_file);
46 struct coda_file_info *cfi = CODA_FTOC(coda_file); 67 struct coda_file_info *cfi = coda_ftoc(coda_file);
47 struct file *host_file; 68 struct file *host_file = cfi->cfi_container;
69 loff_t ki_pos = iocb->ki_pos;
70 size_t count = iov_iter_count(to);
48 ssize_t ret; 71 ssize_t ret;
49 72
50 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC); 73 ret = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
74 &cfi->cfi_access_intent,
75 count, ki_pos, CODA_ACCESS_TYPE_WRITE);
76 if (ret)
77 goto finish_write;
51 78
52 host_file = cfi->cfi_container;
53 file_start_write(host_file); 79 file_start_write(host_file);
54 inode_lock(coda_inode); 80 inode_lock(coda_inode);
55 ret = vfs_iter_write(cfi->cfi_container, to, &iocb->ki_pos, 0); 81 ret = vfs_iter_write(cfi->cfi_container, to, &iocb->ki_pos, 0);
@@ -58,26 +84,73 @@ coda_file_write_iter(struct kiocb *iocb, struct iov_iter *to)
58 coda_inode->i_mtime = coda_inode->i_ctime = current_time(coda_inode); 84 coda_inode->i_mtime = coda_inode->i_ctime = current_time(coda_inode);
59 inode_unlock(coda_inode); 85 inode_unlock(coda_inode);
60 file_end_write(host_file); 86 file_end_write(host_file);
87
88finish_write:
89 venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
90 &cfi->cfi_access_intent,
91 count, ki_pos, CODA_ACCESS_TYPE_WRITE_FINISH);
61 return ret; 92 return ret;
62} 93}
63 94
95static void
96coda_vm_open(struct vm_area_struct *vma)
97{
98 struct coda_vm_ops *cvm_ops =
99 container_of(vma->vm_ops, struct coda_vm_ops, vm_ops);
100
101 atomic_inc(&cvm_ops->refcnt);
102
103 if (cvm_ops->host_vm_ops && cvm_ops->host_vm_ops->open)
104 cvm_ops->host_vm_ops->open(vma);
105}
106
107static void
108coda_vm_close(struct vm_area_struct *vma)
109{
110 struct coda_vm_ops *cvm_ops =
111 container_of(vma->vm_ops, struct coda_vm_ops, vm_ops);
112
113 if (cvm_ops->host_vm_ops && cvm_ops->host_vm_ops->close)
114 cvm_ops->host_vm_ops->close(vma);
115
116 if (atomic_dec_and_test(&cvm_ops->refcnt)) {
117 vma->vm_ops = cvm_ops->host_vm_ops;
118 fput(cvm_ops->coda_file);
119 kfree(cvm_ops);
120 }
121}
122
64static int 123static int
65coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma) 124coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
66{ 125{
67 struct coda_file_info *cfi; 126 struct inode *coda_inode = file_inode(coda_file);
127 struct coda_file_info *cfi = coda_ftoc(coda_file);
128 struct file *host_file = cfi->cfi_container;
129 struct inode *host_inode = file_inode(host_file);
68 struct coda_inode_info *cii; 130 struct coda_inode_info *cii;
69 struct file *host_file; 131 struct coda_vm_ops *cvm_ops;
70 struct inode *coda_inode, *host_inode; 132 loff_t ppos;
71 133 size_t count;
72 cfi = CODA_FTOC(coda_file); 134 int ret;
73 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
74 host_file = cfi->cfi_container;
75 135
76 if (!host_file->f_op->mmap) 136 if (!host_file->f_op->mmap)
77 return -ENODEV; 137 return -ENODEV;
78 138
79 coda_inode = file_inode(coda_file); 139 if (WARN_ON(coda_file != vma->vm_file))
80 host_inode = file_inode(host_file); 140 return -EIO;
141
142 count = vma->vm_end - vma->vm_start;
143 ppos = vma->vm_pgoff * PAGE_SIZE;
144
145 ret = venus_access_intent(coda_inode->i_sb, coda_i2f(coda_inode),
146 &cfi->cfi_access_intent,
147 count, ppos, CODA_ACCESS_TYPE_MMAP);
148 if (ret)
149 return ret;
150
151 cvm_ops = kmalloc(sizeof(struct coda_vm_ops), GFP_KERNEL);
152 if (!cvm_ops)
153 return -ENOMEM;
81 154
82 cii = ITOC(coda_inode); 155 cii = ITOC(coda_inode);
83 spin_lock(&cii->c_lock); 156 spin_lock(&cii->c_lock);
@@ -89,6 +162,7 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
89 * the container file on us! */ 162 * the container file on us! */
90 else if (coda_inode->i_mapping != host_inode->i_mapping) { 163 else if (coda_inode->i_mapping != host_inode->i_mapping) {
91 spin_unlock(&cii->c_lock); 164 spin_unlock(&cii->c_lock);
165 kfree(cvm_ops);
92 return -EBUSY; 166 return -EBUSY;
93 } 167 }
94 168
@@ -97,7 +171,29 @@ coda_file_mmap(struct file *coda_file, struct vm_area_struct *vma)
97 cfi->cfi_mapcount++; 171 cfi->cfi_mapcount++;
98 spin_unlock(&cii->c_lock); 172 spin_unlock(&cii->c_lock);
99 173
100 return call_mmap(host_file, vma); 174 vma->vm_file = get_file(host_file);
175 ret = call_mmap(vma->vm_file, vma);
176
177 if (ret) {
178 /* if call_mmap fails, our caller will put coda_file so we
179 * should drop the reference to the host_file that we got.
180 */
181 fput(host_file);
182 kfree(cvm_ops);
183 } else {
184 /* here we add redirects for the open/close vm_operations */
185 cvm_ops->host_vm_ops = vma->vm_ops;
186 if (vma->vm_ops)
187 cvm_ops->vm_ops = *vma->vm_ops;
188
189 cvm_ops->vm_ops.open = coda_vm_open;
190 cvm_ops->vm_ops.close = coda_vm_close;
191 cvm_ops->coda_file = coda_file;
192 atomic_set(&cvm_ops->refcnt, 1);
193
194 vma->vm_ops = &cvm_ops->vm_ops;
195 }
196 return ret;
101} 197}
102 198
103int coda_open(struct inode *coda_inode, struct file *coda_file) 199int coda_open(struct inode *coda_inode, struct file *coda_file)
@@ -127,6 +223,8 @@ int coda_open(struct inode *coda_inode, struct file *coda_file)
127 cfi->cfi_magic = CODA_MAGIC; 223 cfi->cfi_magic = CODA_MAGIC;
128 cfi->cfi_mapcount = 0; 224 cfi->cfi_mapcount = 0;
129 cfi->cfi_container = host_file; 225 cfi->cfi_container = host_file;
226 /* assume access intents are supported unless we hear otherwise */
227 cfi->cfi_access_intent = true;
130 228
131 BUG_ON(coda_file->private_data != NULL); 229 BUG_ON(coda_file->private_data != NULL);
132 coda_file->private_data = cfi; 230 coda_file->private_data = cfi;
@@ -142,8 +240,7 @@ int coda_release(struct inode *coda_inode, struct file *coda_file)
142 struct inode *host_inode; 240 struct inode *host_inode;
143 int err; 241 int err;
144 242
145 cfi = CODA_FTOC(coda_file); 243 cfi = coda_ftoc(coda_file);
146 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
147 244
148 err = venus_close(coda_inode->i_sb, coda_i2f(coda_inode), 245 err = venus_close(coda_inode->i_sb, coda_i2f(coda_inode),
149 coda_flags, coda_file->f_cred->fsuid); 246 coda_flags, coda_file->f_cred->fsuid);
@@ -185,8 +282,7 @@ int coda_fsync(struct file *coda_file, loff_t start, loff_t end, int datasync)
185 return err; 282 return err;
186 inode_lock(coda_inode); 283 inode_lock(coda_inode);
187 284
188 cfi = CODA_FTOC(coda_file); 285 cfi = coda_ftoc(coda_file);
189 BUG_ON(!cfi || cfi->cfi_magic != CODA_MAGIC);
190 host_file = cfi->cfi_container; 286 host_file = cfi->cfi_container;
191 287
192 err = vfs_fsync(host_file, datasync); 288 err = vfs_fsync(host_file, datasync);
@@ -207,4 +303,3 @@ const struct file_operations coda_file_operations = {
207 .fsync = coda_fsync, 303 .fsync = coda_fsync,
208 .splice_read = generic_file_splice_read, 304 .splice_read = generic_file_splice_read,
209}; 305};
210