From: Brian Foster <bfoster@redhat.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: xfs@oss.sgi.com
Subject: Re: [PATCH 2/5] libxfs: refactor the btree size calculator code
Date: Mon, 1 Feb 2016 10:17:56 -0500 [thread overview]
Message-ID: <20160201151755.GB3992@bfoster.bfoster> (raw)
In-Reply-To: <20160123003508.2475.53723.stgit@birch.djwong.org>
On Fri, Jan 22, 2016 at 04:35:08PM -0800, Darrick J. Wong wrote:
> Create a macro to generate btree height calculator functions.
> This will be used (much) later when we get to the refcount
> btree.
>
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
The refactoring looks fine to me... though shouldn't this head into the
kernel first and get backported to xfsprogs (or did I miss that
somewhere)?
That and one question below...
> libxfs/xfs_bmap.c | 18 +-----------------
> libxfs/xfs_bmap_btree.c | 9 +++++++++
> libxfs/xfs_bmap_btree.h | 3 +++
> libxfs/xfs_btree.c | 28 ++++++++++++++++++++++++++++
> libxfs/xfs_btree.h | 3 +++
> 5 files changed, 44 insertions(+), 17 deletions(-)
>
>
> diff --git a/libxfs/xfs_bmap.c b/libxfs/xfs_bmap.c
> index aef7cf3..c134765 100644
> --- a/libxfs/xfs_bmap.c
> +++ b/libxfs/xfs_bmap.c
> @@ -172,25 +172,9 @@ xfs_bmap_worst_indlen(
> xfs_inode_t *ip, /* incore inode pointer */
> xfs_filblks_t len) /* delayed extent length */
> {
> - int level; /* btree level number */
> - int maxrecs; /* maximum record count at this level */
> - xfs_mount_t *mp; /* mount structure */
> xfs_filblks_t rval; /* return value */
>
> - mp = ip->i_mount;
> - maxrecs = mp->m_bmap_dmxr[0];
> - for (level = 0, rval = 0;
> - level < XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK);
> - level++) {
> - len += maxrecs - 1;
> - do_div(len, maxrecs);
> - rval += len;
> - if (len == 1)
> - return rval + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK) -
> - level - 1;
> - if (level == 0)
> - maxrecs = mp->m_bmap_dmxr[1];
> - }
> + rval = xfs_bmbt_calc_size(ip->i_mount, len);
We go from xfs_filblks_t to unsigned long here. Isn't the latter 4 bytes
on 32-bit systems? Was that intentional?
Brian
> return rval;
> }
>
> diff --git a/libxfs/xfs_bmap_btree.c b/libxfs/xfs_bmap_btree.c
> index 2ef1836..3c595e2 100644
> --- a/libxfs/xfs_bmap_btree.c
> +++ b/libxfs/xfs_bmap_btree.c
> @@ -880,3 +880,12 @@ xfs_bmbt_change_owner(
> xfs_btree_del_cursor(cur, error ? XFS_BTREE_ERROR : XFS_BTREE_NOERROR);
> return error;
> }
> +
> +xfs_filblks_t
> +xfs_bmbt_calc_size(
> + struct xfs_mount *mp,
> + unsigned long len)
> +{
> + return xfs_btree_calc_size(mp, mp->m_bmap_dmxr,
> + XFS_BM_MAXLEVELS(mp, XFS_DATA_FORK), len);
> +}
> diff --git a/libxfs/xfs_bmap_btree.h b/libxfs/xfs_bmap_btree.h
> index 819a8a4..04bc6e2 100644
> --- a/libxfs/xfs_bmap_btree.h
> +++ b/libxfs/xfs_bmap_btree.h
> @@ -140,4 +140,7 @@ extern int xfs_bmbt_change_owner(struct xfs_trans *tp, struct xfs_inode *ip,
> extern struct xfs_btree_cur *xfs_bmbt_init_cursor(struct xfs_mount *,
> struct xfs_trans *, struct xfs_inode *, int);
>
> +extern xfs_filblks_t xfs_bmbt_calc_size(struct xfs_mount *mp,
> + unsigned long len);
> +
> #endif /* __XFS_BMAP_BTREE_H__ */
> diff --git a/libxfs/xfs_btree.c b/libxfs/xfs_btree.c
> index 658f27e..d5f16c5 100644
> --- a/libxfs/xfs_btree.c
> +++ b/libxfs/xfs_btree.c
> @@ -4081,6 +4081,34 @@ xfs_btree_change_owner(
> return 0;
> }
>
> +/*
> + * xfs_btree_calc_size() -- Calculate the number of blocks needed to store
> + * a given number of records.
> + */
> +xfs_filblks_t
> +xfs_btree_calc_size(
> + struct xfs_mount *mp,
> + uint *limits,
> + int maxlevels,
> + unsigned long len)
> +{
> + int level;
> + int maxrecs;
> + xfs_filblks_t rval;
> +
> + maxrecs = limits[0];
> + for (level = 0, rval = 0; level < maxlevels; level++) {
> + len += maxrecs - 1;
> + do_div(len, maxrecs);
> + rval += len;
> + if (len == 1)
> + return rval + maxlevels - level - 1;
> + if (level == 0)
> + maxrecs = limits[1];
> + }
> + return rval;
> +}
> +
> /**
> * xfs_btree_sblock_v5hdr_verify() -- verify the v5 fields of a short-format
> * btree block
> diff --git a/libxfs/xfs_btree.h b/libxfs/xfs_btree.h
> index 48cb251..b25ffd3 100644
> --- a/libxfs/xfs_btree.h
> +++ b/libxfs/xfs_btree.h
> @@ -465,6 +465,9 @@ static inline int xfs_btree_get_level(struct xfs_btree_block *block)
> #define XFS_BTREE_TRACE_ARGR(c, r)
> #define XFS_BTREE_TRACE_CURSOR(c, t)
>
> +xfs_filblks_t xfs_btree_calc_size(struct xfs_mount *mp, uint *limits,
> + int maxlevels, unsigned long len);
> +
> bool xfs_btree_sblock_v5hdr_verify(struct xfs_buf *bp);
> bool xfs_btree_sblock_verify(struct xfs_buf *bp, unsigned int max_recs);
>
>
> _______________________________________________
> xfs mailing list
> xfs@oss.sgi.com
> http://oss.sgi.com/mailman/listinfo/xfs
_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs
next prev parent reply other threads:[~2016-02-01 15:02 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-23 0:35 [PATCH 1/5] xfs_io: detect the '-R' option in getopt Darrick J. Wong
2016-01-23 0:35 ` [PATCH 2/5] libxfs: refactor the btree size calculator code Darrick J. Wong
2016-02-01 15:17 ` Brian Foster [this message]
2016-02-01 19:14 ` Darrick J. Wong
2016-02-11 23:48 ` Darrick J. Wong
2016-02-12 1:07 ` Dave Chinner
2016-02-12 1:24 ` Darrick J. Wong
2016-01-23 0:35 ` [PATCH 3/5] libxfs: move struct xfs_attr_shortform to xfs_da_format.h Darrick J. Wong
2016-01-23 5:08 ` Eric Sandeen
2016-01-23 0:35 ` [PATCH 4/5] xfs_db: don't error out when blocksize > 64 * inodesize Darrick J. Wong
2016-02-01 15:18 ` Brian Foster
2016-01-23 0:35 ` [PATCH 5/5] xfs_io: print dedupe errors to stderr, not stdout Darrick J. Wong
2016-02-02 5:14 ` Dave Chinner
2016-02-02 5:16 ` Darrick J. Wong
2016-02-02 5:16 ` Dave Chinner
2016-01-23 4:55 ` [PATCH 1/5] xfs_io: detect the '-R' option in getopt Eric Sandeen
2016-01-23 6:18 ` Darrick J. Wong
2016-01-23 18:03 ` Eric Sandeen
2016-01-26 22:09 ` Darrick J. Wong
2016-01-27 0:58 ` [PATCH 1/5 v2] " Darrick J. Wong
2016-01-27 4:30 ` Eric Sandeen
2016-01-27 4:44 ` [PATCH 6/5] mkfs: factor finobt changes into min log size when formatting Darrick J. Wong
2016-02-01 15:18 ` Brian Foster
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=20160201151755.GB3992@bfoster.bfoster \
--to=bfoster@redhat.com \
--cc=darrick.wong@oracle.com \
--cc=xfs@oss.sgi.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox