Commit fdbb8c5b authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Darrick J. Wong
Browse files

xfs: devirtualize ->data_entsize



Replace the ->data_entsize dir ops method with a directly called
xfs_dir2_data_entsize helper that takes care of the differences between
the directory format with and without the file type field.

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 5c072127
Loading
Loading
Loading
Loading
+8 −14
Original line number Diff line number Diff line
@@ -41,18 +41,15 @@
		 sizeof(xfs_dir2_data_off_t) + sizeof(uint8_t)),	\
		XFS_DIR2_DATA_ALIGN)

static int
int
xfs_dir2_data_entsize(
	struct xfs_mount	*mp,
	int			n)
{
	return XFS_DIR2_DATA_ENTSIZE(n);
}

static int
xfs_dir3_data_entsize(
	int			n)
{
	if (xfs_sb_version_hasftype(&mp->m_sb))
		return XFS_DIR3_DATA_ENTSIZE(n);
	else
		return XFS_DIR2_DATA_ENTSIZE(n);
}

static uint8_t
@@ -100,7 +97,7 @@ xfs_dir2_data_entry_tag_p(
	struct xfs_dir2_data_entry *dep)
{
	return (__be16 *)((char *)dep +
		xfs_dir2_data_entsize(dep->namelen) - sizeof(__be16));
		XFS_DIR2_DATA_ENTSIZE(dep->namelen) - sizeof(__be16));
}

static __be16 *
@@ -108,7 +105,7 @@ xfs_dir3_data_entry_tag_p(
	struct xfs_dir2_data_entry *dep)
{
	return (__be16 *)((char *)dep +
		xfs_dir3_data_entsize(dep->namelen) - sizeof(__be16));
		XFS_DIR3_DATA_ENTSIZE(dep->namelen) - sizeof(__be16));
}

static struct xfs_dir2_data_free *
@@ -124,7 +121,6 @@ xfs_dir3_data_bestfree_p(struct xfs_dir2_data_hdr *hdr)
}

