]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: move the per-fork nextents fields into struct xfs_ifork
authorChristoph Hellwig <hch@lst.de>
Mon, 10 Aug 2020 20:32:06 +0000 (16:32 -0400)
committerEric Sandeen <sandeen@sandeen.net>
Mon, 10 Aug 2020 20:32:06 +0000 (16:32 -0400)
Source kernel commit: daf83964a3681cf1f1f255ad6095c0b60cba7dca

There are there are three extents counters per inode, one for each of
the forks.  Two are in the legacy icdinode and one is directly in
struct xfs_inode.  Switch to a single counter in the xfs_ifork structure
where it uses up padding at the end of the structure.  This simplifies
various bits of code that just wants the number of extents counter and
can now directly dereference it.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chandan Babu R <chandanrlinux@gmail.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Eric Sandeen <sandeen@sandeen.net>
libxfs/util.c
libxfs/xfs_attr.c
libxfs/xfs_attr_leaf.c
libxfs/xfs_bmap.c
libxfs/xfs_dir2_block.c
libxfs/xfs_inode_buf.c
libxfs/xfs_inode_buf.h
libxfs/xfs_inode_fork.c
libxfs/xfs_inode_fork.h

index f97ddd29c01e16511535058ea65bd8b269f5d959..d61178e86cf43545927aa00b362062bc154b18cd 100644 (file)
@@ -266,7 +266,7 @@ libxfs_ialloc(
        }
 
        ip->i_d.di_size = 0;
-       ip->i_d.di_nextents = 0;
+       ip->i_df.if_nextents = 0;
        ASSERT(ip->i_d.di_nblocks == 0);
        ip->i_d.di_extsize = pip ? 0 : fsx->fsx_extsize;
        ip->i_d.di_dmevmask = 0;
@@ -334,7 +334,6 @@ libxfs_ialloc(
        }
        /* Attribute fork settings for new inode. */
        ip->i_d.di_aformat = XFS_DINODE_FMT_EXTENTS;
-       ip->i_d.di_anextents = 0;
 
        /*
         * Log the new values stuffed into the inode.
@@ -359,7 +358,7 @@ libxfs_iflush_int(
        xfs_mount_t                     *mp;
 
        ASSERT(ip->i_d.di_format != XFS_DINODE_FMT_BTREE ||
-               ip->i_d.di_nextents > ip->i_df.if_ext_max);
+               ip->i_df.if_nextents > ip->i_df.if_ext_max);
 
        iip = ip->i_itemp;
        mp = ip->i_mount;
@@ -376,7 +375,7 @@ libxfs_iflush_int(
                        (ip->i_d.di_format == XFS_DINODE_FMT_BTREE)   ||
                        (ip->i_d.di_format == XFS_DINODE_FMT_LOCAL) );
        }
-       ASSERT(ip->i_d.di_nextents+ip->i_d.di_anextents <= ip->i_d.di_nblocks);
+       ASSERT(ip->i_df.if_nextents+ip->i_afp->if_nextents <= ip->i_d.di_nblocks);
        ASSERT(ip->i_d.di_forkoff <= mp->m_sb.sb_inodesize);
 
        /* bump the change count on v3 inodes */
index 469d6804b5472421882f6e0bea81803cb4237650..a33528198356ceda76dbaa5526eb42007c3d50a4 100644 (file)
@@ -62,7 +62,7 @@ xfs_inode_hasattr(
 {
        if (!XFS_IFORK_Q(ip) ||
            (ip->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
-            ip->i_d.di_anextents == 0))
+            ip->i_afp->if_nextents == 0))
                return 0;
        return 1;
 }
