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
;
70 struct iovec iov
= {buf
, count
};
71 struct file
*file
= iocb
->ki_filp
;
72 vnode_t
*vp
= LINVFS_GET_VP(file
->f_dentry
->d_inode
);
75 BUG_ON(iocb
->ki_pos
!= pos
);
77 if (unlikely(file
->f_flags
& O_DIRECT
))
78 ioflags
|= IO_ISDIRECT
;
79 VOP_READ(vp
, iocb
, &iov
, 1, &iocb
->ki_pos
, ioflags
, NULL
, rval
);
91 return __linvfs_read(iocb
, buf
, IO_ISAIO
, count
, pos
);
95 linvfs_aio_read_invis(
101 return __linvfs_read(iocb
, buf
, IO_ISAIO
|IO_INVIS
, count
, pos
);
105 STATIC
inline ssize_t
108 const char __user
*buf
,
113 struct iovec iov
= {(void __user
*)buf
, count
};
114 struct file
*file
= iocb
->ki_filp
;
115 struct inode
*inode
= file
->f_mapping
->host
;
116 vnode_t
*vp
= LINVFS_GET_VP(inode
);
119 BUG_ON(iocb
->ki_pos
!= pos
);
120 if (unlikely(file
->f_flags
& O_DIRECT
))
121 ioflags
|= IO_ISDIRECT
;
123 VOP_WRITE(vp
, iocb
, &iov
, 1, &iocb
->ki_pos
, ioflags
, NULL
, rval
);
131 const char __user
*buf
,
135 return __linvfs_write(iocb
, buf
, IO_ISAIO
, count
, pos
);
139 linvfs_aio_write_invis(
141 const char __user
*buf
,
145 return __linvfs_write(iocb
, buf
, IO_ISAIO
|IO_INVIS
, count
, pos
);
149 STATIC
inline ssize_t
152 const struct iovec
*iov
,
154 unsigned long nr_segs
,
157 struct inode
*inode
= file
->f_mapping
->host
;
158 vnode_t
*vp
= LINVFS_GET_VP(inode
);
162 init_sync_kiocb(&kiocb
, file
);
163 kiocb
.ki_pos
= *ppos
;
165 if (unlikely(file
->f_flags
& O_DIRECT
))
166 ioflags
|= IO_ISDIRECT
;
167 VOP_READ(vp
, &kiocb
, iov
, nr_segs
, &kiocb
.ki_pos
, ioflags
, NULL
, rval
);
169 *ppos
= kiocb
.ki_pos
;
176 const struct iovec
*iov
,
177 unsigned long nr_segs
,
180 return __linvfs_readv(file
, iov
, 0, nr_segs
, ppos
);
186 const struct iovec
*iov
,
187 unsigned long nr_segs
,
190 return __linvfs_readv(file
, iov
, IO_INVIS
, nr_segs
, ppos
);
194 STATIC
inline ssize_t
197 const struct iovec
*iov
,
199 unsigned long nr_segs
,
202 struct inode
*inode
= file
->f_mapping
->host
;
203 vnode_t
*vp
= LINVFS_GET_VP(inode
);
207 init_sync_kiocb(&kiocb
, file
);
208 kiocb
.ki_pos
= *ppos
;
209 if (unlikely(file
->f_flags
& O_DIRECT
))
210 ioflags
|= IO_ISDIRECT
;
212 VOP_WRITE(vp
, &kiocb
, iov
, nr_segs
, &kiocb
.ki_pos
, ioflags
, NULL
, rval
);
214 *ppos
= kiocb
.ki_pos
;
222 const struct iovec
*iov
,
223 unsigned long nr_segs
,
226 return __linvfs_writev(file
, iov
, 0, nr_segs
, ppos
);
232 const struct iovec
*iov
,
233 unsigned long nr_segs
,
236 return __linvfs_writev(file
, iov
, IO_INVIS
, nr_segs
, ppos
);
247 vnode_t
*vp
= LINVFS_GET_VP(filp
->f_dentry
->d_inode
);
250 VOP_SENDFILE(vp
, filp
, ppos
, 0, count
, actor
, target
, NULL
, rval
);
260 vnode_t
*vp
= LINVFS_GET_VP(inode
);
263 if (!(filp
->f_flags
& O_LARGEFILE
) && i_size_read(inode
) > MAX_NON_LFS
)
267 VOP_OPEN(vp
, NULL
, error
);
277 vnode_t
*vp
= LINVFS_GET_VP(inode
);
281 VOP_RELEASE(vp
, error
);
289 struct dentry
*dentry
,
292 struct inode
*inode
= dentry
->d_inode
;
293 vnode_t
*vp
= LINVFS_GET_VP(inode
);
295 int flags
= FSYNC_WAIT
;
301 VOP_FSYNC(vp
, flags
, NULL
, (xfs_off_t
)0, (xfs_off_t
)-1, error
);
306 * linvfs_readdir maps to VOP_READDIR().
307 * We need to build a uio, cred, ...
310 #define nextdp(dp) ((struct xfs_dirent *)((char *)(dp) + (dp)->d_reclen))
324 int namelen
, size
= 0;
325 size_t rlen
= PAGE_CACHE_SIZE
;
326 xfs_off_t start_offset
, curr_offset
;
327 xfs_dirent_t
*dbp
= NULL
;
329 vp
= LINVFS_GET_VP(filp
->f_dentry
->d_inode
);
332 /* Try fairly hard to get memory */
334 if ((read_buf
= (caddr_t
)kmalloc(rlen
, GFP_KERNEL
)))
337 } while (rlen
>= 1024);
339 if (read_buf
== NULL
)
343 uio
.uio_segflg
= UIO_SYSSPACE
;
344 curr_offset
= filp
->f_pos
;
345 if (filp
->f_pos
!= 0x7fffffff)
346 uio
.uio_offset
= filp
->f_pos
;
348 uio
.uio_offset
= 0xffffffff;
351 uio
.uio_resid
= iov
.iov_len
= rlen
;
352 iov
.iov_base
= read_buf
;
355 start_offset
= uio
.uio_offset
;
357 VOP_READDIR(vp
, &uio
, NULL
, &eof
, error
);
358 if ((uio
.uio_offset
== start_offset
) || error
) {
363 size
= rlen
- uio
.uio_resid
;
364 dbp
= (xfs_dirent_t
*)read_buf
;
366 namelen
= strlen(dbp
->d_name
);
368 if (filldir(dirent
, dbp
->d_name
, namelen
,
369 (loff_t
) curr_offset
& 0x7fffffff,
374 size
-= dbp
->d_reclen
;
375 curr_offset
= (loff_t
)dbp
->d_off
/* & 0x7fffffff */;
382 filp
->f_pos
= uio
.uio_offset
& 0x7fffffff;
384 filp
->f_pos
= curr_offset
;
395 struct vm_area_struct
*vma
)
397 struct inode
*ip
= filp
->f_dentry
->d_inode
;
398 vnode_t
*vp
= LINVFS_GET_VP(ip
);
399 vattr_t va
= { .va_mask
= XFS_AT_UPDATIME
};
402 if (vp
->v_vfsp
->vfs_flag
& VFS_DMI
) {
403 xfs_mount_t
*mp
= XFS_VFSTOM(vp
->v_vfsp
);
405 error
= -XFS_SEND_MMAP(mp
, vma
, 0);
410 vma
->vm_ops
= &linvfs_file_vm_ops
;
412 VOP_SETATTR(vp
, &va
, XFS_AT_UPDATIME
, NULL
, error
);
414 vn_revalidate(vp
); /* update Linux inode flags */
426 struct inode
*inode
= filp
->f_dentry
->d_inode
;
427 vnode_t
*vp
= LINVFS_GET_VP(inode
);
429 VOP_IOCTL(vp
, inode
, filp
, 0, cmd
, (void __user
*)arg
, error
);
432 /* NOTE: some of the ioctl's return positive #'s as a
433 * byte count indicating success, such as
434 * readlink_by_handle. So we don't "sign flip"
435 * like most other routines. This means true
436 * errors need to be returned as a negative value.
448 struct inode
*inode
= filp
->f_dentry
->d_inode
;
449 vnode_t
*vp
= LINVFS_GET_VP(inode
);
452 VOP_IOCTL(vp
, inode
, filp
, IO_INVIS
, cmd
, (void __user
*)arg
, error
);
455 /* NOTE: some of the ioctl's return positive #'s as a
456 * byte count indicating success, such as
457 * readlink_by_handle. So we don't "sign flip"
458 * like most other routines. This means true
459 * errors need to be returned as a negative value.
464 #ifdef HAVE_VMOP_MPROTECT
467 struct vm_area_struct
*vma
,
468 unsigned int newflags
)
470 vnode_t
*vp
= LINVFS_GET_VP(vma
->vm_file
->f_dentry
->d_inode
);
473 if (vp
->v_vfsp
->vfs_flag
& VFS_DMI
) {
474 if ((vma
->vm_flags
& VM_MAYSHARE
) &&
475 (newflags
& VM_WRITE
) && !(vma
->vm_flags
& VM_WRITE
)) {
476 xfs_mount_t
*mp
= XFS_VFSTOM(vp
->v_vfsp
);
478 error
= XFS_SEND_MMAP(mp
, vma
, VM_WRITE
);
483 #endif /* HAVE_VMOP_MPROTECT */
485 #ifdef HAVE_FOP_OPEN_EXEC
486 /* If the user is attempting to execute a file that is offline then
487 * we have to trigger a DMAPI READ event before the file is marked as busy
488 * otherwise the invisible I/O will not be able to write to the file to bring
495 vnode_t
*vp
= LINVFS_GET_VP(inode
);
496 xfs_mount_t
*mp
= XFS_VFSTOM(vp
->v_vfsp
);
501 if (vp
->v_vfsp
->vfs_flag
& VFS_DMI
) {
502 bdp
= vn_bhv_lookup(VN_BHV_HEAD(vp
), &xfs_vnodeops
);
507 ip
= XFS_BHVTOI(bdp
);
508 if (DM_EVENT_ENABLED(vp
->v_vfsp
, ip
, DM_EVENT_READ
)) {
509 error
= -XFS_SEND_DATA(mp
, DM_EVENT_READ
, vp
,
516 #endif /* HAVE_FOP_OPEN_EXEC */
519 * Temporary workaround to the AIO direct IO write problem.
520 * This code can go and we can revert to do_sync_write once
521 * the writepage(s) rework is merged.
526 const char __user
*buf
,
533 init_sync_kiocb(&kiocb
, filp
);
534 kiocb
.ki_pos
= *ppos
;
535 ret
= __linvfs_write(&kiocb
, buf
, 0, len
, kiocb
.ki_pos
);
536 *ppos
= kiocb
.ki_pos
;
542 const char __user
*buf
,
549 init_sync_kiocb(&kiocb
, filp
);
550 kiocb
.ki_pos
= *ppos
;
551 ret
= __linvfs_write(&kiocb
, buf
, IO_INVIS
, len
, kiocb
.ki_pos
);
552 *ppos
= kiocb
.ki_pos
;
557 struct file_operations linvfs_file_operations
= {
558 .llseek
= generic_file_llseek
,
559 .read
= do_sync_read
,
560 .write
= linvfs_write
,
561 .readv
= linvfs_readv
,
562 .writev
= linvfs_writev
,
563 .aio_read
= linvfs_aio_read
,
564 .aio_write
= linvfs_aio_write
,
565 .sendfile
= linvfs_sendfile
,
566 .unlocked_ioctl
= linvfs_ioctl
,
568 .compat_ioctl
= linvfs_compat_ioctl
,
570 .mmap
= linvfs_file_mmap
,
572 .release
= linvfs_release
,
573 .fsync
= linvfs_fsync
,
574 #ifdef HAVE_FOP_OPEN_EXEC
575 .open_exec
= linvfs_open_exec
,
579 struct file_operations linvfs_invis_file_operations
= {
580 .llseek
= generic_file_llseek
,
581 .read
= do_sync_read
,
582 .write
= linvfs_write_invis
,
583 .readv
= linvfs_readv_invis
,
584 .writev
= linvfs_writev_invis
,
585 .aio_read
= linvfs_aio_read_invis
,
586 .aio_write
= linvfs_aio_write_invis
,
587 .sendfile
= linvfs_sendfile
,
588 .unlocked_ioctl
= linvfs_ioctl_invis
,
590 .compat_ioctl
= linvfs_compat_invis_ioctl
,
592 .mmap
= linvfs_file_mmap
,
594 .release
= linvfs_release
,
595 .fsync
= linvfs_fsync
,
599 struct file_operations linvfs_dir_operations
= {
600 .read
= generic_read_dir
,
601 .readdir
= linvfs_readdir
,
602 .unlocked_ioctl
= linvfs_ioctl
,
604 .compat_ioctl
= linvfs_compat_ioctl
,
606 .fsync
= linvfs_fsync
,
609 static struct vm_operations_struct linvfs_file_vm_ops
= {
610 .nopage
= filemap_nopage
,
611 .populate
= filemap_populate
,
612 #ifdef HAVE_VMOP_MPROTECT
613 .mprotect
= linvfs_mprotect
,