From: "Darrick J. Wong" <djwong@kernel.org>
To: Christoph Hellwig <hch@lst.de>
Cc: Chandan Babu R <chandan.babu@oracle.com>, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 11/16] xfs: add xfs_dir2_block_overhead helper
Date: Wed, 1 May 2024 14:27:58 -0700 [thread overview]
Message-ID: <20240501212758.GZ360919@frogsfrogsfrogs> (raw)
In-Reply-To: <20240430124926.1775355-12-hch@lst.de>
On Tue, Apr 30, 2024 at 02:49:21PM +0200, Christoph Hellwig wrote:
> Add a common helper for the calculation of the overhead when converting
> a shortform to block format directory.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> fs/xfs/libxfs/xfs_dir2_block.c | 4 ++--
> fs/xfs/libxfs/xfs_dir2_priv.h | 12 ++++++++++++
> fs/xfs/libxfs/xfs_dir2_sf.c | 12 ++++--------
> 3 files changed, 18 insertions(+), 10 deletions(-)
>
> diff --git a/fs/xfs/libxfs/xfs_dir2_block.c b/fs/xfs/libxfs/xfs_dir2_block.c
> index 378d3aefdd9ced..a19744cb43ca0c 100644
> --- a/fs/xfs/libxfs/xfs_dir2_block.c
> +++ b/fs/xfs/libxfs/xfs_dir2_block.c
> @@ -1109,8 +1109,8 @@ xfs_dir2_sf_to_block(
> /*
> * Compute size of block "tail" area.
> */
> - i = (uint)sizeof(*btp) +
> - (sfp->count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t);
> + i = xfs_dir2_block_overhead(sfp->count);
> +
> /*
> * The whole thing is initialized to free by the init routine.
> * Say we're using the leaf and tail area.
> diff --git a/fs/xfs/libxfs/xfs_dir2_priv.h b/fs/xfs/libxfs/xfs_dir2_priv.h
> index 1e4401f9ec936e..bfbc73251f275a 100644
> --- a/fs/xfs/libxfs/xfs_dir2_priv.h
> +++ b/fs/xfs/libxfs/xfs_dir2_priv.h
> @@ -205,4 +205,16 @@ xfs_dahash_t xfs_dir2_hashname(struct xfs_mount *mp,
> enum xfs_dacmp xfs_dir2_compname(struct xfs_da_args *args,
> const unsigned char *name, int len);
>
> +/*
> + * Overhead if we converted a shortform directory to block format.
> + *
> + * The extra two entries are because "." and ".." don't have real entries in
> + * the shortform format.
> + */
> +static inline unsigned int xfs_dir2_block_overhead(unsigned int count)
> +{
> + return (count + 2) * sizeof(struct xfs_dir2_leaf_entry) +
> + sizeof(struct xfs_dir2_block_tail);
I could've sworn there's a helper to compute this, but as I cannot find
it I guess I'll let that go.
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
--D
> +}
> +
> #endif /* __XFS_DIR2_PRIV_H__ */
> diff --git a/fs/xfs/libxfs/xfs_dir2_sf.c b/fs/xfs/libxfs/xfs_dir2_sf.c
> index 21e04594606b89..1e1dcdf83b8f95 100644
> --- a/fs/xfs/libxfs/xfs_dir2_sf.c
> +++ b/fs/xfs/libxfs/xfs_dir2_sf.c
> @@ -629,9 +629,7 @@ xfs_dir2_sf_addname_pick(
> * Calculate data bytes used excluding the new entry, if this
> * was a data block (block form directory).
> */
> - used = offset +
> - (sfp->count + 3) * (uint)sizeof(xfs_dir2_leaf_entry_t) +
> - (uint)sizeof(xfs_dir2_block_tail_t);
> + used = offset + xfs_dir2_block_overhead(sfp->count + 1);
> /*
> * If it won't fit in a block form then we can't insert it,
> * we'll go back, convert to block, then try the insert and convert
> @@ -691,9 +689,7 @@ xfs_dir2_sf_check(
> }
> ASSERT(i8count == sfp->i8count);
> ASSERT((char *)sfep - (char *)sfp == dp->i_disk_size);
> - ASSERT(offset +
> - (sfp->count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t) +
> - (uint)sizeof(xfs_dir2_block_tail_t) <= args->geo->blksize);
> + ASSERT(offset + xfs_dir2_block_overhead(sfp->count));
> }
> #endif /* DEBUG */
>
> @@ -782,8 +778,8 @@ xfs_dir2_sf_verify(
> return __this_address;
>
> /* Make sure this whole thing ought to be in local format. */
> - if (offset + (sfp->count + 2) * (uint)sizeof(xfs_dir2_leaf_entry_t) +
> - (uint)sizeof(xfs_dir2_block_tail_t) > mp->m_dir_geo->blksize)
> + if (offset + xfs_dir2_block_overhead(sfp->count) >
> + mp->m_dir_geo->blksize)
> return __this_address;
>
> return NULL;
> --
> 2.39.2
>
>
next prev parent reply other threads:[~2024-05-01 21:27 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-30 12:49 optimize local for and shortform directory handling Christoph Hellwig
2024-04-30 12:49 ` [PATCH 01/16] xfs: allow non-empty forks in xfs_bmap_local_to_extents_empty Christoph Hellwig
2024-04-30 15:51 ` Darrick J. Wong
2024-05-01 4:37 ` Christoph Hellwig
2024-05-01 21:04 ` Darrick J. Wong
2024-04-30 12:49 ` [PATCH 02/16] xfs: remove an extra buffer allocation in xfs_attr_shortform_to_leaf Christoph Hellwig
2024-05-01 21:11 ` Darrick J. Wong
2024-04-30 12:49 ` [PATCH 03/16] xfs: rationalize dir2_sf entry condition asserts Christoph Hellwig
2024-05-01 21:13 ` Darrick J. Wong
2024-04-30 12:49 ` [PATCH 04/16] xfs: remove an extra buffer allocation in xfs_dir2_sf_to_block Christoph Hellwig
2024-05-01 21:15 ` Darrick J. Wong
2024-04-30 12:49 ` [PATCH 05/16] xfs: move the "does it fit" check into xfs_dir2_block_to_sf Christoph Hellwig
2024-05-01 21:16 ` Darrick J. Wong
2024-04-30 12:49 ` [PATCH 06/16] xfs: remove the buffer allocation size in xfs_dir2_try_block_to_sf Christoph Hellwig
2024-05-01 21:17 ` Darrick J. Wong
2024-04-30 12:49 ` [PATCH 07/16] xfs: remove a superfluous memory allocation in xfs_dir2_block_to_sf Christoph Hellwig
2024-05-01 21:18 ` Darrick J. Wong
2024-04-30 12:49 ` [PATCH 08/16] xfs: remove a superfluous memory allocation in xfs_dir2_sf_toino8 Christoph Hellwig
2024-05-01 21:20 ` Darrick J. Wong
2024-04-30 12:49 ` [PATCH 09/16] xfs: remove a superfluous memory allocation in xfs_dir2_sf_toino4 Christoph Hellwig
2024-05-01 21:20 ` Darrick J. Wong
2024-04-30 12:49 ` [PATCH 10/16] xfs: optimize removing the last 8-byte inode from a shortform directory Christoph Hellwig
2024-05-01 21:25 ` Darrick J. Wong
2024-05-02 4:13 ` Christoph Hellwig
2024-04-30 12:49 ` [PATCH 11/16] xfs: add xfs_dir2_block_overhead helper Christoph Hellwig
2024-05-01 21:27 ` Darrick J. Wong [this message]
2024-05-02 4:14 ` Christoph Hellwig
2024-04-30 12:49 ` [PATCH 12/16] xfs: factor out a xfs_dir2_sf_addname_common helper Christoph Hellwig
2024-05-01 21:31 ` Darrick J. Wong
2024-05-02 4:15 ` Christoph Hellwig
2024-04-30 12:49 ` [PATCH 13/16] xfs: move common code into xfs_dir2_sf_addname Christoph Hellwig
2024-05-01 21:32 ` Darrick J. Wong
2024-04-30 12:49 ` [PATCH 14/16] xfs: optimize adding the first 8-byte inode to a shortform directory Christoph Hellwig
2024-05-01 21:50 ` Darrick J. Wong
2024-05-02 4:25 ` Christoph Hellwig
2024-05-02 14:43 ` Darrick J. Wong
2024-04-30 12:49 ` [PATCH 15/16] xfs: move the block format conversion out of line in xfs_dir2_sf_addname Christoph Hellwig
2024-05-01 21:33 ` Darrick J. Wong
2024-04-30 12:49 ` [PATCH 16/16] xfs: make the hard case in xfs_dir2_sf_addname less hard Christoph Hellwig
2024-05-01 22:10 ` Darrick J. Wong
2024-05-10 6:29 ` kernel test robot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240501212758.GZ360919@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=chandan.babu@oracle.com \
--cc=hch@lst.de \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.