[2/2] btrfs-progs: check: fixup_extent_flags needs to deal with non-skinny metadata
diff mbox series

Message ID 20190402180956.28893-2-jeffm@suse.com
State New
Headers show
Series
  • [1/2] btrfs-progs: check: run delayed refs after writing out dirty block groups
Related show

Commit Message

Jeff Mahoney April 2, 2019, 6:09 p.m. UTC
From: Jeff Mahoney <jeffm@suse.com>

When repairing a file system created by a very old kernel, I ran into
issues fixing up the extent flags since fixup_extent_flags assumed
that a METADATA_ITEM would be present if the record was for metadata.

Since METADATA_ITEMs don't exist without skinny metadata, we need to
fall back to EXTENT_ITEMs.  This also falls back to EXTENT_ITEMs even
with skinny metadata enabled as other parts of the tools do.

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
---
 check/main.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Filipe Manana April 2, 2019, 7:21 p.m. UTC | #1
On Tue, Apr 2, 2019 at 7:31 PM <jeffm@suse.com> wrote:
>
> From: Jeff Mahoney <jeffm@suse.com>
>
> When repairing a file system created by a very old kernel, I ran into
> issues fixing up the extent flags since fixup_extent_flags assumed
> that a METADATA_ITEM would be present if the record was for metadata.
>
> Since METADATA_ITEMs don't exist without skinny metadata, we need to
> fall back to EXTENT_ITEMs.  This also falls back to EXTENT_ITEMs even
> with skinny metadata enabled as other parts of the tools do.
>
> Signed-off-by: Jeff Mahoney <jeffm@suse.com>

Reviewed-by: Filipe Manana <fdmanana@suse.com>

Looks good.

> ---
>  check/main.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/check/main.c b/check/main.c
> index 7547209c..4a27a443 100644
> --- a/check/main.c
> +++ b/check/main.c
> @@ -7540,9 +7540,13 @@ static int fixup_extent_flags(struct btrfs_fs_info *fs_info,
>         struct btrfs_key key;
>         u64 flags;
>         int ret = 0;
> +       bool metadata_item = rec->metadata;
>
> +       if (!btrfs_fs_incompat(root->fs_info, SKINNY_METADATA))
> +               metadata_item = false;
> +retry:
>         key.objectid = rec->start;
> -       if (rec->metadata) {
> +       if (metadata_item) {
>                 key.type = BTRFS_METADATA_ITEM_KEY;
>                 key.offset = rec->info_level;
>         } else {
> @@ -7561,6 +7565,10 @@ static int fixup_extent_flags(struct btrfs_fs_info *fs_info,
>                 btrfs_commit_transaction(trans, root);
>                 return ret;
>         } else if (ret) {
> +               if (key.type == BTRFS_METADATA_ITEM_KEY) {
> +                       metadata_item = false;
> +                       goto retry;
> +               }
>                 fprintf(stderr, "Didn't find extent for %llu\n",
>                         (unsigned long long)rec->start);
>                 btrfs_release_path(&path);
> --
> 2.16.4
>

Patch
diff mbox series

diff --git a/check/main.c b/check/main.c
index 7547209c..4a27a443 100644
--- a/check/main.c
+++ b/check/main.c
@@ -7540,9 +7540,13 @@  static int fixup_extent_flags(struct btrfs_fs_info *fs_info,
 	struct btrfs_key key;
 	u64 flags;
 	int ret = 0;
+	bool metadata_item = rec->metadata;
 
+	if (!btrfs_fs_incompat(root->fs_info, SKINNY_METADATA))
+		metadata_item = false;
+retry:
 	key.objectid = rec->start;
-	if (rec->metadata) {
+	if (metadata_item) {
 		key.type = BTRFS_METADATA_ITEM_KEY;
 		key.offset = rec->info_level;
 	} else {
@@ -7561,6 +7565,10 @@  static int fixup_extent_flags(struct btrfs_fs_info *fs_info,
 		btrfs_commit_transaction(trans, root);
 		return ret;
 	} else if (ret) {
+		if (key.type == BTRFS_METADATA_ITEM_KEY) {
+			metadata_item = false;
+			goto retry;
+		}
 		fprintf(stderr, "Didn't find extent for %llu\n",
 			(unsigned long long)rec->start);
 		btrfs_release_path(&path);