[XFS] kill the v_flag member in struct bhv_vnode
[deliverable/linux.git] / fs / xfs / linux-2.6 / xfs_file.c
CommitLineData
1da177e4 1/*
7b718769
NS
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
1da177e4 4 *
7b718769
NS
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
1da177e4
LT
7 * published by the Free Software Foundation.
8 *
7b718769
NS
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.
1da177e4 13 *
7b718769
NS
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
1da177e4 17 */
1da177e4 18#include "xfs.h"
a844f451 19#include "xfs_bit.h"
1da177e4 20#include "xfs_log.h"
a844f451 21#include "xfs_inum.h"
1da177e4 22#include "xfs_sb.h"
a844f451 23#include "xfs_ag.h"
1da177e4
LT
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"
1da177e4
LT
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"
739bfb2a 40#include "xfs_vnodeops.h"
1da177e4
LT
41
42#include <linux/dcache.h>
43#include <linux/smp_lock.h>
44
3562fd45 45static struct vm_operations_struct xfs_file_vm_ops;
6fac0cb4 46#ifdef CONFIG_XFS_DMAPI
3562fd45 47static struct vm_operations_struct xfs_dmapi_file_vm_ops;
6fac0cb4 48#endif
1da177e4 49
7989cb8e 50STATIC_INLINE ssize_t
3562fd45 51__xfs_file_read(
1da177e4 52 struct kiocb *iocb,
027445c3
BP
53 const struct iovec *iov,
54 unsigned long nr_segs,
1da177e4 55 int ioflags,
1da177e4
LT
56 loff_t pos)
57{
1da177e4 58 struct file *file = iocb->ki_filp;
1da177e4
LT
59
60 BUG_ON(iocb->ki_pos != pos);
1da177e4
LT
61 if (unlikely(file->f_flags & O_DIRECT))
62 ioflags |= IO_ISDIRECT;
739bfb2a
CH
63 return xfs_read(XFS_I(file->f_path.dentry->d_inode), iocb, iov,
64 nr_segs, &iocb->ki_pos, ioflags);
1da177e4
LT
65}
66
1da177e4 67STATIC ssize_t
3562fd45 68xfs_file_aio_read(
1da177e4 69 struct kiocb *iocb,
027445c3
BP
70 const struct iovec *iov,
71 unsigned long nr_segs,
1da177e4
LT
72 loff_t pos)
73{
027445c3 74 return __xfs_file_read(iocb, iov, nr_segs, IO_ISAIO, pos);
1da177e4
LT
75}
76
77STATIC ssize_t
3562fd45 78xfs_file_aio_read_invis(
1da177e4 79 struct kiocb *iocb,
027445c3
BP
80 const struct iovec *iov,
81 unsigned long nr_segs,
1da177e4
LT
82 loff_t pos)
83{
027445c3 84 return __xfs_file_read(iocb, iov, nr_segs, IO_ISAIO|IO_INVIS, pos);
1da177e4
LT
85}
86
7989cb8e 87STATIC_INLINE ssize_t
3562fd45 88__xfs_file_write(
027445c3
BP
89 struct kiocb *iocb,
90 const struct iovec *iov,
91 unsigned long nr_segs,
92 int ioflags,
93 loff_t pos)
1da177e4 94{
1da177e4 95 struct file *file = iocb->ki_filp;
1da177e4
LT
96
97 BUG_ON(iocb->ki_pos != pos);
98 if (unlikely(file->f_flags & O_DIRECT))
99 ioflags |= IO_ISDIRECT;
739bfb2a
CH
100 return xfs_write(XFS_I(file->f_mapping->host), iocb, iov, nr_segs,
101 &iocb->ki_pos, ioflags);
1da177e4
LT
102}
103
1da177e4 104STATIC ssize_t
3562fd45 105xfs_file_aio_write(
1da177e4 106 struct kiocb *iocb,
027445c3
BP
107 const struct iovec *iov,
108 unsigned long nr_segs,
1da177e4
LT
109 loff_t pos)
110{
027445c3 111 return __xfs_file_write(iocb, iov, nr_segs, IO_ISAIO, pos);
1da177e4
LT
112}
113
114STATIC ssize_t
3562fd45 115xfs_file_aio_write_invis(
1da177e4 116 struct kiocb *iocb,
027445c3
BP
117 const struct iovec *iov,
118 unsigned long nr_segs,
1da177e4
LT
119 loff_t pos)
120{
027445c3 121 return __xfs_file_write(iocb, iov, nr_segs, IO_ISAIO|IO_INVIS, pos);
1da177e4
LT
122}
123
1b895840
NS
124STATIC ssize_t
125xfs_file_splice_read(
126 struct file *infilp,
cbb7e577 127 loff_t *ppos,
3a326a2c 128 struct pipe_inode_info *pipe,
1b895840
NS
129 size_t len,
130 unsigned int flags)
131{
739bfb2a
CH
132 return xfs_splice_read(XFS_I(infilp->f_path.dentry->d_inode),
133 infilp, ppos, pipe, len, flags, 0);
1b895840
NS
134}
135
136STATIC ssize_t
137xfs_file_splice_read_invis(
138 struct file *infilp,
cbb7e577 139 loff_t *ppos,
3a326a2c 140 struct pipe_inode_info *pipe,
1b895840
NS
141 size_t len,
142 unsigned int flags)
143{
739bfb2a
CH
144 return xfs_splice_read(XFS_I(infilp->f_path.dentry->d_inode),
145 infilp, ppos, pipe, len, flags, IO_INVIS);
1b895840
NS
146}
147
148STATIC ssize_t
149xfs_file_splice_write(
3a326a2c 150 struct pipe_inode_info *pipe,
1b895840 151 struct file *outfilp,
cbb7e577 152 loff_t *ppos,
1b895840
NS
153 size_t len,
154 unsigned int flags)
155{
739bfb2a
CH
156 return xfs_splice_write(XFS_I(outfilp->f_path.dentry->d_inode),
157 pipe, outfilp, ppos, len, flags, 0);
1b895840
NS
158}
159
160STATIC ssize_t
161xfs_file_splice_write_invis(
3a326a2c 162 struct pipe_inode_info *pipe,
1b895840 163 struct file *outfilp,
cbb7e577 164 loff_t *ppos,
1b895840
NS
165 size_t len,
166 unsigned int flags)
167{
739bfb2a
CH
168 return xfs_splice_write(XFS_I(outfilp->f_path.dentry->d_inode),
169 pipe, outfilp, ppos, len, flags, IO_INVIS);
1b895840 170}
1da177e4
LT
171
172STATIC int
3562fd45 173xfs_file_open(
1da177e4
LT
174 struct inode *inode,
175 struct file *filp)
176{
1da177e4
LT
177 if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
178 return -EFBIG;
739bfb2a 179 return -xfs_open(XFS_I(inode));
1da177e4
LT
180}
181
1da177e4 182STATIC int
3562fd45 183xfs_file_release(
1da177e4
LT
184 struct inode *inode,
185 struct file *filp)
186{
739bfb2a 187 return -xfs_release(XFS_I(inode));
1da177e4
LT
188}
189
1da177e4 190STATIC int
3562fd45 191xfs_file_fsync(
1da177e4
LT
192 struct file *filp,
193 struct dentry *dentry,
194 int datasync)
195{
1da177e4
LT
196 int flags = FSYNC_WAIT;
197
198 if (datasync)
199 flags |= FSYNC_DATA;
b3aea4ed 200 xfs_iflags_clear(XFS_I(dentry->d_inode), XFS_ITRUNCATED);
739bfb2a
CH
201 return -xfs_fsync(XFS_I(dentry->d_inode), flags,
202 (xfs_off_t)0, (xfs_off_t)-1);
1da177e4
LT
203}
204
bb3f724e 205#ifdef CONFIG_XFS_DMAPI
d0217ac0 206STATIC int
54cb8821
NP
207xfs_vm_fault(
208 struct vm_area_struct *vma,
d0217ac0 209 struct vm_fault *vmf)
bb3f724e 210{
54cb8821 211 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
67fcaa73 212 bhv_vnode_t *vp = vn_from_inode(inode);
bb3f724e
DR
213
214 ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI);
d0217ac0
NP
215 if (XFS_SEND_MMAP(XFS_VFSTOM(vp->v_vfsp), vma, 0))
216 return VM_FAULT_SIGBUS;
217 return filemap_fault(vma, vmf);
bb3f724e 218}
bb3f724e
DR
219#endif /* CONFIG_XFS_DMAPI */
220
1da177e4 221STATIC int
3562fd45 222xfs_file_readdir(
1da177e4
LT
223 struct file *filp,
224 void *dirent,
225 filldir_t filldir)
226{
051e7cd4 227 struct inode *inode = filp->f_path.dentry->d_inode;
739bfb2a 228 xfs_inode_t *ip = XFS_I(inode);
051e7cd4
CH
229 int error;
230 size_t bufsize;
231
232 /*
233 * The Linux API doesn't pass down the total size of the buffer
234 * we read into down to the filesystem. With the filldir concept
235 * it's not needed for correct information, but the XFS dir2 leaf
236 * code wants an estimate of the buffer size to calculate it's
237 * readahead window and size the buffers used for mapping to
238 * physical blocks.
239 *
240 * Try to give it an estimate that's good enough, maybe at some
241 * point we can change the ->readdir prototype to include the
242 * buffer size.
243 */
244 bufsize = (size_t)min_t(loff_t, PAGE_SIZE, inode->i_size);
245
739bfb2a 246 error = xfs_readdir(ip, dirent, bufsize,
051e7cd4
CH
247 (xfs_off_t *)&filp->f_pos, filldir);
248 if (error)
249 return -error;
250 return 0;
1da177e4
LT
251}
252
1da177e4 253STATIC int
3562fd45 254xfs_file_mmap(
1da177e4
LT
255 struct file *filp,
256 struct vm_area_struct *vma)
257{
3562fd45 258 vma->vm_ops = &xfs_file_vm_ops;
d0217ac0 259 vma->vm_flags |= VM_CAN_NONLINEAR;
6fac0cb4 260
6fac0cb4 261#ifdef CONFIG_XFS_DMAPI
2f6f7b3d 262 if (vfs_from_sb(filp->f_path.dentry->d_inode->i_sb)->vfs_flag & VFS_DMI)
3562fd45 263 vma->vm_ops = &xfs_dmapi_file_vm_ops;
bb3f724e 264#endif /* CONFIG_XFS_DMAPI */
1da177e4 265
fbc1462b 266 file_accessed(filp);
1da177e4
LT
267 return 0;
268}
269
1da177e4 270STATIC long
3562fd45 271xfs_file_ioctl(
1da177e4
LT
272 struct file *filp,
273 unsigned int cmd,
67fcaa73 274 unsigned long p)
1da177e4
LT
275{
276 int error;
e678fb0d 277 struct inode *inode = filp->f_path.dentry->d_inode;
1da177e4 278
739bfb2a 279 error = xfs_ioctl(XFS_I(inode), filp, 0, cmd, (void __user *)p);
b3aea4ed 280 xfs_iflags_set(XFS_I(inode), XFS_IMODIFIED);
1da177e4
LT
281
282 /* NOTE: some of the ioctl's return positive #'s as a
283 * byte count indicating success, such as
284 * readlink_by_handle. So we don't "sign flip"
285 * like most other routines. This means true
286 * errors need to be returned as a negative value.
287 */
288 return error;
289}
290
291STATIC long
3562fd45 292xfs_file_ioctl_invis(
1da177e4
LT
293 struct file *filp,
294 unsigned int cmd,
67fcaa73 295 unsigned long p)
1da177e4 296{
1b895840 297 int error;
e678fb0d 298 struct inode *inode = filp->f_path.dentry->d_inode;
1da177e4 299
739bfb2a 300 error = xfs_ioctl(XFS_I(inode), filp, IO_INVIS, cmd, (void __user *)p);
b3aea4ed 301 xfs_iflags_set(XFS_I(inode), XFS_IMODIFIED);
1da177e4
LT
302
303 /* NOTE: some of the ioctl's return positive #'s as a
304 * byte count indicating success, such as
305 * readlink_by_handle. So we don't "sign flip"
306 * like most other routines. This means true
307 * errors need to be returned as a negative value.
308 */
309 return error;
310}
311
bb3f724e 312#ifdef CONFIG_XFS_DMAPI
1da177e4
LT
313#ifdef HAVE_VMOP_MPROTECT
314STATIC int
3562fd45 315xfs_vm_mprotect(
1da177e4
LT
316 struct vm_area_struct *vma,
317 unsigned int newflags)
318{
2f6f7b3d
CH
319 struct inode *inode = vma->vm_file->f_path.dentry->d_inode;
320 bhv_vfs_t *vfsp = vfs_from_sb(inode->i_sb);
1da177e4
LT
321 int error = 0;
322
2f6f7b3d 323 if (vfsp->vfs_flag & VFS_DMI) {
1da177e4 324 if ((vma->vm_flags & VM_MAYSHARE) &&
2f6f7b3d
CH
325 (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE))
326 error = XFS_SEND_MMAP(XFS_VFSTOM(vfsp), vma, VM_WRITE);
1da177e4
LT
327 }
328 return error;
329}
330#endif /* HAVE_VMOP_MPROTECT */
bb3f724e 331#endif /* CONFIG_XFS_DMAPI */
1da177e4
LT
332
333#ifdef HAVE_FOP_OPEN_EXEC
334/* If the user is attempting to execute a file that is offline then
335 * we have to trigger a DMAPI READ event before the file is marked as busy
336 * otherwise the invisible I/O will not be able to write to the file to bring
337 * it back online.
338 */
339STATIC int
3562fd45 340xfs_file_open_exec(
1da177e4
LT
341 struct inode *inode)
342{
2f6f7b3d 343 bhv_vfs_t *vfsp = vfs_from_sb(inode->i_sb);
1da177e4 344
2f6f7b3d
CH
345 if (unlikely(vfsp->vfs_flag & VFS_DMI)) {
346 if (DM_EVENT_ENABLED(XFS_I(inode), DM_EVENT_READ)) {
347 bhv_vnode_t *vp = vn_from_inode(inode);
1d47bec2 348
2f6f7b3d
CH
349 return -XFS_SEND_DATA(XFS_VFSTOM(vfsp), DM_EVENT_READ,
350 vp, 0, 0, 0, NULL);
351 }
1da177e4 352 }
2f6f7b3d 353
1d47bec2 354 return 0;
1da177e4
LT
355}
356#endif /* HAVE_FOP_OPEN_EXEC */
357
4f57dbc6
DC
358/*
359 * mmap()d file has taken write protection fault and is being made
360 * writable. We can set the page state up correctly for a writable
361 * page, which means we can do correct delalloc accounting (ENOSPC
362 * checking!) and unwritten extent mapping.
363 */
364STATIC int
365xfs_vm_page_mkwrite(
366 struct vm_area_struct *vma,
367 struct page *page)
368{
369 return block_page_mkwrite(vma, page, xfs_get_blocks);
370}
371
4b6f5d20 372const struct file_operations xfs_file_operations = {
1da177e4
LT
373 .llseek = generic_file_llseek,
374 .read = do_sync_read,
bb3f724e 375 .write = do_sync_write,
3562fd45
NS
376 .aio_read = xfs_file_aio_read,
377 .aio_write = xfs_file_aio_write,
1b895840
NS
378 .splice_read = xfs_file_splice_read,
379 .splice_write = xfs_file_splice_write,
3562fd45 380 .unlocked_ioctl = xfs_file_ioctl,
1da177e4 381#ifdef CONFIG_COMPAT
3562fd45 382 .compat_ioctl = xfs_file_compat_ioctl,
1da177e4 383#endif
3562fd45
NS
384 .mmap = xfs_file_mmap,
385 .open = xfs_file_open,
386 .release = xfs_file_release,
387 .fsync = xfs_file_fsync,
1da177e4 388#ifdef HAVE_FOP_OPEN_EXEC
3562fd45 389 .open_exec = xfs_file_open_exec,
1da177e4
LT
390#endif
391};
392
4b6f5d20 393const struct file_operations xfs_invis_file_operations = {
1da177e4
LT
394 .llseek = generic_file_llseek,
395 .read = do_sync_read,
bb3f724e 396 .write = do_sync_write,
3562fd45
NS
397 .aio_read = xfs_file_aio_read_invis,
398 .aio_write = xfs_file_aio_write_invis,
1b895840
NS
399 .splice_read = xfs_file_splice_read_invis,
400 .splice_write = xfs_file_splice_write_invis,
3562fd45 401 .unlocked_ioctl = xfs_file_ioctl_invis,
1da177e4 402#ifdef CONFIG_COMPAT
3562fd45 403 .compat_ioctl = xfs_file_compat_invis_ioctl,
1da177e4 404#endif
3562fd45
NS
405 .mmap = xfs_file_mmap,
406 .open = xfs_file_open,
407 .release = xfs_file_release,
408 .fsync = xfs_file_fsync,
1da177e4
LT
409};
410
411
4b6f5d20 412const struct file_operations xfs_dir_file_operations = {
1da177e4 413 .read = generic_read_dir,
3562fd45
NS
414 .readdir = xfs_file_readdir,
415 .unlocked_ioctl = xfs_file_ioctl,
d3870398 416#ifdef CONFIG_COMPAT
3562fd45 417 .compat_ioctl = xfs_file_compat_ioctl,
d3870398 418#endif
3562fd45 419 .fsync = xfs_file_fsync,
1da177e4
LT
420};
421
3562fd45 422static struct vm_operations_struct xfs_file_vm_ops = {
54cb8821 423 .fault = filemap_fault,
4f57dbc6 424 .page_mkwrite = xfs_vm_page_mkwrite,
6fac0cb4
DR
425};
426
427#ifdef CONFIG_XFS_DMAPI
3562fd45 428static struct vm_operations_struct xfs_dmapi_file_vm_ops = {
54cb8821 429 .fault = xfs_vm_fault,
4f57dbc6 430 .page_mkwrite = xfs_vm_page_mkwrite,
1da177e4 431#ifdef HAVE_VMOP_MPROTECT
3562fd45 432 .mprotect = xfs_vm_mprotect,
1da177e4
LT
433#endif
434};
6fac0cb4 435#endif /* CONFIG_XFS_DMAPI */
This page took 0.409901 seconds and 5 git commands to generate.