2 * Copyright (c) 2000-2005 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
39 #include "xfs_trans.h"
40 #include "xfs_dmapi.h"
41 #include "xfs_mount.h"
42 #include "xfs_bmap_btree.h"
43 #include "xfs_alloc_btree.h"
44 #include "xfs_ialloc_btree.h"
45 #include "xfs_alloc.h"
46 #include "xfs_btree.h"
47 #include "xfs_attr_sf.h"
48 #include "xfs_dir_sf.h"
49 #include "xfs_dir2_sf.h"
50 #include "xfs_dinode.h"
51 #include "xfs_inode.h"
52 #include "xfs_error.h"
54 #include "xfs_ioctl32.h"
56 #include <linux/dcache.h>
57 #include <linux/smp_lock.h>
59 static struct vm_operations_struct linvfs_file_vm_ops;
60 #ifdef CONFIG_XFS_DMAPI
61 static struct vm_operations_struct linvfs_dmapi_file_vm_ops;
72 struct iovec iov = {buf, count};
73 struct file *file = iocb->ki_filp;
74 vnode_t *vp = LINVFS_GET_VP(file->f_dentry->d_inode);
77 BUG_ON(iocb->ki_pos != pos);
79 if (unlikely(file->f_flags & O_DIRECT))
80 ioflags |= IO_ISDIRECT;
81 VOP_READ(vp, iocb, &iov, 1, &iocb->ki_pos, ioflags, NULL, rval);
93 return __linvfs_read(iocb, buf, IO_ISAIO, count, pos);
97 linvfs_aio_read_invis(
103 return __linvfs_read(iocb, buf, IO_ISAIO|IO_INVIS, count, pos);
107 STATIC inline ssize_t
110 const char __user *buf,
115 struct iovec iov = {(void __user *)buf, count};
116 struct file *file = iocb->ki_filp;
117 struct inode *inode = file->f_mapping->host;
118 vnode_t *vp = LINVFS_GET_VP(inode);
121 BUG_ON(iocb->ki_pos != pos);
122 if (unlikely(file->f_flags & O_DIRECT))
123 ioflags |= IO_ISDIRECT;
125 VOP_WRITE(vp, iocb, &iov, 1, &iocb->ki_pos, ioflags, NULL, rval);
133 const char __user *buf,
137 return __linvfs_write(iocb, buf, IO_ISAIO, count, pos);
141 linvfs_aio_write_invis(
143 const char __user *buf,
147 return __linvfs_write(iocb, buf, IO_ISAIO|IO_INVIS, count, pos);
151 STATIC inline ssize_t
154 const struct iovec *iov,
156 unsigned long nr_segs,
159 struct inode *inode = file->f_mapping->host;
160 vnode_t *vp = LINVFS_GET_VP(inode);
164 init_sync_kiocb(&kiocb, file);
165 kiocb.ki_pos = *ppos;
167 if (unlikely(file->f_flags & O_DIRECT))
168 ioflags |= IO_ISDIRECT;
169 VOP_READ(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos, ioflags, NULL, rval);
171 *ppos = kiocb.ki_pos;
178 const struct iovec *iov,
179 unsigned long nr_segs,
182 return __linvfs_readv(file, iov, 0, nr_segs, ppos);
188 const struct iovec *iov,
189 unsigned long nr_segs,
192 return __linvfs_readv(file, iov, IO_INVIS, nr_segs, ppos);
196 STATIC inline ssize_t
199 const struct iovec *iov,
201 unsigned long nr_segs,
204 struct inode *inode = file->f_mapping->host;
205 vnode_t *vp = LINVFS_GET_VP(inode);
209 init_sync_kiocb(&kiocb, file);
210 kiocb.ki_pos = *ppos;
211 if (unlikely(file->f_flags & O_DIRECT))
212 ioflags |= IO_ISDIRECT;
214 VOP_WRITE(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos, ioflags, NULL, rval);
216 *ppos = kiocb.ki_pos;
224 const struct iovec *iov,
225 unsigned long nr_segs,
228 return __linvfs_writev(file, iov, 0, nr_segs, ppos);
234 const struct iovec *iov,
235 unsigned long nr_segs,
238 return __linvfs_writev(file, iov, IO_INVIS, nr_segs, ppos);
249 vnode_t *vp = LINVFS_GET_VP(filp->f_dentry->d_inode);
252 VOP_SENDFILE(vp, filp, ppos, 0, count, actor, target, NULL, rval);
262 vnode_t *vp = LINVFS_GET_VP(inode);
265 if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
269 VOP_OPEN(vp, NULL, error);
279 vnode_t *vp = LINVFS_GET_VP(inode);
283 VOP_RELEASE(vp, error);
291 struct dentry *dentry,
294 struct inode *inode = dentry->d_inode;
295 vnode_t *vp = LINVFS_GET_VP(inode);
297 int flags = FSYNC_WAIT;
303 VOP_FSYNC(vp, flags, NULL, (xfs_off_t)0, (xfs_off_t)-1, error);
308 * linvfs_readdir maps to VOP_READDIR().
309 * We need to build a uio, cred, ...
312 #define nextdp(dp) ((struct xfs_dirent *)((char *)(dp) + (dp)->d_reclen))
326 int namelen, size = 0;
327 size_t rlen = PAGE_CACHE_SIZE;
328 xfs_off_t start_offset, curr_offset;
329 xfs_dirent_t *dbp = NULL;
331 vp = LINVFS_GET_VP(filp->f_dentry->d_inode);
334 /* Try fairly hard to get memory */
336 if ((read_buf = (caddr_t)kmalloc(rlen, GFP_KERNEL)))
339 } while (rlen >= 1024);
341 if (read_buf == NULL)
345 uio.uio_segflg = UIO_SYSSPACE;
346 curr_offset = filp->f_pos;
347 if (filp->f_pos != 0x7fffffff)
348 uio.uio_offset = filp->f_pos;
350 uio.uio_offset = 0xffffffff;
353 uio.uio_resid = iov.iov_len = rlen;
354 iov.iov_base = read_buf;
357 start_offset = uio.uio_offset;
359 VOP_READDIR(vp, &uio, NULL, &eof, error);
360 if ((uio.uio_offset == start_offset) || error) {
365 size = rlen - uio.uio_resid;
366 dbp = (xfs_dirent_t *)read_buf;
368 namelen = strlen(dbp->d_name);
370 if (filldir(dirent, dbp->d_name, namelen,
371 (loff_t) curr_offset & 0x7fffffff,
376 size -= dbp->d_reclen;
377 curr_offset = (loff_t)dbp->d_off /* & 0x7fffffff */;
384 filp->f_pos = uio.uio_offset & 0x7fffffff;
386 filp->f_pos = curr_offset;
393 #ifdef CONFIG_XFS_DMAPI
396 struct vm_area_struct *vma)
400 #endif /* CONFIG_XFS_DMAPI */
405 struct vm_area_struct *vma)
407 struct inode *ip = filp->f_dentry->d_inode;
408 vnode_t *vp = LINVFS_GET_VP(ip);
409 vattr_t va = { .va_mask = XFS_AT_UPDATIME };
412 vma->vm_ops = &linvfs_file_vm_ops;
414 if (vp->v_vfsp->vfs_flag & VFS_DMI) {
415 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
417 error = -XFS_SEND_MMAP(mp, vma, 0);
420 #ifdef CONFIG_XFS_DMAPI
421 vma->vm_ops = &linvfs_dmapi_file_vm_ops;
425 VOP_SETATTR(vp, &va, XFS_AT_UPDATIME, NULL, error);
427 vn_revalidate(vp); /* update Linux inode flags */
439 struct inode *inode = filp->f_dentry->d_inode;
440 vnode_t *vp = LINVFS_GET_VP(inode);
442 VOP_IOCTL(vp, inode, filp, 0, cmd, (void __user *)arg, error);
445 /* NOTE: some of the ioctl's return positive #'s as a
446 * byte count indicating success, such as
447 * readlink_by_handle. So we don't "sign flip"
448 * like most other routines. This means true
449 * errors need to be returned as a negative value.
461 struct inode *inode = filp->f_dentry->d_inode;
462 vnode_t *vp = LINVFS_GET_VP(inode);
465 VOP_IOCTL(vp, inode, filp, IO_INVIS, cmd, (void __user *)arg, error);
468 /* NOTE: some of the ioctl's return positive #'s as a
469 * byte count indicating success, such as
470 * readlink_by_handle. So we don't "sign flip"
471 * like most other routines. This means true
472 * errors need to be returned as a negative value.
477 #ifdef HAVE_VMOP_MPROTECT
480 struct vm_area_struct *vma,
481 unsigned int newflags)
483 vnode_t *vp = LINVFS_GET_VP(vma->vm_file->f_dentry->d_inode);
486 if (vp->v_vfsp->vfs_flag & VFS_DMI) {
487 if ((vma->vm_flags & VM_MAYSHARE) &&
488 (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE)) {
489 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
491 error = XFS_SEND_MMAP(mp, vma, VM_WRITE);
496 #endif /* HAVE_VMOP_MPROTECT */
498 #ifdef HAVE_FOP_OPEN_EXEC
499 /* If the user is attempting to execute a file that is offline then
500 * we have to trigger a DMAPI READ event before the file is marked as busy
501 * otherwise the invisible I/O will not be able to write to the file to bring
508 vnode_t *vp = LINVFS_GET_VP(inode);
509 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
514 if (vp->v_vfsp->vfs_flag & VFS_DMI) {
515 bdp = vn_bhv_lookup(VN_BHV_HEAD(vp), &xfs_vnodeops);
520 ip = XFS_BHVTOI(bdp);
521 if (DM_EVENT_ENABLED(vp->v_vfsp, ip, DM_EVENT_READ)) {
522 error = -XFS_SEND_DATA(mp, DM_EVENT_READ, vp,
529 #endif /* HAVE_FOP_OPEN_EXEC */
532 * Temporary workaround to the AIO direct IO write problem.
533 * This code can go and we can revert to do_sync_write once
534 * the writepage(s) rework is merged.
539 const char __user *buf,
546 init_sync_kiocb(&kiocb, filp);
547 kiocb.ki_pos = *ppos;
548 ret = __linvfs_write(&kiocb, buf, 0, len, kiocb.ki_pos);
549 *ppos = kiocb.ki_pos;
555 const char __user *buf,
562 init_sync_kiocb(&kiocb, filp);
563 kiocb.ki_pos = *ppos;
564 ret = __linvfs_write(&kiocb, buf, IO_INVIS, len, kiocb.ki_pos);
565 *ppos = kiocb.ki_pos;
570 struct file_operations linvfs_file_operations = {
571 .llseek = generic_file_llseek,
572 .read = do_sync_read,
573 .write = linvfs_write,
574 .readv = linvfs_readv,
575 .writev = linvfs_writev,
576 .aio_read = linvfs_aio_read,
577 .aio_write = linvfs_aio_write,
578 .sendfile = linvfs_sendfile,
579 .unlocked_ioctl = linvfs_ioctl,
581 .compat_ioctl = linvfs_compat_ioctl,
583 .mmap = linvfs_file_mmap,
585 .release = linvfs_release,
586 .fsync = linvfs_fsync,
587 #ifdef HAVE_FOP_OPEN_EXEC
588 .open_exec = linvfs_open_exec,
592 struct file_operations linvfs_invis_file_operations = {
593 .llseek = generic_file_llseek,
594 .read = do_sync_read,
595 .write = linvfs_write_invis,
596 .readv = linvfs_readv_invis,
597 .writev = linvfs_writev_invis,
598 .aio_read = linvfs_aio_read_invis,
599 .aio_write = linvfs_aio_write_invis,
600 .sendfile = linvfs_sendfile,
601 .unlocked_ioctl = linvfs_ioctl_invis,
603 .compat_ioctl = linvfs_compat_invis_ioctl,
605 .mmap = linvfs_file_mmap,
607 .release = linvfs_release,
608 .fsync = linvfs_fsync,
612 struct file_operations linvfs_dir_operations = {
613 .read = generic_read_dir,
614 .readdir = linvfs_readdir,
615 .unlocked_ioctl = linvfs_ioctl,
617 .compat_ioctl = linvfs_compat_ioctl,
619 .fsync = linvfs_fsync,
622 static struct vm_operations_struct linvfs_file_vm_ops = {
623 .nopage = filemap_nopage,
624 .populate = filemap_populate,
627 #ifdef CONFIG_XFS_DMAPI
628 static struct vm_operations_struct linvfs_dmapi_file_vm_ops = {
629 .close = linvfs_mmap_close,
630 .nopage = filemap_nopage,
631 .populate = filemap_populate,
632 #ifdef HAVE_VMOP_MPROTECT
633 .mprotect = linvfs_mprotect,
636 #endif /* CONFIG_XFS_DMAPI */