usr/src/uts/common/fs/zfs/vdev_raidz.c
author Joshua M. Clulow <jmc@joyent.com>
Mon, 04 Mar 2013 23:52:56 +0000
changeset 14188 afe390b9f1e0
parent 14167 dceb17481b99
permissions -rw-r--r--
4020 Make ldi_ev_remove_callbacks safe to use in LDI callbacks Reviewed by: Robert Mustacchi <[email protected]> Approved by: Dan McDonald <[email protected]>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     1
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     2
 * CDDL HEADER START
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     3
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
     5
 * Common Development and Distribution License (the "License").
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
     6
 * You may not use this file except in compliance with the License.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     7
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    11
 * and limitations under the License.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    12
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    18
 *
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    19
 * CDDL HEADER END
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    20
 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    21
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    22
/*
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11958
diff changeset
    23
 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
13980
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13952
diff changeset
    24
 * Copyright (c) 2013 by Delphix. All rights reserved.
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
    25
 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    26
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    27
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    28
#include <sys/zfs_context.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    29
#include <sys/spa.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    30
#include <sys/vdev_impl.h>
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
    31
#include <sys/vdev_disk.h>
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
    32
#include <sys/vdev_file.h>
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
    33
#include <sys/vdev_raidz.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    34
#include <sys/zio.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    35
#include <sys/zio_checksum.h>
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    36
#include <sys/fs/zfs.h>
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
    37
#include <sys/fm/fs/zfs.h>
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    38
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    39
/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
    40
 * Virtual device vector for RAID-Z.
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    41
 *
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    42
 * This vdev supports single, double, and triple parity. For single parity,
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    43
 * we use a simple XOR of all the data columns. For double or triple parity,
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    44
 * we use a special case of Reed-Solomon coding. This extends the
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    45
 * technique described in "The mathematics of RAID-6" by H. Peter Anvin by
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    46
 * drawing on the system described in "A Tutorial on Reed-Solomon Coding for
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    47
 * Fault-Tolerance in RAID-like Systems" by James S. Plank on which the
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    48
 * former is also based. The latter is designed to provide higher performance
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    49
 * for writes.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    50
 *
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    51
 * Note that the Plank paper claimed to support arbitrary N+M, but was then
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    52
 * amended six years later identifying a critical flaw that invalidates its
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    53
 * claims. Nevertheless, the technique can be adapted to work for up to
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    54
 * triple parity. For additional parity, the amendment "Note: Correction to
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    55
 * the 1997 Tutorial on Reed-Solomon Coding" by James S. Plank and Ying Ding
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    56
 * is viable, but the additional complexity means that write performance will
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    57
 * suffer.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    58
 *
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    59
 * All of the methods above operate on a Galois field, defined over the
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    60
 * integers mod 2^N. In our case we choose N=8 for GF(8) so that all elements
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    61
 * can be expressed with a single byte. Briefly, the operations on the
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    62
 * field are defined as follows:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    63
 *
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    64
 *   o addition (+) is represented by a bitwise XOR
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    65
 *   o subtraction (-) is therefore identical to addition: A + B = A - B
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    66
 *   o multiplication of A by 2 is defined by the following bitwise expression:
14046
6a5a2f4a47db 3742 zfs comments need cleaner, more consistent style
Will Andrews <will@firepipe.net>
parents: 14045
diff changeset
    67
 *
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    68
 *	(A * 2)_7 = A_6
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    69
 *	(A * 2)_6 = A_5
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    70
 *	(A * 2)_5 = A_4
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    71
 *	(A * 2)_4 = A_3 + A_7
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    72
 *	(A * 2)_3 = A_2 + A_7
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    73
 *	(A * 2)_2 = A_1 + A_7
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    74
 *	(A * 2)_1 = A_0
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    75
 *	(A * 2)_0 = A_7
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    76
 *
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    77
 * In C, multiplying by 2 is therefore ((a << 1) ^ ((a & 0x80) ? 0x1d : 0)).
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    78
 * As an aside, this multiplication is derived from the error correcting
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    79
 * primitive polynomial x^8 + x^4 + x^3 + x^2 + 1.
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    80
 *
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    81
 * Observe that any number in the field (except for 0) can be expressed as a
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    82
 * power of 2 -- a generator for the field. We store a table of the powers of
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    83
 * 2 and logs base 2 for quick look ups, and exploit the fact that A * B can
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    84
 * be rewritten as 2^(log_2(A) + log_2(B)) (where '+' is normal addition rather
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    85
 * than field addition). The inverse of a field element A (A^-1) is therefore
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    86
 * A ^ (255 - 1) = A^254.
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    87
 *
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    88
 * The up-to-three parity columns, P, Q, R over several data columns,
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    89
 * D_0, ... D_n-1, can be expressed by field operations:
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    90
 *
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    91
 *	P = D_0 + D_1 + ... + D_n-2 + D_n-1
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    92
 *	Q = 2^n-1 * D_0 + 2^n-2 * D_1 + ... + 2^1 * D_n-2 + 2^0 * D_n-1
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    93
 *	  = ((...((D_0) * 2 + D_1) * 2 + ...) * 2 + D_n-2) * 2 + D_n-1
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    94
 *	R = 4^n-1 * D_0 + 4^n-2 * D_1 + ... + 4^1 * D_n-2 + 4^0 * D_n-1
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    95
 *	  = ((...((D_0) * 4 + D_1) * 4 + ...) * 4 + D_n-2) * 4 + D_n-1
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
    96
 *
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    97
 * We chose 1, 2, and 4 as our generators because 1 corresponds to the trival
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    98
 * XOR operation, and 2 and 4 can be computed quickly and generate linearly-
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
    99
 * independent coefficients. (There are no additional coefficients that have
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   100
 * this property which is why the uncorrected Plank method breaks down.)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   101
 *
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   102
 * See the reconstruction code below for how P, Q and R can used individually
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   103
 * or in concert to recover missing data columns.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   104
 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   105
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   106
typedef struct raidz_col {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   107
	uint64_t rc_devidx;		/* child device index for I/O */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   108
	uint64_t rc_offset;		/* device offset */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   109
	uint64_t rc_size;		/* I/O size */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   110
	void *rc_data;			/* I/O data */
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   111
	void *rc_gdata;			/* used to store the "good" version */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   112
	int rc_error;			/* I/O error for this device */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   113
	uint8_t rc_tried;		/* Did we attempt this I/O column? */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   114
	uint8_t rc_skipped;		/* Did we skip this I/O column? */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   115
} raidz_col_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   116
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   117
typedef struct raidz_map {
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   118
	uint64_t rm_cols;		/* Regular column count */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   119
	uint64_t rm_scols;		/* Count including skipped columns */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   120
	uint64_t rm_bigcols;		/* Number of oversized columns */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   121
	uint64_t rm_asize;		/* Actual total I/O size */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   122
	uint64_t rm_missingdata;	/* Count of missing data devices */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   123
	uint64_t rm_missingparity;	/* Count of missing parity devices */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   124
	uint64_t rm_firstdatacol;	/* First data column/parity count */
10450
c383b4d6980f 6869090 filebench on thumper with ZFS (snv_120) raidz causes checksum errors from all drives
Adam Leventhal <adam.leventhal@sun.com>
parents: 10105
diff changeset
   125
	uint64_t rm_nskip;		/* Skipped sectors for padding */
14046
6a5a2f4a47db 3742 zfs comments need cleaner, more consistent style
Will Andrews <will@firepipe.net>
parents: 14045
diff changeset
   126
	uint64_t rm_skipstart;		/* Column index of padding start */
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   127
	void *rm_datacopy;		/* rm_asize-buffer of copied data */
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   128
	uintptr_t rm_reports;		/* # of referencing checksum reports */
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   129
	uint8_t	rm_freed;		/* map no longer has referencing ZIO */
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   130
	uint8_t	rm_ecksuminjected;	/* checksum error was injected */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   131
	raidz_col_t rm_col[1];		/* Flexible array of I/O columns */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   132
} raidz_map_t;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   133
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   134
#define	VDEV_RAIDZ_P		0
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   135
#define	VDEV_RAIDZ_Q		1
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   136
#define	VDEV_RAIDZ_R		2
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   137
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   138
#define	VDEV_RAIDZ_MUL_2(x)	(((x) << 1) ^ (((x) & 0x80) ? 0x1d : 0))
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   139
#define	VDEV_RAIDZ_MUL_4(x)	(VDEV_RAIDZ_MUL_2(VDEV_RAIDZ_MUL_2(x)))
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   140
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   141
/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   142
 * We provide a mechanism to perform the field multiplication operation on a
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   143
 * 64-bit value all at once rather than a byte at a time. This works by
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   144
 * creating a mask from the top bit in each byte and using that to
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   145
 * conditionally apply the XOR of 0x1d.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   146
 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   147
#define	VDEV_RAIDZ_64MUL_2(x, mask) \
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   148
{ \
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   149
	(mask) = (x) & 0x8080808080808080ULL; \
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   150
	(mask) = ((mask) << 1) - ((mask) >> 7); \
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   151
	(x) = (((x) << 1) & 0xfefefefefefefefeULL) ^ \
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   152
	    ((mask) & 0x1d1d1d1d1d1d1d1d); \
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   153
}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   154
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   155
#define	VDEV_RAIDZ_64MUL_4(x, mask) \
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   156
{ \
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   157
	VDEV_RAIDZ_64MUL_2((x), mask); \
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   158
	VDEV_RAIDZ_64MUL_2((x), mask); \
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   159
}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   160
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
   161
#define	VDEV_LABEL_OFFSET(x)	(x + VDEV_LABEL_START_SIZE)
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
   162
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   163
/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   164
 * Force reconstruction to use the general purpose method.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   165
 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   166
int vdev_raidz_default_to_general;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   167
14046
6a5a2f4a47db 3742 zfs comments need cleaner, more consistent style
Will Andrews <will@firepipe.net>
parents: 14045
diff changeset
   168
/* Powers of 2 in the Galois field defined above. */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   169
static const uint8_t vdev_raidz_pow2[256] = {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   170
	0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   171
	0x1d, 0x3a, 0x74, 0xe8, 0xcd, 0x87, 0x13, 0x26,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   172
	0x4c, 0x98, 0x2d, 0x5a, 0xb4, 0x75, 0xea, 0xc9,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   173
	0x8f, 0x03, 0x06, 0x0c, 0x18, 0x30, 0x60, 0xc0,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   174
	0x9d, 0x27, 0x4e, 0x9c, 0x25, 0x4a, 0x94, 0x35,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   175
	0x6a, 0xd4, 0xb5, 0x77, 0xee, 0xc1, 0x9f, 0x23,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   176
	0x46, 0x8c, 0x05, 0x0a, 0x14, 0x28, 0x50, 0xa0,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   177
	0x5d, 0xba, 0x69, 0xd2, 0xb9, 0x6f, 0xde, 0xa1,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   178
	0x5f, 0xbe, 0x61, 0xc2, 0x99, 0x2f, 0x5e, 0xbc,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   179
	0x65, 0xca, 0x89, 0x0f, 0x1e, 0x3c, 0x78, 0xf0,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   180
	0xfd, 0xe7, 0xd3, 0xbb, 0x6b, 0xd6, 0xb1, 0x7f,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   181
	0xfe, 0xe1, 0xdf, 0xa3, 0x5b, 0xb6, 0x71, 0xe2,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   182
	0xd9, 0xaf, 0x43, 0x86, 0x11, 0x22, 0x44, 0x88,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   183
	0x0d, 0x1a, 0x34, 0x68, 0xd0, 0xbd, 0x67, 0xce,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   184
	0x81, 0x1f, 0x3e, 0x7c, 0xf8, 0xed, 0xc7, 0x93,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   185
	0x3b, 0x76, 0xec, 0xc5, 0x97, 0x33, 0x66, 0xcc,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   186
	0x85, 0x17, 0x2e, 0x5c, 0xb8, 0x6d, 0xda, 0xa9,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   187
	0x4f, 0x9e, 0x21, 0x42, 0x84, 0x15, 0x2a, 0x54,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   188
	0xa8, 0x4d, 0x9a, 0x29, 0x52, 0xa4, 0x55, 0xaa,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   189
	0x49, 0x92, 0x39, 0x72, 0xe4, 0xd5, 0xb7, 0x73,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   190
	0xe6, 0xd1, 0xbf, 0x63, 0xc6, 0x91, 0x3f, 0x7e,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   191
	0xfc, 0xe5, 0xd7, 0xb3, 0x7b, 0xf6, 0xf1, 0xff,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   192
	0xe3, 0xdb, 0xab, 0x4b, 0x96, 0x31, 0x62, 0xc4,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   193
	0x95, 0x37, 0x6e, 0xdc, 0xa5, 0x57, 0xae, 0x41,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   194
	0x82, 0x19, 0x32, 0x64, 0xc8, 0x8d, 0x07, 0x0e,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   195
	0x1c, 0x38, 0x70, 0xe0, 0xdd, 0xa7, 0x53, 0xa6,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   196
	0x51, 0xa2, 0x59, 0xb2, 0x79, 0xf2, 0xf9, 0xef,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   197
	0xc3, 0x9b, 0x2b, 0x56, 0xac, 0x45, 0x8a, 0x09,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   198
	0x12, 0x24, 0x48, 0x90, 0x3d, 0x7a, 0xf4, 0xf5,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   199
	0xf7, 0xf3, 0xfb, 0xeb, 0xcb, 0x8b, 0x0b, 0x16,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   200
	0x2c, 0x58, 0xb0, 0x7d, 0xfa, 0xe9, 0xcf, 0x83,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   201
	0x1b, 0x36, 0x6c, 0xd8, 0xad, 0x47, 0x8e, 0x01
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   202
};
14046
6a5a2f4a47db 3742 zfs comments need cleaner, more consistent style
Will Andrews <will@firepipe.net>
parents: 14045
diff changeset
   203
