From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: Dave Chinner <david@fromorbit.com>
Cc: sandeen@redhat.com, linux-xfs@vger.kernel.org
Subject: Re: [PATCH 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic
Date: Mon, 10 Apr 2017 14:08:07 -0700 [thread overview]
Message-ID: <20170410210807.GP4874@birch.djwong.org> (raw)
In-Reply-To: <20170408231953.GF23007@dastard>
On Sun, Apr 09, 2017 at 09:19:53AM +1000, Dave Chinner wrote:
> On Fri, Apr 07, 2017 at 08:03:55PM -0700, Darrick J. Wong wrote:
> > From: Darrick J. Wong <darrick.wong@oracle.com>
> >
> > The function block_to_bt plays an integral role in determining the btree
> > geometry of a block that we want to manipulate with the debugger.
> > Normally we use the block magic to find the geometry profile, but if the
> > magic is bad we'll never find it and return NULL. The callers of this
> > function do not check for NULL and crash.
> >
> > Therefore, if we can't find a geometry profile matching the magic
> > number, use the iocursor type to guess the profile and scowl about that
> > to stdout. This makes it so that even with a corrupt magic we can try
> > to print the fields instead of crashing the debugger.
>
> ....
>
> > +#define M(a,b) (!xfs_sb_version_hascrc(&mp->m_sb) ? (a) : (b))
> > + switch (iocur_top->typ->typnm) {
> > + case TYP_BMAPBTA:
> > + case TYP_BMAPBTD:
> > + magic = M(XFS_BMAP_MAGIC, XFS_BMAP_CRC_MAGIC);
> > + break;
>
> That's really quite special, Darrick. :P
>
> This:
>
> (!xfs_sb_version_hascrc(&mp->m_sb) ? (a) : (b))
>
> Could written more simply as:
>
> (xfs_sb_version_hascrc(&mp->m_sb) ? (b) : (a))
>
> or you could swap the macro args so you only need to drop the
> negation.
>
> Even better, though, would be to use a local variable to only
> evaluate the CRC status once and kill the macro altogether:
>
> has_crc = xfs_sb_version_hascrc(&mp->m_sb);
> switch (iocur_top->typ->typnm) {
> case TYP_BMAPBTA:
> case TYP_BMAPBTD:
> magic = has_crc ? XFS_ABTB_CRC_MAGIC : XFS_ABTB_MAGIC;
> break;
> .....
Ok, done.
--D
>
> -Dave.
> --
> Dave Chinner
> david@fromorbit.com
next prev parent reply other threads:[~2017-04-10 21:08 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-08 3:03 [RFC PATCH v1 0/4] xfs_db misc. btree dumping improvements Darrick J. Wong
2017-04-08 3:03 ` [PATCH 1/4] xfs_db: don't print arrays off the end of a buffer Darrick J. Wong
2017-04-08 3:03 ` [PATCH 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic Darrick J. Wong
2017-04-08 23:19 ` Dave Chinner
2017-04-10 21:08 ` Darrick J. Wong [this message]
2017-04-08 3:04 ` [PATCH 3/4] xfs_db: complain about dir/attr blocks with bad magics Darrick J. Wong
2017-04-08 3:04 ` [PATCH 4/4] xfs_db: dump metadata btrees via 'btdump' Darrick J. Wong
2017-04-08 23:11 ` Dave Chinner
-- strict thread matches above, loose matches on Subject: below --
2017-04-10 22:47 [PATCH v2 0/4] xfs_db misc. btree dumping improvements Darrick J. Wong
2017-04-10 22:47 ` [PATCH 2/4] xfs_db: use iocursor type to guess btree geometry if bad magic Darrick J. Wong
2017-04-11 0:03 ` Dave Chinner
2017-04-11 0:19 ` Darrick J. Wong
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=20170410210807.GP4874@birch.djwong.org \
--to=darrick.wong@oracle.com \
--cc=david@fromorbit.com \
--cc=linux-xfs@vger.kernel.org \
--cc=sandeen@redhat.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