]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - fs/xfs/linux-2.6/xfs_iops.c
[XFS] optimize xfs_ichgtime
[linux-2.6-omap-h63xx.git] / fs / xfs / linux-2.6 / xfs_iops.c
1 /*
2  * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3  * All Rights Reserved.
4  *
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
7  * published by the Free Software Foundation.
8  *
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.
13  *
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
17  */
18 #include "xfs.h"
19 #include "xfs_fs.h"
20 #include "xfs_bit.h"
21 #include "xfs_log.h"
22 #include "xfs_inum.h"
23 #include "xfs_trans.h"
24 #include "xfs_sb.h"
25 #include "xfs_ag.h"
26 #include "xfs_dir2.h"
27 #include "xfs_alloc.h"
28 #include "xfs_dmapi.h"
29 #include "xfs_quota.h"
30 #include "xfs_mount.h"
31 #include "xfs_bmap_btree.h"
32 #include "xfs_alloc_btree.h"
33 #include "xfs_ialloc_btree.h"
34 #include "xfs_dir2_sf.h"
35 #include "xfs_attr_sf.h"
36 #include "xfs_dinode.h"
37 #include "xfs_inode.h"
38 #include "xfs_bmap.h"
39 #include "xfs_btree.h"
40 #include "xfs_ialloc.h"
41 #include "xfs_rtalloc.h"
42 #include "xfs_error.h"
43 #include "xfs_itable.h"
44 #include "xfs_rw.h"
45 #include "xfs_acl.h"
46 #include "xfs_attr.h"
47 #include "xfs_buf_item.h"
48 #include "xfs_utils.h"
49 #include "xfs_vnodeops.h"
50
51 #include <linux/capability.h>
52 #include <linux/xattr.h>
53 #include <linux/namei.h>
54 #include <linux/security.h>
55 #include <linux/falloc.h>
56
57 /*
58  * Bring the atime in the XFS inode uptodate.
59  * Used before logging the inode to disk or when the Linux inode goes away.
60  */
61 void
62 xfs_synchronize_atime(
63         xfs_inode_t     *ip)
64 {
65         struct inode    *inode = VFS_I(ip);
66
67         if (inode) {
68                 ip->i_d.di_atime.t_sec = (__int32_t)inode->i_atime.tv_sec;
69                 ip->i_d.di_atime.t_nsec = (__int32_t)inode->i_atime.tv_nsec;
70         }
71 }
72
73 /*
74  * If the linux inode exists, mark it dirty.
75  * Used when commiting a dirty inode into a transaction so that
76  * the inode will get written back by the linux code
77  */
78 void
79 xfs_mark_inode_dirty_sync(
80         xfs_inode_t     *ip)
81 {
82         struct inode    *inode = VFS_I(ip);
83
84         if (inode)
85                 mark_inode_dirty_sync(inode);
86 }
87
88 /*
89  * Change the requested timestamp in the given inode.
90  * We don't lock across timestamp updates, and we don't log them but
91  * we do record the fact that there is dirty information in core.
92  */
93 void
94 xfs_ichgtime(
95         xfs_inode_t     *ip,
96         int             flags)
97 {
98         struct inode    *inode = VFS_I(ip);
99         timespec_t      tv;
100         int             sync_it = 0;
101
102         tv = current_fs_time(inode->i_sb);
103
104         if ((flags & XFS_ICHGTIME_MOD) &&
105             !timespec_equal(&inode->i_mtime, &tv)) {
106                 inode->i_mtime = tv;
107                 ip->i_d.di_mtime.t_sec = (__int32_t)tv.tv_sec;
108                 ip->i_d.di_mtime.t_nsec = (__int32_t)tv.tv_nsec;
109                 sync_it = 1;
110         }
111         if ((flags & XFS_ICHGTIME_CHG) &&
112             !timespec_equal(&inode->i_ctime, &tv)) {
113                 inode->i_ctime = tv;
114                 ip->i_d.di_ctime.t_sec = (__int32_t)tv.tv_sec;
115                 ip->i_d.di_ctime.t_nsec = (__int32_t)tv.tv_nsec;
116                 sync_it = 1;
117         }
118
119         /*
120          * We update the i_update_core field _after_ changing
121          * the timestamps in order to coordinate properly with
122          * xfs_iflush() so that we don't lose timestamp updates.
123          * This keeps us from having to hold the inode lock
124          * while doing this.  We use the SYNCHRONIZE macro to
125          * ensure that the compiler does not reorder the update
126          * of i_update_core above the timestamp updates above.
127          */
128         if (sync_it) {
129                 SYNCHRONIZE();
130                 ip->i_update_core = 1;
131                 mark_inode_dirty_sync(inode);
132         }
133 }
134
135 /*
136  * Variant on the above which avoids querying the system clock
137  * in situations where we know the Linux inode timestamps have
138  * just been updated (and so we can update our inode cheaply).
139  */
140 void
141 xfs_ichgtime_fast(
142         xfs_inode_t     *ip,
143         struct inode    *inode,
144         int             flags)
145 {
146         timespec_t      *tvp;
147
148         if (flags & XFS_ICHGTIME_MOD) {
149                 tvp = &inode->i_mtime;
150                 ip->i_d.di_mtime.t_sec = (__int32_t)tvp->tv_sec;
151                 ip->i_d.di_mtime.t_nsec = (__int32_t)tvp->tv_nsec;
152         }
153         if (flags & XFS_ICHGTIME_CHG) {
154                 tvp = &inode->i_ctime;
155                 ip->i_d.di_ctime.t_sec = (__int32_t)tvp->tv_sec;
156                 ip->i_d.di_ctime.t_nsec = (__int32_t)tvp->tv_nsec;
157         }
158
159         /*
160          * We update the i_update_core field _after_ changing
161          * the timestamps in order to coordinate properly with
162          * xfs_iflush() so that we don't lose timestamp updates.
163          * This keeps us from having to hold the inode lock
164          * while doing this.  We use the SYNCHRONIZE macro to
165          * ensure that the compiler does not reorder the update
166          * of i_update_core above the timestamp updates above.
167          */
168         SYNCHRONIZE();
169         ip->i_update_core = 1;
170         if (!(inode->i_state & I_NEW))
171                 mark_inode_dirty_sync(inode);
172 }
173
174 /*
175  * Hook in SELinux.  This is not quite correct yet, what we really need
176  * here (as we do for default ACLs) is a mechanism by which creation of
177  * these attrs can be journalled at inode creation time (along with the
178  * inode, of course, such that log replay can't cause these to be lost).
179  */
180 STATIC int
181 xfs_init_security(
182         struct inode    *inode,
183         struct inode    *dir)
184 {
185         struct xfs_inode *ip = XFS_I(inode);
186         size_t          length;
187         void            *value;
188         char            *name;
189         int             error;
190
191         error = security_inode_init_security(inode, dir, &name,
192                                              &value, &length);
193         if (error) {
194                 if (error == -EOPNOTSUPP)
195                         return 0;
196                 return -error;
197         }
198
199         error = xfs_attr_set(ip, name, value, length, ATTR_SECURE);
200         if (!error)
201                 xfs_iflags_set(ip, XFS_IMODIFIED);
202
203         kfree(name);
204         kfree(value);
205         return error;
206 }
207
208 static void
209 xfs_dentry_to_name(
210         struct xfs_name *namep,
211         struct dentry   *dentry)
212 {
213         namep->name = dentry->d_name.name;
214         namep->len = dentry->d_name.len;
215 }
216
217 STATIC void
218 xfs_cleanup_inode(
219         struct inode    *dir,
220         struct inode    *inode,
221         struct dentry   *dentry)
222 {
223         struct xfs_name teardown;
224
225         /* Oh, the horror.
226          * If we can't add the ACL or we fail in
227          * xfs_init_security we must back out.
228          * ENOSPC can hit here, among other things.
229          */
230         xfs_dentry_to_name(&teardown, dentry);
231
232         xfs_remove(XFS_I(dir), &teardown, XFS_I(inode));
233         iput(inode);
234 }
235
236 STATIC int
237 xfs_vn_mknod(
238         struct inode    *dir,
239         struct dentry   *dentry,
240         int             mode,
241         dev_t           rdev)
242 {
243         struct inode    *inode;
244         struct xfs_inode *ip = NULL;
245         xfs_acl_t       *default_acl = NULL;
246         struct xfs_name name;
247         int (*test_default_acl)(struct inode *) = _ACL_DEFAULT_EXISTS;
248         int             error;
249
250         /*
251          * Irix uses Missed'em'V split, but doesn't want to see
252          * the upper 5 bits of (14bit) major.
253          */
254         if (unlikely(!sysv_valid_dev(rdev) || MAJOR(rdev) & ~0x1ff))
255                 return -EINVAL;
256
257         if (test_default_acl && test_default_acl(dir)) {
258                 if (!_ACL_ALLOC(default_acl)) {
259                         return -ENOMEM;
260                 }
261                 if (!_ACL_GET_DEFAULT(dir, default_acl)) {
262                         _ACL_FREE(default_acl);
263                         default_acl = NULL;
264                 }
265         }
266
267         xfs_dentry_to_name(&name, dentry);
268
269         if (IS_POSIXACL(dir) && !default_acl)
270                 mode &= ~current->fs->umask;
271
272         switch (mode & S_IFMT) {
273         case S_IFCHR:
274         case S_IFBLK:
275         case S_IFIFO:
276         case S_IFSOCK:
277                 rdev = sysv_encode_dev(rdev);
278         case S_IFREG:
279                 error = xfs_create(XFS_I(dir), &name, mode, rdev, &ip, NULL);
280                 break;
281         case S_IFDIR:
282                 error = xfs_mkdir(XFS_I(dir), &name, mode, &ip, NULL);
283                 break;
284         default:
285                 error = EINVAL;
286                 break;
287         }
288
289         if (unlikely(error))
290                 goto out_free_acl;
291
292         inode = VFS_I(ip);
293
294         error = xfs_init_security(inode, dir);
295         if (unlikely(error))
296                 goto out_cleanup_inode;
297
298         if (default_acl) {
299                 error = _ACL_INHERIT(inode, mode, default_acl);
300                 if (unlikely(error))
301                         goto out_cleanup_inode;
302                 xfs_iflags_set(ip, XFS_IMODIFIED);
303                 _ACL_FREE(default_acl);
304         }
305
306
307         d_instantiate(dentry, inode);
308         return -error;
309
310  out_cleanup_inode:
311         xfs_cleanup_inode(dir, inode, dentry);
312  out_free_acl:
313         if (default_acl)
314                 _ACL_FREE(default_acl);
315         return -error;
316 }
317
318 STATIC int
319 xfs_vn_create(
320         struct inode    *dir,
321         struct dentry   *dentry,
322         int             mode,
323         struct nameidata *nd)
324 {
325         return xfs_vn_mknod(dir, dentry, mode, 0);
326 }
327
328 STATIC int
329 xfs_vn_mkdir(
330         struct inode    *dir,
331         struct dentry   *dentry,
332         int             mode)
333 {
334         return xfs_vn_mknod(dir, dentry, mode|S_IFDIR, 0);
335 }
336
337 STATIC struct dentry *
338 xfs_vn_lookup(
339         struct inode    *dir,
340         struct dentry   *dentry,
341         struct nameidata *nd)
342 {
343         struct xfs_inode *cip;
344         struct xfs_name name;
345         int             error;
346
347         if (dentry->d_name.len >= MAXNAMELEN)
348                 return ERR_PTR(-ENAMETOOLONG);
349
350         xfs_dentry_to_name(&name, dentry);
351         error = xfs_lookup(XFS_I(dir), &name, &cip, NULL);
352         if (unlikely(error)) {
353                 if (unlikely(error != ENOENT))
354                         return ERR_PTR(-error);
355                 d_add(dentry, NULL);
356                 return NULL;
357         }
358
359         return d_splice_alias(VFS_I(cip), dentry);
360 }
361
362 STATIC struct dentry *
363 xfs_vn_ci_lookup(
364         struct inode    *dir,
365         struct dentry   *dentry,
366         struct nameidata *nd)
367 {
368         struct xfs_inode *ip;
369         struct xfs_name xname;
370         struct xfs_name ci_name;
371         struct qstr     dname;
372         int             error;
373
374         if (dentry->d_name.len >= MAXNAMELEN)
375                 return ERR_PTR(-ENAMETOOLONG);
376
377         xfs_dentry_to_name(&xname, dentry);
378         error = xfs_lookup(XFS_I(dir), &xname, &ip, &ci_name);
379         if (unlikely(error)) {
380                 if (unlikely(error != ENOENT))
381                         return ERR_PTR(-error);
382                 /*
383                  * call d_add(dentry, NULL) here when d_drop_negative_children
384                  * is called in xfs_vn_mknod (ie. allow negative dentries
385                  * with CI filesystems).
386                  */
387                 return NULL;
388         }
389
390         /* if exact match, just splice and exit */
391         if (!ci_name.name)
392                 return d_splice_alias(VFS_I(ip), dentry);
393
394         /* else case-insensitive match... */
395         dname.name = ci_name.name;
396         dname.len = ci_name.len;
397         dentry = d_add_ci(VFS_I(ip), dentry, &dname);
398         kmem_free(ci_name.name);
399         return dentry;
400 }
401
402 STATIC int
403 xfs_vn_link(
404         struct dentry   *old_dentry,
405         struct inode    *dir,
406         struct dentry   *dentry)
407 {
408         struct inode    *inode; /* inode of guy being linked to */
409         struct xfs_name name;
410         int             error;
411
412         inode = old_dentry->d_inode;
413         xfs_dentry_to_name(&name, dentry);
414
415         igrab(inode);
416         error = xfs_link(XFS_I(dir), XFS_I(inode), &name);
417         if (unlikely(error)) {
418                 iput(inode);
419                 return -error;
420         }
421
422         xfs_iflags_set(XFS_I(dir), XFS_IMODIFIED);
423         d_instantiate(dentry, inode);
424         return 0;
425 }
426
427 STATIC int
428 xfs_vn_unlink(
429         struct inode    *dir,
430         struct dentry   *dentry)
431 {
432         struct xfs_name name;
433         int             error;
434
435         xfs_dentry_to_name(&name, dentry);
436
437         error = -xfs_remove(XFS_I(dir), &name, XFS_I(dentry->d_inode));
438         if (error)
439                 return error;
440
441         /*
442          * With unlink, the VFS makes the dentry "negative": no inode,
443          * but still hashed. This is incompatible with case-insensitive
444          * mode, so invalidate (unhash) the dentry in CI-mode.
445          */
446         if (xfs_sb_version_hasasciici(&XFS_M(dir->i_sb)->m_sb))
447                 d_invalidate(dentry);
448         return 0;
449 }
450
451 STATIC int
452 xfs_vn_symlink(
453         struct inode    *dir,
454         struct dentry   *dentry,
455         const char      *symname)
456 {
457         struct inode    *inode;
458         struct xfs_inode *cip = NULL;
459         struct xfs_name name;
460         int             error;
461         mode_t          mode;
462
463         mode = S_IFLNK |
464                 (irix_symlink_mode ? 0777 & ~current->fs->umask : S_IRWXUGO);
465         xfs_dentry_to_name(&name, dentry);
466
467         error = xfs_symlink(XFS_I(dir), &name, symname, mode, &cip, NULL);
468         if (unlikely(error))
469                 goto out;
470
471         inode = VFS_I(cip);
472
473         error = xfs_init_security(inode, dir);
474         if (unlikely(error))
475                 goto out_cleanup_inode;
476
477         d_instantiate(dentry, inode);
478         return 0;
479
480  out_cleanup_inode:
481         xfs_cleanup_inode(dir, inode, dentry);
482  out:
483         return -error;
484 }
485
486 STATIC int
487 xfs_vn_rename(
488         struct inode    *odir,
489         struct dentry   *odentry,
490         struct inode    *ndir,
491         struct dentry   *ndentry)
492 {
493         struct inode    *new_inode = ndentry->d_inode;
494         struct xfs_name oname;
495         struct xfs_name nname;
496
497         xfs_dentry_to_name(&oname, odentry);
498         xfs_dentry_to_name(&nname, ndentry);
499
500         return -xfs_rename(XFS_I(odir), &oname, XFS_I(odentry->d_inode),
501                            XFS_I(ndir), &nname, new_inode ?
502                                                 XFS_I(new_inode) : NULL);
503 }
504
505 /*
506  * careful here - this function can get called recursively, so
507  * we need to be very careful about how much stack we use.
508  * uio is kmalloced for this reason...
509  */
510 STATIC void *
511 xfs_vn_follow_link(
512         struct dentry           *dentry,
513         struct nameidata        *nd)
514 {
515         char                    *link;
516         int                     error = -ENOMEM;
517
518         link = kmalloc(MAXPATHLEN+1, GFP_KERNEL);
519         if (!link)
520                 goto out_err;
521
522         error = -xfs_readlink(XFS_I(dentry->d_inode), link);
523         if (unlikely(error))
524                 goto out_kfree;
525
526         nd_set_link(nd, link);
527         return NULL;
528
529  out_kfree:
530         kfree(link);
531  out_err:
532         nd_set_link(nd, ERR_PTR(error));
533         return NULL;
534 }
535
536 STATIC void
537 xfs_vn_put_link(
538         struct dentry   *dentry,
539         struct nameidata *nd,
540         void            *p)
541 {
542         char            *s = nd_get_link(nd);
543
544         if (!IS_ERR(s))
545                 kfree(s);
546 }
547
548 #ifdef CONFIG_XFS_POSIX_ACL
549 STATIC int
550 xfs_check_acl(
551         struct inode            *inode,
552         int                     mask)
553 {
554         struct xfs_inode        *ip = XFS_I(inode);
555         int                     error;
556
557         xfs_itrace_entry(ip);
558
559         if (XFS_IFORK_Q(ip)) {
560                 error = xfs_acl_iaccess(ip, mask, NULL);
561                 if (error != -1)
562                         return -error;
563         }
564
565         return -EAGAIN;
566 }
567
568 STATIC int
569 xfs_vn_permission(
570         struct inode            *inode,
571         int                     mask)
572 {
573         return generic_permission(inode, mask, xfs_check_acl);
574 }
575 #else
576 #define xfs_vn_permission NULL
577 #endif
578
579 STATIC int
580 xfs_vn_getattr(
581         struct vfsmount         *mnt,
582         struct dentry           *dentry,
583         struct kstat            *stat)
584 {
585         struct inode            *inode = dentry->d_inode;
586         struct xfs_inode        *ip = XFS_I(inode);
587         struct xfs_mount        *mp = ip->i_mount;
588
589         xfs_itrace_entry(ip);
590
591         if (XFS_FORCED_SHUTDOWN(mp))
592                 return XFS_ERROR(EIO);
593
594         stat->size = XFS_ISIZE(ip);
595         stat->dev = inode->i_sb->s_dev;
596         stat->mode = ip->i_d.di_mode;
597         stat->nlink = ip->i_d.di_nlink;
598         stat->uid = ip->i_d.di_uid;
599         stat->gid = ip->i_d.di_gid;
600         stat->ino = ip->i_ino;
601 #if XFS_BIG_INUMS
602         stat->ino += mp->m_inoadd;
603 #endif
604         stat->atime = inode->i_atime;
605         stat->mtime.tv_sec = ip->i_d.di_mtime.t_sec;
606         stat->mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
607         stat->ctime.tv_sec = ip->i_d.di_ctime.t_sec;
608         stat->ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
609         stat->blocks =
610                 XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
611
612
613         switch (inode->i_mode & S_IFMT) {
614         case S_IFBLK:
615         case S_IFCHR:
616                 stat->blksize = BLKDEV_IOSIZE;
617                 stat->rdev = MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
618                                    sysv_minor(ip->i_df.if_u2.if_rdev));
619                 break;
620         default:
621                 if (XFS_IS_REALTIME_INODE(ip)) {
622                         /*
623                          * If the file blocks are being allocated from a
624                          * realtime volume, then return the inode's realtime
625                          * extent size or the realtime volume's extent size.
626                          */
627                         stat->blksize =
628                                 xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
629                 } else
630                         stat->blksize = xfs_preferred_iosize(mp);
631                 stat->rdev = 0;
632                 break;
633         }
634
635         return 0;
636 }
637
638 STATIC int
639 xfs_vn_setattr(
640         struct dentry   *dentry,
641         struct iattr    *iattr)
642 {
643         return -xfs_setattr(XFS_I(dentry->d_inode), iattr, 0, NULL);
644 }
645
646 /*
647  * block_truncate_page can return an error, but we can't propagate it
648  * at all here. Leave a complaint + stack trace in the syslog because
649  * this could be bad. If it is bad, we need to propagate the error further.
650  */
651 STATIC void
652 xfs_vn_truncate(
653         struct inode    *inode)
654 {
655         int     error;
656         error = block_truncate_page(inode->i_mapping, inode->i_size,
657                                                         xfs_get_blocks);
658         WARN_ON(error);
659 }
660
661 STATIC long
662 xfs_vn_fallocate(
663         struct inode    *inode,
664         int             mode,
665         loff_t          offset,
666         loff_t          len)
667 {
668         long            error;
669         loff_t          new_size = 0;
670         xfs_flock64_t   bf;
671         xfs_inode_t     *ip = XFS_I(inode);
672
673         /* preallocation on directories not yet supported */
674         error = -ENODEV;
675         if (S_ISDIR(inode->i_mode))
676                 goto out_error;
677
678         bf.l_whence = 0;
679         bf.l_start = offset;
680         bf.l_len = len;
681
682         xfs_ilock(ip, XFS_IOLOCK_EXCL);
683         error = xfs_change_file_space(ip, XFS_IOC_RESVSP, &bf,
684                                       0, NULL, XFS_ATTR_NOLOCK);
685         if (!error && !(mode & FALLOC_FL_KEEP_SIZE) &&
686             offset + len > i_size_read(inode))
687                 new_size = offset + len;
688
689         /* Change file size if needed */
690         if (new_size) {
691                 struct iattr iattr;
692
693                 iattr.ia_valid = ATTR_SIZE;
694                 iattr.ia_size = new_size;
695                 error = xfs_setattr(ip, &iattr, XFS_ATTR_NOLOCK, NULL);
696         }
697
698         xfs_iunlock(ip, XFS_IOLOCK_EXCL);
699 out_error:
700         return error;
701 }
702
703 static const struct inode_operations xfs_inode_operations = {
704         .permission             = xfs_vn_permission,
705         .truncate               = xfs_vn_truncate,
706         .getattr                = xfs_vn_getattr,
707         .setattr                = xfs_vn_setattr,
708         .setxattr               = generic_setxattr,
709         .getxattr               = generic_getxattr,
710         .removexattr            = generic_removexattr,
711         .listxattr              = xfs_vn_listxattr,
712         .fallocate              = xfs_vn_fallocate,
713 };
714
715 static const struct inode_operations xfs_dir_inode_operations = {
716         .create                 = xfs_vn_create,
717         .lookup                 = xfs_vn_lookup,
718         .link                   = xfs_vn_link,
719         .unlink                 = xfs_vn_unlink,
720         .symlink                = xfs_vn_symlink,
721         .mkdir                  = xfs_vn_mkdir,
722         /*
723          * Yes, XFS uses the same method for rmdir and unlink.
724          *
725          * There are some subtile differences deeper in the code,
726          * but we use S_ISDIR to check for those.
727          */
728         .rmdir                  = xfs_vn_unlink,
729         .mknod                  = xfs_vn_mknod,
730         .rename                 = xfs_vn_rename,
731         .permission             = xfs_vn_permission,
732         .getattr                = xfs_vn_getattr,
733         .setattr                = xfs_vn_setattr,
734         .setxattr               = generic_setxattr,
735         .getxattr               = generic_getxattr,
736         .removexattr            = generic_removexattr,
737         .listxattr              = xfs_vn_listxattr,
738 };
739
740 static const struct inode_operations xfs_dir_ci_inode_operations = {
741         .create                 = xfs_vn_create,
742         .lookup                 = xfs_vn_ci_lookup,
743         .link                   = xfs_vn_link,
744         .unlink                 = xfs_vn_unlink,
745         .symlink                = xfs_vn_symlink,
746         .mkdir                  = xfs_vn_mkdir,
747         /*
748          * Yes, XFS uses the same method for rmdir and unlink.
749          *
750          * There are some subtile differences deeper in the code,
751          * but we use S_ISDIR to check for those.
752          */
753         .rmdir                  = xfs_vn_unlink,
754         .mknod                  = xfs_vn_mknod,
755         .rename                 = xfs_vn_rename,
756         .permission             = xfs_vn_permission,
757         .getattr                = xfs_vn_getattr,
758         .setattr                = xfs_vn_setattr,
759         .setxattr               = generic_setxattr,
760         .getxattr               = generic_getxattr,
761         .removexattr            = generic_removexattr,
762         .listxattr              = xfs_vn_listxattr,
763 };
764
765 static const struct inode_operations xfs_symlink_inode_operations = {
766         .readlink               = generic_readlink,
767         .follow_link            = xfs_vn_follow_link,
768         .put_link               = xfs_vn_put_link,
769         .permission             = xfs_vn_permission,
770         .getattr                = xfs_vn_getattr,
771         .setattr                = xfs_vn_setattr,
772         .setxattr               = generic_setxattr,
773         .getxattr               = generic_getxattr,
774         .removexattr            = generic_removexattr,
775         .listxattr              = xfs_vn_listxattr,
776 };
777
778 STATIC void
779 xfs_diflags_to_iflags(
780         struct inode            *inode,
781         struct xfs_inode        *ip)
782 {
783         if (ip->i_d.di_flags & XFS_DIFLAG_IMMUTABLE)
784                 inode->i_flags |= S_IMMUTABLE;
785         else
786                 inode->i_flags &= ~S_IMMUTABLE;
787         if (ip->i_d.di_flags & XFS_DIFLAG_APPEND)
788                 inode->i_flags |= S_APPEND;
789         else
790                 inode->i_flags &= ~S_APPEND;
791         if (ip->i_d.di_flags & XFS_DIFLAG_SYNC)
792                 inode->i_flags |= S_SYNC;
793         else
794                 inode->i_flags &= ~S_SYNC;
795         if (ip->i_d.di_flags & XFS_DIFLAG_NOATIME)
796                 inode->i_flags |= S_NOATIME;
797         else
798                 inode->i_flags &= ~S_NOATIME;
799 }
800
801 /*
802  * Initialize the Linux inode, set up the operation vectors and
803  * unlock the inode.
804  *
805  * When reading existing inodes from disk this is called directly
806  * from xfs_iget, when creating a new inode it is called from
807  * xfs_ialloc after setting up the inode.
808  */
809 void
810 xfs_setup_inode(
811         struct xfs_inode        *ip)
812 {
813         struct inode            *inode = ip->i_vnode;
814
815         inode->i_mode   = ip->i_d.di_mode;
816         inode->i_nlink  = ip->i_d.di_nlink;
817         inode->i_uid    = ip->i_d.di_uid;
818         inode->i_gid    = ip->i_d.di_gid;
819
820         switch (inode->i_mode & S_IFMT) {
821         case S_IFBLK:
822         case S_IFCHR:
823                 inode->i_rdev =
824                         MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
825                               sysv_minor(ip->i_df.if_u2.if_rdev));
826                 break;
827         default:
828                 inode->i_rdev = 0;
829                 break;
830         }
831
832         inode->i_generation = ip->i_d.di_gen;
833         i_size_write(inode, ip->i_d.di_size);
834         inode->i_atime.tv_sec   = ip->i_d.di_atime.t_sec;
835         inode->i_atime.tv_nsec  = ip->i_d.di_atime.t_nsec;
836         inode->i_mtime.tv_sec   = ip->i_d.di_mtime.t_sec;
837         inode->i_mtime.tv_nsec  = ip->i_d.di_mtime.t_nsec;
838         inode->i_ctime.tv_sec   = ip->i_d.di_ctime.t_sec;
839         inode->i_ctime.tv_nsec  = ip->i_d.di_ctime.t_nsec;
840         xfs_diflags_to_iflags(inode, ip);
841         xfs_iflags_clear(ip, XFS_IMODIFIED);
842
843         switch (inode->i_mode & S_IFMT) {
844         case S_IFREG:
845                 inode->i_op = &xfs_inode_operations;
846                 inode->i_fop = &xfs_file_operations;
847                 inode->i_mapping->a_ops = &xfs_address_space_operations;
848                 break;
849         case S_IFDIR:
850                 if (xfs_sb_version_hasasciici(&XFS_M(inode->i_sb)->m_sb))
851                         inode->i_op = &xfs_dir_ci_inode_operations;
852                 else
853                         inode->i_op = &xfs_dir_inode_operations;
854                 inode->i_fop = &xfs_dir_file_operations;
855                 break;
856         case S_IFLNK:
857                 inode->i_op = &xfs_symlink_inode_operations;
858                 if (!(ip->i_df.if_flags & XFS_IFINLINE))
859                         inode->i_mapping->a_ops = &xfs_address_space_operations;
860                 break;
861         default:
862                 inode->i_op = &xfs_inode_operations;
863                 init_special_inode(inode, inode->i_mode, inode->i_rdev);
864                 break;
865         }
866
867         xfs_iflags_clear(ip, XFS_INEW);
868         barrier();
869
870         unlock_new_inode(inode);
871 }