]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs: devirtualize ->data_bestfree_p
authorChristoph Hellwig <hch@lst.de>
Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)
committerEric Sandeen <sandeen@redhat.com>
Wed, 22 Jan 2020 16:29:43 +0000 (11:29 -0500)
Source kernel commit: 1848b607a9ad084db0180118304b9af2be68384e

Replace the ->data_bestfree_p dir ops method with a directly called
xfs_dir2_data_bestfree_p helper that takes care of the differences
between the v4 and v5 on-disk format.

Signed-off-by: Christoph Hellwig <hch@lst.de>
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>
db/check.c
libxfs/libxfs_api_defs.h
libxfs/xfs_da_format.c
libxfs/xfs_dir2.h
libxfs/xfs_dir2_block.c
libxfs/xfs_dir2_data.c
libxfs/xfs_dir2_leaf.c
libxfs/xfs_dir2_node.c
libxfs/xfs_dir2_priv.h
repair/dir2.c
repair/phase6.c

index 4b162def026bc8dfbcdad431f04a6283aeb3db29..657102b928dd2e73efa68dcc6a0f851ab1c4b311 100644 (file)
@@ -2315,7 +2315,7 @@ process_data_dir_v2(
                return NULLFSINO;
        }
        db = xfs_dir2_da_to_db(mp->m_dir_geo, dabno);
