[XFS] Improve buffered read throughput by removing unnecessary timer calls
[safe/jmp/linux-2.6] / fs / xfs / linux-2.6 / xfs_iops.c
1 /*
2  * Copyright (c) 2000-2004 Silicon Graphics, Inc.  All Rights Reserved.
3  *
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.
7  *
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.
11  *
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.
18  *
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.
22  *
23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24  * Mountain View, CA  94043, or:
25  *
26  * http://www.sgi.com
27  *
28  * For further information regarding this notice, see:
29  *
30  * http://oss.sgi.com/projects/GenInfo/SGIGPLNoticeExplan/
31  */
32
33 #include "xfs.h"
34 #include "xfs_fs.h"
35 #include "xfs_inum.h"
36 #include "xfs_log.h"
37 #include "xfs_trans.h"
38 #include "xfs_sb.h"
39 #include "xfs_ag.h"
40 #include "xfs_dir.h"
41 #include "xfs_dir2.h"
42 #include "xfs_alloc.h"
43 #include "xfs_dmapi.h"
44 #include "xfs_quota.h"
45 #include "xfs_mount.h"
46 #include "xfs_alloc_btree.h"
47 #include "xfs_bmap_btree.h"
48 #include "xfs_ialloc_btree.h"
49 #include "xfs_btree.h"
50 #include "xfs_ialloc.h"
51 #include "xfs_attr_sf.h"
52 #include "xfs_dir_sf.h"
53 #include "xfs_dir2_sf.h"
54 #include "xfs_dinode.h"
55 #include "xfs_inode.h"
56 #include "xfs_bmap.h"
57 #include "xfs_bit.h"
58 #include "xfs_rtalloc.h"
59 #include "xfs_error.h"
60 #include "xfs_itable.h"
61 #include "xfs_rw.h"
62 #include "xfs_acl.h"
63 #include "xfs_cap.h"
64 #include "xfs_mac.h"
65 #include "xfs_attr.h"
66 #include "xfs_buf_item.h"
67 #include "xfs_utils.h"
68
69 #include <linux/xattr.h>
70 #include <linux/namei.h>
71
72 /*
73  * Change the requested timestamp in the given inode.
74  * We don't lock across timestamp updates, and we don't log them but
75  * we do record the fact that there is dirty information in core.
76  *
77  * NOTE -- callers MUST combine XFS_ICHGTIME_MOD or XFS_ICHGTIME_CHG
78  *              with XFS_ICHGTIME_ACC to be sure that access time
79  *              update will take.  Calling first with XFS_ICHGTIME_ACC
80  *              and then XFS_ICHGTIME_MOD may fail to modify the access
81  *              timestamp if the filesystem is mounted noacctm.
82  */
83 void
84 xfs_ichgtime(
85         xfs_inode_t     *ip,
86         int             flags)
87 {
88         struct inode    *inode = LINVFS_GET_IP(XFS_ITOV(ip));
89         timespec_t      tv;
90
91         /*
92          * We're not supposed to change timestamps in readonly-mounted
93          * filesystems.  Throw it away if anyone asks us.
94          */
95         if (unlikely(IS_RDONLY(inode)))
96                 return;
97
98         /*
99          * Don't update access timestamps on reads if mounted "noatime".
100          * Throw it away if anyone asks us.
101          */
102         if (unlikely(
103             (ip->i_mount->m_flags & XFS_MOUNT_NOATIME || IS_NOATIME(inode)) &&
104             (flags & (XFS_ICHGTIME_ACC|XFS_ICHGTIME_MOD|XFS_ICHGTIME_CHG)) ==
105                         XFS_ICHGTIME_ACC))
106                 return;
107
108         nanotime(&tv);
109         if (flags & XFS_ICHGTIME_MOD) {
110                 inode->i_mtime = tv;
111                 ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec;
112                 ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec;
113         }
114         if (flags & XFS_ICHGTIME_ACC) {
115                 inode->i_atime = tv;
116                 ip->i_d.di_atime.t_sec = (__int32_t)tv.tv_sec;
117                 ip->i_d.di_atime.t_nsec = (__int32_t)tv.tv_nsec;
118         }
119         if (flags & XFS_ICHGTIME_CHG) {
120                 inode->i_ctime = tv;
121                 ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec;
122                 ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec;
123         }
124
125         /*
126          * We update the i_update_core field _after_ changing
127          * the timestamps in order to coordinate properly with
128          * xfs_iflush() so that we don't lose timestamp updates.
129          * This keeps us from having to hold the inode lock
130          * while doing this.  We use the SYNCHRONIZE macro to
131          * ensure that the compiler does not reorder the update
132          * of i_update_core above the timestamp updates above.
133          */
134         SYNCHRONIZE();
135         ip->i_update_core = 1;
136         if (!(inode->i_state & I_LOCK))
137                 mark_inode_dirty_sync(inode);
138 }
139
140 /*
141  * Variant on the above which avoids querying the system clock
142  * in situations where we know the Linux inode timestamps have
143  * just been updated (and so we can update our inode cheaply).
144  * We also skip the readonly and noatime checks here, they are
145  * also catered for already.
146  */
147 void
148 xfs_ichgtime_fast(
149         xfs_inode_t     *ip,
150         struct inode    *inode,
151         int             flags)
152 {
153         timespec_t      *tvp;
154
155         /*
156          * We're not supposed to change timestamps in readonly-mounted
157          * filesystems.  Throw it away if anyone asks us.
158          */
159         if (unlikely(IS_RDONLY(inode)))
160                 return;
161
162         /*
163          * Don't update access timestamps on reads if mounted "noatime".
164          * Throw it away if anyone asks us.
165          */
166         if (unlikely(
167             (ip->i_mount->m_flags & XFS_MOUNT_NOATIME || IS_NOATIME(inode)) &&
168             ((flags & (XFS_ICHGTIME_ACC|XFS_ICHGTIME_MOD|XFS_ICHGTIME_CHG)) ==
169                         XFS_ICHGTIME_ACC)))
170                 return;
171
172         if (flags & XFS_ICHGTIME_MOD) {
173                 tvp = &inode->i_mtime;
174                 ip->i_d.di_mtime.t_sec = (__int32_t)tvp->tv_sec;
175                 ip->i_d.di_mtime.t_nsec = (__int32_t)tvp->tv_nsec;
176         }
177         if (flags & XFS_ICHGTIME_ACC) {
178                 tvp = &inode->i_atime;
179                 ip->i_d.di_atime.t_sec = (__int32_t)tvp->tv_sec;
180                 ip->i_d.di_atime.t_nsec = (__int32_t)tvp->tv_nsec;
181         }
182         if (flags & XFS_ICHGTIME_CHG) {
183                 tvp = &inode->i_ctime;
184                 ip->i_d.di_ctime.t_sec = (__int32_t)tvp->tv_sec;
185                 ip->i_d.di_ctime.t_nsec = (__int32_t)tvp->tv_nsec;
186         }
187
188         /*
189          * We update the i_update_core field _after_ changing
190          * the timestamps in order to coordinate properly with
191          * xfs_iflush() so that we don't lose timestamp updates.
192          * This keeps us from having to hold the inode lock
193          * while doing this.  We use the SYNCHRONIZE macro to
194          * ensure that the compiler does not reorder the update
195          * of i_update_core above the timestamp updates above.
196          */
197         SYNCHRONIZE();
198         ip->i_update_core = 1;
199         if (!(inode->i_state & I_LOCK))
200                 mark_inode_dirty_sync(inode);
201 }
202
203
204 /*
205  * Pull the link count and size up from the xfs inode to the linux inode
206  */
207 STATIC void
208 validate_fields(
209         struct inode    *ip)
210 {
211         vnode_t         *vp = LINVFS_GET_VP(ip);
212         vattr_t         va;
213         int             error;
214
215         va.va_mask = XFS_AT_NLINK|XFS_AT_SIZE|XFS_AT_NBLOCKS;
216         VOP_GETATTR(vp, &va, ATTR_LAZY, NULL, error);
217         if (likely(!error)) {
218                 ip->i_nlink = va.va_nlink;
219                 ip->i_blocks = va.va_nblocks;
220
221                 /* we're under i_sem so i_size can't change under us */
222                 if (i_size_read(ip) != va.va_size)
223                         i_size_write(ip, va.va_size);
224         }
225 }
226
227 /*
228  * Determine whether a process has a valid fs_struct (kernel daemons
229  * like knfsd don't have an fs_struct).
230  *
231  * XXX(hch):  nfsd is broken, better fix it instead.
232  */
233 STATIC inline int
234 has_fs_struct(struct task_struct *task)
235 {
236         return (task->fs != init_task.fs);
237 }
238
239 STATIC int
240 linvfs_mknod(
241         struct inode    *dir,
242         struct dentry   *dentry,
243         int             mode,
244         dev_t           rdev)
245 {
246         struct inode    *ip;
247         vattr_t         va;
248         vnode_t         *vp = NULL, *dvp = LINVFS_GET_VP(dir);
249         xfs_acl_t       *default_acl = NULL;
250         attrexists_t    test_default_acl = _ACL_DEFAULT_EXISTS;
251         int             error;
252
253         /*
254          * Irix uses Missed'em'V split, but doesn't want to see
255          * the upper 5 bits of (14bit) major.
256          */
257         if (!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff)
258                 return -EINVAL;
259
260         if (test_default_acl && test_default_acl(dvp)) {
261                 if (!_ACL_ALLOC(default_acl))
262                         return -ENOMEM;
263                 if (!_ACL_GET_DEFAULT(dvp, default_acl)) {
264                         _ACL_FREE(default_acl);
265                         default_acl = NULL;
266                 }
267         }
268
269         if (IS_POSIXACL(dir) && !default_acl && has_fs_struct(current))
270                 mode &= ~current->fs->umask;
271
272         memset(&va, 0, sizeof(va));
273         va.va_mask = XFS_AT_TYPE|XFS_AT_MODE;
274         va.va_mode = mode;
275
276         switch (mode & S_IFMT) {
277         case S_IFCHR: case S_IFBLK: case S_IFIFO: case S_IFSOCK:
278                 va.va_rdev = sysv_encode_dev(rdev);
279                 va.va_mask |= XFS_AT_RDEV;
280                 /*FALLTHROUGH*/
281         case S_IFREG:
282                 VOP_CREATE(dvp, dentry, &va, &vp, NULL, error);
283                 break;
284         case S_IFDIR:
285                 VOP_MKDIR(dvp, dentry, &va, &vp, NULL, error);
286                 break;
287         default:
288                 error = EINVAL;
289                 break;
290         }
291
292         if (default_acl) {
293                 if (!error) {
294                         error = _ACL_INHERIT(vp, &va, default_acl);
295                         if (!error) {
296                                 VMODIFY(vp);
297                         } else {
298                                 struct dentry   teardown = {};
299                                 int             err2;
300
301                                 /* Oh, the horror.
302                                  * If we can't add the ACL we must back out.
303                                  * ENOSPC can hit here, among other things.
304                                  */
305                                 teardown.d_inode = ip = LINVFS_GET_IP(vp);
306                                 teardown.d_name = dentry->d_name;
307
308                                 vn_mark_bad(vp);
309                                 
310                                 if (S_ISDIR(mode))
311                                         VOP_RMDIR(dvp, &teardown, NULL, err2);
312                                 else
313                                         VOP_REMOVE(dvp, &teardown, NULL, err2);
314                                 VN_RELE(vp);
315                         }
316                 }
317                 _ACL_FREE(default_acl);
318         }
319
320         if (!error) {
321                 ASSERT(vp);
322                 ip = LINVFS_GET_IP(vp);
323
324                 if (S_ISCHR(mode) || S_ISBLK(mode))
325                         ip->i_rdev = rdev;
326                 else if (S_ISDIR(mode))
327                         validate_fields(ip);
328                 d_instantiate(dentry, ip);
329                 validate_fields(dir);
330         }
331         return -error;
332 }
333
334 STATIC int
335 linvfs_create(
336         struct inode    *dir,
337         struct dentry   *dentry,
338         int             mode,
339         struct nameidata *nd)
340 {
341         return linvfs_mknod(dir, dentry, mode, 0);
342 }
343
344 STATIC int
345 linvfs_mkdir(
346         struct inode    *dir,
347         struct dentry   *dentry,
348         int             mode)
349 {
350         return linvfs_mknod(dir, dentry, mode|S_IFDIR, 0);
351 }
352
353 STATIC struct dentry *
354 linvfs_lookup(
355         struct inode    *dir,
356         struct dentry   *dentry,
357         struct nameidata *nd)
358 {
359         struct vnode    *vp = LINVFS_GET_VP(dir), *cvp;
360         int             error;
361
362         if (dentry->d_name.len >= MAXNAMELEN)
363                 return ERR_PTR(-ENAMETOOLONG);
364
365         VOP_LOOKUP(vp, dentry, &cvp, 0, NULL, NULL, error);
366         if (error) {
367                 if (unlikely(error != ENOENT))
368                         return ERR_PTR(-error);
369                 d_add(dentry, NULL);
370                 return NULL;
371         }
372
373         return d_splice_alias(LINVFS_GET_IP(cvp), dentry);
374 }
375
376 STATIC int
377 linvfs_link(
378         struct dentry   *old_dentry,
379         struct inode    *dir,
380         struct dentry   *dentry)
381 {
382         struct inode    *ip;    /* inode of guy being linked to */
383         vnode_t         *tdvp;  /* target directory for new name/link */
384         vnode_t         *vp;    /* vp of name being linked */
385         int             error;
386
387         ip = old_dentry->d_inode;       /* inode being linked to */
388         if (S_ISDIR(ip->i_mode))
389                 return -EPERM;
390
391         tdvp = LINVFS_GET_VP(dir);
392         vp = LINVFS_GET_VP(ip);
393
394         VOP_LINK(tdvp, vp, dentry, NULL, error);
395         if (!error) {
396                 VMODIFY(tdvp);
397                 VN_HOLD(vp);
398                 validate_fields(ip);
399                 d_instantiate(dentry, ip);
400         }
401         return -error;
402 }
403
404 STATIC int
405 linvfs_unlink(
406         struct inode    *dir,
407         struct dentry   *dentry)
408 {
409         struct inode    *inode;
410         vnode_t         *dvp;   /* directory containing name to remove */
411         int             error;
412
413         inode = dentry->d_inode;
414         dvp = LINVFS_GET_VP(dir);
415
416         VOP_REMOVE(dvp, dentry, NULL, error);
417         if (!error) {
418                 validate_fields(dir);   /* For size only */
419                 validate_fields(inode);
420         }
421
422         return -error;
423 }
424
425 STATIC int
426 linvfs_symlink(
427         struct inode    *dir,
428         struct dentry   *dentry,
429         const char      *symname)
430 {
431         struct inode    *ip;
432         vattr_t         va;
433         vnode_t         *dvp;   /* directory containing name of symlink */
434         vnode_t         *cvp;   /* used to lookup symlink to put in dentry */
435         int             error;
436
437         dvp = LINVFS_GET_VP(dir);
438         cvp = NULL;
439
440         memset(&va, 0, sizeof(va));
441         va.va_mode = S_IFLNK |
442                 (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO);
443         va.va_mask = XFS_AT_TYPE|XFS_AT_MODE;
444
445         error = 0;
446         VOP_SYMLINK(dvp, dentry, &va, (char *)symname, &cvp, NULL, error);
447         if (!error && cvp) {
448                 ip = LINVFS_GET_IP(cvp);
449                 d_instantiate(dentry, ip);
450                 validate_fields(dir);
451                 validate_fields(ip); /* size needs update */
452         }
453         return -error;
454 }
455
456 STATIC int
457 linvfs_rmdir(
458         struct inode    *dir,
459         struct dentry   *dentry)
460 {
461         struct inode    *inode = dentry->d_inode;
462         vnode_t         *dvp = LINVFS_GET_VP(dir);
463         int             error;
464
465         VOP_RMDIR(dvp, dentry, NULL, error);
466         if (!error) {
467                 validate_fields(inode);
468                 validate_fields(dir);
469         }
470         return -error;
471 }
472
473 STATIC int
474 linvfs_rename(
475         struct inode    *odir,
476         struct dentry   *odentry,
477         struct inode    *ndir,
478         struct dentry   *ndentry)
479 {
480         struct inode    *new_inode = ndentry->d_inode;
481         vnode_t         *fvp;   /* from directory */
482         vnode_t         *tvp;   /* target directory */
483         int             error;
484
485         fvp = LINVFS_GET_VP(odir);
486         tvp = LINVFS_GET_VP(ndir);
487
488         VOP_RENAME(fvp, odentry, tvp, ndentry, NULL, error);
489         if (error)
490                 return -error;
491
492         if (new_inode)
493                 validate_fields(new_inode);
494
495         validate_fields(odir);
496         if (ndir != odir)
497                 validate_fields(ndir);
498         return 0;
499 }
500
501 /*
502  * careful here - this function can get called recursively, so
503  * we need to be very careful about how much stack we use.
504  * uio is kmalloced for this reason...
505  */
506 STATIC void *
507 linvfs_follow_link(
508         struct dentry           *dentry,
509         struct nameidata        *nd)
510 {
511         vnode_t                 *vp;
512         uio_t                   *uio;
513         iovec_t                 iov;
514         int                     error;
515         char                    *link;
516
517         ASSERT(dentry);
518         ASSERT(nd);
519
520         link = (char *)kmalloc(MAXNAMELEN+1, GFP_KERNEL);
521         if (!link) {
522                 nd_set_link(nd, ERR_PTR(-ENOMEM));
523                 return NULL;
524         }
525
526         uio = (uio_t *)kmalloc(sizeof(uio_t), GFP_KERNEL);
527         if (!uio) {
528                 kfree(link);
529                 nd_set_link(nd, ERR_PTR(-ENOMEM));
530                 return NULL;
531         }
532
533         vp = LINVFS_GET_VP(dentry->d_inode);
534
535         iov.iov_base = link;
536         iov.iov_len = MAXNAMELEN;
537
538         uio->uio_iov = &iov;
539         uio->uio_offset = 0;
540         uio->uio_segflg = UIO_SYSSPACE;
541         uio->uio_resid = MAXNAMELEN;
542         uio->uio_iovcnt = 1;
543
544         VOP_READLINK(vp, uio, 0, NULL, error);
545         if (error) {
546                 kfree(link);
547                 link = ERR_PTR(-error);
548         } else {
549                 link[MAXNAMELEN - uio->uio_resid] = '\0';
550         }
551         kfree(uio);
552
553         nd_set_link(nd, link);
554         return NULL;
555 }
556
557 STATIC void
558 linvfs_put_link(
559         struct dentry   *dentry,
560         struct nameidata *nd,
561         void            *p)
562 {
563         char            *s = nd_get_link(nd);
564
565         if (!IS_ERR(s))
566                 kfree(s);
567 }
568
569 #ifdef CONFIG_XFS_POSIX_ACL
570 STATIC int
571 linvfs_permission(
572         struct inode    *inode,
573         int             mode,
574         struct nameidata *nd)
575 {
576         vnode_t         *vp = LINVFS_GET_VP(inode);
577         int             error;
578
579         mode <<= 6;             /* convert from linux to vnode access bits */
580         VOP_ACCESS(vp, mode, NULL, error);
581         return -error;
582 }
583 #else
584 #define linvfs_permission NULL
585 #endif
586
587 STATIC int
588 linvfs_getattr(
589         struct vfsmount *mnt,
590         struct dentry   *dentry,
591         struct kstat    *stat)
592 {
593         struct inode    *inode = dentry->d_inode;
594         vnode_t         *vp = LINVFS_GET_VP(inode);
595         int             error = 0;
596
597         if (unlikely(vp->v_flag & VMODIFIED))
598                 error = vn_revalidate(vp);
599         if (!error)
600                 generic_fillattr(inode, stat);
601         return 0;
602 }
603
604 STATIC int
605 linvfs_setattr(
606         struct dentry   *dentry,
607         struct iattr    *attr)
608 {
609         struct inode    *inode = dentry->d_inode;
610         unsigned int    ia_valid = attr->ia_valid;
611         vnode_t         *vp = LINVFS_GET_VP(inode);
612         vattr_t         vattr;
613         int             flags = 0;
614         int             error;
615
616         memset(&vattr, 0, sizeof(vattr_t));
617         if (ia_valid & ATTR_UID) {
618                 vattr.va_mask |= XFS_AT_UID;
619                 vattr.va_uid = attr->ia_uid;
620         }
621         if (ia_valid & ATTR_GID) {
622                 vattr.va_mask |= XFS_AT_GID;
623                 vattr.va_gid = attr->ia_gid;
624         }
625         if (ia_valid & ATTR_SIZE) {
626                 vattr.va_mask |= XFS_AT_SIZE;
627                 vattr.va_size = attr->ia_size;
628         }
629         if (ia_valid & ATTR_ATIME) {
630                 vattr.va_mask |= XFS_AT_ATIME;
631                 vattr.va_atime = attr->ia_atime;
632         }
633         if (ia_valid & ATTR_MTIME) {
634                 vattr.va_mask |= XFS_AT_MTIME;
635                 vattr.va_mtime = attr->ia_mtime;
636         }
637         if (ia_valid & ATTR_CTIME) {
638                 vattr.va_mask |= XFS_AT_CTIME;
639                 vattr.va_ctime = attr->ia_ctime;
640         }
641         if (ia_valid & ATTR_MODE) {
642                 vattr.va_mask |= XFS_AT_MODE;
643                 vattr.va_mode = attr->ia_mode;
644                 if (!in_group_p(inode->i_gid) && !capable(CAP_FSETID))
645                         inode->i_mode &= ~S_ISGID;
646         }
647
648         if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))
649                 flags |= ATTR_UTIME;
650 #ifdef ATTR_NO_BLOCK
651         if ((ia_valid & ATTR_NO_BLOCK))
652                 flags |= ATTR_NONBLOCK;
653 #endif
654
655         VOP_SETATTR(vp, &vattr, flags, NULL, error);
656         if (error)
657                 return -error;
658         vn_revalidate(vp);
659         return error;
660 }
661
662 STATIC void
663 linvfs_truncate(
664         struct inode    *inode)
665 {
666         block_truncate_page(inode->i_mapping, inode->i_size, linvfs_get_block);
667 }
668
669 STATIC int
670 linvfs_setxattr(
671         struct dentry   *dentry,
672         const char      *name,
673         const void      *data,
674         size_t          size,
675         int             flags)
676 {
677         vnode_t         *vp = LINVFS_GET_VP(dentry->d_inode);
678         char            *attr = (char *)name;
679         attrnames_t     *namesp;
680         int             xflags = 0;
681         int             error;
682
683         namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
684         if (!namesp)
685                 return -EOPNOTSUPP;
686         attr += namesp->attr_namelen;
687         error = namesp->attr_capable(vp, NULL);
688         if (error)
689                 return error;
690
691         /* Convert Linux syscall to XFS internal ATTR flags */
692         if (flags & XATTR_CREATE)
693                 xflags |= ATTR_CREATE;
694         if (flags & XATTR_REPLACE)
695                 xflags |= ATTR_REPLACE;
696         xflags |= namesp->attr_flag;
697         return namesp->attr_set(vp, attr, (void *)data, size, xflags);
698 }
699
700 STATIC ssize_t
701 linvfs_getxattr(
702         struct dentry   *dentry,
703         const char      *name,
704         void            *data,
705         size_t          size)
706 {
707         vnode_t         *vp = LINVFS_GET_VP(dentry->d_inode);
708         char            *attr = (char *)name;
709         attrnames_t     *namesp;
710         int             xflags = 0;
711         ssize_t         error;
712
713         namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
714         if (!namesp)
715                 return -EOPNOTSUPP;
716         attr += namesp->attr_namelen;
717         error = namesp->attr_capable(vp, NULL);
718         if (error)
719                 return error;
720
721         /* Convert Linux syscall to XFS internal ATTR flags */
722         if (!size) {
723                 xflags |= ATTR_KERNOVAL;
724                 data = NULL;
725         }
726         xflags |= namesp->attr_flag;
727         return namesp->attr_get(vp, attr, (void *)data, size, xflags);
728 }
729
730 STATIC ssize_t
731 linvfs_listxattr(
732         struct dentry           *dentry,
733         char                    *data,
734         size_t                  size)
735 {
736         vnode_t                 *vp = LINVFS_GET_VP(dentry->d_inode);
737         int                     error, xflags = ATTR_KERNAMELS;
738         ssize_t                 result;
739
740         if (!size)
741                 xflags |= ATTR_KERNOVAL;
742         xflags |= capable(CAP_SYS_ADMIN) ? ATTR_KERNFULLS : ATTR_KERNORMALS;
743
744         error = attr_generic_list(vp, data, size, xflags, &result);
745         if (error < 0)
746                 return error;
747         return result;
748 }
749
750 STATIC int
751 linvfs_removexattr(
752         struct dentry   *dentry,
753         const char      *name)
754 {
755         vnode_t         *vp = LINVFS_GET_VP(dentry->d_inode);
756         char            *attr = (char *)name;
757         attrnames_t     *namesp;
758         int             xflags = 0;
759         int             error;
760
761         namesp = attr_lookup_namespace(attr, attr_namespaces, ATTR_NAMECOUNT);
762         if (!namesp)
763                 return -EOPNOTSUPP;
764         attr += namesp->attr_namelen;
765         error = namesp->attr_capable(vp, NULL);
766         if (error)
767                 return error;
768         xflags |= namesp->attr_flag;
769         return namesp->attr_remove(vp, attr, xflags);
770 }
771
772
773 struct inode_operations linvfs_file_inode_operations = {
774         .permission             = linvfs_permission,
775         .truncate               = linvfs_truncate,
776         .getattr                = linvfs_getattr,
777         .setattr                = linvfs_setattr,
778         .setxattr               = linvfs_setxattr,
779         .getxattr               = linvfs_getxattr,
780         .listxattr              = linvfs_listxattr,
781         .removexattr            = linvfs_removexattr,
782 };
783
784 struct inode_operations linvfs_dir_inode_operations = {
785         .create                 = linvfs_create,
786         .lookup                 = linvfs_lookup,
787         .link                   = linvfs_link,
788         .unlink                 = linvfs_unlink,
789         .symlink                = linvfs_symlink,
790         .mkdir                  = linvfs_mkdir,
791         .rmdir                  = linvfs_rmdir,
792         .mknod                  = linvfs_mknod,
793         .rename                 = linvfs_rename,
794         .permission             = linvfs_permission,
795         .getattr                = linvfs_getattr,
796         .setattr                = linvfs_setattr,
797         .setxattr               = linvfs_setxattr,
798         .getxattr               = linvfs_getxattr,
799         .listxattr              = linvfs_listxattr,
800         .removexattr            = linvfs_removexattr,
801 };
802
803 struct inode_operations linvfs_symlink_inode_operations = {
804         .readlink               = generic_readlink,
805         .follow_link            = linvfs_follow_link,
806         .put_link               = linvfs_put_link,
807         .permission             = linvfs_permission,
808         .getattr                = linvfs_getattr,
809         .setattr                = linvfs_setattr,
810         .setxattr               = linvfs_setxattr,
811         .getxattr               = linvfs_getxattr,
812         .listxattr              = linvfs_listxattr,
813         .removexattr            = linvfs_removexattr,
814 };