Commit 1848b607 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong

xfs: devirtualize ->data_bestfree_p

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: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: default avatarDarrick J. Wong <darrick.wong@oracle.com>
parent 711c7dbf
...@@ -56,34 +56,19 @@ xfs_dir3_data_put_ftype( ...@@ -56,34 +56,19 @@ xfs_dir3_data_put_ftype(
dep->name[dep->namelen] = type; 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 = { static const struct xfs_dir_ops xfs_dir2_ops = {
.data_get_ftype = xfs_dir2_data_get_ftype, .data_get_ftype = xfs_dir2_data_get_ftype,
.data_put_ftype = xfs_dir2_data_put_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 = { static const struct xfs_dir_ops xfs_dir2_ftype_ops = {
.data_get_ftype = xfs_dir3_data_get_ftype, .data_get_ftype = xfs_dir3_data_get_ftype,
.data_put_ftype = xfs_dir3_data_put_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 = { static const struct xfs_dir_ops xfs_dir3_ops = {
.data_get_ftype = xfs_dir3_data_get_ftype, .data_get_ftype = xfs_dir3_data_get_ftype,
.data_put_ftype = xfs_dir3_data_put_ftype, .data_put_ftype = xfs_dir3_data_put_ftype,
.data_bestfree_p = xfs_dir3_data_bestfree_p,
}; };
/* /*
......
...@@ -35,8 +35,6 @@ struct xfs_dir_ops { ...@@ -35,8 +35,6 @@ struct xfs_dir_ops {
uint8_t (*data_get_ftype)(struct xfs_dir2_data_entry *dep); uint8_t (*data_get_ftype)(struct xfs_dir2_data_entry *dep);
void (*data_put_ftype)(struct xfs_dir2_data_entry *dep, void (*data_put_ftype)(struct xfs_dir2_data_entry *dep,
uint8_t ftype); uint8_t ftype);
struct xfs_dir2_data_free *
(*data_bestfree_p)(struct xfs_dir2_data_hdr *hdr);
}; };
extern const struct xfs_dir_ops * 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, ...@@ -81,7 +79,6 @@ extern int xfs_dir2_shrink_inode(struct xfs_da_args *args, xfs_dir2_db_t db,
struct xfs_buf *bp); struct xfs_buf *bp);
extern void xfs_dir2_data_freescan_int(struct xfs_mount *mp, 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); struct xfs_dir2_data_hdr *hdr, int *loghead);
extern void xfs_dir2_data_freescan(struct xfs_inode *dp, extern void xfs_dir2_data_freescan(struct xfs_inode *dp,
struct xfs_dir2_data_hdr *hdr, int *loghead); struct xfs_dir2_data_hdr *hdr, int *loghead);
......
...@@ -172,7 +172,7 @@ xfs_dir2_block_need_space( ...@@ -172,7 +172,7 @@ xfs_dir2_block_need_space(
struct xfs_dir2_data_unused *enddup = NULL; struct xfs_dir2_data_unused *enddup = NULL;
*compact = 0; *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. * If there are stale entries we'll use one for the leaf.
...@@ -1199,8 +1199,8 @@ xfs_dir2_sf_to_block( ...@@ -1199,8 +1199,8 @@ xfs_dir2_sf_to_block(
*xfs_dir2_data_unused_tag_p(dup) = cpu_to_be16(offset); *xfs_dir2_data_unused_tag_p(dup) = cpu_to_be16(offset);
xfs_dir2_data_log_unused(args, bp, dup); xfs_dir2_data_log_unused(args, bp, dup);
xfs_dir2_data_freeinsert(hdr, xfs_dir2_data_freeinsert(hdr,
dp->d_ops->data_bestfree_p(hdr), xfs_dir2_data_bestfree_p(mp, hdr),
dup, &dummy); dup, &dummy);
offset += be16_to_cpu(dup->length); offset += be16_to_cpu(dup->length);
continue; continue;
} }
......
...@@ -25,6 +25,16 @@ static xfs_failaddr_t xfs_dir2_data_freefind_verify( ...@@ -25,6 +25,16 @@ static xfs_failaddr_t xfs_dir2_data_freefind_verify(
struct xfs_dir2_data_unused *dup, struct xfs_dir2_data_unused *dup,
struct xfs_dir2_data_free **bf_ent); 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. * Pointer to an entry's tag word.
*/ */
...@@ -121,7 +131,7 @@ __xfs_dir3_data_check( ...@@ -121,7 +131,7 @@ __xfs_dir3_data_check(
/* /*
* Account for zero bestfree entries. * Account for zero bestfree entries.
*/ */
bf = ops->data_bestfree_p(hdr); bf = xfs_dir2_data_bestfree_p(mp, hdr);
count = lastfree = freeseen = 0; count = lastfree = freeseen = 0;
if (!bf[0].length) { if (!bf[0].length) {
if (bf[0].offset) if (bf[0].offset)
...@@ -581,12 +591,11 @@ xfs_dir2_data_freeremove( ...@@ -581,12 +591,11 @@ xfs_dir2_data_freeremove(
void void
xfs_dir2_data_freescan_int( xfs_dir2_data_freescan_int(
struct xfs_mount *mp, struct xfs_mount *mp,
const struct xfs_dir_ops *ops,
struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_hdr *hdr,
int *loghead) int *loghead)
{ {
struct xfs_da_geometry *geo = mp->m_dir_geo; 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; void *addr = hdr;
unsigned int offset = geo->data_entry_offset; unsigned int offset = geo->data_entry_offset;
unsigned int end; unsigned int end;
...@@ -633,7 +642,7 @@ xfs_dir2_data_freescan( ...@@ -633,7 +642,7 @@ xfs_dir2_data_freescan(
struct xfs_dir2_data_hdr *hdr, struct xfs_dir2_data_hdr *hdr,
int *loghead) 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);
} }
/* /*
...@@ -683,7 +692,7 @@ xfs_dir3_data_init( ...@@ -683,7 +692,7 @@ xfs_dir3_data_init(
} else } else
hdr->magic = cpu_to_be32(XFS_DIR2_DATA_MAGIC); 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].offset = cpu_to_be16(geo->data_entry_offset);
bf[0].length = cpu_to_be16(geo->blksize - 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++) { for (i = 1; i < XFS_DIR2_DATA_FD_COUNT; i++) {
...@@ -841,7 +850,7 @@ xfs_dir2_data_make_free( ...@@ -841,7 +850,7 @@ xfs_dir2_data_make_free(
* Previous and following entries are both free, * Previous and following entries are both free,
* merge everything into a single free entry. * 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) { if (prevdup && postdup) {
xfs_dir2_data_free_t *dfp2; /* another bestfree pointer */ xfs_dir2_data_free_t *dfp2; /* another bestfree pointer */
...@@ -1032,7 +1041,7 @@ xfs_dir2_data_use_free( ...@@ -1032,7 +1041,7 @@ xfs_dir2_data_use_free(
* Look up the entry in the bestfree table. * Look up the entry in the bestfree table.
*/ */
oldlen = be16_to_cpu(dup->length); 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); dfp = xfs_dir2_data_freefind(hdr, bf, dup);
ASSERT(dfp || oldlen <= be16_to_cpu(bf[2].length)); ASSERT(dfp || oldlen <= be16_to_cpu(bf[2].length));
/* /*
......
...@@ -425,7 +425,7 @@ xfs_dir2_block_to_leaf( ...@@ -425,7 +425,7 @@ xfs_dir2_block_to_leaf(
xfs_dir3_data_check(dp, dbp); xfs_dir3_data_check(dp, dbp);
btp = xfs_dir2_block_tail_p(args->geo, hdr); btp = xfs_dir2_block_tail_p(args->geo, hdr);
blp = xfs_dir2_block_leaf_p(btp); 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. * Set the counts in the leaf header.
...@@ -823,7 +823,7 @@ xfs_dir2_leaf_addname( ...@@ -823,7 +823,7 @@ xfs_dir2_leaf_addname(
else else
xfs_dir3_leaf_log_bests(args, lbp, use_block, use_block); xfs_dir3_leaf_log_bests(args, lbp, use_block, use_block);
hdr = dbp->b_addr; 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; bestsp[use_block] = bf[0].length;
grown = 1; grown = 1;
} else { } else {
...@@ -839,7 +839,7 @@ xfs_dir2_leaf_addname( ...@@ -839,7 +839,7 @@ xfs_dir2_leaf_addname(
return error; return error;
} }
hdr = dbp->b_addr; hdr = dbp->b_addr;
bf = dp->d_ops->data_bestfree_p(hdr); bf = xfs_dir2_data_bestfree_p(dp->i_mount, hdr);
grown = 0; grown = 0;
} }
/* /*
...@@ -1376,7 +1376,7 @@ xfs_dir2_leaf_removename( ...@@ -1376,7 +1376,7 @@ xfs_dir2_leaf_removename(
leaf = lbp->b_addr; leaf = lbp->b_addr;
hdr = dbp->b_addr; hdr = dbp->b_addr;
xfs_dir3_data_check(dp, dbp); 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. * Point to the leaf entry, use that to point to the data entry.
...@@ -1620,7 +1620,8 @@ xfs_dir2_leaf_trim_data( ...@@ -1620,7 +1620,8 @@ xfs_dir2_leaf_trim_data(
#ifdef DEBUG #ifdef DEBUG
{ {
struct xfs_dir2_data_hdr *hdr = dbp->b_addr; 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) || ASSERT(hdr->magic == cpu_to_be32(XFS_DIR2_DATA_MAGIC) ||
hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC)); hdr->magic == cpu_to_be32(XFS_DIR3_DATA_MAGIC));
......
...@@ -1317,7 +1317,7 @@ xfs_dir2_leafn_remove( ...@@ -1317,7 +1317,7 @@ xfs_dir2_leafn_remove(
dbp = dblk->bp; dbp = dblk->bp;
hdr = dbp->b_addr; hdr = dbp->b_addr;
dep = (xfs_dir2_data_entry_t *)((char *)hdr + off); 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); longest = be16_to_cpu(bf[0].length);
needlog = needscan = 0; needlog = needscan = 0;
xfs_dir2_data_make_free(args, dbp, off, xfs_dir2_data_make_free(args, dbp, off,
...@@ -1775,7 +1775,7 @@ xfs_dir2_node_add_datablk( ...@@ -1775,7 +1775,7 @@ xfs_dir2_node_add_datablk(
} }
/* Update the freespace value for the new block in the table. */ /* 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; hdr->bests[*findex] = bf[0].length;
*dbpp = dbp; *dbpp = dbp;
...@@ -1948,7 +1948,7 @@ xfs_dir2_node_addname_int( ...@@ -1948,7 +1948,7 @@ xfs_dir2_node_addname_int(
/* setup for data block up now */ /* setup for data block up now */
hdr = dbp->b_addr; 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); ASSERT(be16_to_cpu(bf[0].length) >= length);
/* Point to the existing unused space. */ /* Point to the existing unused space. */
......
...@@ -57,6 +57,8 @@ extern int xfs_dir2_leaf_to_block(struct xfs_da_args *args, ...@@ -57,6 +57,8 @@ extern int xfs_dir2_leaf_to_block(struct xfs_da_args *args,
struct xfs_buf *lbp, struct xfs_buf *dbp); struct xfs_buf *lbp, struct xfs_buf *dbp);
/* xfs_dir2_data.c */ /* 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, __be16 *xfs_dir2_data_entry_tag_p(struct xfs_mount *mp,
struct xfs_dir2_data_entry *dep); struct xfs_dir2_data_entry *dep);
......
...@@ -330,7 +330,6 @@ xchk_directory_data_bestfree( ...@@ -330,7 +330,6 @@ xchk_directory_data_bestfree(
struct xfs_buf *bp; struct xfs_buf *bp;
struct xfs_dir2_data_free *bf; struct xfs_dir2_data_free *bf;
struct xfs_mount *mp = sc->mp; struct xfs_mount *mp = sc->mp;
const struct xfs_dir_ops *d_ops;
u16 tag; u16 tag;
unsigned int nr_bestfrees = 0; unsigned int nr_bestfrees = 0;
unsigned int nr_frees = 0; unsigned int nr_frees = 0;
...@@ -340,8 +339,6 @@ xchk_directory_data_bestfree( ...@@ -340,8 +339,6 @@ xchk_directory_data_bestfree(
unsigned int end; unsigned int end;
int error; int error;
d_ops = sc->ip->d_ops;
if (is_block) { if (is_block) {
/* dir block format */ /* dir block format */
if (lblk != XFS_B_TO_FSBT(mp, XFS_DIR2_DATA_OFFSET)) if (lblk != XFS_B_TO_FSBT(mp, XFS_DIR2_DATA_OFFSET))
...@@ -361,7 +358,7 @@ xchk_directory_data_bestfree( ...@@ -361,7 +358,7 @@ xchk_directory_data_bestfree(
goto out_buf; goto out_buf;
/* Do the bestfrees correspond to actual free space? */ /* Do the bestfrees correspond to actual free space? */
bf = d_ops->data_bestfree_p(bp->b_addr); bf = xfs_dir2_data_bestfree_p(mp, bp->b_addr);
smallest_bestfree = UINT_MAX; smallest_bestfree = UINT_MAX;
for (dfp = &bf[0]; dfp < &bf[XFS_DIR2_DATA_FD_COUNT]; dfp++) { for (dfp = &bf[0]; dfp < &bf[XFS_DIR2_DATA_FD_COUNT]; dfp++) {
offset = be16_to_cpu(dfp->offset); offset = be16_to_cpu(dfp->offset);
...@@ -468,7 +465,7 @@ xchk_directory_check_freesp( ...@@ -468,7 +465,7 @@ xchk_directory_check_freesp(
{ {
struct xfs_dir2_data_free *dfp; struct xfs_dir2_data_free *dfp;
dfp = sc->ip->d_ops->data_bestfree_p(dbp->b_addr); dfp = xfs_dir2_data_bestfree_p(sc->mp, dbp->b_addr);
if (len != be16_to_cpu(dfp->length)) if (len != be16_to_cpu(dfp->length))
xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, lblk); xchk_fblock_set_corrupt(sc, XFS_DATA_FORK, lblk);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment