All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH] btrfs-progs: raid56: fix the wrong recovery condition for data and P case
Date: Tue, 16 Nov 2021 21:10:51 +0800	[thread overview]
Message-ID: <20211116131051.247977-1-wqu@suse.com> (raw)

There is a bug in raid56_recov() which doesn't properly repair data and
P case corruption:

	/* Data and P*/
	if (dest2 == nr_devs - 1)
		return raid6_recov_datap(nr_devs, stripe_len, dest1, data);

Note that, dest1/2 is to indicate which slot has corruption.

For RAID6 cases:

[0, nr_devs - 2) is for data stripes,
@data_devs - 2 is for P,
@data_devs - 1 is for Q.

For above code, the comment is correct, but the check condition is
wrong, and leads to the only project, btrfs-fuse, to report raid6
recovery error for 2 devices missing case.

Fix it by using correct condition.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
But I'm more interested in why this function is still there, as there
seems to be no caller of this function in btrfs-progs anyway.
---
 kernel-lib/raid56.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel-lib/raid56.c b/kernel-lib/raid56.c
index a94a60ed73d0..6f690484c810 100644
--- a/kernel-lib/raid56.c
+++ b/kernel-lib/raid56.c
@@ -343,7 +343,7 @@ int raid56_recov(int nr_devs, size_t stripe_len, u64 profile, int dest1,
 		return raid6_recov_data2(nr_devs, stripe_len, dest1, dest2,
 					 data);
 	/* Data and P*/
-	if (dest2 == nr_devs - 1)
+	if (dest2 == nr_devs - 2)
 		return raid6_recov_datap(nr_devs, stripe_len, dest1, data);
 
 	/*
-- 
2.33.1


             reply	other threads:[~2021-11-16 13:11 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-16 13:10 Qu Wenruo [this message]
2021-11-16 13:52 ` [PATCH] btrfs-progs: raid56: fix the wrong recovery condition for data and P case David Sterba
2021-11-16 23:09   ` Qu Wenruo

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=20211116131051.247977-1-wqu@suse.com \
    --to=wqu@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.