]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/xfs/linux-2.6/xfs_iops.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/sparc-2.6
[linux-2.6-omap-h63xx.git] / fs / xfs / linux-2.6 / xfs_iops.c
index 9c4d99709705e6ee4a817db69c6289b7b829fece..cc4abd3daa49b62aa8a6a822015e33c69e099ea9 100644 (file)
@@ -52,6 +52,7 @@
 #include <linux/xattr.h>
 #include <linux/namei.h>
 #include <linux/security.h>
+#include <linux/falloc.h>
 
 /*
  * Bring the atime in the XFS inode uptodate.
@@ -70,6 +71,22 @@ xfs_synchronize_atime(
        }
 }
 
+/*
+ * If the linux inode exists, mark it dirty.
+ * Used when commiting a dirty inode into a transaction so that
+ * the inode will get written back by the linux code
+ */
+void
+xfs_mark_inode_dirty_sync(
+       xfs_inode_t     *ip)
+{
+       bhv_vnode_t     *vp;
+
+       vp = XFS_ITOV_NULL(ip);
+       if (vp)
+               mark_inode_dirty_sync(vn_to_inode(vp));
+}
+
 /*
  * Change the requested timestamp in the given inode.
  * We don't lock across timestamp updates, and we don't log them but
@@ -117,7 +134,7 @@ xfs_ichgtime(
         */
        SYNCHRONIZE();
        ip->i_update_core = 1;
-       if (!(inode->i_state & I_LOCK))
+       if (!(inode->i_state & I_NEW))
                mark_inode_dirty_sync(inode);
 }
 
@@ -169,7 +186,7 @@ xfs_ichgtime_fast(
         */
        SYNCHRONIZE();
        ip->i_update_core = 1;
-       if (!(inode->i_state & I_LOCK))
+       if (!(inode->i_state & I_NEW))
                mark_inode_dirty_sync(inode);
 }
 
@@ -179,18 +196,15 @@ xfs_ichgtime_fast(
  */
 STATIC void
 xfs_validate_fields(
-       struct inode    *ip,
-       bhv_vattr_t     *vattr)
+       struct inode            *inode)
 {
-       vattr->va_mask = XFS_AT_NLINK|XFS_AT_SIZE|XFS_AT_NBLOCKS;
-       if (!xfs_getattr(XFS_I(ip), vattr, ATTR_LAZY)) {
-               ip->i_nlink = vattr->va_nlink;
-               ip->i_blocks = vattr->va_nblocks;
-
-               /* we're under i_sem so i_size can't change under us */
-               if (i_size_read(ip) != vattr->va_size)
-                       i_size_write(ip, vattr->va_size);
-       }
+       struct xfs_inode        *ip = XFS_I(inode);
+       loff_t size;
+
+       /* we're under i_sem so i_size can't change under us */
+       size = XFS_ISIZE(ip);
+       if (i_size_read(inode) != size)
+               i_size_write(inode, size);
 }
 
 /*
@@ -331,12 +345,10 @@ xfs_vn_mknod(
                ASSERT(vp);
                ip = vn_to_inode(vp);
 
-               if (S_ISCHR(mode) || S_ISBLK(mode))
-                       ip->i_rdev = rdev;
-               else if (S_ISDIR(mode))
-                       xfs_validate_fields(ip, &vattr);
+               if (S_ISDIR(mode))
+                       xfs_validate_fields(ip);
                d_instantiate(dentry, ip);
-               xfs_validate_fields(dir, &vattr);
+               xfs_validate_fields(dir);
        }
        return -error;
 }
@@ -391,7 +403,6 @@ xfs_vn_link(
 {
        struct inode    *ip;    /* inode of guy being linked to */
        bhv_vnode_t     *vp;    /* vp of name being linked */
-       bhv_vattr_t     vattr;
        int             error;
 
        ip = old_dentry->d_inode;       /* inode being linked to */
@@ -403,7 +414,7 @@ xfs_vn_link(
                VN_RELE(vp);
        } else {
                xfs_iflags_set(XFS_I(dir), XFS_IMODIFIED);
-               xfs_validate_fields(ip, &vattr);
+               xfs_validate_fields(ip);
                d_instantiate(dentry, ip);
        }
        return -error;
@@ -415,15 +426,14 @@ xfs_vn_unlink(
        struct dentry   *dentry)
 {
        struct inode    *inode;
-       bhv_vattr_t     vattr;
        int             error;
 
        inode = dentry->d_inode;
 
        error = xfs_remove(XFS_I(dir), dentry);
        if (likely(!error)) {
-               xfs_validate_fields(dir, &vattr);       /* size needs update */
-               xfs_validate_fields(inode, &vattr);
+               xfs_validate_fields(dir);       /* size needs update */
+               xfs_validate_fields(inode);
        }
        return -error;
 }
