[XFS] Remove unused ilen variable and references.
[powerpc.git] / fs / xfs / xfs_vnodeops.c
index 061e2ff..e2c9bbc 100644 (file)
@@ -51,7 +51,6 @@
 #include "xfs_refcache.h"
 #include "xfs_trans_space.h"
 #include "xfs_log_priv.h"
-#include "xfs_mac.h"
 
 STATIC int
 xfs_open(
@@ -134,7 +133,7 @@ xfs_getattr(
        if (!(flags & ATTR_LAZY))
                xfs_ilock(ip, XFS_ILOCK_SHARED);
 
-       vap->va_size = ip->i_d.di_size;
+       vap->va_size = XFS_ISIZE(ip);
        if (vap->va_mask == XFS_AT_SIZE)
                goto all_done;
 
@@ -497,7 +496,7 @@ xfs_setattr(
        if (mask & XFS_AT_SIZE) {
                /* Short circuit the truncate case for zero length files */
                if ((vap->va_size == 0) &&
-                  (ip->i_d.di_size == 0) && (ip->i_d.di_nextents == 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)
@@ -615,7 +614,7 @@ xfs_setattr(
         */
        if (mask & XFS_AT_SIZE) {
                code = 0;
-               if ((vap->va_size > ip->i_d.di_size) && 
+               if ((vap->va_size > ip->i_size) &&
                    (flags & ATTR_NOSIZETOK) == 0) {
                        code = xfs_igrow_start(ip, vap->va_size, credp);
                }
@@ -655,10 +654,10 @@ xfs_setattr(
         * Truncate file.  Must have write permission and not be a directory.
         */
        if (mask & XFS_AT_SIZE) {
-               if (vap->va_size > ip->i_d.di_size) {
+               if (vap->va_size > ip->i_size) {
                        xfs_igrow_finish(tp, ip, vap->va_size,
                            !(flags & ATTR_DMI));
-               } else if ((vap->va_size <= ip->i_d.di_size) ||
+               } else if ((vap->va_size <= ip->i_size) ||
                           ((vap->va_size == 0) && ip->i_d.di_nextents)) {
                        /*
                         * signal a sync transaction unless
@@ -874,7 +873,7 @@ xfs_setattr(
                if (mp->m_flags & XFS_MOUNT_WSYNC)
                        xfs_trans_set_sync(tp);
 
-               code = xfs_trans_commit(tp, commit_flags, NULL);
+               code = xfs_trans_commit(tp, commit_flags);
        }
 
        /*
@@ -1013,7 +1012,7 @@ xfs_readlink(
        pathlen = (int)ip->i_d.di_size;
 
        if (ip->i_df.if_flags & XFS_IFINLINE) {
-               error = uio_read(ip->i_df.if_u1.if_data, pathlen, uiop);
+               error = xfs_uio_read(ip->i_df.if_u1.if_data, pathlen, uiop);
        }
        else {
                /*
@@ -1044,7 +1043,7 @@ xfs_readlink(
                                byte_cnt = pathlen;
                        pathlen -= byte_cnt;
 
-                       error = uio_read(XFS_BUF_PTR(bp), byte_cnt, uiop);
+                       error = xfs_uio_read(XFS_BUF_PTR(bp), byte_cnt, uiop);
                        xfs_buf_relse (bp);
                }
 
@@ -1177,7 +1176,7 @@ xfs_fsync(
                xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
                if (flag & FSYNC_WAIT)
                        xfs_trans_set_sync(tp);
-               error = _xfs_trans_commit(tp, 0, NULL, &log_flushed);
+               error = _xfs_trans_commit(tp, 0, &log_flushed);
 
                xfs_iunlock(ip, XFS_ILOCK_EXCL);
        }
@@ -1222,7 +1221,7 @@ xfs_inactive_free_eofblocks(
         * Figure out if there are any blocks beyond the end
         * of the file.  If not, then there is nothing to do.
         */
-       end_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)ip->i_d.di_size));
+       end_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)ip->i_size));
        last_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_MAXIOFFSET(mp));
        map_len = last_fsb - end_fsb;
        if (map_len <= 0)
@@ -1258,8 +1257,12 @@ xfs_inactive_free_eofblocks(
                 * do that within a transaction.
                 */
                xfs_ilock(ip, XFS_IOLOCK_EXCL);
-               xfs_itruncate_start(ip, XFS_ITRUNC_DEFINITE,
-                                   ip->i_d.di_size);
+               error = xfs_itruncate_start(ip, XFS_ITRUNC_DEFINITE,
+                                   ip->i_size);
+               if (error) {
+                       xfs_iunlock(ip, XFS_IOLOCK_EXCL);
+                       return error;
+               }
 
                error = xfs_trans_reserve(tp, 0,
                                          XFS_ITRUNCATE_LOG_RES(mp),
@@ -1279,7 +1282,7 @@ xfs_inactive_free_eofblocks(
                xfs_trans_ihold(tp, ip);
 
                error = xfs_itruncate_finish(&tp, ip,
-                                            ip->i_d.di_size,
+                                            ip->i_size,
                                             XFS_DATA_FORK,
                                             0);
                /*
@@ -1292,8 +1295,7 @@ xfs_inactive_free_eofblocks(
                                          XFS_TRANS_ABORT));
                } else {
                        error = xfs_trans_commit(tp,
-                                               XFS_TRANS_RELEASE_LOG_RES,
-                                               NULL);
+                                               XFS_TRANS_RELEASE_LOG_RES);
                }
                xfs_iunlock(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
        }
@@ -1381,7 +1383,7 @@ xfs_inactive_symlink_rmt(
        /*
         * Commit the first transaction.  This logs the EFI and the inode.
         */
-       if ((error = xfs_bmap_finish(&tp, &free_list, first_block, &committed)))
+       if ((error = xfs_bmap_finish(&tp, &free_list, &committed)))
                goto error1;
        /*
         * The transaction must have been committed, since there were
@@ -1407,7 +1409,7 @@ xfs_inactive_symlink_rmt(
         * we need to unlock the inode since the new transaction doesn't
         * have the inode attached.
         */
-       error = xfs_trans_commit(tp, 0, NULL);
+       error = xfs_trans_commit(tp, 0);
        tp = ntp;
        if (error) {
                ASSERT(XFS_FORCED_SHUTDOWN(mp));
@@ -1504,7 +1506,7 @@ xfs_inactive_attrs(
        tp = *tpp;
        mp = ip->i_mount;
        ASSERT(ip->i_d.di_forkoff != 0);
-       xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
+       xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
        xfs_iunlock(ip, XFS_ILOCK_EXCL);
 
        error = xfs_attr_inactive(ip);
@@ -1566,7 +1568,7 @@ xfs_release(
 
        if (ip->i_d.di_nlink != 0) {
                if ((((ip->i_d.di_mode & S_IFMT) == S_IFREG) &&
-                    ((ip->i_d.di_size > 0) || (VN_CACHED(vp) > 0 ||
+                    ((ip->i_size > 0) || (VN_CACHED(vp) > 0 ||
                       ip->i_delayed_blks > 0)) &&
                     (ip->i_df.if_flags & XFS_IFEXTENTS))  &&
                    (!(ip->i_d.di_flags &
@@ -1627,8 +1629,8 @@ xfs_inactive(
         * only one with a reference to the inode.
         */
        truncate = ((ip->i_d.di_nlink == 0) &&
-            ((ip->i_d.di_size != 0) || (ip->i_d.di_nextents > 0) ||
-             (ip->i_delayed_blks > 0)) &&
+           ((ip->i_d.di_size != 0) || (ip->i_size != 0) ||
+            (ip->i_d.di_nextents > 0) || (ip->i_delayed_blks > 0)) &&
            ((ip->i_d.di_mode & S_IFMT) == S_IFREG));
 
        mp = ip->i_mount;
@@ -1646,7 +1648,7 @@ xfs_inactive(
 
        if (ip->i_d.di_nlink != 0) {
                if ((((ip->i_d.di_mode & S_IFMT) == S_IFREG) &&
-                     ((ip->i_d.di_size > 0) || (VN_CACHED(vp) > 0 ||
+                     ((ip->i_size > 0) || (VN_CACHED(vp) > 0 ||
                        ip->i_delayed_blks > 0)) &&
                      (ip->i_df.if_flags & XFS_IFEXTENTS) &&
                     (!(ip->i_d.di_flags &
@@ -1676,7 +1678,11 @@ xfs_inactive(
                 */
                xfs_ilock(ip, XFS_IOLOCK_EXCL);
 
-               xfs_itruncate_start(ip, XFS_ITRUNC_DEFINITE, 0);
+               error = xfs_itruncate_start(ip, XFS_ITRUNC_DEFINITE, 0);
+               if (error) {
+                       xfs_iunlock(ip, XFS_IOLOCK_EXCL);
+                       return VN_INACTIVE_CACHE;
+               }
 
                error = xfs_trans_reserve(tp, 0,
                                          XFS_ITRUNCATE_LOG_RES(mp),
@@ -1790,9 +1796,8 @@ xfs_inactive(
                 * Just ignore errors at this point.  There is
                 * nothing we can do except to try to keep going.
                 */
-               (void) xfs_bmap_finish(&tp,  &free_list, first_block,
-                                      &committed);
-               (void) xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
+               (void) xfs_bmap_finish(&tp,  &free_list, &committed);
+               (void) xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
        }
        /*
         * Release the dquots held by inode, if any.
@@ -2022,13 +2027,13 @@ xfs_create(
        IHOLD(ip);
        vp = XFS_ITOV(ip);
 
-       error = xfs_bmap_finish(&tp, &free_list, first_block, &committed);
+       error = xfs_bmap_finish(&tp, &free_list, &committed);
        if (error) {
                xfs_bmap_cancel(&free_list);
                goto abort_rele;
        }
 
-       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
+       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
        if (error) {
                IRELE(ip);
                tp = NULL;
@@ -2123,7 +2128,6 @@ int xfs_rm_attempts;
 STATIC int
 xfs_lock_dir_and_entry(
        xfs_inode_t     *dp,
-       bhv_vname_t     *dentry,
        xfs_inode_t     *ip)    /* inode of entry 'name' */
 {
        int             attempts;
@@ -2442,7 +2446,7 @@ xfs_remove(
                return error;
        }
 
-       error = xfs_lock_dir_and_entry(dp, dentry, ip);
+       error = xfs_lock_dir_and_entry(dp, ip);
        if (error) {
                REMOVE_DEBUG_TRACE(__LINE__);
                xfs_trans_cancel(tp, cancel_flags);
@@ -2507,13 +2511,13 @@ xfs_remove(
                xfs_trans_set_sync(tp);
        }
 
-       error = xfs_bmap_finish(&tp, &free_list, first_block, &committed);
+       error = xfs_bmap_finish(&tp, &free_list, &committed);
        if (error) {
                REMOVE_DEBUG_TRACE(__LINE__);
                goto error_rele;
        }
 
-       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
+       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
        if (error) {
                IRELE(ip);
                goto std_return;
@@ -2715,13 +2719,13 @@ xfs_link(
                xfs_trans_set_sync(tp);
        }
 
-       error = xfs_bmap_finish (&tp, &free_list, first_block, &committed);
+       error = xfs_bmap_finish (&tp, &free_list, &committed);
        if (error) {
                xfs_bmap_cancel(&free_list);
                goto abort_return;
        }
 
-       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
+       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
        if (error)
                goto std_return;
 
@@ -2932,13 +2936,13 @@ xfs_mkdir(
                xfs_trans_set_sync(tp);
        }
 
-       error = xfs_bmap_finish(&tp, &free_list, first_block, &committed);
+       error = xfs_bmap_finish(&tp, &free_list, &committed);
        if (error) {
                IRELE(cdp);
                goto error2;
        }
 
-       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
+       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
        XFS_QM_DQRELE(mp, udqp);
        XFS_QM_DQRELE(mp, gdqp);
        if (error) {
@@ -3098,7 +3102,7 @@ xfs_rmdir(
         * that the directory entry for the child directory inode has
         * not changed while we were obtaining a log reservation.
         */
-       error = xfs_lock_dir_and_entry(dp, dentry, cdp);
+       error = xfs_lock_dir_and_entry(dp, cdp);
        if (error) {
                xfs_trans_cancel(tp, cancel_flags);
                IRELE(cdp);
@@ -3183,7 +3187,7 @@ xfs_rmdir(
                xfs_trans_set_sync(tp);
        }
 
-       error = xfs_bmap_finish (&tp, &free_list, first_block, &committed);
+       error = xfs_bmap_finish (&tp, &free_list, &committed);
        if (error) {
                xfs_bmap_cancel(&free_list);
                xfs_trans_cancel(tp, (XFS_TRANS_RELEASE_LOG_RES |
@@ -3192,7 +3196,7 @@ xfs_rmdir(
                goto std_return;
        }
 
-       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
+       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
        if (error) {
                IRELE(cdp);
                goto std_return;
@@ -3533,11 +3537,11 @@ xfs_symlink(
         */
        IHOLD(ip);
 
-       error = xfs_bmap_finish(&tp, &free_list, first_block, &committed);
+       error = xfs_bmap_finish(&tp, &free_list, &committed);
        if (error) {
                goto error2;
        }
-       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
+       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
        XFS_QM_DQRELE(mp, udqp);
        XFS_QM_DQRELE(mp, gdqp);
 
@@ -3792,7 +3796,7 @@ xfs_set_dmattrs (
 
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
        IHOLD(ip);
-       error = xfs_trans_commit(tp, 0, NULL);
+       error = xfs_trans_commit(tp, 0);
 
        return error;
 }
@@ -3827,11 +3831,16 @@ xfs_reclaim(
         */
        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.
+       /*
+        * 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);
@@ -3840,13 +3849,13 @@ xfs_reclaim(
        } else {
                xfs_mount_t     *mp = ip->i_mount;
 
-               /* Protect sync from us */
+               /* Protect sync and unpin from us */
                XFS_MOUNT_ILOCK(mp);
-               vn_bhv_remove(VN_BHV_HEAD(vp), XFS_ITOBHV(ip));
-               list_add_tail(&ip->i_reclaim, &mp->m_del_inodes);
                spin_lock(&ip->i_flags_lock);
-               ip->i_flags |= XFS_IRECLAIMABLE;
+               __xfs_iflags_set(ip, XFS_IRECLAIMABLE);
+               vn_bhv_remove(VN_BHV_HEAD(vp), XFS_ITOBHV(ip));
                spin_unlock(&ip->i_flags_lock);
+               list_add_tail(&ip->i_reclaim, &mp->m_del_inodes);
                XFS_MOUNT_IUNLOCK(mp);
        }
        return 0;
@@ -3872,8 +3881,8 @@ xfs_finish_reclaim(
         */
        write_lock(&ih->ih_lock);
        spin_lock(&ip->i_flags_lock);
-       if ((ip->i_flags & XFS_IRECLAIM) ||
-           (!(ip->i_flags & XFS_IRECLAIMABLE) && vp == NULL)) {
+       if (__xfs_iflags_test(ip, XFS_IRECLAIM) ||
+           (!__xfs_iflags_test(ip, XFS_IRECLAIMABLE) && vp == NULL)) {
                spin_unlock(&ip->i_flags_lock);
                write_unlock(&ih->ih_lock);
                if (locked) {
@@ -3882,7 +3891,7 @@ xfs_finish_reclaim(
                }
                return 1;
        }
-       ip->i_flags |= XFS_IRECLAIM;
+       __xfs_iflags_set(ip, XFS_IRECLAIM);
        spin_unlock(&ip->i_flags_lock);
        write_unlock(&ih->ih_lock);
 
@@ -4046,14 +4055,14 @@ xfs_alloc_file_space(
        allocatesize_fsb = XFS_B_TO_FSB(mp, count);
 
        /*      Generate a DMAPI event if needed.       */
-       if (alloc_type != 0 && offset < ip->i_d.di_size &&
+       if (alloc_type != 0 && offset < ip->i_size &&
                        (attr_flags&ATTR_DMI) == 0  &&
                        DM_EVENT_ENABLED(XFS_MTOVFS(mp), ip, DM_EVENT_WRITE)) {
                xfs_off_t           end_dmi_offset;
 
                end_dmi_offset = offset+len;
-               if (end_dmi_offset > ip->i_d.di_size)
-                       end_dmi_offset = ip->i_d.di_size;
+               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);
@@ -4140,12 +4149,12 @@ retry:
                /*
                 * Complete the transaction
                 */
-               error = xfs_bmap_finish(&tp, &free_list, firstfsb, &committed);
+               error = xfs_bmap_finish(&tp, &free_list, &committed);
                if (error) {
                        goto error0;
                }
 
-               error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
+               error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
                xfs_iunlock(ip, XFS_ILOCK_EXCL);
                if (error) {
                        break;
@@ -4280,7 +4289,6 @@ xfs_free_file_space(
        int                     error;
        xfs_fsblock_t           firstfsb;
        xfs_bmap_free_t         free_list;
-       xfs_off_t               ilen;
        xfs_bmbt_irec_t         imap;
        xfs_off_t               ioffset;
        xfs_extlen_t            mod=0;
@@ -4309,11 +4317,11 @@ xfs_free_file_space(
        end_dmi_offset = offset + len;
        endoffset_fsb = XFS_B_TO_FSBT(mp, end_dmi_offset);
 
-       if (offset < ip->i_d.di_size &&
+       if (offset < ip->i_size &&
            (attr_flags & ATTR_DMI) == 0 &&
            DM_EVENT_ENABLED(XFS_MTOVFS(mp), ip, DM_EVENT_WRITE)) {
-               if (end_dmi_offset > ip->i_d.di_size)
-                       end_dmi_offset = ip->i_d.di_size;
+               if (end_dmi_offset > ip->i_size)
+                       end_dmi_offset = ip->i_size;
                error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, vp,
                                offset, end_dmi_offset - offset,
                                AT_DELAY_FLAG(attr_flags), NULL);
@@ -4329,16 +4337,15 @@ xfs_free_file_space(
        }
 
        rounding = max_t(uint, 1 << mp->m_sb.sb_blocklog, NBPP);
-       ilen = len + (offset & (rounding - 1));
        ioffset = offset & ~(rounding - 1);
-       if (ilen & (rounding - 1))
-               ilen = (ilen + rounding) & ~(rounding - 1);
 
        if (VN_CACHED(vp) != 0) {
                xfs_inval_cached_trace(&ip->i_iocore, ioffset, -1,
                                ctooff(offtoct(ioffset)), -1);
-               bhv_vop_flushinval_pages(vp, ctooff(offtoct(ioffset)),
+               error = bhv_vop_flushinval_pages(vp, ctooff(offtoct(ioffset)),
                                -1, FI_REMAPF_LOCKED);
+               if (error)
+                       goto out_unlock_iolock;
        }
 
        /*
@@ -4447,12 +4454,12 @@ xfs_free_file_space(
                /*
                 * complete the transaction
                 */
-               error = xfs_bmap_finish(&tp, &free_list, firstfsb, &committed);
+               error = xfs_bmap_finish(&tp, &free_list, &committed);
                if (error) {
                        goto error0;
                }
 
-               error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES, NULL);
+               error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
                xfs_iunlock(ip, XFS_ILOCK_EXCL);
        }
 
@@ -4530,7 +4537,7 @@ xfs_change_file_space(
                bf->l_start += offset;
                break;
        case 2: /*SEEK_END*/
-               bf->l_start += ip->i_d.di_size;
+               bf->l_start += ip->i_size;
                break;
        default:
                return XFS_ERROR(EINVAL);
@@ -4547,7 +4554,7 @@ xfs_change_file_space(
        bf->l_whence = 0;
 
        startoffset = bf->l_start;
-       fsize = ip->i_d.di_size;
+       fsize = ip->i_size;
 
        /*
         * XFS_IOC_RESVSP and XFS_IOC_UNRESVSP will reserve or unreserve
@@ -4646,7 +4653,7 @@ xfs_change_file_space(
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
        xfs_trans_set_sync(tp);
 
-       error = xfs_trans_commit(tp, 0, NULL);
+       error = xfs_trans_commit(tp, 0);
 
        xfs_iunlock(ip, XFS_ILOCK_EXCL);