linux-ext4.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <darrick.wong@oracle.com>
To: tytso@mit.edu, linux-ext4@vger.kernel.org
Subject: Re: [PATCH 2/2] ext4: Spot-check block group sub-table locations
Date: Wed, 9 Oct 2013 15:08:24 -0700	[thread overview]
Message-ID: <20131009220824.GM6860@birch.djwong.org> (raw)
In-Reply-To: <20130929064400.GB10285@gmail.com>

On Sun, Sep 29, 2013 at 02:44:01PM +0800, Zheng Liu wrote:
> On Fri, Sep 27, 2013 at 05:14:04PM -0700, Darrick J. Wong wrote:
> > Perform a quick sanity check of bitmap and inode table block numbers when
> > loading them, and if there's something suspicious, mark the block group
> > corrupt.
> > 
> > Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> 
> One comment below.  Otherwise the patch looks good to me.
> Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
> 
> > ---
> >  fs/ext4/balloc.c |    7 +++++++
> >  fs/ext4/ext4.h   |    2 ++
> >  fs/ext4/ialloc.c |    6 ++++++
> >  fs/ext4/inode.c  |    9 +++++++++
> >  fs/ext4/super.c  |   21 +++++++++++++++++++++
> >  5 files changed, 45 insertions(+)
> [...]
> > diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> > index 2c2e6cb..d22248e 100644
> > --- a/fs/ext4/super.c
> > +++ b/fs/ext4/super.c
> > @@ -2049,6 +2049,27 @@ void ext4_group_desc_csum_set(struct super_block *sb, __u32 block_group,
> >  	gdp->bg_checksum = ext4_group_desc_csum(EXT4_SB(sb), block_group, gdp);
> >  }
> >  
> > +/* returns 1 if the location of a blockgroup data item seems sane */
> > +int ext4_is_sane_bgdata_location(struct super_block *sb, ext4_group_t grp,
> > +				 ext4_fsblk_t blk)
> > +{
> > +	struct ext4_sb_info *sbi = EXT4_SB(sb);
> > +	ext4_fsblk_t first_block = le32_to_cpu(sbi->s_es->s_first_data_block);
> > +	ext4_fsblk_t last_block;
> > +
> > +	if (EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_FLEX_BG))
> > +		last_block = ext4_blocks_count(sbi->s_es) - 1;
> > +	else {
> > +		first_block += grp * sbi->s_blocks_per_group;
> > +		last_block = first_block + (EXT4_BLOCKS_PER_GROUP(sb) - 1);
> > +	}
> > +
> > +	if (last_block >= ext4_blocks_count(sbi->s_es))
> > +		last_block = ext4_blocks_count(sbi->s_es) - 1;
> > +
> > +	return blk >= first_block && blk <= last_block;
> > +}
> > +
> >  /* Called at mount-time, super-block is locked */
> >  static int ext4_check_descriptors(struct super_block *sb,
> >  				  ext4_group_t *first_not_zeroed)
> 
> FWIW, I notice that in ext4_check_descriptors() we also check the
> location of bitmap.  So maybe we could use ext4_is_sane_bgdata_location
> in that function.

That could be done, but all we'd be doing is trading this:

	block_bitmap = ext4_block_bitmap(sb, gdp);
	if (block_bitmap < first_block || block_bitmap > last_block) {

for this slightly slower code:

	if (ext4_is_sane_bgdata_location(sb, gdp,
					 ext4_block_bitmap(sb, gdb))) {

I don't know if that's worth the code churn or not.  It's an easy change, but I
don't think it adds much.  Ted -- if you want me to make the change I'll do it,
but if you're content to leave the patch as it is, then so am I.

--D
> 
>                                                 - Zheng

  reply	other threads:[~2013-10-09 22:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-28  0:13 [PATCH v1.1 0/2] ext4: Shut down block groups when damage is detected, part 2 Darrick J. Wong
2013-09-28  0:13 ` [PATCH 1/2] ext4: Don't count free clusters from a corrupt block group Darrick J. Wong
2013-09-29  6:20   ` Zheng Liu
2013-10-30 15:21   ` Theodore Ts'o
2013-09-28  0:14 ` [PATCH 2/2] ext4: Spot-check block group sub-table locations Darrick J. Wong
2013-09-29  6:44   ` Zheng Liu
2013-10-09 22:08     ` Darrick J. Wong [this message]
2013-10-30 16:45       ` Theodore Ts'o
2013-10-30 17:33         ` Darrick J. Wong
  -- strict thread matches above, loose matches on Subject: below --
2013-09-27  0:03 [PATCH v1 0/2] ext4: Shut down block groups when damage is detected, part 2 Darrick J. Wong
2013-09-27  0:03 ` [PATCH 2/2] ext4: Spot-check block group sub-table locations Darrick J. Wong
2013-09-27  5:40   ` Zheng Liu
2013-09-27 17:57     ` 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=20131009220824.GM6860@birch.djwong.org \
    --to=darrick.wong@oracle.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    /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).