]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - fs/xfs/xfs_vnodeops.c
Merge branches 'metronomefb', 'pxa-cm2xx', 'pxa-gumstix', 'pxa-misc', 'pxa-mitac...
[linux-2.6-omap-h63xx.git] / fs / xfs / xfs_vnodeops.c
index ed399523b7824325e088587cc30c63d77715b466..aa238c8fbd7ae605e9f316969bb3012ee4c32f3c 100644 (file)
@@ -75,19 +75,17 @@ xfs_open(
        return 0;
 }
 
-/*
- * xfs_setattr
- */
 int
 xfs_setattr(
-       xfs_inode_t             *ip,
-       bhv_vattr_t             *vap,
+       struct xfs_inode        *ip,
+       struct iattr            *iattr,
        int                     flags,
        cred_t                  *credp)
 {
        xfs_mount_t             *mp = ip->i_mount;
+       struct inode            *inode = VFS_I(ip);
+       int                     mask = iattr->ia_valid;
        xfs_trans_t             *tp;
-       int                     mask;
        int                     code;
        uint                    lock_flags;
        uint                    commit_flags=0;
@@ -103,30 +101,9 @@ xfs_setattr(
        if (mp->m_flags & XFS_MOUNT_RDONLY)
                return XFS_ERROR(EROFS);
 
-       /*
-        * Cannot set certain attributes.
-        */
-       mask = vap->va_mask;
-       if (mask & XFS_AT_NOSET) {
-               return XFS_ERROR(EINVAL);
-       }
-
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
 
-       /*
-        * Timestamps do not need to be logged and hence do not
-        * need to be done within a transaction.
-        */
-       if (mask & XFS_AT_UPDTIMES) {
-               ASSERT((mask & ~XFS_AT_UPDTIMES) == 0);
-               timeflags = ((mask & XFS_AT_UPDATIME) ? XFS_ICHGTIME_ACC : 0) |
-                           ((mask & XFS_AT_UPDCTIME) ? XFS_ICHGTIME_CHG : 0) |
-                           ((mask & XFS_AT_UPDMTIME) ? XFS_ICHGTIME_MOD : 0);
-               xfs_ichgtime(ip, timeflags);
-               return 0;
-       }
-
        olddquot1 = olddquot2 = NULL;
        udqp = gdqp = NULL;
 
@@ -138,17 +115,17 @@ xfs_setattr(
         * If the IDs do change before we take the ilock, we're covered
         * because the i_*dquot fields will get updated anyway.
         */
-       if (XFS_IS_QUOTA_ON(mp) && (mask & (XFS_AT_UID|XFS_AT_GID))) {
+       if (XFS_IS_QUOTA_ON(mp) && (mask & (ATTR_UID|ATTR_GID))) {
                uint    qflags = 0;
 
-               if ((mask & XFS_AT_UID) && XFS_IS_UQUOTA_ON(mp)) {
-                       uid = vap->va_uid;
+               if ((mask & ATTR_UID) && XFS_IS_UQUOTA_ON(mp)) {
+                       uid = iattr->ia_uid;
                        qflags |= XFS_QMOPT_UQUOTA;
                } else {
                        uid = ip->i_d.di_uid;
                }
-               if ((mask & XFS_AT_GID) && XFS_IS_GQUOTA_ON(mp)) {
-                       gid = vap->va_gid;
+               if ((mask & ATTR_GID) && XFS_IS_GQUOTA_ON(mp)) {
+                       gid = iattr->ia_gid;
                        qflags |= XFS_QMOPT_GQUOTA;
                }  else {
                        gid = ip->i_d.di_gid;
@@ -173,10 +150,10 @@ xfs_setattr(
         */
        tp = NULL;
        lock_flags = XFS_ILOCK_EXCL;
-       if (flags & ATTR_NOLOCK)
+       if (flags & XFS_ATTR_NOLOCK)
                need_iolock = 0;
-       if (!(mask & XFS_AT_SIZE)) {
-               if ((mask != (XFS_AT_CTIME|XFS_AT_ATIME|XFS_AT_MTIME)) ||
+       if (!(mask & ATTR_SIZE)) {
+               if ((mask != (ATTR_CTIME|ATTR_ATIME|ATTR_MTIME)) ||
                    (mp->m_flags & XFS_MOUNT_WSYNC)) {
                        tp = xfs_trans_alloc(mp, XFS_TRANS_SETATTR_NOT_SIZE);
                        commit_flags = 0;
@@ -189,10 +166,10 @@ xfs_setattr(
                }
        } else {
                if (DM_EVENT_ENABLED(ip, DM_EVENT_TRUNCATE) &&
-                   !(flags & ATTR_DMI)) {
+                   !(flags & XFS_ATTR_DMI)) {
                        int dmflags = AT_DELAY_FLAG(flags) | DM_SEM_FLAG_WR;
                        code = XFS_SEND_DATA(mp, DM_EVENT_TRUNCATE, ip,
-                               vap->va_size, 0, dmflags, NULL);
+                               iattr->ia_size, 0, dmflags, NULL);
                        if (code) {
                                lock_flags = 0;
                                goto error_return;
@@ -205,14 +182,14 @@ xfs_setattr(
        xfs_ilock(ip, lock_flags);
 
        /* boolean: are we the file owner? */
-       file_owner = (current_fsuid(credp) == ip->i_d.di_uid);
+       file_owner = (current_fsuid() == ip->i_d.di_uid);
 
        /*
         * Change various properties of a file.
         * Only the owner or users with CAP_FOWNER
         * capability may do these things.
         */
-       if (mask & (XFS_AT_MODE|XFS_AT_UID|XFS_AT_GID)) {
+       if (mask & (ATTR_MODE|ATTR_UID|ATTR_GID)) {
                /*
                 * CAP_FOWNER overrides the following restrictions:
                 *
@@ -236,21 +213,21 @@ xfs_setattr(
                 * IDs of the calling process shall match the group owner of
                 * the file when setting the set-group-ID bit on that file
                 */
-               if (mask & XFS_AT_MODE) {
+               if (mask & ATTR_MODE) {
                        mode_t m = 0;
 
-                       if ((vap->va_mode & S_ISUID) && !file_owner)
+                       if ((iattr->ia_mode & S_ISUID) && !file_owner)
                                m |= S_ISUID;
-                       if ((vap->va_mode & S_ISGID) &&
+                       if ((iattr->ia_mode & S_ISGID) &&
                            !in_group_p((gid_t)ip->i_d.di_gid))
                                m |= S_ISGID;
 #if 0
                        /* Linux allows this, Irix doesn't. */
-                       if ((vap->va_mode & S_ISVTX) && !S_ISDIR(ip->i_d.di_mode))
+                       if ((iattr->ia_mode & S_ISVTX) && !S_ISDIR(ip->i_d.di_mode))
                                m |= S_ISVTX;
 #endif
                        if (m && !capable(CAP_FSETID))
-                               vap->va_mode &= ~m;
+                               iattr->ia_mode &= ~m;
                }
        }
 
@@ -261,7 +238,7 @@ xfs_setattr(
         * and can change the group id only to a group of which he
         * or she is a member.
         */
-       if (mask & (XFS_AT_UID|XFS_AT_GID)) {
+       if (mask & (ATTR_UID|ATTR_GID)) {
                /*
                 * These IDs could have changed since we last looked at them.
                 * But, we're assured that if the ownership did change
@@ -270,8 +247,8 @@ xfs_setattr(
                 */
                iuid = ip->i_d.di_uid;
                igid = ip->i_d.di_gid;
-               gid = (mask & XFS_AT_GID) ? vap->va_gid : igid;
-               uid = (mask & XFS_AT_UID) ? vap->va_uid : iuid;
+               gid = (mask & ATTR_GID) ? iattr->ia_gid : igid;
+               uid = (mask & ATTR_UID) ? iattr->ia_uid : iuid;
 
                /*
                 * CAP_CHOWN overrides the following restrictions:
@@ -308,13 +285,13 @@ xfs_setattr(
        /*
         * Truncate file.  Must have write permission and not be a directory.
         */
-       if (mask & XFS_AT_SIZE) {
+       if (mask & ATTR_SIZE) {
                /* Short circuit the truncate case for zero length files */
-               if ((vap->va_size == 0) &&
-                  (ip->i_size == 0) && (ip->i_d.di_nextents == 0)) {
+               if (iattr->ia_size == 0 &&
+                   ip->i_size == 0 && ip->i_d.di_nextents == 0) {
                        xfs_iunlock(ip, XFS_ILOCK_EXCL);
                        lock_flags &= ~XFS_ILOCK_EXCL;
-                       if (mask & XFS_AT_CTIME)
+                       if (mask & ATTR_CTIME)
                                xfs_ichgtime(ip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
                        code = 0;
                        goto error_return;
@@ -337,9 +314,9 @@ xfs_setattr(
        /*
         * Change file access or modified times.
         */
-       if (mask & (XFS_AT_ATIME|XFS_AT_MTIME)) {
+       if (mask & (ATTR_ATIME|ATTR_MTIME)) {
                if (!file_owner) {
-                       if ((flags & ATTR_UTIME) &&
+                       if ((mask & (ATTR_MTIME_SET|ATTR_ATIME_SET)) &&
                            !capable(CAP_FOWNER)) {
                                code = XFS_ERROR(EPERM);
                                goto error_return;
@@ -349,23 +326,22 @@ xfs_setattr(
 
        /*
         * Now we can make the changes.  Before we join the inode
-        * to the transaction, if XFS_AT_SIZE is set then take care of
+        * to the transaction, if ATTR_SIZE is set then take care of
         * the part of the truncation that must be done without the
         * inode lock.  This needs to be done before joining the inode
         * to the transaction, because the inode cannot be unlocked
         * once it is a part of the transaction.
         */
-       if (mask & XFS_AT_SIZE) {
+       if (mask & ATTR_SIZE) {
                code = 0;
-               if ((vap->va_size > ip->i_size) &&
-                   (flags & ATTR_NOSIZETOK) == 0) {
+               if (iattr->ia_size > ip->i_size) {
                        /*
                         * Do the first part of growing a file: zero any data
                         * in the last block that is beyond the old EOF.  We
                         * need to do this before the inode is joined to the
                         * transaction to modify the i_size.
                         */
-                       code = xfs_zero_eof(ip, vap->va_size, ip->i_size);
+                       code = xfs_zero_eof(ip, iattr->ia_size, ip->i_size);
                }
                xfs_iunlock(ip, XFS_ILOCK_EXCL);
 
@@ -382,10 +358,10 @@ xfs_setattr(
                 * not within the range we care about here.
                 */
                if (!code &&
-                   (ip->i_size != ip->i_d.di_size) &&
-                   (vap->va_size > ip->i_d.di_size)) {
+                   ip->i_size != ip->i_d.di_size &&
+                   iattr->ia_size > ip->i_d.di_size) {
                        code = xfs_flush_pages(ip,
-                                       ip->i_d.di_size, vap->va_size,
+                                       ip->i_d.di_size, iattr->ia_size,
                                        XFS_B_ASYNC, FI_NONE);
                }
 
@@ -393,7 +369,7 @@ xfs_setattr(
                vn_iowait(ip);
 
                if (!code)
-                       code = xfs_itruncate_data(ip, vap->va_size);
+                       code = xfs_itruncate_data(ip, iattr->ia_size);
                if (code) {
                        ASSERT(tp == NULL);
                        lock_flags &= ~XFS_ILOCK_EXCL;
@@ -422,31 +398,30 @@ xfs_setattr(
        /*
         * Truncate file.  Must have write permission and not be a directory.
         */
-       if (mask & XFS_AT_SIZE) {
+       if (mask & ATTR_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))
+               if (iattr->ia_size != ip->i_size || (mask & ATTR_CTIME))
                        timeflags |= XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG;
 
-               if (vap->va_size > ip->i_size) {
-                       ip->i_d.di_size = vap->va_size;
-                       ip->i_size = vap->va_size;
-                       if (!(flags & ATTR_DMI))
+               if (iattr->ia_size > ip->i_size) {
+                       ip->i_d.di_size = iattr->ia_size;
+                       ip->i_size = iattr->ia_size;
+                       if (!(flags & XFS_ATTR_DMI))
                                xfs_ichgtime(ip, XFS_ICHGTIME_CHG);
                        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
-               } else if ((vap->va_size <= ip->i_size) ||
-                          ((vap->va_size == 0) && ip->i_d.di_nextents)) {
+               } else if (iattr->ia_size <= ip->i_size ||
+                          (iattr->ia_size == 0 && ip->i_d.di_nextents)) {
                        /*
                         * signal a sync transaction unless
                         * we're truncating an already unlinked
                         * file on a wsync filesystem
                         */
-                       code = xfs_itruncate_finish(&tp, ip,
-                                           (xfs_fsize_t)vap->va_size,
+                       code = xfs_itruncate_finish(&tp, ip, iattr->ia_size,
                                            XFS_DATA_FORK,
                                            ((ip->i_d.di_nlink != 0 ||
                                              !(mp->m_flags & XFS_MOUNT_WSYNC))
@@ -468,9 +443,12 @@ xfs_setattr(
        /*
         * Change file access modes.
         */
-       if (mask & XFS_AT_MODE) {
+       if (mask & ATTR_MODE) {
                ip->i_d.di_mode &= S_IFMT;
-               ip->i_d.di_mode |= vap->va_mode & ~S_IFMT;
+               ip->i_d.di_mode |= iattr->ia_mode & ~S_IFMT;
+
+               inode->i_mode &= S_IFMT;
+               inode->i_mode |= iattr->ia_mode & ~S_IFMT;
 
                xfs_trans_log_inode (tp, ip, XFS_ILOG_CORE);
                timeflags |= XFS_ICHGTIME_CHG;
@@ -483,7 +461,7 @@ xfs_setattr(
         * and can change the group id only to a group of which he
         * or she is a member.
         */
-       if (mask & (XFS_AT_UID|XFS_AT_GID)) {
+       if (mask & (ATTR_UID|ATTR_GID)) {
                /*
                 * CAP_FSETID overrides the following restrictions:
                 *
@@ -501,22 +479,24 @@ xfs_setattr(
                 */
                if (iuid != uid) {
                        if (XFS_IS_UQUOTA_ON(mp)) {
-                               ASSERT(mask & XFS_AT_UID);
+                               ASSERT(mask & ATTR_UID);
                                ASSERT(udqp);
                                olddquot1 = XFS_QM_DQVOPCHOWN(mp, 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)) {
                                ASSERT(!XFS_IS_PQUOTA_ON(mp));
-                               ASSERT(mask & XFS_AT_GID);
+                               ASSERT(mask & ATTR_GID);
                                ASSERT(gdqp);
                                olddquot2 = XFS_QM_DQVOPCHOWN(mp, tp, ip,
                                                        &ip->i_gdquot, gdqp);
                        }
                        ip->i_d.di_gid = gid;
+                       inode->i_gid = gid;
                }
 
                xfs_trans_log_inode (tp, ip, XFS_ILOG_CORE);
@@ -527,31 +507,33 @@ xfs_setattr(
        /*
         * Change file access or modified times.
         */
-       if (mask & (XFS_AT_ATIME|XFS_AT_MTIME)) {
-               if (mask & XFS_AT_ATIME) {
-                       ip->i_d.di_atime.t_sec = vap->va_atime.tv_sec;
-                       ip->i_d.di_atime.t_nsec = vap->va_atime.tv_nsec;
+       if (mask & (ATTR_ATIME|ATTR_MTIME)) {
+               if (mask & ATTR_ATIME) {
+                       inode->i_atime = iattr->ia_atime;
+                       ip->i_d.di_atime.t_sec = iattr->ia_atime.tv_sec;
+                       ip->i_d.di_atime.t_nsec = iattr->ia_atime.tv_nsec;
                        ip->i_update_core = 1;
-                       timeflags &= ~XFS_ICHGTIME_ACC;
                }
-               if (mask & XFS_AT_MTIME) {
-                       ip->i_d.di_mtime.t_sec = vap->va_mtime.tv_sec;
-                       ip->i_d.di_mtime.t_nsec = vap->va_mtime.tv_nsec;
+               if (mask & ATTR_MTIME) {
+                       inode->i_mtime = iattr->ia_mtime;
+                       ip->i_d.di_mtime.t_sec = iattr->ia_mtime.tv_sec;
+                       ip->i_d.di_mtime.t_nsec = iattr->ia_mtime.tv_nsec;
                        timeflags &= ~XFS_ICHGTIME_MOD;
                        timeflags |= XFS_ICHGTIME_CHG;
                }
-               if (tp && (flags & ATTR_UTIME))
+               if (tp && (mask & (ATTR_MTIME_SET|ATTR_ATIME_SET)))
                        xfs_trans_log_inode (tp, ip, XFS_ILOG_CORE);
        }
 
        /*
-        * Change file inode change time only if XFS_AT_CTIME set
+        * Change file inode change time only if ATTR_CTIME set
         * AND we have been called by a DMI function.
         */
 
-       if ( (flags & ATTR_DMI) && (mask & XFS_AT_CTIME) ) {
-               ip->i_d.di_ctime.t_sec = vap->va_ctime.tv_sec;
-               ip->i_d.di_ctime.t_nsec = vap->va_ctime.tv_nsec;
+       if ((flags & XFS_ATTR_DMI) && (mask & ATTR_CTIME)) {
+               inode->i_ctime = iattr->ia_ctime;
+               ip->i_d.di_ctime.t_sec = iattr->ia_ctime.tv_sec;
+               ip->i_d.di_ctime.t_nsec = iattr->ia_ctime.tv_nsec;
                ip->i_update_core = 1;
                timeflags &= ~XFS_ICHGTIME_CHG;
        }
@@ -560,7 +542,7 @@ xfs_setattr(
         * Send out timestamp changes that need to be set to the
         * current time.  Not done when called by a DMI function.
         */
-       if (timeflags && !(flags & ATTR_DMI))
+       if (timeflags && !(flags & XFS_ATTR_DMI))
                xfs_ichgtime(ip, timeflags);
 
        XFS_STATS_INC(xs_ig_attrchg);
@@ -598,7 +580,7 @@ xfs_setattr(
        }
 
        if (DM_EVENT_ENABLED(ip, DM_EVENT_ATTRIBUTE) &&
-           !(flags & ATTR_DMI)) {
+           !(flags & XFS_ATTR_DMI)) {
                (void) XFS_SEND_NAMESP(mp, DM_EVENT_ATTRIBUTE, ip, DM_RIGHT_NULL,
                                        NULL, DM_RIGHT_NULL, NULL, NULL,
                                        0, 0, AT_DELAY_FLAG(flags));
@@ -731,7 +713,7 @@ xfs_fsync(
                return XFS_ERROR(EIO);
 
        /* capture size updates in I/O completion before writing the inode. */
-       error = filemap_fdatawait(vn_to_inode(XFS_ITOV(ip))->i_mapping);
+       error = filemap_fdatawait(VFS_I(ip)->i_mapping);
        if (error)
                return XFS_ERROR(error);
 
@@ -1177,7 +1159,6 @@ int
 xfs_release(
        xfs_inode_t     *ip)
 {
-       bhv_vnode_t     *vp = XFS_ITOV(ip);
        xfs_mount_t     *mp = ip->i_mount;
        int             error;
 
@@ -1212,13 +1193,13 @@ xfs_release(
                 * be exposed to that problem.
                 */
                truncated = xfs_iflags_test_and_clear(ip, XFS_ITRUNCATED);
-               if (truncated && VN_DIRTY(vp) && ip->i_delayed_blks > 0)
+               if (truncated && VN_DIRTY(VFS_I(ip)) && ip->i_delayed_blks > 0)
                        xfs_flush_pages(ip, 0, -1, XFS_B_ASYNC, FI_NONE);
        }
 
        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 ||
+                    ((ip->i_size > 0) || (VN_CACHED(VFS_I(ip)) > 0 ||
                       ip->i_delayed_blks > 0)) &&
                     (ip->i_df.if_flags & XFS_IFEXTENTS))  &&
                    (!(ip->i_d.di_flags &
@@ -1244,7 +1225,6 @@ int
 xfs_inactive(
        xfs_inode_t     *ip)
 {
-       bhv_vnode_t     *vp = XFS_ITOV(ip);
        xfs_bmap_free_t free_list;
        xfs_fsblock_t   first_block;
        int             committed;
@@ -1259,7 +1239,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(vp)) {
+       if (ip->i_d.di_mode == 0 || VN_BAD(VFS_I(ip))) {
                ASSERT(ip->i_df.if_real_bytes == 0);
                ASSERT(ip->i_df.if_broot_bytes == 0);
                return VN_INACTIVE_CACHE;
@@ -1289,7 +1269,7 @@ xfs_inactive(
 
        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 ||
+                     ((ip->i_size > 0) || (VN_CACHED(VFS_I(ip)) > 0 ||
                        ip->i_delayed_blks > 0)) &&
                      (ip->i_df.if_flags & XFS_IFEXTENTS) &&
                     (!(ip->i_d.di_flags &
@@ -1553,7 +1533,7 @@ xfs_create(
         * Make sure that we have allocated dquot(s) on disk.
         */
        error = XFS_QM_DQVOPALLOC(mp, dp,
-                       current_fsuid(credp), current_fsgid(credp), prid,
+                       current_fsuid(), current_fsgid(), prid,
                        XFS_QMOPT_QUOTALL|XFS_QMOPT_INHERIT, &udqp, &gdqp);
        if (error)
                goto std_return;
@@ -1724,111 +1704,6 @@ std_return:
        goto std_return;
 }
 
-#ifdef DEBUG
-/*
- * Some counters to see if (and how often) we are hitting some deadlock
- * prevention code paths.
- */
-
-int xfs_rm_locks;
-int xfs_rm_lock_delays;
-int xfs_rm_attempts;
-#endif
-
-/*
- * The following routine will lock the inodes associated with the
- * directory and the named entry in the directory. The locks are
- * acquired in increasing inode number.
- *
- * If the entry is "..", then only the directory is locked. The
- * vnode ref count will still include that from the .. entry in
- * this case.
- *
- * There is a deadlock we need to worry about. If the locked directory is
- * in the AIL, it might be blocking up the log. The next inode we lock
- * could be already locked by another thread waiting for log space (e.g
- * a permanent log reservation with a long running transaction (see
- * xfs_itruncate_finish)). To solve this, we must check if the directory
- * is in the ail and use lock_nowait. If we can't lock, we need to
- * drop the inode lock on the directory and try again. xfs_iunlock will
- * potentially push the tail if we were holding up the log.
- */
-STATIC int
-xfs_lock_dir_and_entry(
-       xfs_inode_t     *dp,
-       xfs_inode_t     *ip)    /* inode of entry 'name' */
-{
-       int             attempts;
-       xfs_ino_t       e_inum;
-       xfs_inode_t     *ips[2];
-       xfs_log_item_t  *lp;
-
-#ifdef DEBUG
-       xfs_rm_locks++;
-#endif
-       attempts = 0;
-
-again:
-       xfs_ilock(dp, XFS_ILOCK_EXCL | XFS_ILOCK_PARENT);
-
-       e_inum = ip->i_ino;
-
-       xfs_itrace_ref(ip);
-
-       /*
-        * We want to lock in increasing inum. Since we've already
-        * acquired the lock on the directory, we may need to release
-        * if if the inum of the entry turns out to be less.
-        */
-       if (e_inum > dp->i_ino) {
-               /*
-                * We are already in the right order, so just
-                * lock on the inode of the entry.
-                * We need to use nowait if dp is in the AIL.
-                */
-
-               lp = (xfs_log_item_t *)dp->i_itemp;
-               if (lp && (lp->li_flags & XFS_LI_IN_AIL)) {
-                       if (!xfs_ilock_nowait(ip, XFS_ILOCK_EXCL)) {
-                               attempts++;
-#ifdef DEBUG
-                               xfs_rm_attempts++;
-#endif
-
-                               /*
-                                * Unlock dp and try again.
-                                * xfs_iunlock will try to push the tail
-                                * if the inode is in the AIL.
-                                */
-
-                               xfs_iunlock(dp, XFS_ILOCK_EXCL);
-
-                               if ((attempts % 5) == 0) {
-                                       delay(1); /* Don't just spin the CPU */
-#ifdef DEBUG
-                                       xfs_rm_lock_delays++;
-#endif
-                               }
-                               goto again;
-                       }
-               } else {
-                       xfs_ilock(ip, XFS_ILOCK_EXCL);
-               }
-       } else if (e_inum < dp->i_ino) {
-               xfs_iunlock(dp, XFS_ILOCK_EXCL);
-
-               ips[0] = ip;
-               ips[1] = dp;
-               xfs_lock_inodes(ips, 2, XFS_ILOCK_EXCL);
-       }
-       /* else  e_inum == dp->i_ino */
-       /*     This can happen if we're asked to lock /x/..
-        *     the entry is "..", which is also the parent directory.
-        */
-
-       return 0;
-}
-
 #ifdef DEBUG
 int xfs_locked_n;
 int xfs_small_retries;
@@ -1963,6 +1838,45 @@ again:
 #endif
 }
 
+void
+xfs_lock_two_inodes(
+       xfs_inode_t             *ip0,
+       xfs_inode_t             *ip1,
+       uint                    lock_mode)
+{
+       xfs_inode_t             *temp;
+       int                     attempts = 0;
+       xfs_log_item_t          *lp;
+
+       ASSERT(ip0->i_ino != ip1->i_ino);
+
+       if (ip0->i_ino > ip1->i_ino) {
+               temp = ip0;
+               ip0 = ip1;
+               ip1 = temp;
+       }
+
+ again:
+       xfs_ilock(ip0, xfs_lock_inumorder(lock_mode, 0));
+
+       /*
+        * If the first lock we have locked is in the AIL, we must TRY to get
+        * the second lock. If we can't get it, we must release the first one
+        * and try again.
+        */
+       lp = (xfs_log_item_t *)ip0->i_itemp;
+       if (lp && (lp->li_flags & XFS_LI_IN_AIL)) {
+               if (!xfs_ilock_nowait(ip1, xfs_lock_inumorder(lock_mode, 1))) {
+                       xfs_iunlock(ip0, lock_mode);
+                       if ((++attempts % 5) == 0)
+                               delay(1); /* Don't just spin the CPU */
+                       goto again;
+               }
+       } else {
+               xfs_ilock(ip1, xfs_lock_inumorder(lock_mode, 1));
+       }
+}
+
 int
 xfs_remove(
        xfs_inode_t             *dp,
@@ -2035,9 +1949,7 @@ xfs_remove(
                goto out_trans_cancel;
        }
 
-       error = xfs_lock_dir_and_entry(dp, ip);
-       if (error)
-               goto out_trans_cancel;
+       xfs_lock_two_inodes(dp, ip, XFS_ILOCK_EXCL);
 
        /*
         * At this point, we've gotten both the directory and the entry
@@ -2064,9 +1976,6 @@ xfs_remove(
                }
        }
 
-       /*
-        * Entry must exist since we did a lookup in xfs_lock_dir_and_entry.
-        */
        XFS_BMAP_INIT(&free_list, &first_block);
        error = xfs_dir_removename(tp, dp, name, ip->i_ino,
                                        &first_block, &free_list, resblks);
@@ -2172,7 +2081,6 @@ xfs_link(
 {
        xfs_mount_t             *mp = tdp->i_mount;
        xfs_trans_t             *tp;
-       xfs_inode_t             *ips[2];
        int                     error;
        xfs_bmap_free_t         free_list;
        xfs_fsblock_t           first_block;
@@ -2220,15 +2128,7 @@ xfs_link(
                goto error_return;
        }
 
-       if (sip->i_ino < tdp->i_ino) {
-               ips[0] = sip;
-               ips[1] = tdp;
-       } else {
-               ips[0] = tdp;
-               ips[1] = sip;
-       }
-
-       xfs_lock_inodes(ips, 2, XFS_ILOCK_EXCL);
+       xfs_lock_two_inodes(sip, tdp, XFS_ILOCK_EXCL);
 
        /*
         * Increment vnode ref counts since xfs_trans_commit &
@@ -2369,7 +2269,7 @@ xfs_mkdir(
         * Make sure that we have allocated dquot(s) on disk.
         */
        error = XFS_QM_DQVOPALLOC(mp, dp,
-                       current_fsuid(credp), current_fsgid(credp), prid,
+                       current_fsuid(), current_fsgid(), prid,
                        XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, &udqp, &gdqp);
        if (error)
                goto std_return;
@@ -2595,7 +2495,7 @@ xfs_symlink(
         * Make sure that we have allocated dquot(s) on disk.
         */
        error = XFS_QM_DQVOPALLOC(mp, dp,
-                       current_fsuid(credp), current_fsgid(credp), prid,
+                       current_fsuid(), current_fsgid(), prid,
                        XFS_QMOPT_QUOTALL | XFS_QMOPT_INHERIT, &udqp, &gdqp);
        if (error)
                goto std_return;
@@ -2890,14 +2790,13 @@ int
 xfs_reclaim(
        xfs_inode_t     *ip)
 {
-       bhv_vnode_t     *vp = XFS_ITOV(ip);
 
        xfs_itrace_entry(ip);
 
-       ASSERT(!VN_MAPPED(vp));
+       ASSERT(!VN_MAPPED(VFS_I(ip)));
 
        /* bad inode, get out here ASAP */
-       if (VN_BAD(vp)) {
+       if (VN_BAD(VFS_I(ip))) {
                xfs_ireclaim(ip);
                return 0;
        }
@@ -2934,7 +2833,7 @@ xfs_reclaim(
                XFS_MOUNT_ILOCK(mp);
                spin_lock(&ip->i_flags_lock);
                __xfs_iflags_set(ip, XFS_IRECLAIMABLE);
-               vn_to_inode(vp)->i_private = NULL;
+               VFS_I(ip)->i_private = NULL;
                ip->i_vnode = NULL;
                spin_unlock(&ip->i_flags_lock);
                list_add_tail(&ip->i_reclaim, &mp->m_del_inodes);
@@ -2950,7 +2849,7 @@ xfs_finish_reclaim(
        int             sync_mode)
 {
        xfs_perag_t     *pag = xfs_get_perag(ip->i_mount, ip->i_ino);
-       bhv_vnode_t     *vp = XFS_ITOV_NULL(ip);
+       struct inode    *vp = VFS_I(ip);
 
        if (vp && VN_BAD(vp))
                goto reclaim;
@@ -3113,7 +3012,7 @@ xfs_alloc_file_space(
 
        /*      Generate a DMAPI event if needed.       */
        if (alloc_type != 0 && offset < ip->i_size &&
-                       (attr_flags&ATTR_DMI) == 0  &&
+                       (attr_flags & XFS_ATTR_DMI) == 0  &&
                        DM_EVENT_ENABLED(ip, DM_EVENT_WRITE)) {
                xfs_off_t           end_dmi_offset;
 
@@ -3227,7 +3126,7 @@ retry:
                allocatesize_fsb -= allocated_fsb;
        }
 dmapi_enospc_check:
-       if (error == ENOSPC && (attr_flags & ATTR_DMI) == 0 &&
+       if (error == ENOSPC && (attr_flags & XFS_ATTR_DMI) == 0 &&
            DM_EVENT_ENABLED(ip, DM_EVENT_NOSPACE)) {
                error = XFS_SEND_NAMESP(mp, DM_EVENT_NOSPACE,
                                ip, DM_RIGHT_NULL,
@@ -3338,7 +3237,6 @@ xfs_free_file_space(
        xfs_off_t               len,
        int                     attr_flags)
 {
-       bhv_vnode_t             *vp;
        int                     committed;
        int                     done;
        xfs_off_t               end_dmi_offset;
@@ -3358,7 +3256,6 @@ xfs_free_file_space(
        xfs_trans_t             *tp;
        int                     need_iolock = 1;
 
-       vp = XFS_ITOV(ip);
        mp = ip->i_mount;
 
        xfs_itrace_entry(ip);
@@ -3374,7 +3271,7 @@ xfs_free_file_space(
        end_dmi_offset = offset + len;
        endoffset_fsb = XFS_B_TO_FSBT(mp, end_dmi_offset);
 
-       if (offset < ip->i_size && (attr_flags & ATTR_DMI) == 0 &&
+       if (offset < ip->i_size && (attr_flags & XFS_ATTR_DMI) == 0 &&
            DM_EVENT_ENABLED(ip, DM_EVENT_WRITE)) {
                if (end_dmi_offset > ip->i_size)
                        end_dmi_offset = ip->i_size;
@@ -3385,7 +3282,7 @@ xfs_free_file_space(
                        return error;
        }
 
-       if (attr_flags & ATTR_NOLOCK)
+       if (attr_flags & XFS_ATTR_NOLOCK)
                need_iolock = 0;
        if (need_iolock) {
                xfs_ilock(ip, XFS_IOLOCK_EXCL);
@@ -3395,7 +3292,7 @@ xfs_free_file_space(
        rounding = max_t(uint, 1 << mp->m_sb.sb_blocklog, PAGE_CACHE_SIZE);
        ioffset = offset & ~(rounding - 1);
 
-       if (VN_CACHED(vp) != 0) {
+       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)
@@ -3562,7 +3459,7 @@ xfs_change_file_space(
        xfs_off_t       startoffset;
        xfs_off_t       llen;
        xfs_trans_t     *tp;
-       bhv_vattr_t     va;
+       struct iattr    iattr;
 
        xfs_itrace_entry(ip);
 
@@ -3636,10 +3533,10 @@ xfs_change_file_space(
                                break;
                }
 
-               va.va_mask = XFS_AT_SIZE;
-               va.va_size = startoffset;
+               iattr.ia_valid = ATTR_SIZE;
+               iattr.ia_size = startoffset;
 
-               error = xfs_setattr(ip, &va, attr_flags, credp);
+               error = xfs_setattr(ip, &iattr, attr_flags, credp);
 
                if (error)
                        return error;
@@ -3669,7 +3566,7 @@ xfs_change_file_space(
        xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
        xfs_trans_ihold(tp, ip);
 
-       if ((attr_flags & ATTR_DMI) == 0) {
+       if ((attr_flags & XFS_ATTR_DMI) == 0) {
                ip->i_d.di_mode &= ~S_ISUID;
 
                /*