[XFS] Fix a project quota space accounting leak on rename.
[safe/jmp/linux-2.6] / fs / xfs / xfs_vnodeops.c
index 688fc2c..7027ae6 100644 (file)
@@ -15,6 +15,9 @@
  * along with this program; if not, write the Free Software Foundation,
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
+
+#include <linux/capability.h>
+
 #include "xfs.h"
 #include "xfs_fs.h"
 #include "xfs_types.h"
@@ -182,8 +185,7 @@ xfs_getattr(
                break;
        }
 
-       /* atime is only kept uptodate in the Linux inode */
-       vap->va_atime = vp->v_inode.i_atime;
+       vn_atime_to_timespec(vp, &vap->va_atime);
        vap->va_mtime.tv_sec = ip->i_d.di_mtime.t_sec;
        vap->va_mtime.tv_nsec = ip->i_d.di_mtime.t_nsec;
        vap->va_ctime.tv_sec = ip->i_d.di_ctime.t_sec;
@@ -336,7 +338,7 @@ xfs_setattr(
                code = XFS_QM_DQVOPALLOC(mp, ip, uid, gid, projid, qflags,
                                         &udqp, &gdqp);
                if (code)
-                       return (code);
+                       return code;
        }
 
        /*
@@ -613,6 +615,7 @@ xfs_setattr(
                        code = xfs_igrow_start(ip, vap->va_size, credp);
                }
                xfs_iunlock(ip, XFS_ILOCK_EXCL);
+               vn_iowait(vp); /* wait for the completion of any pending DIOs */
                if (!code)
                        code = xfs_itruncate_data(ip, vap->va_size);
                if (code) {
@@ -845,7 +848,7 @@ xfs_setattr(
         * If this is a synchronous mount, make sure that the
         * transaction goes to disk before returning to the user.
         * This is slightly sub-optimal in that truncates require
-        * two sync transactions instead of one for wsync filesytems.
+        * two sync transactions instead of one for wsync filesystems.
         * One for the truncate and one for the timestamps since we
         * don't want to change the timestamps unless we're sure the
         * truncate worked.  Truncates are less than 1% of the laddis
@@ -1025,11 +1028,8 @@ xfs_readlink(
 
        }
 
-
 error_return:
-
        xfs_iunlock(ip, XFS_ILOCK_SHARED);
-
        return error;
 }
 
@@ -1170,7 +1170,7 @@ xfs_fsync(
 
                /*
                 * If this inode is on the RT dev we need to flush that
-                * cache aswell.
+                * cache as well.
                 */
                if (ip->i_d.di_flags & XFS_DIFLAG_REALTIME)
                        xfs_blkdev_issue_flush(ip->i_mount->m_rtdev_targp);
@@ -1204,7 +1204,7 @@ xfs_inactive_free_eofblocks(
        last_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_MAXIOFFSET(mp));
        map_len = last_fsb - end_fsb;
        if (map_len <= 0)
-               return (0);
+               return 0;
 
        nimaps = 1;
        xfs_ilock(ip, XFS_ILOCK_SHARED);
@@ -1213,12 +1213,13 @@ xfs_inactive_free_eofblocks(
        xfs_iunlock(ip, XFS_ILOCK_SHARED);
 
        if (!error && (nimaps != 0) &&
-           (imap.br_startblock != HOLESTARTBLOCK)) {
+           (imap.br_startblock != HOLESTARTBLOCK ||
+            ip->i_delayed_blks)) {
                /*
                 * Attach the dquots to the inode up front.
                 */
                if ((error = XFS_QM_DQATTACH(mp, ip, 0)))
-                       return (error);
+                       return error;
 
                /*
                 * There are blocks after the end of file.
@@ -1246,7 +1247,7 @@ xfs_inactive_free_eofblocks(
                        ASSERT(XFS_FORCED_SHUTDOWN(mp));
                        xfs_trans_cancel(tp, 0);
                        xfs_iunlock(ip, XFS_IOLOCK_EXCL);
-                       return (error);
+                       return error;
                }
 
                xfs_ilock(ip, XFS_ILOCK_EXCL);
@@ -1274,7 +1275,7 @@ xfs_inactive_free_eofblocks(
                }
                xfs_iunlock(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
        }
-       return (error);
+       return error;
 }
 
 /*
@@ -1334,7 +1335,7 @@ xfs_inactive_symlink_rmt(
         */
        done = 0;
        XFS_BMAP_INIT(&free_list, &first_block);
-       nmaps = sizeof(mval) / sizeof(mval[0]);
+       nmaps = ARRAY_SIZE(mval);
        if ((error = xfs_bmapi(tp, ip, 0, XFS_B_TO_FSB(mp, size),
                        XFS_BMAPI_METADATA, &first_block, 0, mval, &nmaps,
                        &free_list)))
@@ -1379,7 +1380,7 @@ xfs_inactive_symlink_rmt(
         */
        ntp = xfs_trans_dup(tp);
        /*
-        * Commit the transaction containing extent freeing and EFD's.
+        * Commit the transaction containing extent freeing and EFDs.
         * If we get an error on the commit here or on the reserve below,
         * we need to unlock the inode since the new transaction doesn't
         * have the inode attached.
@@ -1452,7 +1453,7 @@ xfs_inactive_symlink_local(
        if (error) {
                xfs_trans_cancel(*tpp, 0);
                *tpp = NULL;
-               return (error);
+               return error;
        }
        xfs_ilock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
 
@@ -1465,7 +1466,7 @@ xfs_inactive_symlink_local(
                                  XFS_DATA_FORK);
                ASSERT(ip->i_df.if_bytes == 0);
        }
-       return (0);
+       return 0;
 }
 
 /*
@@ -1491,7 +1492,7 @@ xfs_inactive_attrs(
        if (error) {
                *tpp = NULL;
                xfs_iunlock(ip, XFS_IOLOCK_EXCL);
-               return (error); /* goto out*/
+               return error; /* goto out */
        }
 
        tp = xfs_trans_alloc(mp, XFS_TRANS_INACTIVE);
@@ -1504,7 +1505,7 @@ xfs_inactive_attrs(
                xfs_trans_cancel(tp, 0);
                *tpp = NULL;
                xfs_iunlock(ip, XFS_IOLOCK_EXCL);
-               return (error);
+               return error;
        }
 
        xfs_ilock(ip, XFS_ILOCK_EXCL);
@@ -1515,7 +1516,7 @@ xfs_inactive_attrs(
        ASSERT(ip->i_d.di_anextents == 0);
 
        *tpp = tp;
-       return (0);
+       return 0;
 }
 
 STATIC int
@@ -1548,14 +1549,15 @@ xfs_release(
 
        if (ip->i_d.di_nlink != 0) {
                if ((((ip->i_d.di_mode & S_IFMT) == S_IFREG) &&
-                    ((ip->i_d.di_size > 0) || (VN_CACHED(vp) > 0)) &&
+                    ((ip->i_d.di_size > 0) || (VN_CACHED(vp) > 0 ||
+                      ip->i_delayed_blks > 0)) &&
                     (ip->i_df.if_flags & XFS_IFEXTENTS))  &&
                    (!(ip->i_d.di_flags &
                                (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)))) {
                        if ((error = xfs_inactive_free_eofblocks(mp, ip)))
-                               return (error);
+                               return error;
                        /* Update linux inode block count after free above */
-                       LINVFS_GET_IP(vp)->i_blocks = XFS_FSB_TO_BB(mp,
+                       vn_to_inode(vp)->i_blocks = XFS_FSB_TO_BB(mp,
                                ip->i_d.di_nblocks + ip->i_delayed_blks);
                }
        }
@@ -1627,15 +1629,16 @@ xfs_inactive(
 
        if (ip->i_d.di_nlink != 0) {
                if ((((ip->i_d.di_mode & S_IFMT) == S_IFREG) &&
-                    ((ip->i_d.di_size > 0) || (VN_CACHED(vp) > 0)) &&
+                     ((ip->i_d.di_size > 0) || (VN_CACHED(vp) > 0 ||
+                       ip->i_delayed_blks > 0)) &&
                      (ip->i_df.if_flags & XFS_IFEXTENTS) &&
                     (!(ip->i_d.di_flags &
                                (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) ||
                      (ip->i_delayed_blks != 0)))) {
                        if ((error = xfs_inactive_free_eofblocks(mp, ip)))
-                               return (VN_INACTIVE_CACHE);
+                               return VN_INACTIVE_CACHE;
                        /* Update linux inode block count after free above */
-                       LINVFS_GET_IP(vp)->i_blocks = XFS_FSB_TO_BB(mp,
+                       vn_to_inode(vp)->i_blocks = XFS_FSB_TO_BB(mp,
                                ip->i_d.di_nblocks + ip->i_delayed_blks);
                }
                goto out;
@@ -1644,7 +1647,7 @@ xfs_inactive(
        ASSERT(ip->i_d.di_nlink == 0);
 
        if ((error = XFS_QM_DQATTACH(mp, ip, 0)))
-               return (VN_INACTIVE_CACHE);
+               return VN_INACTIVE_CACHE;
 
        tp = xfs_trans_alloc(mp, XFS_TRANS_INACTIVE);
        if (truncate) {
@@ -1667,7 +1670,7 @@ xfs_inactive(
                        ASSERT(XFS_FORCED_SHUTDOWN(mp));
                        xfs_trans_cancel(tp, 0);
                        xfs_iunlock(ip, XFS_IOLOCK_EXCL);
-                       return (VN_INACTIVE_CACHE);
+                       return VN_INACTIVE_CACHE;
                }
 
                xfs_ilock(ip, XFS_ILOCK_EXCL);
@@ -1688,7 +1691,7 @@ xfs_inactive(
                        xfs_trans_cancel(tp,
                                XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT);
                        xfs_iunlock(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
-                       return (VN_INACTIVE_CACHE);
+                       return VN_INACTIVE_CACHE;
                }
        } else if ((ip->i_d.di_mode & S_IFMT) == S_IFLNK) {
 
@@ -1702,7 +1705,7 @@ xfs_inactive(
 
                if (error) {
                        ASSERT(tp == NULL);
-                       return (VN_INACTIVE_CACHE);
+                       return VN_INACTIVE_CACHE;
                }
 
                xfs_trans_ijoin(tp, ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
@@ -1715,7 +1718,7 @@ xfs_inactive(
                if (error) {
                        ASSERT(XFS_FORCED_SHUTDOWN(mp));
                        xfs_trans_cancel(tp, 0);
-                       return (VN_INACTIVE_CACHE);
+                       return VN_INACTIVE_CACHE;
                }
 
                xfs_ilock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
@@ -1737,7 +1740,7 @@ xfs_inactive(
                 * cancelled, and the inode is unlocked. Just get out.
                 */
                 if (error)
-                        return (VN_INACTIVE_CACHE);
+                        return VN_INACTIVE_CACHE;
        } else if (ip->i_afp) {
                xfs_idestroy_fork(ip, XFS_ATTR_FORK);
        }
@@ -2020,7 +2023,7 @@ xfs_create(
        XFS_QM_DQRELE(mp, gdqp);
 
        /*
-        * Propogate the fact that the vnode changed after the
+        * Propagate the fact that the vnode changed after the
         * xfs_inode locks have been released.
         */
        VOP_VNODE_CHANGE(vp, VCHANGE_FLAGS_TRUNCATED, 3);
@@ -2044,8 +2047,8 @@ std_return:
  abort_return:
        cancel_flags |= XFS_TRANS_ABORT;
        /* FALLTHROUGH */
- error_return:
 
+ error_return:
        if (tp != NULL)
                xfs_trans_cancel(tp, cancel_flags);
 
@@ -2367,7 +2370,7 @@ xfs_remove(
         * for a log reservation. Since we'll have to wait for the
         * inactive code to complete before returning from xfs_iget,
         * we need to make sure that we don't have log space reserved
-        * when we call xfs_iget.  Instead we get an unlocked referece
+        * when we call xfs_iget.  Instead we get an unlocked reference
         * to the inode before getting our log reservation.
         */
        error = xfs_get_dir_entry(dentry, &ip);
@@ -2575,7 +2578,6 @@ xfs_link(
        int                     cancel_flags;
        int                     committed;
        vnode_t                 *target_dir_vp;
-       bhv_desc_t              *src_bdp;
        int                     resblks;
        char                    *target_name = VNAME(dentry);
        int                     target_namelen;
@@ -2588,8 +2590,7 @@ xfs_link(
        if (VN_ISDIR(src_vp))
                return XFS_ERROR(EPERM);
 
-       src_bdp = vn_bhv_lookup_unlocked(VN_BHV_HEAD(src_vp), &xfs_vnodeops);
-       sip = XFS_BHVTOI(src_bdp);
+       sip = xfs_vtoi(src_vp);
        tdp = XFS_BHVTOI(target_dir_bdp);
        mp = tdp->i_mount;
        if (XFS_FORCED_SHUTDOWN(mp))
@@ -2662,7 +2663,7 @@ xfs_link(
         */
        if (unlikely((tdp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT) &&
                     (tdp->i_d.di_projid != sip->i_d.di_projid))) {
-               error = XFS_ERROR(EPERM);
+               error = XFS_ERROR(EXDEV);
                goto error_return;
        }
 
@@ -2721,9 +2722,9 @@ std_return:
  abort_return:
        cancel_flags |= XFS_TRANS_ABORT;
        /* FALLTHROUGH */
+
  error_return:
        xfs_trans_cancel(tp, cancel_flags);
-
        goto std_return;
 }
 /*
@@ -3019,7 +3020,7 @@ xfs_rmdir(
         * for a log reservation.  Since we'll have to wait for the
         * inactive code to complete before returning from xfs_iget,
         * we need to make sure that we don't have log space reserved
-        * when we call xfs_iget.  Instead we get an unlocked referece
+        * when we call xfs_iget.  Instead we get an unlocked reference
         * to the inode before getting our log reservation.
         */
        error = xfs_get_dir_entry(dentry, &cdp);
@@ -3186,7 +3187,7 @@ xfs_rmdir(
 
        /* Fall through to std_return with error = 0 or the errno
         * from xfs_trans_commit. */
-std_return:
+ std_return:
        if (DM_EVENT_ENABLED(dir_vp->v_vfsp, dp, DM_EVENT_POSTREMOVE)) {
                (void) XFS_SEND_NAMESP(mp, DM_EVENT_POSTREMOVE,
                                        dir_vp, DM_RIGHT_NULL,
@@ -3199,6 +3200,8 @@ std_return:
  error1:
        xfs_bmap_cancel(&free_list);
        cancel_flags |= XFS_TRANS_ABORT;
+       /* FALLTHROUGH */
+
  error_return:
        xfs_trans_cancel(tp, cancel_flags);
        goto std_return;
@@ -3615,9 +3618,9 @@ xfs_rwlock(
        if (locktype == VRWLOCK_WRITE) {
                xfs_ilock(ip, XFS_IOLOCK_EXCL);
        } else if (locktype == VRWLOCK_TRY_READ) {
-               return (xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED));
+               return xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED);
        } else if (locktype == VRWLOCK_TRY_WRITE) {
-               return (xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL));
+               return xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL);
        } else {
                ASSERT((locktype == VRWLOCK_READ) ||
                       (locktype == VRWLOCK_WRITE_DIRECT));
@@ -3865,7 +3868,7 @@ xfs_finish_reclaim(
                        xfs_ifunlock(ip);
                        xfs_iunlock(ip, XFS_ILOCK_EXCL);
                }
-               return(1);
+               return 1;
        }
        ip->i_flags |= XFS_IRECLAIM;
        write_unlock(&ih->ih_lock);
@@ -4042,7 +4045,7 @@ xfs_alloc_file_space(
                        offset, end_dmi_offset - offset,
                        0, NULL);
                if (error)
-                       return(error);
+                       return error;
        }
 
        /*
@@ -4302,14 +4305,16 @@ xfs_free_file_space(
                                offset, end_dmi_offset - offset,
                                AT_DELAY_FLAG(attr_flags), NULL);
                if (error)
-                       return(error);
+                       return error;
        }
 
        ASSERT(attr_flags & ATTR_NOLOCK ? attr_flags & ATTR_DMI : 1);
        if (attr_flags & ATTR_NOLOCK)
                need_iolock = 0;
-       if (need_iolock)
+       if (need_iolock) {
                xfs_ilock(ip, XFS_IOLOCK_EXCL);
+               vn_iowait(vp);  /* wait for the completion of any pending DIOs */
+       }
 
        rounding = MAX((__uint8_t)(1 << mp->m_sb.sb_blocklog),
                        (__uint8_t)NBPP);
@@ -4644,6 +4649,10 @@ vnodeops_t xfs_vnodeops = {
 #ifdef HAVE_SENDFILE
        .vop_sendfile           = xfs_sendfile,
 #endif
+#ifdef HAVE_SPLICE
+       .vop_splice_read        = xfs_splice_read,
+       .vop_splice_write       = xfs_splice_write,
+#endif
        .vop_write              = xfs_write,
        .vop_ioctl              = xfs_ioctl,
        .vop_getattr            = xfs_getattr,