Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 2 | * Copyright (c) 2000-2005 Silicon Graphics, Inc. |
| 3 | * All Rights Reserved. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * published by the Free Software Foundation. |
| 8 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * |
Nathan Scott | 7b71876 | 2005-11-02 14:58:39 +1100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include "xfs.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 19 | #include "xfs_bit.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include "xfs_log.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 21 | #include "xfs_inum.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "xfs_sb.h" |
Nathan Scott | a844f45 | 2005-11-02 14:38:42 +1100 | [diff] [blame] | 23 | #include "xfs_ag.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #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 Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 44 | static struct vm_operations_struct xfs_file_vm_ops; |
Dean Roehrich | 6fac0cb | 2005-06-21 14:07:45 +1000 | [diff] [blame] | 45 | #ifdef CONFIG_XFS_DMAPI |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 46 | static struct vm_operations_struct xfs_dmapi_file_vm_ops; |
Dean Roehrich | 6fac0cb | 2005-06-21 14:07:45 +1000 | [diff] [blame] | 47 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
David Chinner | 7989cb8 | 2007-02-10 18:34:56 +1100 | [diff] [blame] | 49 | STATIC_INLINE ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 50 | __xfs_file_read( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | struct kiocb *iocb, |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 52 | const struct iovec *iov, |
| 53 | unsigned long nr_segs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | int ioflags, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | loff_t pos) |
| 56 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | struct file *file = iocb->ki_filp; |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 58 | bhv_vnode_t *vp = vn_from_inode(file->f_path.dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | BUG_ON(iocb->ki_pos != pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | if (unlikely(file->f_flags & O_DIRECT)) |
| 62 | ioflags |= IO_ISDIRECT; |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 63 | return bhv_vop_read(vp, iocb, iov, nr_segs, &iocb->ki_pos, |
| 64 | ioflags, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | STATIC ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 68 | xfs_file_aio_read( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | struct kiocb *iocb, |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 70 | const struct iovec *iov, |
| 71 | unsigned long nr_segs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | loff_t pos) |
| 73 | { |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 74 | return __xfs_file_read(iocb, iov, nr_segs, IO_ISAIO, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | STATIC ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 78 | xfs_file_aio_read_invis( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | struct kiocb *iocb, |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 80 | const struct iovec *iov, |
| 81 | unsigned long nr_segs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | loff_t pos) |
| 83 | { |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 84 | return __xfs_file_read(iocb, iov, nr_segs, IO_ISAIO|IO_INVIS, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | } |
| 86 | |
David Chinner | 7989cb8 | 2007-02-10 18:34:56 +1100 | [diff] [blame] | 87 | STATIC_INLINE ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 88 | __xfs_file_write( |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 89 | struct kiocb *iocb, |
| 90 | const struct iovec *iov, |
| 91 | unsigned long nr_segs, |
| 92 | int ioflags, |
| 93 | loff_t pos) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | struct file *file = iocb->ki_filp; |
| 96 | struct inode *inode = file->f_mapping->host; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 97 | bhv_vnode_t *vp = vn_from_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | BUG_ON(iocb->ki_pos != pos); |
| 100 | if (unlikely(file->f_flags & O_DIRECT)) |
| 101 | ioflags |= IO_ISDIRECT; |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 102 | return bhv_vop_write(vp, iocb, iov, nr_segs, &iocb->ki_pos, |
| 103 | ioflags, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | STATIC ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 107 | xfs_file_aio_write( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | struct kiocb *iocb, |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 109 | const struct iovec *iov, |
| 110 | unsigned long nr_segs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | loff_t pos) |
| 112 | { |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 113 | return __xfs_file_write(iocb, iov, nr_segs, IO_ISAIO, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | STATIC ssize_t |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 117 | xfs_file_aio_write_invis( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | struct kiocb *iocb, |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 119 | const struct iovec *iov, |
| 120 | unsigned long nr_segs, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | loff_t pos) |
| 122 | { |
Badari Pulavarty | 027445c | 2006-09-30 23:28:46 -0700 | [diff] [blame] | 123 | return __xfs_file_write(iocb, iov, nr_segs, IO_ISAIO|IO_INVIS, pos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | STATIC ssize_t |
Nathan Scott | 1b89584 | 2006-03-31 13:08:59 +1000 | [diff] [blame] | 127 | xfs_file_splice_read( |
| 128 | struct file *infilp, |
Jens Axboe | cbb7e57 | 2006-04-11 14:57:50 +0200 | [diff] [blame] | 129 | loff_t *ppos, |
Ingo Molnar | 3a326a2 | 2006-04-10 15:18:35 +0200 | [diff] [blame] | 130 | struct pipe_inode_info *pipe, |
Nathan Scott | 1b89584 | 2006-03-31 13:08:59 +1000 | [diff] [blame] | 131 | size_t len, |
| 132 | unsigned int flags) |
| 133 | { |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 134 | return bhv_vop_splice_read(vn_from_inode(infilp->f_path.dentry->d_inode), |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 135 | infilp, ppos, pipe, len, flags, 0, NULL); |
Nathan Scott | 1b89584 | 2006-03-31 13:08:59 +1000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | STATIC ssize_t |
| 139 | xfs_file_splice_read_invis( |
| 140 | struct file *infilp, |
Jens Axboe | cbb7e57 | 2006-04-11 14:57:50 +0200 | [diff] [blame] | 141 | loff_t *ppos, |
Ingo Molnar | 3a326a2 | 2006-04-10 15:18:35 +0200 | [diff] [blame] | 142 | struct pipe_inode_info *pipe, |
Nathan Scott | 1b89584 | 2006-03-31 13:08:59 +1000 | [diff] [blame] | 143 | size_t len, |
| 144 | unsigned int flags) |
| 145 | { |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 146 | return bhv_vop_splice_read(vn_from_inode(infilp->f_path.dentry->d_inode), |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 147 | infilp, ppos, pipe, len, flags, IO_INVIS, |
| 148 | NULL); |
Nathan Scott | 1b89584 | 2006-03-31 13:08:59 +1000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | STATIC ssize_t |
| 152 | xfs_file_splice_write( |
Ingo Molnar | 3a326a2 | 2006-04-10 15:18:35 +0200 | [diff] [blame] | 153 | struct pipe_inode_info *pipe, |
Nathan Scott | 1b89584 | 2006-03-31 13:08:59 +1000 | [diff] [blame] | 154 | struct file *outfilp, |
Jens Axboe | cbb7e57 | 2006-04-11 14:57:50 +0200 | [diff] [blame] | 155 | loff_t *ppos, |
Nathan Scott | 1b89584 | 2006-03-31 13:08:59 +1000 | [diff] [blame] | 156 | size_t len, |
| 157 | unsigned int flags) |
| 158 | { |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 159 | return bhv_vop_splice_write(vn_from_inode(outfilp->f_path.dentry->d_inode), |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 160 | pipe, outfilp, ppos, len, flags, 0, NULL); |
Nathan Scott | 1b89584 | 2006-03-31 13:08:59 +1000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | STATIC ssize_t |
| 164 | xfs_file_splice_write_invis( |
Ingo Molnar | 3a326a2 | 2006-04-10 15:18:35 +0200 | [diff] [blame] | 165 | struct pipe_inode_info *pipe, |
Nathan Scott | 1b89584 | 2006-03-31 13:08:59 +1000 | [diff] [blame] | 166 | struct file *outfilp, |
Jens Axboe | cbb7e57 | 2006-04-11 14:57:50 +0200 | [diff] [blame] | 167 | loff_t *ppos, |
Nathan Scott | 1b89584 | 2006-03-31 13:08:59 +1000 | [diff] [blame] | 168 | size_t len, |
| 169 | unsigned int flags) |
| 170 | { |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 171 | return bhv_vop_splice_write(vn_from_inode(outfilp->f_path.dentry->d_inode), |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 172 | pipe, outfilp, ppos, len, flags, IO_INVIS, |
| 173 | NULL); |
Nathan Scott | 1b89584 | 2006-03-31 13:08:59 +1000 | [diff] [blame] | 174 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
| 176 | STATIC int |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 177 | xfs_file_open( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | struct inode *inode, |
| 179 | struct file *filp) |
| 180 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS) |
| 182 | return -EFBIG; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 183 | return -bhv_vop_open(vn_from_inode(inode), NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | STATIC int |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 187 | xfs_file_release( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | struct inode *inode, |
| 189 | struct file *filp) |
| 190 | { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 191 | bhv_vnode_t *vp = vn_from_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | if (vp) |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 194 | return -bhv_vop_release(vp); |
| 195 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } |
| 197 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | STATIC int |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 199 | xfs_file_fsync( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | struct file *filp, |
| 201 | struct dentry *dentry, |
| 202 | int datasync) |
| 203 | { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 204 | bhv_vnode_t *vp = vn_from_inode(dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | int flags = FSYNC_WAIT; |
| 206 | |
| 207 | if (datasync) |
| 208 | flags |= FSYNC_DATA; |
Nathan Scott | 7d4fb40 | 2006-06-09 15:27:16 +1000 | [diff] [blame] | 209 | if (VN_TRUNC(vp)) |
| 210 | VUNTRUNCATE(vp); |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 211 | return -bhv_vop_fsync(vp, flags, NULL, (xfs_off_t)0, (xfs_off_t)-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 214 | #ifdef CONFIG_XFS_DMAPI |
Nick Piggin | d0217ac | 2007-07-19 01:47:03 -0700 | [diff] [blame] | 215 | STATIC int |
Nick Piggin | 54cb882 | 2007-07-19 01:46:59 -0700 | [diff] [blame] | 216 | xfs_vm_fault( |
| 217 | struct vm_area_struct *vma, |
Nick Piggin | d0217ac | 2007-07-19 01:47:03 -0700 | [diff] [blame] | 218 | struct vm_fault *vmf) |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 219 | { |
Nick Piggin | 54cb882 | 2007-07-19 01:46:59 -0700 | [diff] [blame] | 220 | struct inode *inode = vma->vm_file->f_path.dentry->d_inode; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 221 | bhv_vnode_t *vp = vn_from_inode(inode); |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 222 | |
| 223 | ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI); |
Nick Piggin | d0217ac | 2007-07-19 01:47:03 -0700 | [diff] [blame] | 224 | if (XFS_SEND_MMAP(XFS_VFSTOM(vp->v_vfsp), vma, 0)) |
| 225 | return VM_FAULT_SIGBUS; |
| 226 | return filemap_fault(vma, vmf); |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 227 | } |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 228 | #endif /* CONFIG_XFS_DMAPI */ |
| 229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | STATIC int |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 231 | xfs_file_readdir( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | struct file *filp, |
| 233 | void *dirent, |
| 234 | filldir_t filldir) |
| 235 | { |
Christoph Hellwig | 051e7cd | 2007-08-28 13:58:24 +1000 | [diff] [blame^] | 236 | struct inode *inode = filp->f_path.dentry->d_inode; |
| 237 | bhv_vnode_t *vp = vn_from_inode(inode); |
| 238 | int error; |
| 239 | size_t bufsize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Christoph Hellwig | 051e7cd | 2007-08-28 13:58:24 +1000 | [diff] [blame^] | 241 | /* |
| 242 | * The Linux API doesn't pass down the total size of the buffer |
| 243 | * we read into down to the filesystem. With the filldir concept |
| 244 | * it's not needed for correct information, but the XFS dir2 leaf |
| 245 | * code wants an estimate of the buffer size to calculate it's |
| 246 | * readahead window and size the buffers used for mapping to |
| 247 | * physical blocks. |
| 248 | * |
| 249 | * Try to give it an estimate that's good enough, maybe at some |
| 250 | * point we can change the ->readdir prototype to include the |
| 251 | * buffer size. |
| 252 | */ |
| 253 | bufsize = (size_t)min_t(loff_t, PAGE_SIZE, inode->i_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
Christoph Hellwig | 051e7cd | 2007-08-28 13:58:24 +1000 | [diff] [blame^] | 255 | error = bhv_vop_readdir(vp, dirent, bufsize, |
| 256 | (xfs_off_t *)&filp->f_pos, filldir); |
| 257 | if (error) |
| 258 | return -error; |
| 259 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | STATIC int |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 263 | xfs_file_mmap( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | struct file *filp, |
| 265 | struct vm_area_struct *vma) |
| 266 | { |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 267 | vma->vm_ops = &xfs_file_vm_ops; |
Nick Piggin | d0217ac | 2007-07-19 01:47:03 -0700 | [diff] [blame] | 268 | vma->vm_flags |= VM_CAN_NONLINEAR; |
Dean Roehrich | 6fac0cb | 2005-06-21 14:07:45 +1000 | [diff] [blame] | 269 | |
Dean Roehrich | 6fac0cb | 2005-06-21 14:07:45 +1000 | [diff] [blame] | 270 | #ifdef CONFIG_XFS_DMAPI |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 271 | if (vn_from_inode(filp->f_path.dentry->d_inode)->v_vfsp->vfs_flag & VFS_DMI) |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 272 | vma->vm_ops = &xfs_dmapi_file_vm_ops; |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 273 | #endif /* CONFIG_XFS_DMAPI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Nathan Scott | fbc1462 | 2006-06-09 14:52:13 +1000 | [diff] [blame] | 275 | file_accessed(filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | return 0; |
| 277 | } |
| 278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | STATIC long |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 280 | xfs_file_ioctl( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | struct file *filp, |
| 282 | unsigned int cmd, |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 283 | unsigned long p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | { |
| 285 | int error; |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 286 | struct inode *inode = filp->f_path.dentry->d_inode; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 287 | bhv_vnode_t *vp = vn_from_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 289 | error = bhv_vop_ioctl(vp, inode, filp, 0, cmd, (void __user *)p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | VMODIFY(vp); |
| 291 | |
| 292 | /* NOTE: some of the ioctl's return positive #'s as a |
| 293 | * byte count indicating success, such as |
| 294 | * readlink_by_handle. So we don't "sign flip" |
| 295 | * like most other routines. This means true |
| 296 | * errors need to be returned as a negative value. |
| 297 | */ |
| 298 | return error; |
| 299 | } |
| 300 | |
| 301 | STATIC long |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 302 | xfs_file_ioctl_invis( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | struct file *filp, |
| 304 | unsigned int cmd, |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 305 | unsigned long p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | { |
Nathan Scott | 1b89584 | 2006-03-31 13:08:59 +1000 | [diff] [blame] | 307 | int error; |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 308 | struct inode *inode = filp->f_path.dentry->d_inode; |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 309 | bhv_vnode_t *vp = vn_from_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 311 | error = bhv_vop_ioctl(vp, inode, filp, IO_INVIS, cmd, (void __user *)p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | VMODIFY(vp); |
| 313 | |
| 314 | /* NOTE: some of the ioctl's return positive #'s as a |
| 315 | * byte count indicating success, such as |
| 316 | * readlink_by_handle. So we don't "sign flip" |
| 317 | * like most other routines. This means true |
| 318 | * errors need to be returned as a negative value. |
| 319 | */ |
| 320 | return error; |
| 321 | } |
| 322 | |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 323 | #ifdef CONFIG_XFS_DMAPI |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | #ifdef HAVE_VMOP_MPROTECT |
| 325 | STATIC int |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 326 | xfs_vm_mprotect( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | struct vm_area_struct *vma, |
| 328 | unsigned int newflags) |
| 329 | { |
Josef "Jeff" Sipek | e678fb0 | 2006-12-08 02:36:49 -0800 | [diff] [blame] | 330 | bhv_vnode_t *vp = vn_from_inode(vma->vm_file->f_path.dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | int error = 0; |
| 332 | |
| 333 | if (vp->v_vfsp->vfs_flag & VFS_DMI) { |
| 334 | if ((vma->vm_flags & VM_MAYSHARE) && |
| 335 | (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE)) { |
| 336 | xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp); |
| 337 | |
| 338 | error = XFS_SEND_MMAP(mp, vma, VM_WRITE); |
| 339 | } |
| 340 | } |
| 341 | return error; |
| 342 | } |
| 343 | #endif /* HAVE_VMOP_MPROTECT */ |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 344 | #endif /* CONFIG_XFS_DMAPI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | #ifdef HAVE_FOP_OPEN_EXEC |
| 347 | /* If the user is attempting to execute a file that is offline then |
| 348 | * we have to trigger a DMAPI READ event before the file is marked as busy |
| 349 | * otherwise the invisible I/O will not be able to write to the file to bring |
| 350 | * it back online. |
| 351 | */ |
| 352 | STATIC int |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 353 | xfs_file_open_exec( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | struct inode *inode) |
| 355 | { |
Nathan Scott | 67fcaa7 | 2006-06-09 17:00:52 +1000 | [diff] [blame] | 356 | bhv_vnode_t *vp = vn_from_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Nathan Scott | 1d47bec | 2006-06-19 08:39:16 +1000 | [diff] [blame] | 358 | if (unlikely(vp->v_vfsp->vfs_flag & VFS_DMI)) { |
| 359 | xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp); |
| 360 | xfs_inode_t *ip = xfs_vtoi(vp); |
| 361 | |
| 362 | if (!ip) |
| 363 | return -EINVAL; |
Christoph Hellwig | eb9df39 | 2007-08-16 18:42:07 +1000 | [diff] [blame] | 364 | if (DM_EVENT_ENABLED(ip, DM_EVENT_READ)) |
Nathan Scott | 1d47bec | 2006-06-19 08:39:16 +1000 | [diff] [blame] | 365 | return -XFS_SEND_DATA(mp, DM_EVENT_READ, vp, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | 0, 0, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
Nathan Scott | 1d47bec | 2006-06-19 08:39:16 +1000 | [diff] [blame] | 368 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | } |
| 370 | #endif /* HAVE_FOP_OPEN_EXEC */ |
| 371 | |
David Chinner | 4f57dbc | 2007-07-19 16:28:17 +1000 | [diff] [blame] | 372 | /* |
| 373 | * mmap()d file has taken write protection fault and is being made |
| 374 | * writable. We can set the page state up correctly for a writable |
| 375 | * page, which means we can do correct delalloc accounting (ENOSPC |
| 376 | * checking!) and unwritten extent mapping. |
| 377 | */ |
| 378 | STATIC int |
| 379 | xfs_vm_page_mkwrite( |
| 380 | struct vm_area_struct *vma, |
| 381 | struct page *page) |
| 382 | { |
| 383 | return block_page_mkwrite(vma, page, xfs_get_blocks); |
| 384 | } |
| 385 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 386 | const struct file_operations xfs_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | .llseek = generic_file_llseek, |
| 388 | .read = do_sync_read, |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 389 | .write = do_sync_write, |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 390 | .aio_read = xfs_file_aio_read, |
| 391 | .aio_write = xfs_file_aio_write, |
Nathan Scott | 1b89584 | 2006-03-31 13:08:59 +1000 | [diff] [blame] | 392 | .splice_read = xfs_file_splice_read, |
| 393 | .splice_write = xfs_file_splice_write, |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 394 | .unlocked_ioctl = xfs_file_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | #ifdef CONFIG_COMPAT |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 396 | .compat_ioctl = xfs_file_compat_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | #endif |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 398 | .mmap = xfs_file_mmap, |
| 399 | .open = xfs_file_open, |
| 400 | .release = xfs_file_release, |
| 401 | .fsync = xfs_file_fsync, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | #ifdef HAVE_FOP_OPEN_EXEC |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 403 | .open_exec = xfs_file_open_exec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | #endif |
| 405 | }; |
| 406 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 407 | const struct file_operations xfs_invis_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | .llseek = generic_file_llseek, |
| 409 | .read = do_sync_read, |
Dean Roehrich | bb3f724 | 2005-09-02 15:43:05 +1000 | [diff] [blame] | 410 | .write = do_sync_write, |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 411 | .aio_read = xfs_file_aio_read_invis, |
| 412 | .aio_write = xfs_file_aio_write_invis, |
Nathan Scott | 1b89584 | 2006-03-31 13:08:59 +1000 | [diff] [blame] | 413 | .splice_read = xfs_file_splice_read_invis, |
| 414 | .splice_write = xfs_file_splice_write_invis, |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 415 | .unlocked_ioctl = xfs_file_ioctl_invis, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | #ifdef CONFIG_COMPAT |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 417 | .compat_ioctl = xfs_file_compat_invis_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | #endif |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 419 | .mmap = xfs_file_mmap, |
| 420 | .open = xfs_file_open, |
| 421 | .release = xfs_file_release, |
| 422 | .fsync = xfs_file_fsync, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | }; |
| 424 | |
| 425 | |
Arjan van de Ven | 4b6f5d2 | 2006-03-28 01:56:42 -0800 | [diff] [blame] | 426 | const struct file_operations xfs_dir_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | .read = generic_read_dir, |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 428 | .readdir = xfs_file_readdir, |
| 429 | .unlocked_ioctl = xfs_file_ioctl, |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 430 | #ifdef CONFIG_COMPAT |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 431 | .compat_ioctl = xfs_file_compat_ioctl, |
Nathan Scott | d387039 | 2005-05-06 06:44:46 -0700 | [diff] [blame] | 432 | #endif |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 433 | .fsync = xfs_file_fsync, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | }; |
| 435 | |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 436 | static struct vm_operations_struct xfs_file_vm_ops = { |
Nick Piggin | 54cb882 | 2007-07-19 01:46:59 -0700 | [diff] [blame] | 437 | .fault = filemap_fault, |
David Chinner | 4f57dbc | 2007-07-19 16:28:17 +1000 | [diff] [blame] | 438 | .page_mkwrite = xfs_vm_page_mkwrite, |
Dean Roehrich | 6fac0cb | 2005-06-21 14:07:45 +1000 | [diff] [blame] | 439 | }; |
| 440 | |
| 441 | #ifdef CONFIG_XFS_DMAPI |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 442 | static struct vm_operations_struct xfs_dmapi_file_vm_ops = { |
Nick Piggin | 54cb882 | 2007-07-19 01:46:59 -0700 | [diff] [blame] | 443 | .fault = xfs_vm_fault, |
David Chinner | 4f57dbc | 2007-07-19 16:28:17 +1000 | [diff] [blame] | 444 | .page_mkwrite = xfs_vm_page_mkwrite, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | #ifdef HAVE_VMOP_MPROTECT |
Nathan Scott | 3562fd4 | 2006-03-14 14:00:35 +1100 | [diff] [blame] | 446 | .mprotect = xfs_vm_mprotect, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | #endif |
| 448 | }; |
Dean Roehrich | 6fac0cb | 2005-06-21 14:07:45 +1000 | [diff] [blame] | 449 | #endif /* CONFIG_XFS_DMAPI */ |