/* Logs of 2 in the Galois field defined above. */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   204
static const uint8_t vdev_raidz_log2[256] = {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   205
	0x00, 0x00, 0x01, 0x19, 0x02, 0x32, 0x1a, 0xc6,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   206
	0x03, 0xdf, 0x33, 0xee, 0x1b, 0x68, 0xc7, 0x4b,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   207
	0x04, 0x64, 0xe0, 0x0e, 0x34, 0x8d, 0xef, 0x81,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   208
	0x1c, 0xc1, 0x69, 0xf8, 0xc8, 0x08, 0x4c, 0x71,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   209
	0x05, 0x8a, 0x65, 0x2f, 0xe1, 0x24, 0x0f, 0x21,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   210
	0x35, 0x93, 0x8e, 0xda, 0xf0, 0x12, 0x82, 0x45,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   211
	0x1d, 0xb5, 0xc2, 0x7d, 0x6a, 0x27, 0xf9, 0xb9,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   212
	0xc9, 0x9a, 0x09, 0x78, 0x4d, 0xe4, 0x72, 0xa6,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   213
	0x06, 0xbf, 0x8b, 0x62, 0x66, 0xdd, 0x30, 0xfd,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   214
	0xe2, 0x98, 0x25, 0xb3, 0x10, 0x91, 0x22, 0x88,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   215
	0x36, 0xd0, 0x94, 0xce, 0x8f, 0x96, 0xdb, 0xbd,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   216
	0xf1, 0xd2, 0x13, 0x5c, 0x83, 0x38, 0x46, 0x40,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   217
	0x1e, 0x42, 0xb6, 0xa3, 0xc3, 0x48, 0x7e, 0x6e,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   218
	0x6b, 0x3a, 0x28, 0x54, 0xfa, 0x85, 0xba, 0x3d,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   219
	0xca, 0x5e, 0x9b, 0x9f, 0x0a, 0x15, 0x79, 0x2b,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   220
	0x4e, 0xd4, 0xe5, 0xac, 0x73, 0xf3, 0xa7, 0x57,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   221
	0x07, 0x70, 0xc0, 0xf7, 0x8c, 0x80, 0x63, 0x0d,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   222
	0x67, 0x4a, 0xde, 0xed, 0x31, 0xc5, 0xfe, 0x18,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   223
	0xe3, 0xa5, 0x99, 0x77, 0x26, 0xb8, 0xb4, 0x7c,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   224
	0x11, 0x44, 0x92, 0xd9, 0x23, 0x20, 0x89, 0x2e,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   225
	0x37, 0x3f, 0xd1, 0x5b, 0x95, 0xbc, 0xcf, 0xcd,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   226
	0x90, 0x87, 0x97, 0xb2, 0xdc, 0xfc, 0xbe, 0x61,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   227
	0xf2, 0x56, 0xd3, 0xab, 0x14, 0x2a, 0x5d, 0x9e,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   228
	0x84, 0x3c, 0x39, 0x53, 0x47, 0x6d, 0x41, 0xa2,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   229
	0x1f, 0x2d, 0x43, 0xd8, 0xb7, 0x7b, 0xa4, 0x76,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   230
	0xc4, 0x17, 0x49, 0xec, 0x7f, 0x0c, 0x6f, 0xf6,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   231
	0x6c, 0xa1, 0x3b, 0x52, 0x29, 0x9d, 0x55, 0xaa,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   232
	0xfb, 0x60, 0x86, 0xb1, 0xbb, 0xcc, 0x3e, 0x5a,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   233
	0xcb, 0x59, 0x5f, 0xb0, 0x9c, 0xa9, 0xa0, 0x51,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   234
	0x0b, 0xf5, 0x16, 0xeb, 0x7a, 0x75, 0x2c, 0xd7,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   235
	0x4f, 0xae, 0xd5, 0xe9, 0xe6, 0xe7, 0xad, 0xe8,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   236
	0x74, 0xd6, 0xf4, 0xea, 0xa8, 0x50, 0x58, 0xaf,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   237
};
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   238
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   239
static void vdev_raidz_generate_parity(raidz_map_t *rm);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   240
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   241
/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   242
 * Multiply a given number by 2 raised to the given power.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   243
 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   244
