[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20201209045515.GH52960@mit.edu>
Date: Tue, 8 Dec 2020 23:55:15 -0500
From: "Theodore Y. Ts'o" <tytso@....edu>
To: Chunguang Xu <brookxu.cn@...il.com>
Cc: adilger.kernel@...ger.ca, linux-ext4@...r.kernel.org
Subject: Re: [PATCH 6/8] ext4: add a helper function to validate metadata
block
On Sat, Nov 07, 2020 at 11:58:16PM +0800, Chunguang Xu wrote:
> From: Chunguang Xu <brookxu@...cent.com>
>
> There is a need to check whether a block or a segment overlaps
> with metadata, since information of system_zone is incomplete,
> we need a more accurate function. Now we check whether it
> overlaps with block bitmap, inode bitmap, and inode table.
> Perhaps it is better to add a check of super_block and block
> group descriptor and provide a helper function.
The original code was valid only for file systems that are not using
flex_bg. I suspect the Lustre folks who implemented mballoc.c did so
before flex_bg, and fortunately, on flex_bg we the check is simply
going to have more false negaties, but not any false positives, so no
one noticed.
> +/*
> + * Returns 1 if the passed-in block region (block, block+count)
> + * overlaps with some other filesystem metadata blocks. Others,
> + * return 0.
> + */
> +int ext4_metadata_block_overlaps(struct super_block *sb,
> + ext4_group_t block_group,
> + ext4_fsblk_t block,
> + unsigned long count)
> +{
> + struct ext4_sb_info *sbi = EXT4_SB(sb);
> + struct ext4_group_desc *gdp;
> + int gd_first = ext4_group_first_block_no(sb, block_group);
> + int itable, gd_blk;
> + int ret = 0;
> +
> + gdp = ext4_get_group_desc(sb, block_group, NULL);
> + // check block bitmap and inode bitmap
> + if (in_range(ext4_block_bitmap(sb, gdp), block, count) ||
> + in_range(ext4_inode_bitmap(sb, gdp), block, count))
We are only checking a single block group descriptor; this is fine if
the allocation bitmaps and inode table are guaranteed to be located in
their own block group. But this is no longer true when flex_bg is
enabled.
I think what we should do is to rely on the rb tree maintained by
block_validity.c (if the inode number is zero, then the entry refers
to blocks in the "system zone"); that's going to be a much more
complete check.
What do you think?
- Ted
Powered by blists - more mailing lists