-       bf = M_DIROPS(mp)->data_bestfree_p(data);
+       bf = libxfs_dir2_data_bestfree_p(mp, data);
        ptr = (char *)data + mp->m_dir_geo->data_entry_offset;
        if (be32_to_cpu(block->magic) == XFS_DIR2_BLOCK_MAGIC ||
            be32_to_cpu(block->magic) == XFS_DIR3_BLOCK_MAGIC) {
@@ -2541,7 +2541,7 @@ process_data_dir_v2_freefind(
        xfs_dir2_data_aoff_t    off;
 
        off = (xfs_dir2_data_aoff_t)((char *)dup - (char *)data);
-       bf = M_DIROPS(mp)->data_bestfree_p(data);
+       bf = libxfs_dir2_data_bestfree_p(mp, data);
        if (be16_to_cpu(dup->length) <
                        be16_to_cpu(bf[XFS_DIR2_DATA_FD_COUNT - 1].length))
                return NULL;
index e095b7d603b7e0bb7ffff53feb7e312750920a9f..cef7be331d1d2f89a6ddd7134c9beaaa12a78237 100644 (file)
@@ -75,6 +75,7 @@
 #define xfs_dir_init                   libxfs_dir_init
 #define xfs_dir_lookup                 libxfs_dir_lookup
 #define xfs_dir_replace                        libxfs_dir_replace
+#define xfs_dir2_data_bestfree_p       libxfs_dir2_data_bestfree_p
 #define xfs_dir2_leaf_hdr_from_disk    libxfs_dir2_leaf_hdr_from_disk
 #define xfs_dir2_free_hdr_from_disk    libxfs_dir2_free_hdr_from_disk
 #define xfs_dir2_isblock               libxfs_dir2_isblock
index 999fc0c275735a21d4e75fe19487d50c6dc26920..88759270b93ef0530112a2dbc27118baaa79ee38 100644 (file)
@@ -56,34 +56,19 @@ xfs_dir3_data_put_ftype(
        dep->name[dep->namelen] = type;
 }
 
-static struct xfs_dir2_data_free *
-xfs_dir2_data_bestfree_p(struct xfs_dir2_data_hdr *hdr)
-{
-       return hdr->bestfree;
-}
-
-static struct xfs_dir2_data_free *
-xfs_dir3_data_bestfree_p(struct xfs_dir2_data_hdr *hdr)
-{
-       return ((struct xfs_dir3_data_hdr *)hdr)->best_free;
-}
-
 static const struct xfs_dir_ops xfs_dir2_ops = {
        .data_get_ftype = xfs_dir2_data_get_ftype,
        .data_put_ftype = xfs_dir2_data_put_ftype,
-       .data_bestfree_p = xfs_dir2_data_bestfree_p,
 };
 
 static const struct xfs_dir_ops xfs_dir2_ftype_ops = {
        .data_get_ftype = xfs_dir3_data_get_ftype,
        .data_put_ftype = xfs_dir3_data_put_ftype,
-       .data_bestfree_p = xfs_dir2_data_bestfree_p,
 };
 
 static const struct xfs_dir_ops xfs_dir3_ops = {
        .data_get_ftype = xfs_dir3_data_get_ftype,
        .data_put_ftype = xfs_dir3_data_put_ftype,
-       .data_bestfree_p = xfs_dir3_data_bestfree_p,
 };
 
 /*
index 830c70a20761fb334a4aa7b433098a83c066d902..b50273b2d9706b8e2b6c923295364437abebd99e 100644 (file)
@@ -35,8 +35,6 @@ struct xfs_dir_ops {
        uint8_t (*data_get_ftype)(struct xfs_dir2_data_entry *dep);
        void    (*data_put_ftype)(struct xfs_dir2_data_entry *dep,
                                uint8_t ftype);
-       struct xfs_dir2_data_free *
-               (*data_bestfree_p)(struct xfs_dir2_data_hdr *hdr);
 };
 
 extern const struct xfs_dir_ops *
@@ -81,7 +79,6 @@ extern int xfs_dir2_shrink_inode(struct xfs_da_args *args, xfs_dir2_db_t db,
                                struct xfs_buf *bp);
 
 extern void xfs_dir2_data_freescan_int(struct xfs_mount *mp,
-               const struct xfs_dir_ops *ops,
                struct xfs_dir2_data_hdr *hdr, int *loghead);
 extern void xfs_dir2_data_freescan(struct xfs_inode *dp,
                struct xfs_dir2_data_hdr *hdr, int *loghead);
index 723c44520d8563a38081c0cb00d4e45d247c5bad..2a328e0136d749f78a5f4ceac61d90fe8d7fa9f8 100644 (file)
@@ -169,7 +169,7 @@ xfs_dir2_block_need_space(
        struct xfs_dir2_data_unused     *enddup = NULL;
 
        *compact = 0;
-       bf = dp->d_ops->data_bestfree_p(hdr);
+       bf = xfs_dir2_data_bestfree_p(dp->i_mount, hdr);
 
        /*
         * If there are stale entries we'll use one for the leaf.
@@ -1196,8 +1196,8 @@ xfs_dir2_sf_to_block(
                        *xfs_dir2_data_unused_tag_p(dup) = cpu_to_be16(offset);
                        xfs_dir2_data_log_unused(args, bp, dup);
                        xfs_dir2_data_freeinsert(hdr,
-                                                dp->d_ops->data_bestfree_p(hdr),
-                                                dup, &dummy);
+                                       xfs_dir2_data_bestfree_p(mp, hdr),
+                                       dup, &dummy);
                        offset += be16_to_cpu(dup->length);
                        continue;
                }
index 8e1af963e866afd151365645ef53c0ecced4ee1d..5fc2e2991e23ddc093d813087b5ca768d2d9a326 100644 (file)
@@ -22,6 +22,16 @@ static xfs_failaddr_t xfs_dir2_data_freefind_verify(
                struct xfs_dir2_data_unused *dup,
                struct xfs_dir2_data_free **bf_ent);
 
+struct xfs_dir2_data_free *
+xfs_dir2_data_bestfree_p(
+       struct xfs_mount                *mp,
+       struct xfs_dir2_data_hdr        *hdr)
+{
+       if (xfs_sb_version_hascrc(&mp->m_sb))
+               return ((struct xfs_dir3_data_hdr *)hdr)->best_free;
+       return hdr->bestfree;
+}
+
 /*
  * Pointer to an entry's tag word.
  */
@@ -118,7 +128,7 @@ __xfs_dir3_data_check(
        /*
         * Account for zero bestfree entries.
         */
-       bf = ops->data_bestfree_p(hdr);
+       bf = xfs_dir2_data_bestfree_p(mp, hdr);
        count = lastfree = freeseen = 0;
        if (!bf[0].length) {
                if (bf[0].offset)
@@ -578,12 +588,11 @@ xfs_dir2_data_freeremove(
 void
 xfs_dir2_data_freescan_int(
        struct xfs_mount                *mp,
-       const struct xfs_dir_ops        *ops,
        struct xfs_dir2_data_hdr        *hdr,
        int                             *loghead)
 {
        struct xfs_da_geometry          *geo = mp->m_dir_geo;
-       struct xfs_dir2_data_free       *bf = ops->data_bestfree_p(hdr);
+       struct xfs_dir2_data_free       *bf = xfs_dir2_data_bestfree_p(mp, hdr);
        void                            *addr = hdr;
        unsigned int                    offset = geo->data_entry_offset;
        unsigned int                    end;
@@ -630,7 +639,7 @@ xfs_dir2_data_freescan(
        struct xfs_dir2_data_hdr *hdr,
        int                     *loghead)
 {
-       return xfs_dir2_data_freescan_int(dp->i_mount, dp->d_ops, hdr, loghead);
+       return xfs_dir2_data_freescan_int(dp->i_mount, hdr, loghead);
 }
 
 /*
@@ -680,7 +689,7 @@ xfs_dir3_data_init(
        } else
                hdr->magic = cpu_to_be32(XFS_DIR2_DATA_MAGIC);
 
-       bf = dp->d_ops->data_bestfree_p(hdr);
+       bf = xfs_dir2_data_bestfree_p(mp, hdr);
        bf[0].offset = cpu_to_be16(geo->data_entry_offset);
        bf[0].length = cpu_to_be16(geo->blksize - geo->data_entry_offset);
        for (i = 1; i < XFS_DIR2_DATA_FD_COUNT; i++) {
@@ -838,7 +847,7 @@ xfs_dir2_data_make_free(
         * Previous and following entries are both free,
         * merge everything into a single free entry.
         */
-       bf = args->dp->d_ops->data_bestfree_p(hdr);
+       bf = xfs_dir2_data_bestfree_p(args->dp->i_mount, hdr);
        if (prevdup && postdup) {
                xfs_dir2_data_free_t    *dfp2;  /* another bestfree pointer */
 
@@ -1029,7 +1038,7 @@ xfs_dir2_data_use_free(
         * Look up the entry in the bestfree table.
         */
        oldlen = be16_to_cpu(dup->length);
-       bf = args->dp->d_ops->data_bestfree_p(hdr);
+       bf = xfs_dir2_data_bestfree_p(args->dp->i_mount, hdr);
        dfp = xfs_dir2_data_freefind(hdr, bf, dup);
        ASSERT(dfp || oldlen <= be16_to_cpu(bf[2].length));
        /*
index ec7d3864ee5cb0478d3052063f739980561d14f1..10fadb42e2e7bd05136e11972b63f21bf3c94231 100644 (file)
@@ -423,7 +423,7 @@ xfs_dir2_block_to_leaf(
        xfs_dir3_data_check(dp, dbp);
        btp = xfs_dir2_block_tail_p(args->geo, hdr);
        blp = xfs_dir2_block_leaf_p(btp);
-       bf = dp->d_ops->data_bestfree_p(hdr);
+       bf = xfs_dir2_data_bestfree_p(dp->i_mount, hdr);
 
        /*
         * Set the counts in the leaf header.
@@ -821,7 +821,7 @@ xfs_dir2_leaf_addname(
                else
                        xfs_dir3_leaf_log_bests(args, lbp, use_block, use_block);
                hdr = dbp->b_addr;
-               bf = dp->d_ops->data_bestfree_p(hdr);
+               bf = xfs_dir2_data_bestfree_p(dp->i_mount, hdr);
                bestsp[use_block] = bf[0].length;
                grown = 1;
        } else {
@@ -837,7 +837,7 @@ xfs_dir2_leaf_addname(
                        return error;
                }
                hdr = dbp->b_addr;
-               bf = dp->d_ops->data_bestfree_p(hdr);
+               bf = xfs_dir2_data_bestfree_p(dp->i_mount, hdr);
                grown = 0;
        }
        /*
@@ -1374,7 +1374,7 @@ xfs_dir2_leaf_removename(
        leaf = lbp->b_addr;
        hdr = dbp->b_addr;
        xfs_dir3_data_check(dp, dbp);
-       bf = dp->d_ops->data_bestfree_p(hdr);
+       bf = xfs_dir2_data_bestfree_p(dp->i_mount, hdr);
 
        /*
         * Point to the leaf entry, use that to point to the data entry.
@@ -1618,7 +1618,8 @@ xfs_dir2_leaf_trim_data(
 #ifdef DEBUG
 {
        struct xfs_dir2_data_hdr *hdr = dbp->b_addr;
-       struct xfs_dir2_data_free *bf = dp->d_ops->data_bestfree_p(hdr);
+       struct xfs_dir2_data_free *bf =
+               xfs_dir2_data_bestfree_p(dp->i_mount, hdr);
 
        ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) ||
               hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC));
index a2b3870102b5445b4a250babcbec3850727106f4..033349e1acdd3edcb297e61d8f09f2e659bf1935 100644 (file)
@@ -1314,7 +1314,7 @@ xfs_dir2_leafn_remove(
        dbp = dblk->bp;
        hdr = dbp->b_addr;
        dep = (xfs_dir2_data_entry_t *)((char *)hdr + off);
-       bf = dp->d_ops->data_bestfree_p(hdr);
+       bf = xfs_dir2_data_bestfree_p(dp->i_mount, hdr);
        longest = be16_to_cpu(bf[0].length);
        needlog = needscan = 0;
        xfs_dir2_data_make_free(args, dbp, off,
@@ -1772,7 +1772,7 @@ xfs_dir2_node_add_datablk(
        }
 
        /* Update the freespace value for the new block in the table. */
-       bf = dp->d_ops->data_bestfree_p(dbp->b_addr);
+       bf = xfs_dir2_data_bestfree_p(mp, dbp->b_addr);
        hdr->bests[*findex] = bf[0].length;
 
        *dbpp = dbp;
@@ -1945,7 +1945,7 @@ xfs_dir2_node_addname_int(
 
        /* setup for data block up now */
        hdr = dbp->b_addr;
-       bf = dp->d_ops->data_bestfree_p(hdr);
+       bf = xfs_dir2_data_bestfree_p(dp->i_mount, hdr);
        ASSERT(be16_to_cpu(bf[0].length) >= length);
 
        /* Point to the existing unused space. */
index 5e938cd61c5334aadc608b22f43bd1bf8caa2728..c80eb6f0ca84b52733c3bbecfdb10815b9cae254 100644 (file)
@@ -57,6 +57,8 @@ extern int xfs_dir2_leaf_to_block(struct xfs_da_args *args,
                struct xfs_buf *lbp, struct xfs_buf *dbp);
 
 /* xfs_dir2_data.c */
+struct xfs_dir2_data_free *xfs_dir2_data_bestfree_p(struct xfs_mount *mp,
+               struct xfs_dir2_data_hdr *hdr);
 __be16 *xfs_dir2_data_entry_tag_p(struct xfs_mount *mp,
                struct xfs_dir2_data_entry *dep);
 
index 623b3da0c376ba4881bdb6867caaa9c6ec4ab8a4..9fc980a2b4b10fff492ed5e3d94ca9abd6b74e24 100644 (file)
@@ -579,7 +579,7 @@ process_dir2_data(
        xfs_ino_t               ent_ino;
 
        d = bp->b_addr;
-       bf = M_DIROPS(mp)->data_bestfree_p(d);
+       bf = libxfs_dir2_data_bestfree_p(mp, d);
        ptr = (char *)d + mp->m_dir_geo->data_entry_offset;
        badbest = lastfree = freeseen = 0;
        if (be16_to_cpu(bf[0].length) == 0) {
@@ -928,7 +928,7 @@ _("bad bestfree table in block %u in directory inode %" PRIu64 ": "),
                        da_bno, ino);
                if (!no_modify) {
                        do_warn(_("repairing table\n"));
-                       libxfs_dir2_data_freescan_int(mp, M_DIROPS(mp), d, &i);
+                       libxfs_dir2_data_freescan_int(mp, d, &i);
                        *dirty = 1;
                } else {
                        do_warn(_("would repair table\n"));
index 81eb62994a5044f2eae84a800d3ac216d82d0948..65b3c4048738939a9f7665e3c1203af5a3c1a4ca 100644 (file)
@@ -1940,7 +1940,7 @@ _("entry \"%s\" in dir inode %" PRIu64 " inconsistent with .. value (%" PRIu64 "
        }
        *num_illegal += nbad;
        if (needscan)
-               libxfs_dir2_data_freescan_int(mp, M_DIROPS(mp), d, &i);
+               libxfs_dir2_data_freescan_int(mp, d, &i);
        if (needlog)
                libxfs_dir2_data_log_header(&da, bp);
        error = -libxfs_trans_commit(tp);
@@ -1949,7 +1949,7 @@ _("entry \"%s\" in dir inode %" PRIu64 " inconsistent with .. value (%" PRIu64 "
 _("directory block fixing failed (%d)\n"), error);
 
        /* record the largest free space in the freetab for later checking */
-       bf = M_DIROPS(mp)->data_bestfree_p(d);
+       bf = libxfs_dir2_data_bestfree_p(mp, d);
        freetab->ents[db].v = be16_to_cpu(bf[0].length);
        freetab->ents[db].s = 0;
 }