[XFS] cleanup vnode use in xfs_symlink and xfs_rename
[pandora-kernel.git] / fs / xfs / xfs_vnodeops.c
index efd5aff..fa694dc 100644 (file)
@@ -48,7 +48,6 @@
 #include "xfs_quota.h"
 #include "xfs_utils.h"
 #include "xfs_rtalloc.h"
-#include "xfs_refcache.h"
 #include "xfs_trans_space.h"
 #include "xfs_log_priv.h"
 #include "xfs_filestream.h"
@@ -88,7 +87,7 @@ xfs_getattr(
        bhv_vnode_t     *vp = XFS_ITOV(ip);
        xfs_mount_t     *mp = ip->i_mount;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
@@ -136,7 +135,7 @@ xfs_getattr(
        default:
                vap->va_rdev = 0;
 
-               if (!(ip->i_d.di_flags & XFS_DIFLAG_REALTIME)) {
+               if (!(XFS_IS_REALTIME_INODE(ip))) {
                        vap->va_blocksize = xfs_preferred_iosize(mp);
                } else {
 
@@ -228,7 +227,7 @@ xfs_setattr(
        int                     file_owner;
        int                     need_iolock = 1;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        if (mp->m_flags & XFS_MOUNT_RDONLY)
                return XFS_ERROR(EROFS);
@@ -327,7 +326,7 @@ xfs_setattr(
                if (DM_EVENT_ENABLED(ip, DM_EVENT_TRUNCATE) &&
                    !(flags & ATTR_DMI)) {
                        int dmflags = AT_DELAY_FLAG(flags) | DM_SEM_FLAG_WR;
-                       code = XFS_SEND_DATA(mp, DM_EVENT_TRUNCATE, vp,
+                       code = XFS_SEND_DATA(mp, DM_EVENT_TRUNCATE, ip,
                                vap->va_size, 0, dmflags, NULL);
                        if (code) {
                                lock_flags = 0;
@@ -508,7 +507,7 @@ xfs_setattr(
                 */
                if ((ip->i_d.di_nextents || ip->i_delayed_blks) &&
                    (mask & XFS_AT_XFLAGS) &&
-                   (ip->i_d.di_flags & XFS_DIFLAG_REALTIME) !=
+                   (XFS_IS_REALTIME_INODE(ip)) !=
                    (vap->va_xflags & XFS_XFLAG_REALTIME)) {
                        code = XFS_ERROR(EINVAL);       /* EFBIG? */
                        goto error_return;
@@ -520,7 +519,7 @@ xfs_setattr(
                if ((mask & XFS_AT_EXTSIZE) && vap->va_extsize != 0) {
                        xfs_extlen_t    size;
 
-                       if ((ip->i_d.di_flags & XFS_DIFLAG_REALTIME) ||
+                       if (XFS_IS_REALTIME_INODE(ip) ||
                            ((mask & XFS_AT_XFLAGS) &&
                            (vap->va_xflags & XFS_XFLAG_REALTIME))) {
                                size = mp->m_sb.sb_rextsize <<
@@ -634,6 +633,15 @@ xfs_setattr(
         * Truncate file.  Must have write permission and not be a directory.
         */
        if (mask & XFS_AT_SIZE) {
+               /*
+                * Only change the c/mtime if we are changing the size
+                * or we are explicitly asked to change it. This handles
+                * the semantic difference between truncate() and ftruncate()
+                * as implemented in the VFS.
+                */
+               if (vap->va_size != ip->i_size || (mask & XFS_AT_CTIME))
+                       timeflags |= XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG;
+
                if (vap->va_size > ip->i_size) {
                        xfs_igrow_finish(tp, ip, vap->va_size,
                            !(flags & ATTR_DMI));
@@ -662,10 +670,6 @@ xfs_setattr(
                         */
                        xfs_iflags_set(ip, XFS_ITRUNCATED);
                }
-               /*
-                * Have to do this even if the file's size doesn't change.
-                */
-               timeflags |= XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG;
        }
 
        /*
@@ -804,12 +808,8 @@ xfs_setattr(
                                if (vap->va_xflags & XFS_XFLAG_EXTSZINHERIT)
                                        di_flags |= XFS_DIFLAG_EXTSZINHERIT;
                        } else if ((ip->i_d.di_mode & S_IFMT) == S_IFREG) {
-                               if (vap->va_xflags & XFS_XFLAG_REALTIME) {
+                               if (vap->va_xflags & XFS_XFLAG_REALTIME)
                                        di_flags |= XFS_DIFLAG_REALTIME;
-                                       ip->i_iocore.io_flags |= XFS_IOCORE_RT;
-                               } else {
-                                       ip->i_iocore.io_flags &= ~XFS_IOCORE_RT;
-                               }
                                if (vap->va_xflags & XFS_XFLAG_EXTSIZE)
                                        di_flags |= XFS_DIFLAG_EXTSIZE;
                        }
@@ -881,7 +881,7 @@ xfs_setattr(
 
        if (DM_EVENT_ENABLED(ip, DM_EVENT_ATTRIBUTE) &&
            !(flags & ATTR_DMI)) {
-               (void) XFS_SEND_NAMESP(mp, DM_EVENT_ATTRIBUTE, vp, DM_RIGHT_NULL,
+               (void) XFS_SEND_NAMESP(mp, DM_EVENT_ATTRIBUTE, ip, DM_RIGHT_NULL,
                                        NULL, DM_RIGHT_NULL, NULL, NULL,
                                        0, 0, AT_DELAY_FLAG(flags));
        }
@@ -902,28 +902,6 @@ xfs_setattr(
        return code;
 }
 
-
-/*
- * xfs_access
- * Null conversion from vnode mode bits to inode mode bits, as in efs.
- */
-int
-xfs_access(
-       xfs_inode_t     *ip,
-       int             mode,
-       cred_t          *credp)
-{
-       int             error;
-
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
-
-       xfs_ilock(ip, XFS_ILOCK_SHARED);
-       error = xfs_iaccess(ip, mode, credp);
-       xfs_iunlock(ip, XFS_ILOCK_SHARED);
-       return error;
-}
-
-
 /*
  * The maximum pathlen is 1024 bytes. Since the minimum file system
  * blocksize is 512 bytes, we can get a max of 2 extents back from
@@ -987,7 +965,7 @@ xfs_readlink(
        int             pathlen;
        int             error = 0;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
@@ -1033,7 +1011,7 @@ xfs_fsync(
        int             error;
        int             log_flushed = 0, changed = 1;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        ASSERT(start >= 0 && stop >= -1);
 
@@ -1149,7 +1127,7 @@ xfs_fsync(
                 * If this inode is on the RT dev we need to flush that
                 * cache as well.
                 */
-               if (ip->i_d.di_flags & XFS_DIFLAG_REALTIME)
+               if (XFS_IS_REALTIME_INODE(ip))
                        xfs_blkdev_issue_flush(ip->i_mount->m_rtdev_targp);
        }
 
@@ -1188,7 +1166,7 @@ xfs_free_eofblocks(
 
        nimaps = 1;
        xfs_ilock(ip, XFS_ILOCK_SHARED);
-       error = XFS_BMAPI(mp, NULL, &ip->i_iocore, end_fsb, map_len, 0,
+       error = xfs_bmapi(NULL, ip, end_fsb, map_len, 0,
                          NULL, 0, &imap, &nimaps, NULL, NULL);
        xfs_iunlock(ip, XFS_ILOCK_SHARED);
 
@@ -1546,12 +1524,6 @@ xfs_release(
                        xfs_flush_pages(ip, 0, -1, XFS_B_ASYNC, FI_NONE);
        }
 
-#ifdef HAVE_REFCACHE
-       /* If we are in the NFS reference cache then don't do this now */
-       if (ip->i_refcache)
-               return 0;
-#endif
-
        if (ip->i_d.di_nlink != 0) {
                if ((((ip->i_d.di_mode & S_IFMT) == S_IFREG) &&
                     ((ip->i_size > 0) || (VN_CACHED(vp) > 0 ||
@@ -1562,9 +1534,6 @@ xfs_release(
                        error = xfs_free_eofblocks(mp, ip, XFS_FREE_EOF_LOCK);
                        if (error)
                                return error;
-                       /* Update linux inode block count after free above */
-                       vn_to_inode(vp)->i_blocks = XFS_FSB_TO_BB(mp,
-                               ip->i_d.di_nblocks + ip->i_delayed_blks);
                }
        }
 
@@ -1592,7 +1561,7 @@ xfs_inactive(
        int             error;
        int             truncate;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        /*
         * If the inode is already free, then there can be nothing
@@ -1617,9 +1586,8 @@ xfs_inactive(
 
        mp = ip->i_mount;
 
-       if (ip->i_d.di_nlink == 0 && DM_EVENT_ENABLED(ip, DM_EVENT_DESTROY)) {
-               (void) XFS_SEND_DESTROY(mp, vp, DM_RIGHT_NULL);
-       }
+       if (ip->i_d.di_nlink == 0 && DM_EVENT_ENABLED(ip, DM_EVENT_DESTROY))
+               XFS_SEND_DESTROY(mp, ip, DM_RIGHT_NULL);
 
        error = 0;
 
@@ -1638,9 +1606,6 @@ xfs_inactive(
                        error = xfs_free_eofblocks(mp, ip, XFS_FREE_EOF_LOCK);
                        if (error)
                                return VN_INACTIVE_CACHE;
-                       /* Update linux inode block count after free above */
-                       vn_to_inode(vp)->i_blocks = XFS_FSB_TO_BB(mp,
-                               ip->i_d.di_nblocks + ip->i_delayed_blks);
                }
                goto out;
        }
@@ -1805,7 +1770,7 @@ xfs_lookup(
        int                     error;
        uint                    lock_mode;
 
-       vn_trace_entry(dp, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(dp);
 
        if (XFS_FORCED_SHUTDOWN(dp->i_mount))
                return XFS_ERROR(EIO);
@@ -1814,7 +1779,7 @@ xfs_lookup(
        error = xfs_dir_lookup_int(dp, lock_mode, dentry, &e_inum, &ip);
        if (!error) {
                *vpp = XFS_ITOV(ip);
-               ITRACE(ip);
+               xfs_itrace_ref(ip);
        }
        xfs_iunlock_map_shared(dp, lock_mode);
        return error;
@@ -1826,14 +1791,12 @@ xfs_create(
        bhv_vname_t             *dentry,
        mode_t                  mode,
        xfs_dev_t               rdev,
-       bhv_vnode_t             **vpp,
+       xfs_inode_t             **ipp,
        cred_t                  *credp)
 {
        char                    *name = VNAME(dentry);
        xfs_mount_t             *mp = dp->i_mount;
-       bhv_vnode_t             *dir_vp = XFS_ITOV(dp);
        xfs_inode_t             *ip;
-       bhv_vnode_t             *vp = NULL;
        xfs_trans_t             *tp;
        int                     error;
        xfs_bmap_free_t         free_list;
@@ -1847,14 +1810,14 @@ xfs_create(
        uint                    resblks;
        int                     namelen;
 
-       ASSERT(!*vpp);
-       vn_trace_entry(dp, __FUNCTION__, (inst_t *)__return_address);
+       ASSERT(!*ipp);
+       xfs_itrace_entry(dp);
 
        namelen = VNAMELEN(dentry);
 
        if (DM_EVENT_ENABLED(dp, DM_EVENT_CREATE)) {
                error = XFS_SEND_NAMESP(mp, DM_EVENT_CREATE,
-                               dir_vp, DM_RIGHT_NULL, NULL,
+                               dp, DM_RIGHT_NULL, NULL,
                                DM_RIGHT_NULL, name, NULL,
                                mode, 0, 0);
 
@@ -1930,7 +1893,7 @@ xfs_create(
                        goto error_return;
                goto abort_return;
        }
-       ITRACE(ip);
+       xfs_itrace_ref(ip);
 
        /*
         * At this point, we've gotten a newly allocated inode.
@@ -1946,7 +1909,7 @@ xfs_create(
         * the transaction cancel unlocking dp so don't do it explicitly in the
         * error path.
         */
-       VN_HOLD(dir_vp);
+       IHOLD(dp);
        xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
        unlock_dp_on_error = B_FALSE;
 
@@ -1984,7 +1947,6 @@ xfs_create(
         * vnode to the caller, we bump the vnode ref count now.
         */
        IHOLD(ip);
-       vp = XFS_ITOV(ip);
 
        error = xfs_bmap_finish(&tp, &free_list, &committed);
        if (error) {
@@ -2002,16 +1964,16 @@ xfs_create(
        XFS_QM_DQRELE(mp, udqp);
        XFS_QM_DQRELE(mp, gdqp);
 
-       *vpp = vp;
+       *ipp = ip;
 
        /* Fallthrough to std_return with error = 0  */
 
 std_return:
-       if ((*vpp || (error != 0 && dm_event_sent != 0)) &&
+       if ((*ipp || (error != 0 && dm_event_sent != 0)) &&
            DM_EVENT_ENABLED(dp, DM_EVENT_POSTCREATE)) {
                (void) XFS_SEND_NAMESP(mp, DM_EVENT_POSTCREATE,
-                       dir_vp, DM_RIGHT_NULL,
-                       *vpp ? vp:NULL,
+                       dp, DM_RIGHT_NULL,
+                       *ipp ? ip : NULL,
                        DM_RIGHT_NULL, name, NULL,
                        mode, error, 0);
        }
@@ -2098,7 +2060,7 @@ again:
 
        e_inum = ip->i_ino;
 
-       ITRACE(ip);
+       xfs_itrace_ref(ip);
 
        /*
         * We want to lock in increasing inum. Since we've already
@@ -2306,44 +2268,32 @@ xfs_remove(
        xfs_inode_t             *dp,
        bhv_vname_t             *dentry)
 {
-       bhv_vnode_t             *dir_vp = XFS_ITOV(dp);
        char                    *name = VNAME(dentry);
        xfs_mount_t             *mp = dp->i_mount;
-       xfs_inode_t             *ip;
+       xfs_inode_t             *ip = VNAME_TO_INODE(dentry);
+       int                     namelen = VNAMELEN(dentry);
        xfs_trans_t             *tp = NULL;
        int                     error = 0;
        xfs_bmap_free_t         free_list;
        xfs_fsblock_t           first_block;
        int                     cancel_flags;
        int                     committed;
-       int                     dm_di_mode = 0;
        int                     link_zero;
        uint                    resblks;
-       int                     namelen;
 
-       vn_trace_entry(dp, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(dp);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
 
-       namelen = VNAMELEN(dentry);
-
-       if (!xfs_get_dir_entry(dentry, &ip)) {
-               dm_di_mode = ip->i_d.di_mode;
-               IRELE(ip);
-       }
-
        if (DM_EVENT_ENABLED(dp, DM_EVENT_REMOVE)) {
-               error = XFS_SEND_NAMESP(mp, DM_EVENT_REMOVE, dir_vp,
+               error = XFS_SEND_NAMESP(mp, DM_EVENT_REMOVE, dp,
                                        DM_RIGHT_NULL, NULL, DM_RIGHT_NULL,
-                                       name, NULL, dm_di_mode, 0, 0);
+                                       name, NULL, ip->i_d.di_mode, 0, 0);
                if (error)
                        return error;
        }
 
-       /* From this point on, return through std_return */
-       ip = NULL;
-
        /*
         * We need to get a reference to ip before we get our log
         * reservation. The reason for this is that we cannot call
@@ -2356,17 +2306,10 @@ xfs_remove(
         * 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);
-       if (error) {
-               REMOVE_DEBUG_TRACE(__LINE__);
-               goto std_return;
-       }
-
-       dm_di_mode = ip->i_d.di_mode;
-
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       IHOLD(ip);
 
-       ITRACE(ip);
+       xfs_itrace_entry(ip);
+       xfs_itrace_ref(ip);
 
        error = XFS_QM_DQATTACH(mp, dp, 0);
        if (!error && dp != ip)
@@ -2481,14 +2424,6 @@ xfs_remove(
                goto std_return;
        }
 
-       /*
-        * Before we drop our extra reference to the inode, purge it
-        * from the refcache if it is there.  By waiting until afterwards
-        * to do the IRELE, we ensure that we won't go inactive in the
-        * xfs_refcache_purge_ip routine (although that would be OK).
-        */
-       xfs_refcache_purge_ip(ip);
-
        /*
         * If we are using filestreams, kill the stream association.
         * If the file is still open it may get a new one but that
@@ -2498,17 +2433,16 @@ xfs_remove(
        if (link_zero && xfs_inode_is_filestream(ip))
                xfs_filestream_deassociate(ip);
 
-       vn_trace_exit(ip, __FUNCTION__, (inst_t *)__return_address);
-
+       xfs_itrace_exit(ip);
        IRELE(ip);
 
 /*     Fall through to std_return with error = 0 */
  std_return:
        if (DM_EVENT_ENABLED(dp, DM_EVENT_POSTREMOVE)) {
                (void) XFS_SEND_NAMESP(mp, DM_EVENT_POSTREMOVE,
-                               dir_vp, DM_RIGHT_NULL,
+                               dp, DM_RIGHT_NULL,
                                NULL, DM_RIGHT_NULL,
-                               name, NULL, dm_di_mode, error, 0);
+                               name, NULL, ip->i_d.di_mode, error, 0);
        }
        return error;
 
@@ -2529,14 +2463,6 @@ xfs_remove(
        cancel_flags |= XFS_TRANS_ABORT;
        xfs_trans_cancel(tp, cancel_flags);
 
-       /*
-        * Before we drop our extra reference to the inode, purge it
-        * from the refcache if it is there.  By waiting until afterwards
-        * to do the IRELE, we ensure that we won't go inactive in the
-        * xfs_refcache_purge_ip routine (although that would be OK).
-        */
-       xfs_refcache_purge_ip(ip);
-
        IRELE(ip);
 
        goto std_return;
@@ -2545,12 +2471,10 @@ xfs_remove(
 int
 xfs_link(
        xfs_inode_t             *tdp,
-       bhv_vnode_t             *src_vp,
+       xfs_inode_t             *sip,
        bhv_vname_t             *dentry)
 {
-       bhv_vnode_t             *target_dir_vp = XFS_ITOV(tdp);
        xfs_mount_t             *mp = tdp->i_mount;
-       xfs_inode_t             *sip = xfs_vtoi(src_vp);
        xfs_trans_t             *tp;
        xfs_inode_t             *ips[2];
        int                     error;
@@ -2562,19 +2486,19 @@ xfs_link(
        char                    *target_name = VNAME(dentry);
        int                     target_namelen;
 
-       vn_trace_entry(tdp, __FUNCTION__, (inst_t *)__return_address);
-       vn_trace_entry(xfs_vtoi(src_vp), __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(tdp);
+       xfs_itrace_entry(sip);
 
        target_namelen = VNAMELEN(dentry);
-       ASSERT(!VN_ISDIR(src_vp));
+       ASSERT(!S_ISDIR(sip->i_d.di_mode));
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
 
        if (DM_EVENT_ENABLED(tdp, DM_EVENT_LINK)) {
                error = XFS_SEND_NAMESP(mp, DM_EVENT_LINK,
-                                       target_dir_vp, DM_RIGHT_NULL,
-                                       src_vp, DM_RIGHT_NULL,
+                                       tdp, DM_RIGHT_NULL,
+                                       sip, DM_RIGHT_NULL,
                                        target_name, NULL, 0, 0, 0);
                if (error)
                        return error;
@@ -2618,8 +2542,8 @@ xfs_link(
         * xfs_trans_cancel will both unlock the inodes and
         * decrement the associated ref counts.
         */
-       VN_HOLD(src_vp);
-       VN_HOLD(target_dir_vp);
+       IHOLD(sip);
+       IHOLD(tdp);
        xfs_trans_ijoin(tp, sip, XFS_ILOCK_EXCL);
        xfs_trans_ijoin(tp, tdp, XFS_ILOCK_EXCL);
 
@@ -2684,8 +2608,8 @@ xfs_link(
 std_return:
        if (DM_EVENT_ENABLED(sip, DM_EVENT_POSTLINK)) {
                (void) XFS_SEND_NAMESP(mp, DM_EVENT_POSTLINK,
-                               target_dir_vp, DM_RIGHT_NULL,
-                               src_vp, DM_RIGHT_NULL,
+                               tdp, DM_RIGHT_NULL,
+                               sip, DM_RIGHT_NULL,
                                target_name, NULL, 0, error, 0);
        }
        return error;
@@ -2705,15 +2629,13 @@ xfs_mkdir(
        xfs_inode_t             *dp,
        bhv_vname_t             *dentry,
        mode_t                  mode,
-       bhv_vnode_t             **vpp,
+       xfs_inode_t             **ipp,
        cred_t                  *credp)
 {
-       bhv_vnode_t             *dir_vp = XFS_ITOV(dp);
        char                    *dir_name = VNAME(dentry);
        int                     dir_namelen = VNAMELEN(dentry);
        xfs_mount_t             *mp = dp->i_mount;
        xfs_inode_t             *cdp;   /* inode of created dir */
-       bhv_vnode_t             *cvp;   /* vnode of created dir */
        xfs_trans_t             *tp;
        int                     cancel_flags;
        int                     error;
@@ -2734,7 +2656,7 @@ xfs_mkdir(
 
        if (DM_EVENT_ENABLED(dp, DM_EVENT_CREATE)) {
                error = XFS_SEND_NAMESP(mp, DM_EVENT_CREATE,
-                                       dir_vp, DM_RIGHT_NULL, NULL,
+                                       dp, DM_RIGHT_NULL, NULL,
                                        DM_RIGHT_NULL, dir_name, NULL,
                                        mode, 0, 0);
                if (error)
@@ -2744,7 +2666,7 @@ xfs_mkdir(
 
        /* Return through std_return after this point. */
 
-       vn_trace_entry(dp, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(dp);
 
        mp = dp->i_mount;
        udqp = gdqp = NULL;
@@ -2810,7 +2732,7 @@ xfs_mkdir(
                        goto error_return;
                goto abort_return;
        }
-       ITRACE(cdp);
+       xfs_itrace_ref(cdp);
 
        /*
         * Now we add the directory inode to the transaction.
@@ -2820,7 +2742,7 @@ xfs_mkdir(
         * from here on will result in the transaction cancel
         * unlocking dp so don't do it explicitly in the error path.
         */
-       VN_HOLD(dir_vp);
+       IHOLD(dp);
        xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
        unlock_dp_on_error = B_FALSE;
 
@@ -2851,11 +2773,9 @@ xfs_mkdir(
        if (error)
                goto error2;
 
-       cvp = XFS_ITOV(cdp);
-
        created = B_TRUE;
 
-       *vpp = cvp;
+       *ipp = cdp;
        IHOLD(cdp);
 
        /*
@@ -2892,8 +2812,8 @@ 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,
-                                       dir_vp, DM_RIGHT_NULL,
-                                       created ? XFS_ITOV(cdp):NULL,
+                                       dp, DM_RIGHT_NULL,
+                                       created ? cdp : NULL,
                                        DM_RIGHT_NULL,
                                        dir_name, NULL,
                                        mode, error, 0);
@@ -2925,40 +2845,30 @@ xfs_rmdir(
        char                    *name = VNAME(dentry);
        int                     namelen = VNAMELEN(dentry);
        xfs_mount_t             *mp = dp->i_mount;
-       xfs_inode_t             *cdp;   /* child directory */
+       xfs_inode_t             *cdp = VNAME_TO_INODE(dentry);
        xfs_trans_t             *tp;
        int                     error;
        xfs_bmap_free_t         free_list;
        xfs_fsblock_t           first_block;
        int                     cancel_flags;
        int                     committed;
-       int                     dm_di_mode = S_IFDIR;
        int                     last_cdp_link;
        uint                    resblks;
 
-       vn_trace_entry(dp, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(dp);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
 
-       if (!xfs_get_dir_entry(dentry, &cdp)) {
-               dm_di_mode = cdp->i_d.di_mode;
-               IRELE(cdp);
-       }
-
        if (DM_EVENT_ENABLED(dp, DM_EVENT_REMOVE)) {
                error = XFS_SEND_NAMESP(mp, DM_EVENT_REMOVE,
-                                       dir_vp, DM_RIGHT_NULL,
+                                       dp, DM_RIGHT_NULL,
                                        NULL, DM_RIGHT_NULL,
-                                       name, NULL, dm_di_mode, 0, 0);
+                                       name, NULL, cdp->i_d.di_mode, 0, 0);
                if (error)
                        return XFS_ERROR(error);
        }
 
-       /* Return through std_return after this point. */
-
-       cdp = NULL;
-
        /*
         * We need to get a reference to cdp before we get our log
         * reservation.  The reason for this is that we cannot call
@@ -2971,13 +2881,7 @@ xfs_rmdir(
         * 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);
-       if (error) {
-               REMOVE_DEBUG_TRACE(__LINE__);
-               goto std_return;
-       }
-       mp = dp->i_mount;
-       dm_di_mode = cdp->i_d.di_mode;
+       IHOLD(cdp);
 
        /*
         * Get the dquots for the inodes.
@@ -3041,7 +2945,7 @@ xfs_rmdir(
                VN_HOLD(dir_vp);
        }
 
-       ITRACE(cdp);
+       xfs_itrace_ref(cdp);
        xfs_trans_ijoin(tp, cdp, XFS_ILOCK_EXCL);
 
        ASSERT(cdp->i_d.di_nlink >= 2);
@@ -3132,9 +3036,9 @@ xfs_rmdir(
  std_return:
        if (DM_EVENT_ENABLED(dp, DM_EVENT_POSTREMOVE)) {
                (void) XFS_SEND_NAMESP(mp, DM_EVENT_POSTREMOVE,
-                                       dir_vp, DM_RIGHT_NULL,
+                                       dp, DM_RIGHT_NULL,
                                        NULL, DM_RIGHT_NULL,
-                                       name, NULL, dm_di_mode,
+                                       name, NULL, cdp->i_d.di_mode,
                                        error, 0);
        }
        return error;
@@ -3155,10 +3059,9 @@ xfs_symlink(
        bhv_vname_t             *dentry,
        char                    *target_path,
        mode_t                  mode,
-       bhv_vnode_t             **vpp,
+       xfs_inode_t             **ipp,
        cred_t                  *credp)
 {
-       bhv_vnode_t             *dir_vp = XFS_ITOV(dp);
        xfs_mount_t             *mp = dp->i_mount;
        xfs_trans_t             *tp;
        xfs_inode_t             *ip;
@@ -3184,13 +3087,12 @@ xfs_symlink(
        char                    *link_name = VNAME(dentry);
        int                     link_namelen;
 
-       *vpp = NULL;
+       *ipp = NULL;
        error = 0;
        ip = NULL;
        tp = NULL;
 
-       vn_trace_entry(dp, __FUNCTION__, (inst_t *)__return_address);
-
+       xfs_itrace_entry(dp);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
@@ -3230,7 +3132,7 @@ xfs_symlink(
        }
 
        if (DM_EVENT_ENABLED(dp, DM_EVENT_SYMLINK)) {
-               error = XFS_SEND_NAMESP(mp, DM_EVENT_SYMLINK, dir_vp,
+               error = XFS_SEND_NAMESP(mp, DM_EVENT_SYMLINK, dp,
                                        DM_RIGHT_NULL, NULL, DM_RIGHT_NULL,
                                        link_name, target_path, 0, 0, 0);
                if (error)
@@ -3317,14 +3219,14 @@ xfs_symlink(
                        goto error_return;
                goto error1;
        }
-       ITRACE(ip);
+       xfs_itrace_ref(ip);
 
        /*
         * An error after we've joined dp to the transaction will result in the
         * transaction cancel unlocking dp so don't do it explicitly in the
         * error path.
         */
-       VN_HOLD(dir_vp);
+       IHOLD(dp);
        xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
        unlock_dp_on_error = B_FALSE;
 
@@ -3434,19 +3336,14 @@ xfs_symlink(
 std_return:
        if (DM_EVENT_ENABLED(dp, DM_EVENT_POSTSYMLINK)) {
                (void) XFS_SEND_NAMESP(mp, DM_EVENT_POSTSYMLINK,
-                                       dir_vp, DM_RIGHT_NULL,
-                                       error ? NULL : XFS_ITOV(ip),
+                                       dp, DM_RIGHT_NULL,
+                                       error ? NULL : ip,
                                        DM_RIGHT_NULL, link_name, target_path,
                                        0, error, 0);
        }
 
-       if (!error) {
-               bhv_vnode_t *vp;
-
-               ASSERT(ip);
-               vp = XFS_ITOV(ip);
-               *vpp = vp;
-       }
+       if (!error)
+               *ipp = ip;
        return error;
 
  error2:
@@ -3465,82 +3362,12 @@ std_return:
        goto std_return;
 }
 
-
-int
-xfs_fid2(
-       xfs_inode_t     *ip,
-       xfs_fid_t       *xfid)
-{
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
-
-       xfid->fid_len = sizeof(xfs_fid_t) - sizeof(xfid->fid_len);
-       xfid->fid_pad = 0;
-       /*
-        * use memcpy because the inode is a long long and there's no
-        * assurance that xfid->fid_ino is properly aligned.
-        */
-       memcpy(&xfid->fid_ino, &ip->i_ino, sizeof(xfid->fid_ino));
-       xfid->fid_gen = ip->i_d.di_gen;
-
-       return 0;
-}
-
-
-int
-xfs_rwlock(
-       xfs_inode_t     *ip,
-       bhv_vrwlock_t   locktype)
-{
-       if (S_ISDIR(ip->i_d.di_mode))
-               return 1;
-       if (locktype == VRWLOCK_WRITE) {
-               xfs_ilock(ip, XFS_IOLOCK_EXCL);
-       } else if (locktype == VRWLOCK_TRY_READ) {
-               return xfs_ilock_nowait(ip, XFS_IOLOCK_SHARED);
-       } else if (locktype == VRWLOCK_TRY_WRITE) {
-               return xfs_ilock_nowait(ip, XFS_IOLOCK_EXCL);
-       } else {
-               ASSERT((locktype == VRWLOCK_READ) ||
-                      (locktype == VRWLOCK_WRITE_DIRECT));
-               xfs_ilock(ip, XFS_IOLOCK_SHARED);
-       }
-
-       return 1;
-}
-
-
-void
-xfs_rwunlock(
-       xfs_inode_t     *ip,
-       bhv_vrwlock_t   locktype)
-{
-       if (S_ISDIR(ip->i_d.di_mode))
-               return;
-       if (locktype == VRWLOCK_WRITE) {
-               /*
-                * In the write case, we may have added a new entry to
-                * the reference cache.  This might store a pointer to
-                * an inode to be released in this inode.  If it is there,
-                * clear the pointer and release the inode after unlocking
-                * this one.
-                */
-               xfs_refcache_iunlock(ip, XFS_IOLOCK_EXCL);
-       } else {
-               ASSERT((locktype == VRWLOCK_READ) ||
-                      (locktype == VRWLOCK_WRITE_DIRECT));
-               xfs_iunlock(ip, XFS_IOLOCK_SHARED);
-       }
-       return;
-}
-
-
 int
 xfs_inode_flush(
        xfs_inode_t     *ip,
        int             flags)
 {
        xfs_mount_t     *mp = ip->i_mount;
-       xfs_inode_log_item_t *iip = ip->i_itemp;
        int             error = 0;
 
        if (XFS_FORCED_SHUTDOWN(mp))
@@ -3550,33 +3377,9 @@ xfs_inode_flush(
         * Bypass inodes which have already been cleaned by
         * the inode flush clustering code inside xfs_iflush
         */
-       if ((ip->i_update_core == 0) &&
-           ((iip == NULL) || !(iip->ili_format.ilf_fields & XFS_ILOG_ALL)))
+       if (xfs_inode_clean(ip))
                return 0;
 
-       if (flags & FLUSH_LOG) {
-               if (iip && iip->ili_last_lsn) {
-                       xlog_t          *log = mp->m_log;
-                       xfs_lsn_t       sync_lsn;
-                       int             s, log_flags = XFS_LOG_FORCE;
-
-                       s = GRANT_LOCK(log);
-                       sync_lsn = log->l_last_sync_lsn;
-                       GRANT_UNLOCK(log, s);
-
-                       if ((XFS_LSN_CMP(iip->ili_last_lsn, sync_lsn) > 0)) {
-                               if (flags & FLUSH_SYNC)
-                                       log_flags |= XFS_LOG_SYNC;
-                               error = xfs_log_force(mp, iip->ili_last_lsn, log_flags);
-                               if (error)
-                                       return error;
-                       }
-
-                       if (ip->i_update_core == 0)
-                               return 0;
-               }
-       }
-
        /*
         * We make this non-blocking if the inode is contended,
         * return EAGAIN to indicate to the caller that they
@@ -3584,30 +3387,22 @@ xfs_inode_flush(
         * blocking on inodes inside another operation right
         * now, they get caught later by xfs_sync.
         */
-       if (flags & FLUSH_INODE) {
-               int     flush_flags;
-
-               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 {
+       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;
                }
-
-               if (flags & FLUSH_SYNC)
-                       flush_flags = XFS_IFLUSH_SYNC;
-               else
-                       flush_flags = XFS_IFLUSH_ASYNC;
-
-               error = xfs_iflush(ip, flush_flags);
-               xfs_iunlock(ip, XFS_ILOCK_SHARED);
+       } 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;
 }
 
@@ -3637,8 +3432,8 @@ xfs_set_dmattrs(
        xfs_ilock(ip, XFS_ILOCK_EXCL);
        xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
 
-       ip->i_iocore.io_dmevmask = ip->i_d.di_dmevmask = evmask;
-       ip->i_iocore.io_dmstate  = ip->i_d.di_dmstate  = state;
+       ip->i_d.di_dmevmask = evmask;
+       ip->i_d.di_dmstate  = state;
 
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
        IHOLD(ip);
@@ -3653,7 +3448,7 @@ xfs_reclaim(
 {
        bhv_vnode_t     *vp = XFS_ITOV(ip);
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        ASSERT(!VN_MAPPED(vp));
 
@@ -3750,12 +3545,12 @@ xfs_finish_reclaim(
         * We get the flush lock regardless, though, just to make sure
         * we don't free it while it is being flushed.
         */
-       if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
-               if (!locked) {
-                       xfs_ilock(ip, XFS_ILOCK_EXCL);
-                       xfs_iflock(ip);
-               }
+       if (!locked) {
+               xfs_ilock(ip, XFS_ILOCK_EXCL);
+               xfs_iflock(ip);
+       }
 
+       if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
                if (ip->i_update_core ||
                    ((ip->i_itemp != NULL) &&
                     (ip->i_itemp->ili_format.ilf_fields != 0))) {
@@ -3775,17 +3570,11 @@ xfs_finish_reclaim(
                ASSERT(ip->i_update_core == 0);
                ASSERT(ip->i_itemp == NULL ||
                       ip->i_itemp->ili_format.ilf_fields == 0);
-               xfs_iunlock(ip, XFS_ILOCK_EXCL);
-       } else if (locked) {
-               /*
-                * We are not interested in doing an iflush if we're
-                * in the process of shutting down the filesystem forcibly.
-                * So, just reclaim the inode.
-                */
-               xfs_ifunlock(ip);
-               xfs_iunlock(ip, XFS_ILOCK_EXCL);
        }
 
+       xfs_ifunlock(ip);
+       xfs_iunlock(ip, XFS_ILOCK_EXCL);
+
  reclaim:
        xfs_ireclaim(ip);
        return 0;
@@ -3871,7 +3660,7 @@ xfs_alloc_file_space(
        int                     committed;
        int                     error;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
@@ -3901,9 +3690,8 @@ xfs_alloc_file_space(
                end_dmi_offset = offset+len;
                if (end_dmi_offset > ip->i_size)
                        end_dmi_offset = ip->i_size;
-               error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, XFS_ITOV(ip),
-                       offset, end_dmi_offset - offset,
-                       0, NULL);
+               error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, ip, offset,
+                                     end_dmi_offset - offset, 0, NULL);
                if (error)
                        return error;
        }
@@ -3976,7 +3764,7 @@ retry:
                 * Issue the xfs_bmapi() call to allocate the blocks
                 */
                XFS_BMAP_INIT(&free_list, &firstfsb);
-               error = XFS_BMAPI(mp, tp, &ip->i_iocore, startoffset_fsb,
+               error = xfs_bmapi(tp, ip, startoffset_fsb,
                                  allocatesize_fsb, bmapi_flag,
                                  &firstfsb, 0, imapp, &nimaps,
                                  &free_list, NULL);
@@ -4012,8 +3800,8 @@ dmapi_enospc_check:
        if (error == ENOSPC && (attr_flags & ATTR_DMI) == 0 &&
            DM_EVENT_ENABLED(ip, DM_EVENT_NOSPACE)) {
                error = XFS_SEND_NAMESP(mp, DM_EVENT_NOSPACE,
-                               XFS_ITOV(ip), DM_RIGHT_NULL,
-                               XFS_ITOV(ip), DM_RIGHT_NULL,
+                               ip, DM_RIGHT_NULL,
+                               ip, DM_RIGHT_NULL,
                                NULL, NULL, 0, 0, 0); /* Delay flag intentionally unused */
                if (error == 0)
                        goto retry;     /* Maybe DMAPI app. has made space */
@@ -4052,13 +3840,13 @@ xfs_zero_remaining_bytes(
        int                     error = 0;
 
        bp = xfs_buf_get_noaddr(mp->m_sb.sb_blocksize,
-                               ip->i_d.di_flags & XFS_DIFLAG_REALTIME ?
+                               XFS_IS_REALTIME_INODE(ip) ?
                                mp->m_rtdev_targp : mp->m_ddev_targp);
 
        for (offset = startoff; offset <= endoff; offset = lastoffset + 1) {
                offset_fsb = XFS_B_TO_FSBT(mp, offset);
                nimap = 1;
-               error = XFS_BMAPI(mp, NULL, &ip->i_iocore, offset_fsb, 1, 0,
+               error = xfs_bmapi(NULL, ip, offset_fsb, 1, 0,
                        NULL, 0, &imap, &nimap, NULL, NULL);
                if (error || nimap < 1)
                        break;
@@ -4141,7 +3929,7 @@ xfs_free_file_space(
        vp = XFS_ITOV(ip);
        mp = ip->i_mount;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
        if ((error = XFS_QM_DQATTACH(mp, ip, 0)))
                return error;
@@ -4149,7 +3937,7 @@ xfs_free_file_space(
        error = 0;
        if (len <= 0)   /* if nothing being freed */
                return error;
-       rt = (ip->i_d.di_flags & XFS_DIFLAG_REALTIME);
+       rt = XFS_IS_REALTIME_INODE(ip);
        startoffset_fsb = XFS_B_TO_FSB(mp, offset);
        end_dmi_offset = offset + len;
        endoffset_fsb = XFS_B_TO_FSBT(mp, end_dmi_offset);
@@ -4158,7 +3946,7 @@ xfs_free_file_space(
            DM_EVENT_ENABLED(ip, DM_EVENT_WRITE)) {
                if (end_dmi_offset > ip->i_size)
                        end_dmi_offset = ip->i_size;
-               error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, vp,
+               error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, ip,
                                offset, end_dmi_offset - offset,
                                AT_DELAY_FLAG(attr_flags), NULL);
                if (error)
@@ -4172,15 +3960,12 @@ xfs_free_file_space(
                vn_iowait(ip);  /* wait for the completion of any pending DIOs */
        }
 
-       rounding = max_t(uint, 1 << mp->m_sb.sb_blocklog, NBPP);
+       rounding = max_t(uint, 1 << mp->m_sb.sb_blocklog, PAGE_CACHE_SIZE);
        ioffset = offset & ~(rounding - 1);
 
        if (VN_CACHED(vp) != 0) {
-               xfs_inval_cached_trace(&ip->i_iocore, ioffset, -1,
-                               ctooff(offtoct(ioffset)), -1);
-               error = xfs_flushinval_pages(ip,
-                               ctooff(offtoct(ioffset)),
-                               -1, FI_REMAPF_LOCKED);
+               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;
        }
@@ -4191,9 +3976,9 @@ xfs_free_file_space(
         * actually need to zero the extent edges.  Otherwise xfs_bunmapi
         * will take care of it for us.
         */
-       if (rt && !XFS_SB_VERSION_HASEXTFLGBIT(&mp->m_sb)) {
+       if (rt && !xfs_sb_version_hasextflgbit(&mp->m_sb)) {
                nimap = 1;
-               error = XFS_BMAPI(mp, NULL, &ip->i_iocore, startoffset_fsb,
+               error = xfs_bmapi(NULL, ip, startoffset_fsb,
                        1, 0, NULL, 0, &imap, &nimap, NULL, NULL);
                if (error)
                        goto out_unlock_iolock;
@@ -4208,7 +3993,7 @@ xfs_free_file_space(
                                startoffset_fsb += mp->m_sb.sb_rextsize - mod;
                }
                nimap = 1;
-               error = XFS_BMAPI(mp, NULL, &ip->i_iocore, endoffset_fsb - 1,
+               error = xfs_bmapi(NULL, ip, endoffset_fsb - 1,
                        1, 0, NULL, 0, &imap, &nimap, NULL, NULL);
                if (error)
                        goto out_unlock_iolock;
@@ -4284,7 +4069,7 @@ xfs_free_file_space(
                 * issue the bunmapi() call to free the blocks
                 */
                XFS_BMAP_INIT(&free_list, &firstfsb);
-               error = XFS_BUNMAPI(mp, tp, &ip->i_iocore, startoffset_fsb,
+               error = xfs_bunmapi(tp, ip, startoffset_fsb,
                                  endoffset_fsb - startoffset_fsb,
                                  0, 2, &firstfsb, &free_list, NULL, &done);
                if (error) {
@@ -4347,23 +4132,11 @@ xfs_change_file_space(
        xfs_trans_t     *tp;
        bhv_vattr_t     va;
 
-       vn_trace_entry(ip, __FUNCTION__, (inst_t *)__return_address);
+       xfs_itrace_entry(ip);
 
-       /*
-        * must be a regular file and have write permission
-        */
        if (!S_ISREG(ip->i_d.di_mode))
                return XFS_ERROR(EINVAL);
 
-       xfs_ilock(ip, XFS_ILOCK_SHARED);
-
-       if ((error = xfs_iaccess(ip, S_IWUSR, credp))) {
-               xfs_iunlock(ip, XFS_ILOCK_SHARED);
-               return error;
-       }
-
-       xfs_iunlock(ip, XFS_ILOCK_SHARED);
-
        switch (bf->l_whence) {
        case 0: /*SEEK_SET*/
                break;