From: Gu Jinxiang <gujx@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Qu Wenruo <quwenruo@cn.fujitsu.com>
Subject: [PATCH v5 04/15] btrfs-progs: scrub: Introduce structures to support offline scrub for RAID56
Date: Sat, 15 Jul 2017 17:10:42 +0800 [thread overview]
Message-ID: <20170715091053.19725-4-gujx@cn.fujitsu.com> (raw)
In-Reply-To: <20170715091053.19725-1-gujx@cn.fujitsu.com>
From: Qu Wenruo <quwenruo@cn.fujitsu.com>
Introuduce new local structures, scrub_full_stripe and scrub_stripe, for
incoming offline RAID56 scrub support.
For pure stripe/mirror based profiles, like raid0/1/10/dup/single, we
will follow the original bytenr and mirror number based iteration, so
they don't need any extra structures for these profiles.
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com>
---
Makefile | 2 +-
scrub.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 125 insertions(+), 1 deletion(-)
create mode 100644 scrub.c
diff --git a/Makefile b/Makefile
index 6f734a6..8275539 100644
--- a/Makefile
+++ b/Makefile
@@ -96,7 +96,7 @@ objects = ctree.o disk-io.o kernel-lib/radix-tree.o extent-tree.o print-tree.o \
qgroup.o free-space-cache.o kernel-lib/list_sort.o props.o \
kernel-shared/ulist.o qgroup-verify.o backref.o string-table.o task-utils.o \
inode.o file.o find-root.o free-space-tree.o help.o send-dump.o \
- fsfeatures.o kernel-lib/tables.o kernel-lib/raid56.o csum.o
+ fsfeatures.o kernel-lib/tables.o kernel-lib/raid56.o csum.o scrub.o
cmds_objects = cmds-subvolume.o cmds-filesystem.o cmds-device.o cmds-scrub.o \
cmds-inspect.o cmds-balance.o cmds-send.o cmds-receive.o \
cmds-quota.o cmds-qgroup.o cmds-replace.o cmds-check.o \
diff --git a/scrub.c b/scrub.c
new file mode 100644
index 0000000..cdb311b
--- /dev/null
+++ b/scrub.c
@@ -0,0 +1,124 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public
+ * License v2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with this program; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 021110-1307, USA.
+ */
+
+/*
+ * Main part to implement offline(unmounted) btrfs scrub
+ */
+
+#include <unistd.h>
+#include "ctree.h"
+#include "volumes.h"
+#include "disk-io.h"
+#include "utils.h"
+
+/*
+ * For parity based profile (RAID56)
+ * Mirror/stripe based on won't need this. They are iterated by bytenr and
+ * mirror number.
+ */
+struct scrub_stripe {
+ /* For P/Q logical start will be BTRFS_RAID5/6_P/Q_STRIPE */
+ u64 logical;
+
+ u64 physical;
+
+ /* Device is missing */
+ unsigned int dev_missing:1;
+
+ /* Any tree/data csum mismatches */
+ unsigned int csum_mismatch:1;
+
+ /* Some data doesn't have csum (nodatasum) */
+ unsigned int csum_missing:1;
+
+ /* Device fd, to write correct data back to disc */
+ int fd;
+
+ char *data;
+};
+
+/*
+ * RAID56 full stripe (data stripes + P/Q)
+ */
+struct scrub_full_stripe {
+ u64 logical_start;
+ u64 logical_len;
+ u64 bg_type;
+ u32 nr_stripes;
+ u32 stripe_len;
+
+ /* Read error stripes */
+ u32 err_read_stripes;
+
+ /* Missing devices */
+ u32 err_missing_devs;
+
+ /* Csum error data stripes */
+ u32 err_csum_dstripes;
+
+ /* Missing csum data stripes */
+ u32 missing_csum_dstripes;
+
+ /* currupted stripe index */
+ int corrupted_index[2];
+
+ int nr_corrupted_stripes;
+
+ /* Already recovered once? */
+ unsigned int recovered:1;
+
+ struct scrub_stripe stripes[];
+};
+
+static void free_full_stripe(struct scrub_full_stripe *fstripe)
+{
+ int i;
+
+ for (i = 0; i < fstripe->nr_stripes; i++)
+ free(fstripe->stripes[i].data);
+ free(fstripe);
+}
+
+static struct scrub_full_stripe *alloc_full_stripe(int nr_stripes,
+ u32 stripe_len)
+{
+ struct scrub_full_stripe *ret;
+ int size = sizeof(*ret) + sizeof(unsigned long *) +
+ nr_stripes * sizeof(struct scrub_stripe);
+ int i;
+
+ ret = malloc(size);
+ if (!ret)
+ return NULL;
+
+ memset(ret, 0, size);
+ ret->nr_stripes = nr_stripes;
+ ret->stripe_len = stripe_len;
+ ret->corrupted_index[0] = -1;
+ ret->corrupted_index[1] = -1;
+
+ /* Alloc data memory for each stripe */
+ for (i = 0; i < nr_stripes; i++) {
+ struct scrub_stripe *stripe = &ret->stripes[i];
+
+ stripe->data = malloc(stripe_len);
+ if (!stripe->data) {
+ free_full_stripe(ret);
+ return NULL;
+ }
+ }
+ return ret;
+}
--
2.9.4
next prev parent reply other threads:[~2017-07-15 9:11 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-15 9:10 [PATCH v5 01/15] btrfs-progs: Introduce new btrfs_map_block function which returns more unified result Gu Jinxiang
2017-07-15 9:10 ` [PATCH v5 02/15] btrfs-progs: Allow __btrfs_map_block_v2 to remove unrelated stripes Gu Jinxiang
2017-07-15 9:10 ` [PATCH v5 03/15] btrfs-progs: csum: Introduce function to read out data csums Gu Jinxiang
2017-07-15 9:10 ` Gu Jinxiang [this message]
2017-07-15 9:10 ` [PATCH v5 05/15] btrfs-progs: scrub: Introduce functions to scrub mirror based tree block Gu Jinxiang
2017-07-15 9:10 ` [PATCH v5 06/15] btrfs-progs: scrub: Introduce functions to scrub mirror based data blocks Gu Jinxiang
2017-07-15 9:10 ` [PATCH v5 07/15] btrfs-progs: scrub: Introduce function to scrub one mirror-based extent Gu Jinxiang
2017-07-15 9:10 ` [PATCH v5 08/15] btrfs-progs: scrub: Introduce function to scrub one data stripe Gu Jinxiang
2017-07-15 9:10 ` [PATCH v5 09/15] btrfs-progs: scrub: Introduce function to verify parities Gu Jinxiang
2017-07-15 9:10 ` [PATCH v5 10/15] btrfs-progs: extent-tree: Introduce function to check if there is any extent in given range Gu Jinxiang
2017-07-15 9:10 ` [PATCH v5 11/15] btrfs-progs: scrub: Introduce function to recover data parity Gu Jinxiang
2017-07-15 9:10 ` [PATCH v5 12/15] btrfs-progs: scrub: Introduce helper to write a full stripe Gu Jinxiang
2017-07-15 9:10 ` [PATCH v5 13/15] btrfs-progs: scrub: Introduce a function to scrub one " Gu Jinxiang
2017-07-15 9:10 ` [PATCH v5 14/15] btrfs-progs: scrub: Introduce function to check a whole block group Gu Jinxiang
2017-07-15 9:10 ` [PATCH v5 15/15] btrfs-progs: scrub: Introduce offline scrub function Gu Jinxiang
2017-07-15 9:20 ` [PATCH v5 01/15] btrfs-progs: Introduce new btrfs_map_block function which returns more unified result Qu Wenruo
2017-07-18 6:33 ` [PATCH 00/15] Btrfs-progs offline scrub Gu Jinxiang
2017-07-19 16:45 ` Marco Lorenzo Crociani
2017-07-20 3:39 ` Qu Wenruo
2017-07-20 8:55 ` Marco Lorenzo Crociani
2017-07-20 9:10 ` Qu Wenruo
2017-07-20 9:17 ` Qu Wenruo
2017-07-20 9:40 ` Marco Lorenzo Crociani
2017-07-20 9:51 ` Qu Wenruo
2017-08-22 9:45 ` Gu, Jinxiang
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=20170715091053.19725-4-gujx@cn.fujitsu.com \
--to=gujx@cn.fujitsu.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=quwenruo@cn.fujitsu.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).