linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Johannes Thumshirn <johannes.thumshirn@wdc.com>,
	Chris Mason <clm@fb.com>, Josef Bacik <josef@toxicpanda.com>,
	David Sterba <dsterba@suse.com>
Cc: Qu Wenru <wqu@suse.com>,
	linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] btrfs: add tree-checker for RAID-stripe-tree
Date: Tue, 19 Sep 2023 10:00:46 +0930	[thread overview]
Message-ID: <a0ea125f-7d1c-43f4-bf05-7b43853138c5@gmx.com> (raw)
In-Reply-To: <20230918-rst-updates-v1-4-17686dc06859@wdc.com>



On 2023/9/18 23:44, Johannes Thumshirn wrote:
> Add a tree checker for RAID stripe tree items.
>
> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
>   fs/btrfs/tree-checker.c | 42 ++++++++++++++++++++++++++++++++++++++++++
>   1 file changed, 42 insertions(+)
>
> diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
> index 01bba79165e7..ea84ca2767e9 100644
> --- a/fs/btrfs/tree-checker.c
> +++ b/fs/btrfs/tree-checker.c
> @@ -30,6 +30,7 @@
>   #include "file-item.h"
>   #include "inode-item.h"
>   #include "dir-item.h"
> +#include "raid-stripe-tree.h"
>
>   /*
>    * Error message should follow the following format:
> @@ -1635,6 +1636,44 @@ static int check_inode_ref(struct extent_buffer *leaf,
>   	return 0;
>   }
>
> +static int check_raid_stripe_extent(struct extent_buffer *leaf,
> +				    struct btrfs_key *key, int slot)
> +{
> +	struct btrfs_stripe_extent *stripe_extent =
> +		btrfs_item_ptr(leaf, slot, struct btrfs_stripe_extent);
> +
> +	if (unlikely(!IS_ALIGNED(key->objectid, leaf->fs_info->sectorsize))) {
> +		generic_err(leaf, slot,
> +"invalid key objectid for raid stripe extent, have %llu expect aligned to %u",
> +			    key->objectid, leaf->fs_info->sectorsize);
> +		return -EUCLEAN;
> +	}
> +
> +	if (unlikely(!btrfs_fs_incompat(leaf->fs_info, RAID_STRIPE_TREE))) {
> +		generic_err(leaf, slot,
> +	"RAID_STRIPE_EXTENT present but RAID_STRIPE_TREE incompat bit unset");
> +		return -EUCLEAN;
> +	}
> +
> +	switch (btrfs_stripe_extent_encoding(leaf, stripe_extent)) {
> +	case BTRFS_STRIPE_RAID0:
> +	case BTRFS_STRIPE_RAID1:
> +	case BTRFS_STRIPE_DUP:
> +	case BTRFS_STRIPE_RAID10:
> +	case BTRFS_STRIPE_RAID5:
> +	case BTRFS_STRIPE_RAID6:
> +	case BTRFS_STRIPE_RAID1C3:
> +	case BTRFS_STRIPE_RAID1C4:
> +		break;
> +	default:
> +		generic_err(leaf, slot, "invalid raid stripe encoding %u",
> +			    btrfs_stripe_extent_encoding(leaf, stripe_extent));
> +		return -EUCLEAN;
> +	}

Another thing we can check is the item size, the item size should be
aligned to a single record, or we can get garbage reading the last record.

Thanks,
Qu
> +
> +	return 0;
> +}
> +
>   /*
>    * Common point to switch the item-specific validation.
>    */
> @@ -1689,6 +1728,9 @@ static enum btrfs_tree_block_status check_leaf_item(struct extent_buffer *leaf,
>   	case BTRFS_EXTENT_DATA_REF_KEY:
>   		ret = check_extent_data_ref(leaf, key, slot);
>   		break;
> +	case BTRFS_RAID_STRIPE_KEY:
> +		ret = check_raid_stripe_extent(leaf, key, slot);
> +		break;
>   	}
>
>   	if (ret)
>

  reply	other threads:[~2023-09-19  0:31 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-18 14:14 [PATCH 0/4] btrfs: RAID stripe tree updates Johannes Thumshirn
2023-09-18 14:14 ` [PATCH 1/4] btrfs: fix 64bit division in btrfs_insert_striped_mirrored_raid_extents Johannes Thumshirn
2023-09-18 14:18   ` Geert Uytterhoeven
2023-09-18 15:03     ` Johannes Thumshirn
2023-09-18 16:24       ` David Sterba
2023-09-18 18:31         ` Geert Uytterhoeven
2023-09-18 21:07           ` David Sterba
2023-09-19  0:37         ` Qu Wenruo
2023-09-19 13:58           ` David Sterba
2023-09-19 21:50             ` Qu Wenruo
2023-09-20 15:34               ` David Sterba
2023-09-18 14:14 ` [PATCH 2/4] btrfs: break loop in case set_io_stripe fails Johannes Thumshirn
2023-09-18 14:14 ` [PATCH 3/4] btrfs: rename ordered_enmtry in btrfs_io_context Johannes Thumshirn
2023-09-18 14:14 ` [PATCH 4/4] btrfs: add tree-checker for RAID-stripe-tree Johannes Thumshirn
2023-09-19  0:30   ` Qu Wenruo [this message]
2023-09-18 16:39 ` [PATCH 0/4] btrfs: RAID stripe tree updates David Sterba

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=a0ea125f-7d1c-43f4-bf05-7b43853138c5@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=clm@fb.com \
    --cc=dsterba@suse.com \
    --cc=johannes.thumshirn@wdc.com \
    --cc=josef@toxicpanda.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=wqu@suse.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;
as well as URLs for NNTP newsgroup(s).