blob: 8c43cd2e237a5f15b18c743e2c13a10fd8c0f51f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110021#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "xfs_sb.h"
Nathan Scotta844f452005-11-02 14:38:42 +110023#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "xfs_dir2.h"
25#include "xfs_trans.h"
26#include "xfs_dmapi.h"
27#include "xfs_mount.h"
28#include "xfs_bmap_btree.h"
29#include "xfs_alloc_btree.h"
30#include "xfs_ialloc_btree.h"
31#include "xfs_alloc.h"
32#include "xfs_btree.h"
33#include "xfs_attr_sf.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070034#include "xfs_dir2_sf.h"
35#include "xfs_dinode.h"
36#include "xfs_inode.h"
37#include "xfs_error.h"
38#include "xfs_rw.h"
39#include "xfs_ioctl32.h"
40
41#include <linux/dcache.h>
42#include <linux/smp_lock.h>
43
Nathan Scott3562fd42006-03-14 14:00:35 +110044static struct vm_operations_struct xfs_file_vm_ops;
Dean Roehrich6fac0cb2005-06-21 14:07:45 +100045#ifdef CONFIG_XFS_DMAPI
Nathan Scott3562fd42006-03-14 14:00:35 +110046static struct vm_operations_struct xfs_dmapi_file_vm_ops;
Dean Roehrich6fac0cb2005-06-21 14:07:45 +100047#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
David Chinner7989cb82007-02-10 18:34:56 +110049STATIC_INLINE ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +110050__xfs_file_read(
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 struct kiocb *iocb,
Badari Pulavarty027445c2006-09-30 23:28:46 -070052 const struct iovec *iov,
53 unsigned long nr_segs,
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 int ioflags,
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 loff_t pos)
56{
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 struct file *file = iocb->ki_filp;
Josef "Jeff" Sipeke678fb02006-12-08 02:36:49 -080058 bhv_vnode_t *vp = vn_from_inode(file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60 BUG_ON(iocb->ki_pos != pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 if (unlikely(file->f_flags & O_DIRECT))
62 ioflags |= IO_ISDIRECT;
Badari Pulavarty027445c2006-09-30 23:28:46 -070063 return bhv_vop_read(vp, iocb, iov, nr_segs, &iocb->ki_pos,
64 ioflags, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
Linus Torvalds1da177e2005-04-16 15:20:36 -070067STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +110068xfs_file_aio_read(
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 struct kiocb *iocb,
Badari Pulavarty027445c2006-09-30 23:28:46 -070070 const struct iovec *iov,
71 unsigned long nr_segs,
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 loff_t pos)
73{
Badari Pulavarty027445c2006-09-30 23:28:46 -070074 return __xfs_file_read(iocb, iov, nr_segs, IO_ISAIO, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
76
77STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +110078xfs_file_aio_read_invis(
Linus Torvalds1da177e2005-04-16 15:20:36 -070079 struct kiocb *iocb,
Badari Pulavarty027445c2006-09-30 23:28:46 -070080 const struct iovec *iov,
81 unsigned long nr_segs,
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 loff_t pos)
83{
Badari Pulavarty027445c2006-09-30 23:28:46 -070084 return __xfs_file_read(iocb, iov, nr_segs, IO_ISAIO|IO_INVIS, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085}
86
David Chinner7989cb82007-02-10 18:34:56 +110087STATIC_INLINE ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +110088__xfs_file_write(
Badari Pulavarty027445c2006-09-30 23:28:46 -070089 struct kiocb *iocb,
90 const struct iovec *iov,
91 unsigned long nr_segs,
92 int ioflags,
93 loff_t pos)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 struct file *file = iocb->ki_filp;
96 struct inode *inode = file->f_mapping->host;
Nathan Scott67fcaa72006-06-09 17:00:52 +100097 bhv_vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
99 BUG_ON(iocb->ki_pos != pos);
100 if (unlikely(file->f_flags & O_DIRECT))
101 ioflags |= IO_ISDIRECT;
Badari Pulavarty027445c2006-09-30 23:28:46 -0700102 return bhv_vop_write(vp, iocb, iov, nr_segs, &iocb->ki_pos,
103 ioflags, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104}
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100107xfs_file_aio_write(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 struct kiocb *iocb,
Badari Pulavarty027445c2006-09-30 23:28:46 -0700109 const struct iovec *iov,
110 unsigned long nr_segs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 loff_t pos)
112{
Badari Pulavarty027445c2006-09-30 23:28:46 -0700113 return __xfs_file_write(iocb, iov, nr_segs, IO_ISAIO, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114}
115
116STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100117xfs_file_aio_write_invis(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 struct kiocb *iocb,
Badari Pulavarty027445c2006-09-30 23:28:46 -0700119 const struct iovec *iov,
120 unsigned long nr_segs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 loff_t pos)
122{
Badari Pulavarty027445c2006-09-30 23:28:46 -0700123 return __xfs_file_write(iocb, iov, nr_segs, IO_ISAIO|IO_INVIS, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124}
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126STATIC ssize_t
Nathan Scott1b895842006-03-31 13:08:59 +1000127xfs_file_splice_read(
128 struct file *infilp,
Jens Axboecbb7e572006-04-11 14:57:50 +0200129 loff_t *ppos,
Ingo Molnar3a326a22006-04-10 15:18:35 +0200130 struct pipe_inode_info *pipe,
Nathan Scott1b895842006-03-31 13:08:59 +1000131 size_t len,
132 unsigned int flags)
133{
Josef "Jeff" Sipeke678fb02006-12-08 02:36:49 -0800134 return bhv_vop_splice_read(vn_from_inode(infilp->f_path.dentry->d_inode),
Nathan Scott67fcaa72006-06-09 17:00:52 +1000135 infilp, ppos, pipe, len, flags, 0, NULL);
Nathan Scott1b895842006-03-31 13:08:59 +1000136}
137
138STATIC ssize_t
139xfs_file_splice_read_invis(
140 struct file *infilp,
Jens Axboecbb7e572006-04-11 14:57:50 +0200141 loff_t *ppos,
Ingo Molnar3a326a22006-04-10 15:18:35 +0200142 struct pipe_inode_info *pipe,
Nathan Scott1b895842006-03-31 13:08:59 +1000143 size_t len,
144 unsigned int flags)
145{
Josef "Jeff" Sipeke678fb02006-12-08 02:36:49 -0800146 return bhv_vop_splice_read(vn_from_inode(infilp->f_path.dentry->d_inode),
Nathan Scott67fcaa72006-06-09 17:00:52 +1000147 infilp, ppos, pipe, len, flags, IO_INVIS,
148 NULL);
Nathan Scott1b895842006-03-31 13:08:59 +1000149}
150
151STATIC ssize_t
152xfs_file_splice_write(
Ingo Molnar3a326a22006-04-10 15:18:35 +0200153 struct pipe_inode_info *pipe,
Nathan Scott1b895842006-03-31 13:08:59 +1000154 struct file *outfilp,
Jens Axboecbb7e572006-04-11 14:57:50 +0200155 loff_t *ppos,
Nathan Scott1b895842006-03-31 13:08:59 +1000156 size_t len,
157 unsigned int flags)
158{
Josef "Jeff" Sipeke678fb02006-12-08 02:36:49 -0800159 return bhv_vop_splice_write(vn_from_inode(outfilp->f_path.dentry->d_inode),
Nathan Scott67fcaa72006-06-09 17:00:52 +1000160 pipe, outfilp, ppos, len, flags, 0, NULL);
Nathan Scott1b895842006-03-31 13:08:59 +1000161}
162
163STATIC ssize_t
164xfs_file_splice_write_invis(
Ingo Molnar3a326a22006-04-10 15:18:35 +0200165 struct pipe_inode_info *pipe,
Nathan Scott1b895842006-03-31 13:08:59 +1000166 struct file *outfilp,
Jens Axboecbb7e572006-04-11 14:57:50 +0200167 loff_t *ppos,
Nathan Scott1b895842006-03-31 13:08:59 +1000168 size_t len,
169 unsigned int flags)
170{
Josef "Jeff" Sipeke678fb02006-12-08 02:36:49 -0800171 return bhv_vop_splice_write(vn_from_inode(outfilp->f_path.dentry->d_inode),
Nathan Scott67fcaa72006-06-09 17:00:52 +1000172 pipe, outfilp, ppos, len, flags, IO_INVIS,
173 NULL);
Nathan Scott1b895842006-03-31 13:08:59 +1000174}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100177xfs_file_open(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 struct inode *inode,
179 struct file *filp)
180{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
182 return -EFBIG;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000183 return -bhv_vop_open(vn_from_inode(inode), NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184}
185
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186STATIC int
Nathan Scott7d4fb402006-06-09 15:27:16 +1000187xfs_file_close(
Alexey Dobriyan1e788f82006-06-25 16:42:33 -0700188 struct file *filp,
189 fl_owner_t id)
Nathan Scott7d4fb402006-06-09 15:27:16 +1000190{
Josef "Jeff" Sipeke678fb02006-12-08 02:36:49 -0800191 return -bhv_vop_close(vn_from_inode(filp->f_path.dentry->d_inode), 0,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000192 file_count(filp) > 1 ? L_FALSE : L_TRUE, NULL);
Nathan Scott7d4fb402006-06-09 15:27:16 +1000193}
194
195STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100196xfs_file_release(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 struct inode *inode,
198 struct file *filp)
199{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000200 bhv_vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 if (vp)
Nathan Scott67fcaa72006-06-09 17:00:52 +1000203 return -bhv_vop_release(vp);
204 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205}
206
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100208xfs_file_fsync(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 struct file *filp,
210 struct dentry *dentry,
211 int datasync)
212{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000213 bhv_vnode_t *vp = vn_from_inode(dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 int flags = FSYNC_WAIT;
215
216 if (datasync)
217 flags |= FSYNC_DATA;
Nathan Scott7d4fb402006-06-09 15:27:16 +1000218 if (VN_TRUNC(vp))
219 VUNTRUNCATE(vp);
Nathan Scott67fcaa72006-06-09 17:00:52 +1000220 return -bhv_vop_fsync(vp, flags, NULL, (xfs_off_t)0, (xfs_off_t)-1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221}
222
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000223#ifdef CONFIG_XFS_DMAPI
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000224STATIC struct page *
Nathan Scott3562fd42006-03-14 14:00:35 +1100225xfs_vm_nopage(
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000226 struct vm_area_struct *area,
227 unsigned long address,
228 int *type)
229{
Josef "Jeff" Sipeke678fb02006-12-08 02:36:49 -0800230 struct inode *inode = area->vm_file->f_path.dentry->d_inode;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000231 bhv_vnode_t *vp = vn_from_inode(inode);
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000232
233 ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI);
Nathan Scottfbc14622006-06-09 14:52:13 +1000234 if (XFS_SEND_MMAP(XFS_VFSTOM(vp->v_vfsp), area, 0))
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000235 return NULL;
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000236 return filemap_nopage(area, address, type);
237}
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000238#endif /* CONFIG_XFS_DMAPI */
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100241xfs_file_readdir(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 struct file *filp,
243 void *dirent,
244 filldir_t filldir)
245{
246 int error = 0;
Josef "Jeff" Sipeke678fb02006-12-08 02:36:49 -0800247 bhv_vnode_t *vp = vn_from_inode(filp->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 uio_t uio;
249 iovec_t iov;
250 int eof = 0;
251 caddr_t read_buf;
252 int namelen, size = 0;
253 size_t rlen = PAGE_CACHE_SIZE;
254 xfs_off_t start_offset, curr_offset;
255 xfs_dirent_t *dbp = NULL;
256
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 /* Try fairly hard to get memory */
258 do {
Panagiotis Issarisf52720c2006-09-27 01:49:39 -0700259 if ((read_buf = kmalloc(rlen, GFP_KERNEL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 break;
261 rlen >>= 1;
262 } while (rlen >= 1024);
263
264 if (read_buf == NULL)
265 return -ENOMEM;
266
267 uio.uio_iov = &iov;
268 uio.uio_segflg = UIO_SYSSPACE;
269 curr_offset = filp->f_pos;
270 if (filp->f_pos != 0x7fffffff)
271 uio.uio_offset = filp->f_pos;
272 else
273 uio.uio_offset = 0xffffffff;
274
275 while (!eof) {
276 uio.uio_resid = iov.iov_len = rlen;
277 iov.iov_base = read_buf;
278 uio.uio_iovcnt = 1;
279
280 start_offset = uio.uio_offset;
281
Nathan Scott67fcaa72006-06-09 17:00:52 +1000282 error = bhv_vop_readdir(vp, &uio, NULL, &eof);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 if ((uio.uio_offset == start_offset) || error) {
284 size = 0;
285 break;
286 }
287
288 size = rlen - uio.uio_resid;
289 dbp = (xfs_dirent_t *)read_buf;
290 while (size > 0) {
291 namelen = strlen(dbp->d_name);
292
293 if (filldir(dirent, dbp->d_name, namelen,
294 (loff_t) curr_offset & 0x7fffffff,
295 (ino_t) dbp->d_ino,
296 DT_UNKNOWN)) {
297 goto done;
298 }
299 size -= dbp->d_reclen;
300 curr_offset = (loff_t)dbp->d_off /* & 0x7fffffff */;
Nathan Scott1b895842006-03-31 13:08:59 +1000301 dbp = (xfs_dirent_t *)((char *)dbp + dbp->d_reclen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 }
303 }
304done:
305 if (!error) {
306 if (size == 0)
307 filp->f_pos = uio.uio_offset & 0x7fffffff;
308 else if (dbp)
309 filp->f_pos = curr_offset;
310 }
311
312 kfree(read_buf);
313 return -error;
314}
315
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100317xfs_file_mmap(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 struct file *filp,
319 struct vm_area_struct *vma)
320{
Nathan Scott3562fd42006-03-14 14:00:35 +1100321 vma->vm_ops = &xfs_file_vm_ops;
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000322
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000323#ifdef CONFIG_XFS_DMAPI
Josef "Jeff" Sipeke678fb02006-12-08 02:36:49 -0800324 if (vn_from_inode(filp->f_path.dentry->d_inode)->v_vfsp->vfs_flag & VFS_DMI)
Nathan Scott3562fd42006-03-14 14:00:35 +1100325 vma->vm_ops = &xfs_dmapi_file_vm_ops;
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000326#endif /* CONFIG_XFS_DMAPI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Nathan Scottfbc14622006-06-09 14:52:13 +1000328 file_accessed(filp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 return 0;
330}
331
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332STATIC long
Nathan Scott3562fd42006-03-14 14:00:35 +1100333xfs_file_ioctl(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 struct file *filp,
335 unsigned int cmd,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000336 unsigned long p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
338 int error;
Josef "Jeff" Sipeke678fb02006-12-08 02:36:49 -0800339 struct inode *inode = filp->f_path.dentry->d_inode;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000340 bhv_vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Nathan Scott67fcaa72006-06-09 17:00:52 +1000342 error = bhv_vop_ioctl(vp, inode, filp, 0, cmd, (void __user *)p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 VMODIFY(vp);
344
345 /* NOTE: some of the ioctl's return positive #'s as a
346 * byte count indicating success, such as
347 * readlink_by_handle. So we don't "sign flip"
348 * like most other routines. This means true
349 * errors need to be returned as a negative value.
350 */
351 return error;
352}
353
354STATIC long
Nathan Scott3562fd42006-03-14 14:00:35 +1100355xfs_file_ioctl_invis(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 struct file *filp,
357 unsigned int cmd,
Nathan Scott67fcaa72006-06-09 17:00:52 +1000358 unsigned long p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359{
Nathan Scott1b895842006-03-31 13:08:59 +1000360 int error;
Josef "Jeff" Sipeke678fb02006-12-08 02:36:49 -0800361 struct inode *inode = filp->f_path.dentry->d_inode;
Nathan Scott67fcaa72006-06-09 17:00:52 +1000362 bhv_vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
Nathan Scott67fcaa72006-06-09 17:00:52 +1000364 error = bhv_vop_ioctl(vp, inode, filp, IO_INVIS, cmd, (void __user *)p);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 VMODIFY(vp);
366
367 /* NOTE: some of the ioctl's return positive #'s as a
368 * byte count indicating success, such as
369 * readlink_by_handle. So we don't "sign flip"
370 * like most other routines. This means true
371 * errors need to be returned as a negative value.
372 */
373 return error;
374}
375
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000376#ifdef CONFIG_XFS_DMAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377#ifdef HAVE_VMOP_MPROTECT
378STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100379xfs_vm_mprotect(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 struct vm_area_struct *vma,
381 unsigned int newflags)
382{
Josef "Jeff" Sipeke678fb02006-12-08 02:36:49 -0800383 bhv_vnode_t *vp = vn_from_inode(vma->vm_file->f_path.dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 int error = 0;
385
386 if (vp->v_vfsp->vfs_flag & VFS_DMI) {
387 if ((vma->vm_flags & VM_MAYSHARE) &&
388 (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE)) {
389 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
390
391 error = XFS_SEND_MMAP(mp, vma, VM_WRITE);
392 }
393 }
394 return error;
395}
396#endif /* HAVE_VMOP_MPROTECT */
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000397#endif /* CONFIG_XFS_DMAPI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399#ifdef HAVE_FOP_OPEN_EXEC
400/* If the user is attempting to execute a file that is offline then
401 * we have to trigger a DMAPI READ event before the file is marked as busy
402 * otherwise the invisible I/O will not be able to write to the file to bring
403 * it back online.
404 */
405STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100406xfs_file_open_exec(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 struct inode *inode)
408{
Nathan Scott67fcaa72006-06-09 17:00:52 +1000409 bhv_vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410
Nathan Scott1d47bec2006-06-19 08:39:16 +1000411 if (unlikely(vp->v_vfsp->vfs_flag & VFS_DMI)) {
412 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
413 xfs_inode_t *ip = xfs_vtoi(vp);
414
415 if (!ip)
416 return -EINVAL;
417 if (DM_EVENT_ENABLED(vp->v_vfsp, ip, DM_EVENT_READ))
418 return -XFS_SEND_DATA(mp, DM_EVENT_READ, vp,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 0, 0, 0, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 }
Nathan Scott1d47bec2006-06-19 08:39:16 +1000421 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422}
423#endif /* HAVE_FOP_OPEN_EXEC */
424
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800425const struct file_operations xfs_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 .llseek = generic_file_llseek,
427 .read = do_sync_read,
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000428 .write = do_sync_write,
Nathan Scott3562fd42006-03-14 14:00:35 +1100429 .aio_read = xfs_file_aio_read,
430 .aio_write = xfs_file_aio_write,
Nathan Scott1b895842006-03-31 13:08:59 +1000431 .splice_read = xfs_file_splice_read,
432 .splice_write = xfs_file_splice_write,
Nathan Scott3562fd42006-03-14 14:00:35 +1100433 .unlocked_ioctl = xfs_file_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434#ifdef CONFIG_COMPAT
Nathan Scott3562fd42006-03-14 14:00:35 +1100435 .compat_ioctl = xfs_file_compat_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436#endif
Nathan Scott3562fd42006-03-14 14:00:35 +1100437 .mmap = xfs_file_mmap,
438 .open = xfs_file_open,
Nathan Scott7d4fb402006-06-09 15:27:16 +1000439 .flush = xfs_file_close,
Nathan Scott3562fd42006-03-14 14:00:35 +1100440 .release = xfs_file_release,
441 .fsync = xfs_file_fsync,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442#ifdef HAVE_FOP_OPEN_EXEC
Nathan Scott3562fd42006-03-14 14:00:35 +1100443 .open_exec = xfs_file_open_exec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444#endif
445};
446
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800447const struct file_operations xfs_invis_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 .llseek = generic_file_llseek,
449 .read = do_sync_read,
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000450 .write = do_sync_write,
Nathan Scott3562fd42006-03-14 14:00:35 +1100451 .aio_read = xfs_file_aio_read_invis,
452 .aio_write = xfs_file_aio_write_invis,
Nathan Scott1b895842006-03-31 13:08:59 +1000453 .splice_read = xfs_file_splice_read_invis,
454 .splice_write = xfs_file_splice_write_invis,
Nathan Scott3562fd42006-03-14 14:00:35 +1100455 .unlocked_ioctl = xfs_file_ioctl_invis,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456#ifdef CONFIG_COMPAT
Nathan Scott3562fd42006-03-14 14:00:35 +1100457 .compat_ioctl = xfs_file_compat_invis_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458#endif
Nathan Scott3562fd42006-03-14 14:00:35 +1100459 .mmap = xfs_file_mmap,
460 .open = xfs_file_open,
Nathan Scott7d4fb402006-06-09 15:27:16 +1000461 .flush = xfs_file_close,
Nathan Scott3562fd42006-03-14 14:00:35 +1100462 .release = xfs_file_release,
463 .fsync = xfs_file_fsync,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464};
465
466
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800467const struct file_operations xfs_dir_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 .read = generic_read_dir,
Nathan Scott3562fd42006-03-14 14:00:35 +1100469 .readdir = xfs_file_readdir,
470 .unlocked_ioctl = xfs_file_ioctl,
Nathan Scottd3870392005-05-06 06:44:46 -0700471#ifdef CONFIG_COMPAT
Nathan Scott3562fd42006-03-14 14:00:35 +1100472 .compat_ioctl = xfs_file_compat_ioctl,
Nathan Scottd3870392005-05-06 06:44:46 -0700473#endif
Nathan Scott3562fd42006-03-14 14:00:35 +1100474 .fsync = xfs_file_fsync,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475};
476
Nathan Scott3562fd42006-03-14 14:00:35 +1100477static struct vm_operations_struct xfs_file_vm_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 .nopage = filemap_nopage,
479 .populate = filemap_populate,
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000480};
481
482#ifdef CONFIG_XFS_DMAPI
Nathan Scott3562fd42006-03-14 14:00:35 +1100483static struct vm_operations_struct xfs_dmapi_file_vm_ops = {
484 .nopage = xfs_vm_nopage,
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000485 .populate = filemap_populate,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486#ifdef HAVE_VMOP_MPROTECT
Nathan Scott3562fd42006-03-14 14:00:35 +1100487 .mprotect = xfs_vm_mprotect,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488#endif
489};
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000490#endif /* CONFIG_XFS_DMAPI */