static uint8_t
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   245
vdev_raidz_exp2(uint_t a, int exp)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   246
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   247
	if (a == 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   248
		return (0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   249
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   250
	ASSERT(exp >= 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   251
	ASSERT(vdev_raidz_log2[a] > 0 || a == 1);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   252
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   253
	exp += vdev_raidz_log2[a];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   254
	if (exp > 255)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   255
		exp -= 255;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   256
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   257
	return (vdev_raidz_pow2[exp]);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   258
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   259
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
   260
static void
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   261
vdev_raidz_map_free(raidz_map_t *rm)
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
   262
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
   263
	int c;
10653
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   264
	size_t size;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
   265
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   266
	for (c = 0; c < rm->rm_firstdatacol; c++) {
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
   267
		zio_buf_free(rm->rm_col[c].rc_data, rm->rm_col[c].rc_size);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
   268
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   269
		if (rm->rm_col[c].rc_gdata != NULL)
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   270
			zio_buf_free(rm->rm_col[c].rc_gdata,
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   271
			    rm->rm_col[c].rc_size);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   272
	}
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   273
10653
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   274
	size = 0;
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   275
	for (c = rm->rm_firstdatacol; c < rm->rm_cols; c++)
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   276
		size += rm->rm_col[c].rc_size;
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   277
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   278
	if (rm->rm_datacopy != NULL)
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   279
		zio_buf_free(rm->rm_datacopy, size);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   280
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   281
	kmem_free(rm, offsetof(raidz_map_t, rm_col[rm->rm_scols]));
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
   282
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
   283
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   284
static void
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   285
vdev_raidz_map_free_vsd(zio_t *zio)
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   286
{
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   287
	raidz_map_t *rm = zio->io_vsd;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   288
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
   289
	ASSERT0(rm->rm_freed);
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   290
	rm->rm_freed = 1;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   291
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   292
	if (rm->rm_reports == 0)
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   293
		vdev_raidz_map_free(rm);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   294
}
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   295
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   296
/*ARGSUSED*/
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   297
static void
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   298
vdev_raidz_cksum_free(void *arg, size_t ignored)
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   299
{
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   300
	raidz_map_t *rm = arg;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   301
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   302
	ASSERT3U(rm->rm_reports, >, 0);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   303
10653
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   304
	if (--rm->rm_reports == 0 && rm->rm_freed != 0)
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   305
		vdev_raidz_map_free(rm);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   306
}
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   307
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   308
static void
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   309
vdev_raidz_cksum_finish(zio_cksum_report_t *zcr, const void *good_data)
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   310
{
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   311
	raidz_map_t *rm = zcr->zcr_cbdata;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   312
	size_t c = zcr->zcr_cbinfo;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   313
	size_t x;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   314
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   315
	const char *good = NULL;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   316
	const char *bad = rm->rm_col[c].rc_data;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   317
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   318
	if (good_data == NULL) {
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   319
		zfs_ereport_finish_checksum(zcr, NULL, NULL, B_FALSE);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   320
		return;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   321
	}
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   322
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   323
	if (c < rm->rm_firstdatacol) {
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   324
		/*
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   325
		 * The first time through, calculate the parity blocks for
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   326
		 * the good data (this relies on the fact that the good
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   327
		 * data never changes for a given logical ZIO)
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   328
		 */
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   329
		if (rm->rm_col[0].rc_gdata == NULL) {
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   330
			char *bad_parity[VDEV_RAIDZ_MAXPARITY];
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   331
			char *buf;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   332
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   333
			/*
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   334
			 * Set up the rm_col[]s to generate the parity for
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   335
			 * good_data, first saving the parity bufs and
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   336
			 * replacing them with buffers to hold the result.
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   337
			 */
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   338
			for (x = 0; x < rm->rm_firstdatacol; x++) {
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   339
				bad_parity[x] = rm->rm_col[x].rc_data;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   340
				rm->rm_col[x].rc_data = rm->rm_col[x].rc_gdata =
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   341
				    zio_buf_alloc(rm->rm_col[x].rc_size);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   342
			}
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   343
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   344
			/* fill in the data columns from good_data */
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   345
			buf = (char *)good_data;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   346
			for (; x < rm->rm_cols; x++) {
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   347
				rm->rm_col[x].rc_data = buf;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   348
				buf += rm->rm_col[x].rc_size;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   349
			}
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   350
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   351
			/*
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   352
			 * Construct the parity from the good data.
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   353
			 */
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   354
			vdev_raidz_generate_parity(rm);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   355
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   356
			/* restore everything back to its original state */
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   357
			for (x = 0; x < rm->rm_firstdatacol; x++)
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   358
				rm->rm_col[x].rc_data = bad_parity[x];
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   359
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   360
			buf = rm->rm_datacopy;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   361
			for (x = rm->rm_firstdatacol; x < rm->rm_cols; x++) {
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   362
				rm->rm_col[x].rc_data = buf;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   363
				buf += rm->rm_col[x].rc_size;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   364
			}
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   365
		}
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   366
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   367
		ASSERT3P(rm->rm_col[c].rc_gdata, !=, NULL);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   368
		good = rm->rm_col[c].rc_gdata;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   369
	} else {
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   370
		/* adjust good_data to point at the start of our column */
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   371
		good = good_data;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   372
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   373
		for (x = rm->rm_firstdatacol; x < c; x++)
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   374
			good += rm->rm_col[x].rc_size;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   375
	}
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   376
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   377
	/* we drop the ereport if it ends up that the data was good */
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   378
	zfs_ereport_finish_checksum(zcr, good, bad, B_TRUE);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   379
}
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   380
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   381
/*
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   382
 * Invoked indirectly by zfs_ereport_start_checksum(), called
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   383
 * below when our read operation fails completely.  The main point
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   384
 * is to keep a copy of everything we read from disk, so that at
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   385
 * vdev_raidz_cksum_finish() time we can compare it with the good data.
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   386
 */
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   387
static void
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   388
vdev_raidz_cksum_report(zio_t *zio, zio_cksum_report_t *zcr, void *arg)
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   389
{
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   390
	size_t c = (size_t)(uintptr_t)arg;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   391
	caddr_t buf;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   392
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   393
	raidz_map_t *rm = zio->io_vsd;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   394
	size_t size;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   395
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   396
	/* set up the report and bump the refcount  */
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   397
	zcr->zcr_cbdata = rm;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   398
	zcr->zcr_cbinfo = c;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   399
	zcr->zcr_finish = vdev_raidz_cksum_finish;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   400
	zcr->zcr_free = vdev_raidz_cksum_free;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   401
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   402
	rm->rm_reports++;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   403
	ASSERT3U(rm->rm_reports, >, 0);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   404
10653
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   405
	if (rm->rm_datacopy != NULL)
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   406
		return;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   407
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   408
	/*
10653
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   409
	 * It's the first time we're called for this raidz_map_t, so we need
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   410
	 * to copy the data aside; there's no guarantee that our zio's buffer
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   411
	 * won't be re-used for something else.
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   412
	 *
10653
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   413
	 * Our parity data is already in separate buffers, so there's no need
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   414
	 * to copy them.
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   415
	 */
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   416
10653
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   417
	size = 0;
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   418
	for (c = rm->rm_firstdatacol; c < rm->rm_cols; c++)
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   419
		size += rm->rm_col[c].rc_size;
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   420
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   421
	buf = rm->rm_datacopy = zio_buf_alloc(size);
10653
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   422
e0ceed15cf0a 6885320 assertion failed: rm->rm_freed != 0 (0x0 != 0x0), file: ../../common/fs/zfs/vdev_raidz.c, line: 298
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10614
diff changeset
   423
	for (c = rm->rm_firstdatacol; c < rm->rm_cols; c++) {
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   424
		raidz_col_t *col = &rm->rm_col[c];
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   425
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   426
		bcopy(col->rc_data, buf, col->rc_size);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   427
		col->rc_data = buf;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   428
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   429
		buf += col->rc_size;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   430
	}
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   431
	ASSERT3P(buf - (caddr_t)rm->rm_datacopy, ==, size);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   432
}
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   433
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   434
static const zio_vsd_ops_t vdev_raidz_vsd_ops = {
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   435
	vdev_raidz_map_free_vsd,
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   436
	vdev_raidz_cksum_report
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   437
};
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   438
14045
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   439
/*
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   440
 * Divides the IO evenly across all child vdevs; usually, dcols is
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   441
 * the number of children in the target vdev.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   442
 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   443
static raidz_map_t *
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
   444
vdev_raidz_map_alloc(caddr_t data, uint64_t size, uint64_t offset,
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
   445
    uint64_t unit_shift, uint64_t dcols, uint64_t nparity)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   446
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   447
	raidz_map_t *rm;
14045
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   448
	/* The starting RAIDZ (parent) vdev sector of the block. */
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
   449
	uint64_t b = offset >> unit_shift;
14045
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   450
	/* The zio's size in units of the vdev's minimum sector size. */
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
   451
	uint64_t s = size >> unit_shift;
14045
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   452
	/* The first column for this stripe. */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   453
	uint64_t f = b % dcols;
14045
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   454
	/* The starting byte offset on each child vdev. */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   455
	uint64_t o = (b / dcols) << unit_shift;
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   456
	uint64_t q, r, c, bc, col, acols, scols, coff, devidx, asize, tot;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   457
14045
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   458
	/*
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   459
	 * "Quotient": The number of data sectors for this stripe on all but
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   460
	 * the "big column" child vdevs that also contain "remainder" data.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   461
	 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   462
	q = s / (dcols - nparity);
14045
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   463
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   464
	/*
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   465
	 * "Remainder": The number of partial stripe data sectors in this I/O.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   466
	 * This will add a sector to some, but not all, child vdevs.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   467
	 */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   468
	r = s - q * (dcols - nparity);
14045
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   469
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   470
	/* The number of "big columns" - those which contain remainder data. */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   471
	bc = (r == 0 ? 0 : r + nparity);
14045
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   472
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   473
	/*
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   474
	 * The total number of data and parity sectors associated with
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   475
	 * this I/O.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   476
	 */
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   477
	tot = s + nparity * (q + (r == 0 ? 0 : 1));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   478
14045
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   479
	/* acols: The columns that will be accessed. */
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   480
	/* scols: The columns that will be accessed or skipped. */
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   481
	if (q == 0) {
14045
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
   482
		/* Our I/O request doesn't span all child vdevs. */
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   483
		acols = bc;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   484
		scols = MIN(dcols, roundup(bc, nparity + 1));
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   485
	} else {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   486
		acols = dcols;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   487
		scols = dcols;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   488
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   489
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   490
	ASSERT3U(acols, <=, scols);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   491
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   492
	rm = kmem_alloc(offsetof(raidz_map_t, rm_col[scols]), KM_SLEEP);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   493
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   494
	rm->rm_cols = acols;
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   495
	rm->rm_scols = scols;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   496
	rm->rm_bigcols = bc;
10450
c383b4d6980f 6869090 filebench on thumper with ZFS (snv_120) raidz causes checksum errors from all drives
Adam Leventhal <adam.leventhal@sun.com>
parents: 10105
diff changeset
   497
	rm->rm_skipstart = bc;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   498
	rm->rm_missingdata = 0;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   499
	rm->rm_missingparity = 0;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   500
	rm->rm_firstdatacol = nparity;
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   501
	rm->rm_datacopy = NULL;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   502
	rm->rm_reports = 0;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   503
	rm->rm_freed = 0;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   504
	rm->rm_ecksuminjected = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   505
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   506
	asize = 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   507
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   508
	for (c = 0; c < scols; c++) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   509
		col = f + c;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   510
		coff = o;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   511
		if (col >= dcols) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   512
			col -= dcols;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   513
			coff += 1ULL << unit_shift;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   514
		}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   515
		rm->rm_col[c].rc_devidx = col;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   516
		rm->rm_col[c].rc_offset = coff;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   517
		rm->rm_col[c].rc_data = NULL;
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
   518
		rm->rm_col[c].rc_gdata = NULL;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   519
		rm->rm_col[c].rc_error = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   520
		rm->rm_col[c].rc_tried = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   521
		rm->rm_col[c].rc_skipped = 0;
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   522
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   523
		if (c >= acols)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   524
			rm->rm_col[c].rc_size = 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   525
		else if (c < bc)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   526
			rm->rm_col[c].rc_size = (q + 1) << unit_shift;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   527
		else
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   528
			rm->rm_col[c].rc_size = q << unit_shift;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   529
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   530
		asize += rm->rm_col[c].rc_size;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   531
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   532
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   533
	ASSERT3U(asize, ==, tot << unit_shift);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   534
	rm->rm_asize = roundup(asize, (nparity + 1) << unit_shift);
10450
c383b4d6980f 6869090 filebench on thumper with ZFS (snv_120) raidz causes checksum errors from all drives
Adam Leventhal <adam.leventhal@sun.com>
parents: 10105
diff changeset
   535
	rm->rm_nskip = roundup(tot, nparity + 1) - tot;
c383b4d6980f 6869090 filebench on thumper with ZFS (snv_120) raidz causes checksum errors from all drives
Adam Leventhal <adam.leventhal@sun.com>
parents: 10105
diff changeset
   536
	ASSERT3U(rm->rm_asize - asize, ==, rm->rm_nskip << unit_shift);
c383b4d6980f 6869090 filebench on thumper with ZFS (snv_120) raidz causes checksum errors from all drives
Adam Leventhal <adam.leventhal@sun.com>
parents: 10105
diff changeset
   537
	ASSERT3U(rm->rm_nskip, <=, nparity);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   538
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   539
	for (c = 0; c < rm->rm_firstdatacol; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   540
		rm->rm_col[c].rc_data = zio_buf_alloc(rm->rm_col[c].rc_size);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   541
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
   542
	rm->rm_col[c].rc_data = data;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   543
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   544
	for (c = c + 1; c < acols; c++)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   545
		rm->rm_col[c].rc_data = (char *)rm->rm_col[c - 1].rc_data +
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   546
		    rm->rm_col[c - 1].rc_size;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   547
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 789
diff changeset
   548
	/*
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   549
	 * If all data stored spans all columns, there's a danger that parity
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   550
	 * will always be on the same device and, since parity isn't read
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   551
	 * during normal operation, that that device's I/O bandwidth won't be
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   552
	 * used effectively. We therefore switch the parity every 1MB.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   553
	 *
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   554
	 * ... at least that was, ostensibly, the theory. As a practical
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   555
	 * matter unless we juggle the parity between all devices evenly, we
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   556
	 * won't see any benefit. Further, occasional writes that aren't a
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   557
	 * multiple of the LCM of the number of children and the minimum
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   558
	 * stripe width are sufficient to avoid pessimal behavior.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   559
	 * Unfortunately, this decision created an implicit on-disk format
3456
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
   560
	 * requirement that we need to support for all eternity, but only
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
   561
	 * for single-parity RAID-Z.
10450
c383b4d6980f 6869090 filebench on thumper with ZFS (snv_120) raidz causes checksum errors from all drives
Adam Leventhal <adam.leventhal@sun.com>
parents: 10105
diff changeset
   562
	 *
c383b4d6980f 6869090 filebench on thumper with ZFS (snv_120) raidz causes checksum errors from all drives
Adam Leventhal <adam.leventhal@sun.com>
parents: 10105
diff changeset
   563
	 * If we intend to skip a sector in the zeroth column for padding
c383b4d6980f 6869090 filebench on thumper with ZFS (snv_120) raidz causes checksum errors from all drives
Adam Leventhal <adam.leventhal@sun.com>
parents: 10105
diff changeset
   564
	 * we must make sure to note this swap. We will never intend to
c383b4d6980f 6869090 filebench on thumper with ZFS (snv_120) raidz causes checksum errors from all drives
Adam Leventhal <adam.leventhal@sun.com>
parents: 10105
diff changeset
   565
	 * skip the first column since at least one data and one parity
c383b4d6980f 6869090 filebench on thumper with ZFS (snv_120) raidz causes checksum errors from all drives
Adam Leventhal <adam.leventhal@sun.com>
parents: 10105
diff changeset
   566
	 * column must appear in each row.
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 789
diff changeset
   567
	 */
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 789
diff changeset
   568
	ASSERT(rm->rm_cols >= 2);
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 789
diff changeset
   569
	ASSERT(rm->rm_col[0].rc_size == rm->rm_col[1].rc_size);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   570
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
   571
	if (rm->rm_firstdatacol == 1 && (offset & (1ULL << 20))) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   572
		devidx = rm->rm_col[0].rc_devidx;
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 789
diff changeset
   573
		o = rm->rm_col[0].rc_offset;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   574
		rm->rm_col[0].rc_devidx = rm->rm_col[1].rc_devidx;
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 789
diff changeset
   575
		rm->rm_col[0].rc_offset = rm->rm_col[1].rc_offset;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   576
		rm->rm_col[1].rc_devidx = devidx;
1133
335d069294d1 6357470 vdev_raidz.c has unused RAIDZ_SINGLE define, code
eschrock
parents: 789
diff changeset
   577
		rm->rm_col[1].rc_offset = o;
10450
c383b4d6980f 6869090 filebench on thumper with ZFS (snv_120) raidz causes checksum errors from all drives
Adam Leventhal <adam.leventhal@sun.com>
parents: 10105
diff changeset
   578
c383b4d6980f 6869090 filebench on thumper with ZFS (snv_120) raidz causes checksum errors from all drives
Adam Leventhal <adam.leventhal@sun.com>
parents: 10105
diff changeset
   579
		if (rm->rm_skipstart == 0)
c383b4d6980f 6869090 filebench on thumper with ZFS (snv_120) raidz causes checksum errors from all drives
Adam Leventhal <adam.leventhal@sun.com>
parents: 10105
diff changeset
   580
			rm->rm_skipstart = 1;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   581
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   582
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   583
	return (rm);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   584
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   585
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   586
static void
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   587
vdev_raidz_generate_parity_p(raidz_map_t *rm)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   588
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   589
	uint64_t *p, *src, pcount, ccount, i;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   590
	int c;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   591
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   592
	pcount = rm->rm_col[VDEV_RAIDZ_P].rc_size / sizeof (src[0]);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   593
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   594
	for (c = rm->rm_firstdatacol; c < rm->rm_cols; c++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   595
		src = rm->rm_col[c].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   596
		p = rm->rm_col[VDEV_RAIDZ_P].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   597
		ccount = rm->rm_col[c].rc_size / sizeof (src[0]);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   598
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   599
		if (c == rm->rm_firstdatacol) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   600
			ASSERT(ccount == pcount);
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   601
			for (i = 0; i < ccount; i++, src++, p++) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   602
				*p = *src;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   603
			}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   604
		} else {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   605
			ASSERT(ccount <= pcount);
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   606
			for (i = 0; i < ccount; i++, src++, p++) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   607
				*p ^= *src;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   608
			}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   609
		}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   610
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   611
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   612
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   613
static void
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   614
vdev_raidz_generate_parity_pq(raidz_map_t *rm)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   615
{
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   616
	uint64_t *p, *q, *src, pcnt, ccnt, mask, i;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   617
	int c;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   618
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   619
	pcnt = rm->rm_col[VDEV_RAIDZ_P].rc_size / sizeof (src[0]);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   620
	ASSERT(rm->rm_col[VDEV_RAIDZ_P].rc_size ==
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   621
	    rm->rm_col[VDEV_RAIDZ_Q].rc_size);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   622
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   623
	for (c = rm->rm_firstdatacol; c < rm->rm_cols; c++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   624
		src = rm->rm_col[c].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   625
		p = rm->rm_col[VDEV_RAIDZ_P].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   626
		q = rm->rm_col[VDEV_RAIDZ_Q].rc_data;
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   627
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   628
		ccnt = rm->rm_col[c].rc_size / sizeof (src[0]);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   629
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   630
		if (c == rm->rm_firstdatacol) {
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   631
			ASSERT(ccnt == pcnt || ccnt == 0);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   632
			for (i = 0; i < ccnt; i++, src++, p++, q++) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   633
				*p = *src;
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   634
				*q = *src;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   635
			}
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   636
			for (; i < pcnt; i++, src++, p++, q++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   637
				*p = 0;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   638
				*q = 0;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   639
			}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   640
		} else {
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   641
			ASSERT(ccnt <= pcnt);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   642
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   643
			/*
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   644
			 * Apply the algorithm described above by multiplying
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   645
			 * the previous result and adding in the new value.
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   646
			 */
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   647
			for (i = 0; i < ccnt; i++, src++, p++, q++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   648
				*p ^= *src;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   649
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   650
				VDEV_RAIDZ_64MUL_2(*q, mask);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   651
				*q ^= *src;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   652
			}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   653
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   654
			/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   655
			 * Treat short columns as though they are full of 0s.
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   656
			 * Note that there's therefore nothing needed for P.
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   657
			 */
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   658
			for (; i < pcnt; i++, q++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   659
				VDEV_RAIDZ_64MUL_2(*q, mask);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   660
			}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   661
		}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   662
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   663
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   664
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   665
static void
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   666
vdev_raidz_generate_parity_pqr(raidz_map_t *rm)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   667
{
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   668
	uint64_t *p, *q, *r, *src, pcnt, ccnt, mask, i;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   669
	int c;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   670
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   671
	pcnt = rm->rm_col[VDEV_RAIDZ_P].rc_size / sizeof (src[0]);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   672
	ASSERT(rm->rm_col[VDEV_RAIDZ_P].rc_size ==
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   673
	    rm->rm_col[VDEV_RAIDZ_Q].rc_size);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   674
	ASSERT(rm->rm_col[VDEV_RAIDZ_P].rc_size ==
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   675
	    rm->rm_col[VDEV_RAIDZ_R].rc_size);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   676
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   677
	for (c = rm->rm_firstdatacol; c < rm->rm_cols; c++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   678
		src = rm->rm_col[c].rc_data;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   679
		p = rm->rm_col[VDEV_RAIDZ_P].rc_data;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   680
		q = rm->rm_col[VDEV_RAIDZ_Q].rc_data;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   681
		r = rm->rm_col[VDEV_RAIDZ_R].rc_data;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   682
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   683
		ccnt = rm->rm_col[c].rc_size / sizeof (src[0]);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   684
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   685
		if (c == rm->rm_firstdatacol) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   686
			ASSERT(ccnt == pcnt || ccnt == 0);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   687
			for (i = 0; i < ccnt; i++, src++, p++, q++, r++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   688
				*p = *src;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   689
				*q = *src;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   690
				*r = *src;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   691
			}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   692
			for (; i < pcnt; i++, src++, p++, q++, r++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   693
				*p = 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   694
				*q = 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   695
				*r = 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   696
			}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   697
		} else {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   698
			ASSERT(ccnt <= pcnt);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   699
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   700
			/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   701
			 * Apply the algorithm described above by multiplying
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   702
			 * the previous result and adding in the new value.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   703
			 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   704
			for (i = 0; i < ccnt; i++, src++, p++, q++, r++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   705
				*p ^= *src;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   706
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   707
				VDEV_RAIDZ_64MUL_2(*q, mask);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   708
				*q ^= *src;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   709
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   710
				VDEV_RAIDZ_64MUL_4(*r, mask);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   711
				*r ^= *src;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   712
			}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   713
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   714
			/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   715
			 * Treat short columns as though they are full of 0s.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   716
			 * Note that there's therefore nothing needed for P.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   717
			 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   718
			for (; i < pcnt; i++, q++, r++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   719
				VDEV_RAIDZ_64MUL_2(*q, mask);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   720
				VDEV_RAIDZ_64MUL_4(*r, mask);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   721
			}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   722
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   723
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   724
}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   725
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   726
/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   727
 * Generate RAID parity in the first virtual columns according to the number of
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   728
 * parity columns available.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   729
 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   730
static void
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   731
vdev_raidz_generate_parity(raidz_map_t *rm)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   732
{
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   733
	switch (rm->rm_firstdatacol) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   734
	case 1:
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   735
		vdev_raidz_generate_parity_p(rm);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   736
		break;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   737
	case 2:
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   738
		vdev_raidz_generate_parity_pq(rm);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   739
		break;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   740
	case 3:
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   741
		vdev_raidz_generate_parity_pqr(rm);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   742
		break;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   743
	default:
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   744
		cmn_err(CE_PANIC, "invalid RAID-Z configuration");
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   745
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   746
}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   747
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   748
static int
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   749
vdev_raidz_reconstruct_p(raidz_map_t *rm, int *tgts, int ntgts)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   750
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   751
	uint64_t *dst, *src, xcount, ccount, count, i;
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   752
	int x = tgts[0];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   753
	int c;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   754
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   755
	ASSERT(ntgts == 1);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   756
	ASSERT(x >= rm->rm_firstdatacol);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   757
	ASSERT(x < rm->rm_cols);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   758
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   759
	xcount = rm->rm_col[x].rc_size / sizeof (src[0]);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   760
	ASSERT(xcount <= rm->rm_col[VDEV_RAIDZ_P].rc_size / sizeof (src[0]));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   761
	ASSERT(xcount > 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   762
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   763
	src = rm->rm_col[VDEV_RAIDZ_P].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   764
	dst = rm->rm_col[x].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   765
	for (i = 0; i < xcount; i++, dst++, src++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   766
		*dst = *src;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   767
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   768
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   769
	for (c = rm->rm_firstdatacol; c < rm->rm_cols; c++) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   770
		src = rm->rm_col[c].rc_data;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   771
		dst = rm->rm_col[x].rc_data;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   772
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   773
		if (c == x)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   774
			continue;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   775
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   776
		ccount = rm->rm_col[c].rc_size / sizeof (src[0]);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   777
		count = MIN(ccount, xcount);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   778
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   779
		for (i = 0; i < count; i++, dst++, src++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   780
			*dst ^= *src;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   781
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   782
	}
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   783
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   784
	return (1 << VDEV_RAIDZ_P);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   785
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
   786
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   787
static int
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   788
vdev_raidz_reconstruct_q(raidz_map_t *rm, int *tgts, int ntgts)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   789
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   790
	uint64_t *dst, *src, xcount, ccount, count, mask, i;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   791
	uint8_t *b;
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   792
	int x = tgts[0];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   793
	int c, j, exp;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   794
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   795
	ASSERT(ntgts == 1);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   796
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   797
	xcount = rm->rm_col[x].rc_size / sizeof (src[0]);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   798
	ASSERT(xcount <= rm->rm_col[VDEV_RAIDZ_Q].rc_size / sizeof (src[0]));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   799
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   800
	for (c = rm->rm_firstdatacol; c < rm->rm_cols; c++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   801
		src = rm->rm_col[c].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   802
		dst = rm->rm_col[x].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   803
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   804
		if (c == x)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   805
			ccount = 0;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   806
		else
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   807
			ccount = rm->rm_col[c].rc_size / sizeof (src[0]);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   808
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   809
		count = MIN(ccount, xcount);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   810
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   811
		if (c == rm->rm_firstdatacol) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   812
			for (i = 0; i < count; i++, dst++, src++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   813
				*dst = *src;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   814
			}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   815
			for (; i < xcount; i++, dst++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   816
				*dst = 0;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   817
			}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   818
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   819
		} else {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   820
			for (i = 0; i < count; i++, dst++, src++) {
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   821
				VDEV_RAIDZ_64MUL_2(*dst, mask);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   822
				*dst ^= *src;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   823
			}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   824
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   825
			for (; i < xcount; i++, dst++) {
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   826
				VDEV_RAIDZ_64MUL_2(*dst, mask);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   827
			}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   828
		}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   829
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   830
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   831
	src = rm->rm_col[VDEV_RAIDZ_Q].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   832
	dst = rm->rm_col[x].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   833
	exp = 255 - (rm->rm_cols - 1 - x);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   834
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   835
	for (i = 0; i < xcount; i++, dst++, src++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   836
		*dst ^= *src;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   837
		for (j = 0, b = (uint8_t *)dst; j < 8; j++, b++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   838
			*b = vdev_raidz_exp2(*b, exp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   839
		}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   840
	}
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   841
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   842
	return (1 << VDEV_RAIDZ_Q);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   843
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   844
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   845
static int
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   846
vdev_raidz_reconstruct_pq(raidz_map_t *rm, int *tgts, int ntgts)
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   847
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   848
	uint8_t *p, *q, *pxy, *qxy, *xd, *yd, tmp, a, b, aexp, bexp;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   849
	void *pdata, *qdata;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   850
	uint64_t xsize, ysize, i;
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   851
	int x = tgts[0];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   852
	int y = tgts[1];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   853
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   854
	ASSERT(ntgts == 2);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   855
	ASSERT(x < y);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   856
	ASSERT(x >= rm->rm_firstdatacol);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   857
	ASSERT(y < rm->rm_cols);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   858
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   859
	ASSERT(rm->rm_col[x].rc_size >= rm->rm_col[y].rc_size);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   860
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   861
	/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   862
	 * Move the parity data aside -- we're going to compute parity as
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   863
	 * though columns x and y were full of zeros -- Pxy and Qxy. We want to
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   864
	 * reuse the parity generation mechanism without trashing the actual
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   865
	 * parity so we make those columns appear to be full of zeros by
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   866
	 * setting their lengths to zero.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   867
	 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   868
	pdata = rm->rm_col[VDEV_RAIDZ_P].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   869
	qdata = rm->rm_col[VDEV_RAIDZ_Q].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   870
	xsize = rm->rm_col[x].rc_size;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   871
	ysize = rm->rm_col[y].rc_size;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   872
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   873
	rm->rm_col[VDEV_RAIDZ_P].rc_data =
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   874
	    zio_buf_alloc(rm->rm_col[VDEV_RAIDZ_P].rc_size);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   875
	rm->rm_col[VDEV_RAIDZ_Q].rc_data =
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   876
	    zio_buf_alloc(rm->rm_col[VDEV_RAIDZ_Q].rc_size);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   877
	rm->rm_col[x].rc_size = 0;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   878
	rm->rm_col[y].rc_size = 0;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   879
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   880
	vdev_raidz_generate_parity_pq(rm);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   881
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   882
	rm->rm_col[x].rc_size = xsize;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   883
	rm->rm_col[y].rc_size = ysize;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   884
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   885
	p = pdata;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   886
	q = qdata;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   887
	pxy = rm->rm_col[VDEV_RAIDZ_P].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   888
	qxy = rm->rm_col[VDEV_RAIDZ_Q].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   889
	xd = rm->rm_col[x].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   890
	yd = rm->rm_col[y].rc_data;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   891
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   892
	/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   893
	 * We now have:
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   894
	 *	Pxy = P + D_x + D_y
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   895
	 *	Qxy = Q + 2^(ndevs - 1 - x) * D_x + 2^(ndevs - 1 - y) * D_y
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   896
	 *
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   897
	 * We can then solve for D_x:
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   898
	 *	D_x = A * (P + Pxy) + B * (Q + Qxy)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   899
	 * where
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   900
	 *	A = 2^(x - y) * (2^(x - y) + 1)^-1
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   901
	 *	B = 2^(ndevs - 1 - x) * (2^(x - y) + 1)^-1
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   902
	 *
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   903
	 * With D_x in hand, we can easily solve for D_y:
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   904
	 *	D_y = P + Pxy + D_x
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   905
	 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   906
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   907
	a = vdev_raidz_pow2[255 + x - y];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   908
	b = vdev_raidz_pow2[255 - (rm->rm_cols - 1 - x)];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   909
	tmp = 255 - vdev_raidz_log2[a ^ 1];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   910
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   911
	aexp = vdev_raidz_log2[vdev_raidz_exp2(a, tmp)];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   912
	bexp = vdev_raidz_log2[vdev_raidz_exp2(b, tmp)];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   913
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   914
	for (i = 0; i < xsize; i++, p++, q++, pxy++, qxy++, xd++, yd++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   915
		*xd = vdev_raidz_exp2(*p ^ *pxy, aexp) ^
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   916
		    vdev_raidz_exp2(*q ^ *qxy, bexp);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   917
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   918
		if (i < ysize)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   919
			*yd = *p ^ *pxy ^ *xd;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   920
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   921
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   922
	zio_buf_free(rm->rm_col[VDEV_RAIDZ_P].rc_data,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   923
	    rm->rm_col[VDEV_RAIDZ_P].rc_size);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   924
	zio_buf_free(rm->rm_col[VDEV_RAIDZ_Q].rc_data,
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   925
	    rm->rm_col[VDEV_RAIDZ_Q].rc_size);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   926
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   927
	/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   928
	 * Restore the saved parity data.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   929
	 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   930
	rm->rm_col[VDEV_RAIDZ_P].rc_data = pdata;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
   931
	rm->rm_col[VDEV_RAIDZ_Q].rc_data = qdata;
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   932
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   933
	return ((1 << VDEV_RAIDZ_P) | (1 << VDEV_RAIDZ_Q));
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   934
}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   935
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   936
/* BEGIN CSTYLED */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   937
/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   938
 * In the general case of reconstruction, we must solve the system of linear
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   939
 * equations defined by the coeffecients used to generate parity as well as
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   940
 * the contents of the data and parity disks. This can be expressed with
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   941
 * vectors for the original data (D) and the actual data (d) and parity (p)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   942
 * and a matrix composed of the identity matrix (I) and a dispersal matrix (V):
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   943
 *
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   944
 *            __   __                     __     __
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   945
 *            |     |         __     __   |  p_0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   946
 *            |  V  |         |  D_0  |   | p_m-1 |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   947
 *            |     |    x    |   :   | = |  d_0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   948
 *            |  I  |         | D_n-1 |   |   :   |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   949
 *            |     |         ~~     ~~   | d_n-1 |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   950
 *            ~~   ~~                     ~~     ~~
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   951
 *
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   952
 * I is simply a square identity matrix of size n, and V is a vandermonde
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   953
 * matrix defined by the coeffecients we chose for the various parity columns
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   954
 * (1, 2, 4). Note that these values were chosen both for simplicity, speedy
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   955
 * computation as well as linear separability.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   956
 *
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   957
 *      __               __               __     __
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   958
 *      |   1   ..  1 1 1 |               |  p_0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   959
 *      | 2^n-1 ..  4 2 1 |   __     __   |   :   |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   960
 *      | 4^n-1 .. 16 4 1 |   |  D_0  |   | p_m-1 |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   961
 *      |   1   ..  0 0 0 |   |  D_1  |   |  d_0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   962
 *      |   0   ..  0 0 0 | x |  D_2  | = |  d_1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   963
 *      |   :       : : : |   |   :   |   |  d_2  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   964
 *      |   0   ..  1 0 0 |   | D_n-1 |   |   :   |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   965
 *      |   0   ..  0 1 0 |   ~~     ~~   |   :   |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   966
 *      |   0   ..  0 0 1 |               | d_n-1 |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   967
 *      ~~               ~~               ~~     ~~
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   968
 *
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   969
 * Note that I, V, d, and p are known. To compute D, we must invert the
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   970
 * matrix and use the known data and parity values to reconstruct the unknown
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   971
 * data values. We begin by removing the rows in V|I and d|p that correspond
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   972
 * to failed or missing columns; we then make V|I square (n x n) and d|p
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   973
 * sized n by removing rows corresponding to unused parity from the bottom up
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   974
 * to generate (V|I)' and (d|p)'. We can then generate the inverse of (V|I)'
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   975
 * using Gauss-Jordan elimination. In the example below we use m=3 parity
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   976
 * columns, n=8 data columns, with errors in d_1, d_2, and p_1:
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   977
 *           __                               __
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   978
 *           |  1   1   1   1   1   1   1   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   979
 *           | 128  64  32  16  8   4   2   1  | <-----+-+-- missing disks
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   980
 *           |  19 205 116  29  64  16  4   1  |      / /
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   981
 *           |  1   0   0   0   0   0   0   0  |     / /
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   982
 *           |  0   1   0   0   0   0   0   0  | <--' /
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   983
 *  (V|I)  = |  0   0   1   0   0   0   0   0  | <---'
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   984
 *           |  0   0   0   1   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   985
 *           |  0   0   0   0   1   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   986
 *           |  0   0   0   0   0   1   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   987
 *           |  0   0   0   0   0   0   1   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   988
 *           |  0   0   0   0   0   0   0   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   989
 *           ~~                               ~~
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   990
 *           __                               __
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   991
 *           |  1   1   1   1   1   1   1   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   992
 *           |  19 205 116  29  64  16  4   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   993
 *           |  1   0   0   0   0   0   0   0  |
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
   994
 *  (V|I)' = |  0   0   0   1   0   0   0   0  |
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   995
 *           |  0   0   0   0   1   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   996
 *           |  0   0   0   0   0   1   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   997
 *           |  0   0   0   0   0   0   1   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   998
 *           |  0   0   0   0   0   0   0   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
   999
 *           ~~                               ~~
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1000
 *
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1001
 * Here we employ Gauss-Jordan elimination to find the inverse of (V|I)'. We
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1002
 * have carefully chosen the seed values 1, 2, and 4 to ensure that this
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1003
 * matrix is not singular.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1004
 * __                                                                 __
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1005
 * |  1   1   1   1   1   1   1   1     1   0   0   0   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1006
 * |  19 205 116  29  64  16  4   1     0   1   0   0   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1007
 * |  1   0   0   0   0   0   0   0     0   0   1   0   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1008
 * |  0   0   0   1   0   0   0   0     0   0   0   1   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1009
 * |  0   0   0   0   1   0   0   0     0   0   0   0   1   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1010
 * |  0   0   0   0   0   1   0   0     0   0   0   0   0   1   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1011
 * |  0   0   0   0   0   0   1   0     0   0   0   0   0   0   1   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1012
 * |  0   0   0   0   0   0   0   1     0   0   0   0   0   0   0   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1013
 * ~~                                                                 ~~
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1014
 * __                                                                 __
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1015
 * |  1   0   0   0   0   0   0   0     0   0   1   0   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1016
 * |  1   1   1   1   1   1   1   1     1   0   0   0   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1017
 * |  19 205 116  29  64  16  4   1     0   1   0   0   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1018
 * |  0   0   0   1   0   0   0   0     0   0   0   1   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1019
 * |  0   0   0   0   1   0   0   0     0   0   0   0   1   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1020
 * |  0   0   0   0   0   1   0   0     0   0   0   0   0   1   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1021
 * |  0   0   0   0   0   0   1   0     0   0   0   0   0   0   1   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1022
 * |  0   0   0   0   0   0   0   1     0   0   0   0   0   0   0   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1023
 * ~~                                                                 ~~
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1024
 * __                                                                 __
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1025
 * |  1   0   0   0   0   0   0   0     0   0   1   0   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1026
 * |  0   1   1   0   0   0   0   0     1   0   1   1   1   1   1   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1027
 * |  0  205 116  0   0   0   0   0     0   1   19  29  64  16  4   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1028
 * |  0   0   0   1   0   0   0   0     0   0   0   1   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1029
 * |  0   0   0   0   1   0   0   0     0   0   0   0   1   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1030
 * |  0   0   0   0   0   1   0   0     0   0   0   0   0   1   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1031
 * |  0   0   0   0   0   0   1   0     0   0   0   0   0   0   1   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1032
 * |  0   0   0   0   0   0   0   1     0   0   0   0   0   0   0   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1033
 * ~~                                                                 ~~
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1034
 * __                                                                 __
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1035
 * |  1   0   0   0   0   0   0   0     0   0   1   0   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1036
 * |  0   1   1   0   0   0   0   0     1   0   1   1   1   1   1   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1037
 * |  0   0  185  0   0   0   0   0    205  1  222 208 141 221 201 204 |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1038
 * |  0   0   0   1   0   0   0   0     0   0   0   1   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1039
 * |  0   0   0   0   1   0   0   0     0   0   0   0   1   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1040
 * |  0   0   0   0   0   1   0   0     0   0   0   0   0   1   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1041
 * |  0   0   0   0   0   0   1   0     0   0   0   0   0   0   1   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1042
 * |  0   0   0   0   0   0   0   1     0   0   0   0   0   0   0   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1043
 * ~~                                                                 ~~
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1044
 * __                                                                 __
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1045
 * |  1   0   0   0   0   0   0   0     0   0   1   0   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1046
 * |  0   1   1   0   0   0   0   0     1   0   1   1   1   1   1   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1047
 * |  0   0   1   0   0   0   0   0    166 100  4   40 158 168 216 209 |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1048
 * |  0   0   0   1   0   0   0   0     0   0   0   1   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1049
 * |  0   0   0   0   1   0   0   0     0   0   0   0   1   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1050
 * |  0   0   0   0   0   1   0   0     0   0   0   0   0   1   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1051
 * |  0   0   0   0   0   0   1   0     0   0   0   0   0   0   1   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1052
 * |  0   0   0   0   0   0   0   1     0   0   0   0   0   0   0   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1053
 * ~~                                                                 ~~
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1054
 * __                                                                 __
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1055
 * |  1   0   0   0   0   0   0   0     0   0   1   0   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1056
 * |  0   1   0   0   0   0   0   0    167 100  5   41 159 169 217 208 |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1057
 * |  0   0   1   0   0   0   0   0    166 100  4   40 158 168 216 209 |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1058
 * |  0   0   0   1   0   0   0   0     0   0   0   1   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1059
 * |  0   0   0   0   1   0   0   0     0   0   0   0   1   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1060
 * |  0   0   0   0   0   1   0   0     0   0   0   0   0   1   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1061
 * |  0   0   0   0   0   0   1   0     0   0   0   0   0   0   1   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1062
 * |  0   0   0   0   0   0   0   1     0   0   0   0   0   0   0   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1063
 * ~~                                                                 ~~
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1064
 *                   __                               __
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1065
 *                   |  0   0   1   0   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1066
 *                   | 167 100  5   41 159 169 217 208 |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1067
 *                   | 166 100  4   40 158 168 216 209 |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1068
 *       (V|I)'^-1 = |  0   0   0   1   0   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1069
 *                   |  0   0   0   0   1   0   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1070
 *                   |  0   0   0   0   0   1   0   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1071
 *                   |  0   0   0   0   0   0   1   0  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1072
 *                   |  0   0   0   0   0   0   0   1  |
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1073
 *                   ~~                               ~~
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1074
 *
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1075
 * We can then simply compute D = (V|I)'^-1 x (d|p)' to discover the values
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1076
 * of the missing data.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1077
 *
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1078
 * As is apparent from the example above, the only non-trivial rows in the
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1079
 * inverse matrix correspond to the data disks that we're trying to
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1080
 * reconstruct. Indeed, those are the only rows we need as the others would
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1081
 * only be useful for reconstructing data known or assumed to be valid. For
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1082
 * that reason, we only build the coefficients in the rows that correspond to
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1083
 * targeted columns.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1084
 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1085
/* END CSTYLED */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1086
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1087
static void
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1088
vdev_raidz_matrix_init(raidz_map_t *rm, int n, int nmap, int *map,
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1089
    uint8_t **rows)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1090
{
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1091
	int i, j;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1092
	int pow;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1093
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1094
	ASSERT(n == rm->rm_cols - rm->rm_firstdatacol);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1095
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1096
	/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1097
	 * Fill in the missing rows of interest.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1098
	 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1099
	for (i = 0; i < nmap; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1100
		ASSERT3S(0, <=, map[i]);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1101
		ASSERT3S(map[i], <=, 2);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1102
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1103
		pow = map[i] * n;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1104
		if (pow > 255)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1105
			pow -= 255;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1106
		ASSERT(pow <= 255);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1107
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1108
		for (j = 0; j < n; j++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1109
			pow -= map[i];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1110
			if (pow < 0)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1111
				pow += 255;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1112
			rows[i][j] = vdev_raidz_pow2[pow];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1113
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1114
	}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1115
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1116
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1117
static void
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1118
vdev_raidz_matrix_invert(raidz_map_t *rm, int n, int nmissing, int *missing,
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1119
    uint8_t **rows, uint8_t **invrows, const uint8_t *used)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1120
{
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1121
	int i, j, ii, jj;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1122
	uint8_t log;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1123
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1124
	/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1125
	 * Assert that the first nmissing entries from the array of used
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1126
	 * columns correspond to parity columns and that subsequent entries
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1127
	 * correspond to data columns.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1128
	 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1129
	for (i = 0; i < nmissing; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1130
		ASSERT3S(used[i], <, rm->rm_firstdatacol);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1131
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1132
	for (; i < n; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1133
		ASSERT3S(used[i], >=, rm->rm_firstdatacol);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1134
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1135
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1136
	/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1137
	 * First initialize the storage where we'll compute the inverse rows.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1138
	 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1139
	for (i = 0; i < nmissing; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1140
		for (j = 0; j < n; j++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1141
			invrows[i][j] = (i == j) ? 1 : 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1142
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1143
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1144
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1145
	/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1146
	 * Subtract all trivial rows from the rows of consequence.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1147
	 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1148
	for (i = 0; i < nmissing; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1149
		for (j = nmissing; j < n; j++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1150
			ASSERT3U(used[j], >=, rm->rm_firstdatacol);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1151
			jj = used[j] - rm->rm_firstdatacol;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1152
			ASSERT3S(jj, <, n);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1153
			invrows[i][j] = rows[i][jj];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1154
			rows[i][jj] = 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1155
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1156
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1157
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1158
	/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1159
	 * For each of the rows of interest, we must normalize it and subtract
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1160
	 * a multiple of it from the other rows.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1161
	 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1162
	for (i = 0; i < nmissing; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1163
		for (j = 0; j < missing[i]; j++) {
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
  1164
			ASSERT0(rows[i][j]);
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1165
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1166
		ASSERT3U(rows[i][missing[i]], !=, 0);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1167
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1168
		/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1169
		 * Compute the inverse of the first element and multiply each
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1170
		 * element in the row by that value.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1171
		 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1172
		log = 255 - vdev_raidz_log2[rows[i][missing[i]]];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1173
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1174
		for (j = 0; j < n; j++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1175
			rows[i][j] = vdev_raidz_exp2(rows[i][j], log);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1176
			invrows[i][j] = vdev_raidz_exp2(invrows[i][j], log);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1177
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1178
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1179
		for (ii = 0; ii < nmissing; ii++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1180
			if (i == ii)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1181
				continue;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1182
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1183
			ASSERT3U(rows[ii][missing[i]], !=, 0);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1184
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1185
			log = vdev_raidz_log2[rows[ii][missing[i]]];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1186
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1187
			for (j = 0; j < n; j++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1188
				rows[ii][j] ^=
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1189
				    vdev_raidz_exp2(rows[i][j], log);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1190
				invrows[ii][j] ^=
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1191
				    vdev_raidz_exp2(invrows[i][j], log);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1192
			}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1193
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1194
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1195
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1196
	/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1197
	 * Verify that the data that is left in the rows are properly part of
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1198
	 * an identity matrix.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1199
	 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1200
	for (i = 0; i < nmissing; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1201
		for (j = 0; j < n; j++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1202
			if (j == missing[i]) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1203
				ASSERT3U(rows[i][j], ==, 1);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1204
			} else {
13805
e3a9ae14a119 3006 VERIFY[S,U,P] and ASSERT[S,U,P] frequently check if first argument is zero
Madhav Suresh <madhav.suresh@delphix.com>
parents: 13765
diff changeset
  1205
				ASSERT0(rows[i][j]);
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1206
			}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1207
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1208
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1209
}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1210
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1211
static void
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1212
vdev_raidz_matrix_reconstruct(raidz_map_t *rm, int n, int nmissing,
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1213
    int *missing, uint8_t **invrows, const uint8_t *used)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1214
{
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1215
	int i, j, x, cc, c;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1216
	uint8_t *src;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1217
	uint64_t ccount;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1218
	uint8_t *dst[VDEV_RAIDZ_MAXPARITY];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1219
	uint64_t dcount[VDEV_RAIDZ_MAXPARITY];
13952
7a22d0770fc8 3522 zfs module should not allow uninitialized variables
George Wilson <george.wilson@delphix.com>
parents: 13805
diff changeset
  1220
	uint8_t log = 0;
7a22d0770fc8 3522 zfs module should not allow uninitialized variables
George Wilson <george.wilson@delphix.com>
parents: 13805
diff changeset
  1221
	uint8_t val;
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1222
	int ll;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1223
	uint8_t *invlog[VDEV_RAIDZ_MAXPARITY];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1224
	uint8_t *p, *pp;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1225
	size_t psize;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1226
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1227
	psize = sizeof (invlog[0][0]) * n * nmissing;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1228
	p = kmem_alloc(psize, KM_SLEEP);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1229
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1230
	for (pp = p, i = 0; i < nmissing; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1231
		invlog[i] = pp;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1232
		pp += n;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1233
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1234
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1235
	for (i = 0; i < nmissing; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1236
		for (j = 0; j < n; j++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1237
			ASSERT3U(invrows[i][j], !=, 0);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1238
			invlog[i][j] = vdev_raidz_log2[invrows[i][j]];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1239
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1240
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1241
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1242
	for (i = 0; i < n; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1243
		c = used[i];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1244
		ASSERT3U(c, <, rm->rm_cols);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1245
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1246
		src = rm->rm_col[c].rc_data;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1247
		ccount = rm->rm_col[c].rc_size;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1248
		for (j = 0; j < nmissing; j++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1249
			cc = missing[j] + rm->rm_firstdatacol;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1250
			ASSERT3U(cc, >=, rm->rm_firstdatacol);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1251
			ASSERT3U(cc, <, rm->rm_cols);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1252
			ASSERT3U(cc, !=, c);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1253
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1254
			dst[j] = rm->rm_col[cc].rc_data;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1255
			dcount[j] = rm->rm_col[cc].rc_size;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1256
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1257
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1258
		ASSERT(ccount >= rm->rm_col[missing[0]].rc_size || i > 0);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1259
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1260
		for (x = 0; x < ccount; x++, src++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1261
			if (*src != 0)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1262
				log = vdev_raidz_log2[*src];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1263
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1264
			for (cc = 0; cc < nmissing; cc++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1265
				if (x >= dcount[cc])
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1266
					continue;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1267
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1268
				if (*src == 0) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1269
					val = 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1270
				} else {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1271
					if ((ll = log + invlog[cc][i]) >= 255)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1272
						ll -= 255;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1273
					val = vdev_raidz_pow2[ll];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1274
				}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1275
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1276
				if (i == 0)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1277
					dst[cc][x] = val;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1278
				else
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1279
					dst[cc][x] ^= val;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1280
			}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1281
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1282
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1283
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1284
	kmem_free(p, psize);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1285
}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1286
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1287
static int
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1288
vdev_raidz_reconstruct_general(raidz_map_t *rm, int *tgts, int ntgts)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1289
{
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1290
	int n, i, c, t, tt;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1291
	int nmissing_rows;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1292
	int missing_rows[VDEV_RAIDZ_MAXPARITY];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1293
	int parity_map[VDEV_RAIDZ_MAXPARITY];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1294
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1295
	uint8_t *p, *pp;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1296
	size_t psize;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1297
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1298
	uint8_t *rows[VDEV_RAIDZ_MAXPARITY];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1299
	uint8_t *invrows[VDEV_RAIDZ_MAXPARITY];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1300
	uint8_t *used;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1301
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1302
	int code = 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1303
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1304
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1305
	n = rm->rm_cols - rm->rm_firstdatacol;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1306
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1307
	/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1308
	 * Figure out which data columns are missing.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1309
	 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1310
	nmissing_rows = 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1311
	for (t = 0; t < ntgts; t++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1312
		if (tgts[t] >= rm->rm_firstdatacol) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1313
			missing_rows[nmissing_rows++] =
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1314
			    tgts[t] - rm->rm_firstdatacol;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1315
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1316
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1317
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1318
	/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1319
	 * Figure out which parity columns to use to help generate the missing
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1320
	 * data columns.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1321
	 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1322
	for (tt = 0, c = 0, i = 0; i < nmissing_rows; c++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1323
		ASSERT(tt < ntgts);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1324
		ASSERT(c < rm->rm_firstdatacol);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1325
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1326
		/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1327
		 * Skip any targeted parity columns.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1328
		 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1329
		if (c == tgts[tt]) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1330
			tt++;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1331
			continue;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1332
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1333
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1334
		code |= 1 << c;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1335
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1336
		parity_map[i] = c;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1337
		i++;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1338
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1339
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1340
	ASSERT(code != 0);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1341
	ASSERT3U(code, <, 1 << VDEV_RAIDZ_MAXPARITY);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1342
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1343
	psize = (sizeof (rows[0][0]) + sizeof (invrows[0][0])) *
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1344
	    nmissing_rows * n + sizeof (used[0]) * n;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1345
	p = kmem_alloc(psize, KM_SLEEP);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1346
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1347
	for (pp = p, i = 0; i < nmissing_rows; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1348
		rows[i] = pp;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1349
		pp += n;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1350
		invrows[i] = pp;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1351
		pp += n;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1352
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1353
	used = pp;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1354
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1355
	for (i = 0; i < nmissing_rows; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1356
		used[i] = parity_map[i];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1357
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1358
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1359
	for (tt = 0, c = rm->rm_firstdatacol; c < rm->rm_cols; c++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1360
		if (tt < nmissing_rows &&
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1361
		    c == missing_rows[tt] + rm->rm_firstdatacol) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1362
			tt++;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1363
			continue;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1364
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1365
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1366
		ASSERT3S(i, <, n);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1367
		used[i] = c;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1368
		i++;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1369
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1370
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1371
	/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1372
	 * Initialize the interesting rows of the matrix.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1373
	 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1374
	vdev_raidz_matrix_init(rm, n, nmissing_rows, parity_map, rows);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1375
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1376
	/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1377
	 * Invert the matrix.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1378
	 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1379
	vdev_raidz_matrix_invert(rm, n, nmissing_rows, missing_rows, rows,
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1380
	    invrows, used);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1381
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1382
	/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1383
	 * Reconstruct the missing data using the generated matrix.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1384
	 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1385
	vdev_raidz_matrix_reconstruct(rm, n, nmissing_rows, missing_rows,
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1386
	    invrows, used);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1387
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1388
	kmem_free(p, psize);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1389
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1390
	return (code);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1391
}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1392
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1393
static int
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1394
vdev_raidz_reconstruct(raidz_map_t *rm, int *t, int nt)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1395
{
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1396
	int tgts[VDEV_RAIDZ_MAXPARITY], *dt;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1397
	int ntgts;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1398
	int i, c;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1399
	int code;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1400
	int nbadparity, nbaddata;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1401
	int parity_valid[VDEV_RAIDZ_MAXPARITY];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1402
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1403
	/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1404
	 * The tgts list must already be sorted.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1405
	 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1406
	for (i = 1; i < nt; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1407
		ASSERT(t[i] > t[i - 1]);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1408
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1409
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1410
	nbadparity = rm->rm_firstdatacol;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1411
	nbaddata = rm->rm_cols - nbadparity;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1412
	ntgts = 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1413
	for (i = 0, c = 0; c < rm->rm_cols; c++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1414
		if (c < rm->rm_firstdatacol)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1415
			parity_valid[c] = B_FALSE;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1416
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1417
		if (i < nt && c == t[i]) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1418
			tgts[ntgts++] = c;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1419
			i++;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1420
		} else if (rm->rm_col[c].rc_error != 0) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1421
			tgts[ntgts++] = c;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1422
		} else if (c >= rm->rm_firstdatacol) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1423
			nbaddata--;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1424
		} else {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1425
			parity_valid[c] = B_TRUE;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1426
			nbadparity--;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1427
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1428
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1429
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1430
	ASSERT(ntgts >= nt);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1431
	ASSERT(nbaddata >= 0);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1432
	ASSERT(nbaddata + nbadparity == ntgts);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1433
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1434
	dt = &tgts[nbadparity];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1435
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1436
	/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1437
	 * See if we can use any of our optimized reconstruction routines.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1438
	 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1439
	if (!vdev_raidz_default_to_general) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1440
		switch (nbaddata) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1441
		case 1:
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1442
			if (parity_valid[VDEV_RAIDZ_P])
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1443
				return (vdev_raidz_reconstruct_p(rm, dt, 1));
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1444
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1445
			ASSERT(rm->rm_firstdatacol > 1);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1446
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1447
			if (parity_valid[VDEV_RAIDZ_Q])
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1448
				return (vdev_raidz_reconstruct_q(rm, dt, 1));
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1449
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1450
			ASSERT(rm->rm_firstdatacol > 2);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1451
			break;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1452
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1453
		case 2:
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1454
			ASSERT(rm->rm_firstdatacol > 1);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1455
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1456
			if (parity_valid[VDEV_RAIDZ_P] &&
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1457
			    parity_valid[VDEV_RAIDZ_Q])
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1458
				return (vdev_raidz_reconstruct_pq(rm, dt, 2));
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1459
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1460
			ASSERT(rm->rm_firstdatacol > 2);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1461
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1462
			break;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1463
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1464
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1465
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1466
	code = vdev_raidz_reconstruct_general(rm, tgts, ntgts);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1467
	ASSERT(code < (1 << VDEV_RAIDZ_MAXPARITY));
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1468
	ASSERT(code > 0);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1469
	return (code);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1470
}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1471
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1472
static int
13570
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 12296
diff changeset
  1473
vdev_raidz_open(vdev_t *vd, uint64_t *asize, uint64_t *max_asize,
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 12296
diff changeset
  1474
    uint64_t *ashift)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1475
{
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1476
	vdev_t *cvd;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1477
	uint64_t nparity = vd->vdev_nparity;
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1478
	int c;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1479
	int lasterror = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1480
	int numerrors = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1481
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1482
	ASSERT(nparity > 0);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1483
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1484
	if (nparity > VDEV_RAIDZ_MAXPARITY ||
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1485
	    vd->vdev_children < nparity + 1) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1486
		vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL;
13980
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13952
diff changeset
  1487
		return (SET_ERROR(EINVAL));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1488
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1489
9846
6527c7b4a92e 6566744 vdev_open() should be done in parallel
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9434
diff changeset
  1490
	vdev_open_children(vd);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1491
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1492
	for (c = 0; c < vd->vdev_children; c++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1493
		cvd = vd->vdev_child[c];
9846
6527c7b4a92e 6566744 vdev_open() should be done in parallel
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9434
diff changeset
  1494
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1495
		if (cvd->vdev_open_error != 0) {
9846
6527c7b4a92e 6566744 vdev_open() should be done in parallel
Eric Taylor <Eric.Taylor@Sun.COM>
parents: 9434
diff changeset
  1496
			lasterror = cvd->vdev_open_error;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1497
			numerrors++;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1498
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1499
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1500
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1501
		*asize = MIN(*asize - 1, cvd->vdev_asize - 1) + 1;
13570
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 12296
diff changeset
  1502
		*max_asize = MIN(*max_asize - 1, cvd->vdev_max_asize - 1) + 1;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1503
		*ashift = MAX(*ashift, cvd->vdev_ashift);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1504
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1505
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1506
	*asize *= vd->vdev_children;
13570
3411fd5f1589 1948 zpool list should show more detailed pool information
George Wilson <George.Wilson@delphix.com>
parents: 12296
diff changeset
  1507
	*max_asize *= vd->vdev_children;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1508
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1509
	if (numerrors > nparity) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1510
		vd->vdev_stat.vs_aux = VDEV_AUX_NO_REPLICAS;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1511
		return (lasterror);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1512
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1513
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1514
	return (0);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1515
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1516
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1517
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1518
vdev_raidz_close(vdev_t *vd)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1519
{
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1520
	int c;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1521
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1522
	for (c = 0; c < vd->vdev_children; c++)
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1523
		vdev_close(vd->vdev_child[c]);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1524
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1525
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1526
/*
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1527
 * Handle a read or write I/O to a RAID-Z dump device.
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1528
 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1529
 * The dump device is in a unique situation compared to other ZFS datasets:
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1530
 * writing to this device should be as simple and fast as possible.  In
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1531
 * addition, durability matters much less since the dump will be extracted
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1532
 * once the machine reboots.  For that reason, this function eschews parity for
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1533
 * performance and simplicity.  The dump device uses the checksum setting
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1534
 * ZIO_CHECKSUM_NOPARITY to indicate that parity is not maintained for this
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1535
 * dataset.
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1536
 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1537
 * Blocks of size 128 KB have been preallocated for this volume.  I/Os less than
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1538
 * 128 KB will not fill an entire block; in addition, they may not be properly
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1539
 * aligned.  In that case, this function uses the preallocated 128 KB block and
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1540
 * omits reading or writing any "empty" portions of that block, as opposed to
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1541
 * allocating a fresh appropriately-sized block.
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1542
 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1543
 * Looking at an example of a 32 KB I/O to a RAID-Z vdev with 5 child vdevs:
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1544
 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1545
 *     vdev_raidz_io_start(data, size: 32 KB, offset: 64 KB)
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1546
 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1547
 * If this were a standard RAID-Z dataset, a block of at least 40 KB would be
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1548
 * allocated which spans all five child vdevs.  8 KB of data would be written to
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1549
 * each of four vdevs, with the fifth containing the parity bits.
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1550
 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1551
 *       parity    data     data     data     data
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1552
 *     |   PP   |   XX   |   XX   |   XX   |   XX   |
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1553
 *         ^        ^        ^        ^        ^
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1554
 *         |        |        |        |        |
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1555
 *   8 KB parity    ------8 KB data blocks------
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1556
 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1557
 * However, when writing to the dump device, the behavior is different:
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1558
 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1559
 *     vdev_raidz_physio(data, size: 32 KB, offset: 64 KB)
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1560
 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1561
 * Unlike the normal RAID-Z case in which the block is allocated based on the
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1562
 * I/O size, reads and writes here always use a 128 KB logical I/O size.  If the
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1563
 * I/O size is less than 128 KB, only the actual portions of data are written.
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1564
 * In this example the data is written to the third data vdev since that vdev
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1565
 * contains the offset [64 KB, 96 KB).
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1566
 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1567
 *       parity    data     data     data     data
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1568
 *     |        |        |        |   XX   |        |
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1569
 *                                    ^
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1570
 *                                    |
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1571
 *                             32 KB data block
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1572
 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1573
 * As a result, an individual I/O may not span all child vdevs; moreover, a
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1574
 * small I/O may only operate on a single child vdev.
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1575
 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1576
 * Note that since there are no parity bits calculated or written, this format
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1577
 * remains the same no matter how many parity bits are used in a normal RAID-Z
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1578
 * stripe.  On a RAID-Z3 configuration with seven child vdevs, the example above
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1579
 * would look like:
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1580
 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1581
 *       parity   parity   parity    data     data     data     data
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1582
 *     |        |        |        |        |        |   XX   |        |
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1583
 *                                                      ^
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1584
 *                                                      |
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1585
 *                                               32 KB data block
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1586
 */
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1587
int
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1588
vdev_raidz_physio(vdev_t *vd, caddr_t data, size_t size,
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1589
    uint64_t offset, uint64_t origoffset, boolean_t doread, boolean_t isdump)
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1590
{
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1591
	vdev_t *tvd = vd->vdev_top;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1592
	vdev_t *cvd;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1593
	raidz_map_t *rm;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1594
	raidz_col_t *rc;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1595
	int c, err = 0;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1596
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1597
	uint64_t start, end, colstart, colend;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1598
	uint64_t coloffset, colsize, colskip;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1599
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1600
	int flags = doread ? B_READ : B_WRITE;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1601
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1602
#ifdef	_KERNEL
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1603
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1604
	/*
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1605
	 * Don't write past the end of the block
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1606
	 */
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1607
	VERIFY3U(offset + size, <=, origoffset + SPA_MAXBLOCKSIZE);
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1608
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1609
	start = offset;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1610
	end = start + size;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1611
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1612
	/*
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1613
	 * Allocate a RAID-Z map for this block.  Note that this block starts
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1614
	 * from the "original" offset, this is, the offset of the extent which
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1615
	 * contains the requisite offset of the data being read or written.
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1616
	 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1617
	 * Even if this I/O operation doesn't span the full block size, let's
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1618
	 * treat the on-disk format as if the only blocks are the complete 128
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1619
	 * KB size.
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1620
	 */
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1621
	rm = vdev_raidz_map_alloc(data - (offset - origoffset),
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1622
	    SPA_MAXBLOCKSIZE, origoffset, tvd->vdev_ashift, vd->vdev_children,
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1623
	    vd->vdev_nparity);
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1624
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1625
	coloffset = origoffset;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1626
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1627
	for (c = rm->rm_firstdatacol; c < rm->rm_cols;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1628
	    c++, coloffset += rc->rc_size) {
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1629
		rc = &rm->rm_col[c];
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1630
		cvd = vd->vdev_child[rc->rc_devidx];
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1631
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1632
		/*
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1633
		 * Find the start and end of this column in the RAID-Z map,
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1634
		 * keeping in mind that the stated size and offset of the
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1635
		 * operation may not fill the entire column for this vdev.
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1636
		 *
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1637
		 * If any portion of the data spans this column, issue the
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1638
		 * appropriate operation to the vdev.
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1639
		 */
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1640
		if (coloffset + rc->rc_size <= start)
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1641
			continue;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1642
		if (coloffset >= end)
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1643
			continue;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1644
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1645
		colstart = MAX(coloffset, start);
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1646
		colend = MIN(end, coloffset + rc->rc_size);
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1647
		colsize = colend - colstart;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1648
		colskip = colstart - coloffset;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1649
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1650
		VERIFY3U(colsize, <=, rc->rc_size);
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1651
		VERIFY3U(colskip, <=, rc->rc_size);
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1652
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1653
		/*
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1654
		 * Note that the child vdev will have a vdev label at the start
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1655
		 * of its range of offsets, hence the need for
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1656
		 * VDEV_LABEL_OFFSET().  See zio_vdev_child_io() for another
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1657
		 * example of why this calculation is needed.
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1658
		 */
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1659
		if ((err = vdev_disk_physio(cvd,
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1660
		    ((char *)rc->rc_data) + colskip, colsize,
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1661
		    VDEV_LABEL_OFFSET(rc->rc_offset) + colskip,
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1662
		    flags, isdump)) != 0)
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1663
			break;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1664
	}
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1665
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1666
	vdev_raidz_map_free(rm);
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1667
#endif	/* KERNEL */
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1668
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1669
	return (err);
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1670
}
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1671
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1672
static uint64_t
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1673
vdev_raidz_asize(vdev_t *vd, uint64_t psize)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1674
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1675
	uint64_t asize;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1676
	uint64_t ashift = vd->vdev_top->vdev_ashift;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1677
	uint64_t cols = vd->vdev_children;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1678
	uint64_t nparity = vd->vdev_nparity;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1679
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1680
	asize = ((psize - 1) >> ashift) + 1;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1681
	asize += nparity * ((asize + cols - nparity - 1) / (cols - nparity));
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1682
	asize = roundup(asize, nparity + 1) << ashift;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1683
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1684
	return (asize);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1685
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1686
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1687
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1688
vdev_raidz_child_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1689
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1690
	raidz_col_t *rc = zio->io_private;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1691
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1692
	rc->rc_error = zio->io_error;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1693
	rc->rc_tried = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1694
	rc->rc_skipped = 0;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1695
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1696
14045
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1697
/*
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1698
 * Start an IO operation on a RAIDZ VDev
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1699
 *
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1700
 * Outline:
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1701
 * - For write operations:
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1702
 *   1. Generate the parity data
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1703
 *   2. Create child zio write operations to each column's vdev, for both
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1704
 *      data and parity.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1705
 *   3. If the column skips any sectors for padding, create optional dummy
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1706
 *      write zio children for those areas to improve aggregation continuity.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1707
 * - For read operations:
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1708
 *   1. Create child zio read operations to each data column's vdev to read
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1709
 *      the range of data required for zio.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1710
 *   2. If this is a scrub or resilver operation, or if any of the data
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1711
 *      vdevs have had errors, then create zio read operations to the parity
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1712
 *      columns' VDevs as well.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  1713
 */
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1714
static int
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1715
vdev_raidz_io_start(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1716
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1717
	vdev_t *vd = zio->io_vd;
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  1718
	vdev_t *tvd = vd->vdev_top;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1719
	vdev_t *cvd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1720
	raidz_map_t *rm;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1721
	raidz_col_t *rc;
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1722
	int c, i;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1723
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1724
	rm = vdev_raidz_map_alloc(zio->io_data, zio->io_size, zio->io_offset,
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1725
	    tvd->vdev_ashift, vd->vdev_children,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1726
	    vd->vdev_nparity);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1727
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1728
	zio->io_vsd = rm;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1729
	zio->io_vsd_ops = &vdev_raidz_vsd_ops;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1730
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  1731
	ASSERT3U(rm->rm_asize, ==, vdev_psize_to_asize(vd, zio->io_size));
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1732
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1733
	if (zio->io_type == ZIO_TYPE_WRITE) {
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1734
		vdev_raidz_generate_parity(rm);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1735
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1736
		for (c = 0; c < rm->rm_cols; c++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1737
			rc = &rm->rm_col[c];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1738
			cvd = vd->vdev_child[rc->rc_devidx];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1739
			zio_nowait(zio_vdev_child_io(zio, NULL, cvd,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1740
			    rc->rc_offset, rc->rc_data, rc->rc_size,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  1741
			    zio->io_type, zio->io_priority, 0,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1742
			    vdev_raidz_child_done, rc));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1743
		}
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1744
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1745
		/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1746
		 * Generate optional I/Os for any skipped sectors to improve
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1747
		 * aggregation contiguity.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1748
		 */
10450
c383b4d6980f 6869090 filebench on thumper with ZFS (snv_120) raidz causes checksum errors from all drives
Adam Leventhal <adam.leventhal@sun.com>
parents: 10105
diff changeset
  1749
		for (c = rm->rm_skipstart, i = 0; i < rm->rm_nskip; c++, i++) {
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1750
			ASSERT(c <= rm->rm_scols);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1751
			if (c == rm->rm_scols)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1752
				c = 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1753
			rc = &rm->rm_col[c];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1754
			cvd = vd->vdev_child[rc->rc_devidx];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1755
			zio_nowait(zio_vdev_child_io(zio, NULL, cvd,
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1756
			    rc->rc_offset + rc->rc_size, NULL,
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1757
			    1 << tvd->vdev_ashift,
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1758
			    zio->io_type, zio->io_priority,
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1759
			    ZIO_FLAG_NODATA | ZIO_FLAG_OPTIONAL, NULL, NULL));
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1760
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1761
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  1762
		return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1763
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1764
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1765
	ASSERT(zio->io_type == ZIO_TYPE_READ);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1766
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1767
	/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1768
	 * Iterate over the columns in reverse order so that we hit the parity
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1769
	 * last -- any errors along the way will force us to read the parity.
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1770
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1771
	for (c = rm->rm_cols - 1; c >= 0; c--) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1772
		rc = &rm->rm_col[c];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1773
		cvd = vd->vdev_child[rc->rc_devidx];
5329
33cb98223b2d PSARC 2007/567 zpool failmode property
gw25295
parents: 4034
diff changeset
  1774
		if (!vdev_readable(cvd)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1775
			if (c >= rm->rm_firstdatacol)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1776
				rm->rm_missingdata++;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1777
			else
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1778
				rm->rm_missingparity++;
13980
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13952
diff changeset
  1779
			rc->rc_error = SET_ERROR(ENXIO);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1780
			rc->rc_tried = 1;	/* don't even try */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1781
			rc->rc_skipped = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1782
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1783
		}
10922
e2081f502306 PSARC 2009/571 ZFS Deduplication Properties
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 10653
diff changeset
  1784
		if (vdev_dtl_contains(cvd, DTL_MISSING, zio->io_txg, 1)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1785
			if (c >= rm->rm_firstdatacol)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1786
				rm->rm_missingdata++;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1787
			else
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1788
				rm->rm_missingparity++;
13980
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13952
diff changeset
  1789
			rc->rc_error = SET_ERROR(ESTALE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1790
			rc->rc_skipped = 1;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1791
			continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1792
		}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1793
		if (c >= rm->rm_firstdatacol || rm->rm_missingdata > 0 ||
9434
3bebded7c76a 6794570 incomplete resilvering after disk replacement
Mark J Musante <Mark.Musante@Sun.COM>
parents: 8241
diff changeset
  1794
		    (zio->io_flags & (ZIO_FLAG_SCRUB | ZIO_FLAG_RESILVER))) {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1795
			zio_nowait(zio_vdev_child_io(zio, NULL, cvd,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1796
			    rc->rc_offset, rc->rc_data, rc->rc_size,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  1797
			    zio->io_type, zio->io_priority, 0,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1798
			    vdev_raidz_child_done, rc));
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1799
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1800
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1801
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  1802
	return (ZIO_PIPELINE_CONTINUE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1803
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  1804
12296
7cf402a7f374 6675946 'zpool status' should show the progress of resilvering for individual disk.
Lin Ling <Lin.Ling@Sun.COM>
parents: 11958
diff changeset
  1805
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1806
/*
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1807
 * Report a checksum error for a child of a RAID-Z device.
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1808
 */
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1809
static void
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1810
raidz_checksum_error(zio_t *zio, raidz_col_t *rc, void *bad_data)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1811
{
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1812
	vdev_t *vd = zio->io_vd->vdev_child[rc->rc_devidx];
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1813
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1814
	if (!(zio->io_flags & ZIO_FLAG_SPECULATIVE)) {
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1815
		zio_bad_cksum_t zbc;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1816
		raidz_map_t *rm = zio->io_vsd;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1817
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1818
		mutex_enter(&vd->vdev_stat_lock);
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1819
		vd->vdev_stat.vs_checksum_errors++;
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1820
		mutex_exit(&vd->vdev_stat_lock);
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1821
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1822
		zbc.zbc_has_cksum = 0;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1823
		zbc.zbc_injected = rm->rm_ecksuminjected;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1824
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1825
		zfs_ereport_post_checksum(zio->io_spa, vd, zio,
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1826
		    rc->rc_offset, rc->rc_size, rc->rc_data, bad_data,
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1827
		    &zbc);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1828
	}
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1829
}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1830
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1831
/*
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1832
 * We keep track of whether or not there were any injected errors, so that
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1833
 * any ereports we generate can note it.
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1834
 */
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1835
static int
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1836
raidz_checksum_verify(zio_t *zio)
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1837
{
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1838
	zio_bad_cksum_t zbc;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1839
	raidz_map_t *rm = zio->io_vsd;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1840
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1841
	int ret = zio_checksum_error(zio, &zbc);
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1842
	if (ret != 0 && zbc.zbc_injected != 0)
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1843
		rm->rm_ecksuminjected = 1;
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1844
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1845
	return (ret);
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1846
}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1847
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1848
/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1849
 * Generate the parity from the data columns. If we tried and were able to
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1850
 * read the parity without error, verify that the generated parity matches the
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1851
 * data we read. If it doesn't, we fire off a checksum error. Return the
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1852
 * number such failures.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1853
 */
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1854
static int
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1855
raidz_parity_verify(zio_t *zio, raidz_map_t *rm)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1856
{
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1857
	void *orig[VDEV_RAIDZ_MAXPARITY];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1858
	int c, ret = 0;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1859
	raidz_col_t *rc;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1860
14162
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1861
	blkptr_t *bp = zio->io_bp;
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1862
	enum zio_checksum checksum = (bp == NULL ? zio->io_prop.zp_checksum :
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1863
	    (BP_IS_GANG(bp) ? ZIO_CHECKSUM_GANG_HEADER : BP_GET_CHECKSUM(bp)));
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1864
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1865
	if (checksum == ZIO_CHECKSUM_NOPARITY)
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1866
		return (ret);
dc75c925d8aa 2932 support crash dumps to raidz, etc. pools
Bill Pijewski <wdp@joyent.com>
parents: 14046
diff changeset
  1867
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1868
	for (c = 0; c < rm->rm_firstdatacol; c++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1869
		rc = &rm->rm_col[c];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1870
		if (!rc->rc_tried || rc->rc_error != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1871
			continue;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1872
		orig[c] = zio_buf_alloc(rc->rc_size);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1873
		bcopy(rc->rc_data, orig[c], rc->rc_size);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1874
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1875
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1876
	vdev_raidz_generate_parity(rm);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1877
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1878
	for (c = 0; c < rm->rm_firstdatacol; c++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1879
		rc = &rm->rm_col[c];
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1880
		if (!rc->rc_tried || rc->rc_error != 0)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1881
			continue;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1882
		if (bcmp(orig[c], rc->rc_data, rc->rc_size) != 0) {
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1883
			raidz_checksum_error(zio, rc, orig[c]);
13980
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13952
diff changeset
  1884
			rc->rc_error = SET_ERROR(ECKSUM);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1885
			ret++;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1886
		}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1887
		zio_buf_free(orig[c], rc->rc_size);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1888
	}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1889
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1890
	return (ret);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1891
}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  1892
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1893
/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1894
 * Keep statistics on all the ways that we used parity to correct data.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1895
 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1896
static uint64_t raidz_corrected[1 << VDEV_RAIDZ_MAXPARITY];
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  1897
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  1898
static int
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  1899
vdev_raidz_worst_error(raidz_map_t *rm)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  1900
{
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  1901
	int error = 0;
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  1902
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  1903
	for (int c = 0; c < rm->rm_cols; c++)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  1904
		error = zio_worst_error(error, rm->rm_col[c].rc_error);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  1905
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  1906
	return (error);
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  1907
}
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  1908
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1909
/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1910
 * Iterate over all combinations of bad data and attempt a reconstruction.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1911
 * Note that the algorithm below is non-optimal because it doesn't take into
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1912
 * account how reconstruction is actually performed. For example, with
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1913
 * triple-parity RAID-Z the reconstruction procedure is the same if column 4
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1914
 * is targeted as invalid as if columns 1 and 4 are targeted since in both
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1915
 * cases we'd only use parity information in column 0.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1916
 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1917
static int
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1918
vdev_raidz_combrec(zio_t *zio, int total_errors, int data_errors)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1919
{
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1920
	raidz_map_t *rm = zio->io_vsd;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1921
	raidz_col_t *rc;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1922
	void *orig[VDEV_RAIDZ_MAXPARITY];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1923
	int tstore[VDEV_RAIDZ_MAXPARITY + 2];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1924
	int *tgts = &tstore[1];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1925
	int current, next, i, c, n;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1926
	int code, ret = 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1927
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1928
	ASSERT(total_errors < rm->rm_firstdatacol);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1929
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1930
	/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1931
	 * This simplifies one edge condition.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1932
	 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1933
	tgts[-1] = -1;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1934
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1935
	for (n = 1; n <= rm->rm_firstdatacol - total_errors; n++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1936
		/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1937
		 * Initialize the targets array by finding the first n columns
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1938
		 * that contain no error.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1939
		 *
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1940
		 * If there were no data errors, we need to ensure that we're
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1941
		 * always explicitly attempting to reconstruct at least one
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1942
		 * data column. To do this, we simply push the highest target
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1943
		 * up into the data columns.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1944
		 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1945
		for (c = 0, i = 0; i < n; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1946
			if (i == n - 1 && data_errors == 0 &&
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1947
			    c < rm->rm_firstdatacol) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1948
				c = rm->rm_firstdatacol;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1949
			}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1950
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1951
			while (rm->rm_col[c].rc_error != 0) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1952
				c++;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1953
				ASSERT3S(c, <, rm->rm_cols);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1954
			}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1955
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1956
			tgts[i] = c++;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1957
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1958
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1959
		/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1960
		 * Setting tgts[n] simplifies the other edge condition.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1961
		 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1962
		tgts[n] = rm->rm_cols;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1963
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1964
		/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1965
		 * These buffers were allocated in previous iterations.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1966
		 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1967
		for (i = 0; i < n - 1; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1968
			ASSERT(orig[i] != NULL);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1969
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1970
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1971
		orig[n - 1] = zio_buf_alloc(rm->rm_col[0].rc_size);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1972
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1973
		current = 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1974
		next = tgts[current];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1975
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1976
		while (current != n) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1977
			tgts[current] = next;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1978
			current = 0;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1979
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1980
			/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1981
			 * Save off the original data that we're going to
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1982
			 * attempt to reconstruct.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1983
			 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1984
			for (i = 0; i < n; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1985
				ASSERT(orig[i] != NULL);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1986
				c = tgts[i];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1987
				ASSERT3S(c, >=, 0);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1988
				ASSERT3S(c, <, rm->rm_cols);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1989
				rc = &rm->rm_col[c];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1990
				bcopy(rc->rc_data, orig[i], rc->rc_size);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1991
			}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1992
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1993
			/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1994
			 * Attempt a reconstruction and exit the outer loop on
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1995
			 * success.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1996
			 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1997
			code = vdev_raidz_reconstruct(rm, tgts, n);
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  1998
			if (raidz_checksum_verify(zio) == 0) {
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  1999
				atomic_inc_64(&raidz_corrected[code]);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2000
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2001
				for (i = 0; i < n; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2002
					c = tgts[i];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2003
					rc = &rm->rm_col[c];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2004
					ASSERT(rc->rc_error == 0);
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2005
					if (rc->rc_tried)
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2006
						raidz_checksum_error(zio, rc,
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2007
						    orig[i]);
13980
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13952
diff changeset
  2008
					rc->rc_error = SET_ERROR(ECKSUM);
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2009
				}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2010
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2011
				ret = code;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2012
				goto done;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2013
			}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2014
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2015
			/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2016
			 * Restore the original data.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2017
			 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2018
			for (i = 0; i < n; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2019
				c = tgts[i];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2020
				rc = &rm->rm_col[c];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2021
				bcopy(orig[i], rc->rc_data, rc->rc_size);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2022
			}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2023
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2024
			do {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2025
				/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2026
				 * Find the next valid column after the current
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2027
				 * position..
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2028
				 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2029
				for (next = tgts[current] + 1;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2030
				    next < rm->rm_cols &&
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2031
				    rm->rm_col[next].rc_error != 0; next++)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2032
					continue;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2033
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2034
				ASSERT(next <= tgts[current + 1]);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2035
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2036
				/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2037
				 * If that spot is available, we're done here.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2038
				 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2039
				if (next != tgts[current + 1])
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2040
					break;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2041
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2042
				/*
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2043
				 * Otherwise, find the next valid column after
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2044
				 * the previous position.
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2045
				 */
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2046
				for (c = tgts[current - 1] + 1;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2047
				    rm->rm_col[c].rc_error != 0; c++)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2048
					continue;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2049
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2050
				tgts[current] = c;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2051
				current++;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2052
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2053
			} while (current != n);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2054
		}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2055
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2056
	n--;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2057
done:
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2058
	for (i = 0; i < n; i++) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2059
		zio_buf_free(orig[i], rm->rm_col[0].rc_size);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2060
	}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2061
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2062
	return (ret);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2063
}
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2064
14045
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2065
/*
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2066
 * Complete an IO operation on a RAIDZ VDev
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2067
 *
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2068
 * Outline:
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2069
 * - For write operations:
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2070
 *   1. Check for errors on the child IOs.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2071
 *   2. Return, setting an error code if too few child VDevs were written
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2072
 *      to reconstruct the data later.  Note that partial writes are
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2073
 *      considered successful if they can be reconstructed at all.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2074
 * - For read operations:
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2075
 *   1. Check for errors on the child IOs.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2076
 *   2. If data errors occurred:
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2077
 *      a. Try to reassemble the data from the parity available.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2078
 *      b. If we haven't yet read the parity drives, read them now.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2079
 *      c. If all parity drives have been read but the data still doesn't
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2080
 *         reassemble with a correct checksum, then try combinatorial
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2081
 *         reconstruction.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2082
 *      d. If that doesn't work, return an error.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2083
 *   3. If there were unexpected errors or this is a resilver operation,
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2084
 *      rewrite the vdevs that had errors.
9475b3fef59d 3741 zfs needs better comments
Will Andrews <will@firepipe.net>
parents: 13980
diff changeset
  2085
 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2086
static void
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2087
vdev_raidz_io_done(zio_t *zio)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2088
{
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2089
	vdev_t *vd = zio->io_vd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2090
	vdev_t *cvd;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2091
	raidz_map_t *rm = zio->io_vsd;
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2092
	raidz_col_t *rc;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2093
	int unexpected_errors = 0;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2094
	int parity_errors = 0;
3456
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2095
	int parity_untried = 0;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2096
	int data_errors = 0;
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2097
	int total_errors = 0;
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2098
	int n, c;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2099
	int tgts[VDEV_RAIDZ_MAXPARITY];
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2100
	int code;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2101
1775
e51e26b432c0 6410698 ZFS metadata needs to be more highly replicated (ditto blocks)
billm
parents: 1732
diff changeset
  2102
	ASSERT(zio->io_bp != NULL);  /* XXX need to add code to enforce this */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2103
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2104
	ASSERT(rm->rm_missingparity <= rm->rm_firstdatacol);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2105
	ASSERT(rm->rm_missingdata <= rm->rm_cols - rm->rm_firstdatacol);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2106
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2107
	for (c = 0; c < rm->rm_cols; c++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2108
		rc = &rm->rm_col[c];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2109
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2110
		if (rc->rc_error) {
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2111
			ASSERT(rc->rc_error != ECKSUM);	/* child has no bp */
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2112
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2113
			if (c < rm->rm_firstdatacol)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2114
				parity_errors++;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2115
			else
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2116
				data_errors++;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2117
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2118
			if (!rc->rc_skipped)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2119
				unexpected_errors++;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2120
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2121
			total_errors++;
3456
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2122
		} else if (c < rm->rm_firstdatacol && !rc->rc_tried) {
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2123
			parity_untried++;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2124
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2125
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2126
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2127
	if (zio->io_type == ZIO_TYPE_WRITE) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2128
		/*
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2129
		 * XXX -- for now, treat partial writes as a success.
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2130
		 * (If we couldn't write enough columns to reconstruct
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2131
		 * the data, the I/O failed.  Otherwise, good enough.)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2132
		 *
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2133
		 * Now that we support write reallocation, it would be better
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2134
		 * to treat partial failure as real failure unless there are
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2135
		 * no non-degraded top-level vdevs left, and not update DTLs
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2136
		 * if we intend to reallocate.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2137
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2138
		/* XXPOLICY */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2139
		if (total_errors > rm->rm_firstdatacol)
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2140
			zio->io_error = vdev_raidz_worst_error(rm);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2141
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2142
		return;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2143
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2144
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2145
	ASSERT(zio->io_type == ZIO_TYPE_READ);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2146
	/*
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2147
	 * There are three potential phases for a read:
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2148
	 *	1. produce valid data from the columns read
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2149
	 *	2. read all disks and try again
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2150
	 *	3. perform combinatorial reconstruction
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2151
	 *
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2152
	 * Each phase is progressively both more expensive and less likely to
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2153
	 * occur. If we encounter more errors than we can repair or all phases
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2154
	 * fail, we have no choice but to return an error.
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2155
	 */
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2156
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2157
	/*
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2158
	 * If the number of errors we saw was correctable -- less than or equal
3456
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2159
	 * to the number of parity disks read -- attempt to produce data that
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2160
	 * has a valid checksum. Naturally, this case applies in the absence of
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2161
	 * any errors.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2162
	 */
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2163
	if (total_errors <= rm->rm_firstdatacol - parity_untried) {
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2164
		if (data_errors == 0) {
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2165
			if (raidz_checksum_verify(zio) == 0) {
4034
b20b176bd1e8 6545015 RAID-Z resilver broken
ahl
parents: 3456
diff changeset
  2166
				/*
b20b176bd1e8 6545015 RAID-Z resilver broken
ahl
parents: 3456
diff changeset
  2167
				 * If we read parity information (unnecessarily
b20b176bd1e8 6545015 RAID-Z resilver broken
ahl
parents: 3456
diff changeset
  2168
				 * as it happens since no reconstruction was
b20b176bd1e8 6545015 RAID-Z resilver broken
ahl
parents: 3456
diff changeset
  2169
				 * needed) regenerate and verify the parity.
b20b176bd1e8 6545015 RAID-Z resilver broken
ahl
parents: 3456
diff changeset
  2170
				 * We also regenerate parity when resilvering
b20b176bd1e8 6545015 RAID-Z resilver broken
ahl
parents: 3456
diff changeset
  2171
				 * so we can write it out to the failed device
b20b176bd1e8 6545015 RAID-Z resilver broken
ahl
parents: 3456
diff changeset
  2172
				 * later.
b20b176bd1e8 6545015 RAID-Z resilver broken
ahl
parents: 3456
diff changeset
  2173
				 */
3456
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2174
				if (parity_errors + parity_untried <
4034
b20b176bd1e8 6545015 RAID-Z resilver broken
ahl
parents: 3456
diff changeset
  2175
				    rm->rm_firstdatacol ||
b20b176bd1e8 6545015 RAID-Z resilver broken
ahl
parents: 3456
diff changeset
  2176
				    (zio->io_flags & ZIO_FLAG_RESILVER)) {
3456
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2177
					n = raidz_parity_verify(zio, rm);
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2178
					unexpected_errors += n;
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2179
					ASSERT(parity_errors + n <=
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2180
					    rm->rm_firstdatacol);
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2181
				}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2182
				goto done;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2183
			}
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2184
		} else {
3456
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2185
			/*
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2186
			 * We either attempt to read all the parity columns or
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2187
			 * none of them. If we didn't try to read parity, we
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2188
			 * wouldn't be here in the correctable case. There must
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2189
			 * also have been fewer parity errors than parity
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2190
			 * columns or, again, we wouldn't be in this code path.
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2191
			 */
95c16947e4af 6509749 RAIDZ reads unnecessarily generate parity
ahl
parents: 2082
diff changeset
  2192
			ASSERT(parity_untried == 0);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2193
			ASSERT(parity_errors < rm->rm_firstdatacol);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2194
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2195
			/*
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2196
			 * Identify the data columns that reported an error.
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2197
			 */
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2198
			n = 0;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2199
			for (c = rm->rm_firstdatacol; c < rm->rm_cols; c++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2200
				rc = &rm->rm_col[c];
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2201
				if (rc->rc_error != 0) {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2202
					ASSERT(n < VDEV_RAIDZ_MAXPARITY);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2203
					tgts[n++] = c;
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2204
				}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2205
			}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2206
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2207
			ASSERT(rm->rm_firstdatacol >= n);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2208
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2209
			code = vdev_raidz_reconstruct(rm, tgts, n);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2210
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2211
			if (raidz_checksum_verify(zio) == 0) {
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2212
				atomic_inc_64(&raidz_corrected[code]);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2213
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2214
				/*
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2215
				 * If we read more parity disks than were used
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2216
				 * for reconstruction, confirm that the other
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2217
				 * parity disks produced correct data. This
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2218
				 * routine is suboptimal in that it regenerates
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2219
				 * the parity that we already used in addition
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2220
				 * to the parity that we're attempting to
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2221
				 * verify, but this should be a relatively
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2222
				 * uncommon case, and can be optimized if it
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2223
				 * becomes a problem. Note that we regenerate
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2224
				 * parity when resilvering so we can write it
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2225
				 * out to failed devices later.
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2226
				 */
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2227
				if (parity_errors < rm->rm_firstdatacol - n ||
4034
b20b176bd1e8 6545015 RAID-Z resilver broken
ahl
parents: 3456
diff changeset
  2228
				    (zio->io_flags & ZIO_FLAG_RESILVER)) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2229
					n = raidz_parity_verify(zio, rm);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2230
					unexpected_errors += n;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2231
					ASSERT(parity_errors + n <=
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2232
					    rm->rm_firstdatacol);
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2233
				}
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2234
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2235
				goto done;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2236
			}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2237
		}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2238
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2239
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2240
	/*
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2241
	 * This isn't a typical situation -- either we got a read error or
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2242
	 * a child silently returned bad data. Read every block so we can
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2243
	 * try again with as much data and parity as we can track down. If
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2244
	 * we've already been through once before, all children will be marked
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2245
	 * as tried so we'll proceed to combinatorial reconstruction.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2246
	 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2247
	unexpected_errors = 1;
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2248
	rm->rm_missingdata = 0;
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2249
	rm->rm_missingparity = 0;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2250
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2251
	for (c = 0; c < rm->rm_cols; c++) {
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2252
		if (rm->rm_col[c].rc_tried)
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2253
			continue;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2254
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2255
		zio_vdev_io_redone(zio);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2256
		do {
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2257
			rc = &rm->rm_col[c];
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2258
			if (rc->rc_tried)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2259
				continue;
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2260
			zio_nowait(zio_vdev_child_io(zio, NULL,
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2261
			    vd->vdev_child[rc->rc_devidx],
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2262
			    rc->rc_offset, rc->rc_data, rc->rc_size,
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2263
			    zio->io_type, zio->io_priority, 0,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2264
			    vdev_raidz_child_done, rc));
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2265
		} while (++c < rm->rm_cols);
5530
4ed96167d864 6354519 stack overflow in zfs due to zio pipeline
bonwick
parents: 5329
diff changeset
  2266
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2267
		return;
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2268
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2269
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2270
	/*
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2271
	 * At this point we've attempted to reconstruct the data given the
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2272
	 * errors we detected, and we've attempted to read all columns. There
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2273
	 * must, therefore, be one or more additional problems -- silent errors
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2274
	 * resulting in invalid data rather than explicit I/O errors resulting
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2275
	 * in absent data. We check if there is enough additional data to
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2276
	 * possibly reconstruct the data and then perform combinatorial
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2277
	 * reconstruction over all possible combinations. If that fails,
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2278
	 * we're cooked.
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2279
	 */
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2280
	if (total_errors > rm->rm_firstdatacol) {
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2281
		zio->io_error = vdev_raidz_worst_error(rm);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2282
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2283
	} else if (total_errors < rm->rm_firstdatacol &&
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2284
	    (code = vdev_raidz_combrec(zio, total_errors, data_errors)) != 0) {
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2285
		/*
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2286
		 * If we didn't use all the available parity for the
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2287
		 * combinatorial reconstruction, verify that the remaining
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2288
		 * parity is correct.
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2289
		 */
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2290
		if (code != (1 << rm->rm_firstdatacol) - 1)
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2291
			(void) raidz_parity_verify(zio, rm);
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2292
	} else {
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2293
		/*
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2294
		 * We're here because either:
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2295
		 *
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2296
		 *	total_errors == rm_first_datacol, or
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2297
		 *	vdev_raidz_combrec() failed
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2298
		 *
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2299
		 * In either case, there is enough bad data to prevent
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2300
		 * reconstruction.
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2301
		 *
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2302
		 * Start checksum ereports for all children which haven't
11670
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2303
		 * failed, and the IO wasn't speculative.
10105
17811c723fb4 6854612 triple-parity RAID-Z
Adam Leventhal <adam.leventhal@sun.com>
parents: 9846
diff changeset
  2304
		 */
13980
d7059eb1884c 3598 want to dtrace when errors are generated in zfs
Matthew Ahrens <mahrens@delphix.com>
parents: 13952
diff changeset
  2305
		zio->io_error = SET_ERROR(ECKSUM);
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2306
11670
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2307
		if (!(zio->io_flags & ZIO_FLAG_SPECULATIVE)) {
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2308
			for (c = 0; c < rm->rm_cols; c++) {
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2309
				rc = &rm->rm_col[c];
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2310
				if (rc->rc_error == 0) {
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2311
					zio_bad_cksum_t zbc;
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2312
					zbc.zbc_has_cksum = 0;
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2313
					zbc.zbc_injected =
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2314
					    rm->rm_ecksuminjected;
10614
4f397871da47 PSARC 2009/497 zfs checksum ereport payload additions
Jonathan Adams <Jonathan.Adams@Sun.COM>
parents: 10450
diff changeset
  2315
11670
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2316
					zfs_ereport_start_checksum(
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2317
					    zio->io_spa,
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2318
					    vd->vdev_child[rc->rc_devidx],
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2319
					    zio, rc->rc_offset, rc->rc_size,
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2320
					    (void *)(uintptr_t)c, &zbc);
1d964fb5d948 6595532 ZIL is too talkative
Neil Perrin <Neil.Perrin@Sun.COM>
parents: 10922
diff changeset
  2321
				}
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2322
			}
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  2323
		}
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  2324
	}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2325
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2326
done:
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2327
	zio_checksum_verified(zio);
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2328
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7754
diff changeset
  2329
	if (zio->io_error == 0 && spa_writeable(zio->io_spa) &&
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2330
	    (unexpected_errors || (zio->io_flags & ZIO_FLAG_RESILVER))) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2331
		/*
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2332
		 * Use the good data we have in hand to repair damaged children.
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2333
		 */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2334
		for (c = 0; c < rm->rm_cols; c++) {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2335
			rc = &rm->rm_col[c];
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2336
			cvd = vd->vdev_child[rc->rc_devidx];
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2337
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  2338
			if (rc->rc_error == 0)
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  2339
				continue;
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  2340
7754
b80e4842ad54 6754011 SPA 3.0: lock breakup, i/o pipeline refactoring, device failure handling
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 5530
diff changeset
  2341
			zio_nowait(zio_vdev_child_io(zio, NULL, cvd,
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  2342
			    rc->rc_offset, rc->rc_data, rc->rc_size,
14167
dceb17481b99 4045 zfs write throttle & i/o scheduler performance work
Matthew Ahrens <mahrens@delphix.com>
parents: 14162
diff changeset
  2343
			    ZIO_TYPE_WRITE, ZIO_PRIORITY_ASYNC_WRITE,
8241
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7754
diff changeset
  2344
			    ZIO_FLAG_IO_REPAIR | (unexpected_errors ?
5a60f16123ba 6328632 zpool offline is a bit too conservative
Jeff Bonwick <Jeff.Bonwick@Sun.COM>
parents: 7754
diff changeset
  2345
			    ZIO_FLAG_SELF_HEAL : 0), NULL, NULL));
1732
9e3ae798af31 6280668 pluggable block allocation policy
bonwick
parents: 1544
diff changeset
  2346
		}
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2347
	}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2348
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2349
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2350
static void
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2351
vdev_raidz_state_change(vdev_t *vd, int faulted, int degraded)
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2352
{
2082
76b439ec3ac1 PSARC 2006/223 ZFS Hot Spares
eschrock
parents: 1775
diff changeset
  2353
	if (faulted > vd->vdev_nparity)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  2354
		vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN,
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  2355
		    VDEV_AUX_NO_REPLICAS);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2356
	else if (degraded + faulted != 0)
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  2357
		vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, VDEV_AUX_NONE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2358
	else
1544
938876158511 PSARC 2006/077 zpool clear
eschrock
parents: 1133
diff changeset
  2359
		vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE);
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2360
}
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2361
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2362
vdev_ops_t vdev_raidz_ops = {
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2363
	vdev_raidz_open,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2364
	vdev_raidz_close,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2365
	vdev_raidz_asize,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2366
	vdev_raidz_io_start,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2367
	vdev_raidz_io_done,
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2368
	vdev_raidz_state_change,
11958
575ffe1e978d 6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents: 11670
diff changeset
  2369
	NULL,
575ffe1e978d 6923585 deadlock while booting OpenSolaris build 132 from mirrored rpool with removed submirror
George Wilson <George.Wilson@Sun.COM>
parents: 11670
diff changeset
  2370
	NULL,
789
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2371
	VDEV_TYPE_RAIDZ,	/* name of this vdev type */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2372
	B_FALSE			/* not a leaf vdev */
b348f31ed315 PSARC 2002/240 ZFS
ahrens
parents:
diff changeset
  2373
};