@@ -214,7 +214,7 @@ xfs_attr_set_args(
         */
        if (dp->i_d.di_aformat == XFS_DINODE_FMT_LOCAL ||
            (dp->i_d.di_aformat == XFS_DINODE_FMT_EXTENTS &&
-            dp->i_d.di_anextents == 0)) {
+            dp->i_afp->if_nextents == 0)) {
 
                /*
                 * Build initial attribute list (if required).
index 5685dacab491d8829865d4faeeecdd3f391d3e9a..16ff1c7b8c029cfb27cff81258df66a66a74bf18 100644 (file)
@@ -715,11 +715,12 @@ xfs_attr_fork_remove(
        struct xfs_inode        *ip,
        struct xfs_trans        *tp)
 {
+       ASSERT(ip->i_afp->if_nextents == 0);
+
        xfs_idestroy_fork(ip, XFS_ATTR_FORK);
        ip->i_d.di_forkoff = 0;
        ip->i_d.di_aformat = XFS_DINODE_FMT_EXTENTS;
 
-       ASSERT(ip->i_d.di_anextents == 0);
        ASSERT(ip->i_afp == NULL);
 
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
index 2389f3ad4fbc01283a432efb1ebee5e87f69bc4b..dbc4bafaaf2c9126ea65b437ab4a94f40e41dd0f 100644 (file)
@@ -54,10 +54,10 @@ xfs_bmap_compute_maxlevels(
        int             sz;             /* root block size */
 
        /*
-        * The maximum number of extents in a file, hence the maximum
-        * number of leaf entries, is controlled by the type of di_nextents
-        * (a signed 32-bit number, xfs_extnum_t), or by di_anextents
-        * (a signed 16-bit number, xfs_aextnum_t).
+        * The maximum number of extents in a file, hence the maximum number of
+        * leaf entries, is controlled by the size of the on-disk extent count,
+        * either a signed 32-bit number for the data fork, or a signed 16-bit
+        * number for the attr fork.
         *
         * Note that we can no longer assume that if we are in ATTR1 that
         * the fork offset of all the inodes will be
@@ -113,10 +113,11 @@ xfs_bmbt_lookup_first(
  */
 static inline bool xfs_bmap_needs_btree(struct xfs_inode *ip, int whichfork)
 {
+       struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
+
        return whichfork != XFS_COW_FORK &&
                XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_EXTENTS &&
-               XFS_IFORK_NEXTENTS(ip, whichfork) >
-                       XFS_IFORK_MAXEXT(ip, whichfork);
+               ifp->if_nextents > XFS_IFORK_MAXEXT(ip, whichfork);
 }
 
 /*
@@ -124,10 +125,11 @@ static inline bool xfs_bmap_needs_btree(struct xfs_inode *ip, int whichfork)
  */
 static inline bool xfs_bmap_wants_extents(struct xfs_inode *ip, int whichfork)
 {
+       struct xfs_ifork *ifp = XFS_IFORK_PTR(ip, whichfork);
+
        return whichfork != XFS_COW_FORK &&
                XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_BTREE &&
-               XFS_IFORK_NEXTENTS(ip, whichfork) <=
-                       XFS_IFORK_MAXEXT(ip, whichfork);
+               ifp->if_nextents <= XFS_IFORK_MAXEXT(ip, whichfork);
 }
 
 /*
@@ -327,7 +329,7 @@ xfs_bmap_check_leaf_extents(
        }
 
        /* skip large extent count inodes */
-       if (ip->i_d.di_nextents > 10000)
+       if (ip->i_df.if_nextents > 10000)
                return;
 
        bno = NULLFSBLOCK;
@@ -743,7 +745,7 @@ xfs_bmap_extents_to_btree(
                xfs_bmbt_disk_set_all(arp, &rec);
                cnt++;
        }
-       ASSERT(cnt == XFS_IFORK_NEXTENTS(ip, whichfork));
+       ASSERT(cnt == ifp->if_nextents);
        xfs_btree_set_numrecs(ablock, cnt);
 
        /*
@@ -795,7 +797,7 @@ xfs_bmap_local_to_extents_empty(
        ASSERT(whichfork != XFS_COW_FORK);
        ASSERT(XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_LOCAL);
        ASSERT(ifp->if_bytes == 0);
-       ASSERT(XFS_IFORK_NEXTENTS(ip, whichfork) == 0);
+       ASSERT(ifp->if_nextents == 0);
 
        xfs_bmap_forkoff_reset(ip, whichfork);
        ifp->if_flags &= ~XFS_IFINLINE;
@@ -900,7 +902,7 @@ xfs_bmap_local_to_extents(
        xfs_iext_first(ifp, &icur);
        xfs_iext_insert(ip, &icur, &rec, 0);
 
-       XFS_IFORK_NEXT_SET(ip, whichfork, 1);
+       ifp->if_nextents = 1;
        ip->i_d.di_nblocks = 1;
        xfs_trans_mod_dquot_byino(tp, ip,
                XFS_TRANS_DQ_BCOUNT, 1L);
@@ -965,7 +967,8 @@ xfs_bmap_add_attrfork_extents(
        xfs_btree_cur_t         *cur;           /* bmap btree cursor */
        int                     error;          /* error return value */
 
-       if (ip->i_d.di_nextents * sizeof(xfs_bmbt_rec_t) <= XFS_IFORK_DSIZE(ip))
+       if (ip->i_df.if_nextents * sizeof(struct xfs_bmbt_rec) <=
+           XFS_IFORK_DSIZE(ip))
                return 0;
        cur = NULL;
        error = xfs_bmap_extents_to_btree(tp, ip, &cur, 0, flags,
@@ -1084,10 +1087,6 @@ xfs_bmap_add_attrfork(
                goto trans_cancel;
        if (XFS_IFORK_Q(ip))
                goto trans_cancel;
-       if (XFS_IS_CORRUPT(mp, ip->i_d.di_anextents != 0)) {
-               error = -EFSCORRUPTED;
-               goto trans_cancel;
-       }
        if (ip->i_d.di_aformat != XFS_DINODE_FMT_EXTENTS) {
                /*
                 * For inodes coming from pre-6.2 filesystems.
@@ -1176,13 +1175,13 @@ xfs_iread_bmbt_block(
        xfs_extnum_t            num_recs;
        xfs_extnum_t            j;
        int                     whichfork = cur->bc_ino.whichfork;
+       struct xfs_ifork        *ifp = XFS_IFORK_PTR(ip, whichfork);
 
        block = xfs_btree_get_block(cur, level, &bp);
 
        /* Abort if we find more records than nextents. */
        num_recs = xfs_btree_get_numrecs(block);
-       if (unlikely(ir->loaded + num_recs >
-                    XFS_IFORK_NEXTENTS(ip, whichfork))) {
+       if (unlikely(ir->loaded + num_recs > ifp->if_nextents)) {
                xfs_warn(ip->i_mount, "corrupt dinode %llu, (btree extents).",
                                (unsigned long long)ip->i_ino);
                xfs_inode_verifier_error(ip, -EFSCORRUPTED, __func__, block,
@@ -1208,7 +1207,7 @@ xfs_iread_bmbt_block(
                                xfs_bmap_fork_to_state(whichfork));
                trace_xfs_read_extent(ip, &ir->icur,
                                xfs_bmap_fork_to_state(whichfork), _THIS_IP_);
-               xfs_iext_next(XFS_IFORK_PTR(ip, whichfork), &ir->icur);
+               xfs_iext_next(ifp, &ir->icur);
        }
 
        return 0;
@@ -1247,8 +1246,7 @@ xfs_iread_extents(
        if (error)
                goto out;
 
-       if (XFS_IS_CORRUPT(mp,
-                          ir.loaded != XFS_IFORK_NEXTENTS(ip, whichfork))) {
+       if (XFS_IS_CORRUPT(mp, ir.loaded != ifp->if_nextents)) {
                error = -EFSCORRUPTED;
                goto out;
        }
@@ -1456,23 +1454,22 @@ xfs_bmap_last_offset(
  */
 int                                    /* 1=>1 block, 0=>otherwise */
 xfs_bmap_one_block(
-       xfs_inode_t     *ip,            /* incore inode */
-       int             whichfork)      /* data or attr fork */
+       struct xfs_inode        *ip,            /* incore inode */
+       int                     whichfork)      /* data or attr fork */
 {
-       struct xfs_ifork *ifp;          /* inode fork pointer */
-       int             rval;           /* return value */
-       xfs_bmbt_irec_t s;              /* internal version of extent */
+       struct xfs_ifork        *ifp = XFS_IFORK_PTR(ip, whichfork);
+       int                     rval;           /* return value */
+       struct xfs_bmbt_irec    s;              /* internal version of extent */
        struct xfs_iext_cursor icur;
 
 #ifndef DEBUG
        if (whichfork == XFS_DATA_FORK)
                return XFS_ISIZE(ip) == ip->i_mount->m_sb.sb_blocksize;
 #endif /* !DEBUG */
-       if (XFS_IFORK_NEXTENTS(ip, whichfork) != 1)
+       if (ifp->if_nextents != 1)
                return 0;
        if (XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_EXTENTS)
                return 0;
-       ifp = XFS_IFORK_PTR(ip, whichfork);
        ASSERT(ifp->if_flags & XFS_IFEXTENTS);
        xfs_iext_first(ifp, &icur);
        xfs_iext_get_extent(ifp, &icur, &s);
@@ -1494,10 +1491,11 @@ xfs_bmap_add_extent_delay_real(
        struct xfs_bmalloca     *bma,
        int                     whichfork)
 {
+       struct xfs_mount        *mp = bma->ip->i_mount;
+       struct xfs_ifork        *ifp = XFS_IFORK_PTR(bma->ip, whichfork);
        struct xfs_bmbt_irec    *new = &bma->got;
        int                     error;  /* error return value */
        int                     i;      /* temp state */
-       struct xfs_ifork        *ifp;   /* inode fork pointer */
        xfs_fileoff_t           new_endoff;     /* end offset of new entry */
        xfs_bmbt_irec_t         r[3];   /* neighbor extent entries */
                                        /* left is 0, right is 1, prev is 2 */
@@ -1507,16 +1505,9 @@ xfs_bmap_add_extent_delay_real(
        xfs_filblks_t           da_old; /* old count del alloc blocks used */
        xfs_filblks_t           temp=0; /* value for da_new calculations */
        int                     tmp_rval;       /* partial logging flags */
-       struct xfs_mount        *mp;
-       xfs_extnum_t            *nextents;
        struct xfs_bmbt_irec    old;
 
-       mp = bma->ip->i_mount;
-       ifp = XFS_IFORK_PTR(bma->ip, whichfork);
        ASSERT(whichfork != XFS_ATTR_FORK);
-       nextents = (whichfork == XFS_COW_FORK ? &bma->ip->i_cnextents :
-                                               &bma->ip->i_d.di_nextents);
-
        ASSERT(!isnullstartblock(new->br_startblock));
        ASSERT(!bma->cur ||
               (bma->cur->bc_ino.flags & XFS_BTCUR_BMBT_WASDEL));
@@ -1607,7 +1598,7 @@ xfs_bmap_add_extent_delay_real(
                xfs_iext_remove(bma->ip, &bma->icur, state);
                xfs_iext_prev(ifp, &bma->icur);
                xfs_iext_update_extent(bma->ip, state, &bma->icur, &LEFT);
-               (*nextents)--;
+               ifp->if_nextents--;
 
                if (bma->cur == NULL)
                        rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
@@ -1711,8 +1702,8 @@ xfs_bmap_add_extent_delay_real(
                PREV.br_startblock = new->br_startblock;
                PREV.br_state = new->br_state;
                xfs_iext_update_extent(bma->ip, state, &bma->icur, &PREV);
+               ifp->if_nextents++;
 
-               (*nextents)++;
                if (bma->cur == NULL)
                        rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
                else {
@@ -1777,7 +1768,8 @@ xfs_bmap_add_extent_delay_real(
                 * The left neighbor is not contiguous.
                 */
                xfs_iext_update_extent(bma->ip, state, &bma->icur, new);
-               (*nextents)++;
+               ifp->if_nextents++;
+
                if (bma->cur == NULL)
                        rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
                else {
@@ -1863,7 +1855,8 @@ xfs_bmap_add_extent_delay_real(
                 * The right neighbor is not contiguous.
                 */
                xfs_iext_update_extent(bma->ip, state, &bma->icur, new);
-               (*nextents)++;
+               ifp->if_nextents++;
+
                if (bma->cur == NULL)
                        rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
                else {
@@ -1948,7 +1941,7 @@ xfs_bmap_add_extent_delay_real(
                xfs_iext_next(ifp, &bma->icur);
                xfs_iext_insert(bma->ip, &bma->icur, &RIGHT, state);
                xfs_iext_insert(bma->ip, &bma->icur, &LEFT, state);
-               (*nextents)++;
+               ifp->if_nextents++;
 
                if (bma->cur == NULL)
                        rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
@@ -2152,8 +2145,7 @@ xfs_bmap_add_extent_unwritten_real(
                xfs_iext_remove(ip, icur, state);
                xfs_iext_prev(ifp, icur);
                xfs_iext_update_extent(ip, state, icur, &LEFT);
-               XFS_IFORK_NEXT_SET(ip, whichfork,
-                               XFS_IFORK_NEXTENTS(ip, whichfork) - 2);
+               ifp->if_nextents -= 2;
                if (cur == NULL)
                        rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
                else {
@@ -2205,8 +2197,7 @@ xfs_bmap_add_extent_unwritten_real(
                xfs_iext_remove(ip, icur, state);
                xfs_iext_prev(ifp, icur);
                xfs_iext_update_extent(ip, state, icur, &LEFT);
-               XFS_IFORK_NEXT_SET(ip, whichfork,
-                               XFS_IFORK_NEXTENTS(ip, whichfork) - 1);
+               ifp->if_nextents--;
                if (cur == NULL)
                        rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
                else {
@@ -2248,9 +2239,8 @@ xfs_bmap_add_extent_unwritten_real(
                xfs_iext_remove(ip, icur, state);
                xfs_iext_prev(ifp, icur);
                xfs_iext_update_extent(ip, state, icur, &PREV);
+               ifp->if_nextents--;
 
-               XFS_IFORK_NEXT_SET(ip, whichfork,
-                               XFS_IFORK_NEXTENTS(ip, whichfork) - 1);
                if (cur == NULL)
                        rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
                else {
@@ -2357,8 +2347,8 @@ xfs_bmap_add_extent_unwritten_real(
 
                xfs_iext_update_extent(ip, state, icur, &PREV);
                xfs_iext_insert(ip, icur, new, state);
-               XFS_IFORK_NEXT_SET(ip, whichfork,
-                               XFS_IFORK_NEXTENTS(ip, whichfork) + 1);
+               ifp->if_nextents++;
+
                if (cur == NULL)
                        rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
                else {
@@ -2433,9 +2423,8 @@ xfs_bmap_add_extent_unwritten_real(
                xfs_iext_update_extent(ip, state, icur, &PREV);
                xfs_iext_next(ifp, icur);
                xfs_iext_insert(ip, icur, new, state);
+               ifp->if_nextents++;
 
-               XFS_IFORK_NEXT_SET(ip, whichfork,
-                               XFS_IFORK_NEXTENTS(ip, whichfork) + 1);
                if (cur == NULL)
                        rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
                else {
@@ -2486,9 +2475,8 @@ xfs_bmap_add_extent_unwritten_real(
                xfs_iext_next(ifp, icur);
                xfs_iext_insert(ip, icur, &r[1], state);
                xfs_iext_insert(ip, icur, &r[0], state);
+               ifp->if_nextents += 2;
 
-               XFS_IFORK_NEXT_SET(ip, whichfork,
-                               XFS_IFORK_NEXTENTS(ip, whichfork) + 2);
                if (cur == NULL)
                        rval = XFS_ILOG_CORE | XFS_ILOG_DEXT;
                else {
@@ -2803,9 +2791,8 @@ xfs_bmap_add_extent_hole_real(
                xfs_iext_remove(ip, icur, state);
                xfs_iext_prev(ifp, icur);
                xfs_iext_update_extent(ip, state, icur, &left);
+               ifp->if_nextents--;
 
-               XFS_IFORK_NEXT_SET(ip, whichfork,
-                       XFS_IFORK_NEXTENTS(ip, whichfork) - 1);
                if (cur == NULL) {
                        rval = XFS_ILOG_CORE | xfs_ilog_fext(whichfork);
                } else {
@@ -2903,8 +2890,8 @@ xfs_bmap_add_extent_hole_real(
                 * Insert a new entry.
                 */
                xfs_iext_insert(ip, icur, new, state);
-               XFS_IFORK_NEXT_SET(ip, whichfork,
-                       XFS_IFORK_NEXTENTS(ip, whichfork) + 1);
+               ifp->if_nextents++;
+
                if (cur == NULL) {
                        rval = XFS_ILOG_CORE | xfs_ilog_fext(whichfork);
                } else {
@@ -4505,8 +4492,7 @@ xfs_bmapi_write(
                goto error0;
 
        ASSERT(XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE ||
-              XFS_IFORK_NEXTENTS(ip, whichfork) >
-               XFS_IFORK_MAXEXT(ip, whichfork));
+              ifp->if_nextents > XFS_IFORK_MAXEXT(ip, whichfork));
        xfs_bmapi_finish(&bma, whichfork, 0);
        xfs_bmap_validate_ret(orig_bno, orig_len, orig_flags, orig_mval,
                orig_nmap, *nmap);
@@ -5049,8 +5035,7 @@ xfs_bmap_del_extent_real(
         */
        if (tp->t_blk_res == 0 &&
            XFS_IFORK_FORMAT(ip, whichfork) == XFS_DINODE_FMT_EXTENTS &&
-           XFS_IFORK_NEXTENTS(ip, whichfork) >=
-                       XFS_IFORK_MAXEXT(ip, whichfork) &&
+           ifp->if_nextents >= XFS_IFORK_MAXEXT(ip, whichfork) &&
            del->br_startoff > got.br_startoff && del_endoff < got_endoff)
                return -ENOSPC;
 
@@ -5102,8 +5087,8 @@ xfs_bmap_del_extent_real(
                 */
                xfs_iext_remove(ip, icur, state);
                xfs_iext_prev(ifp, icur);
-               XFS_IFORK_NEXT_SET(ip, whichfork,
-                       XFS_IFORK_NEXTENTS(ip, whichfork) - 1);
+               ifp->if_nextents--;
+
                flags |= XFS_ILOG_CORE;
                if (!cur) {
                        flags |= xfs_ilog_fext(whichfork);
@@ -5211,8 +5196,8 @@ xfs_bmap_del_extent_real(
                        }
                } else
                        flags |= xfs_ilog_fext(whichfork);
-               XFS_IFORK_NEXT_SET(ip, whichfork,
-                       XFS_IFORK_NEXTENTS(ip, whichfork) + 1);
+
+               ifp->if_nextents++;
                xfs_iext_next(ifp, icur);
                xfs_iext_insert(ip, icur, &new, state);
                break;
@@ -5660,6 +5645,7 @@ xfs_bmse_merge(
        struct xfs_btree_cur            *cur,
        int                             *logflags)      /* output */
 {
+       struct xfs_ifork                *ifp = XFS_IFORK_PTR(ip, whichfork);
        struct xfs_bmbt_irec            new;
        xfs_filblks_t                   blockcount;
        int                             error, i;
@@ -5678,8 +5664,7 @@ xfs_bmse_merge(
         * Update the on-disk extent count, the btree if necessary and log the
         * inode.
         */
-       XFS_IFORK_NEXT_SET(ip, whichfork,
-                          XFS_IFORK_NEXTENTS(ip, whichfork) - 1);
+       ifp->if_nextents--;
        *logflags |= XFS_ILOG_CORE;
        if (!cur) {
                *logflags |= XFS_ILOG_DEXT;
@@ -5717,7 +5702,7 @@ xfs_bmse_merge(
 
 done:
        xfs_iext_remove(ip, icur, 0);
-       xfs_iext_prev(XFS_IFORK_PTR(ip, whichfork), icur);
+       xfs_iext_prev(ifp, icur);
        xfs_iext_update_extent(ip, xfs_bmap_fork_to_state(whichfork), icur,
                        &new);
 
@@ -6067,8 +6052,7 @@ xfs_bmap_split_extent(
        /* Add new extent */
        xfs_iext_next(ifp, &icur);
        xfs_iext_insert(ip, &icur, &new, 0);
-       XFS_IFORK_NEXT_SET(ip, whichfork,
-                          XFS_IFORK_NEXTENTS(ip, whichfork) + 1);
+       ifp->if_nextents++;
 
        if (cur) {
                error = xfs_bmbt_lookup_eq(cur, &new, &i);
index 8e41435cd5bc3488e6e85832612133ac8294018f..eaa2b47a8eb98dab44307e2731dc1710c4ec4569 100644 (file)
@@ -1101,7 +1101,7 @@ xfs_dir2_sf_to_block(
        ASSERT(ifp->if_bytes == dp->i_d.di_size);
        ASSERT(ifp->if_u1.if_data != NULL);
        ASSERT(dp->i_d.di_size >= xfs_dir2_sf_hdr_size(oldsfp->i8count));
-       ASSERT(dp->i_d.di_nextents == 0);
+       ASSERT(dp->i_df.if_nextents == 0);
 
        /*
         * Copy the directory into a temporary buffer.
index 41345a214496eb0ddf7f86a956697fa573f1eb1f..79d5b82083894ab084febd8d17a8f0af22288498 100644 (file)
@@ -242,8 +242,6 @@ xfs_inode_from_disk(
        to->di_size = be64_to_cpu(from->di_size);
        to->di_nblocks = be64_to_cpu(from->di_nblocks);
        to->di_extsize = be32_to_cpu(from->di_extsize);
-       to->di_nextents = be32_to_cpu(from->di_nextents);
-       to->di_anextents = be16_to_cpu(from->di_anextents);
        to->di_forkoff = from->di_forkoff;
        to->di_aformat  = from->di_aformat;
        to->di_dmevmask = be32_to_cpu(from->di_dmevmask);
@@ -308,8 +306,8 @@ xfs_inode_to_disk(
        to->di_size = cpu_to_be64(from->di_size);
        to->di_nblocks = cpu_to_be64(from->di_nblocks);
        to->di_extsize = cpu_to_be32(from->di_extsize);
-       to->di_nextents = cpu_to_be32(from->di_nextents);
-       to->di_anextents = cpu_to_be16(from->di_anextents);
+       to->di_nextents = cpu_to_be32(xfs_ifork_nextents(&ip->i_df));
+       to->di_anextents = cpu_to_be16(xfs_ifork_nextents(ip->i_afp));
        to->di_forkoff = from->di_forkoff;
        to->di_aformat = from->di_aformat;
        to->di_dmevmask = cpu_to_be32(from->di_dmevmask);
index e4cbcaf62a32b7ddf0a8a4202ae3d5f3e6ecc747..fecccfb26463c9a2f50666c2bd19bcafc17095f1 100644 (file)
@@ -22,8 +22,6 @@ struct xfs_icdinode {
        xfs_fsize_t     di_size;        /* number of bytes in file */
        xfs_rfsblock_t  di_nblocks;     /* # of direct & btree blocks used */
        xfs_extlen_t    di_extsize;     /* basic/minimum extent size for file */
-       xfs_extnum_t    di_nextents;    /* number of extents in data fork */
-       xfs_aextnum_t   di_anextents;   /* number of extents in attribute fork*/
        uint8_t         di_forkoff;     /* attr fork offs, <<3 for 64b align */
        int8_t          di_aformat;     /* format of attr fork's data */
        uint32_t        di_dmevmask;    /* DMIG event mask */
index 188b89b4af189da635a4ad274efe5ab67177e030..d7bde9e8f3e21bd05b2e0b05756dea1ced428c56 100644 (file)
@@ -186,12 +186,11 @@ xfs_iformat_btree(
         * or the number of extents is greater than the number of
         * blocks.
         */
-       if (unlikely(XFS_IFORK_NEXTENTS(ip, whichfork) <=
-                                       XFS_IFORK_MAXEXT(ip, whichfork) ||
+       if (unlikely(ifp->if_nextents <= XFS_IFORK_MAXEXT(ip, whichfork) ||
                     nrecs == 0 ||
                     XFS_BMDR_SPACE_CALC(nrecs) >
                                        XFS_DFORK_SIZE(dip, mp, whichfork) ||
-                    XFS_IFORK_NEXTENTS(ip, whichfork) > ip->i_d.di_nblocks) ||
+                    ifp->if_nextents > ip->i_d.di_nblocks) ||
                     level == 0 || level > XFS_BTREE_MAXLEVELS) {
                xfs_warn(mp, "corrupt inode %Lu (btree).",
                                        (unsigned long long) ip->i_ino);
@@ -227,6 +226,12 @@ xfs_iformat_data_fork(
        struct inode            *inode = VFS_I(ip);
        int                     error;
 
+       /*
+        * Initialize the extent count early, as the per-format routines may
+        * depend on it.
+        */
+       ip->i_df.if_nextents = be32_to_cpu(dip->di_nextents);
+
        switch (inode->i_mode & S_IFMT) {
        case S_IFIFO:
        case S_IFCHR:
@@ -279,7 +284,13 @@ xfs_iformat_attr_fork(
 {
        int                     error = 0;
 
+       /*
+        * Initialize the extent count early, as the per-format routines may
+        * depend on it.
+        */
        ip->i_afp = kmem_zone_zalloc(xfs_ifork_zone, KM_NOFS);
+       ip->i_afp->if_nextents = be16_to_cpu(dip->di_anextents);
+
        switch (dip->di_aformat) {
        case XFS_DINODE_FMT_LOCAL:
                error = xfs_iformat_local(ip, dip, XFS_ATTR_FORK,
@@ -615,7 +626,7 @@ xfs_iflush_fork(
                       !(iip->ili_fields & extflag[whichfork]));
                if ((iip->ili_fields & extflag[whichfork]) &&
                    (ifp->if_bytes > 0)) {
-                       ASSERT(XFS_IFORK_NEXTENTS(ip, whichfork) > 0);
+                       ASSERT(ifp->if_nextents > 0);
                        (void)xfs_iextents_copy(ip, (xfs_bmbt_rec_t *)cp,
                                whichfork);
                }
@@ -674,7 +685,6 @@ xfs_ifork_init_cow(
                                       KM_NOFS);
        ip->i_cowfp->if_flags = XFS_IFEXTENTS;
        ip->i_cformat = XFS_DINODE_FMT_EXTENTS;
-       ip->i_cnextents = 0;
 }
 
 /* Verify the inline contents of the data fork of an inode. */
index f46a8c1db596455df468301b97f3ed0631b37b22..a69d425fe68df8bd844c5fcbf08d37f4cd19484e 100644 (file)
@@ -23,6 +23,7 @@ struct xfs_ifork {
        } if_u1;
        short                   if_broot_bytes; /* bytes allocated for root */
        unsigned char           if_flags;       /* per-fork flags */
+       xfs_extnum_t            if_nextents;    /* # of extents in this fork */
 };
 
 /*
@@ -67,18 +68,6 @@ struct xfs_ifork {
                ((w) == XFS_ATTR_FORK ? \
                        ((ip)->i_d.di_aformat = (n)) : \
                        ((ip)->i_cformat = (n))))
-#define XFS_IFORK_NEXTENTS(ip,w) \
-       ((w) == XFS_DATA_FORK ? \
-               (ip)->i_d.di_nextents : \
-               ((w) == XFS_ATTR_FORK ? \
-                       (ip)->i_d.di_anextents : \
-                       (ip)->i_cnextents))
-#define XFS_IFORK_NEXT_SET(ip,w,n) \
-       ((w) == XFS_DATA_FORK ? \
-               ((ip)->i_d.di_nextents = (n)) : \
-               ((w) == XFS_ATTR_FORK ? \
-                       ((ip)->i_d.di_anextents = (n)) : \
-                       ((ip)->i_cnextents = (n))))
 #define XFS_IFORK_MAXEXT(ip, w) \
        (XFS_IFORK_SIZE(ip, w) / sizeof(xfs_bmbt_rec_t))
 
@@ -86,6 +75,13 @@ struct xfs_ifork {
        (XFS_IFORK_FORMAT((ip), (w)) == XFS_DINODE_FMT_EXTENTS || \
         XFS_IFORK_FORMAT((ip), (w)) == XFS_DINODE_FMT_BTREE)
 
+static inline xfs_extnum_t xfs_ifork_nextents(struct xfs_ifork *ifp)
+{
+       if (!ifp)
+               return 0;
+       return ifp->if_nextents;
+}
+
 struct xfs_ifork *xfs_iext_state_to_fork(struct xfs_inode *ip, int state);
 
 int            xfs_iformat_data_fork(struct xfs_inode *, struct xfs_dinode *);