From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: sandeen@sandeen.net, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 2/2] xfs_db: calculate iext tree geometry in btheight command
Date: Thu, 26 Sep 2019 10:40:23 -0700 [thread overview]
Message-ID: <20190926174023.GE9916@magnolia> (raw)
In-Reply-To: <20190926092041.4br7562bwqsqwznr@pegasus.maiolino.io>
On Thu, Sep 26, 2019 at 11:20:42AM +0200, Carlos Maiolino wrote:
> On Wed, Sep 25, 2019 at 02:40:59PM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> >
> > (Ab)use the btheight command to calculate the geometry of the incore
> > extent tree.
> >
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> > ---
> > db/btheight.c | 87 +++++++++++++++++++++++++++++++++++++++------------------
> > 1 file changed, 60 insertions(+), 27 deletions(-)
> >
> >
> > diff --git a/db/btheight.c b/db/btheight.c
> > index e2c9759f..be604ebc 100644
> > --- a/db/btheight.c
> > +++ b/db/btheight.c
> > @@ -22,18 +22,37 @@ static int rmap_maxrecs(struct xfs_mount *mp, int blocklen, int leaf)
> > return libxfs_rmapbt_maxrecs(blocklen, leaf);
> > }
> >
> > +static int iext_maxrecs(struct xfs_mount *mp, int blocklen, int leaf)
> > +{
> > + blocklen -= 2 * sizeof(void *);
> > +
> > + return blocklen / sizeof(struct xfs_bmbt_rec);
> > +}
> > +
> > +static int disk_blocksize(struct xfs_mount *mp)
>
> This naming looks confusing to me, disk_blocksize sounds to me like
> 'sector size', maybe fs_blocksize() or get_fs_blocksize()?
Fixed.
--D
> > +{
> > + return mp->m_sb.sb_blocksize;
> > +}
> > +
>
> Otherwise looks good.
>
>
> > +static int iext_blocksize(struct xfs_mount *mp)
> > +{
> > + return 256;
> > +}
> > +
> > struct btmap {
> > const char *tag;
> > int (*maxrecs)(struct xfs_mount *mp, int blocklen,
> > int leaf);
> > + int (*default_blocksize)(struct xfs_mount *mp);
> > } maps[] = {
> > - {"bnobt", libxfs_allocbt_maxrecs},
> > - {"cntbt", libxfs_allocbt_maxrecs},
> > - {"inobt", libxfs_inobt_maxrecs},
> > - {"finobt", libxfs_inobt_maxrecs},
> > - {"bmapbt", libxfs_bmbt_maxrecs},
> > - {"refcountbt", refc_maxrecs},
> > - {"rmapbt", rmap_maxrecs},
> > + {"bnobt", libxfs_allocbt_maxrecs, disk_blocksize},
> > + {"cntbt", libxfs_allocbt_maxrecs, disk_blocksize},
> > + {"inobt", libxfs_inobt_maxrecs, disk_blocksize},
> > + {"finobt", libxfs_inobt_maxrecs, disk_blocksize},
> > + {"bmapbt", libxfs_bmbt_maxrecs, disk_blocksize},
> > + {"refcountbt", refc_maxrecs, disk_blocksize},
> > + {"rmapbt", rmap_maxrecs, disk_blocksize},
> > + {"iext", iext_maxrecs, iext_blocksize},
> > };
> >
> > static void
> > @@ -108,7 +127,7 @@ calc_height(
> > static int
> > construct_records_per_block(
> > char *tag,
> > - int blocksize,
> > + int *blocksize,
> > unsigned int *records_per_block)
> > {
> > char *toktag;
> > @@ -119,8 +138,10 @@ construct_records_per_block(
> >
> > for (i = 0, m = maps; i < ARRAY_SIZE(maps); i++, m++) {
> > if (!strcmp(m->tag, tag)) {
> > - records_per_block[0] = m->maxrecs(mp, blocksize, 1);
> > - records_per_block[1] = m->maxrecs(mp, blocksize, 0);
> > + if (*blocksize < 0)
> > + *blocksize = m->default_blocksize(mp);
> > + records_per_block[0] = m->maxrecs(mp, *blocksize, 1);
> > + records_per_block[1] = m->maxrecs(mp, *blocksize, 0);
> > return 0;
> > }
> > }
> > @@ -178,38 +199,50 @@ construct_records_per_block(
> > fprintf(stderr, _("%s: header type not found.\n"), tag);
> > goto out;
> > }
> > - if (!strcmp(p, "short"))
> > + if (!strcmp(p, "short")) {
> > + if (*blocksize < 0)
> > + *blocksize = mp->m_sb.sb_blocksize;
> > blocksize -= XFS_BTREE_SBLOCK_LEN;
> > - else if (!strcmp(p, "shortcrc"))
> > + } else if (!strcmp(p, "shortcrc")) {
> > + if (*blocksize < 0)
> > + *blocksize = mp->m_sb.sb_blocksize;
> > blocksize -= XFS_BTREE_SBLOCK_CRC_LEN;
> > - else if (!strcmp(p, "long"))
> > + } else if (!strcmp(p, "long")) {
> > + if (*blocksize < 0)
> > + *blocksize = mp->m_sb.sb_blocksize;
> > blocksize -= XFS_BTREE_LBLOCK_LEN;
> > - else if (!strcmp(p, "longcrc"))
> > + } else if (!strcmp(p, "longcrc")) {
> > + if (*blocksize < 0)
> > + *blocksize = mp->m_sb.sb_blocksize;
> > blocksize -= XFS_BTREE_LBLOCK_CRC_LEN;
> > - else {
> > + } else if (!strcmp(p, "iext")) {
> > + if (*blocksize < 0)
> > + *blocksize = 256;
> > + blocksize -= 2 * sizeof(void *);
> > + } else {
> > fprintf(stderr, _("%s: unrecognized btree header type."),
> > p);
> > goto out;
> > }
> >
> > - if (record_size > blocksize) {
> > + if (record_size > *blocksize) {
> > fprintf(stderr,
> > _("%s: record size must be less than %u bytes.\n"),
> > - tag, blocksize);
> > + tag, *blocksize);
> > goto out;
> > }
> >
> > - if (key_size > blocksize) {
> > + if (key_size > *blocksize) {
> > fprintf(stderr,
> > _("%s: key size must be less than %u bytes.\n"),
> > - tag, blocksize);
> > + tag, *blocksize);
> > goto out;
> > }
> >
> > - if (ptr_size > blocksize) {
> > + if (ptr_size > *blocksize) {
> > fprintf(stderr,
> > _("%s: pointer size must be less than %u bytes.\n"),
> > - tag, blocksize);
> > + tag, *blocksize);
> > goto out;
> > }
> >
> > @@ -221,8 +254,8 @@ construct_records_per_block(
> > goto out;
> > }
> >
> > - records_per_block[0] = blocksize / record_size;
> > - records_per_block[1] = blocksize / (key_size + ptr_size);
> > + records_per_block[0] = *blocksize / record_size;
> > + records_per_block[1] = *blocksize / (key_size + ptr_size);
> > ret = 0;
> > out:
> > free(toktag);
> > @@ -238,12 +271,12 @@ report(
> > char *tag,
> > unsigned int report_what,
> > unsigned long long nr_records,
> > - unsigned int blocksize)
> > + int blocksize)
> > {
> > unsigned int records_per_block[2];
> > int ret;
> >
> > - ret = construct_records_per_block(tag, blocksize, records_per_block);
> > + ret = construct_records_per_block(tag, &blocksize, records_per_block);
> > if (ret)
> > return;
> >
> > @@ -302,7 +335,7 @@ btheight_f(
> > int argc,
> > char **argv)
> > {
> > - long long blocksize = mp->m_sb.sb_blocksize;
> > + long long blocksize = -1;
> > uint64_t nr_records = 0;
> > int report_what = REPORT_DEFAULT;
> > int i, c;
> > @@ -355,7 +388,7 @@ _("The largest block size this command will consider is %u bytes.\n"),
> > return 0;
> > }
> >
> > - if (blocksize < 128) {
> > + if (blocksize >= 0 && blocksize < 128) {
> > fprintf(stderr,
> > _("The smallest block size this command will consider is 128 bytes.\n"));
> > return 0;
> >
>
> --
> Carlos
>
next prev parent reply other threads:[~2019-09-26 17:40 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-25 21:40 [PATCH 0/2] xfs_db: fixes to the btheight command Darrick J. Wong
2019-09-25 21:40 ` [PATCH 1/2] xfs_db: btheight should check geometry more carefully Darrick J. Wong
2019-09-26 9:11 ` Carlos Maiolino
2019-09-26 17:38 ` Darrick J. Wong
2019-09-27 12:30 ` Carlos Maiolino
2019-09-26 19:09 ` [PATCH v2 " Darrick J. Wong
2019-10-01 6:40 ` Carlos Maiolino
2019-09-30 7:55 ` [PATCH " Christoph Hellwig
2019-09-25 21:40 ` [PATCH 2/2] xfs_db: calculate iext tree geometry in btheight command Darrick J. Wong
2019-09-26 9:20 ` Carlos Maiolino
2019-09-26 17:40 ` Darrick J. Wong [this message]
2019-09-26 19:09 ` [PATCH v2 " Darrick J. Wong
2019-09-26 21:41 ` [PATCH " Dave Chinner
2019-09-27 2:58 ` Darrick J. Wong
2019-09-27 22:08 ` Dave Chinner
2019-09-30 7:58 ` Christoph Hellwig
2019-09-30 16:11 ` Darrick J. Wong
2019-10-01 6:24 ` Christoph Hellwig
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=20190926174023.GE9916@magnolia \
--to=darrick.wong@oracle.com \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@sandeen.net \
/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;
as well as URLs for NNTP newsgroup(s).