GFS2: Ensure uptodate inode size when using O_APPEND
[safe/jmp/linux-2.6] / fs / xfs / xfs_vnodeops.c
index 0e55c5d..6558ffd 100644 (file)
@@ -42,6 +42,7 @@
 #include "xfs_ialloc.h"
 #include "xfs_alloc.h"
 #include "xfs_bmap.h"
+#include "xfs_acl.h"
 #include "xfs_attr.h"
 #include "xfs_rw.h"
 #include "xfs_error.h"
@@ -52,6 +53,7 @@
 #include "xfs_log_priv.h"
 #include "xfs_filestream.h"
 #include "xfs_vnodeops.h"
+#include "xfs_trace.h"
 
 int
 xfs_setattr(
@@ -118,7 +120,7 @@ xfs_setattr(
                 */
                ASSERT(udqp == NULL);
                ASSERT(gdqp == NULL);
-               code = XFS_QM_DQVOPALLOC(mp, ip, uid, gid, ip->i_d.di_projid,
+               code = xfs_qm_vop_dqalloc(ip, uid, gid, ip->i_d.di_projid,
                                         qflags, &udqp, &gdqp);
                if (code)
                        return code;
@@ -180,10 +182,11 @@ xfs_setattr(
                 * Do a quota reservation only if uid/gid is actually
                 * going to change.
                 */
-               if ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
-                   (XFS_IS_GQUOTA_ON(mp) && igid != gid)) {
+               if (XFS_IS_QUOTA_RUNNING(mp) &&
+                   ((XFS_IS_UQUOTA_ON(mp) && iuid != uid) ||
+                    (XFS_IS_GQUOTA_ON(mp) && igid != gid))) {
                        ASSERT(tp);
-                       code = XFS_QM_DQVOPCHOWNRESV(mp, tp, ip, udqp, gdqp,
+                       code = xfs_qm_vop_chown_reserve(tp, ip, udqp, gdqp,
                                                capable(CAP_FOWNER) ?
                                                XFS_QMOPT_FORCE_RES : 0);
                        if (code)       /* out of quota */
@@ -217,7 +220,7 @@ xfs_setattr(
                /*
                 * Make sure that the dquots are attached to the inode.
                 */
-               code = XFS_QM_DQATTACH(mp, ip, XFS_QMOPT_ILOCKED);
+               code = xfs_qm_dqattach_locked(ip, 0);
                if (code)
                        goto error_return;
 
@@ -351,21 +354,21 @@ xfs_setattr(
                 * in the transaction.
                 */
                if (iuid != uid) {
-                       if (XFS_IS_UQUOTA_ON(mp)) {
+                       if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_UQUOTA_ON(mp)) {
                                ASSERT(mask & ATTR_UID);
                                ASSERT(udqp);
-                               olddquot1 = XFS_QM_DQVOPCHOWN(mp, tp, ip,
+                               olddquot1 = xfs_qm_vop_chown(tp, ip,
                                                        &ip->i_udquot, udqp);
                        }
                        ip->i_d.di_uid = uid;
                        inode->i_uid = uid;
                }
                if (igid != gid) {
-                       if (XFS_IS_GQUOTA_ON(mp)) {
+                       if (XFS_IS_QUOTA_RUNNING(mp) && XFS_IS_GQUOTA_ON(mp)) {
                                ASSERT(!XFS_IS_PQUOTA_ON(mp));
                                ASSERT(mask & ATTR_GID);
                                ASSERT(gdqp);
-                               olddquot2 = XFS_QM_DQVOPCHOWN(mp, tp, ip,
+                               olddquot2 = xfs_qm_vop_chown(tp, ip,
                                                        &ip->i_gdquot, gdqp);
                        }
                        ip->i_d.di_gid = gid;
@@ -461,13 +464,25 @@ xfs_setattr(
        /*
         * Release any dquot(s) the inode had kept before chown.
         */
-       XFS_QM_DQRELE(mp, olddquot1);
-       XFS_QM_DQRELE(mp, olddquot2);
-       XFS_QM_DQRELE(mp, udqp);
-       XFS_QM_DQRELE(mp, gdqp);
+       xfs_qm_dqrele(olddquot1);
+       xfs_qm_dqrele(olddquot2);
+       xfs_qm_dqrele(udqp);
+       xfs_qm_dqrele(gdqp);
 
-       if (code) {
+       if (code)
                return code;
+
+       /*
+        * XXX(hch): Updating the ACL entries is not atomic vs the i_mode
+        *           update.  We could avoid this with linked transactions
+        *           and passing down the transaction pointer all the way
+        *           to attr_set.  No previous user of the generic
+        *           Posix ACL code seems to care about this issue either.
+        */
+       if ((mask & ATTR_MODE) && !(flags & XFS_ATTR_NOACL)) {
+               code = -xfs_acl_chmod(inode);
+               if (code)
+                       return XFS_ERROR(code);
        }
 
        if (DM_EVENT_ENABLED(ip, DM_EVENT_ATTRIBUTE) &&
@@ -482,8 +497,8 @@ xfs_setattr(
        commit_flags |= XFS_TRANS_ABORT;
        /* FALLTHROUGH */
  error_return:
-       XFS_QM_DQRELE(mp, udqp);
-       XFS_QM_DQRELE(mp, gdqp);
+       xfs_qm_dqrele(udqp);
+       xfs_qm_dqrele(gdqp);
        if (tp) {
                xfs_trans_cancel(tp, commit_flags);
        }
@@ -524,7 +539,8 @@ xfs_readlink_bmap(
                d = XFS_FSB_TO_DADDR(mp, mval[n].br_startblock);
                byte_cnt = XFS_FSB_TO_B(mp, mval[n].br_blockcount);
 
-               bp = xfs_buf_read(mp->m_ddev_targp, d, BTOBB(byte_cnt), 0);
+               bp = xfs_buf_read(mp->m_ddev_targp, d, BTOBB(byte_cnt),
+                                 XBF_LOCK | XBF_MAPPED | XBF_DONT_BLOCK);
                error = XFS_BUF_GETERROR(bp);
                if (error) {
                        xfs_ioerror_alert("xfs_readlink",
@@ -595,7 +611,7 @@ xfs_fsync(
        xfs_inode_t     *ip)
 {
        xfs_trans_t     *tp;
-       int             error;
+       int             error = 0;
        int             log_flushed = 0, changed = 1;
 
        xfs_itrace_entry(ip);
@@ -603,14 +619,9 @@ xfs_fsync(
        if (XFS_FORCED_SHUTDOWN(ip->i_mount))
                return XFS_ERROR(EIO);
 
-       /* capture size updates in I/O completion before writing the inode. */
-       error = xfs_wait_on_pages(ip, 0, -1);
-       if (error)
-               return XFS_ERROR(error);
-
        /*
         * We always need to make sure that the required inode state is safe on
-        * disk.  The vnode might be clean but we still might need to force the
+        * disk.  The inode might be clean but we still might need to force the
         * log because of committed transactions that haven't hit the disk yet.
         * Likewise, there could be unflushed non-transactional changes to the
         * inode core that have to go to disk and this requires us to issue
@@ -622,7 +633,7 @@ xfs_fsync(
         */
        xfs_ilock(ip, XFS_ILOCK_SHARED);
 
-       if (!(ip->i_update_size || ip->i_update_core)) {
+       if (!ip->i_update_core) {
                /*
                 * Timestamps/size haven't changed since last inode flush or
                 * inode transaction commit.  That means either nothing got
@@ -698,11 +709,16 @@ xfs_fsync(
 }
 
 /*
+ * Flags for xfs_free_eofblocks
+ */
+#define XFS_FREE_EOF_TRYLOCK   (1<<0)
+
+/*
  * This is called by xfs_inactive to free any blocks beyond eof
  * when the link count isn't zero and by xfs_dm_punch_hole() when
  * punching a hole to EOF.
  */
-int
+STATIC int
 xfs_free_eofblocks(
        xfs_mount_t     *mp,
        xfs_inode_t     *ip,
@@ -715,7 +731,6 @@ xfs_free_eofblocks(
        xfs_filblks_t   map_len;
        int             nimaps;
        xfs_bmbt_irec_t imap;
-       int             use_iolock = (flags & XFS_FREE_EOF_LOCK);
 
        /*
         * Figure out if there are any blocks beyond the end
@@ -739,7 +754,8 @@ xfs_free_eofblocks(
                /*
                 * Attach the dquots to the inode up front.
                 */
-               if ((error = XFS_QM_DQATTACH(mp, ip, 0)))
+               error = xfs_qm_dqattach(ip, 0);
+               if (error)
                        return error;
 
                /*
@@ -756,14 +772,19 @@ xfs_free_eofblocks(
                 * cache and we can't
                 * do that within a transaction.
                 */
-               if (use_iolock)
+               if (flags & XFS_FREE_EOF_TRYLOCK) {
+                       if (!xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL)) {
+                               xfs_trans_cancel(tp, 0);
+                               return 0;
+                       }
+               } else {
                        xfs_ilock(ip, XFS_IOLOCK_EXCL);
+               }
                error = xfs_itruncate_start(ip, XFS_ITRUNC_DEFINITE,
                                    ip->i_size);
                if (error) {
                        xfs_trans_cancel(tp, 0);
-                       if (use_iolock)
-                               xfs_iunlock(ip, XFS_IOLOCK_EXCL);
+                       xfs_iunlock(ip, XFS_IOLOCK_EXCL);
                        return error;
                }
 
@@ -800,8 +821,7 @@ xfs_free_eofblocks(
                        error = xfs_trans_commit(tp,
                                                XFS_TRANS_RELEASE_LOG_RES);
                }
-               xfs_iunlock(ip, (use_iolock ? (XFS_IOLOCK_EXCL|XFS_ILOCK_EXCL)
-                                           : XFS_ILOCK_EXCL));
+               xfs_iunlock(ip, XFS_IOLOCK_EXCL|XFS_ILOCK_EXCL);
        }
        return error;
 }
@@ -1101,7 +1121,17 @@ xfs_release(
                     (ip->i_df.if_flags & XFS_IFEXTENTS))  &&
                    (!(ip->i_d.di_flags &
                                (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)))) {
-                       error = xfs_free_eofblocks(mp, ip, XFS_FREE_EOF_LOCK);
+
+                       /*
+                        * If we can't get the iolock just skip truncating
+                        * the blocks past EOF because we could deadlock
+                        * with the mmap_sem otherwise.  We'll get another
+                        * chance to drop them once the last reference to
+                        * the inode is dropped, so we'll never leak blocks
+                        * permanently.
+                        */
+                       error = xfs_free_eofblocks(mp, ip,
+                                                  XFS_FREE_EOF_TRYLOCK);
                        if (error)
                                return error;
                }
@@ -1136,7 +1166,7 @@ xfs_inactive(
         * If the inode is already free, then there can be nothing
         * to clean up here.
         */
-       if (ip->i_d.di_mode == 0 || VN_BAD(VFS_I(ip))) {
+       if (ip->i_d.di_mode == 0 || is_bad_inode(VFS_I(ip))) {
                ASSERT(ip->i_df.if_real_bytes == 0);
                ASSERT(ip->i_df.if_broot_bytes == 0);
                return VN_INACTIVE_CACHE;
@@ -1172,7 +1202,7 @@ xfs_inactive(
                     (!(ip->i_d.di_flags &
                                (XFS_DIFLAG_PREALLOC | XFS_DIFLAG_APPEND)) ||
                      (ip->i_delayed_blks != 0)))) {
-                       error = xfs_free_eofblocks(mp, ip, XFS_FREE_EOF_LOCK);
+                       error = xfs_free_eofblocks(mp, ip, 0);
                        if (error)
                                return VN_INACTIVE_CACHE;
                }
@@ -1181,7 +1211,8 @@ xfs_inactive(
 
        ASSERT(ip->i_d.di_nlink == 0);
 
-       if ((error = XFS_QM_DQATTACH(mp, ip, 0)))
+       error = xfs_qm_dqattach(ip, 0);
+       if (error)
                return VN_INACTIVE_CACHE;
 
        tp = xfs_trans_alloc(mp, XFS_TRANS_INACTIVE);
@@ -1307,7 +1338,7 @@ xfs_inactive(
                /*
                 * Credit the quota account(s). The inode is gone.
                 */
-               XFS_TRANS_MOD_DQUOT_BYINO(mp, tp, ip, XFS_TRANS_DQ_ICOUNT, -1);
+               xfs_trans_mod_dquot_byino(tp, ip, XFS_TRANS_DQ_ICOUNT, -1);
 
                /*
                 * Just ignore errors at this point.  There is nothing we can
@@ -1323,11 +1354,11 @@ xfs_inactive(
                        xfs_fs_cmn_err(CE_NOTE, mp, "xfs_inactive: "
                                "xfs_trans_commit() returned error %d", error);
        }
+
        /*
         * Release the dquots held by inode, if any.
         */
-       XFS_QM_DQDETACH(mp, ip);
-
+       xfs_qm_dqdetach(ip);
        xfs_iunlock(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
 
  out:
@@ -1367,7 +1398,6 @@ xfs_lookup(
        if (error)
                goto out_free_name;
 
-       xfs_itrace_ref(*ipp);
        return 0;
 
 out_free_name:
@@ -1387,23 +1417,28 @@ xfs_create(
        xfs_inode_t             **ipp,
        cred_t                  *credp)
 {
-       xfs_mount_t             *mp = dp->i_mount;
-       xfs_inode_t             *ip;
-       xfs_trans_t             *tp;
+       int                     is_dir = S_ISDIR(mode);
+       struct xfs_mount        *mp = dp->i_mount;
+       struct xfs_inode        *ip = NULL;
+       struct xfs_trans        *tp = NULL;
        int                     error;
        xfs_bmap_free_t         free_list;
        xfs_fsblock_t           first_block;
        boolean_t               unlock_dp_on_error = B_FALSE;
-       int                     dm_event_sent = 0;
        uint                    cancel_flags;
        int                     committed;
        xfs_prid_t              prid;
-       struct xfs_dquot        *udqp, *gdqp;
+       struct xfs_dquot        *udqp = NULL;
+       struct xfs_dquot        *gdqp = NULL;
        uint                    resblks;
+       uint                    log_res;
+       uint                    log_count;
 
-       ASSERT(!*ipp);
        xfs_itrace_entry(dp);
 
+       if (XFS_FORCED_SHUTDOWN(mp))
+               return XFS_ERROR(EIO);
+
        if (DM_EVENT_ENABLED(dp, DM_EVENT_CREATE)) {
                error = XFS_SEND_NAMESP(mp, DM_EVENT_CREATE,
                                dp, DM_RIGHT_NULL, NULL,
@@ -1412,84 +1447,102 @@ xfs_create(
 
                if (error)
                        return error;
-               dm_event_sent = 1;
        }
 
-       if (XFS_FORCED_SHUTDOWN(mp))
-               return XFS_ERROR(EIO);
-
-       /* Return through std_return after this point. */
-
-       udqp = gdqp = NULL;
        if (dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT)
                prid = dp->i_d.di_projid;
        else
-               prid = (xfs_prid_t)dfltprid;
+               prid = dfltprid;
 
        /*
         * Make sure that we have allocated dquot(s) on disk.
         */
-       error = XFS_QM_DQVOPALLOC(mp, dp,
-                       current_fsuid(), current_fsgid(), prid,
-                       XFS_QMOPT_QUOTALL|XFS_QMOPT_INHERIT, &udqp, &gdqp);
+       error = xfs_qm_vop_dqalloc(dp, current_fsuid(), current_fsgid(), prid,
+                       XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, &udqp, &gdqp);
        if (error)
                goto std_return;
 
-       ip = NULL;
+       if (is_dir) {
+               rdev = 0;
+               resblks = XFS_MKDIR_SPACE_RES(mp, name->len);
+               log_res = XFS_MKDIR_LOG_RES(mp);
+               log_count = XFS_MKDIR_LOG_COUNT;
+               tp = xfs_trans_alloc(mp, XFS_TRANS_MKDIR);
+       } else {
+               resblks = XFS_CREATE_SPACE_RES(mp, name->len);
+               log_res = XFS_CREATE_LOG_RES(mp);
+               log_count = XFS_CREATE_LOG_COUNT;
+               tp = xfs_trans_alloc(mp, XFS_TRANS_CREATE);
+       }
 
-       tp = xfs_trans_alloc(mp, XFS_TRANS_CREATE);
        cancel_flags = XFS_TRANS_RELEASE_LOG_RES;
-       resblks = XFS_CREATE_SPACE_RES(mp, name->len);
+
        /*
         * Initially assume that the file does not exist and
         * reserve the resources for that case.  If that is not
         * the case we'll drop the one we have and get a more
         * appropriate transaction later.
         */
-       error = xfs_trans_reserve(tp, resblks, XFS_CREATE_LOG_RES(mp), 0,
-                       XFS_TRANS_PERM_LOG_RES, XFS_CREATE_LOG_COUNT);
+       error = xfs_trans_reserve(tp, resblks, log_res, 0,
+                       XFS_TRANS_PERM_LOG_RES, log_count);
+       if (error == ENOSPC) {
+               /* flush outstanding delalloc blocks and retry */
+               xfs_flush_inodes(dp);
+               error = xfs_trans_reserve(tp, resblks, log_res, 0,
+                               XFS_TRANS_PERM_LOG_RES, log_count);
+       }
        if (error == ENOSPC) {
+               /* No space at all so try a "no-allocation" reservation */
                resblks = 0;
-               error = xfs_trans_reserve(tp, 0, XFS_CREATE_LOG_RES(mp), 0,
-                               XFS_TRANS_PERM_LOG_RES, XFS_CREATE_LOG_COUNT);
+               error = xfs_trans_reserve(tp, 0, log_res, 0,
+                               XFS_TRANS_PERM_LOG_RES, log_count);
        }
        if (error) {
                cancel_flags = 0;
-               goto error_return;
+               goto out_trans_cancel;
        }
 
        xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
        unlock_dp_on_error = B_TRUE;
 
-       xfs_bmap_init(&free_list, &first_block);
+       /*
+        * Check for directory link count overflow.
+        */
+       if (is_dir && dp->i_d.di_nlink >= XFS_MAXLINK) {
+               error = XFS_ERROR(EMLINK);
+               goto out_trans_cancel;
+       }
 
-       ASSERT(ip == NULL);
+       xfs_bmap_init(&free_list, &first_block);
 
        /*
         * Reserve disk quota and the inode.
         */
-       error = XFS_TRANS_RESERVE_QUOTA(mp, tp, udqp, gdqp, resblks, 1, 0);
+       error = xfs_trans_reserve_quota(tp, mp, udqp, gdqp, resblks, 1, 0);
        if (error)
-               goto error_return;
+               goto out_trans_cancel;
 
        error = xfs_dir_canenter(tp, dp, name, resblks);
        if (error)
-               goto error_return;
-       error = xfs_dir_ialloc(&tp, dp, mode, 1,
-                       rdev, credp, prid, resblks > 0,
-                       &ip, &committed);
+               goto out_trans_cancel;
+
+       /*
+        * A newly created regular or special file just has one directory
+        * entry pointing to them, but a directory also the "." entry
+        * pointing to itself.
+        */
+       error = xfs_dir_ialloc(&tp, dp, mode, is_dir ? 2 : 1, rdev, credp,
+                              prid, resblks > 0, &ip, &committed);
        if (error) {
                if (error == ENOSPC)
-                       goto error_return;
-               goto abort_return;
+                       goto out_trans_cancel;
+               goto out_trans_abort;
        }
-       xfs_itrace_ref(ip);
 
        /*
         * At this point, we've gotten a newly allocated inode.
         * It is locked (and joined to the transaction).
         */
-
        ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
 
        /*
@@ -1508,26 +1561,35 @@ xfs_create(
                                        resblks - XFS_IALLOC_SPACE_RES(mp) : 0);
        if (error) {
                ASSERT(error != ENOSPC);
-               goto abort_return;
+               goto out_trans_abort;
        }
        xfs_ichgtime(dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
        xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE);
 
+       if (is_dir) {
+               error = xfs_dir_init(tp, ip, dp);
+               if (error)
+                       goto out_bmap_cancel;
+
+               error = xfs_bumplink(tp, dp);
+               if (error)
+                       goto out_bmap_cancel;
+       }
+
        /*
         * If this is a synchronous mount, make sure that the
         * create transaction goes to disk before returning to
         * the user.
         */
-       if (mp->m_flags & (XFS_MOUNT_WSYNC|XFS_MOUNT_DIRSYNC)) {
+       if (mp->m_flags & (XFS_MOUNT_WSYNC|XFS_MOUNT_DIRSYNC))
                xfs_trans_set_sync(tp);
-       }
 
        /*
         * Attach the dquot(s) to the inodes and modify them incore.
         * These ids of the inode couldn't have changed since the new
         * inode has been locked ever since it was created.
         */
-       XFS_QM_DQVOPCREATE(mp, tp, ip, udqp, gdqp);
+       xfs_qm_vop_create_dqattach(tp, ip, udqp, gdqp);
 
        /*
         * xfs_trans_commit normally decrements the vnode ref count
@@ -1537,66 +1599,57 @@ xfs_create(
        IHOLD(ip);
 
        error = xfs_bmap_finish(&tp, &free_list, &committed);
-       if (error) {
-               xfs_bmap_cancel(&free_list);
-               goto abort_rele;
-       }
+       if (error)
+               goto out_abort_rele;
 
        error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
        if (error) {
                IRELE(ip);
-               tp = NULL;
-               goto error_return;
+               goto out_dqrele;
        }
 
-       XFS_QM_DQRELE(mp, udqp);
-       XFS_QM_DQRELE(mp, gdqp);
+       xfs_qm_dqrele(udqp);
+       xfs_qm_dqrele(gdqp);
 
        *ipp = ip;
 
        /* Fallthrough to std_return with error = 0  */
-
-std_return:
-       if ((*ipp || (error != 0 && dm_event_sent != 0)) &&
-           DM_EVENT_ENABLED(dp, DM_EVENT_POSTCREATE)) {
-               (void) XFS_SEND_NAMESP(mp, DM_EVENT_POSTCREATE,
-                       dp, DM_RIGHT_NULL,
-                       *ipp ? ip : NULL,
-                       DM_RIGHT_NULL, name->name, NULL,
-                       mode, error, 0);
+ std_return:
+       if (DM_EVENT_ENABLED(dp, DM_EVENT_POSTCREATE)) {
+               XFS_SEND_NAMESP(mp, DM_EVENT_POSTCREATE, dp, DM_RIGHT_NULL,
+                               ip, DM_RIGHT_NULL, name->name, NULL, mode,
+                               error, 0);
        }
+
        return error;
 
- abort_return:
+ out_bmap_cancel:
+       xfs_bmap_cancel(&free_list);
+ out_trans_abort:
        cancel_flags |= XFS_TRANS_ABORT;
-       /* FALLTHROUGH */
-
- error_return:
-       if (tp != NULL)
-               xfs_trans_cancel(tp, cancel_flags);
-
-       XFS_QM_DQRELE(mp, udqp);
-       XFS_QM_DQRELE(mp, gdqp);
+ out_trans_cancel:
+       xfs_trans_cancel(tp, cancel_flags);
+ out_dqrele:
+       xfs_qm_dqrele(udqp);
+       xfs_qm_dqrele(gdqp);
 
        if (unlock_dp_on_error)
                xfs_iunlock(dp, XFS_ILOCK_EXCL);
 
        goto std_return;
 
- abort_rele:
out_abort_rele:
        /*
         * Wait until after the current transaction is aborted to
         * release the inode.  This prevents recursive transactions
         * and deadlocks from xfs_inactive.
         */
+       xfs_bmap_cancel(&free_list);
        cancel_flags |= XFS_TRANS_ABORT;
        xfs_trans_cancel(tp, cancel_flags);
        IRELE(ip);
-
-       XFS_QM_DQRELE(mp, udqp);
-       XFS_QM_DQRELE(mp, gdqp);
-
-       goto std_return;
+       unlock_dp_on_error = B_FALSE;
+       goto out_dqrele;
 }
 
 #ifdef DEBUG
@@ -1812,11 +1865,11 @@ xfs_remove(
                        return error;
        }
 
-       error = XFS_QM_DQATTACH(mp, dp, 0);
+       error = xfs_qm_dqattach(dp, 0);
        if (error)
                goto std_return;
 
-       error = XFS_QM_DQATTACH(mp, ip, 0);
+       error = xfs_qm_dqattach(ip, 0);
        if (error)
                goto std_return;
 
@@ -1949,9 +2002,6 @@ xfs_remove(
        if (!is_dir && link_zero && xfs_inode_is_filestream(ip))
                xfs_filestream_deassociate(ip);
 
-       xfs_itrace_exit(ip);
-       xfs_itrace_exit(dp);
-
  std_return:
        if (DM_EVENT_ENABLED(dp, DM_EVENT_POSTREMOVE)) {
                XFS_SEND_NAMESP(mp, DM_EVENT_POSTREMOVE, dp, DM_RIGHT_NULL,
@@ -2003,9 +2053,11 @@ xfs_link(
 
        /* Return through std_return after this point. */
 
-       error = XFS_QM_DQATTACH(mp, sip, 0);
-       if (!error && sip != tdp)
-               error = XFS_QM_DQATTACH(mp, tdp, 0);
+       error = xfs_qm_dqattach(sip, 0);
+       if (error)
+               goto std_return;
+
+       error = xfs_qm_dqattach(tdp, 0);
        if (error)
                goto std_return;
 
@@ -2110,209 +2162,6 @@ std_return:
        goto std_return;
 }
 
-
-int
-xfs_mkdir(
-       xfs_inode_t             *dp,
-       struct xfs_name         *dir_name,
-       mode_t                  mode,
-       xfs_inode_t             **ipp,
-       cred_t                  *credp)
-{
-       xfs_mount_t             *mp = dp->i_mount;
-       xfs_inode_t             *cdp;   /* inode of created dir */
-       xfs_trans_t             *tp;
-       int                     cancel_flags;
-       int                     error;
-       int                     committed;
-       xfs_bmap_free_t         free_list;
-       xfs_fsblock_t           first_block;
-       boolean_t               unlock_dp_on_error = B_FALSE;
-       boolean_t               created = B_FALSE;
-       int                     dm_event_sent = 0;
-       xfs_prid_t              prid;
-       struct xfs_dquot        *udqp, *gdqp;
-       uint                    resblks;
-
-       if (XFS_FORCED_SHUTDOWN(mp))
-               return XFS_ERROR(EIO);
-
-       tp = NULL;
-
-       if (DM_EVENT_ENABLED(dp, DM_EVENT_CREATE)) {
-               error = XFS_SEND_NAMESP(mp, DM_EVENT_CREATE,
-                                       dp, DM_RIGHT_NULL, NULL,
-                                       DM_RIGHT_NULL, dir_name->name, NULL,
-                                       mode, 0, 0);
-               if (error)
-                       return error;
-               dm_event_sent = 1;
-       }
-
-       /* Return through std_return after this point. */
-
-       xfs_itrace_entry(dp);
-
-       mp = dp->i_mount;
-       udqp = gdqp = NULL;
-       if (dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT)
-               prid = dp->i_d.di_projid;
-       else
-               prid = (xfs_prid_t)dfltprid;
-
-       /*
-        * Make sure that we have allocated dquot(s) on disk.
-        */
-       error = XFS_QM_DQVOPALLOC(mp, dp,
-                       current_fsuid(), current_fsgid(), prid,
-                       XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, &udqp, &gdqp);
-       if (error)
-               goto std_return;
-
-       tp = xfs_trans_alloc(mp, XFS_TRANS_MKDIR);
-       cancel_flags = XFS_TRANS_RELEASE_LOG_RES;
-       resblks = XFS_MKDIR_SPACE_RES(mp, dir_name->len);
-       error = xfs_trans_reserve(tp, resblks, XFS_MKDIR_LOG_RES(mp), 0,
-                                 XFS_TRANS_PERM_LOG_RES, XFS_MKDIR_LOG_COUNT);
-       if (error == ENOSPC) {
-               resblks = 0;
-               error = xfs_trans_reserve(tp, 0, XFS_MKDIR_LOG_RES(mp), 0,
-                                         XFS_TRANS_PERM_LOG_RES,
-                                         XFS_MKDIR_LOG_COUNT);
-       }
-       if (error) {
-               cancel_flags = 0;
-               goto error_return;
-       }
-
-       xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
-       unlock_dp_on_error = B_TRUE;
-
-       /*
-        * Check for directory link count overflow.
-        */
-       if (dp->i_d.di_nlink >= XFS_MAXLINK) {
-               error = XFS_ERROR(EMLINK);
-               goto error_return;
-       }
-
-       /*
-        * Reserve disk quota and the inode.
-        */
-       error = XFS_TRANS_RESERVE_QUOTA(mp, tp, udqp, gdqp, resblks, 1, 0);
-       if (error)
-               goto error_return;
-
-       error = xfs_dir_canenter(tp, dp, dir_name, resblks);
-       if (error)
-               goto error_return;
-       /*
-        * create the directory inode.
-        */
-       error = xfs_dir_ialloc(&tp, dp, mode, 2,
-                       0, credp, prid, resblks > 0,
-               &cdp, NULL);
-       if (error) {
-               if (error == ENOSPC)
-                       goto error_return;
-               goto abort_return;
-       }
-       xfs_itrace_ref(cdp);
-
-       /*
-        * Now we add the directory inode to the transaction.
-        * We waited until now since xfs_dir_ialloc might start
-        * a new transaction.  Had we joined the transaction
-        * earlier, the locks might have gotten released. An error
-        * from here on will result in the transaction cancel
-        * unlocking dp so don't do it explicitly in the error path.
-        */
-       IHOLD(dp);
-       xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
-       unlock_dp_on_error = B_FALSE;
-
-       xfs_bmap_init(&free_list, &first_block);
-
-       error = xfs_dir_createname(tp, dp, dir_name, cdp->i_ino,
-                                       &first_block, &free_list, resblks ?
-                                       resblks - XFS_IALLOC_SPACE_RES(mp) : 0);
-       if (error) {
-               ASSERT(error != ENOSPC);
-               goto error1;
-       }
-       xfs_ichgtime(dp, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
-
-       error = xfs_dir_init(tp, cdp, dp);
-       if (error)
-               goto error2;
-
-       error = xfs_bumplink(tp, dp);
-       if (error)
-               goto error2;
-
-       created = B_TRUE;
-
-       *ipp = cdp;
-       IHOLD(cdp);
-
-       /*
-        * Attach the dquots to the new inode and modify the icount incore.
-        */
-       XFS_QM_DQVOPCREATE(mp, tp, cdp, udqp, gdqp);
-
-       /*
-        * If this is a synchronous mount, make sure that the
-        * mkdir transaction goes to disk before returning to
-        * the user.
-        */
-       if (mp->m_flags & (XFS_MOUNT_WSYNC|XFS_MOUNT_DIRSYNC)) {
-               xfs_trans_set_sync(tp);
-       }
-
-       error = xfs_bmap_finish(&tp, &free_list, &committed);
-       if (error) {
-               IRELE(cdp);
-               goto error2;
-       }
-
-       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
-       XFS_QM_DQRELE(mp, udqp);
-       XFS_QM_DQRELE(mp, gdqp);
-       if (error) {
-               IRELE(cdp);
-       }
-
-       /* Fall through to std_return with error = 0 or errno from
-        * xfs_trans_commit. */
-
-std_return:
-       if ((created || (error != 0 && dm_event_sent != 0)) &&
-           DM_EVENT_ENABLED(dp, DM_EVENT_POSTCREATE)) {
-               (void) XFS_SEND_NAMESP(mp, DM_EVENT_POSTCREATE,
-                                       dp, DM_RIGHT_NULL,
-                                       created ? cdp : NULL,
-                                       DM_RIGHT_NULL,
-                                       dir_name->name, NULL,
-                                       mode, error, 0);
-       }
-       return error;
-
- error2:
- error1:
-       xfs_bmap_cancel(&free_list);
- abort_return:
-       cancel_flags |= XFS_TRANS_ABORT;
- error_return:
-       xfs_trans_cancel(tp, cancel_flags);
-       XFS_QM_DQRELE(mp, udqp);
-       XFS_QM_DQRELE(mp, gdqp);
-
-       if (unlock_dp_on_error)
-               xfs_iunlock(dp, XFS_ILOCK_EXCL);
-
-       goto std_return;
-}
-
 int
 xfs_symlink(
        xfs_inode_t             *dp,
@@ -2381,8 +2230,7 @@ xfs_symlink(
        /*
         * Make sure that we have allocated dquot(s) on disk.
         */
-       error = XFS_QM_DQVOPALLOC(mp, dp,
-                       current_fsuid(), current_fsgid(), prid,
+       error = xfs_qm_vop_dqalloc(dp, current_fsuid(), current_fsgid(), prid,
                        XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, &udqp, &gdqp);
        if (error)
                goto std_return;
@@ -2424,7 +2272,7 @@ xfs_symlink(
        /*
         * Reserve disk quota : blocks and inode.
         */
-       error = XFS_TRANS_RESERVE_QUOTA(mp, tp, udqp, gdqp, resblks, 1, 0);
+       error = xfs_trans_reserve_quota(tp, mp, udqp, gdqp, resblks, 1, 0);
        if (error)
                goto error_return;
 
@@ -2450,7 +2298,6 @@ xfs_symlink(
                        goto error_return;
                goto error1;
        }
-       xfs_itrace_ref(ip);
 
        /*
         * An error after we've joined dp to the transaction will result in the
@@ -2464,7 +2311,7 @@ xfs_symlink(
        /*
         * Also attach the dquot(s) to it, if applicable.
         */
-       XFS_QM_DQVOPCREATE(mp, tp, ip, udqp, gdqp);
+       xfs_qm_vop_create_dqattach(tp, ip, udqp, gdqp);
 
        if (resblks)
                resblks -= XFS_IALLOC_SPACE_RES(mp);
@@ -2552,8 +2399,8 @@ xfs_symlink(
                goto error2;
        }
        error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
-       XFS_QM_DQRELE(mp, udqp);
-       XFS_QM_DQRELE(mp, gdqp);
+       xfs_qm_dqrele(udqp);
+       xfs_qm_dqrele(gdqp);
 
        /* Fall through to std_return with error = 0 or errno from
         * xfs_trans_commit     */
@@ -2577,8 +2424,8 @@ std_return:
        cancel_flags |= XFS_TRANS_ABORT;
  error_return:
        xfs_trans_cancel(tp, cancel_flags);
-       XFS_QM_DQRELE(mp, udqp);
-       XFS_QM_DQRELE(mp, gdqp);
+       xfs_qm_dqrele(udqp);
+       xfs_qm_dqrele(gdqp);
 
        if (unlock_dp_on_error)
                xfs_iunlock(dp, XFS_ILOCK_EXCL);
@@ -2587,51 +2434,6 @@ std_return:
 }
 
 int
-xfs_inode_flush(
-       xfs_inode_t     *ip,
-       int             flags)
-{
-       xfs_mount_t     *mp = ip->i_mount;
-       int             error = 0;
-
-       if (XFS_FORCED_SHUTDOWN(mp))
-               return XFS_ERROR(EIO);
-
-       /*
-        * Bypass inodes which have already been cleaned by
-        * the inode flush clustering code inside xfs_iflush
-        */
-       if (xfs_inode_clean(ip))
-               return 0;
-
-       /*
-        * We make this non-blocking if the inode is contended,
-        * return EAGAIN to indicate to the caller that they
-        * did not succeed. This prevents the flush path from
-        * blocking on inodes inside another operation right
-        * now, they get caught later by xfs_sync.
-        */
-       if (flags & FLUSH_SYNC) {
-               xfs_ilock(ip, XFS_ILOCK_SHARED);
-               xfs_iflock(ip);
-       } else if (xfs_ilock_nowait(ip, XFS_ILOCK_SHARED)) {
-               if (xfs_ipincount(ip) || !xfs_iflock_nowait(ip)) {
-                       xfs_iunlock(ip, XFS_ILOCK_SHARED);
-                       return EAGAIN;
-               }
-       } else {
-               return EAGAIN;
-       }
-
-       error = xfs_iflush(ip, (flags & FLUSH_SYNC) ? XFS_IFLUSH_SYNC
-                                                   : XFS_IFLUSH_ASYNC_NOBLOCK);
-       xfs_iunlock(ip, XFS_ILOCK_SHARED);
-
-       return error;
-}
-
-
-int
 xfs_set_dmattrs(
        xfs_inode_t     *ip,
        u_int           evmask,
@@ -2666,52 +2468,6 @@ xfs_set_dmattrs(
        return error;
 }
 
-int
-xfs_reclaim(
-       xfs_inode_t     *ip)
-{
-
-       xfs_itrace_entry(ip);
-
-       ASSERT(!VN_MAPPED(VFS_I(ip)));
-
-       /* bad inode, get out here ASAP */
-       if (VN_BAD(VFS_I(ip))) {
-               xfs_ireclaim(ip);
-               return 0;
-       }
-
-       xfs_ioend_wait(ip);
-
-       ASSERT(XFS_FORCED_SHUTDOWN(ip->i_mount) || ip->i_delayed_blks == 0);
-
-       /*
-        * Make sure the atime in the XFS inode is correct before freeing the
-        * Linux inode.
-        */
-       xfs_synchronize_atime(ip);
-
-       /*
-        * If we have nothing to flush with this inode then complete the
-        * teardown now, otherwise break the link between the xfs inode and the
-        * linux inode and clean up the xfs inode later. This avoids flushing
-        * the inode to disk during the delete operation itself.
-        *
-        * When breaking the link, we need to set the XFS_IRECLAIMABLE flag
-        * first to ensure that xfs_iunpin() will never see an xfs inode
-        * that has a linux inode being reclaimed. Synchronisation is provided
-        * by the i_flags_lock.
-        */
-       if (!ip->i_update_core && (ip->i_itemp == NULL)) {
-               xfs_ilock(ip, XFS_ILOCK_EXCL);
-               xfs_iflock(ip);
-               xfs_iflags_set(ip, XFS_IRECLAIMABLE);
-               return xfs_reclaim_inode(ip, 1, XFS_IFLUSH_DELWRI_ELSE_SYNC);
-       }
-       xfs_inode_set_reclaim_tag(ip);
-       return 0;
-}
-
 /*
  * xfs_alloc_file_space()
  *      This routine allocates disk space for the given file.
@@ -2762,7 +2518,8 @@ xfs_alloc_file_space(
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
 
-       if ((error = XFS_QM_DQATTACH(mp, ip, 0)))
+       error = xfs_qm_dqattach(ip, 0);
+       if (error)
                return error;
 
        if (len <= 0)
@@ -2849,8 +2606,8 @@ retry:
                        break;
                }
                xfs_ilock(ip, XFS_ILOCK_EXCL);
-               error = XFS_TRANS_RESERVE_QUOTA_NBLKS(mp, tp, ip,
-                                                     qblocks, 0, quota_flag);
+               error = xfs_trans_reserve_quota_nblks(tp, ip, qblocks,
+                                                     0, quota_flag);
                if (error)
                        goto error1;
 
@@ -2909,7 +2666,7 @@ dmapi_enospc_check:
 
 error0:        /* Cancel bmap, unlock inode, unreserve quota blocks, cancel trans */
        xfs_bmap_cancel(&free_list);
-       XFS_TRANS_UNRESERVE_QUOTA_NBLKS(mp, tp, ip, qblocks, 0, quota_flag);
+       xfs_trans_unreserve_quota_nblks(tp, ip, qblocks, 0, quota_flag);
 
 error1:        /* Just cancel transaction */
        xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT);
@@ -3048,7 +2805,8 @@ xfs_free_file_space(
 
        xfs_itrace_entry(ip);
 
-       if ((error = XFS_QM_DQATTACH(mp, ip, 0)))
+       error = xfs_qm_dqattach(ip, 0);
+       if (error)
                return error;
 
        error = 0;
@@ -3082,7 +2840,6 @@ xfs_free_file_space(
        ioffset = offset & ~(rounding - 1);
 
        if (VN_CACHED(VFS_I(ip)) != 0) {
-               xfs_inval_cached_trace(ip, ioffset, -1, ioffset, -1);
                error = xfs_flushinval_pages(ip, ioffset, -1, FI_REMAPF_LOCKED);
                if (error)
                        goto out_unlock_iolock;
@@ -3090,7 +2847,7 @@ xfs_free_file_space(
 
        /*
         * Need to zero the stuff we're not freeing, on disk.
-        * If its a realtime file & can't use unwritten extents then we
+        * If it's a realtime file & can't use unwritten extents then we
         * actually need to zero the extent edges.  Otherwise xfs_bunmapi
         * will take care of it for us.
         */
@@ -3174,9 +2931,9 @@ xfs_free_file_space(
                        break;
                }
                xfs_ilock(ip, XFS_ILOCK_EXCL);
-               error = XFS_TRANS_RESERVE_QUOTA(mp, tp,
-                               ip->i_udquot, ip->i_gdquot, resblks, 0,
-                               XFS_QMOPT_RES_REGBLKS);
+               error = xfs_trans_reserve_quota(tp, mp,
+                               ip->i_udquot, ip->i_gdquot,
+                               resblks, 0, XFS_QMOPT_RES_REGBLKS);
                if (error)
                        goto error1;