2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * 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.
14 * 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
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"
34 #include "xfs_dir2_sf.h"
35 #include "xfs_dinode.h"
36 #include "xfs_inode.h"
37 #include "xfs_error.h"
39 #include "xfs_ioctl32.h"
41 #include <linux/dcache.h>
42 #include <linux/smp_lock.h>
44 static struct vm_operations_struct xfs_file_vm_ops;
45 #ifdef CONFIG_XFS_DMAPI
46 static struct vm_operations_struct xfs_dmapi_file_vm_ops;
52 const struct iovec *iov,
53 unsigned long nr_segs,
57 struct file *file = iocb->ki_filp;
58 bhv_vnode_t *vp = vn_from_inode(file->f_path.dentry->d_inode);
60 BUG_ON(iocb->ki_pos != pos);
61 if (unlikely(file->f_flags & O_DIRECT))
62 ioflags |= IO_ISDIRECT;
63 return bhv_vop_read(vp, iocb, iov, nr_segs, &iocb->ki_pos,
70 const struct iovec *iov,
71 unsigned long nr_segs,
74 return __xfs_file_read(iocb, iov, nr_segs, IO_ISAIO, pos);
78 xfs_file_aio_read_invis(
80 const struct iovec *iov,
81 unsigned long nr_segs,
84 return __xfs_file_read(iocb, iov, nr_segs, IO_ISAIO|IO_INVIS, pos);
90 const struct iovec *iov,
91 unsigned long nr_segs,
95 struct file *file = iocb->ki_filp;
96 struct inode *inode = file->f_mapping->host;
97 bhv_vnode_t *vp = vn_from_inode(inode);
99 BUG_ON(iocb->ki_pos != pos);
100 if (unlikely(file->f_flags & O_DIRECT))
101 ioflags |= IO_ISDIRECT;
102 return bhv_vop_write(vp, iocb, iov, nr_segs, &iocb->ki_pos,
109 const struct iovec *iov,
110 unsigned long nr_segs,
113 return __xfs_file_write(iocb, iov, nr_segs, IO_ISAIO, pos);
117 xfs_file_aio_write_invis(
119 const struct iovec *iov,
120 unsigned long nr_segs,
123 return __xfs_file_write(iocb, iov, nr_segs, IO_ISAIO|IO_INVIS, pos);
134 return bhv_vop_sendfile(vn_from_inode(filp->f_path.dentry->d_inode),
135 filp, pos, 0, count, actor, target, NULL);
139 xfs_file_sendfile_invis(
146 return bhv_vop_sendfile(vn_from_inode(filp->f_path.dentry->d_inode),
147 filp, pos, IO_INVIS, count, actor, target, NULL);
151 xfs_file_splice_read(
154 struct pipe_inode_info *pipe,
158 return bhv_vop_splice_read(vn_from_inode(infilp->f_path.dentry->d_inode),
159 infilp, ppos, pipe, len, flags, 0, NULL);
163 xfs_file_splice_read_invis(
166 struct pipe_inode_info *pipe,
170 return bhv_vop_splice_read(vn_from_inode(infilp->f_path.dentry->d_inode),
171 infilp, ppos, pipe, len, flags, IO_INVIS,
176 xfs_file_splice_write(
177 struct pipe_inode_info *pipe,
178 struct file *outfilp,
183 return bhv_vop_splice_write(vn_from_inode(outfilp->f_path.dentry->d_inode),
184 pipe, outfilp, ppos, len, flags, 0, NULL);
188 xfs_file_splice_write_invis(
189 struct pipe_inode_info *pipe,
190 struct file *outfilp,
195 return bhv_vop_splice_write(vn_from_inode(outfilp->f_path.dentry->d_inode),
196 pipe, outfilp, ppos, len, flags, IO_INVIS,
205 if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
207 return -bhv_vop_open(vn_from_inode(inode), NULL);
215 return -bhv_vop_close(vn_from_inode(filp->f_path.dentry->d_inode), 0,
216 file_count(filp) > 1 ? L_FALSE : L_TRUE, NULL);
224 bhv_vnode_t *vp = vn_from_inode(inode);
227 return -bhv_vop_release(vp);
234 struct dentry *dentry,
237 bhv_vnode_t *vp = vn_from_inode(dentry->d_inode);
238 int flags = FSYNC_WAIT;
244 return -bhv_vop_fsync(vp, flags, NULL, (xfs_off_t)0, (xfs_off_t)-1);
247 #ifdef CONFIG_XFS_DMAPI
250 struct vm_area_struct *area,
251 unsigned long address,
254 struct inode *inode = area->vm_file->f_path.dentry->d_inode;
255 bhv_vnode_t *vp = vn_from_inode(inode);
257 ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI);
258 if (XFS_SEND_MMAP(XFS_VFSTOM(vp->v_vfsp), area, 0))
260 return filemap_nopage(area, address, type);
262 #endif /* CONFIG_XFS_DMAPI */
271 bhv_vnode_t *vp = vn_from_inode(filp->f_path.dentry->d_inode);
276 int namelen, size = 0;
277 size_t rlen = PAGE_CACHE_SIZE;
278 xfs_off_t start_offset, curr_offset;
279 xfs_dirent_t *dbp = NULL;
281 /* Try fairly hard to get memory */
283 if ((read_buf = kmalloc(rlen, GFP_KERNEL)))
286 } while (rlen >= 1024);
288 if (read_buf == NULL)
292 uio.uio_segflg = UIO_SYSSPACE;
293 curr_offset = filp->f_pos;
294 if (filp->f_pos != 0x7fffffff)
295 uio.uio_offset = filp->f_pos;
297 uio.uio_offset = 0xffffffff;
300 uio.uio_resid = iov.iov_len = rlen;
301 iov.iov_base = read_buf;
304 start_offset = uio.uio_offset;
306 error = bhv_vop_readdir(vp, &uio, NULL, &eof);
307 if ((uio.uio_offset == start_offset) || error) {
312 size = rlen - uio.uio_resid;
313 dbp = (xfs_dirent_t *)read_buf;
315 namelen = strlen(dbp->d_name);
317 if (filldir(dirent, dbp->d_name, namelen,
318 (loff_t) curr_offset & 0x7fffffff,
323 size -= dbp->d_reclen;
324 curr_offset = (loff_t)dbp->d_off /* & 0x7fffffff */;
325 dbp = (xfs_dirent_t *)((char *)dbp + dbp->d_reclen);
331 filp->f_pos = uio.uio_offset & 0x7fffffff;
333 filp->f_pos = curr_offset;
343 struct vm_area_struct *vma)
345 vma->vm_ops = &xfs_file_vm_ops;
347 #ifdef CONFIG_XFS_DMAPI
348 if (vn_from_inode(filp->f_path.dentry->d_inode)->v_vfsp->vfs_flag & VFS_DMI)
349 vma->vm_ops = &xfs_dmapi_file_vm_ops;
350 #endif /* CONFIG_XFS_DMAPI */
363 struct inode *inode = filp->f_path.dentry->d_inode;
364 bhv_vnode_t *vp = vn_from_inode(inode);
366 error = bhv_vop_ioctl(vp, inode, filp, 0, cmd, (void __user *)p);
369 /* NOTE: some of the ioctl's return positive #'s as a
370 * byte count indicating success, such as
371 * readlink_by_handle. So we don't "sign flip"
372 * like most other routines. This means true
373 * errors need to be returned as a negative value.
379 xfs_file_ioctl_invis(
385 struct inode *inode = filp->f_path.dentry->d_inode;
386 bhv_vnode_t *vp = vn_from_inode(inode);
388 error = bhv_vop_ioctl(vp, inode, filp, IO_INVIS, cmd, (void __user *)p);
391 /* NOTE: some of the ioctl's return positive #'s as a
392 * byte count indicating success, such as
393 * readlink_by_handle. So we don't "sign flip"
394 * like most other routines. This means true
395 * errors need to be returned as a negative value.
400 #ifdef CONFIG_XFS_DMAPI
401 #ifdef HAVE_VMOP_MPROTECT
404 struct vm_area_struct *vma,
405 unsigned int newflags)
407 bhv_vnode_t *vp = vn_from_inode(vma->vm_file->f_path.dentry->d_inode);
410 if (vp->v_vfsp->vfs_flag & VFS_DMI) {
411 if ((vma->vm_flags & VM_MAYSHARE) &&
412 (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE)) {
413 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
415 error = XFS_SEND_MMAP(mp, vma, VM_WRITE);
420 #endif /* HAVE_VMOP_MPROTECT */
421 #endif /* CONFIG_XFS_DMAPI */
423 #ifdef HAVE_FOP_OPEN_EXEC
424 /* If the user is attempting to execute a file that is offline then
425 * we have to trigger a DMAPI READ event before the file is marked as busy
426 * otherwise the invisible I/O will not be able to write to the file to bring
433 bhv_vnode_t *vp = vn_from_inode(inode);
435 if (unlikely(vp->v_vfsp->vfs_flag & VFS_DMI)) {
436 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
437 xfs_inode_t *ip = xfs_vtoi(vp);
441 if (DM_EVENT_ENABLED(vp->v_vfsp, ip, DM_EVENT_READ))
442 return -XFS_SEND_DATA(mp, DM_EVENT_READ, vp,
447 #endif /* HAVE_FOP_OPEN_EXEC */
449 const struct file_operations xfs_file_operations = {
450 .llseek = generic_file_llseek,
451 .read = do_sync_read,
452 .write = do_sync_write,
453 .aio_read = xfs_file_aio_read,
454 .aio_write = xfs_file_aio_write,
455 .sendfile = xfs_file_sendfile,
456 .splice_read = xfs_file_splice_read,
457 .splice_write = xfs_file_splice_write,
458 .unlocked_ioctl = xfs_file_ioctl,
460 .compat_ioctl = xfs_file_compat_ioctl,
462 .mmap = xfs_file_mmap,
463 .open = xfs_file_open,
464 .flush = xfs_file_close,
465 .release = xfs_file_release,
466 .fsync = xfs_file_fsync,
467 #ifdef HAVE_FOP_OPEN_EXEC
468 .open_exec = xfs_file_open_exec,
472 const struct file_operations xfs_invis_file_operations = {
473 .llseek = generic_file_llseek,
474 .read = do_sync_read,
475 .write = do_sync_write,
476 .aio_read = xfs_file_aio_read_invis,
477 .aio_write = xfs_file_aio_write_invis,
478 .sendfile = xfs_file_sendfile_invis,
479 .splice_read = xfs_file_splice_read_invis,
480 .splice_write = xfs_file_splice_write_invis,
481 .unlocked_ioctl = xfs_file_ioctl_invis,
483 .compat_ioctl = xfs_file_compat_invis_ioctl,
485 .mmap = xfs_file_mmap,
486 .open = xfs_file_open,
487 .flush = xfs_file_close,
488 .release = xfs_file_release,
489 .fsync = xfs_file_fsync,
493 const struct file_operations xfs_dir_file_operations = {
494 .read = generic_read_dir,
495 .readdir = xfs_file_readdir,
496 .unlocked_ioctl = xfs_file_ioctl,
498 .compat_ioctl = xfs_file_compat_ioctl,
500 .fsync = xfs_file_fsync,
503 static struct vm_operations_struct xfs_file_vm_ops = {
504 .nopage = filemap_nopage,
505 .populate = filemap_populate,
508 #ifdef CONFIG_XFS_DMAPI
509 static struct vm_operations_struct xfs_dmapi_file_vm_ops = {
510 .nopage = xfs_vm_nopage,
511 .populate = filemap_populate,
512 #ifdef HAVE_VMOP_MPROTECT
513 .mprotect = xfs_vm_mprotect,
516 #endif /* CONFIG_XFS_DMAPI */