@@ -451,8 +461,8 @@ xfs_vn_symlink(
                if (likely(!error)) {
                        ip = vn_to_inode(cvp);
                        d_instantiate(dentry, ip);
-                       xfs_validate_fields(dir, &va);
-                       xfs_validate_fields(ip, &va);
+                       xfs_validate_fields(dir);
+                       xfs_validate_fields(ip);
                } else {
                        xfs_cleanup_inode(dir, cvp, dentry, 0);
                }
@@ -466,13 +476,12 @@ xfs_vn_rmdir(
        struct dentry   *dentry)
 {
        struct inode    *inode = dentry->d_inode;
-       bhv_vattr_t     vattr;
        int             error;
 
        error = xfs_rmdir(XFS_I(dir), dentry);
        if (likely(!error)) {
-               xfs_validate_fields(inode, &vattr);
-               xfs_validate_fields(dir, &vattr);
+               xfs_validate_fields(inode);
+               xfs_validate_fields(dir);
        }
        return -error;
 }
@@ -486,7 +495,6 @@ xfs_vn_rename(
 {
        struct inode    *new_inode = ndentry->d_inode;
        bhv_vnode_t     *tvp;   /* target directory */
-       bhv_vattr_t     vattr;
        int             error;
 
        tvp = vn_from_inode(ndir);
@@ -494,10 +502,10 @@ xfs_vn_rename(
        error = xfs_rename(XFS_I(odir), odentry, tvp, ndentry);
        if (likely(!error)) {
                if (new_inode)
-                       xfs_validate_fields(new_inode, &vattr);
-               xfs_validate_fields(odir, &vattr);
+                       xfs_validate_fields(new_inode);
+               xfs_validate_fields(odir);
                if (ndir != odir)
-                       xfs_validate_fields(ndir, &vattr);
+                       xfs_validate_fields(ndir);
        }
        return -error;
 }
@@ -546,13 +554,32 @@ xfs_vn_put_link(
 }
 
 #ifdef CONFIG_XFS_POSIX_ACL
+STATIC int
+xfs_check_acl(
+       struct inode            *inode,
+       int                     mask)
+{
+       struct xfs_inode        *ip = XFS_I(inode);
+       int                     error;
+
+       xfs_itrace_entry(ip);
+
+       if (XFS_IFORK_Q(ip)) {
+               error = xfs_acl_iaccess(ip, mask, NULL);
+               if (error != -1)
+                       return -error;
+       }
+
+       return -EAGAIN;
+}
+
 STATIC int
 xfs_vn_permission(
-       struct inode    *inode,
-       int             mode,
-       struct nameidata *nd)
+       struct inode            *inode,
+       int                     mask,
+       struct nameidata        *nd)
 {
-       return -xfs_access(XFS_I(inode), mode << 6, NULL);
+       return generic_permission(inode, mask, xfs_check_acl);
 }
 #else
 #define xfs_vn_permission NULL
@@ -560,33 +587,61 @@ xfs_vn_permission(
 
 STATIC int
 xfs_vn_getattr(
-       struct vfsmount *mnt,
-       struct dentry   *dentry,
-       struct kstat    *stat)
+       struct vfsmount         *mnt,
+       struct dentry           *dentry,
+       struct kstat            *stat)
 {
-       struct inode    *inode = dentry->d_inode;
-       bhv_vattr_t     vattr = { .va_mask = XFS_AT_STAT };
-       int             error;
-
-       error = xfs_getattr(XFS_I(inode), &vattr, ATTR_LAZY);
-       if (likely(!error)) {
-               stat->size = i_size_read(inode);
-               stat->dev = inode->i_sb->s_dev;
-               stat->rdev = (vattr.va_rdev == 0) ? 0 :
-                               MKDEV(sysv_major(vattr.va_rdev) & 0x1ff,
-                                     sysv_minor(vattr.va_rdev));
-               stat->mode = vattr.va_mode;
-               stat->nlink = vattr.va_nlink;
-               stat->uid = vattr.va_uid;
-               stat->gid = vattr.va_gid;
-               stat->ino = vattr.va_nodeid;
-               stat->atime = vattr.va_atime;
-               stat->mtime = vattr.va_mtime;
-               stat->ctime = vattr.va_ctime;
-               stat->blocks = vattr.va_nblocks;
-               stat->blksize = vattr.va_blocksize;
+       struct inode            *inode = dentry->d_inode;
+       struct xfs_inode        *ip = XFS_I(inode);
+       struct xfs_mount        *mp = ip->i_mount;
+
+       xfs_itrace_entry(ip);
+
+       if (XFS_FORCED_SHUTDOWN(mp))
+               return XFS_ERROR(EIO);
+
+       stat->size = XFS_ISIZE(ip);
+       stat->dev = inode->i_sb->s_dev;
+       stat->mode = ip->i_d.di_mode;
+       stat->nlink = ip->i_d.di_nlink;
+       stat->uid = ip->i_d.di_uid;
+       stat->gid = ip->i_d.di_gid;
+       stat->ino = ip->i_ino;
+#if XFS_BIG_INUMS
+       stat->ino += mp->m_inoadd;
+#endif
+       stat->atime = inode->i_atime;
+       stat->mtime.tv_sec = ip->i_d.di_mtime.t_sec;
+       stat->mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
+       stat->ctime.tv_sec = ip->i_d.di_ctime.t_sec;
+       stat->ctime.tv_nsec = ip->i_d.di_ctime.t_nsec;
+       stat->blocks =
+               XFS_FSB_TO_BB(mp, ip->i_d.di_nblocks + ip->i_delayed_blks);
+
+
+       switch (inode->i_mode & S_IFMT) {
+       case S_IFBLK:
+       case S_IFCHR:
+               stat->blksize = BLKDEV_IOSIZE;
+               stat->rdev = MKDEV(sysv_major(ip->i_df.if_u2.if_rdev) & 0x1ff,
+                                  sysv_minor(ip->i_df.if_u2.if_rdev));
+               break;
+       default:
+               if (XFS_IS_REALTIME_INODE(ip)) {
+                       /*
+                        * If the file blocks are being allocated from a
+                        * realtime volume, then return the inode's realtime
+                        * extent size or the realtime volume's extent size.
+                        */
+                       stat->blksize =
+                               xfs_get_extsz_hint(ip) << mp->m_sb.sb_blocklog;
+               } else
+                       stat->blksize = xfs_preferred_iosize(mp);
+               stat->rdev = 0;
+               break;
        }
-       return -error;
+
+       return 0;
 }
 
 STATIC int
@@ -641,7 +696,7 @@ xfs_vn_setattr(
 
        error = xfs_setattr(XFS_I(inode), &vattr, flags, NULL);
        if (likely(!error))
-               __vn_revalidate(vn_from_inode(inode), &vattr);
+               vn_revalidate(vn_from_inode(inode));
        return -error;
 }
 
@@ -755,6 +810,47 @@ xfs_vn_removexattr(
        return namesp->attr_remove(vp, attr, xflags);
 }
 
+STATIC long
+xfs_vn_fallocate(
+       struct inode    *inode,
+       int             mode,
+       loff_t          offset,
+       loff_t          len)
+{
+       long            error;
+       loff_t          new_size = 0;
+       xfs_flock64_t   bf;
+       xfs_inode_t     *ip = XFS_I(inode);
+
+       /* preallocation on directories not yet supported */
+       error = -ENODEV;
+       if (S_ISDIR(inode->i_mode))
+               goto out_error;
+
+       bf.l_whence = 0;
+       bf.l_start = offset;
+       bf.l_len = len;
+
+       xfs_ilock(ip, XFS_IOLOCK_EXCL);
+       error = xfs_change_file_space(ip, XFS_IOC_RESVSP, &bf,
+                                               0, NULL, ATTR_NOLOCK);
+       if (!error && !(mode & FALLOC_FL_KEEP_SIZE) &&
+           offset + len > i_size_read(inode))
+               new_size = offset + len;
+
+       /* Change file size if needed */
+       if (new_size) {
+               bhv_vattr_t     va;
+
+               va.va_mask = XFS_AT_SIZE;
+               va.va_size = new_size;
+               error = xfs_setattr(ip, &va, ATTR_NOLOCK, NULL);
+       }
+
+       xfs_iunlock(ip, XFS_IOLOCK_EXCL);
+out_error:
+       return error;
+}
 
 const struct inode_operations xfs_inode_operations = {
        .permission             = xfs_vn_permission,
@@ -765,6 +861,7 @@ const struct inode_operations xfs_inode_operations = {
        .getxattr               = xfs_vn_getxattr,
        .listxattr              = xfs_vn_listxattr,
        .removexattr            = xfs_vn_removexattr,
+       .fallocate              = xfs_vn_fallocate,
 };
 
 const struct inode_operations xfs_dir_inode_operations = {