@@ -95,7 +95,7 @@ objects = ctree.o disk-io.o kernel-lib/radix-tree.o extent-tree.o print-tree.o \
qgroup.o raid56.o free-space-cache.o kernel-lib/list_sort.o props.o \
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 \
- check/csum.o
+ check/csum.o check/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 \
new file mode 100644
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2016 Fujitsu. All rights reserved.
+ *
+ * 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.
+ */
+
+#include <unistd.h>
+#include "ctree.h"
+#include "volumes.h"
+#include "disk-io.h"
+#include "utils.h"
+#include "check.h"
+
+struct scrub_stripe {
+ /* For P/Q logical start will be BTRFS_RAID5/6_P/Q_STRIPE */
+ u64 logical;
+
+ /* 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;
+
+ char *data;
+};
+
+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;
+
+ /* Csum error data stripes */
+ u32 err_csum_dstripes;
+
+ /* Missing csum data stripes */
+ u32 missing_csum_dstripes;
+
+ /* Missing stripe index */
+ int missing_stripes[2];
+
+ 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) + 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;
+
+ /* 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;
+}
+
Introuduce new local structures, scrub_full_stripe and scrub_stripe, for incoming offline scrub support. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> --- Makefile.in | 2 +- check/scrub.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 check/scrub.c