static const struct xfs_dir_ops xfs_dir2_ops = {
	.data_entsize = xfs_dir2_data_entsize,
	.data_get_ftype = xfs_dir2_data_get_ftype,
	.data_put_ftype = xfs_dir2_data_put_ftype,
	.data_entry_tag_p = xfs_dir2_data_entry_tag_p,
@@ -137,7 +133,6 @@ static const struct xfs_dir_ops xfs_dir2_ops = {
};

static const struct xfs_dir_ops xfs_dir2_ftype_ops = {
	.data_entsize = xfs_dir3_data_entsize,
	.data_get_ftype = xfs_dir3_data_get_ftype,
	.data_put_ftype = xfs_dir3_data_put_ftype,
	.data_entry_tag_p = xfs_dir3_data_entry_tag_p,
@@ -150,7 +145,6 @@ static const struct xfs_dir_ops xfs_dir2_ftype_ops = {
};

static const struct xfs_dir_ops xfs_dir3_ops = {
	.data_entsize = xfs_dir3_data_entsize,
	.data_get_ftype = xfs_dir3_data_get_ftype,
	.data_put_ftype = xfs_dir3_data_put_ftype,
	.data_entry_tag_p = xfs_dir3_data_entry_tag_p,
+1 −2
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ extern unsigned char xfs_mode_to_ftype(int mode);
 * directory operations vector for encode/decode routines
 */
struct xfs_dir_ops {
	int	(*data_entsize)(int len);
	uint8_t (*data_get_ftype)(struct xfs_dir2_data_entry *dep);
	void	(*data_put_ftype)(struct xfs_dir2_data_entry *dep,
				uint8_t ftype);
@@ -85,7 +84,7 @@ extern int xfs_dir2_isleaf(struct xfs_da_args *args, int *r);
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_da_geometry *geo,
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,
+5 −4
Original line number Diff line number Diff line
@@ -355,7 +355,7 @@ xfs_dir2_block_addname(
	if (error)
		return error;

	len = dp->d_ops->data_entsize(args->namelen);
	len = xfs_dir2_data_entsize(dp->i_mount, args->namelen);

	/*
	 * Set up pointers to parts of the block.
@@ -791,7 +791,8 @@ xfs_dir2_block_removename(
	needlog = needscan = 0;
	xfs_dir2_data_make_free(args, bp,
		(xfs_dir2_data_aoff_t)((char *)dep - (char *)hdr),
		dp->d_ops->data_entsize(dep->namelen), &needlog, &needscan);
		xfs_dir2_data_entsize(dp->i_mount, dep->namelen), &needlog,
		&needscan);
	/*
	 * Fix up the block tail.
	 */
@@ -1149,7 +1150,7 @@ xfs_dir2_sf_to_block(
	xfs_dir2_data_log_entry(args, bp, dep);
	blp[0].hashval = cpu_to_be32(xfs_dir_hash_dot);
	blp[0].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(offset));
	offset += dp->d_ops->data_entsize(dep->namelen);
	offset += xfs_dir2_data_entsize(mp, dep->namelen);

	/*
	 * Create entry for ..
@@ -1164,7 +1165,7 @@ xfs_dir2_sf_to_block(
	xfs_dir2_data_log_entry(args, bp, dep);
	blp[1].hashval = cpu_to_be32(xfs_dir_hash_dotdot);
	blp[1].address = cpu_to_be32(xfs_dir2_byte_to_dataptr(offset));
	offset += dp->d_ops->data_entsize(dep->namelen);
	offset += xfs_dir2_data_entsize(mp, dep->namelen);

	/*
	 * Loop over existing entries, stuff them in.
+7 −7
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
#include "xfs_mount.h"
#include "xfs_inode.h"
#include "xfs_dir2.h"
#include "xfs_dir2_priv.h"
#include "xfs_error.h"
#include "xfs_trans.h"
#include "xfs_buf_item.h"
@@ -179,7 +180,7 @@ __xfs_dir3_data_check(
			return __this_address;
		if (xfs_dir_ino_validate(mp, be64_to_cpu(dep->inumber)))
			return __this_address;
		if (offset + ops->data_entsize(dep->namelen) > end)
		if (offset + xfs_dir2_data_entsize(mp, dep->namelen) > end)
			return __this_address;
		if (be16_to_cpu(*ops->data_entry_tag_p(dep)) != offset)
			return __this_address;
@@ -203,7 +204,7 @@ __xfs_dir3_data_check(
			if (i >= be32_to_cpu(btp->count))
				return __this_address;
		}
		offset += ops->data_entsize(dep->namelen);
		offset += xfs_dir2_data_entsize(mp, dep->namelen);
	}
	/*
	 * Need to have seen all the entries and all the bestfree slots.
@@ -567,7 +568,7 @@ xfs_dir2_data_freeremove(
 */
void
xfs_dir2_data_freescan_int(
	struct xfs_da_geometry		*geo,
	struct xfs_mount		*mp,
	const struct xfs_dir_ops	*ops,
	struct xfs_dir2_data_hdr	*hdr,
	int				*loghead)
@@ -588,7 +589,7 @@ xfs_dir2_data_freescan_int(
	memset(bf, 0, sizeof(*bf) * XFS_DIR2_DATA_FD_COUNT);
	*loghead = 1;

	end = xfs_dir3_data_end_offset(geo, addr);
	end = xfs_dir3_data_end_offset(mp->m_dir_geo, addr);
	while (offset < end) {
		struct xfs_dir2_data_unused	*dup = addr + offset;
		struct xfs_dir2_data_entry	*dep = addr + offset;
@@ -608,7 +609,7 @@ xfs_dir2_data_freescan_int(
		 * For active entries, check their tags and skip them.
		 */
		ASSERT(offset == be16_to_cpu(*ops->data_entry_tag_p(dep)));
		offset += ops->data_entsize(dep->namelen);
		offset += xfs_dir2_data_entsize(mp, dep->namelen);
	}
}

@@ -618,8 +619,7 @@ xfs_dir2_data_freescan(
	struct xfs_dir2_data_hdr *hdr,
	int			*loghead)
{
	return xfs_dir2_data_freescan_int(dp->i_mount->m_dir_geo, dp->d_ops,
			hdr, loghead);
	return xfs_dir2_data_freescan_int(dp->i_mount, dp->d_ops, hdr, loghead);
}

/*
+3 −2
Original line number Diff line number Diff line
@@ -660,7 +660,7 @@ xfs_dir2_leaf_addname(
	xfs_dir2_leaf_hdr_from_disk(dp->i_mount, &leafhdr, leaf);
	ents = leafhdr.ents;
	bestsp = xfs_dir2_leaf_bests_p(ltp);
	length = dp->d_ops->data_entsize(args->namelen);
	length = xfs_dir2_data_entsize(dp->i_mount, args->namelen);

	/*
	 * See if there are any entries with the same hash value
@@ -1397,7 +1397,8 @@ xfs_dir2_leaf_removename(
	 */
	xfs_dir2_data_make_free(args, dbp,
		(xfs_dir2_data_aoff_t)((char *)dep - (char *)hdr),
		dp->d_ops->data_entsize(dep->namelen), &needlog, &needscan);
		xfs_dir2_data_entsize(dp->i_mount, dep->namelen), &needlog,
		&needscan);
	/*
	 * We just mark the leaf entry stale by putting a null in it.
	 */
Loading