blob: 269721af02f3bf4390ac325b54f64f05435ee960 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Nathan Scott7b718762005-11-02 14:58:39 +11002 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Nathan Scott7b718762005-11-02 14:58:39 +11005 * 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 Torvalds1da177e2005-04-16 15:20:36 -07007 * published by the Free Software Foundation.
8 *
Nathan Scott7b718762005-11-02 14:58:39 +11009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070013 *
Nathan Scott7b718762005-11-02 14:58:39 +110014 * 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 Torvalds1da177e2005-04-16 15:20:36 -070017 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include "xfs.h"
Nathan Scotta844f452005-11-02 14:38:42 +110019#include "xfs_bit.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include "xfs_log.h"
Nathan Scotta844f452005-11-02 14:38:42 +110021#include "xfs_inum.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include "xfs_sb.h"
Nathan Scotta844f452005-11-02 14:38:42 +110023#include "xfs_ag.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include "xfs_dir.h"
25#include "xfs_dir2.h"
26#include "xfs_trans.h"
27#include "xfs_dmapi.h"
28#include "xfs_mount.h"
29#include "xfs_bmap_btree.h"
30#include "xfs_alloc_btree.h"
31#include "xfs_ialloc_btree.h"
32#include "xfs_alloc.h"
33#include "xfs_btree.h"
34#include "xfs_attr_sf.h"
35#include "xfs_dir_sf.h"
36#include "xfs_dir2_sf.h"
37#include "xfs_dinode.h"
38#include "xfs_inode.h"
39#include "xfs_error.h"
40#include "xfs_rw.h"
41#include "xfs_ioctl32.h"
42
43#include <linux/dcache.h>
44#include <linux/smp_lock.h>
45
Nathan Scott3562fd42006-03-14 14:00:35 +110046static struct vm_operations_struct xfs_file_vm_ops;
Dean Roehrich6fac0cb2005-06-21 14:07:45 +100047#ifdef CONFIG_XFS_DMAPI
Nathan Scott3562fd42006-03-14 14:00:35 +110048static struct vm_operations_struct xfs_dmapi_file_vm_ops;
Dean Roehrich6fac0cb2005-06-21 14:07:45 +100049#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51STATIC inline ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +110052__xfs_file_read(
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 struct kiocb *iocb,
54 char __user *buf,
55 int ioflags,
56 size_t count,
57 loff_t pos)
58{
59 struct iovec iov = {buf, count};
60 struct file *file = iocb->ki_filp;
Nathan Scottec86dc02006-03-17 17:25:36 +110061 vnode_t *vp = vn_from_inode(file->f_dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 ssize_t rval;
63
64 BUG_ON(iocb->ki_pos != pos);
65
66 if (unlikely(file->f_flags & O_DIRECT))
67 ioflags |= IO_ISDIRECT;
68 VOP_READ(vp, iocb, &iov, 1, &iocb->ki_pos, ioflags, NULL, rval);
69 return rval;
70}
71
Linus Torvalds1da177e2005-04-16 15:20:36 -070072STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +110073xfs_file_aio_read(
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 struct kiocb *iocb,
75 char __user *buf,
76 size_t count,
77 loff_t pos)
78{
Nathan Scott3562fd42006-03-14 14:00:35 +110079 return __xfs_file_read(iocb, buf, IO_ISAIO, count, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080}
81
82STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +110083xfs_file_aio_read_invis(
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 struct kiocb *iocb,
85 char __user *buf,
86 size_t count,
87 loff_t pos)
88{
Nathan Scott3562fd42006-03-14 14:00:35 +110089 return __xfs_file_read(iocb, buf, IO_ISAIO|IO_INVIS, count, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092STATIC inline ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +110093__xfs_file_write(
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 struct kiocb *iocb,
95 const char __user *buf,
96 int ioflags,
97 size_t count,
98 loff_t pos)
99{
100 struct iovec iov = {(void __user *)buf, count};
101 struct file *file = iocb->ki_filp;
102 struct inode *inode = file->f_mapping->host;
Nathan Scottec86dc02006-03-17 17:25:36 +1100103 vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 ssize_t rval;
105
106 BUG_ON(iocb->ki_pos != pos);
107 if (unlikely(file->f_flags & O_DIRECT))
108 ioflags |= IO_ISDIRECT;
109
110 VOP_WRITE(vp, iocb, &iov, 1, &iocb->ki_pos, ioflags, NULL, rval);
111 return rval;
112}
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100115xfs_file_aio_write(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 struct kiocb *iocb,
117 const char __user *buf,
118 size_t count,
119 loff_t pos)
120{
Nathan Scott3562fd42006-03-14 14:00:35 +1100121 return __xfs_file_write(iocb, buf, IO_ISAIO, count, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
124STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100125xfs_file_aio_write_invis(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 struct kiocb *iocb,
127 const char __user *buf,
128 size_t count,
129 loff_t pos)
130{
Nathan Scott3562fd42006-03-14 14:00:35 +1100131 return __xfs_file_write(iocb, buf, IO_ISAIO|IO_INVIS, count, pos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134STATIC inline ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100135__xfs_file_readv(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 struct file *file,
137 const struct iovec *iov,
138 int ioflags,
139 unsigned long nr_segs,
140 loff_t *ppos)
141{
142 struct inode *inode = file->f_mapping->host;
Nathan Scottec86dc02006-03-17 17:25:36 +1100143 vnode_t *vp = vn_from_inode(inode);
Nathan Scott524fbf52006-03-14 14:07:53 +1100144 struct kiocb kiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 ssize_t rval;
146
Nathan Scott524fbf52006-03-14 14:07:53 +1100147 init_sync_kiocb(&kiocb, file);
148 kiocb.ki_pos = *ppos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 if (unlikely(file->f_flags & O_DIRECT))
151 ioflags |= IO_ISDIRECT;
Nathan Scott524fbf52006-03-14 14:07:53 +1100152 VOP_READ(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos, ioflags, NULL, rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Nathan Scott524fbf52006-03-14 14:07:53 +1100154 *ppos = kiocb.ki_pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 return rval;
156}
157
158STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100159xfs_file_readv(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 struct file *file,
161 const struct iovec *iov,
162 unsigned long nr_segs,
163 loff_t *ppos)
164{
Nathan Scott3562fd42006-03-14 14:00:35 +1100165 return __xfs_file_readv(file, iov, 0, nr_segs, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166}
167
168STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100169xfs_file_readv_invis(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 struct file *file,
171 const struct iovec *iov,
172 unsigned long nr_segs,
173 loff_t *ppos)
174{
Nathan Scott3562fd42006-03-14 14:00:35 +1100175 return __xfs_file_readv(file, iov, IO_INVIS, nr_segs, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178STATIC inline ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100179__xfs_file_writev(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 struct file *file,
181 const struct iovec *iov,
182 int ioflags,
183 unsigned long nr_segs,
184 loff_t *ppos)
185{
186 struct inode *inode = file->f_mapping->host;
Nathan Scottec86dc02006-03-17 17:25:36 +1100187 vnode_t *vp = vn_from_inode(inode);
Nathan Scott524fbf52006-03-14 14:07:53 +1100188 struct kiocb kiocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 ssize_t rval;
190
Nathan Scott524fbf52006-03-14 14:07:53 +1100191 init_sync_kiocb(&kiocb, file);
192 kiocb.ki_pos = *ppos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 if (unlikely(file->f_flags & O_DIRECT))
194 ioflags |= IO_ISDIRECT;
195
Nathan Scott524fbf52006-03-14 14:07:53 +1100196 VOP_WRITE(vp, &kiocb, iov, nr_segs, &kiocb.ki_pos, ioflags, NULL, rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Nathan Scott524fbf52006-03-14 14:07:53 +1100198 *ppos = kiocb.ki_pos;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 return rval;
200}
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100203xfs_file_writev(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 struct file *file,
205 const struct iovec *iov,
206 unsigned long nr_segs,
207 loff_t *ppos)
208{
Nathan Scott3562fd42006-03-14 14:00:35 +1100209 return __xfs_file_writev(file, iov, 0, nr_segs, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210}
211
212STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100213xfs_file_writev_invis(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 struct file *file,
215 const struct iovec *iov,
216 unsigned long nr_segs,
217 loff_t *ppos)
218{
Nathan Scott3562fd42006-03-14 14:00:35 +1100219 return __xfs_file_writev(file, iov, IO_INVIS, nr_segs, ppos);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220}
221
222STATIC ssize_t
Nathan Scott3562fd42006-03-14 14:00:35 +1100223xfs_file_sendfile(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 struct file *filp,
Nathan Scott1b895842006-03-31 13:08:59 +1000225 loff_t *pos,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 size_t count,
227 read_actor_t actor,
228 void *target)
229{
Nathan Scottec86dc02006-03-17 17:25:36 +1100230 vnode_t *vp = vn_from_inode(filp->f_dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 ssize_t rval;
232
Nathan Scott1b895842006-03-31 13:08:59 +1000233 VOP_SENDFILE(vp, filp, pos, 0, count, actor, target, NULL, rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return rval;
235}
236
Nathan Scott1b895842006-03-31 13:08:59 +1000237STATIC ssize_t
238xfs_file_sendfile_invis(
239 struct file *filp,
240 loff_t *pos,
241 size_t count,
242 read_actor_t actor,
243 void *target)
244{
245 vnode_t *vp = vn_from_inode(filp->f_dentry->d_inode);
246 ssize_t rval;
247
248 VOP_SENDFILE(vp, filp, pos, IO_INVIS, count, actor, target, NULL, rval);
249 return rval;
250}
251
252STATIC ssize_t
253xfs_file_splice_read(
254 struct file *infilp,
Ingo Molnar3a326a22006-04-10 15:18:35 +0200255 struct pipe_inode_info *pipe,
Nathan Scott1b895842006-03-31 13:08:59 +1000256 size_t len,
257 unsigned int flags)
258{
259 vnode_t *vp = vn_from_inode(infilp->f_dentry->d_inode);
260 ssize_t rval;
261
262 VOP_SPLICE_READ(vp, infilp, pipe, len, flags, 0, NULL, rval);
263 return rval;
264}
265
266STATIC ssize_t
267xfs_file_splice_read_invis(
268 struct file *infilp,
Ingo Molnar3a326a22006-04-10 15:18:35 +0200269 struct pipe_inode_info *pipe,
Nathan Scott1b895842006-03-31 13:08:59 +1000270 size_t len,
271 unsigned int flags)
272{
273 vnode_t *vp = vn_from_inode(infilp->f_dentry->d_inode);
274 ssize_t rval;
275
276 VOP_SPLICE_READ(vp, infilp, pipe, len, flags, IO_INVIS, NULL, rval);
277 return rval;
278}
279
280STATIC ssize_t
281xfs_file_splice_write(
Ingo Molnar3a326a22006-04-10 15:18:35 +0200282 struct pipe_inode_info *pipe,
Nathan Scott1b895842006-03-31 13:08:59 +1000283 struct file *outfilp,
284 size_t len,
285 unsigned int flags)
286{
287 vnode_t *vp = vn_from_inode(outfilp->f_dentry->d_inode);
288 ssize_t rval;
289
290 VOP_SPLICE_WRITE(vp, pipe, outfilp, len, flags, 0, NULL, rval);
291 return rval;
292}
293
294STATIC ssize_t
295xfs_file_splice_write_invis(
Ingo Molnar3a326a22006-04-10 15:18:35 +0200296 struct pipe_inode_info *pipe,
Nathan Scott1b895842006-03-31 13:08:59 +1000297 struct file *outfilp,
298 size_t len,
299 unsigned int flags)
300{
301 vnode_t *vp = vn_from_inode(outfilp->f_dentry->d_inode);
302 ssize_t rval;
303
304 VOP_SPLICE_WRITE(vp, pipe, outfilp, len, flags, IO_INVIS, NULL, rval);
305 return rval;
306}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100309xfs_file_open(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 struct inode *inode,
311 struct file *filp)
312{
Nathan Scottec86dc02006-03-17 17:25:36 +1100313 vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 int error;
315
316 if (!(filp->f_flags & O_LARGEFILE) && i_size_read(inode) > MAX_NON_LFS)
317 return -EFBIG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 VOP_OPEN(vp, NULL, error);
319 return -error;
320}
321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100323xfs_file_release(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 struct inode *inode,
325 struct file *filp)
326{
Nathan Scottec86dc02006-03-17 17:25:36 +1100327 vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 int error = 0;
329
330 if (vp)
331 VOP_RELEASE(vp, error);
332 return -error;
333}
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100336xfs_file_fsync(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337 struct file *filp,
338 struct dentry *dentry,
339 int datasync)
340{
341 struct inode *inode = dentry->d_inode;
Nathan Scottec86dc02006-03-17 17:25:36 +1100342 vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 int error;
344 int flags = FSYNC_WAIT;
345
346 if (datasync)
347 flags |= FSYNC_DATA;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 VOP_FSYNC(vp, flags, NULL, (xfs_off_t)0, (xfs_off_t)-1, error);
349 return -error;
350}
351
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000352#ifdef CONFIG_XFS_DMAPI
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000353STATIC struct page *
Nathan Scott3562fd42006-03-14 14:00:35 +1100354xfs_vm_nopage(
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000355 struct vm_area_struct *area,
356 unsigned long address,
357 int *type)
358{
359 struct inode *inode = area->vm_file->f_dentry->d_inode;
Nathan Scottec86dc02006-03-17 17:25:36 +1100360 vnode_t *vp = vn_from_inode(inode);
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000361 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
362 int error;
363
364 ASSERT_ALWAYS(vp->v_vfsp->vfs_flag & VFS_DMI);
365
366 error = XFS_SEND_MMAP(mp, area, 0);
367 if (error)
368 return NULL;
369
370 return filemap_nopage(area, address, type);
371}
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000372#endif /* CONFIG_XFS_DMAPI */
373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100375xfs_file_readdir(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 struct file *filp,
377 void *dirent,
378 filldir_t filldir)
379{
380 int error = 0;
Nathan Scott1b895842006-03-31 13:08:59 +1000381 vnode_t *vp = vn_from_inode(filp->f_dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 uio_t uio;
383 iovec_t iov;
384 int eof = 0;
385 caddr_t read_buf;
386 int namelen, size = 0;
387 size_t rlen = PAGE_CACHE_SIZE;
388 xfs_off_t start_offset, curr_offset;
389 xfs_dirent_t *dbp = NULL;
390
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 /* Try fairly hard to get memory */
392 do {
393 if ((read_buf = (caddr_t)kmalloc(rlen, GFP_KERNEL)))
394 break;
395 rlen >>= 1;
396 } while (rlen >= 1024);
397
398 if (read_buf == NULL)
399 return -ENOMEM;
400
401 uio.uio_iov = &iov;
402 uio.uio_segflg = UIO_SYSSPACE;
403 curr_offset = filp->f_pos;
404 if (filp->f_pos != 0x7fffffff)
405 uio.uio_offset = filp->f_pos;
406 else
407 uio.uio_offset = 0xffffffff;
408
409 while (!eof) {
410 uio.uio_resid = iov.iov_len = rlen;
411 iov.iov_base = read_buf;
412 uio.uio_iovcnt = 1;
413
414 start_offset = uio.uio_offset;
415
416 VOP_READDIR(vp, &uio, NULL, &eof, error);
417 if ((uio.uio_offset == start_offset) || error) {
418 size = 0;
419 break;
420 }
421
422 size = rlen - uio.uio_resid;
423 dbp = (xfs_dirent_t *)read_buf;
424 while (size > 0) {
425 namelen = strlen(dbp->d_name);
426
427 if (filldir(dirent, dbp->d_name, namelen,
428 (loff_t) curr_offset & 0x7fffffff,
429 (ino_t) dbp->d_ino,
430 DT_UNKNOWN)) {
431 goto done;
432 }
433 size -= dbp->d_reclen;
434 curr_offset = (loff_t)dbp->d_off /* & 0x7fffffff */;
Nathan Scott1b895842006-03-31 13:08:59 +1000435 dbp = (xfs_dirent_t *)((char *)dbp + dbp->d_reclen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 }
437 }
438done:
439 if (!error) {
440 if (size == 0)
441 filp->f_pos = uio.uio_offset & 0x7fffffff;
442 else if (dbp)
443 filp->f_pos = curr_offset;
444 }
445
446 kfree(read_buf);
447 return -error;
448}
449
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100451xfs_file_mmap(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 struct file *filp,
453 struct vm_area_struct *vma)
454{
455 struct inode *ip = filp->f_dentry->d_inode;
Nathan Scottec86dc02006-03-17 17:25:36 +1100456 vnode_t *vp = vn_from_inode(ip);
Nathan Scott524fbf52006-03-14 14:07:53 +1100457 vattr_t vattr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 int error;
459
Nathan Scott3562fd42006-03-14 14:00:35 +1100460 vma->vm_ops = &xfs_file_vm_ops;
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000461
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000462#ifdef CONFIG_XFS_DMAPI
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000463 if (vp->v_vfsp->vfs_flag & VFS_DMI) {
Nathan Scott3562fd42006-03-14 14:00:35 +1100464 vma->vm_ops = &xfs_dmapi_file_vm_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 }
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000466#endif /* CONFIG_XFS_DMAPI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Nathan Scott524fbf52006-03-14 14:07:53 +1100468 vattr.va_mask = XFS_AT_UPDATIME;
469 VOP_SETATTR(vp, &vattr, XFS_AT_UPDATIME, NULL, error);
Nathan Scott220b5282006-03-14 13:33:36 +1100470 if (likely(!error))
Nathan Scott524fbf52006-03-14 14:07:53 +1100471 __vn_revalidate(vp, &vattr); /* update flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 return 0;
473}
474
475
476STATIC long
Nathan Scott3562fd42006-03-14 14:00:35 +1100477xfs_file_ioctl(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478 struct file *filp,
479 unsigned int cmd,
480 unsigned long arg)
481{
482 int error;
Nathan Scott1f6553f2006-03-14 13:30:48 +1100483 struct inode *inode = filp->f_dentry->d_inode;
Nathan Scottec86dc02006-03-17 17:25:36 +1100484 vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
486 VOP_IOCTL(vp, inode, filp, 0, cmd, (void __user *)arg, error);
487 VMODIFY(vp);
488
489 /* NOTE: some of the ioctl's return positive #'s as a
490 * byte count indicating success, such as
491 * readlink_by_handle. So we don't "sign flip"
492 * like most other routines. This means true
493 * errors need to be returned as a negative value.
494 */
495 return error;
496}
497
498STATIC long
Nathan Scott3562fd42006-03-14 14:00:35 +1100499xfs_file_ioctl_invis(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 struct file *filp,
501 unsigned int cmd,
502 unsigned long arg)
503{
Nathan Scott1f6553f2006-03-14 13:30:48 +1100504 struct inode *inode = filp->f_dentry->d_inode;
Nathan Scottec86dc02006-03-17 17:25:36 +1100505 vnode_t *vp = vn_from_inode(inode);
Nathan Scott1b895842006-03-31 13:08:59 +1000506 int error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 VOP_IOCTL(vp, inode, filp, IO_INVIS, cmd, (void __user *)arg, error);
509 VMODIFY(vp);
510
511 /* NOTE: some of the ioctl's return positive #'s as a
512 * byte count indicating success, such as
513 * readlink_by_handle. So we don't "sign flip"
514 * like most other routines. This means true
515 * errors need to be returned as a negative value.
516 */
517 return error;
518}
519
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000520#ifdef CONFIG_XFS_DMAPI
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521#ifdef HAVE_VMOP_MPROTECT
522STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100523xfs_vm_mprotect(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 struct vm_area_struct *vma,
525 unsigned int newflags)
526{
Nathan Scottec86dc02006-03-17 17:25:36 +1100527 vnode_t *vp = vn_from_inode(vma->vm_file->f_dentry->d_inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 int error = 0;
529
530 if (vp->v_vfsp->vfs_flag & VFS_DMI) {
531 if ((vma->vm_flags & VM_MAYSHARE) &&
532 (newflags & VM_WRITE) && !(vma->vm_flags & VM_WRITE)) {
533 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
534
535 error = XFS_SEND_MMAP(mp, vma, VM_WRITE);
536 }
537 }
538 return error;
539}
540#endif /* HAVE_VMOP_MPROTECT */
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000541#endif /* CONFIG_XFS_DMAPI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
543#ifdef HAVE_FOP_OPEN_EXEC
544/* If the user is attempting to execute a file that is offline then
545 * we have to trigger a DMAPI READ event before the file is marked as busy
546 * otherwise the invisible I/O will not be able to write to the file to bring
547 * it back online.
548 */
549STATIC int
Nathan Scott3562fd42006-03-14 14:00:35 +1100550xfs_file_open_exec(
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 struct inode *inode)
552{
Nathan Scottec86dc02006-03-17 17:25:36 +1100553 vnode_t *vp = vn_from_inode(inode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 xfs_mount_t *mp = XFS_VFSTOM(vp->v_vfsp);
555 int error = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 xfs_inode_t *ip;
557
558 if (vp->v_vfsp->vfs_flag & VFS_DMI) {
Christoph Hellwig75e17b32006-01-11 20:58:44 +1100559 ip = xfs_vtoi(vp);
560 if (!ip) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 error = -EINVAL;
562 goto open_exec_out;
563 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 if (DM_EVENT_ENABLED(vp->v_vfsp, ip, DM_EVENT_READ)) {
565 error = -XFS_SEND_DATA(mp, DM_EVENT_READ, vp,
566 0, 0, 0, NULL);
567 }
568 }
569open_exec_out:
570 return error;
571}
572#endif /* HAVE_FOP_OPEN_EXEC */
573
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800574const struct file_operations xfs_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 .llseek = generic_file_llseek,
576 .read = do_sync_read,
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000577 .write = do_sync_write,
Nathan Scott3562fd42006-03-14 14:00:35 +1100578 .readv = xfs_file_readv,
579 .writev = xfs_file_writev,
580 .aio_read = xfs_file_aio_read,
581 .aio_write = xfs_file_aio_write,
582 .sendfile = xfs_file_sendfile,
Nathan Scott1b895842006-03-31 13:08:59 +1000583 .splice_read = xfs_file_splice_read,
584 .splice_write = xfs_file_splice_write,
Nathan Scott3562fd42006-03-14 14:00:35 +1100585 .unlocked_ioctl = xfs_file_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586#ifdef CONFIG_COMPAT
Nathan Scott3562fd42006-03-14 14:00:35 +1100587 .compat_ioctl = xfs_file_compat_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588#endif
Nathan Scott3562fd42006-03-14 14:00:35 +1100589 .mmap = xfs_file_mmap,
590 .open = xfs_file_open,
591 .release = xfs_file_release,
592 .fsync = xfs_file_fsync,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593#ifdef HAVE_FOP_OPEN_EXEC
Nathan Scott3562fd42006-03-14 14:00:35 +1100594 .open_exec = xfs_file_open_exec,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595#endif
596};
597
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800598const struct file_operations xfs_invis_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 .llseek = generic_file_llseek,
600 .read = do_sync_read,
Dean Roehrichbb3f7242005-09-02 15:43:05 +1000601 .write = do_sync_write,
Nathan Scott3562fd42006-03-14 14:00:35 +1100602 .readv = xfs_file_readv_invis,
603 .writev = xfs_file_writev_invis,
604 .aio_read = xfs_file_aio_read_invis,
605 .aio_write = xfs_file_aio_write_invis,
Nathan Scott1b895842006-03-31 13:08:59 +1000606 .sendfile = xfs_file_sendfile_invis,
607 .splice_read = xfs_file_splice_read_invis,
608 .splice_write = xfs_file_splice_write_invis,
Nathan Scott3562fd42006-03-14 14:00:35 +1100609 .unlocked_ioctl = xfs_file_ioctl_invis,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610#ifdef CONFIG_COMPAT
Nathan Scott3562fd42006-03-14 14:00:35 +1100611 .compat_ioctl = xfs_file_compat_invis_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612#endif
Nathan Scott3562fd42006-03-14 14:00:35 +1100613 .mmap = xfs_file_mmap,
614 .open = xfs_file_open,
615 .release = xfs_file_release,
616 .fsync = xfs_file_fsync,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617};
618
619
Arjan van de Ven4b6f5d22006-03-28 01:56:42 -0800620const struct file_operations xfs_dir_file_operations = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 .read = generic_read_dir,
Nathan Scott3562fd42006-03-14 14:00:35 +1100622 .readdir = xfs_file_readdir,
623 .unlocked_ioctl = xfs_file_ioctl,
Nathan Scottd3870392005-05-06 06:44:46 -0700624#ifdef CONFIG_COMPAT
Nathan Scott3562fd42006-03-14 14:00:35 +1100625 .compat_ioctl = xfs_file_compat_ioctl,
Nathan Scottd3870392005-05-06 06:44:46 -0700626#endif
Nathan Scott3562fd42006-03-14 14:00:35 +1100627 .fsync = xfs_file_fsync,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628};
629
Nathan Scott3562fd42006-03-14 14:00:35 +1100630static struct vm_operations_struct xfs_file_vm_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 .nopage = filemap_nopage,
632 .populate = filemap_populate,
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000633};
634
635#ifdef CONFIG_XFS_DMAPI
Nathan Scott3562fd42006-03-14 14:00:35 +1100636static struct vm_operations_struct xfs_dmapi_file_vm_ops = {
637 .nopage = xfs_vm_nopage,
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000638 .populate = filemap_populate,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639#ifdef HAVE_VMOP_MPROTECT
Nathan Scott3562fd42006-03-14 14:00:35 +1100640 .mprotect = xfs_vm_mprotect,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641#endif
642};
Dean Roehrich6fac0cb2005-06-21 14:07:45 +1000643#endif /* CONFIG_XFS_DMAPI */