1eda14cbcSMatt Macy /* 2eda14cbcSMatt Macy * CDDL HEADER START 3eda14cbcSMatt Macy * 4eda14cbcSMatt Macy * The contents of this file are subject to the terms of the 5eda14cbcSMatt Macy * Common Development and Distribution License (the "License"). 6eda14cbcSMatt Macy * You may not use this file except in compliance with the License. 7eda14cbcSMatt Macy * 8eda14cbcSMatt Macy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9eda14cbcSMatt Macy * or http://www.opensolaris.org/os/licensing. 10eda14cbcSMatt Macy * See the License for the specific language governing permissions 11eda14cbcSMatt Macy * and limitations under the License. 12eda14cbcSMatt Macy * 13eda14cbcSMatt Macy * When distributing Covered Code, include this CDDL HEADER in each 14eda14cbcSMatt Macy * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15eda14cbcSMatt Macy * If applicable, add the following below this CDDL HEADER, with the 16eda14cbcSMatt Macy * fields enclosed by brackets "[]" replaced with your own identifying 17eda14cbcSMatt Macy * information: Portions Copyright [yyyy] [name of copyright owner] 18eda14cbcSMatt Macy * 19eda14cbcSMatt Macy * CDDL HEADER END 20eda14cbcSMatt Macy */ 21eda14cbcSMatt Macy 22eda14cbcSMatt Macy /* 23eda14cbcSMatt Macy * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 242c48331dSMatt Macy * Copyright (c) 2012, 2020 by Delphix. All rights reserved. 25eda14cbcSMatt Macy * Copyright (c) 2016 Gvozden Nešković. All rights reserved. 26eda14cbcSMatt Macy */ 27eda14cbcSMatt Macy 28eda14cbcSMatt Macy #include <sys/zfs_context.h> 29eda14cbcSMatt Macy #include <sys/spa.h> 30eda14cbcSMatt Macy #include <sys/vdev_impl.h> 31eda14cbcSMatt Macy #include <sys/zio.h> 32eda14cbcSMatt Macy #include <sys/zio_checksum.h> 33eda14cbcSMatt Macy #include <sys/abd.h> 34eda14cbcSMatt Macy #include <sys/fs/zfs.h> 35eda14cbcSMatt Macy #include <sys/fm/fs/zfs.h> 36eda14cbcSMatt Macy #include <sys/vdev_raidz.h> 37eda14cbcSMatt Macy #include <sys/vdev_raidz_impl.h> 387877fdebSMatt Macy #include <sys/vdev_draid.h> 39eda14cbcSMatt Macy 40eda14cbcSMatt Macy #ifdef ZFS_DEBUG 41eda14cbcSMatt Macy #include <sys/vdev.h> /* For vdev_xlate() in vdev_raidz_io_verify() */ 42eda14cbcSMatt Macy #endif 43eda14cbcSMatt Macy 44eda14cbcSMatt Macy /* 45eda14cbcSMatt Macy * Virtual device vector for RAID-Z. 46eda14cbcSMatt Macy * 47eda14cbcSMatt Macy * This vdev supports single, double, and triple parity. For single parity, 48eda14cbcSMatt Macy * we use a simple XOR of all the data columns. For double or triple parity, 49eda14cbcSMatt Macy * we use a special case of Reed-Solomon coding. This extends the 50eda14cbcSMatt Macy * technique described in "The mathematics of RAID-6" by H. Peter Anvin by 51eda14cbcSMatt Macy * drawing on the system described in "A Tutorial on Reed-Solomon Coding for 52eda14cbcSMatt Macy * Fault-Tolerance in RAID-like Systems" by James S. Plank on which the 53eda14cbcSMatt Macy * former is also based. The latter is designed to provide higher performance 54eda14cbcSMatt Macy * for writes. 55eda14cbcSMatt Macy * 56eda14cbcSMatt Macy * Note that the Plank paper claimed to support arbitrary N+M, but was then 57eda14cbcSMatt Macy * amended six years later identifying a critical flaw that invalidates its 58eda14cbcSMatt Macy * claims. Nevertheless, the technique can be adapted to work for up to 59eda14cbcSMatt Macy * triple parity. For additional parity, the amendment "Note: Correction to 60eda14cbcSMatt Macy * the 1997 Tutorial on Reed-Solomon Coding" by James S. Plank and Ying Ding 61eda14cbcSMatt Macy * is viable, but the additional complexity means that write performance will 62eda14cbcSMatt Macy * suffer. 63eda14cbcSMatt Macy * 64eda14cbcSMatt Macy * All of the methods above operate on a Galois field, defined over the 65eda14cbcSMatt Macy * integers mod 2^N. In our case we choose N=8 for GF(8) so that all elements 66eda14cbcSMatt Macy * can be expressed with a single byte. Briefly, the operations on the 67eda14cbcSMatt Macy * field are defined as follows: 68eda14cbcSMatt Macy * 69eda14cbcSMatt Macy * o addition (+) is represented by a bitwise XOR 70eda14cbcSMatt Macy * o subtraction (-) is therefore identical to addition: A + B = A - B 71eda14cbcSMatt Macy * o multiplication of A by 2 is defined by the following bitwise expression: 72eda14cbcSMatt Macy * 73eda14cbcSMatt Macy * (A * 2)_7 = A_6 74eda14cbcSMatt Macy * (A * 2)_6 = A_5 75eda14cbcSMatt Macy * (A * 2)_5 = A_4 76eda14cbcSMatt Macy * (A * 2)_4 = A_3 + A_7 77eda14cbcSMatt Macy * (A * 2)_3 = A_2 + A_7 78eda14cbcSMatt Macy * (A * 2)_2 = A_1 + A_7 79eda14cbcSMatt Macy * (A * 2)_1 = A_0 80eda14cbcSMatt Macy * (A * 2)_0 = A_7 81eda14cbcSMatt Macy * 82eda14cbcSMatt Macy * In C, multiplying by 2 is therefore ((a << 1) ^ ((a & 0x80) ? 0x1d : 0)). 83eda14cbcSMatt Macy * As an aside, this multiplication is derived from the error correcting 84eda14cbcSMatt Macy * primitive polynomial x^8 + x^4 + x^3 + x^2 + 1. 85eda14cbcSMatt Macy * 86eda14cbcSMatt Macy * Observe that any number in the field (except for 0) can be expressed as a 87eda14cbcSMatt Macy * power of 2 -- a generator for the field. We store a table of the powers of 88eda14cbcSMatt Macy * 2 and logs base 2 for quick look ups, and exploit the fact that A * B can 89eda14cbcSMatt Macy * be rewritten as 2^(log_2(A) + log_2(B)) (where '+' is normal addition rather 90eda14cbcSMatt Macy * than field addition). The inverse of a field element A (A^-1) is therefore 91eda14cbcSMatt Macy * A ^ (255 - 1) = A^254. 92eda14cbcSMatt Macy * 93eda14cbcSMatt Macy * The up-to-three parity columns, P, Q, R over several data columns, 94eda14cbcSMatt Macy * D_0, ... D_n-1, can be expressed by field operations: 95eda14cbcSMatt Macy * 96eda14cbcSMatt Macy * P = D_0 + D_1 + ... + D_n-2 + D_n-1 97eda14cbcSMatt Macy * Q = 2^n-1 * D_0 + 2^n-2 * D_1 + ... + 2^1 * D_n-2 + 2^0 * D_n-1 98eda14cbcSMatt Macy * = ((...((D_0) * 2 + D_1) * 2 + ...) * 2 + D_n-2) * 2 + D_n-1 99eda14cbcSMatt Macy * R = 4^n-1 * D_0 + 4^n-2 * D_1 + ... + 4^1 * D_n-2 + 4^0 * D_n-1 100eda14cbcSMatt Macy * = ((...((D_0) * 4 + D_1) * 4 + ...) * 4 + D_n-2) * 4 + D_n-1 101eda14cbcSMatt Macy * 102eda14cbcSMatt Macy * We chose 1, 2, and 4 as our generators because 1 corresponds to the trivial 103eda14cbcSMatt Macy * XOR operation, and 2 and 4 can be computed quickly and generate linearly- 104eda14cbcSMatt Macy * independent coefficients. (There are no additional coefficients that have 105eda14cbcSMatt Macy * this property which is why the uncorrected Plank method breaks down.) 106eda14cbcSMatt Macy * 107eda14cbcSMatt Macy * See the reconstruction code below for how P, Q and R can used individually 108eda14cbcSMatt Macy * or in concert to recover missing data columns. 109eda14cbcSMatt Macy */ 110eda14cbcSMatt Macy 111eda14cbcSMatt Macy #define VDEV_RAIDZ_P 0 112eda14cbcSMatt Macy #define VDEV_RAIDZ_Q 1 113eda14cbcSMatt Macy #define VDEV_RAIDZ_R 2 114eda14cbcSMatt Macy 115eda14cbcSMatt Macy #define VDEV_RAIDZ_MUL_2(x) (((x) << 1) ^ (((x) & 0x80) ? 0x1d : 0)) 116eda14cbcSMatt Macy #define VDEV_RAIDZ_MUL_4(x) (VDEV_RAIDZ_MUL_2(VDEV_RAIDZ_MUL_2(x))) 117eda14cbcSMatt Macy 118eda14cbcSMatt Macy /* 119eda14cbcSMatt Macy * We provide a mechanism to perform the field multiplication operation on a 120eda14cbcSMatt Macy * 64-bit value all at once rather than a byte at a time. This works by 121eda14cbcSMatt Macy * creating a mask from the top bit in each byte and using that to 122eda14cbcSMatt Macy * conditionally apply the XOR of 0x1d. 123eda14cbcSMatt Macy */ 124eda14cbcSMatt Macy #define VDEV_RAIDZ_64MUL_2(x, mask) \ 125eda14cbcSMatt Macy { \ 126eda14cbcSMatt Macy (mask) = (x) & 0x8080808080808080ULL; \ 127eda14cbcSMatt Macy (mask) = ((mask) << 1) - ((mask) >> 7); \ 128eda14cbcSMatt Macy (x) = (((x) << 1) & 0xfefefefefefefefeULL) ^ \ 129eda14cbcSMatt Macy ((mask) & 0x1d1d1d1d1d1d1d1dULL); \ 130eda14cbcSMatt Macy } 131eda14cbcSMatt Macy 132eda14cbcSMatt Macy #define VDEV_RAIDZ_64MUL_4(x, mask) \ 133eda14cbcSMatt Macy { \ 134eda14cbcSMatt Macy VDEV_RAIDZ_64MUL_2((x), mask); \ 135eda14cbcSMatt Macy VDEV_RAIDZ_64MUL_2((x), mask); \ 136eda14cbcSMatt Macy } 137eda14cbcSMatt Macy 1387877fdebSMatt Macy static void 1397877fdebSMatt Macy vdev_raidz_row_free(raidz_row_t *rr) 140eda14cbcSMatt Macy { 141184c1b94SMartin Matuska for (int c = 0; c < rr->rr_cols; c++) { 142184c1b94SMartin Matuska raidz_col_t *rc = &rr->rr_col[c]; 143eda14cbcSMatt Macy 144184c1b94SMartin Matuska if (rc->rc_size != 0) 145184c1b94SMartin Matuska abd_free(rc->rc_abd); 146184c1b94SMartin Matuska if (rc->rc_orig_data != NULL) 147*f9693befSMartin Matuska abd_free(rc->rc_orig_data); 148eda14cbcSMatt Macy } 149eda14cbcSMatt Macy 1507877fdebSMatt Macy if (rr->rr_abd_empty != NULL) 1517877fdebSMatt Macy abd_free(rr->rr_abd_empty); 152eda14cbcSMatt Macy 1537877fdebSMatt Macy kmem_free(rr, offsetof(raidz_row_t, rr_col[rr->rr_scols])); 1547877fdebSMatt Macy } 1557877fdebSMatt Macy 1567877fdebSMatt Macy void 1577877fdebSMatt Macy vdev_raidz_map_free(raidz_map_t *rm) 1587877fdebSMatt Macy { 1597877fdebSMatt Macy for (int i = 0; i < rm->rm_nrows; i++) 1607877fdebSMatt Macy vdev_raidz_row_free(rm->rm_row[i]); 1617877fdebSMatt Macy 1627877fdebSMatt Macy kmem_free(rm, offsetof(raidz_map_t, rm_row[rm->rm_nrows])); 163eda14cbcSMatt Macy } 164eda14cbcSMatt Macy 165eda14cbcSMatt Macy static void 166eda14cbcSMatt Macy vdev_raidz_map_free_vsd(zio_t *zio) 167eda14cbcSMatt Macy { 168eda14cbcSMatt Macy raidz_map_t *rm = zio->io_vsd; 169eda14cbcSMatt Macy 170eda14cbcSMatt Macy vdev_raidz_map_free(rm); 171eda14cbcSMatt Macy } 172eda14cbcSMatt Macy 173*f9693befSMartin Matuska const zio_vsd_ops_t vdev_raidz_vsd_ops = { 174eda14cbcSMatt Macy .vsd_free = vdev_raidz_map_free_vsd, 175eda14cbcSMatt Macy }; 176eda14cbcSMatt Macy 177eda14cbcSMatt Macy /* 178eda14cbcSMatt Macy * Divides the IO evenly across all child vdevs; usually, dcols is 179eda14cbcSMatt Macy * the number of children in the target vdev. 180eda14cbcSMatt Macy * 181eda14cbcSMatt Macy * Avoid inlining the function to keep vdev_raidz_io_start(), which 182eda14cbcSMatt Macy * is this functions only caller, as small as possible on the stack. 183eda14cbcSMatt Macy */ 184eda14cbcSMatt Macy noinline raidz_map_t * 185eda14cbcSMatt Macy vdev_raidz_map_alloc(zio_t *zio, uint64_t ashift, uint64_t dcols, 186eda14cbcSMatt Macy uint64_t nparity) 187eda14cbcSMatt Macy { 1887877fdebSMatt Macy raidz_row_t *rr; 189eda14cbcSMatt Macy /* The starting RAIDZ (parent) vdev sector of the block. */ 190eda14cbcSMatt Macy uint64_t b = zio->io_offset >> ashift; 191eda14cbcSMatt Macy /* The zio's size in units of the vdev's minimum sector size. */ 192eda14cbcSMatt Macy uint64_t s = zio->io_size >> ashift; 193eda14cbcSMatt Macy /* The first column for this stripe. */ 194eda14cbcSMatt Macy uint64_t f = b % dcols; 195eda14cbcSMatt Macy /* The starting byte offset on each child vdev. */ 196eda14cbcSMatt Macy uint64_t o = (b / dcols) << ashift; 197eda14cbcSMatt Macy uint64_t q, r, c, bc, col, acols, scols, coff, devidx, asize, tot; 198eda14cbcSMatt Macy 1997877fdebSMatt Macy raidz_map_t *rm = 2007877fdebSMatt Macy kmem_zalloc(offsetof(raidz_map_t, rm_row[1]), KM_SLEEP); 2017877fdebSMatt Macy rm->rm_nrows = 1; 2027877fdebSMatt Macy 203eda14cbcSMatt Macy /* 204eda14cbcSMatt Macy * "Quotient": The number of data sectors for this stripe on all but 205eda14cbcSMatt Macy * the "big column" child vdevs that also contain "remainder" data. 206eda14cbcSMatt Macy */ 207eda14cbcSMatt Macy q = s / (dcols - nparity); 208eda14cbcSMatt Macy 209eda14cbcSMatt Macy /* 210eda14cbcSMatt Macy * "Remainder": The number of partial stripe data sectors in this I/O. 211eda14cbcSMatt Macy * This will add a sector to some, but not all, child vdevs. 212eda14cbcSMatt Macy */ 213eda14cbcSMatt Macy r = s - q * (dcols - nparity); 214eda14cbcSMatt Macy 215eda14cbcSMatt Macy /* The number of "big columns" - those which contain remainder data. */ 216eda14cbcSMatt Macy bc = (r == 0 ? 0 : r + nparity); 217eda14cbcSMatt Macy 218eda14cbcSMatt Macy /* 219eda14cbcSMatt Macy * The total number of data and parity sectors associated with 220eda14cbcSMatt Macy * this I/O. 221eda14cbcSMatt Macy */ 222eda14cbcSMatt Macy tot = s + nparity * (q + (r == 0 ? 0 : 1)); 223eda14cbcSMatt Macy 2247877fdebSMatt Macy /* 2257877fdebSMatt Macy * acols: The columns that will be accessed. 2267877fdebSMatt Macy * scols: The columns that will be accessed or skipped. 2277877fdebSMatt Macy */ 228eda14cbcSMatt Macy if (q == 0) { 229eda14cbcSMatt Macy /* Our I/O request doesn't span all child vdevs. */ 230eda14cbcSMatt Macy acols = bc; 231eda14cbcSMatt Macy scols = MIN(dcols, roundup(bc, nparity + 1)); 232eda14cbcSMatt Macy } else { 233eda14cbcSMatt Macy acols = dcols; 234eda14cbcSMatt Macy scols = dcols; 235eda14cbcSMatt Macy } 236eda14cbcSMatt Macy 237eda14cbcSMatt Macy ASSERT3U(acols, <=, scols); 238eda14cbcSMatt Macy 2397877fdebSMatt Macy rr = kmem_alloc(offsetof(raidz_row_t, rr_col[scols]), KM_SLEEP); 2407877fdebSMatt Macy rm->rm_row[0] = rr; 241eda14cbcSMatt Macy 2427877fdebSMatt Macy rr->rr_cols = acols; 2437877fdebSMatt Macy rr->rr_scols = scols; 2447877fdebSMatt Macy rr->rr_bigcols = bc; 2457877fdebSMatt Macy rr->rr_missingdata = 0; 2467877fdebSMatt Macy rr->rr_missingparity = 0; 2477877fdebSMatt Macy rr->rr_firstdatacol = nparity; 2487877fdebSMatt Macy rr->rr_abd_empty = NULL; 2497877fdebSMatt Macy rr->rr_nempty = 0; 2507877fdebSMatt Macy #ifdef ZFS_DEBUG 2517877fdebSMatt Macy rr->rr_offset = zio->io_offset; 2527877fdebSMatt Macy rr->rr_size = zio->io_size; 2537877fdebSMatt Macy #endif 254eda14cbcSMatt Macy 255eda14cbcSMatt Macy asize = 0; 256eda14cbcSMatt Macy 257eda14cbcSMatt Macy for (c = 0; c < scols; c++) { 2587877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 259eda14cbcSMatt Macy col = f + c; 260eda14cbcSMatt Macy coff = o; 261eda14cbcSMatt Macy if (col >= dcols) { 262eda14cbcSMatt Macy col -= dcols; 263eda14cbcSMatt Macy coff += 1ULL << ashift; 264eda14cbcSMatt Macy } 2657877fdebSMatt Macy rc->rc_devidx = col; 2667877fdebSMatt Macy rc->rc_offset = coff; 2677877fdebSMatt Macy rc->rc_abd = NULL; 2687877fdebSMatt Macy rc->rc_orig_data = NULL; 2697877fdebSMatt Macy rc->rc_error = 0; 2707877fdebSMatt Macy rc->rc_tried = 0; 2717877fdebSMatt Macy rc->rc_skipped = 0; 2727877fdebSMatt Macy rc->rc_repair = 0; 2737877fdebSMatt Macy rc->rc_need_orig_restore = B_FALSE; 274eda14cbcSMatt Macy 275eda14cbcSMatt Macy if (c >= acols) 2767877fdebSMatt Macy rc->rc_size = 0; 277eda14cbcSMatt Macy else if (c < bc) 2787877fdebSMatt Macy rc->rc_size = (q + 1) << ashift; 279eda14cbcSMatt Macy else 2807877fdebSMatt Macy rc->rc_size = q << ashift; 281eda14cbcSMatt Macy 2827877fdebSMatt Macy asize += rc->rc_size; 283eda14cbcSMatt Macy } 284eda14cbcSMatt Macy 285eda14cbcSMatt Macy ASSERT3U(asize, ==, tot << ashift); 286eda14cbcSMatt Macy rm->rm_nskip = roundup(tot, nparity + 1) - tot; 2877877fdebSMatt Macy rm->rm_skipstart = bc; 288eda14cbcSMatt Macy 2897877fdebSMatt Macy for (c = 0; c < rr->rr_firstdatacol; c++) 2907877fdebSMatt Macy rr->rr_col[c].rc_abd = 2917877fdebSMatt Macy abd_alloc_linear(rr->rr_col[c].rc_size, B_FALSE); 292eda14cbcSMatt Macy 293184c1b94SMartin Matuska for (uint64_t off = 0; c < acols; c++) { 2947877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 295184c1b94SMartin Matuska rc->rc_abd = abd_get_offset_struct(&rc->rc_abdstruct, 296184c1b94SMartin Matuska zio->io_abd, off, rc->rc_size); 2977877fdebSMatt Macy off += rc->rc_size; 298eda14cbcSMatt Macy } 299eda14cbcSMatt Macy 300eda14cbcSMatt Macy /* 301eda14cbcSMatt Macy * If all data stored spans all columns, there's a danger that parity 302eda14cbcSMatt Macy * will always be on the same device and, since parity isn't read 303eda14cbcSMatt Macy * during normal operation, that device's I/O bandwidth won't be 304eda14cbcSMatt Macy * used effectively. We therefore switch the parity every 1MB. 305eda14cbcSMatt Macy * 306eda14cbcSMatt Macy * ... at least that was, ostensibly, the theory. As a practical 307eda14cbcSMatt Macy * matter unless we juggle the parity between all devices evenly, we 308eda14cbcSMatt Macy * won't see any benefit. Further, occasional writes that aren't a 309eda14cbcSMatt Macy * multiple of the LCM of the number of children and the minimum 310eda14cbcSMatt Macy * stripe width are sufficient to avoid pessimal behavior. 311eda14cbcSMatt Macy * Unfortunately, this decision created an implicit on-disk format 312eda14cbcSMatt Macy * requirement that we need to support for all eternity, but only 313eda14cbcSMatt Macy * for single-parity RAID-Z. 314eda14cbcSMatt Macy * 315eda14cbcSMatt Macy * If we intend to skip a sector in the zeroth column for padding 316eda14cbcSMatt Macy * we must make sure to note this swap. We will never intend to 317eda14cbcSMatt Macy * skip the first column since at least one data and one parity 318eda14cbcSMatt Macy * column must appear in each row. 319eda14cbcSMatt Macy */ 3207877fdebSMatt Macy ASSERT(rr->rr_cols >= 2); 3217877fdebSMatt Macy ASSERT(rr->rr_col[0].rc_size == rr->rr_col[1].rc_size); 322eda14cbcSMatt Macy 3237877fdebSMatt Macy if (rr->rr_firstdatacol == 1 && (zio->io_offset & (1ULL << 20))) { 3247877fdebSMatt Macy devidx = rr->rr_col[0].rc_devidx; 3257877fdebSMatt Macy o = rr->rr_col[0].rc_offset; 3267877fdebSMatt Macy rr->rr_col[0].rc_devidx = rr->rr_col[1].rc_devidx; 3277877fdebSMatt Macy rr->rr_col[0].rc_offset = rr->rr_col[1].rc_offset; 3287877fdebSMatt Macy rr->rr_col[1].rc_devidx = devidx; 3297877fdebSMatt Macy rr->rr_col[1].rc_offset = o; 330eda14cbcSMatt Macy 331eda14cbcSMatt Macy if (rm->rm_skipstart == 0) 332eda14cbcSMatt Macy rm->rm_skipstart = 1; 333eda14cbcSMatt Macy } 334eda14cbcSMatt Macy 335eda14cbcSMatt Macy /* init RAIDZ parity ops */ 336eda14cbcSMatt Macy rm->rm_ops = vdev_raidz_math_get_ops(); 337eda14cbcSMatt Macy 338eda14cbcSMatt Macy return (rm); 339eda14cbcSMatt Macy } 340eda14cbcSMatt Macy 341eda14cbcSMatt Macy struct pqr_struct { 342eda14cbcSMatt Macy uint64_t *p; 343eda14cbcSMatt Macy uint64_t *q; 344eda14cbcSMatt Macy uint64_t *r; 345eda14cbcSMatt Macy }; 346eda14cbcSMatt Macy 347eda14cbcSMatt Macy static int 348eda14cbcSMatt Macy vdev_raidz_p_func(void *buf, size_t size, void *private) 349eda14cbcSMatt Macy { 350eda14cbcSMatt Macy struct pqr_struct *pqr = private; 351eda14cbcSMatt Macy const uint64_t *src = buf; 352eda14cbcSMatt Macy int i, cnt = size / sizeof (src[0]); 353eda14cbcSMatt Macy 354eda14cbcSMatt Macy ASSERT(pqr->p && !pqr->q && !pqr->r); 355eda14cbcSMatt Macy 356eda14cbcSMatt Macy for (i = 0; i < cnt; i++, src++, pqr->p++) 357eda14cbcSMatt Macy *pqr->p ^= *src; 358eda14cbcSMatt Macy 359eda14cbcSMatt Macy return (0); 360eda14cbcSMatt Macy } 361eda14cbcSMatt Macy 362eda14cbcSMatt Macy static int 363eda14cbcSMatt Macy vdev_raidz_pq_func(void *buf, size_t size, void *private) 364eda14cbcSMatt Macy { 365eda14cbcSMatt Macy struct pqr_struct *pqr = private; 366eda14cbcSMatt Macy const uint64_t *src = buf; 367eda14cbcSMatt Macy uint64_t mask; 368eda14cbcSMatt Macy int i, cnt = size / sizeof (src[0]); 369eda14cbcSMatt Macy 370eda14cbcSMatt Macy ASSERT(pqr->p && pqr->q && !pqr->r); 371eda14cbcSMatt Macy 372eda14cbcSMatt Macy for (i = 0; i < cnt; i++, src++, pqr->p++, pqr->q++) { 373eda14cbcSMatt Macy *pqr->p ^= *src; 374eda14cbcSMatt Macy VDEV_RAIDZ_64MUL_2(*pqr->q, mask); 375eda14cbcSMatt Macy *pqr->q ^= *src; 376eda14cbcSMatt Macy } 377eda14cbcSMatt Macy 378eda14cbcSMatt Macy return (0); 379eda14cbcSMatt Macy } 380eda14cbcSMatt Macy 381eda14cbcSMatt Macy static int 382eda14cbcSMatt Macy vdev_raidz_pqr_func(void *buf, size_t size, void *private) 383eda14cbcSMatt Macy { 384eda14cbcSMatt Macy struct pqr_struct *pqr = private; 385eda14cbcSMatt Macy const uint64_t *src = buf; 386eda14cbcSMatt Macy uint64_t mask; 387eda14cbcSMatt Macy int i, cnt = size / sizeof (src[0]); 388eda14cbcSMatt Macy 389eda14cbcSMatt Macy ASSERT(pqr->p && pqr->q && pqr->r); 390eda14cbcSMatt Macy 391eda14cbcSMatt Macy for (i = 0; i < cnt; i++, src++, pqr->p++, pqr->q++, pqr->r++) { 392eda14cbcSMatt Macy *pqr->p ^= *src; 393eda14cbcSMatt Macy VDEV_RAIDZ_64MUL_2(*pqr->q, mask); 394eda14cbcSMatt Macy *pqr->q ^= *src; 395eda14cbcSMatt Macy VDEV_RAIDZ_64MUL_4(*pqr->r, mask); 396eda14cbcSMatt Macy *pqr->r ^= *src; 397eda14cbcSMatt Macy } 398eda14cbcSMatt Macy 399eda14cbcSMatt Macy return (0); 400eda14cbcSMatt Macy } 401eda14cbcSMatt Macy 402eda14cbcSMatt Macy static void 4037877fdebSMatt Macy vdev_raidz_generate_parity_p(raidz_row_t *rr) 404eda14cbcSMatt Macy { 4057877fdebSMatt Macy uint64_t *p = abd_to_buf(rr->rr_col[VDEV_RAIDZ_P].rc_abd); 406eda14cbcSMatt Macy 4077877fdebSMatt Macy for (int c = rr->rr_firstdatacol; c < rr->rr_cols; c++) { 4087877fdebSMatt Macy abd_t *src = rr->rr_col[c].rc_abd; 409eda14cbcSMatt Macy 4107877fdebSMatt Macy if (c == rr->rr_firstdatacol) { 4117877fdebSMatt Macy abd_copy_to_buf(p, src, rr->rr_col[c].rc_size); 412eda14cbcSMatt Macy } else { 413eda14cbcSMatt Macy struct pqr_struct pqr = { p, NULL, NULL }; 4147877fdebSMatt Macy (void) abd_iterate_func(src, 0, rr->rr_col[c].rc_size, 415eda14cbcSMatt Macy vdev_raidz_p_func, &pqr); 416eda14cbcSMatt Macy } 417eda14cbcSMatt Macy } 418eda14cbcSMatt Macy } 419eda14cbcSMatt Macy 420eda14cbcSMatt Macy static void 4217877fdebSMatt Macy vdev_raidz_generate_parity_pq(raidz_row_t *rr) 422eda14cbcSMatt Macy { 4237877fdebSMatt Macy uint64_t *p = abd_to_buf(rr->rr_col[VDEV_RAIDZ_P].rc_abd); 4247877fdebSMatt Macy uint64_t *q = abd_to_buf(rr->rr_col[VDEV_RAIDZ_Q].rc_abd); 4257877fdebSMatt Macy uint64_t pcnt = rr->rr_col[VDEV_RAIDZ_P].rc_size / sizeof (p[0]); 4267877fdebSMatt Macy ASSERT(rr->rr_col[VDEV_RAIDZ_P].rc_size == 4277877fdebSMatt Macy rr->rr_col[VDEV_RAIDZ_Q].rc_size); 428eda14cbcSMatt Macy 4297877fdebSMatt Macy for (int c = rr->rr_firstdatacol; c < rr->rr_cols; c++) { 4307877fdebSMatt Macy abd_t *src = rr->rr_col[c].rc_abd; 431eda14cbcSMatt Macy 4327877fdebSMatt Macy uint64_t ccnt = rr->rr_col[c].rc_size / sizeof (p[0]); 433eda14cbcSMatt Macy 4347877fdebSMatt Macy if (c == rr->rr_firstdatacol) { 435eda14cbcSMatt Macy ASSERT(ccnt == pcnt || ccnt == 0); 4367877fdebSMatt Macy abd_copy_to_buf(p, src, rr->rr_col[c].rc_size); 4377877fdebSMatt Macy (void) memcpy(q, p, rr->rr_col[c].rc_size); 438eda14cbcSMatt Macy 4397877fdebSMatt Macy for (uint64_t i = ccnt; i < pcnt; i++) { 440eda14cbcSMatt Macy p[i] = 0; 441eda14cbcSMatt Macy q[i] = 0; 442eda14cbcSMatt Macy } 443eda14cbcSMatt Macy } else { 444eda14cbcSMatt Macy struct pqr_struct pqr = { p, q, NULL }; 445eda14cbcSMatt Macy 446eda14cbcSMatt Macy ASSERT(ccnt <= pcnt); 4477877fdebSMatt Macy (void) abd_iterate_func(src, 0, rr->rr_col[c].rc_size, 448eda14cbcSMatt Macy vdev_raidz_pq_func, &pqr); 449eda14cbcSMatt Macy 450eda14cbcSMatt Macy /* 451eda14cbcSMatt Macy * Treat short columns as though they are full of 0s. 452eda14cbcSMatt Macy * Note that there's therefore nothing needed for P. 453eda14cbcSMatt Macy */ 4547877fdebSMatt Macy uint64_t mask; 4557877fdebSMatt Macy for (uint64_t i = ccnt; i < pcnt; i++) { 456eda14cbcSMatt Macy VDEV_RAIDZ_64MUL_2(q[i], mask); 457eda14cbcSMatt Macy } 458eda14cbcSMatt Macy } 459eda14cbcSMatt Macy } 460eda14cbcSMatt Macy } 461eda14cbcSMatt Macy 462eda14cbcSMatt Macy static void 4637877fdebSMatt Macy vdev_raidz_generate_parity_pqr(raidz_row_t *rr) 464eda14cbcSMatt Macy { 4657877fdebSMatt Macy uint64_t *p = abd_to_buf(rr->rr_col[VDEV_RAIDZ_P].rc_abd); 4667877fdebSMatt Macy uint64_t *q = abd_to_buf(rr->rr_col[VDEV_RAIDZ_Q].rc_abd); 4677877fdebSMatt Macy uint64_t *r = abd_to_buf(rr->rr_col[VDEV_RAIDZ_R].rc_abd); 4687877fdebSMatt Macy uint64_t pcnt = rr->rr_col[VDEV_RAIDZ_P].rc_size / sizeof (p[0]); 4697877fdebSMatt Macy ASSERT(rr->rr_col[VDEV_RAIDZ_P].rc_size == 4707877fdebSMatt Macy rr->rr_col[VDEV_RAIDZ_Q].rc_size); 4717877fdebSMatt Macy ASSERT(rr->rr_col[VDEV_RAIDZ_P].rc_size == 4727877fdebSMatt Macy rr->rr_col[VDEV_RAIDZ_R].rc_size); 473eda14cbcSMatt Macy 4747877fdebSMatt Macy for (int c = rr->rr_firstdatacol; c < rr->rr_cols; c++) { 4757877fdebSMatt Macy abd_t *src = rr->rr_col[c].rc_abd; 476eda14cbcSMatt Macy 4777877fdebSMatt Macy uint64_t ccnt = rr->rr_col[c].rc_size / sizeof (p[0]); 478eda14cbcSMatt Macy 4797877fdebSMatt Macy if (c == rr->rr_firstdatacol) { 480eda14cbcSMatt Macy ASSERT(ccnt == pcnt || ccnt == 0); 4817877fdebSMatt Macy abd_copy_to_buf(p, src, rr->rr_col[c].rc_size); 4827877fdebSMatt Macy (void) memcpy(q, p, rr->rr_col[c].rc_size); 4837877fdebSMatt Macy (void) memcpy(r, p, rr->rr_col[c].rc_size); 484eda14cbcSMatt Macy 4857877fdebSMatt Macy for (uint64_t i = ccnt; i < pcnt; i++) { 486eda14cbcSMatt Macy p[i] = 0; 487eda14cbcSMatt Macy q[i] = 0; 488eda14cbcSMatt Macy r[i] = 0; 489eda14cbcSMatt Macy } 490eda14cbcSMatt Macy } else { 491eda14cbcSMatt Macy struct pqr_struct pqr = { p, q, r }; 492eda14cbcSMatt Macy 493eda14cbcSMatt Macy ASSERT(ccnt <= pcnt); 4947877fdebSMatt Macy (void) abd_iterate_func(src, 0, rr->rr_col[c].rc_size, 495eda14cbcSMatt Macy vdev_raidz_pqr_func, &pqr); 496eda14cbcSMatt Macy 497eda14cbcSMatt Macy /* 498eda14cbcSMatt Macy * Treat short columns as though they are full of 0s. 499eda14cbcSMatt Macy * Note that there's therefore nothing needed for P. 500eda14cbcSMatt Macy */ 5017877fdebSMatt Macy uint64_t mask; 5027877fdebSMatt Macy for (uint64_t i = ccnt; i < pcnt; i++) { 503eda14cbcSMatt Macy VDEV_RAIDZ_64MUL_2(q[i], mask); 504eda14cbcSMatt Macy VDEV_RAIDZ_64MUL_4(r[i], mask); 505eda14cbcSMatt Macy } 506eda14cbcSMatt Macy } 507eda14cbcSMatt Macy } 508eda14cbcSMatt Macy } 509eda14cbcSMatt Macy 510eda14cbcSMatt Macy /* 511eda14cbcSMatt Macy * Generate RAID parity in the first virtual columns according to the number of 512eda14cbcSMatt Macy * parity columns available. 513eda14cbcSMatt Macy */ 514eda14cbcSMatt Macy void 5157877fdebSMatt Macy vdev_raidz_generate_parity_row(raidz_map_t *rm, raidz_row_t *rr) 516eda14cbcSMatt Macy { 5177877fdebSMatt Macy ASSERT3U(rr->rr_cols, !=, 0); 5187877fdebSMatt Macy 519eda14cbcSMatt Macy /* Generate using the new math implementation */ 5207877fdebSMatt Macy if (vdev_raidz_math_generate(rm, rr) != RAIDZ_ORIGINAL_IMPL) 521eda14cbcSMatt Macy return; 522eda14cbcSMatt Macy 5237877fdebSMatt Macy switch (rr->rr_firstdatacol) { 524eda14cbcSMatt Macy case 1: 5257877fdebSMatt Macy vdev_raidz_generate_parity_p(rr); 526eda14cbcSMatt Macy break; 527eda14cbcSMatt Macy case 2: 5287877fdebSMatt Macy vdev_raidz_generate_parity_pq(rr); 529eda14cbcSMatt Macy break; 530eda14cbcSMatt Macy case 3: 5317877fdebSMatt Macy vdev_raidz_generate_parity_pqr(rr); 532eda14cbcSMatt Macy break; 533eda14cbcSMatt Macy default: 534eda14cbcSMatt Macy cmn_err(CE_PANIC, "invalid RAID-Z configuration"); 535eda14cbcSMatt Macy } 536eda14cbcSMatt Macy } 537eda14cbcSMatt Macy 5387877fdebSMatt Macy void 5397877fdebSMatt Macy vdev_raidz_generate_parity(raidz_map_t *rm) 5407877fdebSMatt Macy { 5417877fdebSMatt Macy for (int i = 0; i < rm->rm_nrows; i++) { 5427877fdebSMatt Macy raidz_row_t *rr = rm->rm_row[i]; 5437877fdebSMatt Macy vdev_raidz_generate_parity_row(rm, rr); 5447877fdebSMatt Macy } 5457877fdebSMatt Macy } 5467877fdebSMatt Macy 547eda14cbcSMatt Macy /* ARGSUSED */ 548eda14cbcSMatt Macy static int 549eda14cbcSMatt Macy vdev_raidz_reconst_p_func(void *dbuf, void *sbuf, size_t size, void *private) 550eda14cbcSMatt Macy { 551eda14cbcSMatt Macy uint64_t *dst = dbuf; 552eda14cbcSMatt Macy uint64_t *src = sbuf; 553eda14cbcSMatt Macy int cnt = size / sizeof (src[0]); 554eda14cbcSMatt Macy 555eda14cbcSMatt Macy for (int i = 0; i < cnt; i++) { 556eda14cbcSMatt Macy dst[i] ^= src[i]; 557eda14cbcSMatt Macy } 558eda14cbcSMatt Macy 559eda14cbcSMatt Macy return (0); 560eda14cbcSMatt Macy } 561eda14cbcSMatt Macy 562eda14cbcSMatt Macy /* ARGSUSED */ 563eda14cbcSMatt Macy static int 564eda14cbcSMatt Macy vdev_raidz_reconst_q_pre_func(void *dbuf, void *sbuf, size_t size, 565eda14cbcSMatt Macy void *private) 566eda14cbcSMatt Macy { 567eda14cbcSMatt Macy uint64_t *dst = dbuf; 568eda14cbcSMatt Macy uint64_t *src = sbuf; 569eda14cbcSMatt Macy uint64_t mask; 570eda14cbcSMatt Macy int cnt = size / sizeof (dst[0]); 571eda14cbcSMatt Macy 572eda14cbcSMatt Macy for (int i = 0; i < cnt; i++, dst++, src++) { 573eda14cbcSMatt Macy VDEV_RAIDZ_64MUL_2(*dst, mask); 574eda14cbcSMatt Macy *dst ^= *src; 575eda14cbcSMatt Macy } 576eda14cbcSMatt Macy 577eda14cbcSMatt Macy return (0); 578eda14cbcSMatt Macy } 579eda14cbcSMatt Macy 580eda14cbcSMatt Macy /* ARGSUSED */ 581eda14cbcSMatt Macy static int 582eda14cbcSMatt Macy vdev_raidz_reconst_q_pre_tail_func(void *buf, size_t size, void *private) 583eda14cbcSMatt Macy { 584eda14cbcSMatt Macy uint64_t *dst = buf; 585eda14cbcSMatt Macy uint64_t mask; 586eda14cbcSMatt Macy int cnt = size / sizeof (dst[0]); 587eda14cbcSMatt Macy 588eda14cbcSMatt Macy for (int i = 0; i < cnt; i++, dst++) { 589eda14cbcSMatt Macy /* same operation as vdev_raidz_reconst_q_pre_func() on dst */ 590eda14cbcSMatt Macy VDEV_RAIDZ_64MUL_2(*dst, mask); 591eda14cbcSMatt Macy } 592eda14cbcSMatt Macy 593eda14cbcSMatt Macy return (0); 594eda14cbcSMatt Macy } 595eda14cbcSMatt Macy 596eda14cbcSMatt Macy struct reconst_q_struct { 597eda14cbcSMatt Macy uint64_t *q; 598eda14cbcSMatt Macy int exp; 599eda14cbcSMatt Macy }; 600eda14cbcSMatt Macy 601eda14cbcSMatt Macy static int 602eda14cbcSMatt Macy vdev_raidz_reconst_q_post_func(void *buf, size_t size, void *private) 603eda14cbcSMatt Macy { 604eda14cbcSMatt Macy struct reconst_q_struct *rq = private; 605eda14cbcSMatt Macy uint64_t *dst = buf; 606eda14cbcSMatt Macy int cnt = size / sizeof (dst[0]); 607eda14cbcSMatt Macy 608eda14cbcSMatt Macy for (int i = 0; i < cnt; i++, dst++, rq->q++) { 609eda14cbcSMatt Macy int j; 610eda14cbcSMatt Macy uint8_t *b; 611eda14cbcSMatt Macy 612eda14cbcSMatt Macy *dst ^= *rq->q; 613eda14cbcSMatt Macy for (j = 0, b = (uint8_t *)dst; j < 8; j++, b++) { 614eda14cbcSMatt Macy *b = vdev_raidz_exp2(*b, rq->exp); 615eda14cbcSMatt Macy } 616eda14cbcSMatt Macy } 617eda14cbcSMatt Macy 618eda14cbcSMatt Macy return (0); 619eda14cbcSMatt Macy } 620eda14cbcSMatt Macy 621eda14cbcSMatt Macy struct reconst_pq_struct { 622eda14cbcSMatt Macy uint8_t *p; 623eda14cbcSMatt Macy uint8_t *q; 624eda14cbcSMatt Macy uint8_t *pxy; 625eda14cbcSMatt Macy uint8_t *qxy; 626eda14cbcSMatt Macy int aexp; 627eda14cbcSMatt Macy int bexp; 628eda14cbcSMatt Macy }; 629eda14cbcSMatt Macy 630eda14cbcSMatt Macy static int 631eda14cbcSMatt Macy vdev_raidz_reconst_pq_func(void *xbuf, void *ybuf, size_t size, void *private) 632eda14cbcSMatt Macy { 633eda14cbcSMatt Macy struct reconst_pq_struct *rpq = private; 634eda14cbcSMatt Macy uint8_t *xd = xbuf; 635eda14cbcSMatt Macy uint8_t *yd = ybuf; 636eda14cbcSMatt Macy 637eda14cbcSMatt Macy for (int i = 0; i < size; 638eda14cbcSMatt Macy i++, rpq->p++, rpq->q++, rpq->pxy++, rpq->qxy++, xd++, yd++) { 639eda14cbcSMatt Macy *xd = vdev_raidz_exp2(*rpq->p ^ *rpq->pxy, rpq->aexp) ^ 640eda14cbcSMatt Macy vdev_raidz_exp2(*rpq->q ^ *rpq->qxy, rpq->bexp); 641eda14cbcSMatt Macy *yd = *rpq->p ^ *rpq->pxy ^ *xd; 642eda14cbcSMatt Macy } 643eda14cbcSMatt Macy 644eda14cbcSMatt Macy return (0); 645eda14cbcSMatt Macy } 646eda14cbcSMatt Macy 647eda14cbcSMatt Macy static int 648eda14cbcSMatt Macy vdev_raidz_reconst_pq_tail_func(void *xbuf, size_t size, void *private) 649eda14cbcSMatt Macy { 650eda14cbcSMatt Macy struct reconst_pq_struct *rpq = private; 651eda14cbcSMatt Macy uint8_t *xd = xbuf; 652eda14cbcSMatt Macy 653eda14cbcSMatt Macy for (int i = 0; i < size; 654eda14cbcSMatt Macy i++, rpq->p++, rpq->q++, rpq->pxy++, rpq->qxy++, xd++) { 655eda14cbcSMatt Macy /* same operation as vdev_raidz_reconst_pq_func() on xd */ 656eda14cbcSMatt Macy *xd = vdev_raidz_exp2(*rpq->p ^ *rpq->pxy, rpq->aexp) ^ 657eda14cbcSMatt Macy vdev_raidz_exp2(*rpq->q ^ *rpq->qxy, rpq->bexp); 658eda14cbcSMatt Macy } 659eda14cbcSMatt Macy 660eda14cbcSMatt Macy return (0); 661eda14cbcSMatt Macy } 662eda14cbcSMatt Macy 663*f9693befSMartin Matuska static void 6647877fdebSMatt Macy vdev_raidz_reconstruct_p(raidz_row_t *rr, int *tgts, int ntgts) 665eda14cbcSMatt Macy { 666eda14cbcSMatt Macy int x = tgts[0]; 667eda14cbcSMatt Macy abd_t *dst, *src; 668eda14cbcSMatt Macy 6697877fdebSMatt Macy ASSERT3U(ntgts, ==, 1); 6707877fdebSMatt Macy ASSERT3U(x, >=, rr->rr_firstdatacol); 6717877fdebSMatt Macy ASSERT3U(x, <, rr->rr_cols); 672eda14cbcSMatt Macy 6737877fdebSMatt Macy ASSERT3U(rr->rr_col[x].rc_size, <=, rr->rr_col[VDEV_RAIDZ_P].rc_size); 674eda14cbcSMatt Macy 6757877fdebSMatt Macy src = rr->rr_col[VDEV_RAIDZ_P].rc_abd; 6767877fdebSMatt Macy dst = rr->rr_col[x].rc_abd; 677eda14cbcSMatt Macy 6787877fdebSMatt Macy abd_copy_from_buf(dst, abd_to_buf(src), rr->rr_col[x].rc_size); 679eda14cbcSMatt Macy 6807877fdebSMatt Macy for (int c = rr->rr_firstdatacol; c < rr->rr_cols; c++) { 6817877fdebSMatt Macy uint64_t size = MIN(rr->rr_col[x].rc_size, 6827877fdebSMatt Macy rr->rr_col[c].rc_size); 683eda14cbcSMatt Macy 6847877fdebSMatt Macy src = rr->rr_col[c].rc_abd; 685eda14cbcSMatt Macy 686eda14cbcSMatt Macy if (c == x) 687eda14cbcSMatt Macy continue; 688eda14cbcSMatt Macy 689eda14cbcSMatt Macy (void) abd_iterate_func2(dst, src, 0, 0, size, 690eda14cbcSMatt Macy vdev_raidz_reconst_p_func, NULL); 691eda14cbcSMatt Macy } 692eda14cbcSMatt Macy } 693eda14cbcSMatt Macy 694*f9693befSMartin Matuska static void 6957877fdebSMatt Macy vdev_raidz_reconstruct_q(raidz_row_t *rr, int *tgts, int ntgts) 696eda14cbcSMatt Macy { 697eda14cbcSMatt Macy int x = tgts[0]; 698eda14cbcSMatt Macy int c, exp; 699eda14cbcSMatt Macy abd_t *dst, *src; 700eda14cbcSMatt Macy 701eda14cbcSMatt Macy ASSERT(ntgts == 1); 702eda14cbcSMatt Macy 7037877fdebSMatt Macy ASSERT(rr->rr_col[x].rc_size <= rr->rr_col[VDEV_RAIDZ_Q].rc_size); 704eda14cbcSMatt Macy 7057877fdebSMatt Macy for (c = rr->rr_firstdatacol; c < rr->rr_cols; c++) { 7067877fdebSMatt Macy uint64_t size = (c == x) ? 0 : MIN(rr->rr_col[x].rc_size, 7077877fdebSMatt Macy rr->rr_col[c].rc_size); 708eda14cbcSMatt Macy 7097877fdebSMatt Macy src = rr->rr_col[c].rc_abd; 7107877fdebSMatt Macy dst = rr->rr_col[x].rc_abd; 711eda14cbcSMatt Macy 7127877fdebSMatt Macy if (c == rr->rr_firstdatacol) { 713eda14cbcSMatt Macy abd_copy(dst, src, size); 7147877fdebSMatt Macy if (rr->rr_col[x].rc_size > size) { 715eda14cbcSMatt Macy abd_zero_off(dst, size, 7167877fdebSMatt Macy rr->rr_col[x].rc_size - size); 7177877fdebSMatt Macy } 718eda14cbcSMatt Macy } else { 7197877fdebSMatt Macy ASSERT3U(size, <=, rr->rr_col[x].rc_size); 720eda14cbcSMatt Macy (void) abd_iterate_func2(dst, src, 0, 0, size, 721eda14cbcSMatt Macy vdev_raidz_reconst_q_pre_func, NULL); 722eda14cbcSMatt Macy (void) abd_iterate_func(dst, 7237877fdebSMatt Macy size, rr->rr_col[x].rc_size - size, 724eda14cbcSMatt Macy vdev_raidz_reconst_q_pre_tail_func, NULL); 725eda14cbcSMatt Macy } 726eda14cbcSMatt Macy } 727eda14cbcSMatt Macy 7287877fdebSMatt Macy src = rr->rr_col[VDEV_RAIDZ_Q].rc_abd; 7297877fdebSMatt Macy dst = rr->rr_col[x].rc_abd; 7307877fdebSMatt Macy exp = 255 - (rr->rr_cols - 1 - x); 731eda14cbcSMatt Macy 732eda14cbcSMatt Macy struct reconst_q_struct rq = { abd_to_buf(src), exp }; 7337877fdebSMatt Macy (void) abd_iterate_func(dst, 0, rr->rr_col[x].rc_size, 734eda14cbcSMatt Macy vdev_raidz_reconst_q_post_func, &rq); 735eda14cbcSMatt Macy } 736eda14cbcSMatt Macy 737*f9693befSMartin Matuska static void 7387877fdebSMatt Macy vdev_raidz_reconstruct_pq(raidz_row_t *rr, int *tgts, int ntgts) 739eda14cbcSMatt Macy { 740eda14cbcSMatt Macy uint8_t *p, *q, *pxy, *qxy, tmp, a, b, aexp, bexp; 741eda14cbcSMatt Macy abd_t *pdata, *qdata; 742eda14cbcSMatt Macy uint64_t xsize, ysize; 743eda14cbcSMatt Macy int x = tgts[0]; 744eda14cbcSMatt Macy int y = tgts[1]; 745eda14cbcSMatt Macy abd_t *xd, *yd; 746eda14cbcSMatt Macy 747eda14cbcSMatt Macy ASSERT(ntgts == 2); 748eda14cbcSMatt Macy ASSERT(x < y); 7497877fdebSMatt Macy ASSERT(x >= rr->rr_firstdatacol); 7507877fdebSMatt Macy ASSERT(y < rr->rr_cols); 751eda14cbcSMatt Macy 7527877fdebSMatt Macy ASSERT(rr->rr_col[x].rc_size >= rr->rr_col[y].rc_size); 753eda14cbcSMatt Macy 754eda14cbcSMatt Macy /* 755eda14cbcSMatt Macy * Move the parity data aside -- we're going to compute parity as 756eda14cbcSMatt Macy * though columns x and y were full of zeros -- Pxy and Qxy. We want to 757eda14cbcSMatt Macy * reuse the parity generation mechanism without trashing the actual 758eda14cbcSMatt Macy * parity so we make those columns appear to be full of zeros by 759eda14cbcSMatt Macy * setting their lengths to zero. 760eda14cbcSMatt Macy */ 7617877fdebSMatt Macy pdata = rr->rr_col[VDEV_RAIDZ_P].rc_abd; 7627877fdebSMatt Macy qdata = rr->rr_col[VDEV_RAIDZ_Q].rc_abd; 7637877fdebSMatt Macy xsize = rr->rr_col[x].rc_size; 7647877fdebSMatt Macy ysize = rr->rr_col[y].rc_size; 765eda14cbcSMatt Macy 7667877fdebSMatt Macy rr->rr_col[VDEV_RAIDZ_P].rc_abd = 7677877fdebSMatt Macy abd_alloc_linear(rr->rr_col[VDEV_RAIDZ_P].rc_size, B_TRUE); 7687877fdebSMatt Macy rr->rr_col[VDEV_RAIDZ_Q].rc_abd = 7697877fdebSMatt Macy abd_alloc_linear(rr->rr_col[VDEV_RAIDZ_Q].rc_size, B_TRUE); 7707877fdebSMatt Macy rr->rr_col[x].rc_size = 0; 7717877fdebSMatt Macy rr->rr_col[y].rc_size = 0; 772eda14cbcSMatt Macy 7737877fdebSMatt Macy vdev_raidz_generate_parity_pq(rr); 774eda14cbcSMatt Macy 7757877fdebSMatt Macy rr->rr_col[x].rc_size = xsize; 7767877fdebSMatt Macy rr->rr_col[y].rc_size = ysize; 777eda14cbcSMatt Macy 778eda14cbcSMatt Macy p = abd_to_buf(pdata); 779eda14cbcSMatt Macy q = abd_to_buf(qdata); 7807877fdebSMatt Macy pxy = abd_to_buf(rr->rr_col[VDEV_RAIDZ_P].rc_abd); 7817877fdebSMatt Macy qxy = abd_to_buf(rr->rr_col[VDEV_RAIDZ_Q].rc_abd); 7827877fdebSMatt Macy xd = rr->rr_col[x].rc_abd; 7837877fdebSMatt Macy yd = rr->rr_col[y].rc_abd; 784eda14cbcSMatt Macy 785eda14cbcSMatt Macy /* 786eda14cbcSMatt Macy * We now have: 787eda14cbcSMatt Macy * Pxy = P + D_x + D_y 788eda14cbcSMatt Macy * Qxy = Q + 2^(ndevs - 1 - x) * D_x + 2^(ndevs - 1 - y) * D_y 789eda14cbcSMatt Macy * 790eda14cbcSMatt Macy * We can then solve for D_x: 791eda14cbcSMatt Macy * D_x = A * (P + Pxy) + B * (Q + Qxy) 792eda14cbcSMatt Macy * where 793eda14cbcSMatt Macy * A = 2^(x - y) * (2^(x - y) + 1)^-1 794eda14cbcSMatt Macy * B = 2^(ndevs - 1 - x) * (2^(x - y) + 1)^-1 795eda14cbcSMatt Macy * 796eda14cbcSMatt Macy * With D_x in hand, we can easily solve for D_y: 797eda14cbcSMatt Macy * D_y = P + Pxy + D_x 798eda14cbcSMatt Macy */ 799eda14cbcSMatt Macy 800eda14cbcSMatt Macy a = vdev_raidz_pow2[255 + x - y]; 8017877fdebSMatt Macy b = vdev_raidz_pow2[255 - (rr->rr_cols - 1 - x)]; 802eda14cbcSMatt Macy tmp = 255 - vdev_raidz_log2[a ^ 1]; 803eda14cbcSMatt Macy 804eda14cbcSMatt Macy aexp = vdev_raidz_log2[vdev_raidz_exp2(a, tmp)]; 805eda14cbcSMatt Macy bexp = vdev_raidz_log2[vdev_raidz_exp2(b, tmp)]; 806eda14cbcSMatt Macy 807eda14cbcSMatt Macy ASSERT3U(xsize, >=, ysize); 808eda14cbcSMatt Macy struct reconst_pq_struct rpq = { p, q, pxy, qxy, aexp, bexp }; 809eda14cbcSMatt Macy 810eda14cbcSMatt Macy (void) abd_iterate_func2(xd, yd, 0, 0, ysize, 811eda14cbcSMatt Macy vdev_raidz_reconst_pq_func, &rpq); 812eda14cbcSMatt Macy (void) abd_iterate_func(xd, ysize, xsize - ysize, 813eda14cbcSMatt Macy vdev_raidz_reconst_pq_tail_func, &rpq); 814eda14cbcSMatt Macy 8157877fdebSMatt Macy abd_free(rr->rr_col[VDEV_RAIDZ_P].rc_abd); 8167877fdebSMatt Macy abd_free(rr->rr_col[VDEV_RAIDZ_Q].rc_abd); 817eda14cbcSMatt Macy 818eda14cbcSMatt Macy /* 819eda14cbcSMatt Macy * Restore the saved parity data. 820eda14cbcSMatt Macy */ 8217877fdebSMatt Macy rr->rr_col[VDEV_RAIDZ_P].rc_abd = pdata; 8227877fdebSMatt Macy rr->rr_col[VDEV_RAIDZ_Q].rc_abd = qdata; 823eda14cbcSMatt Macy } 824eda14cbcSMatt Macy 825eda14cbcSMatt Macy /* BEGIN CSTYLED */ 826eda14cbcSMatt Macy /* 827eda14cbcSMatt Macy * In the general case of reconstruction, we must solve the system of linear 828eda14cbcSMatt Macy * equations defined by the coefficients used to generate parity as well as 829eda14cbcSMatt Macy * the contents of the data and parity disks. This can be expressed with 830eda14cbcSMatt Macy * vectors for the original data (D) and the actual data (d) and parity (p) 831eda14cbcSMatt Macy * and a matrix composed of the identity matrix (I) and a dispersal matrix (V): 832eda14cbcSMatt Macy * 833eda14cbcSMatt Macy * __ __ __ __ 834eda14cbcSMatt Macy * | | __ __ | p_0 | 835eda14cbcSMatt Macy * | V | | D_0 | | p_m-1 | 836eda14cbcSMatt Macy * | | x | : | = | d_0 | 837eda14cbcSMatt Macy * | I | | D_n-1 | | : | 838eda14cbcSMatt Macy * | | ~~ ~~ | d_n-1 | 839eda14cbcSMatt Macy * ~~ ~~ ~~ ~~ 840eda14cbcSMatt Macy * 841eda14cbcSMatt Macy * I is simply a square identity matrix of size n, and V is a vandermonde 842eda14cbcSMatt Macy * matrix defined by the coefficients we chose for the various parity columns 843eda14cbcSMatt Macy * (1, 2, 4). Note that these values were chosen both for simplicity, speedy 844eda14cbcSMatt Macy * computation as well as linear separability. 845eda14cbcSMatt Macy * 846eda14cbcSMatt Macy * __ __ __ __ 847eda14cbcSMatt Macy * | 1 .. 1 1 1 | | p_0 | 848eda14cbcSMatt Macy * | 2^n-1 .. 4 2 1 | __ __ | : | 849eda14cbcSMatt Macy * | 4^n-1 .. 16 4 1 | | D_0 | | p_m-1 | 850eda14cbcSMatt Macy * | 1 .. 0 0 0 | | D_1 | | d_0 | 851eda14cbcSMatt Macy * | 0 .. 0 0 0 | x | D_2 | = | d_1 | 852eda14cbcSMatt Macy * | : : : : | | : | | d_2 | 853eda14cbcSMatt Macy * | 0 .. 1 0 0 | | D_n-1 | | : | 854eda14cbcSMatt Macy * | 0 .. 0 1 0 | ~~ ~~ | : | 855eda14cbcSMatt Macy * | 0 .. 0 0 1 | | d_n-1 | 856eda14cbcSMatt Macy * ~~ ~~ ~~ ~~ 857eda14cbcSMatt Macy * 858eda14cbcSMatt Macy * Note that I, V, d, and p are known. To compute D, we must invert the 859eda14cbcSMatt Macy * matrix and use the known data and parity values to reconstruct the unknown 860eda14cbcSMatt Macy * data values. We begin by removing the rows in V|I and d|p that correspond 861eda14cbcSMatt Macy * to failed or missing columns; we then make V|I square (n x n) and d|p 862eda14cbcSMatt Macy * sized n by removing rows corresponding to unused parity from the bottom up 863eda14cbcSMatt Macy * to generate (V|I)' and (d|p)'. We can then generate the inverse of (V|I)' 864eda14cbcSMatt Macy * using Gauss-Jordan elimination. In the example below we use m=3 parity 865eda14cbcSMatt Macy * columns, n=8 data columns, with errors in d_1, d_2, and p_1: 866eda14cbcSMatt Macy * __ __ 867eda14cbcSMatt Macy * | 1 1 1 1 1 1 1 1 | 868eda14cbcSMatt Macy * | 128 64 32 16 8 4 2 1 | <-----+-+-- missing disks 869eda14cbcSMatt Macy * | 19 205 116 29 64 16 4 1 | / / 870eda14cbcSMatt Macy * | 1 0 0 0 0 0 0 0 | / / 871eda14cbcSMatt Macy * | 0 1 0 0 0 0 0 0 | <--' / 872eda14cbcSMatt Macy * (V|I) = | 0 0 1 0 0 0 0 0 | <---' 873eda14cbcSMatt Macy * | 0 0 0 1 0 0 0 0 | 874eda14cbcSMatt Macy * | 0 0 0 0 1 0 0 0 | 875eda14cbcSMatt Macy * | 0 0 0 0 0 1 0 0 | 876eda14cbcSMatt Macy * | 0 0 0 0 0 0 1 0 | 877eda14cbcSMatt Macy * | 0 0 0 0 0 0 0 1 | 878eda14cbcSMatt Macy * ~~ ~~ 879eda14cbcSMatt Macy * __ __ 880eda14cbcSMatt Macy * | 1 1 1 1 1 1 1 1 | 881eda14cbcSMatt Macy * | 128 64 32 16 8 4 2 1 | 882eda14cbcSMatt Macy * | 19 205 116 29 64 16 4 1 | 883eda14cbcSMatt Macy * | 1 0 0 0 0 0 0 0 | 884eda14cbcSMatt Macy * | 0 1 0 0 0 0 0 0 | 885eda14cbcSMatt Macy * (V|I)' = | 0 0 1 0 0 0 0 0 | 886eda14cbcSMatt Macy * | 0 0 0 1 0 0 0 0 | 887eda14cbcSMatt Macy * | 0 0 0 0 1 0 0 0 | 888eda14cbcSMatt Macy * | 0 0 0 0 0 1 0 0 | 889eda14cbcSMatt Macy * | 0 0 0 0 0 0 1 0 | 890eda14cbcSMatt Macy * | 0 0 0 0 0 0 0 1 | 891eda14cbcSMatt Macy * ~~ ~~ 892eda14cbcSMatt Macy * 893eda14cbcSMatt Macy * Here we employ Gauss-Jordan elimination to find the inverse of (V|I)'. We 894eda14cbcSMatt Macy * have carefully chosen the seed values 1, 2, and 4 to ensure that this 895eda14cbcSMatt Macy * matrix is not singular. 896eda14cbcSMatt Macy * __ __ 897eda14cbcSMatt Macy * | 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 | 898eda14cbcSMatt Macy * | 19 205 116 29 64 16 4 1 0 1 0 0 0 0 0 0 | 899eda14cbcSMatt Macy * | 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 | 900eda14cbcSMatt Macy * | 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 | 901eda14cbcSMatt Macy * | 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 | 902eda14cbcSMatt Macy * | 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 | 903eda14cbcSMatt Macy * | 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 | 904eda14cbcSMatt Macy * | 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 | 905eda14cbcSMatt Macy * ~~ ~~ 906eda14cbcSMatt Macy * __ __ 907eda14cbcSMatt Macy * | 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 | 908eda14cbcSMatt Macy * | 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 | 909eda14cbcSMatt Macy * | 19 205 116 29 64 16 4 1 0 1 0 0 0 0 0 0 | 910eda14cbcSMatt Macy * | 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 | 911eda14cbcSMatt Macy * | 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 | 912eda14cbcSMatt Macy * | 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 | 913eda14cbcSMatt Macy * | 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 | 914eda14cbcSMatt Macy * | 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 | 915eda14cbcSMatt Macy * ~~ ~~ 916eda14cbcSMatt Macy * __ __ 917eda14cbcSMatt Macy * | 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 | 918eda14cbcSMatt Macy * | 0 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 | 919eda14cbcSMatt Macy * | 0 205 116 0 0 0 0 0 0 1 19 29 64 16 4 1 | 920eda14cbcSMatt Macy * | 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 | 921eda14cbcSMatt Macy * | 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 | 922eda14cbcSMatt Macy * | 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 | 923eda14cbcSMatt Macy * | 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 | 924eda14cbcSMatt Macy * | 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 | 925eda14cbcSMatt Macy * ~~ ~~ 926eda14cbcSMatt Macy * __ __ 927eda14cbcSMatt Macy * | 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 | 928eda14cbcSMatt Macy * | 0 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 | 929eda14cbcSMatt Macy * | 0 0 185 0 0 0 0 0 205 1 222 208 141 221 201 204 | 930eda14cbcSMatt Macy * | 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 | 931eda14cbcSMatt Macy * | 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 | 932eda14cbcSMatt Macy * | 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 | 933eda14cbcSMatt Macy * | 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 | 934eda14cbcSMatt Macy * | 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 | 935eda14cbcSMatt Macy * ~~ ~~ 936eda14cbcSMatt Macy * __ __ 937eda14cbcSMatt Macy * | 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 | 938eda14cbcSMatt Macy * | 0 1 1 0 0 0 0 0 1 0 1 1 1 1 1 1 | 939eda14cbcSMatt Macy * | 0 0 1 0 0 0 0 0 166 100 4 40 158 168 216 209 | 940eda14cbcSMatt Macy * | 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 | 941eda14cbcSMatt Macy * | 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 | 942eda14cbcSMatt Macy * | 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 | 943eda14cbcSMatt Macy * | 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 | 944eda14cbcSMatt Macy * | 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 | 945eda14cbcSMatt Macy * ~~ ~~ 946eda14cbcSMatt Macy * __ __ 947eda14cbcSMatt Macy * | 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 | 948eda14cbcSMatt Macy * | 0 1 0 0 0 0 0 0 167 100 5 41 159 169 217 208 | 949eda14cbcSMatt Macy * | 0 0 1 0 0 0 0 0 166 100 4 40 158 168 216 209 | 950eda14cbcSMatt Macy * | 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 | 951eda14cbcSMatt Macy * | 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 | 952eda14cbcSMatt Macy * | 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 0 | 953eda14cbcSMatt Macy * | 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 0 | 954eda14cbcSMatt Macy * | 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 | 955eda14cbcSMatt Macy * ~~ ~~ 956eda14cbcSMatt Macy * __ __ 957eda14cbcSMatt Macy * | 0 0 1 0 0 0 0 0 | 958eda14cbcSMatt Macy * | 167 100 5 41 159 169 217 208 | 959eda14cbcSMatt Macy * | 166 100 4 40 158 168 216 209 | 960eda14cbcSMatt Macy * (V|I)'^-1 = | 0 0 0 1 0 0 0 0 | 961eda14cbcSMatt Macy * | 0 0 0 0 1 0 0 0 | 962eda14cbcSMatt Macy * | 0 0 0 0 0 1 0 0 | 963eda14cbcSMatt Macy * | 0 0 0 0 0 0 1 0 | 964eda14cbcSMatt Macy * | 0 0 0 0 0 0 0 1 | 965eda14cbcSMatt Macy * ~~ ~~ 966eda14cbcSMatt Macy * 967eda14cbcSMatt Macy * We can then simply compute D = (V|I)'^-1 x (d|p)' to discover the values 968eda14cbcSMatt Macy * of the missing data. 969eda14cbcSMatt Macy * 970eda14cbcSMatt Macy * As is apparent from the example above, the only non-trivial rows in the 971eda14cbcSMatt Macy * inverse matrix correspond to the data disks that we're trying to 972eda14cbcSMatt Macy * reconstruct. Indeed, those are the only rows we need as the others would 973eda14cbcSMatt Macy * only be useful for reconstructing data known or assumed to be valid. For 974eda14cbcSMatt Macy * that reason, we only build the coefficients in the rows that correspond to 975eda14cbcSMatt Macy * targeted columns. 976eda14cbcSMatt Macy */ 977eda14cbcSMatt Macy /* END CSTYLED */ 978eda14cbcSMatt Macy 979eda14cbcSMatt Macy static void 9807877fdebSMatt Macy vdev_raidz_matrix_init(raidz_row_t *rr, int n, int nmap, int *map, 981eda14cbcSMatt Macy uint8_t **rows) 982eda14cbcSMatt Macy { 983eda14cbcSMatt Macy int i, j; 984eda14cbcSMatt Macy int pow; 985eda14cbcSMatt Macy 9867877fdebSMatt Macy ASSERT(n == rr->rr_cols - rr->rr_firstdatacol); 987eda14cbcSMatt Macy 988eda14cbcSMatt Macy /* 989eda14cbcSMatt Macy * Fill in the missing rows of interest. 990eda14cbcSMatt Macy */ 991eda14cbcSMatt Macy for (i = 0; i < nmap; i++) { 992eda14cbcSMatt Macy ASSERT3S(0, <=, map[i]); 993eda14cbcSMatt Macy ASSERT3S(map[i], <=, 2); 994eda14cbcSMatt Macy 995eda14cbcSMatt Macy pow = map[i] * n; 996eda14cbcSMatt Macy if (pow > 255) 997eda14cbcSMatt Macy pow -= 255; 998eda14cbcSMatt Macy ASSERT(pow <= 255); 999eda14cbcSMatt Macy 1000eda14cbcSMatt Macy for (j = 0; j < n; j++) { 1001eda14cbcSMatt Macy pow -= map[i]; 1002eda14cbcSMatt Macy if (pow < 0) 1003eda14cbcSMatt Macy pow += 255; 1004eda14cbcSMatt Macy rows[i][j] = vdev_raidz_pow2[pow]; 1005eda14cbcSMatt Macy } 1006eda14cbcSMatt Macy } 1007eda14cbcSMatt Macy } 1008eda14cbcSMatt Macy 1009eda14cbcSMatt Macy static void 10107877fdebSMatt Macy vdev_raidz_matrix_invert(raidz_row_t *rr, int n, int nmissing, int *missing, 1011eda14cbcSMatt Macy uint8_t **rows, uint8_t **invrows, const uint8_t *used) 1012eda14cbcSMatt Macy { 1013eda14cbcSMatt Macy int i, j, ii, jj; 1014eda14cbcSMatt Macy uint8_t log; 1015eda14cbcSMatt Macy 1016eda14cbcSMatt Macy /* 1017eda14cbcSMatt Macy * Assert that the first nmissing entries from the array of used 1018eda14cbcSMatt Macy * columns correspond to parity columns and that subsequent entries 1019eda14cbcSMatt Macy * correspond to data columns. 1020eda14cbcSMatt Macy */ 1021eda14cbcSMatt Macy for (i = 0; i < nmissing; i++) { 10227877fdebSMatt Macy ASSERT3S(used[i], <, rr->rr_firstdatacol); 1023eda14cbcSMatt Macy } 1024eda14cbcSMatt Macy for (; i < n; i++) { 10257877fdebSMatt Macy ASSERT3S(used[i], >=, rr->rr_firstdatacol); 1026eda14cbcSMatt Macy } 1027eda14cbcSMatt Macy 1028eda14cbcSMatt Macy /* 1029eda14cbcSMatt Macy * First initialize the storage where we'll compute the inverse rows. 1030eda14cbcSMatt Macy */ 1031eda14cbcSMatt Macy for (i = 0; i < nmissing; i++) { 1032eda14cbcSMatt Macy for (j = 0; j < n; j++) { 1033eda14cbcSMatt Macy invrows[i][j] = (i == j) ? 1 : 0; 1034eda14cbcSMatt Macy } 1035eda14cbcSMatt Macy } 1036eda14cbcSMatt Macy 1037eda14cbcSMatt Macy /* 1038eda14cbcSMatt Macy * Subtract all trivial rows from the rows of consequence. 1039eda14cbcSMatt Macy */ 1040eda14cbcSMatt Macy for (i = 0; i < nmissing; i++) { 1041eda14cbcSMatt Macy for (j = nmissing; j < n; j++) { 10427877fdebSMatt Macy ASSERT3U(used[j], >=, rr->rr_firstdatacol); 10437877fdebSMatt Macy jj = used[j] - rr->rr_firstdatacol; 1044eda14cbcSMatt Macy ASSERT3S(jj, <, n); 1045eda14cbcSMatt Macy invrows[i][j] = rows[i][jj]; 1046eda14cbcSMatt Macy rows[i][jj] = 0; 1047eda14cbcSMatt Macy } 1048eda14cbcSMatt Macy } 1049eda14cbcSMatt Macy 1050eda14cbcSMatt Macy /* 1051eda14cbcSMatt Macy * For each of the rows of interest, we must normalize it and subtract 1052eda14cbcSMatt Macy * a multiple of it from the other rows. 1053eda14cbcSMatt Macy */ 1054eda14cbcSMatt Macy for (i = 0; i < nmissing; i++) { 1055eda14cbcSMatt Macy for (j = 0; j < missing[i]; j++) { 1056eda14cbcSMatt Macy ASSERT0(rows[i][j]); 1057eda14cbcSMatt Macy } 1058eda14cbcSMatt Macy ASSERT3U(rows[i][missing[i]], !=, 0); 1059eda14cbcSMatt Macy 1060eda14cbcSMatt Macy /* 1061eda14cbcSMatt Macy * Compute the inverse of the first element and multiply each 1062eda14cbcSMatt Macy * element in the row by that value. 1063eda14cbcSMatt Macy */ 1064eda14cbcSMatt Macy log = 255 - vdev_raidz_log2[rows[i][missing[i]]]; 1065eda14cbcSMatt Macy 1066eda14cbcSMatt Macy for (j = 0; j < n; j++) { 1067eda14cbcSMatt Macy rows[i][j] = vdev_raidz_exp2(rows[i][j], log); 1068eda14cbcSMatt Macy invrows[i][j] = vdev_raidz_exp2(invrows[i][j], log); 1069eda14cbcSMatt Macy } 1070eda14cbcSMatt Macy 1071eda14cbcSMatt Macy for (ii = 0; ii < nmissing; ii++) { 1072eda14cbcSMatt Macy if (i == ii) 1073eda14cbcSMatt Macy continue; 1074eda14cbcSMatt Macy 1075eda14cbcSMatt Macy ASSERT3U(rows[ii][missing[i]], !=, 0); 1076eda14cbcSMatt Macy 1077eda14cbcSMatt Macy log = vdev_raidz_log2[rows[ii][missing[i]]]; 1078eda14cbcSMatt Macy 1079eda14cbcSMatt Macy for (j = 0; j < n; j++) { 1080eda14cbcSMatt Macy rows[ii][j] ^= 1081eda14cbcSMatt Macy vdev_raidz_exp2(rows[i][j], log); 1082eda14cbcSMatt Macy invrows[ii][j] ^= 1083eda14cbcSMatt Macy vdev_raidz_exp2(invrows[i][j], log); 1084eda14cbcSMatt Macy } 1085eda14cbcSMatt Macy } 1086eda14cbcSMatt Macy } 1087eda14cbcSMatt Macy 1088eda14cbcSMatt Macy /* 1089eda14cbcSMatt Macy * Verify that the data that is left in the rows are properly part of 1090eda14cbcSMatt Macy * an identity matrix. 1091eda14cbcSMatt Macy */ 1092eda14cbcSMatt Macy for (i = 0; i < nmissing; i++) { 1093eda14cbcSMatt Macy for (j = 0; j < n; j++) { 1094eda14cbcSMatt Macy if (j == missing[i]) { 1095eda14cbcSMatt Macy ASSERT3U(rows[i][j], ==, 1); 1096eda14cbcSMatt Macy } else { 1097eda14cbcSMatt Macy ASSERT0(rows[i][j]); 1098eda14cbcSMatt Macy } 1099eda14cbcSMatt Macy } 1100eda14cbcSMatt Macy } 1101eda14cbcSMatt Macy } 1102eda14cbcSMatt Macy 1103eda14cbcSMatt Macy static void 11047877fdebSMatt Macy vdev_raidz_matrix_reconstruct(raidz_row_t *rr, int n, int nmissing, 1105eda14cbcSMatt Macy int *missing, uint8_t **invrows, const uint8_t *used) 1106eda14cbcSMatt Macy { 1107eda14cbcSMatt Macy int i, j, x, cc, c; 1108eda14cbcSMatt Macy uint8_t *src; 1109eda14cbcSMatt Macy uint64_t ccount; 1110eda14cbcSMatt Macy uint8_t *dst[VDEV_RAIDZ_MAXPARITY] = { NULL }; 1111eda14cbcSMatt Macy uint64_t dcount[VDEV_RAIDZ_MAXPARITY] = { 0 }; 1112eda14cbcSMatt Macy uint8_t log = 0; 1113eda14cbcSMatt Macy uint8_t val; 1114eda14cbcSMatt Macy int ll; 1115eda14cbcSMatt Macy uint8_t *invlog[VDEV_RAIDZ_MAXPARITY]; 1116eda14cbcSMatt Macy uint8_t *p, *pp; 1117eda14cbcSMatt Macy size_t psize; 1118eda14cbcSMatt Macy 1119eda14cbcSMatt Macy psize = sizeof (invlog[0][0]) * n * nmissing; 1120eda14cbcSMatt Macy p = kmem_alloc(psize, KM_SLEEP); 1121eda14cbcSMatt Macy 1122eda14cbcSMatt Macy for (pp = p, i = 0; i < nmissing; i++) { 1123eda14cbcSMatt Macy invlog[i] = pp; 1124eda14cbcSMatt Macy pp += n; 1125eda14cbcSMatt Macy } 1126eda14cbcSMatt Macy 1127eda14cbcSMatt Macy for (i = 0; i < nmissing; i++) { 1128eda14cbcSMatt Macy for (j = 0; j < n; j++) { 1129eda14cbcSMatt Macy ASSERT3U(invrows[i][j], !=, 0); 1130eda14cbcSMatt Macy invlog[i][j] = vdev_raidz_log2[invrows[i][j]]; 1131eda14cbcSMatt Macy } 1132eda14cbcSMatt Macy } 1133eda14cbcSMatt Macy 1134eda14cbcSMatt Macy for (i = 0; i < n; i++) { 1135eda14cbcSMatt Macy c = used[i]; 11367877fdebSMatt Macy ASSERT3U(c, <, rr->rr_cols); 1137eda14cbcSMatt Macy 11387877fdebSMatt Macy ccount = rr->rr_col[c].rc_size; 11397877fdebSMatt Macy ASSERT(ccount >= rr->rr_col[missing[0]].rc_size || i > 0); 11407877fdebSMatt Macy if (ccount == 0) 11417877fdebSMatt Macy continue; 11427877fdebSMatt Macy src = abd_to_buf(rr->rr_col[c].rc_abd); 1143eda14cbcSMatt Macy for (j = 0; j < nmissing; j++) { 11447877fdebSMatt Macy cc = missing[j] + rr->rr_firstdatacol; 11457877fdebSMatt Macy ASSERT3U(cc, >=, rr->rr_firstdatacol); 11467877fdebSMatt Macy ASSERT3U(cc, <, rr->rr_cols); 1147eda14cbcSMatt Macy ASSERT3U(cc, !=, c); 1148eda14cbcSMatt Macy 11497877fdebSMatt Macy dcount[j] = rr->rr_col[cc].rc_size; 11507877fdebSMatt Macy if (dcount[j] != 0) 11517877fdebSMatt Macy dst[j] = abd_to_buf(rr->rr_col[cc].rc_abd); 1152eda14cbcSMatt Macy } 1153eda14cbcSMatt Macy 1154eda14cbcSMatt Macy for (x = 0; x < ccount; x++, src++) { 1155eda14cbcSMatt Macy if (*src != 0) 1156eda14cbcSMatt Macy log = vdev_raidz_log2[*src]; 1157eda14cbcSMatt Macy 1158eda14cbcSMatt Macy for (cc = 0; cc < nmissing; cc++) { 1159eda14cbcSMatt Macy if (x >= dcount[cc]) 1160eda14cbcSMatt Macy continue; 1161eda14cbcSMatt Macy 1162eda14cbcSMatt Macy if (*src == 0) { 1163eda14cbcSMatt Macy val = 0; 1164eda14cbcSMatt Macy } else { 1165eda14cbcSMatt Macy if ((ll = log + invlog[cc][i]) >= 255) 1166eda14cbcSMatt Macy ll -= 255; 1167eda14cbcSMatt Macy val = vdev_raidz_pow2[ll]; 1168eda14cbcSMatt Macy } 1169eda14cbcSMatt Macy 1170eda14cbcSMatt Macy if (i == 0) 1171eda14cbcSMatt Macy dst[cc][x] = val; 1172eda14cbcSMatt Macy else 1173eda14cbcSMatt Macy dst[cc][x] ^= val; 1174eda14cbcSMatt Macy } 1175eda14cbcSMatt Macy } 1176eda14cbcSMatt Macy } 1177eda14cbcSMatt Macy 1178eda14cbcSMatt Macy kmem_free(p, psize); 1179eda14cbcSMatt Macy } 1180eda14cbcSMatt Macy 1181*f9693befSMartin Matuska static void 11827877fdebSMatt Macy vdev_raidz_reconstruct_general(raidz_row_t *rr, int *tgts, int ntgts) 1183eda14cbcSMatt Macy { 1184eda14cbcSMatt Macy int n, i, c, t, tt; 1185eda14cbcSMatt Macy int nmissing_rows; 1186eda14cbcSMatt Macy int missing_rows[VDEV_RAIDZ_MAXPARITY]; 1187eda14cbcSMatt Macy int parity_map[VDEV_RAIDZ_MAXPARITY]; 1188eda14cbcSMatt Macy uint8_t *p, *pp; 1189eda14cbcSMatt Macy size_t psize; 1190eda14cbcSMatt Macy uint8_t *rows[VDEV_RAIDZ_MAXPARITY]; 1191eda14cbcSMatt Macy uint8_t *invrows[VDEV_RAIDZ_MAXPARITY]; 1192eda14cbcSMatt Macy uint8_t *used; 1193eda14cbcSMatt Macy 1194eda14cbcSMatt Macy abd_t **bufs = NULL; 1195eda14cbcSMatt Macy 1196eda14cbcSMatt Macy /* 1197eda14cbcSMatt Macy * Matrix reconstruction can't use scatter ABDs yet, so we allocate 11987877fdebSMatt Macy * temporary linear ABDs if any non-linear ABDs are found. 1199eda14cbcSMatt Macy */ 12007877fdebSMatt Macy for (i = rr->rr_firstdatacol; i < rr->rr_cols; i++) { 12017877fdebSMatt Macy if (!abd_is_linear(rr->rr_col[i].rc_abd)) { 12027877fdebSMatt Macy bufs = kmem_alloc(rr->rr_cols * sizeof (abd_t *), 12037877fdebSMatt Macy KM_PUSHPAGE); 1204eda14cbcSMatt Macy 12057877fdebSMatt Macy for (c = rr->rr_firstdatacol; c < rr->rr_cols; c++) { 12067877fdebSMatt Macy raidz_col_t *col = &rr->rr_col[c]; 1207eda14cbcSMatt Macy 1208eda14cbcSMatt Macy bufs[c] = col->rc_abd; 12097877fdebSMatt Macy if (bufs[c] != NULL) { 12107877fdebSMatt Macy col->rc_abd = abd_alloc_linear( 12117877fdebSMatt Macy col->rc_size, B_TRUE); 12127877fdebSMatt Macy abd_copy(col->rc_abd, bufs[c], 12137877fdebSMatt Macy col->rc_size); 1214eda14cbcSMatt Macy } 1215eda14cbcSMatt Macy } 1216eda14cbcSMatt Macy 12177877fdebSMatt Macy break; 12187877fdebSMatt Macy } 12197877fdebSMatt Macy } 12207877fdebSMatt Macy 12217877fdebSMatt Macy n = rr->rr_cols - rr->rr_firstdatacol; 1222eda14cbcSMatt Macy 1223eda14cbcSMatt Macy /* 1224eda14cbcSMatt Macy * Figure out which data columns are missing. 1225eda14cbcSMatt Macy */ 1226eda14cbcSMatt Macy nmissing_rows = 0; 1227eda14cbcSMatt Macy for (t = 0; t < ntgts; t++) { 12287877fdebSMatt Macy if (tgts[t] >= rr->rr_firstdatacol) { 1229eda14cbcSMatt Macy missing_rows[nmissing_rows++] = 12307877fdebSMatt Macy tgts[t] - rr->rr_firstdatacol; 1231eda14cbcSMatt Macy } 1232eda14cbcSMatt Macy } 1233eda14cbcSMatt Macy 1234eda14cbcSMatt Macy /* 1235eda14cbcSMatt Macy * Figure out which parity columns to use to help generate the missing 1236eda14cbcSMatt Macy * data columns. 1237eda14cbcSMatt Macy */ 1238eda14cbcSMatt Macy for (tt = 0, c = 0, i = 0; i < nmissing_rows; c++) { 1239eda14cbcSMatt Macy ASSERT(tt < ntgts); 12407877fdebSMatt Macy ASSERT(c < rr->rr_firstdatacol); 1241eda14cbcSMatt Macy 1242eda14cbcSMatt Macy /* 1243eda14cbcSMatt Macy * Skip any targeted parity columns. 1244eda14cbcSMatt Macy */ 1245eda14cbcSMatt Macy if (c == tgts[tt]) { 1246eda14cbcSMatt Macy tt++; 1247eda14cbcSMatt Macy continue; 1248eda14cbcSMatt Macy } 1249eda14cbcSMatt Macy 1250eda14cbcSMatt Macy parity_map[i] = c; 1251eda14cbcSMatt Macy i++; 1252eda14cbcSMatt Macy } 1253eda14cbcSMatt Macy 1254eda14cbcSMatt Macy psize = (sizeof (rows[0][0]) + sizeof (invrows[0][0])) * 1255eda14cbcSMatt Macy nmissing_rows * n + sizeof (used[0]) * n; 1256eda14cbcSMatt Macy p = kmem_alloc(psize, KM_SLEEP); 1257eda14cbcSMatt Macy 1258eda14cbcSMatt Macy for (pp = p, i = 0; i < nmissing_rows; i++) { 1259eda14cbcSMatt Macy rows[i] = pp; 1260eda14cbcSMatt Macy pp += n; 1261eda14cbcSMatt Macy invrows[i] = pp; 1262eda14cbcSMatt Macy pp += n; 1263eda14cbcSMatt Macy } 1264eda14cbcSMatt Macy used = pp; 1265eda14cbcSMatt Macy 1266eda14cbcSMatt Macy for (i = 0; i < nmissing_rows; i++) { 1267eda14cbcSMatt Macy used[i] = parity_map[i]; 1268eda14cbcSMatt Macy } 1269eda14cbcSMatt Macy 12707877fdebSMatt Macy for (tt = 0, c = rr->rr_firstdatacol; c < rr->rr_cols; c++) { 1271eda14cbcSMatt Macy if (tt < nmissing_rows && 12727877fdebSMatt Macy c == missing_rows[tt] + rr->rr_firstdatacol) { 1273eda14cbcSMatt Macy tt++; 1274eda14cbcSMatt Macy continue; 1275eda14cbcSMatt Macy } 1276eda14cbcSMatt Macy 1277eda14cbcSMatt Macy ASSERT3S(i, <, n); 1278eda14cbcSMatt Macy used[i] = c; 1279eda14cbcSMatt Macy i++; 1280eda14cbcSMatt Macy } 1281eda14cbcSMatt Macy 1282eda14cbcSMatt Macy /* 1283eda14cbcSMatt Macy * Initialize the interesting rows of the matrix. 1284eda14cbcSMatt Macy */ 12857877fdebSMatt Macy vdev_raidz_matrix_init(rr, n, nmissing_rows, parity_map, rows); 1286eda14cbcSMatt Macy 1287eda14cbcSMatt Macy /* 1288eda14cbcSMatt Macy * Invert the matrix. 1289eda14cbcSMatt Macy */ 12907877fdebSMatt Macy vdev_raidz_matrix_invert(rr, n, nmissing_rows, missing_rows, rows, 1291eda14cbcSMatt Macy invrows, used); 1292eda14cbcSMatt Macy 1293eda14cbcSMatt Macy /* 1294eda14cbcSMatt Macy * Reconstruct the missing data using the generated matrix. 1295eda14cbcSMatt Macy */ 12967877fdebSMatt Macy vdev_raidz_matrix_reconstruct(rr, n, nmissing_rows, missing_rows, 1297eda14cbcSMatt Macy invrows, used); 1298eda14cbcSMatt Macy 1299eda14cbcSMatt Macy kmem_free(p, psize); 1300eda14cbcSMatt Macy 1301eda14cbcSMatt Macy /* 1302eda14cbcSMatt Macy * copy back from temporary linear abds and free them 1303eda14cbcSMatt Macy */ 1304eda14cbcSMatt Macy if (bufs) { 13057877fdebSMatt Macy for (c = rr->rr_firstdatacol; c < rr->rr_cols; c++) { 13067877fdebSMatt Macy raidz_col_t *col = &rr->rr_col[c]; 1307eda14cbcSMatt Macy 13087877fdebSMatt Macy if (bufs[c] != NULL) { 1309eda14cbcSMatt Macy abd_copy(bufs[c], col->rc_abd, col->rc_size); 1310eda14cbcSMatt Macy abd_free(col->rc_abd); 13117877fdebSMatt Macy } 1312eda14cbcSMatt Macy col->rc_abd = bufs[c]; 1313eda14cbcSMatt Macy } 13147877fdebSMatt Macy kmem_free(bufs, rr->rr_cols * sizeof (abd_t *)); 1315eda14cbcSMatt Macy } 1316eda14cbcSMatt Macy } 1317eda14cbcSMatt Macy 1318*f9693befSMartin Matuska static void 13197877fdebSMatt Macy vdev_raidz_reconstruct_row(raidz_map_t *rm, raidz_row_t *rr, 13207877fdebSMatt Macy const int *t, int nt) 1321eda14cbcSMatt Macy { 1322eda14cbcSMatt Macy int tgts[VDEV_RAIDZ_MAXPARITY], *dt; 1323eda14cbcSMatt Macy int ntgts; 1324eda14cbcSMatt Macy int i, c, ret; 1325eda14cbcSMatt Macy int nbadparity, nbaddata; 1326eda14cbcSMatt Macy int parity_valid[VDEV_RAIDZ_MAXPARITY]; 1327eda14cbcSMatt Macy 13287877fdebSMatt Macy nbadparity = rr->rr_firstdatacol; 13297877fdebSMatt Macy nbaddata = rr->rr_cols - nbadparity; 1330eda14cbcSMatt Macy ntgts = 0; 13317877fdebSMatt Macy for (i = 0, c = 0; c < rr->rr_cols; c++) { 13327877fdebSMatt Macy if (c < rr->rr_firstdatacol) 1333eda14cbcSMatt Macy parity_valid[c] = B_FALSE; 1334eda14cbcSMatt Macy 1335eda14cbcSMatt Macy if (i < nt && c == t[i]) { 1336eda14cbcSMatt Macy tgts[ntgts++] = c; 1337eda14cbcSMatt Macy i++; 13387877fdebSMatt Macy } else if (rr->rr_col[c].rc_error != 0) { 1339eda14cbcSMatt Macy tgts[ntgts++] = c; 13407877fdebSMatt Macy } else if (c >= rr->rr_firstdatacol) { 1341eda14cbcSMatt Macy nbaddata--; 1342eda14cbcSMatt Macy } else { 1343eda14cbcSMatt Macy parity_valid[c] = B_TRUE; 1344eda14cbcSMatt Macy nbadparity--; 1345eda14cbcSMatt Macy } 1346eda14cbcSMatt Macy } 1347eda14cbcSMatt Macy 1348eda14cbcSMatt Macy ASSERT(ntgts >= nt); 1349eda14cbcSMatt Macy ASSERT(nbaddata >= 0); 1350eda14cbcSMatt Macy ASSERT(nbaddata + nbadparity == ntgts); 1351eda14cbcSMatt Macy 1352eda14cbcSMatt Macy dt = &tgts[nbadparity]; 1353eda14cbcSMatt Macy 1354eda14cbcSMatt Macy /* Reconstruct using the new math implementation */ 13557877fdebSMatt Macy ret = vdev_raidz_math_reconstruct(rm, rr, parity_valid, dt, nbaddata); 1356eda14cbcSMatt Macy if (ret != RAIDZ_ORIGINAL_IMPL) 1357*f9693befSMartin Matuska return; 1358eda14cbcSMatt Macy 1359eda14cbcSMatt Macy /* 1360eda14cbcSMatt Macy * See if we can use any of our optimized reconstruction routines. 1361eda14cbcSMatt Macy */ 1362eda14cbcSMatt Macy switch (nbaddata) { 1363eda14cbcSMatt Macy case 1: 1364*f9693befSMartin Matuska if (parity_valid[VDEV_RAIDZ_P]) { 1365*f9693befSMartin Matuska vdev_raidz_reconstruct_p(rr, dt, 1); 1366*f9693befSMartin Matuska return; 1367*f9693befSMartin Matuska } 1368eda14cbcSMatt Macy 13697877fdebSMatt Macy ASSERT(rr->rr_firstdatacol > 1); 1370eda14cbcSMatt Macy 1371*f9693befSMartin Matuska if (parity_valid[VDEV_RAIDZ_Q]) { 1372*f9693befSMartin Matuska vdev_raidz_reconstruct_q(rr, dt, 1); 1373*f9693befSMartin Matuska return; 1374*f9693befSMartin Matuska } 1375eda14cbcSMatt Macy 13767877fdebSMatt Macy ASSERT(rr->rr_firstdatacol > 2); 1377eda14cbcSMatt Macy break; 1378eda14cbcSMatt Macy 1379eda14cbcSMatt Macy case 2: 13807877fdebSMatt Macy ASSERT(rr->rr_firstdatacol > 1); 1381eda14cbcSMatt Macy 1382eda14cbcSMatt Macy if (parity_valid[VDEV_RAIDZ_P] && 1383*f9693befSMartin Matuska parity_valid[VDEV_RAIDZ_Q]) { 1384*f9693befSMartin Matuska vdev_raidz_reconstruct_pq(rr, dt, 2); 1385*f9693befSMartin Matuska return; 1386*f9693befSMartin Matuska } 1387eda14cbcSMatt Macy 13887877fdebSMatt Macy ASSERT(rr->rr_firstdatacol > 2); 1389eda14cbcSMatt Macy 1390eda14cbcSMatt Macy break; 1391eda14cbcSMatt Macy } 1392eda14cbcSMatt Macy 1393*f9693befSMartin Matuska vdev_raidz_reconstruct_general(rr, tgts, ntgts); 1394eda14cbcSMatt Macy } 1395eda14cbcSMatt Macy 1396eda14cbcSMatt Macy static int 1397eda14cbcSMatt Macy vdev_raidz_open(vdev_t *vd, uint64_t *asize, uint64_t *max_asize, 1398eda14cbcSMatt Macy uint64_t *logical_ashift, uint64_t *physical_ashift) 1399eda14cbcSMatt Macy { 14007877fdebSMatt Macy vdev_raidz_t *vdrz = vd->vdev_tsd; 14017877fdebSMatt Macy uint64_t nparity = vdrz->vd_nparity; 1402eda14cbcSMatt Macy int c; 1403eda14cbcSMatt Macy int lasterror = 0; 1404eda14cbcSMatt Macy int numerrors = 0; 1405eda14cbcSMatt Macy 1406eda14cbcSMatt Macy ASSERT(nparity > 0); 1407eda14cbcSMatt Macy 1408eda14cbcSMatt Macy if (nparity > VDEV_RAIDZ_MAXPARITY || 1409eda14cbcSMatt Macy vd->vdev_children < nparity + 1) { 1410eda14cbcSMatt Macy vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL; 1411eda14cbcSMatt Macy return (SET_ERROR(EINVAL)); 1412eda14cbcSMatt Macy } 1413eda14cbcSMatt Macy 1414eda14cbcSMatt Macy vdev_open_children(vd); 1415eda14cbcSMatt Macy 1416eda14cbcSMatt Macy for (c = 0; c < vd->vdev_children; c++) { 14177877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[c]; 1418eda14cbcSMatt Macy 1419eda14cbcSMatt Macy if (cvd->vdev_open_error != 0) { 1420eda14cbcSMatt Macy lasterror = cvd->vdev_open_error; 1421eda14cbcSMatt Macy numerrors++; 1422eda14cbcSMatt Macy continue; 1423eda14cbcSMatt Macy } 1424eda14cbcSMatt Macy 1425eda14cbcSMatt Macy *asize = MIN(*asize - 1, cvd->vdev_asize - 1) + 1; 1426eda14cbcSMatt Macy *max_asize = MIN(*max_asize - 1, cvd->vdev_max_asize - 1) + 1; 1427eda14cbcSMatt Macy *logical_ashift = MAX(*logical_ashift, cvd->vdev_ashift); 1428eda14cbcSMatt Macy *physical_ashift = MAX(*physical_ashift, 1429eda14cbcSMatt Macy cvd->vdev_physical_ashift); 1430eda14cbcSMatt Macy } 1431eda14cbcSMatt Macy 1432eda14cbcSMatt Macy *asize *= vd->vdev_children; 1433eda14cbcSMatt Macy *max_asize *= vd->vdev_children; 1434eda14cbcSMatt Macy 1435eda14cbcSMatt Macy if (numerrors > nparity) { 1436eda14cbcSMatt Macy vd->vdev_stat.vs_aux = VDEV_AUX_NO_REPLICAS; 1437eda14cbcSMatt Macy return (lasterror); 1438eda14cbcSMatt Macy } 1439eda14cbcSMatt Macy 1440eda14cbcSMatt Macy return (0); 1441eda14cbcSMatt Macy } 1442eda14cbcSMatt Macy 1443eda14cbcSMatt Macy static void 1444eda14cbcSMatt Macy vdev_raidz_close(vdev_t *vd) 1445eda14cbcSMatt Macy { 14467877fdebSMatt Macy for (int c = 0; c < vd->vdev_children; c++) { 14477877fdebSMatt Macy if (vd->vdev_child[c] != NULL) 1448eda14cbcSMatt Macy vdev_close(vd->vdev_child[c]); 1449eda14cbcSMatt Macy } 14507877fdebSMatt Macy } 1451eda14cbcSMatt Macy 1452eda14cbcSMatt Macy static uint64_t 1453eda14cbcSMatt Macy vdev_raidz_asize(vdev_t *vd, uint64_t psize) 1454eda14cbcSMatt Macy { 14557877fdebSMatt Macy vdev_raidz_t *vdrz = vd->vdev_tsd; 1456eda14cbcSMatt Macy uint64_t asize; 1457eda14cbcSMatt Macy uint64_t ashift = vd->vdev_top->vdev_ashift; 14587877fdebSMatt Macy uint64_t cols = vdrz->vd_logical_width; 14597877fdebSMatt Macy uint64_t nparity = vdrz->vd_nparity; 1460eda14cbcSMatt Macy 1461eda14cbcSMatt Macy asize = ((psize - 1) >> ashift) + 1; 1462eda14cbcSMatt Macy asize += nparity * ((asize + cols - nparity - 1) / (cols - nparity)); 1463eda14cbcSMatt Macy asize = roundup(asize, nparity + 1) << ashift; 1464eda14cbcSMatt Macy 1465eda14cbcSMatt Macy return (asize); 1466eda14cbcSMatt Macy } 1467eda14cbcSMatt Macy 14687877fdebSMatt Macy /* 14697877fdebSMatt Macy * The allocatable space for a raidz vdev is N * sizeof(smallest child) 14707877fdebSMatt Macy * so each child must provide at least 1/Nth of its asize. 14717877fdebSMatt Macy */ 14727877fdebSMatt Macy static uint64_t 14737877fdebSMatt Macy vdev_raidz_min_asize(vdev_t *vd) 14747877fdebSMatt Macy { 14757877fdebSMatt Macy return ((vd->vdev_min_asize + vd->vdev_children - 1) / 14767877fdebSMatt Macy vd->vdev_children); 14777877fdebSMatt Macy } 14787877fdebSMatt Macy 14797877fdebSMatt Macy void 1480eda14cbcSMatt Macy vdev_raidz_child_done(zio_t *zio) 1481eda14cbcSMatt Macy { 1482eda14cbcSMatt Macy raidz_col_t *rc = zio->io_private; 1483eda14cbcSMatt Macy 1484eda14cbcSMatt Macy rc->rc_error = zio->io_error; 1485eda14cbcSMatt Macy rc->rc_tried = 1; 1486eda14cbcSMatt Macy rc->rc_skipped = 0; 1487eda14cbcSMatt Macy } 1488eda14cbcSMatt Macy 1489eda14cbcSMatt Macy static void 14907877fdebSMatt Macy vdev_raidz_io_verify(vdev_t *vd, raidz_row_t *rr, int col) 1491eda14cbcSMatt Macy { 1492eda14cbcSMatt Macy #ifdef ZFS_DEBUG 1493eda14cbcSMatt Macy vdev_t *tvd = vd->vdev_top; 1494eda14cbcSMatt Macy 14957877fdebSMatt Macy range_seg64_t logical_rs, physical_rs, remain_rs; 14967877fdebSMatt Macy logical_rs.rs_start = rr->rr_offset; 1497eda14cbcSMatt Macy logical_rs.rs_end = logical_rs.rs_start + 14987877fdebSMatt Macy vdev_raidz_asize(vd, rr->rr_size); 1499eda14cbcSMatt Macy 15007877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[col]; 1501eda14cbcSMatt Macy vdev_t *cvd = vd->vdev_child[rc->rc_devidx]; 1502eda14cbcSMatt Macy 15037877fdebSMatt Macy vdev_xlate(cvd, &logical_rs, &physical_rs, &remain_rs); 15047877fdebSMatt Macy ASSERT(vdev_xlate_is_empty(&remain_rs)); 1505eda14cbcSMatt Macy ASSERT3U(rc->rc_offset, ==, physical_rs.rs_start); 1506eda14cbcSMatt Macy ASSERT3U(rc->rc_offset, <, physical_rs.rs_end); 1507eda14cbcSMatt Macy /* 1508eda14cbcSMatt Macy * It would be nice to assert that rs_end is equal 1509eda14cbcSMatt Macy * to rc_offset + rc_size but there might be an 1510eda14cbcSMatt Macy * optional I/O at the end that is not accounted in 1511eda14cbcSMatt Macy * rc_size. 1512eda14cbcSMatt Macy */ 1513eda14cbcSMatt Macy if (physical_rs.rs_end > rc->rc_offset + rc->rc_size) { 1514eda14cbcSMatt Macy ASSERT3U(physical_rs.rs_end, ==, rc->rc_offset + 1515eda14cbcSMatt Macy rc->rc_size + (1 << tvd->vdev_ashift)); 1516eda14cbcSMatt Macy } else { 1517eda14cbcSMatt Macy ASSERT3U(physical_rs.rs_end, ==, rc->rc_offset + rc->rc_size); 1518eda14cbcSMatt Macy } 1519eda14cbcSMatt Macy #endif 1520eda14cbcSMatt Macy } 1521eda14cbcSMatt Macy 15227877fdebSMatt Macy static void 15237877fdebSMatt Macy vdev_raidz_io_start_write(zio_t *zio, raidz_row_t *rr, uint64_t ashift) 15247877fdebSMatt Macy { 15257877fdebSMatt Macy vdev_t *vd = zio->io_vd; 15267877fdebSMatt Macy raidz_map_t *rm = zio->io_vsd; 15277877fdebSMatt Macy int c, i; 15287877fdebSMatt Macy 15297877fdebSMatt Macy vdev_raidz_generate_parity_row(rm, rr); 15307877fdebSMatt Macy 15317877fdebSMatt Macy for (int c = 0; c < rr->rr_cols; c++) { 15327877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 15337877fdebSMatt Macy if (rc->rc_size == 0) 15347877fdebSMatt Macy continue; 15357877fdebSMatt Macy 15367877fdebSMatt Macy /* Verify physical to logical translation */ 15377877fdebSMatt Macy vdev_raidz_io_verify(vd, rr, c); 15387877fdebSMatt Macy 15397877fdebSMatt Macy zio_nowait(zio_vdev_child_io(zio, NULL, 15407877fdebSMatt Macy vd->vdev_child[rc->rc_devidx], rc->rc_offset, 15417877fdebSMatt Macy rc->rc_abd, rc->rc_size, zio->io_type, zio->io_priority, 15427877fdebSMatt Macy 0, vdev_raidz_child_done, rc)); 15437877fdebSMatt Macy } 15447877fdebSMatt Macy 15457877fdebSMatt Macy /* 15467877fdebSMatt Macy * Generate optional I/Os for skip sectors to improve aggregation 15477877fdebSMatt Macy * contiguity. 15487877fdebSMatt Macy */ 15497877fdebSMatt Macy for (c = rm->rm_skipstart, i = 0; i < rm->rm_nskip; c++, i++) { 15507877fdebSMatt Macy ASSERT(c <= rr->rr_scols); 15517877fdebSMatt Macy if (c == rr->rr_scols) 15527877fdebSMatt Macy c = 0; 15537877fdebSMatt Macy 15547877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 15557877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[rc->rc_devidx]; 15567877fdebSMatt Macy 15577877fdebSMatt Macy zio_nowait(zio_vdev_child_io(zio, NULL, cvd, 15587877fdebSMatt Macy rc->rc_offset + rc->rc_size, NULL, 1ULL << ashift, 15597877fdebSMatt Macy zio->io_type, zio->io_priority, 15607877fdebSMatt Macy ZIO_FLAG_NODATA | ZIO_FLAG_OPTIONAL, NULL, NULL)); 15617877fdebSMatt Macy } 15627877fdebSMatt Macy } 15637877fdebSMatt Macy 15647877fdebSMatt Macy static void 15657877fdebSMatt Macy vdev_raidz_io_start_read(zio_t *zio, raidz_row_t *rr) 15667877fdebSMatt Macy { 15677877fdebSMatt Macy vdev_t *vd = zio->io_vd; 15687877fdebSMatt Macy 15697877fdebSMatt Macy /* 15707877fdebSMatt Macy * Iterate over the columns in reverse order so that we hit the parity 15717877fdebSMatt Macy * last -- any errors along the way will force us to read the parity. 15727877fdebSMatt Macy */ 15737877fdebSMatt Macy for (int c = rr->rr_cols - 1; c >= 0; c--) { 15747877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 15757877fdebSMatt Macy if (rc->rc_size == 0) 15767877fdebSMatt Macy continue; 15777877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[rc->rc_devidx]; 15787877fdebSMatt Macy if (!vdev_readable(cvd)) { 15797877fdebSMatt Macy if (c >= rr->rr_firstdatacol) 15807877fdebSMatt Macy rr->rr_missingdata++; 15817877fdebSMatt Macy else 15827877fdebSMatt Macy rr->rr_missingparity++; 15837877fdebSMatt Macy rc->rc_error = SET_ERROR(ENXIO); 15847877fdebSMatt Macy rc->rc_tried = 1; /* don't even try */ 15857877fdebSMatt Macy rc->rc_skipped = 1; 15867877fdebSMatt Macy continue; 15877877fdebSMatt Macy } 15887877fdebSMatt Macy if (vdev_dtl_contains(cvd, DTL_MISSING, zio->io_txg, 1)) { 15897877fdebSMatt Macy if (c >= rr->rr_firstdatacol) 15907877fdebSMatt Macy rr->rr_missingdata++; 15917877fdebSMatt Macy else 15927877fdebSMatt Macy rr->rr_missingparity++; 15937877fdebSMatt Macy rc->rc_error = SET_ERROR(ESTALE); 15947877fdebSMatt Macy rc->rc_skipped = 1; 15957877fdebSMatt Macy continue; 15967877fdebSMatt Macy } 15977877fdebSMatt Macy if (c >= rr->rr_firstdatacol || rr->rr_missingdata > 0 || 15987877fdebSMatt Macy (zio->io_flags & (ZIO_FLAG_SCRUB | ZIO_FLAG_RESILVER))) { 15997877fdebSMatt Macy zio_nowait(zio_vdev_child_io(zio, NULL, cvd, 16007877fdebSMatt Macy rc->rc_offset, rc->rc_abd, rc->rc_size, 16017877fdebSMatt Macy zio->io_type, zio->io_priority, 0, 16027877fdebSMatt Macy vdev_raidz_child_done, rc)); 16037877fdebSMatt Macy } 16047877fdebSMatt Macy } 16057877fdebSMatt Macy } 16067877fdebSMatt Macy 1607eda14cbcSMatt Macy /* 1608eda14cbcSMatt Macy * Start an IO operation on a RAIDZ VDev 1609eda14cbcSMatt Macy * 1610eda14cbcSMatt Macy * Outline: 1611eda14cbcSMatt Macy * - For write operations: 1612eda14cbcSMatt Macy * 1. Generate the parity data 1613eda14cbcSMatt Macy * 2. Create child zio write operations to each column's vdev, for both 1614eda14cbcSMatt Macy * data and parity. 1615eda14cbcSMatt Macy * 3. If the column skips any sectors for padding, create optional dummy 1616eda14cbcSMatt Macy * write zio children for those areas to improve aggregation continuity. 1617eda14cbcSMatt Macy * - For read operations: 1618eda14cbcSMatt Macy * 1. Create child zio read operations to each data column's vdev to read 1619eda14cbcSMatt Macy * the range of data required for zio. 1620eda14cbcSMatt Macy * 2. If this is a scrub or resilver operation, or if any of the data 1621eda14cbcSMatt Macy * vdevs have had errors, then create zio read operations to the parity 1622eda14cbcSMatt Macy * columns' VDevs as well. 1623eda14cbcSMatt Macy */ 1624eda14cbcSMatt Macy static void 1625eda14cbcSMatt Macy vdev_raidz_io_start(zio_t *zio) 1626eda14cbcSMatt Macy { 1627eda14cbcSMatt Macy vdev_t *vd = zio->io_vd; 1628eda14cbcSMatt Macy vdev_t *tvd = vd->vdev_top; 16297877fdebSMatt Macy vdev_raidz_t *vdrz = vd->vdev_tsd; 1630eda14cbcSMatt Macy 1631*f9693befSMartin Matuska raidz_map_t *rm = vdev_raidz_map_alloc(zio, tvd->vdev_ashift, 16327877fdebSMatt Macy vdrz->vd_logical_width, vdrz->vd_nparity); 1633*f9693befSMartin Matuska zio->io_vsd = rm; 1634*f9693befSMartin Matuska zio->io_vsd_ops = &vdev_raidz_vsd_ops; 1635eda14cbcSMatt Macy 16367877fdebSMatt Macy /* 16377877fdebSMatt Macy * Until raidz expansion is implemented all maps for a raidz vdev 16387877fdebSMatt Macy * contain a single row. 16397877fdebSMatt Macy */ 16407877fdebSMatt Macy ASSERT3U(rm->rm_nrows, ==, 1); 16417877fdebSMatt Macy raidz_row_t *rr = rm->rm_row[0]; 16427877fdebSMatt Macy 1643eda14cbcSMatt Macy if (zio->io_type == ZIO_TYPE_WRITE) { 16447877fdebSMatt Macy vdev_raidz_io_start_write(zio, rr, tvd->vdev_ashift); 16457877fdebSMatt Macy } else { 1646eda14cbcSMatt Macy ASSERT(zio->io_type == ZIO_TYPE_READ); 16477877fdebSMatt Macy vdev_raidz_io_start_read(zio, rr); 1648eda14cbcSMatt Macy } 1649eda14cbcSMatt Macy 1650eda14cbcSMatt Macy zio_execute(zio); 1651eda14cbcSMatt Macy } 1652eda14cbcSMatt Macy 1653eda14cbcSMatt Macy /* 1654eda14cbcSMatt Macy * Report a checksum error for a child of a RAID-Z device. 1655eda14cbcSMatt Macy */ 1656eda14cbcSMatt Macy static void 1657eda14cbcSMatt Macy raidz_checksum_error(zio_t *zio, raidz_col_t *rc, abd_t *bad_data) 1658eda14cbcSMatt Macy { 1659eda14cbcSMatt Macy vdev_t *vd = zio->io_vd->vdev_child[rc->rc_devidx]; 1660eda14cbcSMatt Macy 16617877fdebSMatt Macy if (!(zio->io_flags & ZIO_FLAG_SPECULATIVE) && 16627877fdebSMatt Macy zio->io_priority != ZIO_PRIORITY_REBUILD) { 1663eda14cbcSMatt Macy zio_bad_cksum_t zbc; 1664eda14cbcSMatt Macy raidz_map_t *rm = zio->io_vsd; 1665eda14cbcSMatt Macy 1666eda14cbcSMatt Macy zbc.zbc_has_cksum = 0; 1667eda14cbcSMatt Macy zbc.zbc_injected = rm->rm_ecksuminjected; 1668eda14cbcSMatt Macy 1669ba27dd8bSMartin Matuska (void) zfs_ereport_post_checksum(zio->io_spa, vd, 1670eda14cbcSMatt Macy &zio->io_bookmark, zio, rc->rc_offset, rc->rc_size, 1671eda14cbcSMatt Macy rc->rc_abd, bad_data, &zbc); 16722c48331dSMatt Macy mutex_enter(&vd->vdev_stat_lock); 16732c48331dSMatt Macy vd->vdev_stat.vs_checksum_errors++; 16742c48331dSMatt Macy mutex_exit(&vd->vdev_stat_lock); 16752c48331dSMatt Macy } 1676eda14cbcSMatt Macy } 1677eda14cbcSMatt Macy 1678eda14cbcSMatt Macy /* 1679eda14cbcSMatt Macy * We keep track of whether or not there were any injected errors, so that 1680eda14cbcSMatt Macy * any ereports we generate can note it. 1681eda14cbcSMatt Macy */ 1682eda14cbcSMatt Macy static int 1683eda14cbcSMatt Macy raidz_checksum_verify(zio_t *zio) 1684eda14cbcSMatt Macy { 1685eda14cbcSMatt Macy zio_bad_cksum_t zbc; 1686eda14cbcSMatt Macy raidz_map_t *rm = zio->io_vsd; 1687eda14cbcSMatt Macy 1688eda14cbcSMatt Macy bzero(&zbc, sizeof (zio_bad_cksum_t)); 1689eda14cbcSMatt Macy 1690eda14cbcSMatt Macy int ret = zio_checksum_error(zio, &zbc); 1691eda14cbcSMatt Macy if (ret != 0 && zbc.zbc_injected != 0) 1692eda14cbcSMatt Macy rm->rm_ecksuminjected = 1; 1693eda14cbcSMatt Macy 1694eda14cbcSMatt Macy return (ret); 1695eda14cbcSMatt Macy } 1696eda14cbcSMatt Macy 1697eda14cbcSMatt Macy /* 1698eda14cbcSMatt Macy * Generate the parity from the data columns. If we tried and were able to 1699eda14cbcSMatt Macy * read the parity without error, verify that the generated parity matches the 1700eda14cbcSMatt Macy * data we read. If it doesn't, we fire off a checksum error. Return the 17017877fdebSMatt Macy * number of such failures. 1702eda14cbcSMatt Macy */ 1703eda14cbcSMatt Macy static int 17047877fdebSMatt Macy raidz_parity_verify(zio_t *zio, raidz_row_t *rr) 1705eda14cbcSMatt Macy { 1706eda14cbcSMatt Macy abd_t *orig[VDEV_RAIDZ_MAXPARITY]; 1707eda14cbcSMatt Macy int c, ret = 0; 17087877fdebSMatt Macy raidz_map_t *rm = zio->io_vsd; 1709eda14cbcSMatt Macy raidz_col_t *rc; 1710eda14cbcSMatt Macy 1711eda14cbcSMatt Macy blkptr_t *bp = zio->io_bp; 1712eda14cbcSMatt Macy enum zio_checksum checksum = (bp == NULL ? zio->io_prop.zp_checksum : 1713eda14cbcSMatt Macy (BP_IS_GANG(bp) ? ZIO_CHECKSUM_GANG_HEADER : BP_GET_CHECKSUM(bp))); 1714eda14cbcSMatt Macy 1715eda14cbcSMatt Macy if (checksum == ZIO_CHECKSUM_NOPARITY) 1716eda14cbcSMatt Macy return (ret); 1717eda14cbcSMatt Macy 17187877fdebSMatt Macy for (c = 0; c < rr->rr_firstdatacol; c++) { 17197877fdebSMatt Macy rc = &rr->rr_col[c]; 1720eda14cbcSMatt Macy if (!rc->rc_tried || rc->rc_error != 0) 1721eda14cbcSMatt Macy continue; 1722eda14cbcSMatt Macy 1723eda14cbcSMatt Macy orig[c] = abd_alloc_sametype(rc->rc_abd, rc->rc_size); 1724eda14cbcSMatt Macy abd_copy(orig[c], rc->rc_abd, rc->rc_size); 1725eda14cbcSMatt Macy } 1726eda14cbcSMatt Macy 17277877fdebSMatt Macy /* 17287877fdebSMatt Macy * Regenerates parity even for !tried||rc_error!=0 columns. This 17297877fdebSMatt Macy * isn't harmful but it does have the side effect of fixing stuff 17307877fdebSMatt Macy * we didn't realize was necessary (i.e. even if we return 0). 17317877fdebSMatt Macy */ 17327877fdebSMatt Macy vdev_raidz_generate_parity_row(rm, rr); 1733eda14cbcSMatt Macy 17347877fdebSMatt Macy for (c = 0; c < rr->rr_firstdatacol; c++) { 17357877fdebSMatt Macy rc = &rr->rr_col[c]; 17367877fdebSMatt Macy 1737eda14cbcSMatt Macy if (!rc->rc_tried || rc->rc_error != 0) 1738eda14cbcSMatt Macy continue; 17397877fdebSMatt Macy 1740eda14cbcSMatt Macy if (abd_cmp(orig[c], rc->rc_abd) != 0) { 1741eda14cbcSMatt Macy raidz_checksum_error(zio, rc, orig[c]); 1742eda14cbcSMatt Macy rc->rc_error = SET_ERROR(ECKSUM); 1743eda14cbcSMatt Macy ret++; 1744eda14cbcSMatt Macy } 1745eda14cbcSMatt Macy abd_free(orig[c]); 1746eda14cbcSMatt Macy } 1747eda14cbcSMatt Macy 1748eda14cbcSMatt Macy return (ret); 1749eda14cbcSMatt Macy } 1750eda14cbcSMatt Macy 1751eda14cbcSMatt Macy static int 17527877fdebSMatt Macy vdev_raidz_worst_error(raidz_row_t *rr) 1753eda14cbcSMatt Macy { 1754eda14cbcSMatt Macy int error = 0; 1755eda14cbcSMatt Macy 17567877fdebSMatt Macy for (int c = 0; c < rr->rr_cols; c++) 17577877fdebSMatt Macy error = zio_worst_error(error, rr->rr_col[c].rc_error); 1758eda14cbcSMatt Macy 1759eda14cbcSMatt Macy return (error); 1760eda14cbcSMatt Macy } 1761eda14cbcSMatt Macy 1762eda14cbcSMatt Macy static void 17637877fdebSMatt Macy vdev_raidz_io_done_verified(zio_t *zio, raidz_row_t *rr) 1764eda14cbcSMatt Macy { 1765eda14cbcSMatt Macy int unexpected_errors = 0; 1766eda14cbcSMatt Macy int parity_errors = 0; 1767eda14cbcSMatt Macy int parity_untried = 0; 1768eda14cbcSMatt Macy int data_errors = 0; 1769eda14cbcSMatt Macy 17707877fdebSMatt Macy ASSERT3U(zio->io_type, ==, ZIO_TYPE_READ); 1771eda14cbcSMatt Macy 17727877fdebSMatt Macy for (int c = 0; c < rr->rr_cols; c++) { 17737877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 1774eda14cbcSMatt Macy 1775eda14cbcSMatt Macy if (rc->rc_error) { 17767877fdebSMatt Macy if (c < rr->rr_firstdatacol) 1777eda14cbcSMatt Macy parity_errors++; 1778eda14cbcSMatt Macy else 1779eda14cbcSMatt Macy data_errors++; 1780eda14cbcSMatt Macy 1781eda14cbcSMatt Macy if (!rc->rc_skipped) 1782eda14cbcSMatt Macy unexpected_errors++; 17837877fdebSMatt Macy } else if (c < rr->rr_firstdatacol && !rc->rc_tried) { 1784eda14cbcSMatt Macy parity_untried++; 1785eda14cbcSMatt Macy } 1786eda14cbcSMatt Macy } 1787eda14cbcSMatt Macy 1788eda14cbcSMatt Macy /* 17897877fdebSMatt Macy * If we read more parity disks than were used for 17907877fdebSMatt Macy * reconstruction, confirm that the other parity disks produced 17917877fdebSMatt Macy * correct data. 17927877fdebSMatt Macy * 17937877fdebSMatt Macy * Note that we also regenerate parity when resilvering so we 17947877fdebSMatt Macy * can write it out to failed devices later. 17957877fdebSMatt Macy */ 17967877fdebSMatt Macy if (parity_errors + parity_untried < 17977877fdebSMatt Macy rr->rr_firstdatacol - data_errors || 17987877fdebSMatt Macy (zio->io_flags & ZIO_FLAG_RESILVER)) { 17997877fdebSMatt Macy int n = raidz_parity_verify(zio, rr); 18007877fdebSMatt Macy unexpected_errors += n; 18017877fdebSMatt Macy ASSERT3U(parity_errors + n, <=, rr->rr_firstdatacol); 18027877fdebSMatt Macy } 18037877fdebSMatt Macy 18047877fdebSMatt Macy if (zio->io_error == 0 && spa_writeable(zio->io_spa) && 18057877fdebSMatt Macy (unexpected_errors > 0 || (zio->io_flags & ZIO_FLAG_RESILVER))) { 18067877fdebSMatt Macy /* 18077877fdebSMatt Macy * Use the good data we have in hand to repair damaged children. 18087877fdebSMatt Macy */ 18097877fdebSMatt Macy for (int c = 0; c < rr->rr_cols; c++) { 18107877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 18117877fdebSMatt Macy vdev_t *vd = zio->io_vd; 18127877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[rc->rc_devidx]; 18137877fdebSMatt Macy 18147877fdebSMatt Macy if ((rc->rc_error == 0 || rc->rc_size == 0) && 18157877fdebSMatt Macy (rc->rc_repair == 0)) { 18167877fdebSMatt Macy continue; 18177877fdebSMatt Macy } 18187877fdebSMatt Macy 18197877fdebSMatt Macy zio_nowait(zio_vdev_child_io(zio, NULL, cvd, 18207877fdebSMatt Macy rc->rc_offset, rc->rc_abd, rc->rc_size, 18217877fdebSMatt Macy ZIO_TYPE_WRITE, 18227877fdebSMatt Macy zio->io_priority == ZIO_PRIORITY_REBUILD ? 18237877fdebSMatt Macy ZIO_PRIORITY_REBUILD : ZIO_PRIORITY_ASYNC_WRITE, 18247877fdebSMatt Macy ZIO_FLAG_IO_REPAIR | (unexpected_errors ? 18257877fdebSMatt Macy ZIO_FLAG_SELF_HEAL : 0), NULL, NULL)); 18267877fdebSMatt Macy } 18277877fdebSMatt Macy } 18287877fdebSMatt Macy } 18297877fdebSMatt Macy 18307877fdebSMatt Macy static void 18317877fdebSMatt Macy raidz_restore_orig_data(raidz_map_t *rm) 18327877fdebSMatt Macy { 18337877fdebSMatt Macy for (int i = 0; i < rm->rm_nrows; i++) { 18347877fdebSMatt Macy raidz_row_t *rr = rm->rm_row[i]; 18357877fdebSMatt Macy for (int c = 0; c < rr->rr_cols; c++) { 18367877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 18377877fdebSMatt Macy if (rc->rc_need_orig_restore) { 1838*f9693befSMartin Matuska abd_copy(rc->rc_abd, 18397877fdebSMatt Macy rc->rc_orig_data, rc->rc_size); 18407877fdebSMatt Macy rc->rc_need_orig_restore = B_FALSE; 18417877fdebSMatt Macy } 18427877fdebSMatt Macy } 18437877fdebSMatt Macy } 18447877fdebSMatt Macy } 18457877fdebSMatt Macy 18467877fdebSMatt Macy /* 18477877fdebSMatt Macy * returns EINVAL if reconstruction of the block will not be possible 18487877fdebSMatt Macy * returns ECKSUM if this specific reconstruction failed 18497877fdebSMatt Macy * returns 0 on successful reconstruction 18507877fdebSMatt Macy */ 18517877fdebSMatt Macy static int 18527877fdebSMatt Macy raidz_reconstruct(zio_t *zio, int *ltgts, int ntgts, int nparity) 18537877fdebSMatt Macy { 18547877fdebSMatt Macy raidz_map_t *rm = zio->io_vsd; 18557877fdebSMatt Macy 18567877fdebSMatt Macy /* Reconstruct each row */ 18577877fdebSMatt Macy for (int r = 0; r < rm->rm_nrows; r++) { 18587877fdebSMatt Macy raidz_row_t *rr = rm->rm_row[r]; 18597877fdebSMatt Macy int my_tgts[VDEV_RAIDZ_MAXPARITY]; /* value is child id */ 18607877fdebSMatt Macy int t = 0; 18617877fdebSMatt Macy int dead = 0; 18627877fdebSMatt Macy int dead_data = 0; 18637877fdebSMatt Macy 18647877fdebSMatt Macy for (int c = 0; c < rr->rr_cols; c++) { 18657877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 18667877fdebSMatt Macy ASSERT0(rc->rc_need_orig_restore); 18677877fdebSMatt Macy if (rc->rc_error != 0) { 18687877fdebSMatt Macy dead++; 18697877fdebSMatt Macy if (c >= nparity) 18707877fdebSMatt Macy dead_data++; 18717877fdebSMatt Macy continue; 18727877fdebSMatt Macy } 18737877fdebSMatt Macy if (rc->rc_size == 0) 18747877fdebSMatt Macy continue; 18757877fdebSMatt Macy for (int lt = 0; lt < ntgts; lt++) { 18767877fdebSMatt Macy if (rc->rc_devidx == ltgts[lt]) { 18777877fdebSMatt Macy if (rc->rc_orig_data == NULL) { 18787877fdebSMatt Macy rc->rc_orig_data = 1879*f9693befSMartin Matuska abd_alloc_linear( 1880*f9693befSMartin Matuska rc->rc_size, B_TRUE); 1881*f9693befSMartin Matuska abd_copy(rc->rc_orig_data, 18827877fdebSMatt Macy rc->rc_abd, rc->rc_size); 18837877fdebSMatt Macy } 18847877fdebSMatt Macy rc->rc_need_orig_restore = B_TRUE; 18857877fdebSMatt Macy 18867877fdebSMatt Macy dead++; 18877877fdebSMatt Macy if (c >= nparity) 18887877fdebSMatt Macy dead_data++; 18897877fdebSMatt Macy my_tgts[t++] = c; 18907877fdebSMatt Macy break; 18917877fdebSMatt Macy } 18927877fdebSMatt Macy } 18937877fdebSMatt Macy } 18947877fdebSMatt Macy if (dead > nparity) { 18957877fdebSMatt Macy /* reconstruction not possible */ 18967877fdebSMatt Macy raidz_restore_orig_data(rm); 18977877fdebSMatt Macy return (EINVAL); 18987877fdebSMatt Macy } 18997877fdebSMatt Macy if (dead_data > 0) 1900*f9693befSMartin Matuska vdev_raidz_reconstruct_row(rm, rr, my_tgts, t); 19017877fdebSMatt Macy } 19027877fdebSMatt Macy 19037877fdebSMatt Macy /* Check for success */ 19047877fdebSMatt Macy if (raidz_checksum_verify(zio) == 0) { 19057877fdebSMatt Macy 19067877fdebSMatt Macy /* Reconstruction succeeded - report errors */ 19077877fdebSMatt Macy for (int i = 0; i < rm->rm_nrows; i++) { 19087877fdebSMatt Macy raidz_row_t *rr = rm->rm_row[i]; 19097877fdebSMatt Macy 19107877fdebSMatt Macy for (int c = 0; c < rr->rr_cols; c++) { 19117877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 19127877fdebSMatt Macy if (rc->rc_need_orig_restore) { 19137877fdebSMatt Macy /* 19147877fdebSMatt Macy * Note: if this is a parity column, 19157877fdebSMatt Macy * we don't really know if it's wrong. 19167877fdebSMatt Macy * We need to let 19177877fdebSMatt Macy * vdev_raidz_io_done_verified() check 19187877fdebSMatt Macy * it, and if we set rc_error, it will 19197877fdebSMatt Macy * think that it is a "known" error 19207877fdebSMatt Macy * that doesn't need to be checked 19217877fdebSMatt Macy * or corrected. 19227877fdebSMatt Macy */ 19237877fdebSMatt Macy if (rc->rc_error == 0 && 19247877fdebSMatt Macy c >= rr->rr_firstdatacol) { 19257877fdebSMatt Macy raidz_checksum_error(zio, 1926*f9693befSMartin Matuska rc, rc->rc_orig_data); 19277877fdebSMatt Macy rc->rc_error = 19287877fdebSMatt Macy SET_ERROR(ECKSUM); 19297877fdebSMatt Macy } 19307877fdebSMatt Macy rc->rc_need_orig_restore = B_FALSE; 19317877fdebSMatt Macy } 19327877fdebSMatt Macy } 19337877fdebSMatt Macy 19347877fdebSMatt Macy vdev_raidz_io_done_verified(zio, rr); 19357877fdebSMatt Macy } 19367877fdebSMatt Macy 19377877fdebSMatt Macy zio_checksum_verified(zio); 19387877fdebSMatt Macy 19397877fdebSMatt Macy return (0); 19407877fdebSMatt Macy } 19417877fdebSMatt Macy 19427877fdebSMatt Macy /* Reconstruction failed - restore original data */ 19437877fdebSMatt Macy raidz_restore_orig_data(rm); 19447877fdebSMatt Macy return (ECKSUM); 19457877fdebSMatt Macy } 19467877fdebSMatt Macy 19477877fdebSMatt Macy /* 19487877fdebSMatt Macy * Iterate over all combinations of N bad vdevs and attempt a reconstruction. 19497877fdebSMatt Macy * Note that the algorithm below is non-optimal because it doesn't take into 19507877fdebSMatt Macy * account how reconstruction is actually performed. For example, with 19517877fdebSMatt Macy * triple-parity RAID-Z the reconstruction procedure is the same if column 4 19527877fdebSMatt Macy * is targeted as invalid as if columns 1 and 4 are targeted since in both 19537877fdebSMatt Macy * cases we'd only use parity information in column 0. 19547877fdebSMatt Macy * 19557877fdebSMatt Macy * The order that we find the various possible combinations of failed 19567877fdebSMatt Macy * disks is dictated by these rules: 19577877fdebSMatt Macy * - Examine each "slot" (the "i" in tgts[i]) 19587877fdebSMatt Macy * - Try to increment this slot (tgts[i] = tgts[i] + 1) 19597877fdebSMatt Macy * - if we can't increment because it runs into the next slot, 19607877fdebSMatt Macy * reset our slot to the minimum, and examine the next slot 19617877fdebSMatt Macy * 19627877fdebSMatt Macy * For example, with a 6-wide RAIDZ3, and no known errors (so we have to choose 19637877fdebSMatt Macy * 3 columns to reconstruct), we will generate the following sequence: 19647877fdebSMatt Macy * 19657877fdebSMatt Macy * STATE ACTION 19667877fdebSMatt Macy * 0 1 2 special case: skip since these are all parity 19677877fdebSMatt Macy * 0 1 3 first slot: reset to 0; middle slot: increment to 2 19687877fdebSMatt Macy * 0 2 3 first slot: increment to 1 19697877fdebSMatt Macy * 1 2 3 first: reset to 0; middle: reset to 1; last: increment to 4 19707877fdebSMatt Macy * 0 1 4 first: reset to 0; middle: increment to 2 19717877fdebSMatt Macy * 0 2 4 first: increment to 1 19727877fdebSMatt Macy * 1 2 4 first: reset to 0; middle: increment to 3 19737877fdebSMatt Macy * 0 3 4 first: increment to 1 19747877fdebSMatt Macy * 1 3 4 first: increment to 2 19757877fdebSMatt Macy * 2 3 4 first: reset to 0; middle: reset to 1; last: increment to 5 19767877fdebSMatt Macy * 0 1 5 first: reset to 0; middle: increment to 2 19777877fdebSMatt Macy * 0 2 5 first: increment to 1 19787877fdebSMatt Macy * 1 2 5 first: reset to 0; middle: increment to 3 19797877fdebSMatt Macy * 0 3 5 first: increment to 1 19807877fdebSMatt Macy * 1 3 5 first: increment to 2 19817877fdebSMatt Macy * 2 3 5 first: reset to 0; middle: increment to 4 19827877fdebSMatt Macy * 0 4 5 first: increment to 1 19837877fdebSMatt Macy * 1 4 5 first: increment to 2 19847877fdebSMatt Macy * 2 4 5 first: increment to 3 19857877fdebSMatt Macy * 3 4 5 done 19867877fdebSMatt Macy * 19877877fdebSMatt Macy * This strategy works for dRAID but is less effecient when there are a large 19887877fdebSMatt Macy * number of child vdevs and therefore permutations to check. Furthermore, 19897877fdebSMatt Macy * since the raidz_map_t rows likely do not overlap reconstruction would be 19907877fdebSMatt Macy * possible as long as there are no more than nparity data errors per row. 19917877fdebSMatt Macy * These additional permutations are not currently checked but could be as 19927877fdebSMatt Macy * a future improvement. 19937877fdebSMatt Macy */ 19947877fdebSMatt Macy static int 19957877fdebSMatt Macy vdev_raidz_combrec(zio_t *zio) 19967877fdebSMatt Macy { 19977877fdebSMatt Macy int nparity = vdev_get_nparity(zio->io_vd); 19987877fdebSMatt Macy raidz_map_t *rm = zio->io_vsd; 19997877fdebSMatt Macy 20007877fdebSMatt Macy /* Check if there's enough data to attempt reconstrution. */ 20017877fdebSMatt Macy for (int i = 0; i < rm->rm_nrows; i++) { 20027877fdebSMatt Macy raidz_row_t *rr = rm->rm_row[i]; 20037877fdebSMatt Macy int total_errors = 0; 20047877fdebSMatt Macy 20057877fdebSMatt Macy for (int c = 0; c < rr->rr_cols; c++) { 20067877fdebSMatt Macy if (rr->rr_col[c].rc_error) 20077877fdebSMatt Macy total_errors++; 20087877fdebSMatt Macy } 20097877fdebSMatt Macy 20107877fdebSMatt Macy if (total_errors > nparity) 20117877fdebSMatt Macy return (vdev_raidz_worst_error(rr)); 20127877fdebSMatt Macy } 20137877fdebSMatt Macy 20147877fdebSMatt Macy for (int num_failures = 1; num_failures <= nparity; num_failures++) { 20157877fdebSMatt Macy int tstore[VDEV_RAIDZ_MAXPARITY + 2]; 20167877fdebSMatt Macy int *ltgts = &tstore[1]; /* value is logical child ID */ 20177877fdebSMatt Macy 20187877fdebSMatt Macy /* Determine number of logical children, n */ 20197877fdebSMatt Macy int n = zio->io_vd->vdev_children; 20207877fdebSMatt Macy 20217877fdebSMatt Macy ASSERT3U(num_failures, <=, nparity); 20227877fdebSMatt Macy ASSERT3U(num_failures, <=, VDEV_RAIDZ_MAXPARITY); 20237877fdebSMatt Macy 20247877fdebSMatt Macy /* Handle corner cases in combrec logic */ 20257877fdebSMatt Macy ltgts[-1] = -1; 20267877fdebSMatt Macy for (int i = 0; i < num_failures; i++) { 20277877fdebSMatt Macy ltgts[i] = i; 20287877fdebSMatt Macy } 20297877fdebSMatt Macy ltgts[num_failures] = n; 20307877fdebSMatt Macy 20317877fdebSMatt Macy for (;;) { 20327877fdebSMatt Macy int err = raidz_reconstruct(zio, ltgts, num_failures, 20337877fdebSMatt Macy nparity); 20347877fdebSMatt Macy if (err == EINVAL) { 20357877fdebSMatt Macy /* 20367877fdebSMatt Macy * Reconstruction not possible with this # 20377877fdebSMatt Macy * failures; try more failures. 20387877fdebSMatt Macy */ 20397877fdebSMatt Macy break; 20407877fdebSMatt Macy } else if (err == 0) 20417877fdebSMatt Macy return (0); 20427877fdebSMatt Macy 20437877fdebSMatt Macy /* Compute next targets to try */ 20447877fdebSMatt Macy for (int t = 0; ; t++) { 20457877fdebSMatt Macy ASSERT3U(t, <, num_failures); 20467877fdebSMatt Macy ltgts[t]++; 20477877fdebSMatt Macy if (ltgts[t] == n) { 20487877fdebSMatt Macy /* try more failures */ 20497877fdebSMatt Macy ASSERT3U(t, ==, num_failures - 1); 20507877fdebSMatt Macy break; 20517877fdebSMatt Macy } 20527877fdebSMatt Macy 20537877fdebSMatt Macy ASSERT3U(ltgts[t], <, n); 20547877fdebSMatt Macy ASSERT3U(ltgts[t], <=, ltgts[t + 1]); 20557877fdebSMatt Macy 20567877fdebSMatt Macy /* 20577877fdebSMatt Macy * If that spot is available, we're done here. 20587877fdebSMatt Macy * Try the next combination. 20597877fdebSMatt Macy */ 20607877fdebSMatt Macy if (ltgts[t] != ltgts[t + 1]) 20617877fdebSMatt Macy break; 20627877fdebSMatt Macy 20637877fdebSMatt Macy /* 20647877fdebSMatt Macy * Otherwise, reset this tgt to the minimum, 20657877fdebSMatt Macy * and move on to the next tgt. 20667877fdebSMatt Macy */ 20677877fdebSMatt Macy ltgts[t] = ltgts[t - 1] + 1; 20687877fdebSMatt Macy ASSERT3U(ltgts[t], ==, t); 20697877fdebSMatt Macy } 20707877fdebSMatt Macy 20717877fdebSMatt Macy /* Increase the number of failures and keep trying. */ 20727877fdebSMatt Macy if (ltgts[num_failures - 1] == n) 20737877fdebSMatt Macy break; 20747877fdebSMatt Macy } 20757877fdebSMatt Macy } 20767877fdebSMatt Macy 20777877fdebSMatt Macy return (ECKSUM); 20787877fdebSMatt Macy } 20797877fdebSMatt Macy 20807877fdebSMatt Macy void 20817877fdebSMatt Macy vdev_raidz_reconstruct(raidz_map_t *rm, const int *t, int nt) 20827877fdebSMatt Macy { 20837877fdebSMatt Macy for (uint64_t row = 0; row < rm->rm_nrows; row++) { 20847877fdebSMatt Macy raidz_row_t *rr = rm->rm_row[row]; 20857877fdebSMatt Macy vdev_raidz_reconstruct_row(rm, rr, t, nt); 20867877fdebSMatt Macy } 20877877fdebSMatt Macy } 20887877fdebSMatt Macy 20897877fdebSMatt Macy /* 20907877fdebSMatt Macy * Complete a write IO operation on a RAIDZ VDev 20917877fdebSMatt Macy * 20927877fdebSMatt Macy * Outline: 20937877fdebSMatt Macy * 1. Check for errors on the child IOs. 20947877fdebSMatt Macy * 2. Return, setting an error code if too few child VDevs were written 20957877fdebSMatt Macy * to reconstruct the data later. Note that partial writes are 20967877fdebSMatt Macy * considered successful if they can be reconstructed at all. 20977877fdebSMatt Macy */ 20987877fdebSMatt Macy static void 20997877fdebSMatt Macy vdev_raidz_io_done_write_impl(zio_t *zio, raidz_row_t *rr) 21007877fdebSMatt Macy { 21017877fdebSMatt Macy int total_errors = 0; 21027877fdebSMatt Macy 21037877fdebSMatt Macy ASSERT3U(rr->rr_missingparity, <=, rr->rr_firstdatacol); 21047877fdebSMatt Macy ASSERT3U(rr->rr_missingdata, <=, rr->rr_cols - rr->rr_firstdatacol); 21057877fdebSMatt Macy ASSERT3U(zio->io_type, ==, ZIO_TYPE_WRITE); 21067877fdebSMatt Macy 21077877fdebSMatt Macy for (int c = 0; c < rr->rr_cols; c++) { 21087877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 21097877fdebSMatt Macy 21107877fdebSMatt Macy if (rc->rc_error) { 21117877fdebSMatt Macy ASSERT(rc->rc_error != ECKSUM); /* child has no bp */ 21127877fdebSMatt Macy 21137877fdebSMatt Macy total_errors++; 21147877fdebSMatt Macy } 21157877fdebSMatt Macy } 21167877fdebSMatt Macy 21177877fdebSMatt Macy /* 21187877fdebSMatt Macy * Treat partial writes as a success. If we couldn't write enough 21197877fdebSMatt Macy * columns to reconstruct the data, the I/O failed. Otherwise, 21207877fdebSMatt Macy * good enough. 2121eda14cbcSMatt Macy * 2122eda14cbcSMatt Macy * Now that we support write reallocation, it would be better 2123eda14cbcSMatt Macy * to treat partial failure as real failure unless there are 2124eda14cbcSMatt Macy * no non-degraded top-level vdevs left, and not update DTLs 2125eda14cbcSMatt Macy * if we intend to reallocate. 2126eda14cbcSMatt Macy */ 21277877fdebSMatt Macy if (total_errors > rr->rr_firstdatacol) { 21287877fdebSMatt Macy zio->io_error = zio_worst_error(zio->io_error, 21297877fdebSMatt Macy vdev_raidz_worst_error(rr)); 21307877fdebSMatt Macy } 2131eda14cbcSMatt Macy } 2132eda14cbcSMatt Macy 2133*f9693befSMartin Matuska static void 21347877fdebSMatt Macy vdev_raidz_io_done_reconstruct_known_missing(zio_t *zio, raidz_map_t *rm, 21357877fdebSMatt Macy raidz_row_t *rr) 21367877fdebSMatt Macy { 21377877fdebSMatt Macy int parity_errors = 0; 21387877fdebSMatt Macy int parity_untried = 0; 21397877fdebSMatt Macy int data_errors = 0; 21407877fdebSMatt Macy int total_errors = 0; 21417877fdebSMatt Macy 21427877fdebSMatt Macy ASSERT3U(rr->rr_missingparity, <=, rr->rr_firstdatacol); 21437877fdebSMatt Macy ASSERT3U(rr->rr_missingdata, <=, rr->rr_cols - rr->rr_firstdatacol); 21447877fdebSMatt Macy ASSERT3U(zio->io_type, ==, ZIO_TYPE_READ); 21457877fdebSMatt Macy 21467877fdebSMatt Macy for (int c = 0; c < rr->rr_cols; c++) { 21477877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 21487877fdebSMatt Macy 21497877fdebSMatt Macy if (rc->rc_error) { 21507877fdebSMatt Macy ASSERT(rc->rc_error != ECKSUM); /* child has no bp */ 21517877fdebSMatt Macy 21527877fdebSMatt Macy if (c < rr->rr_firstdatacol) 21537877fdebSMatt Macy parity_errors++; 21547877fdebSMatt Macy else 21557877fdebSMatt Macy data_errors++; 21567877fdebSMatt Macy 21577877fdebSMatt Macy total_errors++; 21587877fdebSMatt Macy } else if (c < rr->rr_firstdatacol && !rc->rc_tried) { 21597877fdebSMatt Macy parity_untried++; 21607877fdebSMatt Macy } 21617877fdebSMatt Macy } 2162eda14cbcSMatt Macy 2163eda14cbcSMatt Macy /* 21647877fdebSMatt Macy * If there were data errors and the number of errors we saw was 21657877fdebSMatt Macy * correctable -- less than or equal to the number of parity disks read 21667877fdebSMatt Macy * -- reconstruct based on the missing data. 2167eda14cbcSMatt Macy */ 21687877fdebSMatt Macy if (data_errors != 0 && 21697877fdebSMatt Macy total_errors <= rr->rr_firstdatacol - parity_untried) { 2170eda14cbcSMatt Macy /* 2171eda14cbcSMatt Macy * We either attempt to read all the parity columns or 2172eda14cbcSMatt Macy * none of them. If we didn't try to read parity, we 2173eda14cbcSMatt Macy * wouldn't be here in the correctable case. There must 2174eda14cbcSMatt Macy * also have been fewer parity errors than parity 2175eda14cbcSMatt Macy * columns or, again, we wouldn't be in this code path. 2176eda14cbcSMatt Macy */ 2177eda14cbcSMatt Macy ASSERT(parity_untried == 0); 21787877fdebSMatt Macy ASSERT(parity_errors < rr->rr_firstdatacol); 2179eda14cbcSMatt Macy 2180eda14cbcSMatt Macy /* 2181eda14cbcSMatt Macy * Identify the data columns that reported an error. 2182eda14cbcSMatt Macy */ 21837877fdebSMatt Macy int n = 0; 21847877fdebSMatt Macy int tgts[VDEV_RAIDZ_MAXPARITY]; 21857877fdebSMatt Macy for (int c = rr->rr_firstdatacol; c < rr->rr_cols; c++) { 21867877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 2187eda14cbcSMatt Macy if (rc->rc_error != 0) { 2188eda14cbcSMatt Macy ASSERT(n < VDEV_RAIDZ_MAXPARITY); 2189eda14cbcSMatt Macy tgts[n++] = c; 2190eda14cbcSMatt Macy } 2191eda14cbcSMatt Macy } 2192eda14cbcSMatt Macy 21937877fdebSMatt Macy ASSERT(rr->rr_firstdatacol >= n); 2194eda14cbcSMatt Macy 2195*f9693befSMartin Matuska vdev_raidz_reconstruct_row(rm, rr, tgts, n); 2196eda14cbcSMatt Macy } 2197eda14cbcSMatt Macy } 2198eda14cbcSMatt Macy 2199eda14cbcSMatt Macy /* 22007877fdebSMatt Macy * Return the number of reads issued. 2201eda14cbcSMatt Macy */ 22027877fdebSMatt Macy static int 22037877fdebSMatt Macy vdev_raidz_read_all(zio_t *zio, raidz_row_t *rr) 22047877fdebSMatt Macy { 22057877fdebSMatt Macy vdev_t *vd = zio->io_vd; 22067877fdebSMatt Macy int nread = 0; 2207eda14cbcSMatt Macy 22087877fdebSMatt Macy rr->rr_missingdata = 0; 22097877fdebSMatt Macy rr->rr_missingparity = 0; 22107877fdebSMatt Macy 22117877fdebSMatt Macy /* 22127877fdebSMatt Macy * If this rows contains empty sectors which are not required 22137877fdebSMatt Macy * for a normal read then allocate an ABD for them now so they 22147877fdebSMatt Macy * may be read, verified, and any needed repairs performed. 22157877fdebSMatt Macy */ 22167877fdebSMatt Macy if (rr->rr_nempty && rr->rr_abd_empty == NULL) 22177877fdebSMatt Macy vdev_draid_map_alloc_empty(zio, rr); 22187877fdebSMatt Macy 22197877fdebSMatt Macy for (int c = 0; c < rr->rr_cols; c++) { 22207877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 22217877fdebSMatt Macy if (rc->rc_tried || rc->rc_size == 0) 2222eda14cbcSMatt Macy continue; 2223eda14cbcSMatt Macy 2224eda14cbcSMatt Macy zio_nowait(zio_vdev_child_io(zio, NULL, 2225eda14cbcSMatt Macy vd->vdev_child[rc->rc_devidx], 2226eda14cbcSMatt Macy rc->rc_offset, rc->rc_abd, rc->rc_size, 2227eda14cbcSMatt Macy zio->io_type, zio->io_priority, 0, 2228eda14cbcSMatt Macy vdev_raidz_child_done, rc)); 22297877fdebSMatt Macy nread++; 22307877fdebSMatt Macy } 22317877fdebSMatt Macy return (nread); 2232eda14cbcSMatt Macy } 2233eda14cbcSMatt Macy 2234eda14cbcSMatt Macy /* 22357877fdebSMatt Macy * We're here because either there were too many errors to even attempt 22367877fdebSMatt Macy * reconstruction (total_errors == rm_first_datacol), or vdev_*_combrec() 22377877fdebSMatt Macy * failed. In either case, there is enough bad data to prevent reconstruction. 22387877fdebSMatt Macy * Start checksum ereports for all children which haven't failed. 2239eda14cbcSMatt Macy */ 22407877fdebSMatt Macy static void 22417877fdebSMatt Macy vdev_raidz_io_done_unrecoverable(zio_t *zio) 22427877fdebSMatt Macy { 22437877fdebSMatt Macy raidz_map_t *rm = zio->io_vsd; 2244eda14cbcSMatt Macy 22457877fdebSMatt Macy for (int i = 0; i < rm->rm_nrows; i++) { 22467877fdebSMatt Macy raidz_row_t *rr = rm->rm_row[i]; 2247eda14cbcSMatt Macy 22487877fdebSMatt Macy for (int c = 0; c < rr->rr_cols; c++) { 22497877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 22507877fdebSMatt Macy vdev_t *cvd = zio->io_vd->vdev_child[rc->rc_devidx]; 22517877fdebSMatt Macy 22522c48331dSMatt Macy if (rc->rc_error != 0) 22532c48331dSMatt Macy continue; 22542c48331dSMatt Macy 2255eda14cbcSMatt Macy zio_bad_cksum_t zbc; 2256eda14cbcSMatt Macy zbc.zbc_has_cksum = 0; 22572c48331dSMatt Macy zbc.zbc_injected = rm->rm_ecksuminjected; 2258eda14cbcSMatt Macy 2259ba27dd8bSMartin Matuska (void) zfs_ereport_start_checksum(zio->io_spa, 22607877fdebSMatt Macy cvd, &zio->io_bookmark, zio, rc->rc_offset, 2261*f9693befSMartin Matuska rc->rc_size, &zbc); 2262eda14cbcSMatt Macy mutex_enter(&cvd->vdev_stat_lock); 2263eda14cbcSMatt Macy cvd->vdev_stat.vs_checksum_errors++; 2264eda14cbcSMatt Macy mutex_exit(&cvd->vdev_stat_lock); 2265eda14cbcSMatt Macy } 2266eda14cbcSMatt Macy } 2267eda14cbcSMatt Macy } 2268eda14cbcSMatt Macy 22697877fdebSMatt Macy void 22707877fdebSMatt Macy vdev_raidz_io_done(zio_t *zio) 22717877fdebSMatt Macy { 22727877fdebSMatt Macy raidz_map_t *rm = zio->io_vsd; 22737877fdebSMatt Macy 22747877fdebSMatt Macy if (zio->io_type == ZIO_TYPE_WRITE) { 22757877fdebSMatt Macy for (int i = 0; i < rm->rm_nrows; i++) { 22767877fdebSMatt Macy vdev_raidz_io_done_write_impl(zio, rm->rm_row[i]); 22777877fdebSMatt Macy } 22787877fdebSMatt Macy } else { 22797877fdebSMatt Macy for (int i = 0; i < rm->rm_nrows; i++) { 22807877fdebSMatt Macy raidz_row_t *rr = rm->rm_row[i]; 22817877fdebSMatt Macy vdev_raidz_io_done_reconstruct_known_missing(zio, 22827877fdebSMatt Macy rm, rr); 22837877fdebSMatt Macy } 22847877fdebSMatt Macy 22857877fdebSMatt Macy if (raidz_checksum_verify(zio) == 0) { 22867877fdebSMatt Macy for (int i = 0; i < rm->rm_nrows; i++) { 22877877fdebSMatt Macy raidz_row_t *rr = rm->rm_row[i]; 22887877fdebSMatt Macy vdev_raidz_io_done_verified(zio, rr); 22897877fdebSMatt Macy } 2290eda14cbcSMatt Macy zio_checksum_verified(zio); 22917877fdebSMatt Macy } else { 2292eda14cbcSMatt Macy /* 22937877fdebSMatt Macy * A sequential resilver has no checksum which makes 22947877fdebSMatt Macy * combinatoral reconstruction impossible. This code 22957877fdebSMatt Macy * path is unreachable since raidz_checksum_verify() 22967877fdebSMatt Macy * has no checksum to verify and must succeed. 2297eda14cbcSMatt Macy */ 22987877fdebSMatt Macy ASSERT3U(zio->io_priority, !=, ZIO_PRIORITY_REBUILD); 2299eda14cbcSMatt Macy 23007877fdebSMatt Macy /* 23017877fdebSMatt Macy * This isn't a typical situation -- either we got a 23027877fdebSMatt Macy * read error or a child silently returned bad data. 23037877fdebSMatt Macy * Read every block so we can try again with as much 23047877fdebSMatt Macy * data and parity as we can track down. If we've 23057877fdebSMatt Macy * already been through once before, all children will 23067877fdebSMatt Macy * be marked as tried so we'll proceed to combinatorial 23077877fdebSMatt Macy * reconstruction. 23087877fdebSMatt Macy */ 23097877fdebSMatt Macy int nread = 0; 23107877fdebSMatt Macy for (int i = 0; i < rm->rm_nrows; i++) { 23117877fdebSMatt Macy nread += vdev_raidz_read_all(zio, 23127877fdebSMatt Macy rm->rm_row[i]); 23137877fdebSMatt Macy } 23147877fdebSMatt Macy if (nread != 0) { 23157877fdebSMatt Macy /* 23167877fdebSMatt Macy * Normally our stage is VDEV_IO_DONE, but if 23177877fdebSMatt Macy * we've already called redone(), it will have 23187877fdebSMatt Macy * changed to VDEV_IO_START, in which case we 23197877fdebSMatt Macy * don't want to call redone() again. 23207877fdebSMatt Macy */ 23217877fdebSMatt Macy if (zio->io_stage != ZIO_STAGE_VDEV_IO_START) 23227877fdebSMatt Macy zio_vdev_io_redone(zio); 23237877fdebSMatt Macy return; 23247877fdebSMatt Macy } 2325eda14cbcSMatt Macy 23267877fdebSMatt Macy zio->io_error = vdev_raidz_combrec(zio); 23277877fdebSMatt Macy if (zio->io_error == ECKSUM && 23287877fdebSMatt Macy !(zio->io_flags & ZIO_FLAG_SPECULATIVE)) { 23297877fdebSMatt Macy vdev_raidz_io_done_unrecoverable(zio); 23307877fdebSMatt Macy } 2331eda14cbcSMatt Macy } 2332eda14cbcSMatt Macy } 2333eda14cbcSMatt Macy } 2334eda14cbcSMatt Macy 2335eda14cbcSMatt Macy static void 2336eda14cbcSMatt Macy vdev_raidz_state_change(vdev_t *vd, int faulted, int degraded) 2337eda14cbcSMatt Macy { 23387877fdebSMatt Macy vdev_raidz_t *vdrz = vd->vdev_tsd; 23397877fdebSMatt Macy if (faulted > vdrz->vd_nparity) 2340eda14cbcSMatt Macy vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN, 2341eda14cbcSMatt Macy VDEV_AUX_NO_REPLICAS); 2342eda14cbcSMatt Macy else if (degraded + faulted != 0) 2343eda14cbcSMatt Macy vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, VDEV_AUX_NONE); 2344eda14cbcSMatt Macy else 2345eda14cbcSMatt Macy vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE); 2346eda14cbcSMatt Macy } 2347eda14cbcSMatt Macy 2348eda14cbcSMatt Macy /* 2349eda14cbcSMatt Macy * Determine if any portion of the provided block resides on a child vdev 2350eda14cbcSMatt Macy * with a dirty DTL and therefore needs to be resilvered. The function 2351eda14cbcSMatt Macy * assumes that at least one DTL is dirty which implies that full stripe 2352eda14cbcSMatt Macy * width blocks must be resilvered. 2353eda14cbcSMatt Macy */ 2354eda14cbcSMatt Macy static boolean_t 23557877fdebSMatt Macy vdev_raidz_need_resilver(vdev_t *vd, const dva_t *dva, size_t psize, 23567877fdebSMatt Macy uint64_t phys_birth) 2357eda14cbcSMatt Macy { 23587877fdebSMatt Macy vdev_raidz_t *vdrz = vd->vdev_tsd; 2359eda14cbcSMatt Macy uint64_t dcols = vd->vdev_children; 23607877fdebSMatt Macy uint64_t nparity = vdrz->vd_nparity; 2361eda14cbcSMatt Macy uint64_t ashift = vd->vdev_top->vdev_ashift; 2362eda14cbcSMatt Macy /* The starting RAIDZ (parent) vdev sector of the block. */ 23637877fdebSMatt Macy uint64_t b = DVA_GET_OFFSET(dva) >> ashift; 2364eda14cbcSMatt Macy /* The zio's size in units of the vdev's minimum sector size. */ 2365eda14cbcSMatt Macy uint64_t s = ((psize - 1) >> ashift) + 1; 2366eda14cbcSMatt Macy /* The first column for this stripe. */ 2367eda14cbcSMatt Macy uint64_t f = b % dcols; 2368eda14cbcSMatt Macy 23697877fdebSMatt Macy /* Unreachable by sequential resilver. */ 23707877fdebSMatt Macy ASSERT3U(phys_birth, !=, TXG_UNKNOWN); 23717877fdebSMatt Macy 23727877fdebSMatt Macy if (!vdev_dtl_contains(vd, DTL_PARTIAL, phys_birth, 1)) 23737877fdebSMatt Macy return (B_FALSE); 23747877fdebSMatt Macy 2375eda14cbcSMatt Macy if (s + nparity >= dcols) 2376eda14cbcSMatt Macy return (B_TRUE); 2377eda14cbcSMatt Macy 2378eda14cbcSMatt Macy for (uint64_t c = 0; c < s + nparity; c++) { 2379eda14cbcSMatt Macy uint64_t devidx = (f + c) % dcols; 2380eda14cbcSMatt Macy vdev_t *cvd = vd->vdev_child[devidx]; 2381eda14cbcSMatt Macy 2382eda14cbcSMatt Macy /* 2383eda14cbcSMatt Macy * dsl_scan_need_resilver() already checked vd with 2384eda14cbcSMatt Macy * vdev_dtl_contains(). So here just check cvd with 2385eda14cbcSMatt Macy * vdev_dtl_empty(), cheaper and a good approximation. 2386eda14cbcSMatt Macy */ 2387eda14cbcSMatt Macy if (!vdev_dtl_empty(cvd, DTL_PARTIAL)) 2388eda14cbcSMatt Macy return (B_TRUE); 2389eda14cbcSMatt Macy } 2390eda14cbcSMatt Macy 2391eda14cbcSMatt Macy return (B_FALSE); 2392eda14cbcSMatt Macy } 2393eda14cbcSMatt Macy 2394eda14cbcSMatt Macy static void 23957877fdebSMatt Macy vdev_raidz_xlate(vdev_t *cvd, const range_seg64_t *logical_rs, 23967877fdebSMatt Macy range_seg64_t *physical_rs, range_seg64_t *remain_rs) 2397eda14cbcSMatt Macy { 2398eda14cbcSMatt Macy vdev_t *raidvd = cvd->vdev_parent; 2399eda14cbcSMatt Macy ASSERT(raidvd->vdev_ops == &vdev_raidz_ops); 2400eda14cbcSMatt Macy 2401eda14cbcSMatt Macy uint64_t width = raidvd->vdev_children; 2402eda14cbcSMatt Macy uint64_t tgt_col = cvd->vdev_id; 2403eda14cbcSMatt Macy uint64_t ashift = raidvd->vdev_top->vdev_ashift; 2404eda14cbcSMatt Macy 2405eda14cbcSMatt Macy /* make sure the offsets are block-aligned */ 24067877fdebSMatt Macy ASSERT0(logical_rs->rs_start % (1 << ashift)); 24077877fdebSMatt Macy ASSERT0(logical_rs->rs_end % (1 << ashift)); 24087877fdebSMatt Macy uint64_t b_start = logical_rs->rs_start >> ashift; 24097877fdebSMatt Macy uint64_t b_end = logical_rs->rs_end >> ashift; 2410eda14cbcSMatt Macy 2411eda14cbcSMatt Macy uint64_t start_row = 0; 2412eda14cbcSMatt Macy if (b_start > tgt_col) /* avoid underflow */ 2413eda14cbcSMatt Macy start_row = ((b_start - tgt_col - 1) / width) + 1; 2414eda14cbcSMatt Macy 2415eda14cbcSMatt Macy uint64_t end_row = 0; 2416eda14cbcSMatt Macy if (b_end > tgt_col) 2417eda14cbcSMatt Macy end_row = ((b_end - tgt_col - 1) / width) + 1; 2418eda14cbcSMatt Macy 24197877fdebSMatt Macy physical_rs->rs_start = start_row << ashift; 24207877fdebSMatt Macy physical_rs->rs_end = end_row << ashift; 2421eda14cbcSMatt Macy 24227877fdebSMatt Macy ASSERT3U(physical_rs->rs_start, <=, logical_rs->rs_start); 24237877fdebSMatt Macy ASSERT3U(physical_rs->rs_end - physical_rs->rs_start, <=, 24247877fdebSMatt Macy logical_rs->rs_end - logical_rs->rs_start); 24257877fdebSMatt Macy } 24267877fdebSMatt Macy 24277877fdebSMatt Macy /* 24287877fdebSMatt Macy * Initialize private RAIDZ specific fields from the nvlist. 24297877fdebSMatt Macy */ 24307877fdebSMatt Macy static int 24317877fdebSMatt Macy vdev_raidz_init(spa_t *spa, nvlist_t *nv, void **tsd) 24327877fdebSMatt Macy { 24337877fdebSMatt Macy vdev_raidz_t *vdrz; 24347877fdebSMatt Macy uint64_t nparity; 24357877fdebSMatt Macy 24367877fdebSMatt Macy uint_t children; 24377877fdebSMatt Macy nvlist_t **child; 24387877fdebSMatt Macy int error = nvlist_lookup_nvlist_array(nv, 24397877fdebSMatt Macy ZPOOL_CONFIG_CHILDREN, &child, &children); 24407877fdebSMatt Macy if (error != 0) 24417877fdebSMatt Macy return (SET_ERROR(EINVAL)); 24427877fdebSMatt Macy 24437877fdebSMatt Macy if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NPARITY, &nparity) == 0) { 24447877fdebSMatt Macy if (nparity == 0 || nparity > VDEV_RAIDZ_MAXPARITY) 24457877fdebSMatt Macy return (SET_ERROR(EINVAL)); 24467877fdebSMatt Macy 24477877fdebSMatt Macy /* 24487877fdebSMatt Macy * Previous versions could only support 1 or 2 parity 24497877fdebSMatt Macy * device. 24507877fdebSMatt Macy */ 24517877fdebSMatt Macy if (nparity > 1 && spa_version(spa) < SPA_VERSION_RAIDZ2) 24527877fdebSMatt Macy return (SET_ERROR(EINVAL)); 24537877fdebSMatt Macy else if (nparity > 2 && spa_version(spa) < SPA_VERSION_RAIDZ3) 24547877fdebSMatt Macy return (SET_ERROR(EINVAL)); 24557877fdebSMatt Macy } else { 24567877fdebSMatt Macy /* 24577877fdebSMatt Macy * We require the parity to be specified for SPAs that 24587877fdebSMatt Macy * support multiple parity levels. 24597877fdebSMatt Macy */ 24607877fdebSMatt Macy if (spa_version(spa) >= SPA_VERSION_RAIDZ2) 24617877fdebSMatt Macy return (SET_ERROR(EINVAL)); 24627877fdebSMatt Macy 24637877fdebSMatt Macy /* 24647877fdebSMatt Macy * Otherwise, we default to 1 parity device for RAID-Z. 24657877fdebSMatt Macy */ 24667877fdebSMatt Macy nparity = 1; 24677877fdebSMatt Macy } 24687877fdebSMatt Macy 24697877fdebSMatt Macy vdrz = kmem_zalloc(sizeof (*vdrz), KM_SLEEP); 24707877fdebSMatt Macy vdrz->vd_logical_width = children; 24717877fdebSMatt Macy vdrz->vd_nparity = nparity; 24727877fdebSMatt Macy 24737877fdebSMatt Macy *tsd = vdrz; 24747877fdebSMatt Macy 24757877fdebSMatt Macy return (0); 24767877fdebSMatt Macy } 24777877fdebSMatt Macy 24787877fdebSMatt Macy static void 24797877fdebSMatt Macy vdev_raidz_fini(vdev_t *vd) 24807877fdebSMatt Macy { 24817877fdebSMatt Macy kmem_free(vd->vdev_tsd, sizeof (vdev_raidz_t)); 24827877fdebSMatt Macy } 24837877fdebSMatt Macy 24847877fdebSMatt Macy /* 24857877fdebSMatt Macy * Add RAIDZ specific fields to the config nvlist. 24867877fdebSMatt Macy */ 24877877fdebSMatt Macy static void 24887877fdebSMatt Macy vdev_raidz_config_generate(vdev_t *vd, nvlist_t *nv) 24897877fdebSMatt Macy { 24907877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_raidz_ops); 24917877fdebSMatt Macy vdev_raidz_t *vdrz = vd->vdev_tsd; 24927877fdebSMatt Macy 24937877fdebSMatt Macy /* 24947877fdebSMatt Macy * Make sure someone hasn't managed to sneak a fancy new vdev 24957877fdebSMatt Macy * into a crufty old storage pool. 24967877fdebSMatt Macy */ 24977877fdebSMatt Macy ASSERT(vdrz->vd_nparity == 1 || 24987877fdebSMatt Macy (vdrz->vd_nparity <= 2 && 24997877fdebSMatt Macy spa_version(vd->vdev_spa) >= SPA_VERSION_RAIDZ2) || 25007877fdebSMatt Macy (vdrz->vd_nparity <= 3 && 25017877fdebSMatt Macy spa_version(vd->vdev_spa) >= SPA_VERSION_RAIDZ3)); 25027877fdebSMatt Macy 25037877fdebSMatt Macy /* 25047877fdebSMatt Macy * Note that we'll add these even on storage pools where they 25057877fdebSMatt Macy * aren't strictly required -- older software will just ignore 25067877fdebSMatt Macy * it. 25077877fdebSMatt Macy */ 25087877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_NPARITY, vdrz->vd_nparity); 25097877fdebSMatt Macy } 25107877fdebSMatt Macy 25117877fdebSMatt Macy static uint64_t 25127877fdebSMatt Macy vdev_raidz_nparity(vdev_t *vd) 25137877fdebSMatt Macy { 25147877fdebSMatt Macy vdev_raidz_t *vdrz = vd->vdev_tsd; 25157877fdebSMatt Macy return (vdrz->vd_nparity); 25167877fdebSMatt Macy } 25177877fdebSMatt Macy 25187877fdebSMatt Macy static uint64_t 25197877fdebSMatt Macy vdev_raidz_ndisks(vdev_t *vd) 25207877fdebSMatt Macy { 25217877fdebSMatt Macy return (vd->vdev_children); 2522eda14cbcSMatt Macy } 2523eda14cbcSMatt Macy 2524eda14cbcSMatt Macy vdev_ops_t vdev_raidz_ops = { 25257877fdebSMatt Macy .vdev_op_init = vdev_raidz_init, 25267877fdebSMatt Macy .vdev_op_fini = vdev_raidz_fini, 2527eda14cbcSMatt Macy .vdev_op_open = vdev_raidz_open, 2528eda14cbcSMatt Macy .vdev_op_close = vdev_raidz_close, 2529eda14cbcSMatt Macy .vdev_op_asize = vdev_raidz_asize, 25307877fdebSMatt Macy .vdev_op_min_asize = vdev_raidz_min_asize, 25317877fdebSMatt Macy .vdev_op_min_alloc = NULL, 2532eda14cbcSMatt Macy .vdev_op_io_start = vdev_raidz_io_start, 2533eda14cbcSMatt Macy .vdev_op_io_done = vdev_raidz_io_done, 2534eda14cbcSMatt Macy .vdev_op_state_change = vdev_raidz_state_change, 2535eda14cbcSMatt Macy .vdev_op_need_resilver = vdev_raidz_need_resilver, 2536eda14cbcSMatt Macy .vdev_op_hold = NULL, 2537eda14cbcSMatt Macy .vdev_op_rele = NULL, 2538eda14cbcSMatt Macy .vdev_op_remap = NULL, 2539eda14cbcSMatt Macy .vdev_op_xlate = vdev_raidz_xlate, 25407877fdebSMatt Macy .vdev_op_rebuild_asize = NULL, 25417877fdebSMatt Macy .vdev_op_metaslab_init = NULL, 25427877fdebSMatt Macy .vdev_op_config_generate = vdev_raidz_config_generate, 25437877fdebSMatt Macy .vdev_op_nparity = vdev_raidz_nparity, 25447877fdebSMatt Macy .vdev_op_ndisks = vdev_raidz_ndisks, 2545eda14cbcSMatt Macy .vdev_op_type = VDEV_TYPE_RAIDZ, /* name of this vdev type */ 2546eda14cbcSMatt Macy .vdev_op_leaf = B_FALSE /* not a leaf vdev */ 2547eda14cbcSMatt Macy }; 2548