From patchwork Mon Oct 17 01:27:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9378361 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 019EE60CDC for ; Mon, 17 Oct 2016 01:28:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E680B28CCD for ; Mon, 17 Oct 2016 01:28:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA4A928E49; Mon, 17 Oct 2016 01:28:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20A2D28E49 for ; Mon, 17 Oct 2016 01:28:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756907AbcJQB2L (ORCPT ); Sun, 16 Oct 2016 21:28:11 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:55698 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1756519AbcJQB2I (ORCPT ); Sun, 16 Oct 2016 21:28:08 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="901593" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 17 Oct 2016 09:27:52 +0800 Received: from adam-work.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 6CF1A41B4BCA for ; Mon, 17 Oct 2016 09:27:51 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Subject: [RFC PATCH v0.8 11/14] btrfs-progs: check/scrub: Introduce function to recover data parity Date: Mon, 17 Oct 2016 09:27:40 +0800 Message-Id: <20161017012743.9692-12-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20161017012743.9692-1-quwenruo@cn.fujitsu.com> References: <20161017012743.9692-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: 6CF1A41B4BCA.A059F X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce function, recover_from_parities(), to recover data stripes. However this function only support RAID5 yet, but should be good enough for the scrub framework. Signed-off-by: Qu Wenruo --- check/scrub.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/check/scrub.c b/check/scrub.c index d8182d6..c965328 100644 --- a/check/scrub.c +++ b/check/scrub.c @@ -58,6 +58,9 @@ struct scrub_full_stripe { /* Missing stripe index */ int missing_stripes[2]; + /* Has already been recovered using parities */ + unsigned int recovered:1; + struct scrub_stripe stripes[]; }; @@ -467,3 +470,49 @@ out: free(ptrs); return ret; } + +static int recovery_from_parities(struct btrfs_fs_info *fs_info, + struct btrfs_scrub_progress *scrub_ctx, + struct scrub_full_stripe *fstripe) +{ + void **ptrs; + int nr_stripes = fstripe->nr_stripes; + int corrupted = -1; + int stripe_len = BTRFS_STRIPE_LEN; + int i; + int ret; + + /* No need to recover */ + if (!fstripe->err_read_stripes && !fstripe->err_csum_dstripes) + return 0; + + /* Already recovered once, no more chance */ + if (fstripe->recovered) + return -EINVAL; + + if (fstripe->bg_type == BTRFS_BLOCK_GROUP_RAID6) { + /* Need to recover 2 stripes, not supported yet */ + error("recover data stripes for RAID6 is not support yet"); + return -ENOTTY; + } + + /* Out of repair */ + if (fstripe->err_read_stripes + fstripe->err_csum_dstripes > 1) + return -EINVAL; + + ptrs = malloc(sizeof(void *) * fstripe->nr_stripes); + if (!ptrs) + return -ENOMEM; + + /* Construct ptrs */ + for (i = 0; i < nr_stripes; i++) + ptrs[i] = fstripe->stripes[i].data; + corrupted = fstripe->missing_stripes[0]; + + /* Recover the corrupted data csum */ + ret = raid5_gen_result(nr_stripes, stripe_len, corrupted, ptrs); + + fstripe->recovered = 1; + free(ptrs); + return ret; +}