17877fdebSMatt Macy /* 27877fdebSMatt Macy * CDDL HEADER START 37877fdebSMatt Macy * 47877fdebSMatt Macy * The contents of this file are subject to the terms of the 57877fdebSMatt Macy * Common Development and Distribution License (the "License"). 67877fdebSMatt Macy * You may not use this file except in compliance with the License. 77877fdebSMatt Macy * 87877fdebSMatt Macy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97877fdebSMatt Macy * or http://www.opensolaris.org/os/licensing. 107877fdebSMatt Macy * See the License for the specific language governing permissions 117877fdebSMatt Macy * and limitations under the License. 127877fdebSMatt Macy * 137877fdebSMatt Macy * When distributing Covered Code, include this CDDL HEADER in each 147877fdebSMatt Macy * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157877fdebSMatt Macy * If applicable, add the following below this CDDL HEADER, with the 167877fdebSMatt Macy * fields enclosed by brackets "[]" replaced with your own identifying 177877fdebSMatt Macy * information: Portions Copyright [yyyy] [name of copyright owner] 187877fdebSMatt Macy * 197877fdebSMatt Macy * CDDL HEADER END 207877fdebSMatt Macy */ 217877fdebSMatt Macy /* 227877fdebSMatt Macy * Copyright (c) 2018 Intel Corporation. 237877fdebSMatt Macy * Copyright (c) 2020 by Lawrence Livermore National Security, LLC. 247877fdebSMatt Macy */ 257877fdebSMatt Macy 267877fdebSMatt Macy #include <sys/zfs_context.h> 277877fdebSMatt Macy #include <sys/spa.h> 287877fdebSMatt Macy #include <sys/spa_impl.h> 297877fdebSMatt Macy #include <sys/vdev_impl.h> 307877fdebSMatt Macy #include <sys/vdev_draid.h> 317877fdebSMatt Macy #include <sys/vdev_raidz.h> 327877fdebSMatt Macy #include <sys/vdev_rebuild.h> 337877fdebSMatt Macy #include <sys/abd.h> 347877fdebSMatt Macy #include <sys/zio.h> 357877fdebSMatt Macy #include <sys/nvpair.h> 367877fdebSMatt Macy #include <sys/zio_checksum.h> 377877fdebSMatt Macy #include <sys/fs/zfs.h> 387877fdebSMatt Macy #include <sys/fm/fs/zfs.h> 397877fdebSMatt Macy #include <zfs_fletcher.h> 407877fdebSMatt Macy 417877fdebSMatt Macy #ifdef ZFS_DEBUG 427877fdebSMatt Macy #include <sys/vdev.h> /* For vdev_xlate() in vdev_draid_io_verify() */ 437877fdebSMatt Macy #endif 447877fdebSMatt Macy 457877fdebSMatt Macy /* 467877fdebSMatt Macy * dRAID is a distributed spare implementation for ZFS. A dRAID vdev is 477877fdebSMatt Macy * comprised of multiple raidz redundancy groups which are spread over the 487877fdebSMatt Macy * dRAID children. To ensure an even distribution, and avoid hot spots, a 497877fdebSMatt Macy * permutation mapping is applied to the order of the dRAID children. 507877fdebSMatt Macy * This mixing effectively distributes the parity columns evenly over all 517877fdebSMatt Macy * of the disks in the dRAID. 527877fdebSMatt Macy * 537877fdebSMatt Macy * This is beneficial because it means when resilvering all of the disks 547877fdebSMatt Macy * can participate thereby increasing the available IOPs and bandwidth. 557877fdebSMatt Macy * Furthermore, by reserving a small fraction of each child's total capacity 567877fdebSMatt Macy * virtual distributed spare disks can be created. These spares similarly 577877fdebSMatt Macy * benefit from the performance gains of spanning all of the children. The 587877fdebSMatt Macy * consequence of which is that resilvering to a distributed spare can 597877fdebSMatt Macy * substantially reduce the time required to restore full parity to pool 607877fdebSMatt Macy * with a failed disks. 617877fdebSMatt Macy * 627877fdebSMatt Macy * === dRAID group layout === 637877fdebSMatt Macy * 647877fdebSMatt Macy * First, let's define a "row" in the configuration to be a 16M chunk from 657877fdebSMatt Macy * each physical drive at the same offset. This is the minimum allowable 667877fdebSMatt Macy * size since it must be possible to store a full 16M block when there is 677877fdebSMatt Macy * only a single data column. Next, we define a "group" to be a set of 687877fdebSMatt Macy * sequential disks containing both the parity and data columns. We allow 697877fdebSMatt Macy * groups to span multiple rows in order to align any group size to any 707877fdebSMatt Macy * number of physical drives. Finally, a "slice" is comprised of the rows 717877fdebSMatt Macy * which contain the target number of groups. The permutation mappings 727877fdebSMatt Macy * are applied in a round robin fashion to each slice. 737877fdebSMatt Macy * 747877fdebSMatt Macy * Given D+P drives in a group (including parity drives) and C-S physical 757877fdebSMatt Macy * drives (not including the spare drives), we can distribute the groups 767877fdebSMatt Macy * across R rows without remainder by selecting the least common multiple 777877fdebSMatt Macy * of D+P and C-S as the number of groups; i.e. ngroups = LCM(D+P, C-S). 787877fdebSMatt Macy * 797877fdebSMatt Macy * In the example below, there are C=14 physical drives in the configuration 807877fdebSMatt Macy * with S=2 drives worth of spare capacity. Each group has a width of 9 817877fdebSMatt Macy * which includes D=8 data and P=1 parity drive. There are 4 groups and 827877fdebSMatt Macy * 3 rows per slice. Each group has a size of 144M (16M * 9) and a slice 837877fdebSMatt Macy * size is 576M (144M * 4). When allocating from a dRAID each group is 847877fdebSMatt Macy * filled before moving on to the next as show in slice0 below. 857877fdebSMatt Macy * 867877fdebSMatt Macy * data disks (8 data + 1 parity) spares (2) 877877fdebSMatt Macy * +===+===+===+===+===+===+===+===+===+===+===+===+===+===+ 887877fdebSMatt Macy * ^ | 2 | 6 | 1 | 11| 4 | 0 | 7 | 10| 8 | 9 | 13| 5 | 12| 3 | device map 0 897877fdebSMatt Macy * | +===+===+===+===+===+===+===+===+===+===+===+===+===+===+ 907877fdebSMatt Macy * | | group 0 | group 1..| | 917877fdebSMatt Macy * | +-----------------------------------+-----------+-------| 927877fdebSMatt Macy * | | 0 1 2 3 4 5 6 7 8 | 36 37 38| | r 937877fdebSMatt Macy * | | 9 10 11 12 13 14 15 16 17| 45 46 47| | o 947877fdebSMatt Macy * | | 18 19 20 21 22 23 24 25 26| 54 55 56| | w 957877fdebSMatt Macy * | 27 28 29 30 31 32 33 34 35| 63 64 65| | 0 967877fdebSMatt Macy * s +-----------------------+-----------------------+-------+ 977877fdebSMatt Macy * l | ..group 1 | group 2.. | | 987877fdebSMatt Macy * i +-----------------------+-----------------------+-------+ 997877fdebSMatt Macy * c | 39 40 41 42 43 44| 72 73 74 75 76 77| | r 1007877fdebSMatt Macy * e | 48 49 50 51 52 53| 81 82 83 84 85 86| | o 1017877fdebSMatt Macy * 0 | 57 58 59 60 61 62| 90 91 92 93 94 95| | w 1027877fdebSMatt Macy * | 66 67 68 69 70 71| 99 100 101 102 103 104| | 1 1037877fdebSMatt Macy * | +-----------+-----------+-----------------------+-------+ 1047877fdebSMatt Macy * | |..group 2 | group 3 | | 1057877fdebSMatt Macy * | +-----------+-----------+-----------------------+-------+ 1067877fdebSMatt Macy * | | 78 79 80|108 109 110 111 112 113 114 115 116| | r 1077877fdebSMatt Macy * | | 87 88 89|117 118 119 120 121 122 123 124 125| | o 1087877fdebSMatt Macy * | | 96 97 98|126 127 128 129 130 131 132 133 134| | w 1097877fdebSMatt Macy * v |105 106 107|135 136 137 138 139 140 141 142 143| | 2 1107877fdebSMatt Macy * +===+===+===+===+===+===+===+===+===+===+===+===+===+===+ 1117877fdebSMatt Macy * | 9 | 11| 12| 2 | 4 | 1 | 3 | 0 | 10| 13| 8 | 5 | 6 | 7 | device map 1 1127877fdebSMatt Macy * s +===+===+===+===+===+===+===+===+===+===+===+===+===+===+ 1137877fdebSMatt Macy * l | group 4 | group 5..| | row 3 1147877fdebSMatt Macy * i +-----------------------+-----------+-----------+-------| 1157877fdebSMatt Macy * c | ..group 5 | group 6.. | | row 4 1167877fdebSMatt Macy * e +-----------+-----------+-----------------------+-------+ 1177877fdebSMatt Macy * 1 |..group 6 | group 7 | | row 5 1187877fdebSMatt Macy * +===+===+===+===+===+===+===+===+===+===+===+===+===+===+ 1197877fdebSMatt Macy * | 3 | 5 | 10| 8 | 6 | 11| 12| 0 | 2 | 4 | 7 | 1 | 9 | 13| device map 2 1207877fdebSMatt Macy * s +===+===+===+===+===+===+===+===+===+===+===+===+===+===+ 1217877fdebSMatt Macy * l | group 8 | group 9..| | row 6 1227877fdebSMatt Macy * i +-----------------------------------------------+-------| 1237877fdebSMatt Macy * c | ..group 9 | group 10.. | | row 7 1247877fdebSMatt Macy * e +-----------------------+-----------------------+-------+ 1257877fdebSMatt Macy * 2 |..group 10 | group 11 | | row 8 1267877fdebSMatt Macy * +-----------+-----------------------------------+-------+ 1277877fdebSMatt Macy * 1287877fdebSMatt Macy * This layout has several advantages over requiring that each row contain 1297877fdebSMatt Macy * a whole number of groups. 1307877fdebSMatt Macy * 1317877fdebSMatt Macy * 1. The group count is not a relevant parameter when defining a dRAID 1327877fdebSMatt Macy * layout. Only the group width is needed, and *all* groups will have 1337877fdebSMatt Macy * the desired size. 1347877fdebSMatt Macy * 1357877fdebSMatt Macy * 2. All possible group widths (<= physical disk count) can be supported. 1367877fdebSMatt Macy * 1377877fdebSMatt Macy * 3. The logic within vdev_draid.c is simplified when the group width is 1387877fdebSMatt Macy * the same for all groups (although some of the logic around computing 1397877fdebSMatt Macy * permutation numbers and drive offsets is more complicated). 1407877fdebSMatt Macy * 1417877fdebSMatt Macy * N.B. The following array describes all valid dRAID permutation maps. 1427877fdebSMatt Macy * Each row is used to generate a permutation map for a different number 1437877fdebSMatt Macy * of children from a unique seed. The seeds were generated and carefully 1447877fdebSMatt Macy * evaluated by the 'draid' utility in order to provide balanced mappings. 1457877fdebSMatt Macy * In addition to the seed a checksum of the in-memory mapping is stored 1467877fdebSMatt Macy * for verification. 1477877fdebSMatt Macy * 1487877fdebSMatt Macy * The imbalance ratio of a given failure (e.g. 5 disks wide, child 3 failed, 1497877fdebSMatt Macy * with a given permutation map) is the ratio of the amounts of I/O that will 1507877fdebSMatt Macy * be sent to the least and most busy disks when resilvering. The average 1517877fdebSMatt Macy * imbalance ratio (of a given number of disks and permutation map) is the 1527877fdebSMatt Macy * average of the ratios of all possible single and double disk failures. 1537877fdebSMatt Macy * 1547877fdebSMatt Macy * In order to achieve a low imbalance ratio the number of permutations in 1557877fdebSMatt Macy * the mapping must be significantly larger than the number of children. 1567877fdebSMatt Macy * For dRAID the number of permutations has been limited to 512 to minimize 1577877fdebSMatt Macy * the map size. This does result in a gradually increasing imbalance ratio 1587877fdebSMatt Macy * as seen in the table below. Increasing the number of permutations for 1597877fdebSMatt Macy * larger child counts would reduce the imbalance ratio. However, in practice 1607877fdebSMatt Macy * when there are a large number of children each child is responsible for 1617877fdebSMatt Macy * fewer total IOs so it's less of a concern. 1627877fdebSMatt Macy * 1637877fdebSMatt Macy * Note these values are hard coded and must never be changed. Existing 1647877fdebSMatt Macy * pools depend on the same mapping always being generated in order to 1657877fdebSMatt Macy * read and write from the correct locations. Any change would make 1667877fdebSMatt Macy * existing pools completely inaccessible. 1677877fdebSMatt Macy */ 1687877fdebSMatt Macy static const draid_map_t draid_maps[VDEV_DRAID_MAX_MAPS] = { 1697877fdebSMatt Macy { 2, 256, 0x89ef3dabbcc7de37, 0x00000000433d433d }, /* 1.000 */ 1707877fdebSMatt Macy { 3, 256, 0x89a57f3de98121b4, 0x00000000bcd8b7b5 }, /* 1.000 */ 1717877fdebSMatt Macy { 4, 256, 0xc9ea9ec82340c885, 0x00000001819d7c69 }, /* 1.000 */ 1727877fdebSMatt Macy { 5, 256, 0xf46733b7f4d47dfd, 0x00000002a1648d74 }, /* 1.010 */ 1737877fdebSMatt Macy { 6, 256, 0x88c3c62d8585b362, 0x00000003d3b0c2c4 }, /* 1.031 */ 1747877fdebSMatt Macy { 7, 256, 0x3a65d809b4d1b9d5, 0x000000055c4183ee }, /* 1.043 */ 1757877fdebSMatt Macy { 8, 256, 0xe98930e3c5d2e90a, 0x00000006edfb0329 }, /* 1.059 */ 1767877fdebSMatt Macy { 9, 256, 0x5a5430036b982ccb, 0x00000008ceaf6934 }, /* 1.056 */ 1777877fdebSMatt Macy { 10, 256, 0x92bf389e9eadac74, 0x0000000b26668c09 }, /* 1.072 */ 1787877fdebSMatt Macy { 11, 256, 0x74ccebf1dcf3ae80, 0x0000000dd691358c }, /* 1.083 */ 1797877fdebSMatt Macy { 12, 256, 0x8847e41a1a9f5671, 0x00000010a0c63c8e }, /* 1.097 */ 1807877fdebSMatt Macy { 13, 256, 0x7481b56debf0e637, 0x0000001424121fe4 }, /* 1.100 */ 1817877fdebSMatt Macy { 14, 256, 0x559b8c44065f8967, 0x00000016ab2ff079 }, /* 1.121 */ 1827877fdebSMatt Macy { 15, 256, 0x34c49545a2ee7f01, 0x0000001a6028efd6 }, /* 1.103 */ 1837877fdebSMatt Macy { 16, 256, 0xb85f4fa81a7698f7, 0x0000001e95ff5e66 }, /* 1.111 */ 1847877fdebSMatt Macy { 17, 256, 0x6353e47b7e47aba0, 0x00000021a81fa0fe }, /* 1.133 */ 1857877fdebSMatt Macy { 18, 256, 0xaa549746b1cbb81c, 0x00000026f02494c9 }, /* 1.131 */ 1867877fdebSMatt Macy { 19, 256, 0x892e343f2f31d690, 0x00000029eb392835 }, /* 1.130 */ 1877877fdebSMatt Macy { 20, 256, 0x76914824db98cc3f, 0x0000003004f31a7c }, /* 1.141 */ 1887877fdebSMatt Macy { 21, 256, 0x4b3cbabf9cfb1d0f, 0x00000036363a2408 }, /* 1.139 */ 1897877fdebSMatt Macy { 22, 256, 0xf45c77abb4f035d4, 0x00000038dd0f3e84 }, /* 1.150 */ 1907877fdebSMatt Macy { 23, 256, 0x5e18bd7f3fd4baf4, 0x0000003f0660391f }, /* 1.174 */ 1917877fdebSMatt Macy { 24, 256, 0xa7b3a4d285d6503b, 0x000000443dfc9ff6 }, /* 1.168 */ 1927877fdebSMatt Macy { 25, 256, 0x56ac7dd967521f5a, 0x0000004b03a87eb7 }, /* 1.180 */ 1937877fdebSMatt Macy { 26, 256, 0x3a42dfda4eb880f7, 0x000000522c719bba }, /* 1.226 */ 1947877fdebSMatt Macy { 27, 256, 0xd200d2fc6b54bf60, 0x0000005760b4fdf5 }, /* 1.228 */ 1957877fdebSMatt Macy { 28, 256, 0xc52605bbd486c546, 0x0000005e00d8f74c }, /* 1.217 */ 1967877fdebSMatt Macy { 29, 256, 0xc761779e63cd762f, 0x00000067be3cd85c }, /* 1.239 */ 1977877fdebSMatt Macy { 30, 256, 0xca577b1e07f85ca5, 0x0000006f5517f3e4 }, /* 1.238 */ 1987877fdebSMatt Macy { 31, 256, 0xfd50a593c518b3d4, 0x0000007370e7778f }, /* 1.273 */ 1997877fdebSMatt Macy { 32, 512, 0xc6c87ba5b042650b, 0x000000f7eb08a156 }, /* 1.191 */ 2007877fdebSMatt Macy { 33, 512, 0xc3880d0c9d458304, 0x0000010734b5d160 }, /* 1.199 */ 2017877fdebSMatt Macy { 34, 512, 0xe920927e4d8b2c97, 0x00000118c1edbce0 }, /* 1.195 */ 2027877fdebSMatt Macy { 35, 512, 0x8da7fcda87bde316, 0x0000012a3e9f9110 }, /* 1.201 */ 2037877fdebSMatt Macy { 36, 512, 0xcf09937491514a29, 0x0000013bd6a24bef }, /* 1.194 */ 2047877fdebSMatt Macy { 37, 512, 0x9b5abbf345cbd7cc, 0x0000014b9d90fac3 }, /* 1.237 */ 2057877fdebSMatt Macy { 38, 512, 0x506312a44668d6a9, 0x0000015e1b5f6148 }, /* 1.242 */ 2067877fdebSMatt Macy { 39, 512, 0x71659ede62b4755f, 0x00000173ef029bcd }, /* 1.231 */ 2077877fdebSMatt Macy { 40, 512, 0xa7fde73fb74cf2d7, 0x000001866fb72748 }, /* 1.233 */ 2087877fdebSMatt Macy { 41, 512, 0x19e8b461a1dea1d3, 0x000001a046f76b23 }, /* 1.271 */ 2097877fdebSMatt Macy { 42, 512, 0x031c9b868cc3e976, 0x000001afa64c49d3 }, /* 1.263 */ 2107877fdebSMatt Macy { 43, 512, 0xbaa5125faa781854, 0x000001c76789e278 }, /* 1.270 */ 2117877fdebSMatt Macy { 44, 512, 0x4ed55052550d721b, 0x000001d800ccd8eb }, /* 1.281 */ 2127877fdebSMatt Macy { 45, 512, 0x0fd63ddbdff90677, 0x000001f08ad59ed2 }, /* 1.282 */ 2137877fdebSMatt Macy { 46, 512, 0x36d66546de7fdd6f, 0x000002016f09574b }, /* 1.286 */ 2147877fdebSMatt Macy { 47, 512, 0x99f997e7eafb69d7, 0x0000021e42e47cb6 }, /* 1.329 */ 2157877fdebSMatt Macy { 48, 512, 0xbecd9c2571312c5d, 0x000002320fe2872b }, /* 1.286 */ 2167877fdebSMatt Macy { 49, 512, 0xd97371329e488a32, 0x0000024cd73f2ca7 }, /* 1.322 */ 2177877fdebSMatt Macy { 50, 512, 0x30e9b136670749ee, 0x000002681c83b0e0 }, /* 1.335 */ 2187877fdebSMatt Macy { 51, 512, 0x11ad6bc8f47aaeb4, 0x0000027e9261b5d5 }, /* 1.305 */ 2197877fdebSMatt Macy { 52, 512, 0x68e445300af432c1, 0x0000029aa0eb7dbf }, /* 1.330 */ 2207877fdebSMatt Macy { 53, 512, 0x910fb561657ea98c, 0x000002b3dca04853 }, /* 1.365 */ 2217877fdebSMatt Macy { 54, 512, 0xd619693d8ce5e7a5, 0x000002cc280e9c97 }, /* 1.334 */ 2227877fdebSMatt Macy { 55, 512, 0x24e281f564dbb60a, 0x000002e9fa842713 }, /* 1.364 */ 2237877fdebSMatt Macy { 56, 512, 0x947a7d3bdaab44c5, 0x000003046680f72e }, /* 1.374 */ 2247877fdebSMatt Macy { 57, 512, 0x2d44fec9c093e0de, 0x00000324198ba810 }, /* 1.363 */ 2257877fdebSMatt Macy { 58, 512, 0x87743c272d29bb4c, 0x0000033ec48c9ac9 }, /* 1.401 */ 2267877fdebSMatt Macy { 59, 512, 0x96aa3b6f67f5d923, 0x0000034faead902c }, /* 1.392 */ 2277877fdebSMatt Macy { 60, 512, 0x94a4f1faf520b0d3, 0x0000037d713ab005 }, /* 1.360 */ 2287877fdebSMatt Macy { 61, 512, 0xb13ed3a272f711a2, 0x00000397368f3cbd }, /* 1.396 */ 2297877fdebSMatt Macy { 62, 512, 0x3b1b11805fa4a64a, 0x000003b8a5e2840c }, /* 1.453 */ 2307877fdebSMatt Macy { 63, 512, 0x4c74caad9172ba71, 0x000003d4be280290 }, /* 1.437 */ 2317877fdebSMatt Macy { 64, 512, 0x035ff643923dd29e, 0x000003fad6c355e1 }, /* 1.402 */ 2327877fdebSMatt Macy { 65, 512, 0x768e9171b11abd3c, 0x0000040eb07fed20 }, /* 1.459 */ 2337877fdebSMatt Macy { 66, 512, 0x75880e6f78a13ddd, 0x000004433d6acf14 }, /* 1.423 */ 2347877fdebSMatt Macy { 67, 512, 0x910b9714f698a877, 0x00000451ea65d5db }, /* 1.447 */ 2357877fdebSMatt Macy { 68, 512, 0x87f5db6f9fdcf5c7, 0x000004732169e3f7 }, /* 1.450 */ 2367877fdebSMatt Macy { 69, 512, 0x836d4968fbaa3706, 0x000004954068a380 }, /* 1.455 */ 2377877fdebSMatt Macy { 70, 512, 0xc567d73a036421ab, 0x000004bd7cb7bd3d }, /* 1.463 */ 2387877fdebSMatt Macy { 71, 512, 0x619df40f240b8fed, 0x000004e376c2e972 }, /* 1.463 */ 2397877fdebSMatt Macy { 72, 512, 0x42763a680d5bed8e, 0x000005084275c680 }, /* 1.452 */ 2407877fdebSMatt Macy { 73, 512, 0x5866f064b3230431, 0x0000052906f2c9ab }, /* 1.498 */ 2417877fdebSMatt Macy { 74, 512, 0x9fa08548b1621a44, 0x0000054708019247 }, /* 1.526 */ 2427877fdebSMatt Macy { 75, 512, 0xb6053078ce0fc303, 0x00000572cc5c72b0 }, /* 1.491 */ 2437877fdebSMatt Macy { 76, 512, 0x4a7aad7bf3890923, 0x0000058e987bc8e9 }, /* 1.470 */ 2447877fdebSMatt Macy { 77, 512, 0xe165613fd75b5a53, 0x000005c20473a211 }, /* 1.527 */ 2457877fdebSMatt Macy { 78, 512, 0x3ff154ac878163a6, 0x000005d659194bf3 }, /* 1.509 */ 2467877fdebSMatt Macy { 79, 512, 0x24b93ade0aa8a532, 0x0000060a201c4f8e }, /* 1.569 */ 2477877fdebSMatt Macy { 80, 512, 0xc18e2d14cd9bb554, 0x0000062c55cfe48c }, /* 1.555 */ 2487877fdebSMatt Macy { 81, 512, 0x98cc78302feb58b6, 0x0000066656a07194 }, /* 1.509 */ 2497877fdebSMatt Macy { 82, 512, 0xc6c5fd5a2abc0543, 0x0000067cff94fbf8 }, /* 1.596 */ 2507877fdebSMatt Macy { 83, 512, 0xa7962f514acbba21, 0x000006ab7b5afa2e }, /* 1.568 */ 2517877fdebSMatt Macy { 84, 512, 0xba02545069ddc6dc, 0x000006d19861364f }, /* 1.541 */ 2527877fdebSMatt Macy { 85, 512, 0x447c73192c35073e, 0x000006fce315ce35 }, /* 1.623 */ 2537877fdebSMatt Macy { 86, 512, 0x48beef9e2d42b0c2, 0x00000720a8e38b6b }, /* 1.620 */ 2547877fdebSMatt Macy { 87, 512, 0x4874cf98541a35e0, 0x00000758382a2273 }, /* 1.597 */ 2557877fdebSMatt Macy { 88, 512, 0xad4cf8333a31127a, 0x00000781e1651b1b }, /* 1.575 */ 2567877fdebSMatt Macy { 89, 512, 0x47ae4859d57888c1, 0x000007b27edbe5bc }, /* 1.627 */ 2577877fdebSMatt Macy { 90, 512, 0x06f7723cfe5d1891, 0x000007dc2a96d8eb }, /* 1.596 */ 2587877fdebSMatt Macy { 91, 512, 0xd4e44218d660576d, 0x0000080ac46f02d5 }, /* 1.622 */ 2597877fdebSMatt Macy { 92, 512, 0x7066702b0d5be1f2, 0x00000832c96d154e }, /* 1.695 */ 2607877fdebSMatt Macy { 93, 512, 0x011209b4f9e11fb9, 0x0000085eefda104c }, /* 1.605 */ 2617877fdebSMatt Macy { 94, 512, 0x47ffba30a0b35708, 0x00000899badc32dc }, /* 1.625 */ 2627877fdebSMatt Macy { 95, 512, 0x1a95a6ac4538aaa8, 0x000008b6b69a42b2 }, /* 1.687 */ 2637877fdebSMatt Macy { 96, 512, 0xbda2b239bb2008eb, 0x000008f22d2de38a }, /* 1.621 */ 2647877fdebSMatt Macy { 97, 512, 0x7ffa0bea90355c6c, 0x0000092e5b23b816 }, /* 1.699 */ 2657877fdebSMatt Macy { 98, 512, 0x1d56ba34be426795, 0x0000094f482e5d1b }, /* 1.688 */ 2667877fdebSMatt Macy { 99, 512, 0x0aa89d45c502e93d, 0x00000977d94a98ce }, /* 1.642 */ 2677877fdebSMatt Macy { 100, 512, 0x54369449f6857774, 0x000009c06c9b34cc }, /* 1.683 */ 2687877fdebSMatt Macy { 101, 512, 0xf7d4dd8445b46765, 0x000009e5dc542259 }, /* 1.755 */ 2697877fdebSMatt Macy { 102, 512, 0xfa8866312f169469, 0x00000a16b54eae93 }, /* 1.692 */ 2707877fdebSMatt Macy { 103, 512, 0xd8a5aea08aef3ff9, 0x00000a381d2cbfe7 }, /* 1.747 */ 2717877fdebSMatt Macy { 104, 512, 0x66bcd2c3d5f9ef0e, 0x00000a8191817be7 }, /* 1.751 */ 2727877fdebSMatt Macy { 105, 512, 0x3fb13a47a012ec81, 0x00000ab562b9a254 }, /* 1.751 */ 2737877fdebSMatt Macy { 106, 512, 0x43100f01c9e5e3ca, 0x00000aeee84c185f }, /* 1.726 */ 2747877fdebSMatt Macy { 107, 512, 0xca09c50ccee2d054, 0x00000b1c359c047d }, /* 1.788 */ 2757877fdebSMatt Macy { 108, 512, 0xd7176732ac503f9b, 0x00000b578bc52a73 }, /* 1.740 */ 2767877fdebSMatt Macy { 109, 512, 0xed206e51f8d9422d, 0x00000b8083e0d960 }, /* 1.780 */ 2777877fdebSMatt Macy { 110, 512, 0x17ead5dc6ba0dcd6, 0x00000bcfb1a32ca8 }, /* 1.836 */ 2787877fdebSMatt Macy { 111, 512, 0x5f1dc21e38a969eb, 0x00000c0171becdd6 }, /* 1.778 */ 2797877fdebSMatt Macy { 112, 512, 0xddaa973de33ec528, 0x00000c3edaba4b95 }, /* 1.831 */ 2807877fdebSMatt Macy { 113, 512, 0x2a5eccd7735a3630, 0x00000c630664e7df }, /* 1.825 */ 2817877fdebSMatt Macy { 114, 512, 0xafcccee5c0b71446, 0x00000cb65392f6e4 }, /* 1.826 */ 2827877fdebSMatt Macy { 115, 512, 0x8fa30c5e7b147e27, 0x00000cd4db391e55 }, /* 1.843 */ 2837877fdebSMatt Macy { 116, 512, 0x5afe0711fdfafd82, 0x00000d08cb4ec35d }, /* 1.826 */ 2847877fdebSMatt Macy { 117, 512, 0x533a6090238afd4c, 0x00000d336f115d1b }, /* 1.803 */ 2857877fdebSMatt Macy { 118, 512, 0x90cf11b595e39a84, 0x00000d8e041c2048 }, /* 1.857 */ 2867877fdebSMatt Macy { 119, 512, 0x0d61a3b809444009, 0x00000dcb798afe35 }, /* 1.877 */ 2877877fdebSMatt Macy { 120, 512, 0x7f34da0f54b0d114, 0x00000df3922664e1 }, /* 1.849 */ 2887877fdebSMatt Macy { 121, 512, 0xa52258d5b72f6551, 0x00000e4d37a9872d }, /* 1.867 */ 2897877fdebSMatt Macy { 122, 512, 0xc1de54d7672878db, 0x00000e6583a94cf6 }, /* 1.978 */ 2907877fdebSMatt Macy { 123, 512, 0x1d03354316a414ab, 0x00000ebffc50308d }, /* 1.947 */ 2917877fdebSMatt Macy { 124, 512, 0xcebdcc377665412c, 0x00000edee1997cea }, /* 1.865 */ 2927877fdebSMatt Macy { 125, 512, 0x4ddd4c04b1a12344, 0x00000f21d64b373f }, /* 1.881 */ 2937877fdebSMatt Macy { 126, 512, 0x64fc8f94e3973658, 0x00000f8f87a8896b }, /* 1.882 */ 2947877fdebSMatt Macy { 127, 512, 0x68765f78034a334e, 0x00000fb8fe62197e }, /* 1.867 */ 2957877fdebSMatt Macy { 128, 512, 0xaf36b871a303e816, 0x00000fec6f3afb1e }, /* 1.972 */ 2967877fdebSMatt Macy { 129, 512, 0x2a4cbf73866c3a28, 0x00001027febfe4e5 }, /* 1.896 */ 2977877fdebSMatt Macy { 130, 512, 0x9cb128aacdcd3b2f, 0x0000106aa8ac569d }, /* 1.965 */ 2987877fdebSMatt Macy { 131, 512, 0x5511d41c55869124, 0x000010bbd755ddf1 }, /* 1.963 */ 2997877fdebSMatt Macy { 132, 512, 0x42f92461937f284a, 0x000010fb8bceb3b5 }, /* 1.925 */ 3007877fdebSMatt Macy { 133, 512, 0xe2d89a1cf6f1f287, 0x0000114cf5331e34 }, /* 1.862 */ 3017877fdebSMatt Macy { 134, 512, 0xdc631a038956200e, 0x0000116428d2adc5 }, /* 2.042 */ 3027877fdebSMatt Macy { 135, 512, 0xb2e5ac222cd236be, 0x000011ca88e4d4d2 }, /* 1.935 */ 3037877fdebSMatt Macy { 136, 512, 0xbc7d8236655d88e7, 0x000011e39cb94e66 }, /* 2.005 */ 3047877fdebSMatt Macy { 137, 512, 0x073e02d88d2d8e75, 0x0000123136c7933c }, /* 2.041 */ 3057877fdebSMatt Macy { 138, 512, 0x3ddb9c3873166be0, 0x00001280e4ec6d52 }, /* 1.997 */ 3067877fdebSMatt Macy { 139, 512, 0x7d3b1a845420e1b5, 0x000012c2e7cd6a44 }, /* 1.996 */ 3077877fdebSMatt Macy { 140, 512, 0x60102308aa7b2a6c, 0x000012fc490e6c7d }, /* 2.053 */ 3087877fdebSMatt Macy { 141, 512, 0xdb22bb2f9eb894aa, 0x00001343f5a85a1a }, /* 1.971 */ 3097877fdebSMatt Macy { 142, 512, 0xd853f879a13b1606, 0x000013bb7d5f9048 }, /* 2.018 */ 3107877fdebSMatt Macy { 143, 512, 0x001620a03f804b1d, 0x000013e74cc794fd }, /* 1.961 */ 3117877fdebSMatt Macy { 144, 512, 0xfdb52dda76fbf667, 0x00001442d2f22480 }, /* 2.046 */ 3127877fdebSMatt Macy { 145, 512, 0xa9160110f66e24ff, 0x0000144b899f9dbb }, /* 1.968 */ 3137877fdebSMatt Macy { 146, 512, 0x77306a30379ae03b, 0x000014cb98eb1f81 }, /* 2.143 */ 3147877fdebSMatt Macy { 147, 512, 0x14f5985d2752319d, 0x000014feab821fc9 }, /* 2.064 */ 3157877fdebSMatt Macy { 148, 512, 0xa4b8ff11de7863f8, 0x0000154a0e60b9c9 }, /* 2.023 */ 3167877fdebSMatt Macy { 149, 512, 0x44b345426455c1b3, 0x000015999c3c569c }, /* 2.136 */ 3177877fdebSMatt Macy { 150, 512, 0x272677826049b46c, 0x000015c9697f4b92 }, /* 2.063 */ 3187877fdebSMatt Macy { 151, 512, 0x2f9216e2cd74fe40, 0x0000162b1f7bbd39 }, /* 1.974 */ 3197877fdebSMatt Macy { 152, 512, 0x706ae3e763ad8771, 0x00001661371c55e1 }, /* 2.210 */ 3207877fdebSMatt Macy { 153, 512, 0xf7fd345307c2480e, 0x000016e251f28b6a }, /* 2.006 */ 3217877fdebSMatt Macy { 154, 512, 0x6e94e3d26b3139eb, 0x000016f2429bb8c6 }, /* 2.193 */ 3227877fdebSMatt Macy { 155, 512, 0x5458bbfbb781fcba, 0x0000173efdeca1b9 }, /* 2.163 */ 3237877fdebSMatt Macy { 156, 512, 0xa80e2afeccd93b33, 0x000017bfdcb78adc }, /* 2.046 */ 3247877fdebSMatt Macy { 157, 512, 0x1e4ccbb22796cf9d, 0x00001826fdcc39c9 }, /* 2.084 */ 3257877fdebSMatt Macy { 158, 512, 0x8fba4b676aaa3663, 0x00001841a1379480 }, /* 2.264 */ 3267877fdebSMatt Macy { 159, 512, 0xf82b843814b315fa, 0x000018886e19b8a3 }, /* 2.074 */ 3277877fdebSMatt Macy { 160, 512, 0x7f21e920ecf753a3, 0x0000191812ca0ea7 }, /* 2.282 */ 3287877fdebSMatt Macy { 161, 512, 0x48bb8ea2c4caa620, 0x0000192f310faccf }, /* 2.148 */ 3297877fdebSMatt Macy { 162, 512, 0x5cdb652b4952c91b, 0x0000199e1d7437c7 }, /* 2.355 */ 3307877fdebSMatt Macy { 163, 512, 0x6ac1ba6f78c06cd4, 0x000019cd11f82c70 }, /* 2.164 */ 3317877fdebSMatt Macy { 164, 512, 0x9faf5f9ca2669a56, 0x00001a18d5431f6a }, /* 2.393 */ 3327877fdebSMatt Macy { 165, 512, 0xaa57e9383eb01194, 0x00001a9e7d253d85 }, /* 2.178 */ 3337877fdebSMatt Macy { 166, 512, 0x896967bf495c34d2, 0x00001afb8319b9fc }, /* 2.334 */ 3347877fdebSMatt Macy { 167, 512, 0xdfad5f05de225f1b, 0x00001b3a59c3093b }, /* 2.266 */ 3357877fdebSMatt Macy { 168, 512, 0xfd299a99f9f2abdd, 0x00001bb6f1a10799 }, /* 2.304 */ 3367877fdebSMatt Macy { 169, 512, 0xdda239e798fe9fd4, 0x00001bfae0c9692d }, /* 2.218 */ 3377877fdebSMatt Macy { 170, 512, 0x5fca670414a32c3e, 0x00001c22129dbcff }, /* 2.377 */ 3387877fdebSMatt Macy { 171, 512, 0x1bb8934314b087de, 0x00001c955db36cd0 }, /* 2.155 */ 3397877fdebSMatt Macy { 172, 512, 0xd96394b4b082200d, 0x00001cfc8619b7e6 }, /* 2.404 */ 3407877fdebSMatt Macy { 173, 512, 0xb612a7735b1c8cbc, 0x00001d303acdd585 }, /* 2.205 */ 3417877fdebSMatt Macy { 174, 512, 0x28e7430fe5875fe1, 0x00001d7ed5b3697d }, /* 2.359 */ 3427877fdebSMatt Macy { 175, 512, 0x5038e89efdd981b9, 0x00001dc40ec35c59 }, /* 2.158 */ 3437877fdebSMatt Macy { 176, 512, 0x075fd78f1d14db7c, 0x00001e31c83b4a2b }, /* 2.614 */ 3447877fdebSMatt Macy { 177, 512, 0xc50fafdb5021be15, 0x00001e7cdac82fbc }, /* 2.239 */ 3457877fdebSMatt Macy { 178, 512, 0xe6dc7572ce7b91c7, 0x00001edd8bb454fc }, /* 2.493 */ 3467877fdebSMatt Macy { 179, 512, 0x21f7843e7beda537, 0x00001f3a8e019d6c }, /* 2.327 */ 3477877fdebSMatt Macy { 180, 512, 0xc83385e20b43ec82, 0x00001f70735ec137 }, /* 2.231 */ 3487877fdebSMatt Macy { 181, 512, 0xca818217dddb21fd, 0x0000201ca44c5a3c }, /* 2.237 */ 3497877fdebSMatt Macy { 182, 512, 0xe6035defea48f933, 0x00002038e3346658 }, /* 2.691 */ 3507877fdebSMatt Macy { 183, 512, 0x47262a4f953dac5a, 0x000020c2e554314e }, /* 2.170 */ 3517877fdebSMatt Macy { 184, 512, 0xe24c7246260873ea, 0x000021197e618d64 }, /* 2.600 */ 3527877fdebSMatt Macy { 185, 512, 0xeef6b57c9b58e9e1, 0x0000217ea48ecddc }, /* 2.391 */ 3537877fdebSMatt Macy { 186, 512, 0x2becd3346e386142, 0x000021c496d4a5f9 }, /* 2.677 */ 3547877fdebSMatt Macy { 187, 512, 0x63c6207bdf3b40a3, 0x0000220e0f2eec0c }, /* 2.410 */ 3557877fdebSMatt Macy { 188, 512, 0x3056ce8989767d4b, 0x0000228eb76cd137 }, /* 2.776 */ 3567877fdebSMatt Macy { 189, 512, 0x91af61c307cee780, 0x000022e17e2ea501 }, /* 2.266 */ 3577877fdebSMatt Macy { 190, 512, 0xda359da225f6d54f, 0x00002358a2debc19 }, /* 2.717 */ 3587877fdebSMatt Macy { 191, 512, 0x0a5f7a2a55607ba0, 0x0000238a79dac18c }, /* 2.474 */ 3597877fdebSMatt Macy { 192, 512, 0x27bb75bf5224638a, 0x00002403a58e2351 }, /* 2.673 */ 3607877fdebSMatt Macy { 193, 512, 0x1ebfdb94630f5d0f, 0x00002492a10cb339 }, /* 2.420 */ 3617877fdebSMatt Macy { 194, 512, 0x6eae5e51d9c5f6fb, 0x000024ce4bf98715 }, /* 2.898 */ 3627877fdebSMatt Macy { 195, 512, 0x08d903b4daedc2e0, 0x0000250d1e15886c }, /* 2.363 */ 3637877fdebSMatt Macy { 196, 512, 0xc722a2f7fa7cd686, 0x0000258a99ed0c9e }, /* 2.747 */ 3647877fdebSMatt Macy { 197, 512, 0x8f71faf0e54e361d, 0x000025dee11976f5 }, /* 2.531 */ 3657877fdebSMatt Macy { 198, 512, 0x87f64695c91a54e7, 0x0000264e00a43da0 }, /* 2.707 */ 3667877fdebSMatt Macy { 199, 512, 0xc719cbac2c336b92, 0x000026d327277ac1 }, /* 2.315 */ 3677877fdebSMatt Macy { 200, 512, 0xe7e647afaf771ade, 0x000027523a5c44bf }, /* 3.012 */ 3687877fdebSMatt Macy { 201, 512, 0x12d4b5c38ce8c946, 0x0000273898432545 }, /* 2.378 */ 3697877fdebSMatt Macy { 202, 512, 0xf2e0cd4067bdc94a, 0x000027e47bb2c935 }, /* 2.969 */ 3707877fdebSMatt Macy { 203, 512, 0x21b79f14d6d947d3, 0x0000281e64977f0d }, /* 2.594 */ 3717877fdebSMatt Macy { 204, 512, 0x515093f952f18cd6, 0x0000289691a473fd }, /* 2.763 */ 3727877fdebSMatt Macy { 205, 512, 0xd47b160a1b1022c8, 0x00002903e8b52411 }, /* 2.457 */ 3737877fdebSMatt Macy { 206, 512, 0xc02fc96684715a16, 0x0000297515608601 }, /* 3.057 */ 3747877fdebSMatt Macy { 207, 512, 0xef51e68efba72ed0, 0x000029ef73604804 }, /* 2.590 */ 3757877fdebSMatt Macy { 208, 512, 0x9e3be6e5448b4f33, 0x00002a2846ed074b }, /* 3.047 */ 3767877fdebSMatt Macy { 209, 512, 0x81d446c6d5fec063, 0x00002a92ca693455 }, /* 2.676 */ 3777877fdebSMatt Macy { 210, 512, 0xff215de8224e57d5, 0x00002b2271fe3729 }, /* 2.993 */ 3787877fdebSMatt Macy { 211, 512, 0xe2524d9ba8f69796, 0x00002b64b99c3ba2 }, /* 2.457 */ 3797877fdebSMatt Macy { 212, 512, 0xf6b28e26097b7e4b, 0x00002bd768b6e068 }, /* 3.182 */ 3807877fdebSMatt Macy { 213, 512, 0x893a487f30ce1644, 0x00002c67f722b4b2 }, /* 2.563 */ 3817877fdebSMatt Macy { 214, 512, 0x386566c3fc9871df, 0x00002cc1cf8b4037 }, /* 3.025 */ 3827877fdebSMatt Macy { 215, 512, 0x1e0ed78edf1f558a, 0x00002d3948d36c7f }, /* 2.730 */ 3837877fdebSMatt Macy { 216, 512, 0xe3bc20c31e61f113, 0x00002d6d6b12e025 }, /* 3.036 */ 3847877fdebSMatt Macy { 217, 512, 0xd6c3ad2e23021882, 0x00002deff7572241 }, /* 2.722 */ 3857877fdebSMatt Macy { 218, 512, 0xb4a9f95cf0f69c5a, 0x00002e67d537aa36 }, /* 3.356 */ 3867877fdebSMatt Macy { 219, 512, 0x6e98ed6f6c38e82f, 0x00002e9720626789 }, /* 2.697 */ 3877877fdebSMatt Macy { 220, 512, 0x2e01edba33fddac7, 0x00002f407c6b0198 }, /* 2.979 */ 3887877fdebSMatt Macy { 221, 512, 0x559d02e1f5f57ccc, 0x00002fb6a5ab4f24 }, /* 2.858 */ 3897877fdebSMatt Macy { 222, 512, 0xac18f5a916adcd8e, 0x0000304ae1c5c57e }, /* 3.258 */ 3907877fdebSMatt Macy { 223, 512, 0x15789fbaddb86f4b, 0x0000306f6e019c78 }, /* 2.693 */ 3917877fdebSMatt Macy { 224, 512, 0xf4a9c36d5bc4c408, 0x000030da40434213 }, /* 3.259 */ 3927877fdebSMatt Macy { 225, 512, 0xf640f90fd2727f44, 0x00003189ed37b90c }, /* 2.733 */ 3937877fdebSMatt Macy { 226, 512, 0xb5313d390d61884a, 0x000031e152616b37 }, /* 3.235 */ 3947877fdebSMatt Macy { 227, 512, 0x4bae6b3ce9160939, 0x0000321f40aeac42 }, /* 2.983 */ 3957877fdebSMatt Macy { 228, 512, 0x838c34480f1a66a1, 0x000032f389c0f78e }, /* 3.308 */ 3967877fdebSMatt Macy { 229, 512, 0xb1c4a52c8e3d6060, 0x0000330062a40284 }, /* 2.715 */ 3977877fdebSMatt Macy { 230, 512, 0xe0f1110c6d0ed822, 0x0000338be435644f }, /* 3.540 */ 3987877fdebSMatt Macy { 231, 512, 0x9f1a8ccdcea68d4b, 0x000034045a4e97e1 }, /* 2.779 */ 3997877fdebSMatt Macy { 232, 512, 0x3261ed62223f3099, 0x000034702cfc401c }, /* 3.084 */ 4007877fdebSMatt Macy { 233, 512, 0xf2191e2311022d65, 0x00003509dd19c9fc }, /* 2.987 */ 4017877fdebSMatt Macy { 234, 512, 0xf102a395c2033abc, 0x000035654dc96fae }, /* 3.341 */ 4027877fdebSMatt Macy { 235, 512, 0x11fe378f027906b6, 0x000035b5193b0264 }, /* 2.793 */ 4037877fdebSMatt Macy { 236, 512, 0xf777f2c026b337aa, 0x000036704f5d9297 }, /* 3.518 */ 4047877fdebSMatt Macy { 237, 512, 0x1b04e9c2ee143f32, 0x000036dfbb7af218 }, /* 2.962 */ 4057877fdebSMatt Macy { 238, 512, 0x2fcec95266f9352c, 0x00003785c8df24a9 }, /* 3.196 */ 4067877fdebSMatt Macy { 239, 512, 0xfe2b0e47e427dd85, 0x000037cbdf5da729 }, /* 2.914 */ 4077877fdebSMatt Macy { 240, 512, 0x72b49bf2225f6c6d, 0x0000382227c15855 }, /* 3.408 */ 4087877fdebSMatt Macy { 241, 512, 0x50486b43df7df9c7, 0x0000389b88be6453 }, /* 2.903 */ 4097877fdebSMatt Macy { 242, 512, 0x5192a3e53181c8ab, 0x000038ddf3d67263 }, /* 3.778 */ 4107877fdebSMatt Macy { 243, 512, 0xe9f5d8365296fd5e, 0x0000399f1c6c9e9c }, /* 3.026 */ 4117877fdebSMatt Macy { 244, 512, 0xc740263f0301efa8, 0x00003a147146512d }, /* 3.347 */ 4127877fdebSMatt Macy { 245, 512, 0x23cd0f2b5671e67d, 0x00003ab10bcc0d9d }, /* 3.212 */ 4137877fdebSMatt Macy { 246, 512, 0x002ccc7e5cd41390, 0x00003ad6cd14a6c0 }, /* 3.482 */ 4147877fdebSMatt Macy { 247, 512, 0x9aafb3c02544b31b, 0x00003b8cb8779fb0 }, /* 3.146 */ 4157877fdebSMatt Macy { 248, 512, 0x72ba07a78b121999, 0x00003c24142a5a3f }, /* 3.626 */ 4167877fdebSMatt Macy { 249, 512, 0x3d784aa58edfc7b4, 0x00003cd084817d99 }, /* 2.952 */ 4177877fdebSMatt Macy { 250, 512, 0xaab750424d8004af, 0x00003d506a8e098e }, /* 3.463 */ 4187877fdebSMatt Macy { 251, 512, 0x84403fcf8e6b5ca2, 0x00003d4c54c2aec4 }, /* 3.131 */ 4197877fdebSMatt Macy { 252, 512, 0x71eb7455ec98e207, 0x00003e655715cf2c }, /* 3.538 */ 4207877fdebSMatt Macy { 253, 512, 0xd752b4f19301595b, 0x00003ecd7b2ca5ac }, /* 2.974 */ 4217877fdebSMatt Macy { 254, 512, 0xc4674129750499de, 0x00003e99e86d3e95 }, /* 3.843 */ 4227877fdebSMatt Macy { 255, 512, 0x9772baff5cd12ef5, 0x00003f895c019841 }, /* 3.088 */ 4237877fdebSMatt Macy }; 4247877fdebSMatt Macy 4257877fdebSMatt Macy /* 4267877fdebSMatt Macy * Verify the map is valid. Each device index must appear exactly 4277877fdebSMatt Macy * once in every row, and the permutation array checksum must match. 4287877fdebSMatt Macy */ 4297877fdebSMatt Macy static int 4307877fdebSMatt Macy verify_perms(uint8_t *perms, uint64_t children, uint64_t nperms, 4317877fdebSMatt Macy uint64_t checksum) 4327877fdebSMatt Macy { 4337877fdebSMatt Macy int countssz = sizeof (uint16_t) * children; 4347877fdebSMatt Macy uint16_t *counts = kmem_zalloc(countssz, KM_SLEEP); 4357877fdebSMatt Macy 4367877fdebSMatt Macy for (int i = 0; i < nperms; i++) { 4377877fdebSMatt Macy for (int j = 0; j < children; j++) { 4387877fdebSMatt Macy uint8_t val = perms[(i * children) + j]; 4397877fdebSMatt Macy 4407877fdebSMatt Macy if (val >= children || counts[val] != i) { 4417877fdebSMatt Macy kmem_free(counts, countssz); 4427877fdebSMatt Macy return (EINVAL); 4437877fdebSMatt Macy } 4447877fdebSMatt Macy 4457877fdebSMatt Macy counts[val]++; 4467877fdebSMatt Macy } 4477877fdebSMatt Macy } 4487877fdebSMatt Macy 4497877fdebSMatt Macy if (checksum != 0) { 4507877fdebSMatt Macy int permssz = sizeof (uint8_t) * children * nperms; 4517877fdebSMatt Macy zio_cksum_t cksum; 4527877fdebSMatt Macy 4537877fdebSMatt Macy fletcher_4_native_varsize(perms, permssz, &cksum); 4547877fdebSMatt Macy 4557877fdebSMatt Macy if (checksum != cksum.zc_word[0]) { 4567877fdebSMatt Macy kmem_free(counts, countssz); 4577877fdebSMatt Macy return (ECKSUM); 4587877fdebSMatt Macy } 4597877fdebSMatt Macy } 4607877fdebSMatt Macy 4617877fdebSMatt Macy kmem_free(counts, countssz); 4627877fdebSMatt Macy 4637877fdebSMatt Macy return (0); 4647877fdebSMatt Macy } 4657877fdebSMatt Macy 4667877fdebSMatt Macy /* 4677877fdebSMatt Macy * Generate the permutation array for the draid_map_t. These maps control 4687877fdebSMatt Macy * the placement of all data in a dRAID. Therefore it's critical that the 4697877fdebSMatt Macy * seed always generates the same mapping. We provide our own pseudo-random 4707877fdebSMatt Macy * number generator for this purpose. 4717877fdebSMatt Macy */ 4727877fdebSMatt Macy int 4737877fdebSMatt Macy vdev_draid_generate_perms(const draid_map_t *map, uint8_t **permsp) 4747877fdebSMatt Macy { 4757877fdebSMatt Macy VERIFY3U(map->dm_children, >=, VDEV_DRAID_MIN_CHILDREN); 4767877fdebSMatt Macy VERIFY3U(map->dm_children, <=, VDEV_DRAID_MAX_CHILDREN); 4777877fdebSMatt Macy VERIFY3U(map->dm_seed, !=, 0); 4787877fdebSMatt Macy VERIFY3U(map->dm_nperms, !=, 0); 4797877fdebSMatt Macy VERIFY3P(map->dm_perms, ==, NULL); 4807877fdebSMatt Macy 4817877fdebSMatt Macy #ifdef _KERNEL 4827877fdebSMatt Macy /* 4837877fdebSMatt Macy * The kernel code always provides both a map_seed and checksum. 4847877fdebSMatt Macy * Only the tests/zfs-tests/cmd/draid/draid.c utility will provide 4857877fdebSMatt Macy * a zero checksum when generating new candidate maps. 4867877fdebSMatt Macy */ 4877877fdebSMatt Macy VERIFY3U(map->dm_checksum, !=, 0); 4887877fdebSMatt Macy #endif 4897877fdebSMatt Macy uint64_t children = map->dm_children; 4907877fdebSMatt Macy uint64_t nperms = map->dm_nperms; 4917877fdebSMatt Macy int rowsz = sizeof (uint8_t) * children; 4927877fdebSMatt Macy int permssz = rowsz * nperms; 4937877fdebSMatt Macy uint8_t *perms; 4947877fdebSMatt Macy 4957877fdebSMatt Macy /* Allocate the permutation array */ 4967877fdebSMatt Macy perms = vmem_alloc(permssz, KM_SLEEP); 4977877fdebSMatt Macy 4987877fdebSMatt Macy /* Setup an initial row with a known pattern */ 4997877fdebSMatt Macy uint8_t *initial_row = kmem_alloc(rowsz, KM_SLEEP); 5007877fdebSMatt Macy for (int i = 0; i < children; i++) 5017877fdebSMatt Macy initial_row[i] = i; 5027877fdebSMatt Macy 5037877fdebSMatt Macy uint64_t draid_seed[2] = { VDEV_DRAID_SEED, map->dm_seed }; 5047877fdebSMatt Macy uint8_t *current_row, *previous_row = initial_row; 5057877fdebSMatt Macy 5067877fdebSMatt Macy /* 5077877fdebSMatt Macy * Perform a Fisher-Yates shuffle of each row using the previous 5087877fdebSMatt Macy * row as the starting point. An initial_row with known pattern 5097877fdebSMatt Macy * is used as the input for the first row. 5107877fdebSMatt Macy */ 5117877fdebSMatt Macy for (int i = 0; i < nperms; i++) { 5127877fdebSMatt Macy current_row = &perms[i * children]; 5137877fdebSMatt Macy memcpy(current_row, previous_row, rowsz); 5147877fdebSMatt Macy 5157877fdebSMatt Macy for (int j = children - 1; j > 0; j--) { 5167877fdebSMatt Macy uint64_t k = vdev_draid_rand(draid_seed) % (j + 1); 5177877fdebSMatt Macy uint8_t val = current_row[j]; 5187877fdebSMatt Macy current_row[j] = current_row[k]; 5197877fdebSMatt Macy current_row[k] = val; 5207877fdebSMatt Macy } 5217877fdebSMatt Macy 5227877fdebSMatt Macy previous_row = current_row; 5237877fdebSMatt Macy } 5247877fdebSMatt Macy 5257877fdebSMatt Macy kmem_free(initial_row, rowsz); 5267877fdebSMatt Macy 5277877fdebSMatt Macy int error = verify_perms(perms, children, nperms, map->dm_checksum); 5287877fdebSMatt Macy if (error) { 5297877fdebSMatt Macy vmem_free(perms, permssz); 5307877fdebSMatt Macy return (error); 5317877fdebSMatt Macy } 5327877fdebSMatt Macy 5337877fdebSMatt Macy *permsp = perms; 5347877fdebSMatt Macy 5357877fdebSMatt Macy return (0); 5367877fdebSMatt Macy } 5377877fdebSMatt Macy 5387877fdebSMatt Macy /* 5397877fdebSMatt Macy * Lookup the fixed draid_map_t for the requested number of children. 5407877fdebSMatt Macy */ 5417877fdebSMatt Macy int 5427877fdebSMatt Macy vdev_draid_lookup_map(uint64_t children, const draid_map_t **mapp) 5437877fdebSMatt Macy { 5447877fdebSMatt Macy for (int i = 0; i <= VDEV_DRAID_MAX_MAPS; i++) { 5457877fdebSMatt Macy if (draid_maps[i].dm_children == children) { 5467877fdebSMatt Macy *mapp = &draid_maps[i]; 5477877fdebSMatt Macy return (0); 5487877fdebSMatt Macy } 5497877fdebSMatt Macy } 5507877fdebSMatt Macy 5517877fdebSMatt Macy return (ENOENT); 5527877fdebSMatt Macy } 5537877fdebSMatt Macy 5547877fdebSMatt Macy /* 5557877fdebSMatt Macy * Lookup the permutation array and iteration id for the provided offset. 5567877fdebSMatt Macy */ 5577877fdebSMatt Macy static void 5587877fdebSMatt Macy vdev_draid_get_perm(vdev_draid_config_t *vdc, uint64_t pindex, 5597877fdebSMatt Macy uint8_t **base, uint64_t *iter) 5607877fdebSMatt Macy { 5617877fdebSMatt Macy uint64_t ncols = vdc->vdc_children; 5627877fdebSMatt Macy uint64_t poff = pindex % (vdc->vdc_nperms * ncols); 5637877fdebSMatt Macy 5647877fdebSMatt Macy *base = vdc->vdc_perms + (poff / ncols) * ncols; 5657877fdebSMatt Macy *iter = poff % ncols; 5667877fdebSMatt Macy } 5677877fdebSMatt Macy 5687877fdebSMatt Macy static inline uint64_t 5697877fdebSMatt Macy vdev_draid_permute_id(vdev_draid_config_t *vdc, 5707877fdebSMatt Macy uint8_t *base, uint64_t iter, uint64_t index) 5717877fdebSMatt Macy { 5727877fdebSMatt Macy return ((base[index] + iter) % vdc->vdc_children); 5737877fdebSMatt Macy } 5747877fdebSMatt Macy 5757877fdebSMatt Macy /* 5767877fdebSMatt Macy * Return the asize which is the psize rounded up to a full group width. 5777877fdebSMatt Macy * i.e. vdev_draid_psize_to_asize(). 5787877fdebSMatt Macy */ 5797877fdebSMatt Macy static uint64_t 5807877fdebSMatt Macy vdev_draid_asize(vdev_t *vd, uint64_t psize) 5817877fdebSMatt Macy { 5827877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 5837877fdebSMatt Macy uint64_t ashift = vd->vdev_ashift; 5847877fdebSMatt Macy 5857877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_ops); 5867877fdebSMatt Macy 5877877fdebSMatt Macy uint64_t rows = ((psize - 1) / (vdc->vdc_ndata << ashift)) + 1; 5887877fdebSMatt Macy uint64_t asize = (rows * vdc->vdc_groupwidth) << ashift; 5897877fdebSMatt Macy 5907877fdebSMatt Macy ASSERT3U(asize, !=, 0); 5917877fdebSMatt Macy ASSERT3U(asize % (vdc->vdc_groupwidth), ==, 0); 5927877fdebSMatt Macy 5937877fdebSMatt Macy return (asize); 5947877fdebSMatt Macy } 5957877fdebSMatt Macy 5967877fdebSMatt Macy /* 5977877fdebSMatt Macy * Deflate the asize to the psize, this includes stripping parity. 5987877fdebSMatt Macy */ 5997877fdebSMatt Macy uint64_t 6007877fdebSMatt Macy vdev_draid_asize_to_psize(vdev_t *vd, uint64_t asize) 6017877fdebSMatt Macy { 6027877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 6037877fdebSMatt Macy 6047877fdebSMatt Macy ASSERT0(asize % vdc->vdc_groupwidth); 6057877fdebSMatt Macy 6067877fdebSMatt Macy return ((asize / vdc->vdc_groupwidth) * vdc->vdc_ndata); 6077877fdebSMatt Macy } 6087877fdebSMatt Macy 6097877fdebSMatt Macy /* 6107877fdebSMatt Macy * Convert a logical offset to the corresponding group number. 6117877fdebSMatt Macy */ 6127877fdebSMatt Macy static uint64_t 6137877fdebSMatt Macy vdev_draid_offset_to_group(vdev_t *vd, uint64_t offset) 6147877fdebSMatt Macy { 6157877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 6167877fdebSMatt Macy 6177877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_ops); 6187877fdebSMatt Macy 6197877fdebSMatt Macy return (offset / vdc->vdc_groupsz); 6207877fdebSMatt Macy } 6217877fdebSMatt Macy 6227877fdebSMatt Macy /* 6237877fdebSMatt Macy * Convert a group number to the logical starting offset for that group. 6247877fdebSMatt Macy */ 6257877fdebSMatt Macy static uint64_t 6267877fdebSMatt Macy vdev_draid_group_to_offset(vdev_t *vd, uint64_t group) 6277877fdebSMatt Macy { 6287877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 6297877fdebSMatt Macy 6307877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_ops); 6317877fdebSMatt Macy 6327877fdebSMatt Macy return (group * vdc->vdc_groupsz); 6337877fdebSMatt Macy } 6347877fdebSMatt Macy 6357877fdebSMatt Macy /* 6367877fdebSMatt Macy * Full stripe writes. When writing, all columns (D+P) are required. Parity 6377877fdebSMatt Macy * is calculated over all the columns, including empty zero filled sectors, 6387877fdebSMatt Macy * and each is written to disk. While only the data columns are needed for 6397877fdebSMatt Macy * a normal read, all of the columns are required for reconstruction when 6407877fdebSMatt Macy * performing a sequential resilver. 6417877fdebSMatt Macy * 6427877fdebSMatt Macy * For "big columns" it's sufficient to map the correct range of the zio ABD. 6437877fdebSMatt Macy * Partial columns require allocating a gang ABD in order to zero fill the 6447877fdebSMatt Macy * empty sectors. When the column is empty a zero filled sector must be 6457877fdebSMatt Macy * mapped. In all cases the data ABDs must be the same size as the parity 6467877fdebSMatt Macy * ABDs (e.g. rc->rc_size == parity_size). 6477877fdebSMatt Macy */ 6487877fdebSMatt Macy static void 6497877fdebSMatt Macy vdev_draid_map_alloc_write(zio_t *zio, uint64_t abd_offset, raidz_row_t *rr) 6507877fdebSMatt Macy { 6517877fdebSMatt Macy uint64_t skip_size = 1ULL << zio->io_vd->vdev_top->vdev_ashift; 6527877fdebSMatt Macy uint64_t parity_size = rr->rr_col[0].rc_size; 6537877fdebSMatt Macy uint64_t abd_off = abd_offset; 6547877fdebSMatt Macy 6557877fdebSMatt Macy ASSERT3U(zio->io_type, ==, ZIO_TYPE_WRITE); 6567877fdebSMatt Macy ASSERT3U(parity_size, ==, abd_get_size(rr->rr_col[0].rc_abd)); 6577877fdebSMatt Macy 6587877fdebSMatt Macy for (uint64_t c = rr->rr_firstdatacol; c < rr->rr_cols; c++) { 6597877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 6607877fdebSMatt Macy 6617877fdebSMatt Macy if (rc->rc_size == 0) { 6627877fdebSMatt Macy /* empty data column (small write), add a skip sector */ 6637877fdebSMatt Macy ASSERT3U(skip_size, ==, parity_size); 6647877fdebSMatt Macy rc->rc_abd = abd_get_zeros(skip_size); 6657877fdebSMatt Macy } else if (rc->rc_size == parity_size) { 6667877fdebSMatt Macy /* this is a "big column" */ 667184c1b94SMartin Matuska rc->rc_abd = abd_get_offset_struct(&rc->rc_abdstruct, 668184c1b94SMartin Matuska zio->io_abd, abd_off, rc->rc_size); 6697877fdebSMatt Macy } else { 6707877fdebSMatt Macy /* short data column, add a skip sector */ 6717877fdebSMatt Macy ASSERT3U(rc->rc_size + skip_size, ==, parity_size); 672184c1b94SMartin Matuska rc->rc_abd = abd_alloc_gang(); 6737877fdebSMatt Macy abd_gang_add(rc->rc_abd, abd_get_offset_size( 6747877fdebSMatt Macy zio->io_abd, abd_off, rc->rc_size), B_TRUE); 6757877fdebSMatt Macy abd_gang_add(rc->rc_abd, abd_get_zeros(skip_size), 6767877fdebSMatt Macy B_TRUE); 6777877fdebSMatt Macy } 6787877fdebSMatt Macy 6797877fdebSMatt Macy ASSERT3U(abd_get_size(rc->rc_abd), ==, parity_size); 6807877fdebSMatt Macy 6817877fdebSMatt Macy abd_off += rc->rc_size; 6827877fdebSMatt Macy rc->rc_size = parity_size; 6837877fdebSMatt Macy } 6847877fdebSMatt Macy 6857877fdebSMatt Macy IMPLY(abd_offset != 0, abd_off == zio->io_size); 6867877fdebSMatt Macy } 6877877fdebSMatt Macy 6887877fdebSMatt Macy /* 6897877fdebSMatt Macy * Scrub/resilver reads. In order to store the contents of the skip sectors 6907877fdebSMatt Macy * an additional ABD is allocated. The columns are handled in the same way 6917877fdebSMatt Macy * as a full stripe write except instead of using the zero ABD the newly 6927877fdebSMatt Macy * allocated skip ABD is used to back the skip sectors. In all cases the 6937877fdebSMatt Macy * data ABD must be the same size as the parity ABDs. 6947877fdebSMatt Macy */ 6957877fdebSMatt Macy static void 6967877fdebSMatt Macy vdev_draid_map_alloc_scrub(zio_t *zio, uint64_t abd_offset, raidz_row_t *rr) 6977877fdebSMatt Macy { 6987877fdebSMatt Macy uint64_t skip_size = 1ULL << zio->io_vd->vdev_top->vdev_ashift; 6997877fdebSMatt Macy uint64_t parity_size = rr->rr_col[0].rc_size; 7007877fdebSMatt Macy uint64_t abd_off = abd_offset; 7017877fdebSMatt Macy uint64_t skip_off = 0; 7027877fdebSMatt Macy 7037877fdebSMatt Macy ASSERT3U(zio->io_type, ==, ZIO_TYPE_READ); 7047877fdebSMatt Macy ASSERT3P(rr->rr_abd_empty, ==, NULL); 7057877fdebSMatt Macy 7067877fdebSMatt Macy if (rr->rr_nempty > 0) { 7077877fdebSMatt Macy rr->rr_abd_empty = abd_alloc_linear(rr->rr_nempty * skip_size, 7087877fdebSMatt Macy B_FALSE); 7097877fdebSMatt Macy } 7107877fdebSMatt Macy 7117877fdebSMatt Macy for (uint64_t c = rr->rr_firstdatacol; c < rr->rr_cols; c++) { 7127877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 7137877fdebSMatt Macy 7147877fdebSMatt Macy if (rc->rc_size == 0) { 7157877fdebSMatt Macy /* empty data column (small read), add a skip sector */ 7167877fdebSMatt Macy ASSERT3U(skip_size, ==, parity_size); 7177877fdebSMatt Macy ASSERT3U(rr->rr_nempty, !=, 0); 7187877fdebSMatt Macy rc->rc_abd = abd_get_offset_size(rr->rr_abd_empty, 7197877fdebSMatt Macy skip_off, skip_size); 7207877fdebSMatt Macy skip_off += skip_size; 7217877fdebSMatt Macy } else if (rc->rc_size == parity_size) { 7227877fdebSMatt Macy /* this is a "big column" */ 723184c1b94SMartin Matuska rc->rc_abd = abd_get_offset_struct(&rc->rc_abdstruct, 724184c1b94SMartin Matuska zio->io_abd, abd_off, rc->rc_size); 7257877fdebSMatt Macy } else { 7267877fdebSMatt Macy /* short data column, add a skip sector */ 7277877fdebSMatt Macy ASSERT3U(rc->rc_size + skip_size, ==, parity_size); 7287877fdebSMatt Macy ASSERT3U(rr->rr_nempty, !=, 0); 729184c1b94SMartin Matuska rc->rc_abd = abd_alloc_gang(); 7307877fdebSMatt Macy abd_gang_add(rc->rc_abd, abd_get_offset_size( 7317877fdebSMatt Macy zio->io_abd, abd_off, rc->rc_size), B_TRUE); 7327877fdebSMatt Macy abd_gang_add(rc->rc_abd, abd_get_offset_size( 7337877fdebSMatt Macy rr->rr_abd_empty, skip_off, skip_size), B_TRUE); 7347877fdebSMatt Macy skip_off += skip_size; 7357877fdebSMatt Macy } 7367877fdebSMatt Macy 7377877fdebSMatt Macy uint64_t abd_size = abd_get_size(rc->rc_abd); 7387877fdebSMatt Macy ASSERT3U(abd_size, ==, abd_get_size(rr->rr_col[0].rc_abd)); 7397877fdebSMatt Macy 7407877fdebSMatt Macy /* 7417877fdebSMatt Macy * Increase rc_size so the skip ABD is included in subsequent 7427877fdebSMatt Macy * parity calculations. 7437877fdebSMatt Macy */ 7447877fdebSMatt Macy abd_off += rc->rc_size; 7457877fdebSMatt Macy rc->rc_size = abd_size; 7467877fdebSMatt Macy } 7477877fdebSMatt Macy 7487877fdebSMatt Macy IMPLY(abd_offset != 0, abd_off == zio->io_size); 7497877fdebSMatt Macy ASSERT3U(skip_off, ==, rr->rr_nempty * skip_size); 7507877fdebSMatt Macy } 7517877fdebSMatt Macy 7527877fdebSMatt Macy /* 7537877fdebSMatt Macy * Normal reads. In this common case only the columns containing data 7547877fdebSMatt Macy * are read in to the zio ABDs. Neither the parity columns or empty skip 7557877fdebSMatt Macy * sectors are read unless the checksum fails verification. In which case 7567877fdebSMatt Macy * vdev_raidz_read_all() will call vdev_draid_map_alloc_empty() to expand 7577877fdebSMatt Macy * the raid map in order to allow reconstruction using the parity data and 7587877fdebSMatt Macy * skip sectors. 7597877fdebSMatt Macy */ 7607877fdebSMatt Macy static void 7617877fdebSMatt Macy vdev_draid_map_alloc_read(zio_t *zio, uint64_t abd_offset, raidz_row_t *rr) 7627877fdebSMatt Macy { 7637877fdebSMatt Macy uint64_t abd_off = abd_offset; 7647877fdebSMatt Macy 7657877fdebSMatt Macy ASSERT3U(zio->io_type, ==, ZIO_TYPE_READ); 7667877fdebSMatt Macy 7677877fdebSMatt Macy for (uint64_t c = rr->rr_firstdatacol; c < rr->rr_cols; c++) { 7687877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 7697877fdebSMatt Macy 7707877fdebSMatt Macy if (rc->rc_size > 0) { 771184c1b94SMartin Matuska rc->rc_abd = abd_get_offset_struct(&rc->rc_abdstruct, 772184c1b94SMartin Matuska zio->io_abd, abd_off, rc->rc_size); 7737877fdebSMatt Macy abd_off += rc->rc_size; 7747877fdebSMatt Macy } 7757877fdebSMatt Macy } 7767877fdebSMatt Macy 7777877fdebSMatt Macy IMPLY(abd_offset != 0, abd_off == zio->io_size); 7787877fdebSMatt Macy } 7797877fdebSMatt Macy 7807877fdebSMatt Macy /* 7817877fdebSMatt Macy * Converts a normal "read" raidz_row_t to a "scrub" raidz_row_t. The key 7827877fdebSMatt Macy * difference is that an ABD is allocated to back skip sectors so they may 7837877fdebSMatt Macy * be read in to memory, verified, and repaired if needed. 7847877fdebSMatt Macy */ 7857877fdebSMatt Macy void 7867877fdebSMatt Macy vdev_draid_map_alloc_empty(zio_t *zio, raidz_row_t *rr) 7877877fdebSMatt Macy { 7887877fdebSMatt Macy uint64_t skip_size = 1ULL << zio->io_vd->vdev_top->vdev_ashift; 7897877fdebSMatt Macy uint64_t parity_size = rr->rr_col[0].rc_size; 7907877fdebSMatt Macy uint64_t skip_off = 0; 7917877fdebSMatt Macy 7927877fdebSMatt Macy ASSERT3U(zio->io_type, ==, ZIO_TYPE_READ); 7937877fdebSMatt Macy ASSERT3P(rr->rr_abd_empty, ==, NULL); 7947877fdebSMatt Macy 7957877fdebSMatt Macy if (rr->rr_nempty > 0) { 7967877fdebSMatt Macy rr->rr_abd_empty = abd_alloc_linear(rr->rr_nempty * skip_size, 7977877fdebSMatt Macy B_FALSE); 7987877fdebSMatt Macy } 7997877fdebSMatt Macy 8007877fdebSMatt Macy for (uint64_t c = rr->rr_firstdatacol; c < rr->rr_cols; c++) { 8017877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 8027877fdebSMatt Macy 8037877fdebSMatt Macy if (rc->rc_size == 0) { 8047877fdebSMatt Macy /* empty data column (small read), add a skip sector */ 8057877fdebSMatt Macy ASSERT3U(skip_size, ==, parity_size); 8067877fdebSMatt Macy ASSERT3U(rr->rr_nempty, !=, 0); 8077877fdebSMatt Macy ASSERT3P(rc->rc_abd, ==, NULL); 8087877fdebSMatt Macy rc->rc_abd = abd_get_offset_size(rr->rr_abd_empty, 8097877fdebSMatt Macy skip_off, skip_size); 8107877fdebSMatt Macy skip_off += skip_size; 8117877fdebSMatt Macy } else if (rc->rc_size == parity_size) { 8127877fdebSMatt Macy /* this is a "big column", nothing to add */ 8137877fdebSMatt Macy ASSERT3P(rc->rc_abd, !=, NULL); 8147877fdebSMatt Macy } else { 81516038816SMartin Matuska /* 81616038816SMartin Matuska * short data column, add a skip sector and clear 81716038816SMartin Matuska * rc_tried to force the entire column to be re-read 81816038816SMartin Matuska * thereby including the missing skip sector data 81916038816SMartin Matuska * which is needed for reconstruction. 82016038816SMartin Matuska */ 8217877fdebSMatt Macy ASSERT3U(rc->rc_size + skip_size, ==, parity_size); 8227877fdebSMatt Macy ASSERT3U(rr->rr_nempty, !=, 0); 8237877fdebSMatt Macy ASSERT3P(rc->rc_abd, !=, NULL); 8247877fdebSMatt Macy ASSERT(!abd_is_gang(rc->rc_abd)); 8257877fdebSMatt Macy abd_t *read_abd = rc->rc_abd; 826184c1b94SMartin Matuska rc->rc_abd = abd_alloc_gang(); 8277877fdebSMatt Macy abd_gang_add(rc->rc_abd, read_abd, B_TRUE); 8287877fdebSMatt Macy abd_gang_add(rc->rc_abd, abd_get_offset_size( 8297877fdebSMatt Macy rr->rr_abd_empty, skip_off, skip_size), B_TRUE); 8307877fdebSMatt Macy skip_off += skip_size; 83116038816SMartin Matuska rc->rc_tried = 0; 8327877fdebSMatt Macy } 8337877fdebSMatt Macy 8347877fdebSMatt Macy /* 8357877fdebSMatt Macy * Increase rc_size so the empty ABD is included in subsequent 8367877fdebSMatt Macy * parity calculations. 8377877fdebSMatt Macy */ 8387877fdebSMatt Macy rc->rc_size = parity_size; 8397877fdebSMatt Macy } 8407877fdebSMatt Macy 8417877fdebSMatt Macy ASSERT3U(skip_off, ==, rr->rr_nempty * skip_size); 8427877fdebSMatt Macy } 8437877fdebSMatt Macy 8447877fdebSMatt Macy /* 8457877fdebSMatt Macy * Given a logical address within a dRAID configuration, return the physical 8467877fdebSMatt Macy * address on the first drive in the group that this address maps to 8477877fdebSMatt Macy * (at position 'start' in permutation number 'perm'). 8487877fdebSMatt Macy */ 8497877fdebSMatt Macy static uint64_t 8507877fdebSMatt Macy vdev_draid_logical_to_physical(vdev_t *vd, uint64_t logical_offset, 8517877fdebSMatt Macy uint64_t *perm, uint64_t *start) 8527877fdebSMatt Macy { 8537877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 8547877fdebSMatt Macy 8557877fdebSMatt Macy /* b is the dRAID (parent) sector offset. */ 8567877fdebSMatt Macy uint64_t ashift = vd->vdev_top->vdev_ashift; 8577877fdebSMatt Macy uint64_t b_offset = logical_offset >> ashift; 8587877fdebSMatt Macy 8597877fdebSMatt Macy /* 8607877fdebSMatt Macy * The height of a row in units of the vdev's minimum sector size. 8617877fdebSMatt Macy * This is the amount of data written to each disk of each group 8627877fdebSMatt Macy * in a given permutation. 8637877fdebSMatt Macy */ 8647877fdebSMatt Macy uint64_t rowheight_sectors = VDEV_DRAID_ROWHEIGHT >> ashift; 8657877fdebSMatt Macy 8667877fdebSMatt Macy /* 8677877fdebSMatt Macy * We cycle through a disk permutation every groupsz * ngroups chunk 8687877fdebSMatt Macy * of address space. Note that ngroups * groupsz must be a multiple 8697877fdebSMatt Macy * of the number of data drives (ndisks) in order to guarantee 8707877fdebSMatt Macy * alignment. So, for example, if our row height is 16MB, our group 8717877fdebSMatt Macy * size is 10, and there are 13 data drives in the draid, then ngroups 8727877fdebSMatt Macy * will be 13, we will change permutation every 2.08GB and each 8737877fdebSMatt Macy * disk will have 160MB of data per chunk. 8747877fdebSMatt Macy */ 8757877fdebSMatt Macy uint64_t groupwidth = vdc->vdc_groupwidth; 8767877fdebSMatt Macy uint64_t ngroups = vdc->vdc_ngroups; 8777877fdebSMatt Macy uint64_t ndisks = vdc->vdc_ndisks; 8787877fdebSMatt Macy 8797877fdebSMatt Macy /* 8807877fdebSMatt Macy * groupstart is where the group this IO will land in "starts" in 8817877fdebSMatt Macy * the permutation array. 8827877fdebSMatt Macy */ 8837877fdebSMatt Macy uint64_t group = logical_offset / vdc->vdc_groupsz; 8847877fdebSMatt Macy uint64_t groupstart = (group * groupwidth) % ndisks; 8857877fdebSMatt Macy ASSERT3U(groupstart + groupwidth, <=, ndisks + groupstart); 8867877fdebSMatt Macy *start = groupstart; 8877877fdebSMatt Macy 8887877fdebSMatt Macy /* b_offset is the sector offset within a group chunk */ 8897877fdebSMatt Macy b_offset = b_offset % (rowheight_sectors * groupwidth); 8907877fdebSMatt Macy ASSERT0(b_offset % groupwidth); 8917877fdebSMatt Macy 8927877fdebSMatt Macy /* 8937877fdebSMatt Macy * Find the starting byte offset on each child vdev: 8947877fdebSMatt Macy * - within a permutation there are ngroups groups spread over the 8957877fdebSMatt Macy * rows, where each row covers a slice portion of the disk 8967877fdebSMatt Macy * - each permutation has (groupwidth * ngroups) / ndisks rows 8977877fdebSMatt Macy * - so each permutation covers rows * slice portion of the disk 8987877fdebSMatt Macy * - so we need to find the row where this IO group target begins 8997877fdebSMatt Macy */ 9007877fdebSMatt Macy *perm = group / ngroups; 9017877fdebSMatt Macy uint64_t row = (*perm * ((groupwidth * ngroups) / ndisks)) + 9027877fdebSMatt Macy (((group % ngroups) * groupwidth) / ndisks); 9037877fdebSMatt Macy 9047877fdebSMatt Macy return (((rowheight_sectors * row) + 9057877fdebSMatt Macy (b_offset / groupwidth)) << ashift); 9067877fdebSMatt Macy } 9077877fdebSMatt Macy 9087877fdebSMatt Macy static uint64_t 9097877fdebSMatt Macy vdev_draid_map_alloc_row(zio_t *zio, raidz_row_t **rrp, uint64_t io_offset, 9107877fdebSMatt Macy uint64_t abd_offset, uint64_t abd_size) 9117877fdebSMatt Macy { 9127877fdebSMatt Macy vdev_t *vd = zio->io_vd; 9137877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 9147877fdebSMatt Macy uint64_t ashift = vd->vdev_top->vdev_ashift; 9157877fdebSMatt Macy uint64_t io_size = abd_size; 9167877fdebSMatt Macy uint64_t io_asize = vdev_draid_asize(vd, io_size); 9177877fdebSMatt Macy uint64_t group = vdev_draid_offset_to_group(vd, io_offset); 9187877fdebSMatt Macy uint64_t start_offset = vdev_draid_group_to_offset(vd, group + 1); 9197877fdebSMatt Macy 9207877fdebSMatt Macy /* 9217877fdebSMatt Macy * Limit the io_size to the space remaining in the group. A second 9227877fdebSMatt Macy * row in the raidz_map_t is created for the remainder. 9237877fdebSMatt Macy */ 9247877fdebSMatt Macy if (io_offset + io_asize > start_offset) { 9257877fdebSMatt Macy io_size = vdev_draid_asize_to_psize(vd, 9267877fdebSMatt Macy start_offset - io_offset); 9277877fdebSMatt Macy } 9287877fdebSMatt Macy 9297877fdebSMatt Macy /* 9307877fdebSMatt Macy * At most a block may span the logical end of one group and the start 9317877fdebSMatt Macy * of the next group. Therefore, at the end of a group the io_size must 9327877fdebSMatt Macy * span the group width evenly and the remainder must be aligned to the 9337877fdebSMatt Macy * start of the next group. 9347877fdebSMatt Macy */ 9357877fdebSMatt Macy IMPLY(abd_offset == 0 && io_size < zio->io_size, 9367877fdebSMatt Macy (io_asize >> ashift) % vdc->vdc_groupwidth == 0); 9377877fdebSMatt Macy IMPLY(abd_offset != 0, 9387877fdebSMatt Macy vdev_draid_group_to_offset(vd, group) == io_offset); 9397877fdebSMatt Macy 9407877fdebSMatt Macy /* Lookup starting byte offset on each child vdev */ 9417877fdebSMatt Macy uint64_t groupstart, perm; 9427877fdebSMatt Macy uint64_t physical_offset = vdev_draid_logical_to_physical(vd, 9437877fdebSMatt Macy io_offset, &perm, &groupstart); 9447877fdebSMatt Macy 9457877fdebSMatt Macy /* 9467877fdebSMatt Macy * If there is less than groupwidth drives available after the group 9477877fdebSMatt Macy * start, the group is going to wrap onto the next row. 'wrap' is the 9487877fdebSMatt Macy * group disk number that starts on the next row. 9497877fdebSMatt Macy */ 9507877fdebSMatt Macy uint64_t ndisks = vdc->vdc_ndisks; 9517877fdebSMatt Macy uint64_t groupwidth = vdc->vdc_groupwidth; 9527877fdebSMatt Macy uint64_t wrap = groupwidth; 9537877fdebSMatt Macy 9547877fdebSMatt Macy if (groupstart + groupwidth > ndisks) 9557877fdebSMatt Macy wrap = ndisks - groupstart; 9567877fdebSMatt Macy 9577877fdebSMatt Macy /* The io size in units of the vdev's minimum sector size. */ 9587877fdebSMatt Macy const uint64_t psize = io_size >> ashift; 9597877fdebSMatt Macy 9607877fdebSMatt Macy /* 9617877fdebSMatt Macy * "Quotient": The number of data sectors for this stripe on all but 9627877fdebSMatt Macy * the "big column" child vdevs that also contain "remainder" data. 9637877fdebSMatt Macy */ 9647877fdebSMatt Macy uint64_t q = psize / vdc->vdc_ndata; 9657877fdebSMatt Macy 9667877fdebSMatt Macy /* 9677877fdebSMatt Macy * "Remainder": The number of partial stripe data sectors in this I/O. 9687877fdebSMatt Macy * This will add a sector to some, but not all, child vdevs. 9697877fdebSMatt Macy */ 9707877fdebSMatt Macy uint64_t r = psize - q * vdc->vdc_ndata; 9717877fdebSMatt Macy 9727877fdebSMatt Macy /* The number of "big columns" - those which contain remainder data. */ 9737877fdebSMatt Macy uint64_t bc = (r == 0 ? 0 : r + vdc->vdc_nparity); 9747877fdebSMatt Macy ASSERT3U(bc, <, groupwidth); 9757877fdebSMatt Macy 9767877fdebSMatt Macy /* The total number of data and parity sectors for this I/O. */ 9777877fdebSMatt Macy uint64_t tot = psize + (vdc->vdc_nparity * (q + (r == 0 ? 0 : 1))); 9787877fdebSMatt Macy 9797877fdebSMatt Macy raidz_row_t *rr; 9807877fdebSMatt Macy rr = kmem_alloc(offsetof(raidz_row_t, rr_col[groupwidth]), KM_SLEEP); 9817877fdebSMatt Macy rr->rr_cols = groupwidth; 9827877fdebSMatt Macy rr->rr_scols = groupwidth; 9837877fdebSMatt Macy rr->rr_bigcols = bc; 9847877fdebSMatt Macy rr->rr_missingdata = 0; 9857877fdebSMatt Macy rr->rr_missingparity = 0; 9867877fdebSMatt Macy rr->rr_firstdatacol = vdc->vdc_nparity; 9877877fdebSMatt Macy rr->rr_abd_empty = NULL; 9887877fdebSMatt Macy #ifdef ZFS_DEBUG 9897877fdebSMatt Macy rr->rr_offset = io_offset; 9907877fdebSMatt Macy rr->rr_size = io_size; 9917877fdebSMatt Macy #endif 9927877fdebSMatt Macy *rrp = rr; 9937877fdebSMatt Macy 9947877fdebSMatt Macy uint8_t *base; 9957877fdebSMatt Macy uint64_t iter, asize = 0; 9967877fdebSMatt Macy vdev_draid_get_perm(vdc, perm, &base, &iter); 9977877fdebSMatt Macy for (uint64_t i = 0; i < groupwidth; i++) { 9987877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[i]; 9997877fdebSMatt Macy uint64_t c = (groupstart + i) % ndisks; 10007877fdebSMatt Macy 10017877fdebSMatt Macy /* increment the offset if we wrap to the next row */ 10027877fdebSMatt Macy if (i == wrap) 10037877fdebSMatt Macy physical_offset += VDEV_DRAID_ROWHEIGHT; 10047877fdebSMatt Macy 10057877fdebSMatt Macy rc->rc_devidx = vdev_draid_permute_id(vdc, base, iter, c); 10067877fdebSMatt Macy rc->rc_offset = physical_offset; 10077877fdebSMatt Macy rc->rc_abd = NULL; 10087877fdebSMatt Macy rc->rc_orig_data = NULL; 10097877fdebSMatt Macy rc->rc_error = 0; 10107877fdebSMatt Macy rc->rc_tried = 0; 10117877fdebSMatt Macy rc->rc_skipped = 0; 101216038816SMartin Matuska rc->rc_force_repair = 0; 101316038816SMartin Matuska rc->rc_allow_repair = 1; 10147877fdebSMatt Macy rc->rc_need_orig_restore = B_FALSE; 10157877fdebSMatt Macy 10167877fdebSMatt Macy if (q == 0 && i >= bc) 10177877fdebSMatt Macy rc->rc_size = 0; 10187877fdebSMatt Macy else if (i < bc) 10197877fdebSMatt Macy rc->rc_size = (q + 1) << ashift; 10207877fdebSMatt Macy else 10217877fdebSMatt Macy rc->rc_size = q << ashift; 10227877fdebSMatt Macy 10237877fdebSMatt Macy asize += rc->rc_size; 10247877fdebSMatt Macy } 10257877fdebSMatt Macy 10267877fdebSMatt Macy ASSERT3U(asize, ==, tot << ashift); 10277877fdebSMatt Macy rr->rr_nempty = roundup(tot, groupwidth) - tot; 10287877fdebSMatt Macy IMPLY(bc > 0, rr->rr_nempty == groupwidth - bc); 10297877fdebSMatt Macy 10307877fdebSMatt Macy /* Allocate buffers for the parity columns */ 10317877fdebSMatt Macy for (uint64_t c = 0; c < rr->rr_firstdatacol; c++) { 10327877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 10337877fdebSMatt Macy rc->rc_abd = abd_alloc_linear(rc->rc_size, B_FALSE); 10347877fdebSMatt Macy } 10357877fdebSMatt Macy 10367877fdebSMatt Macy /* 10377877fdebSMatt Macy * Map buffers for data columns and allocate/map buffers for skip 10387877fdebSMatt Macy * sectors. There are three distinct cases for dRAID which are 10397877fdebSMatt Macy * required to support sequential rebuild. 10407877fdebSMatt Macy */ 10417877fdebSMatt Macy if (zio->io_type == ZIO_TYPE_WRITE) { 10427877fdebSMatt Macy vdev_draid_map_alloc_write(zio, abd_offset, rr); 10437877fdebSMatt Macy } else if ((rr->rr_nempty > 0) && 10447877fdebSMatt Macy (zio->io_flags & (ZIO_FLAG_SCRUB | ZIO_FLAG_RESILVER))) { 10457877fdebSMatt Macy vdev_draid_map_alloc_scrub(zio, abd_offset, rr); 10467877fdebSMatt Macy } else { 10477877fdebSMatt Macy ASSERT3U(zio->io_type, ==, ZIO_TYPE_READ); 10487877fdebSMatt Macy vdev_draid_map_alloc_read(zio, abd_offset, rr); 10497877fdebSMatt Macy } 10507877fdebSMatt Macy 10517877fdebSMatt Macy return (io_size); 10527877fdebSMatt Macy } 10537877fdebSMatt Macy 10547877fdebSMatt Macy /* 10557877fdebSMatt Macy * Allocate the raidz mapping to be applied to the dRAID I/O. The parity 10567877fdebSMatt Macy * calculations for dRAID are identical to raidz however there are a few 10577877fdebSMatt Macy * differences in the layout. 10587877fdebSMatt Macy * 10597877fdebSMatt Macy * - dRAID always allocates a full stripe width. Any extra sectors due 10607877fdebSMatt Macy * this padding are zero filled and written to disk. They will be read 10617877fdebSMatt Macy * back during a scrub or repair operation since they are included in 10627877fdebSMatt Macy * the parity calculation. This property enables sequential resilvering. 10637877fdebSMatt Macy * 10647877fdebSMatt Macy * - When the block at the logical offset spans redundancy groups then two 10657877fdebSMatt Macy * rows are allocated in the raidz_map_t. One row resides at the end of 10667877fdebSMatt Macy * the first group and the other at the start of the following group. 10677877fdebSMatt Macy */ 10687877fdebSMatt Macy static raidz_map_t * 10697877fdebSMatt Macy vdev_draid_map_alloc(zio_t *zio) 10707877fdebSMatt Macy { 10717877fdebSMatt Macy raidz_row_t *rr[2]; 10727877fdebSMatt Macy uint64_t abd_offset = 0; 10737877fdebSMatt Macy uint64_t abd_size = zio->io_size; 10747877fdebSMatt Macy uint64_t io_offset = zio->io_offset; 10757877fdebSMatt Macy uint64_t size; 10767877fdebSMatt Macy int nrows = 1; 10777877fdebSMatt Macy 10787877fdebSMatt Macy size = vdev_draid_map_alloc_row(zio, &rr[0], io_offset, 10797877fdebSMatt Macy abd_offset, abd_size); 10807877fdebSMatt Macy if (size < abd_size) { 10817877fdebSMatt Macy vdev_t *vd = zio->io_vd; 10827877fdebSMatt Macy 10837877fdebSMatt Macy io_offset += vdev_draid_asize(vd, size); 10847877fdebSMatt Macy abd_offset += size; 10857877fdebSMatt Macy abd_size -= size; 10867877fdebSMatt Macy nrows++; 10877877fdebSMatt Macy 10887877fdebSMatt Macy ASSERT3U(io_offset, ==, vdev_draid_group_to_offset( 10897877fdebSMatt Macy vd, vdev_draid_offset_to_group(vd, io_offset))); 10907877fdebSMatt Macy ASSERT3U(abd_offset, <, zio->io_size); 10917877fdebSMatt Macy ASSERT3U(abd_size, !=, 0); 10927877fdebSMatt Macy 10937877fdebSMatt Macy size = vdev_draid_map_alloc_row(zio, &rr[1], 10947877fdebSMatt Macy io_offset, abd_offset, abd_size); 10957877fdebSMatt Macy VERIFY3U(size, ==, abd_size); 10967877fdebSMatt Macy } 10977877fdebSMatt Macy 10987877fdebSMatt Macy raidz_map_t *rm; 10997877fdebSMatt Macy rm = kmem_zalloc(offsetof(raidz_map_t, rm_row[nrows]), KM_SLEEP); 11007877fdebSMatt Macy rm->rm_ops = vdev_raidz_math_get_ops(); 11017877fdebSMatt Macy rm->rm_nrows = nrows; 11027877fdebSMatt Macy rm->rm_row[0] = rr[0]; 11037877fdebSMatt Macy if (nrows == 2) 11047877fdebSMatt Macy rm->rm_row[1] = rr[1]; 11057877fdebSMatt Macy 11067877fdebSMatt Macy return (rm); 11077877fdebSMatt Macy } 11087877fdebSMatt Macy 11097877fdebSMatt Macy /* 11107877fdebSMatt Macy * Given an offset into a dRAID return the next group width aligned offset 11117877fdebSMatt Macy * which can be used to start an allocation. 11127877fdebSMatt Macy */ 11137877fdebSMatt Macy static uint64_t 11147877fdebSMatt Macy vdev_draid_get_astart(vdev_t *vd, const uint64_t start) 11157877fdebSMatt Macy { 11167877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 11177877fdebSMatt Macy 11187877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_ops); 11197877fdebSMatt Macy 11207877fdebSMatt Macy return (roundup(start, vdc->vdc_groupwidth << vd->vdev_ashift)); 11217877fdebSMatt Macy } 11227877fdebSMatt Macy 11237877fdebSMatt Macy /* 11247877fdebSMatt Macy * Allocatable space for dRAID is (children - nspares) * sizeof(smallest child) 11257877fdebSMatt Macy * rounded down to the last full slice. So each child must provide at least 11267877fdebSMatt Macy * 1 / (children - nspares) of its asize. 11277877fdebSMatt Macy */ 11287877fdebSMatt Macy static uint64_t 11297877fdebSMatt Macy vdev_draid_min_asize(vdev_t *vd) 11307877fdebSMatt Macy { 11317877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 11327877fdebSMatt Macy 11337877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_ops); 11347877fdebSMatt Macy 11350d8fe237SMartin Matuska return (VDEV_DRAID_REFLOW_RESERVE + 11360d8fe237SMartin Matuska (vd->vdev_min_asize + vdc->vdc_ndisks - 1) / (vdc->vdc_ndisks)); 11377877fdebSMatt Macy } 11387877fdebSMatt Macy 11397877fdebSMatt Macy /* 11407877fdebSMatt Macy * When using dRAID the minimum allocation size is determined by the number 11417877fdebSMatt Macy * of data disks in the redundancy group. Full stripes are always used. 11427877fdebSMatt Macy */ 11437877fdebSMatt Macy static uint64_t 11447877fdebSMatt Macy vdev_draid_min_alloc(vdev_t *vd) 11457877fdebSMatt Macy { 11467877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 11477877fdebSMatt Macy 11487877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_ops); 11497877fdebSMatt Macy 11507877fdebSMatt Macy return (vdc->vdc_ndata << vd->vdev_ashift); 11517877fdebSMatt Macy } 11527877fdebSMatt Macy 11537877fdebSMatt Macy /* 11547877fdebSMatt Macy * Returns true if the txg range does not exist on any leaf vdev. 11557877fdebSMatt Macy * 11567877fdebSMatt Macy * A dRAID spare does not fit into the DTL model. While it has child vdevs 11577877fdebSMatt Macy * there is no redundancy among them, and the effective child vdev is 11587877fdebSMatt Macy * determined by offset. Essentially we do a vdev_dtl_reassess() on the 11597877fdebSMatt Macy * fly by replacing a dRAID spare with the child vdev under the offset. 11607877fdebSMatt Macy * Note that it is a recursive process because the child vdev can be 11617877fdebSMatt Macy * another dRAID spare and so on. 11627877fdebSMatt Macy */ 11637877fdebSMatt Macy boolean_t 11647877fdebSMatt Macy vdev_draid_missing(vdev_t *vd, uint64_t physical_offset, uint64_t txg, 11657877fdebSMatt Macy uint64_t size) 11667877fdebSMatt Macy { 11677877fdebSMatt Macy if (vd->vdev_ops == &vdev_spare_ops || 11687877fdebSMatt Macy vd->vdev_ops == &vdev_replacing_ops) { 11697877fdebSMatt Macy /* 11707877fdebSMatt Macy * Check all of the readable children, if any child 11717877fdebSMatt Macy * contains the txg range the data it is not missing. 11727877fdebSMatt Macy */ 11737877fdebSMatt Macy for (int c = 0; c < vd->vdev_children; c++) { 11747877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[c]; 11757877fdebSMatt Macy 11767877fdebSMatt Macy if (!vdev_readable(cvd)) 11777877fdebSMatt Macy continue; 11787877fdebSMatt Macy 11797877fdebSMatt Macy if (!vdev_draid_missing(cvd, physical_offset, 11807877fdebSMatt Macy txg, size)) 11817877fdebSMatt Macy return (B_FALSE); 11827877fdebSMatt Macy } 11837877fdebSMatt Macy 11847877fdebSMatt Macy return (B_TRUE); 11857877fdebSMatt Macy } 11867877fdebSMatt Macy 11877877fdebSMatt Macy if (vd->vdev_ops == &vdev_draid_spare_ops) { 11887877fdebSMatt Macy /* 11897877fdebSMatt Macy * When sequentially resilvering we don't have a proper 11907877fdebSMatt Macy * txg range so instead we must presume all txgs are 11917877fdebSMatt Macy * missing on this vdev until the resilver completes. 11927877fdebSMatt Macy */ 11937877fdebSMatt Macy if (vd->vdev_rebuild_txg != 0) 11947877fdebSMatt Macy return (B_TRUE); 11957877fdebSMatt Macy 11967877fdebSMatt Macy /* 11977877fdebSMatt Macy * DTL_MISSING is set for all prior txgs when a resilver 11987877fdebSMatt Macy * is started in spa_vdev_attach(). 11997877fdebSMatt Macy */ 12007877fdebSMatt Macy if (vdev_dtl_contains(vd, DTL_MISSING, txg, size)) 12017877fdebSMatt Macy return (B_TRUE); 12027877fdebSMatt Macy 12037877fdebSMatt Macy /* 12047877fdebSMatt Macy * Consult the DTL on the relevant vdev. Either a vdev 12057877fdebSMatt Macy * leaf or spare/replace mirror child may be returned so 12067877fdebSMatt Macy * we must recursively call vdev_draid_missing_impl(). 12077877fdebSMatt Macy */ 12087877fdebSMatt Macy vd = vdev_draid_spare_get_child(vd, physical_offset); 12097877fdebSMatt Macy if (vd == NULL) 12107877fdebSMatt Macy return (B_TRUE); 12117877fdebSMatt Macy 12127877fdebSMatt Macy return (vdev_draid_missing(vd, physical_offset, 12137877fdebSMatt Macy txg, size)); 12147877fdebSMatt Macy } 12157877fdebSMatt Macy 12167877fdebSMatt Macy return (vdev_dtl_contains(vd, DTL_MISSING, txg, size)); 12177877fdebSMatt Macy } 12187877fdebSMatt Macy 12197877fdebSMatt Macy /* 12207877fdebSMatt Macy * Returns true if the txg is only partially replicated on the leaf vdevs. 12217877fdebSMatt Macy */ 12227877fdebSMatt Macy static boolean_t 12237877fdebSMatt Macy vdev_draid_partial(vdev_t *vd, uint64_t physical_offset, uint64_t txg, 12247877fdebSMatt Macy uint64_t size) 12257877fdebSMatt Macy { 12267877fdebSMatt Macy if (vd->vdev_ops == &vdev_spare_ops || 12277877fdebSMatt Macy vd->vdev_ops == &vdev_replacing_ops) { 12287877fdebSMatt Macy /* 12297877fdebSMatt Macy * Check all of the readable children, if any child is 12307877fdebSMatt Macy * missing the txg range then it is partially replicated. 12317877fdebSMatt Macy */ 12327877fdebSMatt Macy for (int c = 0; c < vd->vdev_children; c++) { 12337877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[c]; 12347877fdebSMatt Macy 12357877fdebSMatt Macy if (!vdev_readable(cvd)) 12367877fdebSMatt Macy continue; 12377877fdebSMatt Macy 12387877fdebSMatt Macy if (vdev_draid_partial(cvd, physical_offset, txg, size)) 12397877fdebSMatt Macy return (B_TRUE); 12407877fdebSMatt Macy } 12417877fdebSMatt Macy 12427877fdebSMatt Macy return (B_FALSE); 12437877fdebSMatt Macy } 12447877fdebSMatt Macy 12457877fdebSMatt Macy if (vd->vdev_ops == &vdev_draid_spare_ops) { 12467877fdebSMatt Macy /* 12477877fdebSMatt Macy * When sequentially resilvering we don't have a proper 12487877fdebSMatt Macy * txg range so instead we must presume all txgs are 12497877fdebSMatt Macy * missing on this vdev until the resilver completes. 12507877fdebSMatt Macy */ 12517877fdebSMatt Macy if (vd->vdev_rebuild_txg != 0) 12527877fdebSMatt Macy return (B_TRUE); 12537877fdebSMatt Macy 12547877fdebSMatt Macy /* 12557877fdebSMatt Macy * DTL_MISSING is set for all prior txgs when a resilver 12567877fdebSMatt Macy * is started in spa_vdev_attach(). 12577877fdebSMatt Macy */ 12587877fdebSMatt Macy if (vdev_dtl_contains(vd, DTL_MISSING, txg, size)) 12597877fdebSMatt Macy return (B_TRUE); 12607877fdebSMatt Macy 12617877fdebSMatt Macy /* 12627877fdebSMatt Macy * Consult the DTL on the relevant vdev. Either a vdev 12637877fdebSMatt Macy * leaf or spare/replace mirror child may be returned so 12647877fdebSMatt Macy * we must recursively call vdev_draid_missing_impl(). 12657877fdebSMatt Macy */ 12667877fdebSMatt Macy vd = vdev_draid_spare_get_child(vd, physical_offset); 12677877fdebSMatt Macy if (vd == NULL) 12687877fdebSMatt Macy return (B_TRUE); 12697877fdebSMatt Macy 12707877fdebSMatt Macy return (vdev_draid_partial(vd, physical_offset, txg, size)); 12717877fdebSMatt Macy } 12727877fdebSMatt Macy 12737877fdebSMatt Macy return (vdev_dtl_contains(vd, DTL_MISSING, txg, size)); 12747877fdebSMatt Macy } 12757877fdebSMatt Macy 12767877fdebSMatt Macy /* 12777877fdebSMatt Macy * Determine if the vdev is readable at the given offset. 12787877fdebSMatt Macy */ 12797877fdebSMatt Macy boolean_t 12807877fdebSMatt Macy vdev_draid_readable(vdev_t *vd, uint64_t physical_offset) 12817877fdebSMatt Macy { 12827877fdebSMatt Macy if (vd->vdev_ops == &vdev_draid_spare_ops) { 12837877fdebSMatt Macy vd = vdev_draid_spare_get_child(vd, physical_offset); 12847877fdebSMatt Macy if (vd == NULL) 12857877fdebSMatt Macy return (B_FALSE); 12867877fdebSMatt Macy } 12877877fdebSMatt Macy 12887877fdebSMatt Macy if (vd->vdev_ops == &vdev_spare_ops || 12897877fdebSMatt Macy vd->vdev_ops == &vdev_replacing_ops) { 12907877fdebSMatt Macy 12917877fdebSMatt Macy for (int c = 0; c < vd->vdev_children; c++) { 12927877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[c]; 12937877fdebSMatt Macy 12947877fdebSMatt Macy if (!vdev_readable(cvd)) 12957877fdebSMatt Macy continue; 12967877fdebSMatt Macy 12977877fdebSMatt Macy if (vdev_draid_readable(cvd, physical_offset)) 12987877fdebSMatt Macy return (B_TRUE); 12997877fdebSMatt Macy } 13007877fdebSMatt Macy 13017877fdebSMatt Macy return (B_FALSE); 13027877fdebSMatt Macy } 13037877fdebSMatt Macy 13047877fdebSMatt Macy return (vdev_readable(vd)); 13057877fdebSMatt Macy } 13067877fdebSMatt Macy 13077877fdebSMatt Macy /* 13087877fdebSMatt Macy * Returns the first distributed spare found under the provided vdev tree. 13097877fdebSMatt Macy */ 13107877fdebSMatt Macy static vdev_t * 13117877fdebSMatt Macy vdev_draid_find_spare(vdev_t *vd) 13127877fdebSMatt Macy { 13137877fdebSMatt Macy if (vd->vdev_ops == &vdev_draid_spare_ops) 13147877fdebSMatt Macy return (vd); 13157877fdebSMatt Macy 13167877fdebSMatt Macy for (int c = 0; c < vd->vdev_children; c++) { 13177877fdebSMatt Macy vdev_t *svd = vdev_draid_find_spare(vd->vdev_child[c]); 13187877fdebSMatt Macy if (svd != NULL) 13197877fdebSMatt Macy return (svd); 13207877fdebSMatt Macy } 13217877fdebSMatt Macy 13227877fdebSMatt Macy return (NULL); 13237877fdebSMatt Macy } 13247877fdebSMatt Macy 13257877fdebSMatt Macy /* 13267877fdebSMatt Macy * Returns B_TRUE if the passed in vdev is currently "faulted". 13277877fdebSMatt Macy * Faulted, in this context, means that the vdev represents a 13287877fdebSMatt Macy * replacing or sparing vdev tree. 13297877fdebSMatt Macy */ 13307877fdebSMatt Macy static boolean_t 13317877fdebSMatt Macy vdev_draid_faulted(vdev_t *vd, uint64_t physical_offset) 13327877fdebSMatt Macy { 13337877fdebSMatt Macy if (vd->vdev_ops == &vdev_draid_spare_ops) { 13347877fdebSMatt Macy vd = vdev_draid_spare_get_child(vd, physical_offset); 13357877fdebSMatt Macy if (vd == NULL) 13367877fdebSMatt Macy return (B_FALSE); 13377877fdebSMatt Macy 13387877fdebSMatt Macy /* 13397877fdebSMatt Macy * After resolving the distributed spare to a leaf vdev 13407877fdebSMatt Macy * check the parent to determine if it's "faulted". 13417877fdebSMatt Macy */ 13427877fdebSMatt Macy vd = vd->vdev_parent; 13437877fdebSMatt Macy } 13447877fdebSMatt Macy 13457877fdebSMatt Macy return (vd->vdev_ops == &vdev_replacing_ops || 13467877fdebSMatt Macy vd->vdev_ops == &vdev_spare_ops); 13477877fdebSMatt Macy } 13487877fdebSMatt Macy 13497877fdebSMatt Macy /* 13507877fdebSMatt Macy * Determine if the dRAID block at the logical offset is degraded. 13517877fdebSMatt Macy * Used by sequential resilver. 13527877fdebSMatt Macy */ 13537877fdebSMatt Macy static boolean_t 13547877fdebSMatt Macy vdev_draid_group_degraded(vdev_t *vd, uint64_t offset) 13557877fdebSMatt Macy { 13567877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 13577877fdebSMatt Macy 13587877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_ops); 13597877fdebSMatt Macy ASSERT3U(vdev_draid_get_astart(vd, offset), ==, offset); 13607877fdebSMatt Macy 13617877fdebSMatt Macy uint64_t groupstart, perm; 13627877fdebSMatt Macy uint64_t physical_offset = vdev_draid_logical_to_physical(vd, 13637877fdebSMatt Macy offset, &perm, &groupstart); 13647877fdebSMatt Macy 13657877fdebSMatt Macy uint8_t *base; 13667877fdebSMatt Macy uint64_t iter; 13677877fdebSMatt Macy vdev_draid_get_perm(vdc, perm, &base, &iter); 13687877fdebSMatt Macy 13697877fdebSMatt Macy for (uint64_t i = 0; i < vdc->vdc_groupwidth; i++) { 13707877fdebSMatt Macy uint64_t c = (groupstart + i) % vdc->vdc_ndisks; 13717877fdebSMatt Macy uint64_t cid = vdev_draid_permute_id(vdc, base, iter, c); 13727877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[cid]; 13737877fdebSMatt Macy 13747877fdebSMatt Macy /* Group contains a faulted vdev. */ 13757877fdebSMatt Macy if (vdev_draid_faulted(cvd, physical_offset)) 13767877fdebSMatt Macy return (B_TRUE); 13777877fdebSMatt Macy 13787877fdebSMatt Macy /* 13797877fdebSMatt Macy * Always check groups with active distributed spares 13807877fdebSMatt Macy * because any vdev failure in the pool will affect them. 13817877fdebSMatt Macy */ 13827877fdebSMatt Macy if (vdev_draid_find_spare(cvd) != NULL) 13837877fdebSMatt Macy return (B_TRUE); 13847877fdebSMatt Macy } 13857877fdebSMatt Macy 13867877fdebSMatt Macy return (B_FALSE); 13877877fdebSMatt Macy } 13887877fdebSMatt Macy 13897877fdebSMatt Macy /* 13907877fdebSMatt Macy * Determine if the txg is missing. Used by healing resilver. 13917877fdebSMatt Macy */ 13927877fdebSMatt Macy static boolean_t 13937877fdebSMatt Macy vdev_draid_group_missing(vdev_t *vd, uint64_t offset, uint64_t txg, 13947877fdebSMatt Macy uint64_t size) 13957877fdebSMatt Macy { 13967877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 13977877fdebSMatt Macy 13987877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_ops); 13997877fdebSMatt Macy ASSERT3U(vdev_draid_get_astart(vd, offset), ==, offset); 14007877fdebSMatt Macy 14017877fdebSMatt Macy uint64_t groupstart, perm; 14027877fdebSMatt Macy uint64_t physical_offset = vdev_draid_logical_to_physical(vd, 14037877fdebSMatt Macy offset, &perm, &groupstart); 14047877fdebSMatt Macy 14057877fdebSMatt Macy uint8_t *base; 14067877fdebSMatt Macy uint64_t iter; 14077877fdebSMatt Macy vdev_draid_get_perm(vdc, perm, &base, &iter); 14087877fdebSMatt Macy 14097877fdebSMatt Macy for (uint64_t i = 0; i < vdc->vdc_groupwidth; i++) { 14107877fdebSMatt Macy uint64_t c = (groupstart + i) % vdc->vdc_ndisks; 14117877fdebSMatt Macy uint64_t cid = vdev_draid_permute_id(vdc, base, iter, c); 14127877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[cid]; 14137877fdebSMatt Macy 14147877fdebSMatt Macy /* Transaction group is known to be partially replicated. */ 14157877fdebSMatt Macy if (vdev_draid_partial(cvd, physical_offset, txg, size)) 14167877fdebSMatt Macy return (B_TRUE); 14177877fdebSMatt Macy 14187877fdebSMatt Macy /* 14197877fdebSMatt Macy * Always check groups with active distributed spares 14207877fdebSMatt Macy * because any vdev failure in the pool will affect them. 14217877fdebSMatt Macy */ 14227877fdebSMatt Macy if (vdev_draid_find_spare(cvd) != NULL) 14237877fdebSMatt Macy return (B_TRUE); 14247877fdebSMatt Macy } 14257877fdebSMatt Macy 14267877fdebSMatt Macy return (B_FALSE); 14277877fdebSMatt Macy } 14287877fdebSMatt Macy 14297877fdebSMatt Macy /* 14307877fdebSMatt Macy * Find the smallest child asize and largest sector size to calculate the 14317877fdebSMatt Macy * available capacity. Distributed spares are ignored since their capacity 14327877fdebSMatt Macy * is also based of the minimum child size in the top-level dRAID. 14337877fdebSMatt Macy */ 14347877fdebSMatt Macy static void 14357877fdebSMatt Macy vdev_draid_calculate_asize(vdev_t *vd, uint64_t *asizep, uint64_t *max_asizep, 14367877fdebSMatt Macy uint64_t *logical_ashiftp, uint64_t *physical_ashiftp) 14377877fdebSMatt Macy { 14387877fdebSMatt Macy uint64_t logical_ashift = 0, physical_ashift = 0; 14397877fdebSMatt Macy uint64_t asize = 0, max_asize = 0; 14407877fdebSMatt Macy 14417877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_ops); 14427877fdebSMatt Macy 14437877fdebSMatt Macy for (int c = 0; c < vd->vdev_children; c++) { 14447877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[c]; 14457877fdebSMatt Macy 14467877fdebSMatt Macy if (cvd->vdev_ops == &vdev_draid_spare_ops) 14477877fdebSMatt Macy continue; 14487877fdebSMatt Macy 14497877fdebSMatt Macy asize = MIN(asize - 1, cvd->vdev_asize - 1) + 1; 14507877fdebSMatt Macy max_asize = MIN(max_asize - 1, cvd->vdev_max_asize - 1) + 1; 14517877fdebSMatt Macy logical_ashift = MAX(logical_ashift, cvd->vdev_ashift); 14527877fdebSMatt Macy physical_ashift = MAX(physical_ashift, 14537877fdebSMatt Macy cvd->vdev_physical_ashift); 14547877fdebSMatt Macy } 14557877fdebSMatt Macy 14567877fdebSMatt Macy *asizep = asize; 14577877fdebSMatt Macy *max_asizep = max_asize; 14587877fdebSMatt Macy *logical_ashiftp = logical_ashift; 14597877fdebSMatt Macy *physical_ashiftp = physical_ashift; 14607877fdebSMatt Macy } 14617877fdebSMatt Macy 14627877fdebSMatt Macy /* 14637877fdebSMatt Macy * Open spare vdevs. 14647877fdebSMatt Macy */ 14657877fdebSMatt Macy static boolean_t 14667877fdebSMatt Macy vdev_draid_open_spares(vdev_t *vd) 14677877fdebSMatt Macy { 14687877fdebSMatt Macy return (vd->vdev_ops == &vdev_draid_spare_ops || 14697877fdebSMatt Macy vd->vdev_ops == &vdev_replacing_ops || 14707877fdebSMatt Macy vd->vdev_ops == &vdev_spare_ops); 14717877fdebSMatt Macy } 14727877fdebSMatt Macy 14737877fdebSMatt Macy /* 14747877fdebSMatt Macy * Open all children, excluding spares. 14757877fdebSMatt Macy */ 14767877fdebSMatt Macy static boolean_t 14777877fdebSMatt Macy vdev_draid_open_children(vdev_t *vd) 14787877fdebSMatt Macy { 14797877fdebSMatt Macy return (!vdev_draid_open_spares(vd)); 14807877fdebSMatt Macy } 14817877fdebSMatt Macy 14827877fdebSMatt Macy /* 14837877fdebSMatt Macy * Open a top-level dRAID vdev. 14847877fdebSMatt Macy */ 14857877fdebSMatt Macy static int 14867877fdebSMatt Macy vdev_draid_open(vdev_t *vd, uint64_t *asize, uint64_t *max_asize, 14877877fdebSMatt Macy uint64_t *logical_ashift, uint64_t *physical_ashift) 14887877fdebSMatt Macy { 14897877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 14907877fdebSMatt Macy uint64_t nparity = vdc->vdc_nparity; 14917877fdebSMatt Macy int open_errors = 0; 14927877fdebSMatt Macy 14937877fdebSMatt Macy if (nparity > VDEV_DRAID_MAXPARITY || 14947877fdebSMatt Macy vd->vdev_children < nparity + 1) { 14957877fdebSMatt Macy vd->vdev_stat.vs_aux = VDEV_AUX_BAD_LABEL; 14967877fdebSMatt Macy return (SET_ERROR(EINVAL)); 14977877fdebSMatt Macy } 14987877fdebSMatt Macy 14997877fdebSMatt Macy /* 15007877fdebSMatt Macy * First open the normal children then the distributed spares. This 15017877fdebSMatt Macy * ordering is important to ensure the distributed spares calculate 15027877fdebSMatt Macy * the correct psize in the event that the dRAID vdevs were expanded. 15037877fdebSMatt Macy */ 15047877fdebSMatt Macy vdev_open_children_subset(vd, vdev_draid_open_children); 15057877fdebSMatt Macy vdev_open_children_subset(vd, vdev_draid_open_spares); 15067877fdebSMatt Macy 15077877fdebSMatt Macy /* Verify enough of the children are available to continue. */ 15087877fdebSMatt Macy for (int c = 0; c < vd->vdev_children; c++) { 15097877fdebSMatt Macy if (vd->vdev_child[c]->vdev_open_error != 0) { 15107877fdebSMatt Macy if ((++open_errors) > nparity) { 15117877fdebSMatt Macy vd->vdev_stat.vs_aux = VDEV_AUX_NO_REPLICAS; 15127877fdebSMatt Macy return (SET_ERROR(ENXIO)); 15137877fdebSMatt Macy } 15147877fdebSMatt Macy } 15157877fdebSMatt Macy } 15167877fdebSMatt Macy 15177877fdebSMatt Macy /* 15187877fdebSMatt Macy * Allocatable capacity is the sum of the space on all children less 15197877fdebSMatt Macy * the number of distributed spares rounded down to last full row 15207877fdebSMatt Macy * and then to the last full group. An additional 32MB of scratch 15217877fdebSMatt Macy * space is reserved at the end of each child for use by the dRAID 15227877fdebSMatt Macy * expansion feature. 15237877fdebSMatt Macy */ 15247877fdebSMatt Macy uint64_t child_asize, child_max_asize; 15257877fdebSMatt Macy vdev_draid_calculate_asize(vd, &child_asize, &child_max_asize, 15267877fdebSMatt Macy logical_ashift, physical_ashift); 15277877fdebSMatt Macy 15287877fdebSMatt Macy /* 15297877fdebSMatt Macy * Should be unreachable since the minimum child size is 64MB, but 15307877fdebSMatt Macy * we want to make sure an underflow absolutely cannot occur here. 15317877fdebSMatt Macy */ 15327877fdebSMatt Macy if (child_asize < VDEV_DRAID_REFLOW_RESERVE || 15337877fdebSMatt Macy child_max_asize < VDEV_DRAID_REFLOW_RESERVE) { 15347877fdebSMatt Macy return (SET_ERROR(ENXIO)); 15357877fdebSMatt Macy } 15367877fdebSMatt Macy 15377877fdebSMatt Macy child_asize = ((child_asize - VDEV_DRAID_REFLOW_RESERVE) / 15387877fdebSMatt Macy VDEV_DRAID_ROWHEIGHT) * VDEV_DRAID_ROWHEIGHT; 15397877fdebSMatt Macy child_max_asize = ((child_max_asize - VDEV_DRAID_REFLOW_RESERVE) / 15407877fdebSMatt Macy VDEV_DRAID_ROWHEIGHT) * VDEV_DRAID_ROWHEIGHT; 15417877fdebSMatt Macy 15427877fdebSMatt Macy *asize = (((child_asize * vdc->vdc_ndisks) / vdc->vdc_groupsz) * 15437877fdebSMatt Macy vdc->vdc_groupsz); 15447877fdebSMatt Macy *max_asize = (((child_max_asize * vdc->vdc_ndisks) / vdc->vdc_groupsz) * 15457877fdebSMatt Macy vdc->vdc_groupsz); 15467877fdebSMatt Macy 15477877fdebSMatt Macy return (0); 15487877fdebSMatt Macy } 15497877fdebSMatt Macy 15507877fdebSMatt Macy /* 15517877fdebSMatt Macy * Close a top-level dRAID vdev. 15527877fdebSMatt Macy */ 15537877fdebSMatt Macy static void 15547877fdebSMatt Macy vdev_draid_close(vdev_t *vd) 15557877fdebSMatt Macy { 15567877fdebSMatt Macy for (int c = 0; c < vd->vdev_children; c++) { 15577877fdebSMatt Macy if (vd->vdev_child[c] != NULL) 15587877fdebSMatt Macy vdev_close(vd->vdev_child[c]); 15597877fdebSMatt Macy } 15607877fdebSMatt Macy } 15617877fdebSMatt Macy 15627877fdebSMatt Macy /* 15637877fdebSMatt Macy * Return the maximum asize for a rebuild zio in the provided range 15647877fdebSMatt Macy * given the following constraints. A dRAID chunks may not: 15657877fdebSMatt Macy * 15667877fdebSMatt Macy * - Exceed the maximum allowed block size (SPA_MAXBLOCKSIZE), or 15677877fdebSMatt Macy * - Span dRAID redundancy groups. 15687877fdebSMatt Macy */ 15697877fdebSMatt Macy static uint64_t 15707877fdebSMatt Macy vdev_draid_rebuild_asize(vdev_t *vd, uint64_t start, uint64_t asize, 15717877fdebSMatt Macy uint64_t max_segment) 15727877fdebSMatt Macy { 15737877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 15747877fdebSMatt Macy 15757877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_ops); 15767877fdebSMatt Macy 15777877fdebSMatt Macy uint64_t ashift = vd->vdev_ashift; 15787877fdebSMatt Macy uint64_t ndata = vdc->vdc_ndata; 15797877fdebSMatt Macy uint64_t psize = MIN(P2ROUNDUP(max_segment * ndata, 1 << ashift), 15807877fdebSMatt Macy SPA_MAXBLOCKSIZE); 15817877fdebSMatt Macy 15827877fdebSMatt Macy ASSERT3U(vdev_draid_get_astart(vd, start), ==, start); 15837877fdebSMatt Macy ASSERT3U(asize % (vdc->vdc_groupwidth << ashift), ==, 0); 15847877fdebSMatt Macy 15857877fdebSMatt Macy /* Chunks must evenly span all data columns in the group. */ 15867877fdebSMatt Macy psize = (((psize >> ashift) / ndata) * ndata) << ashift; 15877877fdebSMatt Macy uint64_t chunk_size = MIN(asize, vdev_psize_to_asize(vd, psize)); 15887877fdebSMatt Macy 15897877fdebSMatt Macy /* Reduce the chunk size to the group space remaining. */ 15907877fdebSMatt Macy uint64_t group = vdev_draid_offset_to_group(vd, start); 15917877fdebSMatt Macy uint64_t left = vdev_draid_group_to_offset(vd, group + 1) - start; 15927877fdebSMatt Macy chunk_size = MIN(chunk_size, left); 15937877fdebSMatt Macy 15947877fdebSMatt Macy ASSERT3U(chunk_size % (vdc->vdc_groupwidth << ashift), ==, 0); 15957877fdebSMatt Macy ASSERT3U(vdev_draid_offset_to_group(vd, start), ==, 15967877fdebSMatt Macy vdev_draid_offset_to_group(vd, start + chunk_size - 1)); 15977877fdebSMatt Macy 15987877fdebSMatt Macy return (chunk_size); 15997877fdebSMatt Macy } 16007877fdebSMatt Macy 16017877fdebSMatt Macy /* 16027877fdebSMatt Macy * Align the start of the metaslab to the group width and slightly reduce 16037877fdebSMatt Macy * its size to a multiple of the group width. Since full stripe writes are 16047877fdebSMatt Macy * required by dRAID this space is unallocable. Furthermore, aligning the 16057877fdebSMatt Macy * metaslab start is important for vdev initialize and TRIM which both operate 16067877fdebSMatt Macy * on metaslab boundaries which vdev_xlate() expects to be aligned. 16077877fdebSMatt Macy */ 16087877fdebSMatt Macy static void 16097877fdebSMatt Macy vdev_draid_metaslab_init(vdev_t *vd, uint64_t *ms_start, uint64_t *ms_size) 16107877fdebSMatt Macy { 16117877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 16127877fdebSMatt Macy 16137877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_ops); 16147877fdebSMatt Macy 16157877fdebSMatt Macy uint64_t sz = vdc->vdc_groupwidth << vd->vdev_ashift; 16167877fdebSMatt Macy uint64_t astart = vdev_draid_get_astart(vd, *ms_start); 16177877fdebSMatt Macy uint64_t asize = ((*ms_size - (astart - *ms_start)) / sz) * sz; 16187877fdebSMatt Macy 16197877fdebSMatt Macy *ms_start = astart; 16207877fdebSMatt Macy *ms_size = asize; 16217877fdebSMatt Macy 16227877fdebSMatt Macy ASSERT0(*ms_start % sz); 16237877fdebSMatt Macy ASSERT0(*ms_size % sz); 16247877fdebSMatt Macy } 16257877fdebSMatt Macy 16267877fdebSMatt Macy /* 16277877fdebSMatt Macy * Add virtual dRAID spares to the list of valid spares. In order to accomplish 16287877fdebSMatt Macy * this the existing array must be freed and reallocated with the additional 16297877fdebSMatt Macy * entries. 16307877fdebSMatt Macy */ 16317877fdebSMatt Macy int 16327877fdebSMatt Macy vdev_draid_spare_create(nvlist_t *nvroot, vdev_t *vd, uint64_t *ndraidp, 16337877fdebSMatt Macy uint64_t next_vdev_id) 16347877fdebSMatt Macy { 16357877fdebSMatt Macy uint64_t draid_nspares = 0; 16367877fdebSMatt Macy uint64_t ndraid = 0; 16377877fdebSMatt Macy int error; 16387877fdebSMatt Macy 16397877fdebSMatt Macy for (uint64_t i = 0; i < vd->vdev_children; i++) { 16407877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[i]; 16417877fdebSMatt Macy 16427877fdebSMatt Macy if (cvd->vdev_ops == &vdev_draid_ops) { 16437877fdebSMatt Macy vdev_draid_config_t *vdc = cvd->vdev_tsd; 16447877fdebSMatt Macy draid_nspares += vdc->vdc_nspares; 16457877fdebSMatt Macy ndraid++; 16467877fdebSMatt Macy } 16477877fdebSMatt Macy } 16487877fdebSMatt Macy 16497877fdebSMatt Macy if (draid_nspares == 0) { 16507877fdebSMatt Macy *ndraidp = ndraid; 16517877fdebSMatt Macy return (0); 16527877fdebSMatt Macy } 16537877fdebSMatt Macy 16547877fdebSMatt Macy nvlist_t **old_spares, **new_spares; 16557877fdebSMatt Macy uint_t old_nspares; 16567877fdebSMatt Macy error = nvlist_lookup_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, 16577877fdebSMatt Macy &old_spares, &old_nspares); 16587877fdebSMatt Macy if (error) 16597877fdebSMatt Macy old_nspares = 0; 16607877fdebSMatt Macy 16617877fdebSMatt Macy /* Allocate memory and copy of the existing spares. */ 16627877fdebSMatt Macy new_spares = kmem_alloc(sizeof (nvlist_t *) * 16637877fdebSMatt Macy (draid_nspares + old_nspares), KM_SLEEP); 16647877fdebSMatt Macy for (uint_t i = 0; i < old_nspares; i++) 16657877fdebSMatt Macy new_spares[i] = fnvlist_dup(old_spares[i]); 16667877fdebSMatt Macy 16677877fdebSMatt Macy /* Add new distributed spares to ZPOOL_CONFIG_SPARES. */ 16687877fdebSMatt Macy uint64_t n = old_nspares; 16697877fdebSMatt Macy for (uint64_t vdev_id = 0; vdev_id < vd->vdev_children; vdev_id++) { 16707877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[vdev_id]; 16717877fdebSMatt Macy char path[64]; 16727877fdebSMatt Macy 16737877fdebSMatt Macy if (cvd->vdev_ops != &vdev_draid_ops) 16747877fdebSMatt Macy continue; 16757877fdebSMatt Macy 16767877fdebSMatt Macy vdev_draid_config_t *vdc = cvd->vdev_tsd; 16777877fdebSMatt Macy uint64_t nspares = vdc->vdc_nspares; 16787877fdebSMatt Macy uint64_t nparity = vdc->vdc_nparity; 16797877fdebSMatt Macy 16807877fdebSMatt Macy for (uint64_t spare_id = 0; spare_id < nspares; spare_id++) { 16817877fdebSMatt Macy bzero(path, sizeof (path)); 16827877fdebSMatt Macy (void) snprintf(path, sizeof (path) - 1, 16837877fdebSMatt Macy "%s%llu-%llu-%llu", VDEV_TYPE_DRAID, 16847877fdebSMatt Macy (u_longlong_t)nparity, 16857877fdebSMatt Macy (u_longlong_t)next_vdev_id + vdev_id, 16867877fdebSMatt Macy (u_longlong_t)spare_id); 16877877fdebSMatt Macy 16887877fdebSMatt Macy nvlist_t *spare = fnvlist_alloc(); 16897877fdebSMatt Macy fnvlist_add_string(spare, ZPOOL_CONFIG_PATH, path); 16907877fdebSMatt Macy fnvlist_add_string(spare, ZPOOL_CONFIG_TYPE, 16917877fdebSMatt Macy VDEV_TYPE_DRAID_SPARE); 16927877fdebSMatt Macy fnvlist_add_uint64(spare, ZPOOL_CONFIG_TOP_GUID, 16937877fdebSMatt Macy cvd->vdev_guid); 16947877fdebSMatt Macy fnvlist_add_uint64(spare, ZPOOL_CONFIG_SPARE_ID, 16957877fdebSMatt Macy spare_id); 16967877fdebSMatt Macy fnvlist_add_uint64(spare, ZPOOL_CONFIG_IS_LOG, 0); 16977877fdebSMatt Macy fnvlist_add_uint64(spare, ZPOOL_CONFIG_IS_SPARE, 1); 16987877fdebSMatt Macy fnvlist_add_uint64(spare, ZPOOL_CONFIG_WHOLE_DISK, 1); 16997877fdebSMatt Macy fnvlist_add_uint64(spare, ZPOOL_CONFIG_ASHIFT, 17007877fdebSMatt Macy cvd->vdev_ashift); 17017877fdebSMatt Macy 17027877fdebSMatt Macy new_spares[n] = spare; 17037877fdebSMatt Macy n++; 17047877fdebSMatt Macy } 17057877fdebSMatt Macy } 17067877fdebSMatt Macy 17077877fdebSMatt Macy if (n > 0) { 17087877fdebSMatt Macy (void) nvlist_remove_all(nvroot, ZPOOL_CONFIG_SPARES); 17097877fdebSMatt Macy fnvlist_add_nvlist_array(nvroot, ZPOOL_CONFIG_SPARES, 1710*681ce946SMartin Matuska (const nvlist_t **)new_spares, n); 17117877fdebSMatt Macy } 17127877fdebSMatt Macy 17137877fdebSMatt Macy for (int i = 0; i < n; i++) 17147877fdebSMatt Macy nvlist_free(new_spares[i]); 17157877fdebSMatt Macy 17167877fdebSMatt Macy kmem_free(new_spares, sizeof (*new_spares) * n); 17177877fdebSMatt Macy *ndraidp = ndraid; 17187877fdebSMatt Macy 17197877fdebSMatt Macy return (0); 17207877fdebSMatt Macy } 17217877fdebSMatt Macy 17227877fdebSMatt Macy /* 17237877fdebSMatt Macy * Determine if any portion of the provided block resides on a child vdev 17247877fdebSMatt Macy * with a dirty DTL and therefore needs to be resilvered. 17257877fdebSMatt Macy */ 17267877fdebSMatt Macy static boolean_t 17277877fdebSMatt Macy vdev_draid_need_resilver(vdev_t *vd, const dva_t *dva, size_t psize, 17287877fdebSMatt Macy uint64_t phys_birth) 17297877fdebSMatt Macy { 17307877fdebSMatt Macy uint64_t offset = DVA_GET_OFFSET(dva); 17317877fdebSMatt Macy uint64_t asize = vdev_draid_asize(vd, psize); 17327877fdebSMatt Macy 17337877fdebSMatt Macy if (phys_birth == TXG_UNKNOWN) { 17347877fdebSMatt Macy /* 17357877fdebSMatt Macy * Sequential resilver. There is no meaningful phys_birth 17367877fdebSMatt Macy * for this block, we can only determine if block resides 17377877fdebSMatt Macy * in a degraded group in which case it must be resilvered. 17387877fdebSMatt Macy */ 17397877fdebSMatt Macy ASSERT3U(vdev_draid_offset_to_group(vd, offset), ==, 17407877fdebSMatt Macy vdev_draid_offset_to_group(vd, offset + asize - 1)); 17417877fdebSMatt Macy 17427877fdebSMatt Macy return (vdev_draid_group_degraded(vd, offset)); 17437877fdebSMatt Macy } else { 17447877fdebSMatt Macy /* 17457877fdebSMatt Macy * Healing resilver. TXGs not in DTL_PARTIAL are intact, 17467877fdebSMatt Macy * as are blocks in non-degraded groups. 17477877fdebSMatt Macy */ 17487877fdebSMatt Macy if (!vdev_dtl_contains(vd, DTL_PARTIAL, phys_birth, 1)) 17497877fdebSMatt Macy return (B_FALSE); 17507877fdebSMatt Macy 17517877fdebSMatt Macy if (vdev_draid_group_missing(vd, offset, phys_birth, 1)) 17527877fdebSMatt Macy return (B_TRUE); 17537877fdebSMatt Macy 17547877fdebSMatt Macy /* The block may span groups in which case check both. */ 17557877fdebSMatt Macy if (vdev_draid_offset_to_group(vd, offset) != 17567877fdebSMatt Macy vdev_draid_offset_to_group(vd, offset + asize - 1)) { 17577877fdebSMatt Macy if (vdev_draid_group_missing(vd, 17587877fdebSMatt Macy offset + asize, phys_birth, 1)) 17597877fdebSMatt Macy return (B_TRUE); 17607877fdebSMatt Macy } 17617877fdebSMatt Macy 17627877fdebSMatt Macy return (B_FALSE); 17637877fdebSMatt Macy } 17647877fdebSMatt Macy } 17657877fdebSMatt Macy 17667877fdebSMatt Macy static boolean_t 17677877fdebSMatt Macy vdev_draid_rebuilding(vdev_t *vd) 17687877fdebSMatt Macy { 17697877fdebSMatt Macy if (vd->vdev_ops->vdev_op_leaf && vd->vdev_rebuild_txg) 17707877fdebSMatt Macy return (B_TRUE); 17717877fdebSMatt Macy 17727877fdebSMatt Macy for (int i = 0; i < vd->vdev_children; i++) { 17737877fdebSMatt Macy if (vdev_draid_rebuilding(vd->vdev_child[i])) { 17747877fdebSMatt Macy return (B_TRUE); 17757877fdebSMatt Macy } 17767877fdebSMatt Macy } 17777877fdebSMatt Macy 17787877fdebSMatt Macy return (B_FALSE); 17797877fdebSMatt Macy } 17807877fdebSMatt Macy 17817877fdebSMatt Macy static void 17827877fdebSMatt Macy vdev_draid_io_verify(vdev_t *vd, raidz_row_t *rr, int col) 17837877fdebSMatt Macy { 17847877fdebSMatt Macy #ifdef ZFS_DEBUG 17857877fdebSMatt Macy range_seg64_t logical_rs, physical_rs, remain_rs; 17867877fdebSMatt Macy logical_rs.rs_start = rr->rr_offset; 17877877fdebSMatt Macy logical_rs.rs_end = logical_rs.rs_start + 17887877fdebSMatt Macy vdev_draid_asize(vd, rr->rr_size); 17897877fdebSMatt Macy 17907877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[col]; 17917877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[rc->rc_devidx]; 17927877fdebSMatt Macy 17937877fdebSMatt Macy vdev_xlate(cvd, &logical_rs, &physical_rs, &remain_rs); 17947877fdebSMatt Macy ASSERT(vdev_xlate_is_empty(&remain_rs)); 17957877fdebSMatt Macy ASSERT3U(rc->rc_offset, ==, physical_rs.rs_start); 17967877fdebSMatt Macy ASSERT3U(rc->rc_offset, <, physical_rs.rs_end); 17977877fdebSMatt Macy ASSERT3U(rc->rc_offset + rc->rc_size, ==, physical_rs.rs_end); 17987877fdebSMatt Macy #endif 17997877fdebSMatt Macy } 18007877fdebSMatt Macy 18017877fdebSMatt Macy /* 18027877fdebSMatt Macy * For write operations: 18037877fdebSMatt Macy * 1. Generate the parity data 18047877fdebSMatt Macy * 2. Create child zio write operations to each column's vdev, for both 18057877fdebSMatt Macy * data and parity. A gang ABD is allocated by vdev_draid_map_alloc() 18067877fdebSMatt Macy * if a skip sector needs to be added to a column. 18077877fdebSMatt Macy */ 18087877fdebSMatt Macy static void 18097877fdebSMatt Macy vdev_draid_io_start_write(zio_t *zio, raidz_row_t *rr) 18107877fdebSMatt Macy { 18117877fdebSMatt Macy vdev_t *vd = zio->io_vd; 18127877fdebSMatt Macy raidz_map_t *rm = zio->io_vsd; 18137877fdebSMatt Macy 18147877fdebSMatt Macy vdev_raidz_generate_parity_row(rm, rr); 18157877fdebSMatt Macy 18167877fdebSMatt Macy for (int c = 0; c < rr->rr_cols; c++) { 18177877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 18187877fdebSMatt Macy 18197877fdebSMatt Macy /* 18207877fdebSMatt Macy * Empty columns are zero filled and included in the parity 18217877fdebSMatt Macy * calculation and therefore must be written. 18227877fdebSMatt Macy */ 18237877fdebSMatt Macy ASSERT3U(rc->rc_size, !=, 0); 18247877fdebSMatt Macy 18257877fdebSMatt Macy /* Verify physical to logical translation */ 18267877fdebSMatt Macy vdev_draid_io_verify(vd, rr, c); 18277877fdebSMatt Macy 18287877fdebSMatt Macy zio_nowait(zio_vdev_child_io(zio, NULL, 18297877fdebSMatt Macy vd->vdev_child[rc->rc_devidx], rc->rc_offset, 18307877fdebSMatt Macy rc->rc_abd, rc->rc_size, zio->io_type, zio->io_priority, 18317877fdebSMatt Macy 0, vdev_raidz_child_done, rc)); 18327877fdebSMatt Macy } 18337877fdebSMatt Macy } 18347877fdebSMatt Macy 18357877fdebSMatt Macy /* 18367877fdebSMatt Macy * For read operations: 18377877fdebSMatt Macy * 1. The vdev_draid_map_alloc() function will create a minimal raidz 18387877fdebSMatt Macy * mapping for the read based on the zio->io_flags. There are two 18397877fdebSMatt Macy * possible mappings either 1) a normal read, or 2) a scrub/resilver. 18407877fdebSMatt Macy * 2. Create the zio read operations. This will include all parity 18417877fdebSMatt Macy * columns and skip sectors for a scrub/resilver. 18427877fdebSMatt Macy */ 18437877fdebSMatt Macy static void 18447877fdebSMatt Macy vdev_draid_io_start_read(zio_t *zio, raidz_row_t *rr) 18457877fdebSMatt Macy { 18467877fdebSMatt Macy vdev_t *vd = zio->io_vd; 18477877fdebSMatt Macy 18487877fdebSMatt Macy /* Sequential rebuild must do IO at redundancy group boundary. */ 18497877fdebSMatt Macy IMPLY(zio->io_priority == ZIO_PRIORITY_REBUILD, rr->rr_nempty == 0); 18507877fdebSMatt Macy 18517877fdebSMatt Macy /* 18527877fdebSMatt Macy * Iterate over the columns in reverse order so that we hit the parity 18537877fdebSMatt Macy * last. Any errors along the way will force us to read the parity. 18547877fdebSMatt Macy * For scrub/resilver IOs which verify skip sectors, a gang ABD will 18557877fdebSMatt Macy * have been allocated to store them and rc->rc_size is increased. 18567877fdebSMatt Macy */ 18577877fdebSMatt Macy for (int c = rr->rr_cols - 1; c >= 0; c--) { 18587877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 18597877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[rc->rc_devidx]; 18607877fdebSMatt Macy 18617877fdebSMatt Macy if (!vdev_draid_readable(cvd, rc->rc_offset)) { 18627877fdebSMatt Macy if (c >= rr->rr_firstdatacol) 18637877fdebSMatt Macy rr->rr_missingdata++; 18647877fdebSMatt Macy else 18657877fdebSMatt Macy rr->rr_missingparity++; 18667877fdebSMatt Macy rc->rc_error = SET_ERROR(ENXIO); 18677877fdebSMatt Macy rc->rc_tried = 1; 18687877fdebSMatt Macy rc->rc_skipped = 1; 18697877fdebSMatt Macy continue; 18707877fdebSMatt Macy } 18717877fdebSMatt Macy 18727877fdebSMatt Macy if (vdev_draid_missing(cvd, rc->rc_offset, zio->io_txg, 1)) { 18737877fdebSMatt Macy if (c >= rr->rr_firstdatacol) 18747877fdebSMatt Macy rr->rr_missingdata++; 18757877fdebSMatt Macy else 18767877fdebSMatt Macy rr->rr_missingparity++; 18777877fdebSMatt Macy rc->rc_error = SET_ERROR(ESTALE); 18787877fdebSMatt Macy rc->rc_skipped = 1; 18797877fdebSMatt Macy continue; 18807877fdebSMatt Macy } 18817877fdebSMatt Macy 18827877fdebSMatt Macy /* 18837877fdebSMatt Macy * Empty columns may be read during vdev_draid_io_done(). 18847877fdebSMatt Macy * Only skip them after the readable and missing checks 18857877fdebSMatt Macy * verify they are available. 18867877fdebSMatt Macy */ 18877877fdebSMatt Macy if (rc->rc_size == 0) { 18887877fdebSMatt Macy rc->rc_skipped = 1; 18897877fdebSMatt Macy continue; 18907877fdebSMatt Macy } 18917877fdebSMatt Macy 18927877fdebSMatt Macy if (zio->io_flags & ZIO_FLAG_RESILVER) { 18937877fdebSMatt Macy vdev_t *svd; 18947877fdebSMatt Macy 18957877fdebSMatt Macy /* 189616038816SMartin Matuska * Sequential rebuilds need to always consider the data 189716038816SMartin Matuska * on the child being rebuilt to be stale. This is 189816038816SMartin Matuska * important when all columns are available to aid 189916038816SMartin Matuska * known reconstruction in identifing which columns 190016038816SMartin Matuska * contain incorrect data. 190116038816SMartin Matuska * 190216038816SMartin Matuska * Furthermore, all repairs need to be constrained to 190316038816SMartin Matuska * the devices being rebuilt because without a checksum 190416038816SMartin Matuska * we cannot verify the data is actually correct and 190516038816SMartin Matuska * performing an incorrect repair could result in 190616038816SMartin Matuska * locking in damage and making the data unrecoverable. 190716038816SMartin Matuska */ 190816038816SMartin Matuska if (zio->io_priority == ZIO_PRIORITY_REBUILD) { 190916038816SMartin Matuska if (vdev_draid_rebuilding(cvd)) { 191016038816SMartin Matuska if (c >= rr->rr_firstdatacol) 191116038816SMartin Matuska rr->rr_missingdata++; 191216038816SMartin Matuska else 191316038816SMartin Matuska rr->rr_missingparity++; 191416038816SMartin Matuska rc->rc_error = SET_ERROR(ESTALE); 191516038816SMartin Matuska rc->rc_skipped = 1; 191616038816SMartin Matuska rc->rc_allow_repair = 1; 191716038816SMartin Matuska continue; 191816038816SMartin Matuska } else { 191916038816SMartin Matuska rc->rc_allow_repair = 0; 192016038816SMartin Matuska } 192116038816SMartin Matuska } else { 192216038816SMartin Matuska rc->rc_allow_repair = 1; 192316038816SMartin Matuska } 192416038816SMartin Matuska 192516038816SMartin Matuska /* 19267877fdebSMatt Macy * If this child is a distributed spare then the 19277877fdebSMatt Macy * offset might reside on the vdev being replaced. 19287877fdebSMatt Macy * In which case this data must be written to the 19297877fdebSMatt Macy * new device. Failure to do so would result in 19307877fdebSMatt Macy * checksum errors when the old device is detached 19317877fdebSMatt Macy * and the pool is scrubbed. 19327877fdebSMatt Macy */ 19337877fdebSMatt Macy if ((svd = vdev_draid_find_spare(cvd)) != NULL) { 19347877fdebSMatt Macy svd = vdev_draid_spare_get_child(svd, 19357877fdebSMatt Macy rc->rc_offset); 19367877fdebSMatt Macy if (svd && (svd->vdev_ops == &vdev_spare_ops || 19377877fdebSMatt Macy svd->vdev_ops == &vdev_replacing_ops)) { 193816038816SMartin Matuska rc->rc_force_repair = 1; 193916038816SMartin Matuska 194016038816SMartin Matuska if (vdev_draid_rebuilding(svd)) 194116038816SMartin Matuska rc->rc_allow_repair = 1; 19427877fdebSMatt Macy } 19437877fdebSMatt Macy } 19447877fdebSMatt Macy 19457877fdebSMatt Macy /* 19467877fdebSMatt Macy * Always issue a repair IO to this child when its 19477877fdebSMatt Macy * a spare or replacing vdev with an active rebuild. 19487877fdebSMatt Macy */ 19497877fdebSMatt Macy if ((cvd->vdev_ops == &vdev_spare_ops || 19507877fdebSMatt Macy cvd->vdev_ops == &vdev_replacing_ops) && 19517877fdebSMatt Macy vdev_draid_rebuilding(cvd)) { 195216038816SMartin Matuska rc->rc_force_repair = 1; 195316038816SMartin Matuska rc->rc_allow_repair = 1; 19547877fdebSMatt Macy } 19557877fdebSMatt Macy } 19567877fdebSMatt Macy } 19577877fdebSMatt Macy 19587877fdebSMatt Macy /* 19597877fdebSMatt Macy * Either a parity or data column is missing this means a repair 19607877fdebSMatt Macy * may be attempted by vdev_draid_io_done(). Expand the raid map 19617877fdebSMatt Macy * to read in empty columns which are needed along with the parity 19627877fdebSMatt Macy * during reconstruction. 19637877fdebSMatt Macy */ 19647877fdebSMatt Macy if ((rr->rr_missingdata > 0 || rr->rr_missingparity > 0) && 19657877fdebSMatt Macy rr->rr_nempty > 0 && rr->rr_abd_empty == NULL) { 19667877fdebSMatt Macy vdev_draid_map_alloc_empty(zio, rr); 19677877fdebSMatt Macy } 19687877fdebSMatt Macy 19697877fdebSMatt Macy for (int c = rr->rr_cols - 1; c >= 0; c--) { 19707877fdebSMatt Macy raidz_col_t *rc = &rr->rr_col[c]; 19717877fdebSMatt Macy vdev_t *cvd = vd->vdev_child[rc->rc_devidx]; 19727877fdebSMatt Macy 19737877fdebSMatt Macy if (rc->rc_error || rc->rc_size == 0) 19747877fdebSMatt Macy continue; 19757877fdebSMatt Macy 19767877fdebSMatt Macy if (c >= rr->rr_firstdatacol || rr->rr_missingdata > 0 || 19777877fdebSMatt Macy (zio->io_flags & (ZIO_FLAG_SCRUB | ZIO_FLAG_RESILVER))) { 19787877fdebSMatt Macy zio_nowait(zio_vdev_child_io(zio, NULL, cvd, 19797877fdebSMatt Macy rc->rc_offset, rc->rc_abd, rc->rc_size, 19807877fdebSMatt Macy zio->io_type, zio->io_priority, 0, 19817877fdebSMatt Macy vdev_raidz_child_done, rc)); 19827877fdebSMatt Macy } 19837877fdebSMatt Macy } 19847877fdebSMatt Macy } 19857877fdebSMatt Macy 19867877fdebSMatt Macy /* 19877877fdebSMatt Macy * Start an IO operation to a dRAID vdev. 19887877fdebSMatt Macy */ 19897877fdebSMatt Macy static void 19907877fdebSMatt Macy vdev_draid_io_start(zio_t *zio) 19917877fdebSMatt Macy { 19927877fdebSMatt Macy vdev_t *vd __maybe_unused = zio->io_vd; 19937877fdebSMatt Macy 19947877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_ops); 19957877fdebSMatt Macy ASSERT3U(zio->io_offset, ==, vdev_draid_get_astart(vd, zio->io_offset)); 19967877fdebSMatt Macy 1997f9693befSMartin Matuska raidz_map_t *rm = vdev_draid_map_alloc(zio); 1998f9693befSMartin Matuska zio->io_vsd = rm; 1999f9693befSMartin Matuska zio->io_vsd_ops = &vdev_raidz_vsd_ops; 20007877fdebSMatt Macy 20017877fdebSMatt Macy if (zio->io_type == ZIO_TYPE_WRITE) { 20027877fdebSMatt Macy for (int i = 0; i < rm->rm_nrows; i++) { 20037877fdebSMatt Macy vdev_draid_io_start_write(zio, rm->rm_row[i]); 20047877fdebSMatt Macy } 20057877fdebSMatt Macy } else { 20067877fdebSMatt Macy ASSERT(zio->io_type == ZIO_TYPE_READ); 20077877fdebSMatt Macy 20087877fdebSMatt Macy for (int i = 0; i < rm->rm_nrows; i++) { 20097877fdebSMatt Macy vdev_draid_io_start_read(zio, rm->rm_row[i]); 20107877fdebSMatt Macy } 20117877fdebSMatt Macy } 20127877fdebSMatt Macy 20137877fdebSMatt Macy zio_execute(zio); 20147877fdebSMatt Macy } 20157877fdebSMatt Macy 20167877fdebSMatt Macy /* 20177877fdebSMatt Macy * Complete an IO operation on a dRAID vdev. The raidz logic can be applied 20187877fdebSMatt Macy * to dRAID since the layout is fully described by the raidz_map_t. 20197877fdebSMatt Macy */ 20207877fdebSMatt Macy static void 20217877fdebSMatt Macy vdev_draid_io_done(zio_t *zio) 20227877fdebSMatt Macy { 20237877fdebSMatt Macy vdev_raidz_io_done(zio); 20247877fdebSMatt Macy } 20257877fdebSMatt Macy 20267877fdebSMatt Macy static void 20277877fdebSMatt Macy vdev_draid_state_change(vdev_t *vd, int faulted, int degraded) 20287877fdebSMatt Macy { 20297877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 20307877fdebSMatt Macy ASSERT(vd->vdev_ops == &vdev_draid_ops); 20317877fdebSMatt Macy 20327877fdebSMatt Macy if (faulted > vdc->vdc_nparity) 20337877fdebSMatt Macy vdev_set_state(vd, B_FALSE, VDEV_STATE_CANT_OPEN, 20347877fdebSMatt Macy VDEV_AUX_NO_REPLICAS); 20357877fdebSMatt Macy else if (degraded + faulted != 0) 20367877fdebSMatt Macy vdev_set_state(vd, B_FALSE, VDEV_STATE_DEGRADED, VDEV_AUX_NONE); 20377877fdebSMatt Macy else 20387877fdebSMatt Macy vdev_set_state(vd, B_FALSE, VDEV_STATE_HEALTHY, VDEV_AUX_NONE); 20397877fdebSMatt Macy } 20407877fdebSMatt Macy 20417877fdebSMatt Macy static void 20427877fdebSMatt Macy vdev_draid_xlate(vdev_t *cvd, const range_seg64_t *logical_rs, 20437877fdebSMatt Macy range_seg64_t *physical_rs, range_seg64_t *remain_rs) 20447877fdebSMatt Macy { 20457877fdebSMatt Macy vdev_t *raidvd = cvd->vdev_parent; 20467877fdebSMatt Macy ASSERT(raidvd->vdev_ops == &vdev_draid_ops); 20477877fdebSMatt Macy 20487877fdebSMatt Macy vdev_draid_config_t *vdc = raidvd->vdev_tsd; 20497877fdebSMatt Macy uint64_t ashift = raidvd->vdev_top->vdev_ashift; 20507877fdebSMatt Macy 20517877fdebSMatt Macy /* Make sure the offsets are block-aligned */ 20527877fdebSMatt Macy ASSERT0(logical_rs->rs_start % (1 << ashift)); 20537877fdebSMatt Macy ASSERT0(logical_rs->rs_end % (1 << ashift)); 20547877fdebSMatt Macy 20557877fdebSMatt Macy uint64_t logical_start = logical_rs->rs_start; 20567877fdebSMatt Macy uint64_t logical_end = logical_rs->rs_end; 20577877fdebSMatt Macy 20587877fdebSMatt Macy /* 20597877fdebSMatt Macy * Unaligned ranges must be skipped. All metaslabs are correctly 20607877fdebSMatt Macy * aligned so this should not happen, but this case is handled in 20617877fdebSMatt Macy * case it's needed by future callers. 20627877fdebSMatt Macy */ 20637877fdebSMatt Macy uint64_t astart = vdev_draid_get_astart(raidvd, logical_start); 20647877fdebSMatt Macy if (astart != logical_start) { 20657877fdebSMatt Macy physical_rs->rs_start = logical_start; 20667877fdebSMatt Macy physical_rs->rs_end = logical_start; 20677877fdebSMatt Macy remain_rs->rs_start = MIN(astart, logical_end); 20687877fdebSMatt Macy remain_rs->rs_end = logical_end; 20697877fdebSMatt Macy return; 20707877fdebSMatt Macy } 20717877fdebSMatt Macy 20727877fdebSMatt Macy /* 20737877fdebSMatt Macy * Unlike with mirrors and raidz a dRAID logical range can map 20747877fdebSMatt Macy * to multiple non-contiguous physical ranges. This is handled by 20757877fdebSMatt Macy * limiting the size of the logical range to a single group and 20767877fdebSMatt Macy * setting the remain argument such that it describes the remaining 20777877fdebSMatt Macy * unmapped logical range. This is stricter than absolutely 20787877fdebSMatt Macy * necessary but helps simplify the logic below. 20797877fdebSMatt Macy */ 20807877fdebSMatt Macy uint64_t group = vdev_draid_offset_to_group(raidvd, logical_start); 20817877fdebSMatt Macy uint64_t nextstart = vdev_draid_group_to_offset(raidvd, group + 1); 20827877fdebSMatt Macy if (logical_end > nextstart) 20837877fdebSMatt Macy logical_end = nextstart; 20847877fdebSMatt Macy 20857877fdebSMatt Macy /* Find the starting offset for each vdev in the group */ 20867877fdebSMatt Macy uint64_t perm, groupstart; 20877877fdebSMatt Macy uint64_t start = vdev_draid_logical_to_physical(raidvd, 20887877fdebSMatt Macy logical_start, &perm, &groupstart); 20897877fdebSMatt Macy uint64_t end = start; 20907877fdebSMatt Macy 20917877fdebSMatt Macy uint8_t *base; 20927877fdebSMatt Macy uint64_t iter, id; 20937877fdebSMatt Macy vdev_draid_get_perm(vdc, perm, &base, &iter); 20947877fdebSMatt Macy 20957877fdebSMatt Macy /* 20967877fdebSMatt Macy * Check if the passed child falls within the group. If it does 20977877fdebSMatt Macy * update the start and end to reflect the physical range. 20987877fdebSMatt Macy * Otherwise, leave them unmodified which will result in an empty 20997877fdebSMatt Macy * (zero-length) physical range being returned. 21007877fdebSMatt Macy */ 21017877fdebSMatt Macy for (uint64_t i = 0; i < vdc->vdc_groupwidth; i++) { 21027877fdebSMatt Macy uint64_t c = (groupstart + i) % vdc->vdc_ndisks; 21037877fdebSMatt Macy 21047877fdebSMatt Macy if (c == 0 && i != 0) { 21057877fdebSMatt Macy /* the group wrapped, increment the start */ 21067877fdebSMatt Macy start += VDEV_DRAID_ROWHEIGHT; 21077877fdebSMatt Macy end = start; 21087877fdebSMatt Macy } 21097877fdebSMatt Macy 21107877fdebSMatt Macy id = vdev_draid_permute_id(vdc, base, iter, c); 21117877fdebSMatt Macy if (id == cvd->vdev_id) { 21127877fdebSMatt Macy uint64_t b_size = (logical_end >> ashift) - 21137877fdebSMatt Macy (logical_start >> ashift); 21147877fdebSMatt Macy ASSERT3U(b_size, >, 0); 21157877fdebSMatt Macy end = start + ((((b_size - 1) / 21167877fdebSMatt Macy vdc->vdc_groupwidth) + 1) << ashift); 21177877fdebSMatt Macy break; 21187877fdebSMatt Macy } 21197877fdebSMatt Macy } 21207877fdebSMatt Macy physical_rs->rs_start = start; 21217877fdebSMatt Macy physical_rs->rs_end = end; 21227877fdebSMatt Macy 21237877fdebSMatt Macy /* 21247877fdebSMatt Macy * Only top-level vdevs are allowed to set remain_rs because 21257877fdebSMatt Macy * when .vdev_op_xlate() is called for their children the full 21267877fdebSMatt Macy * logical range is not provided by vdev_xlate(). 21277877fdebSMatt Macy */ 21287877fdebSMatt Macy remain_rs->rs_start = logical_end; 21297877fdebSMatt Macy remain_rs->rs_end = logical_rs->rs_end; 21307877fdebSMatt Macy 21317877fdebSMatt Macy ASSERT3U(physical_rs->rs_start, <=, logical_start); 21327877fdebSMatt Macy ASSERT3U(physical_rs->rs_end - physical_rs->rs_start, <=, 21337877fdebSMatt Macy logical_end - logical_start); 21347877fdebSMatt Macy } 21357877fdebSMatt Macy 21367877fdebSMatt Macy /* 21377877fdebSMatt Macy * Add dRAID specific fields to the config nvlist. 21387877fdebSMatt Macy */ 21397877fdebSMatt Macy static void 21407877fdebSMatt Macy vdev_draid_config_generate(vdev_t *vd, nvlist_t *nv) 21417877fdebSMatt Macy { 21427877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_ops); 21437877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 21447877fdebSMatt Macy 21457877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_NPARITY, vdc->vdc_nparity); 21467877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_DRAID_NDATA, vdc->vdc_ndata); 21477877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_DRAID_NSPARES, vdc->vdc_nspares); 21487877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_DRAID_NGROUPS, vdc->vdc_ngroups); 21497877fdebSMatt Macy } 21507877fdebSMatt Macy 21517877fdebSMatt Macy /* 21527877fdebSMatt Macy * Initialize private dRAID specific fields from the nvlist. 21537877fdebSMatt Macy */ 21547877fdebSMatt Macy static int 21557877fdebSMatt Macy vdev_draid_init(spa_t *spa, nvlist_t *nv, void **tsd) 21567877fdebSMatt Macy { 21577877fdebSMatt Macy uint64_t ndata, nparity, nspares, ngroups; 21587877fdebSMatt Macy int error; 21597877fdebSMatt Macy 21607877fdebSMatt Macy if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_DRAID_NDATA, &ndata)) 21617877fdebSMatt Macy return (SET_ERROR(EINVAL)); 21627877fdebSMatt Macy 21637877fdebSMatt Macy if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NPARITY, &nparity) || 21647877fdebSMatt Macy nparity == 0 || nparity > VDEV_DRAID_MAXPARITY) { 21657877fdebSMatt Macy return (SET_ERROR(EINVAL)); 21667877fdebSMatt Macy } 21677877fdebSMatt Macy 21687877fdebSMatt Macy uint_t children; 21697877fdebSMatt Macy nvlist_t **child; 21707877fdebSMatt Macy if (nvlist_lookup_nvlist_array(nv, ZPOOL_CONFIG_CHILDREN, 21717877fdebSMatt Macy &child, &children) != 0 || children == 0 || 21727877fdebSMatt Macy children > VDEV_DRAID_MAX_CHILDREN) { 21737877fdebSMatt Macy return (SET_ERROR(EINVAL)); 21747877fdebSMatt Macy } 21757877fdebSMatt Macy 21767877fdebSMatt Macy if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_DRAID_NSPARES, &nspares) || 21777877fdebSMatt Macy nspares > 100 || nspares > (children - (ndata + nparity))) { 21787877fdebSMatt Macy return (SET_ERROR(EINVAL)); 21797877fdebSMatt Macy } 21807877fdebSMatt Macy 21817877fdebSMatt Macy if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_DRAID_NGROUPS, &ngroups) || 21827877fdebSMatt Macy ngroups == 0 || ngroups > VDEV_DRAID_MAX_CHILDREN) { 21837877fdebSMatt Macy return (SET_ERROR(EINVAL)); 21847877fdebSMatt Macy } 21857877fdebSMatt Macy 21867877fdebSMatt Macy /* 21877877fdebSMatt Macy * Validate the minimum number of children exist per group for the 21887877fdebSMatt Macy * specified parity level (draid1 >= 2, draid2 >= 3, draid3 >= 4). 21897877fdebSMatt Macy */ 21907877fdebSMatt Macy if (children < (ndata + nparity + nspares)) 21917877fdebSMatt Macy return (SET_ERROR(EINVAL)); 21927877fdebSMatt Macy 21937877fdebSMatt Macy /* 21947877fdebSMatt Macy * Create the dRAID configuration using the pool nvlist configuration 21957877fdebSMatt Macy * and the fixed mapping for the correct number of children. 21967877fdebSMatt Macy */ 21977877fdebSMatt Macy vdev_draid_config_t *vdc; 21987877fdebSMatt Macy const draid_map_t *map; 21997877fdebSMatt Macy 22007877fdebSMatt Macy error = vdev_draid_lookup_map(children, &map); 22017877fdebSMatt Macy if (error) 22027877fdebSMatt Macy return (SET_ERROR(EINVAL)); 22037877fdebSMatt Macy 22047877fdebSMatt Macy vdc = kmem_zalloc(sizeof (*vdc), KM_SLEEP); 22057877fdebSMatt Macy vdc->vdc_ndata = ndata; 22067877fdebSMatt Macy vdc->vdc_nparity = nparity; 22077877fdebSMatt Macy vdc->vdc_nspares = nspares; 22087877fdebSMatt Macy vdc->vdc_children = children; 22097877fdebSMatt Macy vdc->vdc_ngroups = ngroups; 22107877fdebSMatt Macy vdc->vdc_nperms = map->dm_nperms; 22117877fdebSMatt Macy 22127877fdebSMatt Macy error = vdev_draid_generate_perms(map, &vdc->vdc_perms); 22137877fdebSMatt Macy if (error) { 22147877fdebSMatt Macy kmem_free(vdc, sizeof (*vdc)); 22157877fdebSMatt Macy return (SET_ERROR(EINVAL)); 22167877fdebSMatt Macy } 22177877fdebSMatt Macy 22187877fdebSMatt Macy /* 22197877fdebSMatt Macy * Derived constants. 22207877fdebSMatt Macy */ 22217877fdebSMatt Macy vdc->vdc_groupwidth = vdc->vdc_ndata + vdc->vdc_nparity; 22227877fdebSMatt Macy vdc->vdc_ndisks = vdc->vdc_children - vdc->vdc_nspares; 22237877fdebSMatt Macy vdc->vdc_groupsz = vdc->vdc_groupwidth * VDEV_DRAID_ROWHEIGHT; 22247877fdebSMatt Macy vdc->vdc_devslicesz = (vdc->vdc_groupsz * vdc->vdc_ngroups) / 22257877fdebSMatt Macy vdc->vdc_ndisks; 22267877fdebSMatt Macy 22277877fdebSMatt Macy ASSERT3U(vdc->vdc_groupwidth, >=, 2); 22287877fdebSMatt Macy ASSERT3U(vdc->vdc_groupwidth, <=, vdc->vdc_ndisks); 22297877fdebSMatt Macy ASSERT3U(vdc->vdc_groupsz, >=, 2 * VDEV_DRAID_ROWHEIGHT); 22307877fdebSMatt Macy ASSERT3U(vdc->vdc_devslicesz, >=, VDEV_DRAID_ROWHEIGHT); 22317877fdebSMatt Macy ASSERT3U(vdc->vdc_devslicesz % VDEV_DRAID_ROWHEIGHT, ==, 0); 22327877fdebSMatt Macy ASSERT3U((vdc->vdc_groupwidth * vdc->vdc_ngroups) % 22337877fdebSMatt Macy vdc->vdc_ndisks, ==, 0); 22347877fdebSMatt Macy 22357877fdebSMatt Macy *tsd = vdc; 22367877fdebSMatt Macy 22377877fdebSMatt Macy return (0); 22387877fdebSMatt Macy } 22397877fdebSMatt Macy 22407877fdebSMatt Macy static void 22417877fdebSMatt Macy vdev_draid_fini(vdev_t *vd) 22427877fdebSMatt Macy { 22437877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 22447877fdebSMatt Macy 22457877fdebSMatt Macy vmem_free(vdc->vdc_perms, sizeof (uint8_t) * 22467877fdebSMatt Macy vdc->vdc_children * vdc->vdc_nperms); 22477877fdebSMatt Macy kmem_free(vdc, sizeof (*vdc)); 22487877fdebSMatt Macy } 22497877fdebSMatt Macy 22507877fdebSMatt Macy static uint64_t 22517877fdebSMatt Macy vdev_draid_nparity(vdev_t *vd) 22527877fdebSMatt Macy { 22537877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 22547877fdebSMatt Macy 22557877fdebSMatt Macy return (vdc->vdc_nparity); 22567877fdebSMatt Macy } 22577877fdebSMatt Macy 22587877fdebSMatt Macy static uint64_t 22597877fdebSMatt Macy vdev_draid_ndisks(vdev_t *vd) 22607877fdebSMatt Macy { 22617877fdebSMatt Macy vdev_draid_config_t *vdc = vd->vdev_tsd; 22627877fdebSMatt Macy 22637877fdebSMatt Macy return (vdc->vdc_ndisks); 22647877fdebSMatt Macy } 22657877fdebSMatt Macy 22667877fdebSMatt Macy vdev_ops_t vdev_draid_ops = { 22677877fdebSMatt Macy .vdev_op_init = vdev_draid_init, 22687877fdebSMatt Macy .vdev_op_fini = vdev_draid_fini, 22697877fdebSMatt Macy .vdev_op_open = vdev_draid_open, 22707877fdebSMatt Macy .vdev_op_close = vdev_draid_close, 22717877fdebSMatt Macy .vdev_op_asize = vdev_draid_asize, 22727877fdebSMatt Macy .vdev_op_min_asize = vdev_draid_min_asize, 22737877fdebSMatt Macy .vdev_op_min_alloc = vdev_draid_min_alloc, 22747877fdebSMatt Macy .vdev_op_io_start = vdev_draid_io_start, 22757877fdebSMatt Macy .vdev_op_io_done = vdev_draid_io_done, 22767877fdebSMatt Macy .vdev_op_state_change = vdev_draid_state_change, 22777877fdebSMatt Macy .vdev_op_need_resilver = vdev_draid_need_resilver, 22787877fdebSMatt Macy .vdev_op_hold = NULL, 22797877fdebSMatt Macy .vdev_op_rele = NULL, 22807877fdebSMatt Macy .vdev_op_remap = NULL, 22817877fdebSMatt Macy .vdev_op_xlate = vdev_draid_xlate, 22827877fdebSMatt Macy .vdev_op_rebuild_asize = vdev_draid_rebuild_asize, 22837877fdebSMatt Macy .vdev_op_metaslab_init = vdev_draid_metaslab_init, 22847877fdebSMatt Macy .vdev_op_config_generate = vdev_draid_config_generate, 22857877fdebSMatt Macy .vdev_op_nparity = vdev_draid_nparity, 22867877fdebSMatt Macy .vdev_op_ndisks = vdev_draid_ndisks, 22877877fdebSMatt Macy .vdev_op_type = VDEV_TYPE_DRAID, 22887877fdebSMatt Macy .vdev_op_leaf = B_FALSE, 22897877fdebSMatt Macy }; 22907877fdebSMatt Macy 22917877fdebSMatt Macy 22927877fdebSMatt Macy /* 22937877fdebSMatt Macy * A dRAID distributed spare is a virtual leaf vdev which is included in the 22947877fdebSMatt Macy * parent dRAID configuration. The last N columns of the dRAID permutation 22957877fdebSMatt Macy * table are used to determine on which dRAID children a specific offset 22967877fdebSMatt Macy * should be written. These spare leaf vdevs can only be used to replace 22977877fdebSMatt Macy * faulted children in the same dRAID configuration. 22987877fdebSMatt Macy */ 22997877fdebSMatt Macy 23007877fdebSMatt Macy /* 23017877fdebSMatt Macy * Distributed spare state. All fields are set when the distributed spare is 23027877fdebSMatt Macy * first opened and are immutable. 23037877fdebSMatt Macy */ 23047877fdebSMatt Macy typedef struct { 23057877fdebSMatt Macy vdev_t *vds_draid_vdev; /* top-level parent dRAID vdev */ 23067877fdebSMatt Macy uint64_t vds_top_guid; /* top-level parent dRAID guid */ 23077877fdebSMatt Macy uint64_t vds_spare_id; /* spare id (0 - vdc->vdc_nspares-1) */ 23087877fdebSMatt Macy } vdev_draid_spare_t; 23097877fdebSMatt Macy 23107877fdebSMatt Macy /* 23117877fdebSMatt Macy * Returns the parent dRAID vdev to which the distributed spare belongs. 23127877fdebSMatt Macy * This may be safely called even when the vdev is not open. 23137877fdebSMatt Macy */ 23147877fdebSMatt Macy vdev_t * 23157877fdebSMatt Macy vdev_draid_spare_get_parent(vdev_t *vd) 23167877fdebSMatt Macy { 23177877fdebSMatt Macy vdev_draid_spare_t *vds = vd->vdev_tsd; 23187877fdebSMatt Macy 23197877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_spare_ops); 23207877fdebSMatt Macy 23217877fdebSMatt Macy if (vds->vds_draid_vdev != NULL) 23227877fdebSMatt Macy return (vds->vds_draid_vdev); 23237877fdebSMatt Macy 23247877fdebSMatt Macy return (vdev_lookup_by_guid(vd->vdev_spa->spa_root_vdev, 23257877fdebSMatt Macy vds->vds_top_guid)); 23267877fdebSMatt Macy } 23277877fdebSMatt Macy 23287877fdebSMatt Macy /* 23297877fdebSMatt Macy * A dRAID space is active when it's the child of a vdev using the 23307877fdebSMatt Macy * vdev_spare_ops, vdev_replacing_ops or vdev_draid_ops. 23317877fdebSMatt Macy */ 23327877fdebSMatt Macy static boolean_t 23337877fdebSMatt Macy vdev_draid_spare_is_active(vdev_t *vd) 23347877fdebSMatt Macy { 23357877fdebSMatt Macy vdev_t *pvd = vd->vdev_parent; 23367877fdebSMatt Macy 23377877fdebSMatt Macy if (pvd != NULL && (pvd->vdev_ops == &vdev_spare_ops || 23387877fdebSMatt Macy pvd->vdev_ops == &vdev_replacing_ops || 23397877fdebSMatt Macy pvd->vdev_ops == &vdev_draid_ops)) { 23407877fdebSMatt Macy return (B_TRUE); 23417877fdebSMatt Macy } else { 23427877fdebSMatt Macy return (B_FALSE); 23437877fdebSMatt Macy } 23447877fdebSMatt Macy } 23457877fdebSMatt Macy 23467877fdebSMatt Macy /* 23477877fdebSMatt Macy * Given a dRAID distribute spare vdev, returns the physical child vdev 23487877fdebSMatt Macy * on which the provided offset resides. This may involve recursing through 23497877fdebSMatt Macy * multiple layers of distributed spares. Note that offset is relative to 23507877fdebSMatt Macy * this vdev. 23517877fdebSMatt Macy */ 23527877fdebSMatt Macy vdev_t * 23537877fdebSMatt Macy vdev_draid_spare_get_child(vdev_t *vd, uint64_t physical_offset) 23547877fdebSMatt Macy { 23557877fdebSMatt Macy vdev_draid_spare_t *vds = vd->vdev_tsd; 23567877fdebSMatt Macy 23577877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_spare_ops); 23587877fdebSMatt Macy 23597877fdebSMatt Macy /* The vdev is closed */ 23607877fdebSMatt Macy if (vds->vds_draid_vdev == NULL) 23617877fdebSMatt Macy return (NULL); 23627877fdebSMatt Macy 23637877fdebSMatt Macy vdev_t *tvd = vds->vds_draid_vdev; 23647877fdebSMatt Macy vdev_draid_config_t *vdc = tvd->vdev_tsd; 23657877fdebSMatt Macy 23667877fdebSMatt Macy ASSERT3P(tvd->vdev_ops, ==, &vdev_draid_ops); 23677877fdebSMatt Macy ASSERT3U(vds->vds_spare_id, <, vdc->vdc_nspares); 23687877fdebSMatt Macy 23697877fdebSMatt Macy uint8_t *base; 23707877fdebSMatt Macy uint64_t iter; 23717877fdebSMatt Macy uint64_t perm = physical_offset / vdc->vdc_devslicesz; 23727877fdebSMatt Macy 23737877fdebSMatt Macy vdev_draid_get_perm(vdc, perm, &base, &iter); 23747877fdebSMatt Macy 23757877fdebSMatt Macy uint64_t cid = vdev_draid_permute_id(vdc, base, iter, 23767877fdebSMatt Macy (tvd->vdev_children - 1) - vds->vds_spare_id); 23777877fdebSMatt Macy vdev_t *cvd = tvd->vdev_child[cid]; 23787877fdebSMatt Macy 23797877fdebSMatt Macy if (cvd->vdev_ops == &vdev_draid_spare_ops) 23807877fdebSMatt Macy return (vdev_draid_spare_get_child(cvd, physical_offset)); 23817877fdebSMatt Macy 23827877fdebSMatt Macy return (cvd); 23837877fdebSMatt Macy } 23847877fdebSMatt Macy 23857877fdebSMatt Macy /* ARGSUSED */ 23867877fdebSMatt Macy static void 23877877fdebSMatt Macy vdev_draid_spare_close(vdev_t *vd) 23887877fdebSMatt Macy { 23897877fdebSMatt Macy vdev_draid_spare_t *vds = vd->vdev_tsd; 23907877fdebSMatt Macy vds->vds_draid_vdev = NULL; 23917877fdebSMatt Macy } 23927877fdebSMatt Macy 23937877fdebSMatt Macy /* 23947877fdebSMatt Macy * Opening a dRAID spare device is done by looking up the associated dRAID 23957877fdebSMatt Macy * top-level vdev guid from the spare configuration. 23967877fdebSMatt Macy */ 23977877fdebSMatt Macy static int 23987877fdebSMatt Macy vdev_draid_spare_open(vdev_t *vd, uint64_t *psize, uint64_t *max_psize, 23997877fdebSMatt Macy uint64_t *logical_ashift, uint64_t *physical_ashift) 24007877fdebSMatt Macy { 24017877fdebSMatt Macy vdev_draid_spare_t *vds = vd->vdev_tsd; 24027877fdebSMatt Macy vdev_t *rvd = vd->vdev_spa->spa_root_vdev; 24037877fdebSMatt Macy uint64_t asize, max_asize; 24047877fdebSMatt Macy 24057877fdebSMatt Macy vdev_t *tvd = vdev_lookup_by_guid(rvd, vds->vds_top_guid); 24067877fdebSMatt Macy if (tvd == NULL) { 24077877fdebSMatt Macy /* 24087877fdebSMatt Macy * When spa_vdev_add() is labeling new spares the 24097877fdebSMatt Macy * associated dRAID is not attached to the root vdev 24107877fdebSMatt Macy * nor does this spare have a parent. Simulate a valid 24117877fdebSMatt Macy * device in order to allow the label to be initialized 24127877fdebSMatt Macy * and the distributed spare added to the configuration. 24137877fdebSMatt Macy */ 24147877fdebSMatt Macy if (vd->vdev_parent == NULL) { 24157877fdebSMatt Macy *psize = *max_psize = SPA_MINDEVSIZE; 24167877fdebSMatt Macy *logical_ashift = *physical_ashift = ASHIFT_MIN; 24177877fdebSMatt Macy return (0); 24187877fdebSMatt Macy } 24197877fdebSMatt Macy 24207877fdebSMatt Macy return (SET_ERROR(EINVAL)); 24217877fdebSMatt Macy } 24227877fdebSMatt Macy 24237877fdebSMatt Macy vdev_draid_config_t *vdc = tvd->vdev_tsd; 24247877fdebSMatt Macy if (tvd->vdev_ops != &vdev_draid_ops || vdc == NULL) 24257877fdebSMatt Macy return (SET_ERROR(EINVAL)); 24267877fdebSMatt Macy 24277877fdebSMatt Macy if (vds->vds_spare_id >= vdc->vdc_nspares) 24287877fdebSMatt Macy return (SET_ERROR(EINVAL)); 24297877fdebSMatt Macy 24307877fdebSMatt Macy /* 24317877fdebSMatt Macy * Neither tvd->vdev_asize or tvd->vdev_max_asize can be used here 24327877fdebSMatt Macy * because the caller may be vdev_draid_open() in which case the 24337877fdebSMatt Macy * values are stale as they haven't yet been updated by vdev_open(). 24347877fdebSMatt Macy * To avoid this always recalculate the dRAID asize and max_asize. 24357877fdebSMatt Macy */ 24367877fdebSMatt Macy vdev_draid_calculate_asize(tvd, &asize, &max_asize, 24377877fdebSMatt Macy logical_ashift, physical_ashift); 24387877fdebSMatt Macy 24397877fdebSMatt Macy *psize = asize + VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE; 24407877fdebSMatt Macy *max_psize = max_asize + VDEV_LABEL_START_SIZE + VDEV_LABEL_END_SIZE; 24417877fdebSMatt Macy 24427877fdebSMatt Macy vds->vds_draid_vdev = tvd; 24437877fdebSMatt Macy 24447877fdebSMatt Macy return (0); 24457877fdebSMatt Macy } 24467877fdebSMatt Macy 24477877fdebSMatt Macy /* 24487877fdebSMatt Macy * Completed distributed spare IO. Store the result in the parent zio 24497877fdebSMatt Macy * as if it had performed the operation itself. Only the first error is 24507877fdebSMatt Macy * preserved if there are multiple errors. 24517877fdebSMatt Macy */ 24527877fdebSMatt Macy static void 24537877fdebSMatt Macy vdev_draid_spare_child_done(zio_t *zio) 24547877fdebSMatt Macy { 24557877fdebSMatt Macy zio_t *pio = zio->io_private; 24567877fdebSMatt Macy 24577877fdebSMatt Macy /* 24587877fdebSMatt Macy * IOs are issued to non-writable vdevs in order to keep their 24597877fdebSMatt Macy * DTLs accurate. However, we don't want to propagate the 24607877fdebSMatt Macy * error in to the distributed spare's DTL. When resilvering 24617877fdebSMatt Macy * vdev_draid_need_resilver() will consult the relevant DTL 24627877fdebSMatt Macy * to determine if the data is missing and must be repaired. 24637877fdebSMatt Macy */ 24647877fdebSMatt Macy if (!vdev_writeable(zio->io_vd)) 24657877fdebSMatt Macy return; 24667877fdebSMatt Macy 24677877fdebSMatt Macy if (pio->io_error == 0) 24687877fdebSMatt Macy pio->io_error = zio->io_error; 24697877fdebSMatt Macy } 24707877fdebSMatt Macy 24717877fdebSMatt Macy /* 24727877fdebSMatt Macy * Returns a valid label nvlist for the distributed spare vdev. This is 24737877fdebSMatt Macy * used to bypass the IO pipeline to avoid the complexity of constructing 24747877fdebSMatt Macy * a complete label with valid checksum to return when read. 24757877fdebSMatt Macy */ 24767877fdebSMatt Macy nvlist_t * 24777877fdebSMatt Macy vdev_draid_read_config_spare(vdev_t *vd) 24787877fdebSMatt Macy { 24797877fdebSMatt Macy spa_t *spa = vd->vdev_spa; 24807877fdebSMatt Macy spa_aux_vdev_t *sav = &spa->spa_spares; 24817877fdebSMatt Macy uint64_t guid = vd->vdev_guid; 24827877fdebSMatt Macy 24837877fdebSMatt Macy nvlist_t *nv = fnvlist_alloc(); 24847877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_IS_SPARE, 1); 24857877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_CREATE_TXG, vd->vdev_crtxg); 24867877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_VERSION, spa_version(spa)); 24877877fdebSMatt Macy fnvlist_add_string(nv, ZPOOL_CONFIG_POOL_NAME, spa_name(spa)); 24887877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_POOL_GUID, spa_guid(spa)); 24897877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_POOL_TXG, spa->spa_config_txg); 24907877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_TOP_GUID, vd->vdev_top->vdev_guid); 24917877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_POOL_STATE, 24927877fdebSMatt Macy vdev_draid_spare_is_active(vd) ? 24937877fdebSMatt Macy POOL_STATE_ACTIVE : POOL_STATE_SPARE); 24947877fdebSMatt Macy 24957877fdebSMatt Macy /* Set the vdev guid based on the vdev list in sav_count. */ 24967877fdebSMatt Macy for (int i = 0; i < sav->sav_count; i++) { 24977877fdebSMatt Macy if (sav->sav_vdevs[i]->vdev_ops == &vdev_draid_spare_ops && 24987877fdebSMatt Macy strcmp(sav->sav_vdevs[i]->vdev_path, vd->vdev_path) == 0) { 24997877fdebSMatt Macy guid = sav->sav_vdevs[i]->vdev_guid; 25007877fdebSMatt Macy break; 25017877fdebSMatt Macy } 25027877fdebSMatt Macy } 25037877fdebSMatt Macy 25047877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_GUID, guid); 25057877fdebSMatt Macy 25067877fdebSMatt Macy return (nv); 25077877fdebSMatt Macy } 25087877fdebSMatt Macy 25097877fdebSMatt Macy /* 25107877fdebSMatt Macy * Handle any ioctl requested of the distributed spare. Only flushes 25117877fdebSMatt Macy * are supported in which case all children must be flushed. 25127877fdebSMatt Macy */ 25137877fdebSMatt Macy static int 25147877fdebSMatt Macy vdev_draid_spare_ioctl(zio_t *zio) 25157877fdebSMatt Macy { 25167877fdebSMatt Macy vdev_t *vd = zio->io_vd; 25177877fdebSMatt Macy int error = 0; 25187877fdebSMatt Macy 25197877fdebSMatt Macy if (zio->io_cmd == DKIOCFLUSHWRITECACHE) { 25207877fdebSMatt Macy for (int c = 0; c < vd->vdev_children; c++) { 25217877fdebSMatt Macy zio_nowait(zio_vdev_child_io(zio, NULL, 25227877fdebSMatt Macy vd->vdev_child[c], zio->io_offset, zio->io_abd, 25237877fdebSMatt Macy zio->io_size, zio->io_type, zio->io_priority, 0, 25247877fdebSMatt Macy vdev_draid_spare_child_done, zio)); 25257877fdebSMatt Macy } 25267877fdebSMatt Macy } else { 25277877fdebSMatt Macy error = SET_ERROR(ENOTSUP); 25287877fdebSMatt Macy } 25297877fdebSMatt Macy 25307877fdebSMatt Macy return (error); 25317877fdebSMatt Macy } 25327877fdebSMatt Macy 25337877fdebSMatt Macy /* 25347877fdebSMatt Macy * Initiate an IO to the distributed spare. For normal IOs this entails using 25357877fdebSMatt Macy * the zio->io_offset and permutation table to calculate which child dRAID vdev 25367877fdebSMatt Macy * is responsible for the data. Then passing along the zio to that child to 25377877fdebSMatt Macy * perform the actual IO. The label ranges are not stored on disk and require 25387877fdebSMatt Macy * some special handling which is described below. 25397877fdebSMatt Macy */ 25407877fdebSMatt Macy static void 25417877fdebSMatt Macy vdev_draid_spare_io_start(zio_t *zio) 25427877fdebSMatt Macy { 25437877fdebSMatt Macy vdev_t *cvd = NULL, *vd = zio->io_vd; 25447877fdebSMatt Macy vdev_draid_spare_t *vds = vd->vdev_tsd; 25457877fdebSMatt Macy uint64_t offset = zio->io_offset - VDEV_LABEL_START_SIZE; 25467877fdebSMatt Macy 25477877fdebSMatt Macy /* 25487877fdebSMatt Macy * If the vdev is closed, it's likely in the REMOVED or FAULTED state. 25497877fdebSMatt Macy * Nothing to be done here but return failure. 25507877fdebSMatt Macy */ 25517877fdebSMatt Macy if (vds == NULL) { 25527877fdebSMatt Macy zio->io_error = ENXIO; 25537877fdebSMatt Macy zio_interrupt(zio); 25547877fdebSMatt Macy return; 25557877fdebSMatt Macy } 25567877fdebSMatt Macy 25577877fdebSMatt Macy switch (zio->io_type) { 25587877fdebSMatt Macy case ZIO_TYPE_IOCTL: 25597877fdebSMatt Macy zio->io_error = vdev_draid_spare_ioctl(zio); 25607877fdebSMatt Macy break; 25617877fdebSMatt Macy 25627877fdebSMatt Macy case ZIO_TYPE_WRITE: 25637877fdebSMatt Macy if (VDEV_OFFSET_IS_LABEL(vd, zio->io_offset)) { 25647877fdebSMatt Macy /* 25657877fdebSMatt Macy * Accept probe IOs and config writers to simulate the 25667877fdebSMatt Macy * existence of an on disk label. vdev_label_sync(), 25677877fdebSMatt Macy * vdev_uberblock_sync() and vdev_copy_uberblocks() 25687877fdebSMatt Macy * skip the distributed spares. This only leaves 25697877fdebSMatt Macy * vdev_label_init() which is allowed to succeed to 25707877fdebSMatt Macy * avoid adding special cases the function. 25717877fdebSMatt Macy */ 25727877fdebSMatt Macy if (zio->io_flags & ZIO_FLAG_PROBE || 25737877fdebSMatt Macy zio->io_flags & ZIO_FLAG_CONFIG_WRITER) { 25747877fdebSMatt Macy zio->io_error = 0; 25757877fdebSMatt Macy } else { 25767877fdebSMatt Macy zio->io_error = SET_ERROR(EIO); 25777877fdebSMatt Macy } 25787877fdebSMatt Macy } else { 25797877fdebSMatt Macy cvd = vdev_draid_spare_get_child(vd, offset); 25807877fdebSMatt Macy 25817877fdebSMatt Macy if (cvd == NULL) { 25827877fdebSMatt Macy zio->io_error = SET_ERROR(ENXIO); 25837877fdebSMatt Macy } else { 25847877fdebSMatt Macy zio_nowait(zio_vdev_child_io(zio, NULL, cvd, 25857877fdebSMatt Macy offset, zio->io_abd, zio->io_size, 25867877fdebSMatt Macy zio->io_type, zio->io_priority, 0, 25877877fdebSMatt Macy vdev_draid_spare_child_done, zio)); 25887877fdebSMatt Macy } 25897877fdebSMatt Macy } 25907877fdebSMatt Macy break; 25917877fdebSMatt Macy 25927877fdebSMatt Macy case ZIO_TYPE_READ: 25937877fdebSMatt Macy if (VDEV_OFFSET_IS_LABEL(vd, zio->io_offset)) { 25947877fdebSMatt Macy /* 25957877fdebSMatt Macy * Accept probe IOs to simulate the existence of a 25967877fdebSMatt Macy * label. vdev_label_read_config() bypasses the 25977877fdebSMatt Macy * pipeline to read the label configuration and 25987877fdebSMatt Macy * vdev_uberblock_load() skips distributed spares 25997877fdebSMatt Macy * when attempting to locate the best uberblock. 26007877fdebSMatt Macy */ 26017877fdebSMatt Macy if (zio->io_flags & ZIO_FLAG_PROBE) { 26027877fdebSMatt Macy zio->io_error = 0; 26037877fdebSMatt Macy } else { 26047877fdebSMatt Macy zio->io_error = SET_ERROR(EIO); 26057877fdebSMatt Macy } 26067877fdebSMatt Macy } else { 26077877fdebSMatt Macy cvd = vdev_draid_spare_get_child(vd, offset); 26087877fdebSMatt Macy 26097877fdebSMatt Macy if (cvd == NULL || !vdev_readable(cvd)) { 26107877fdebSMatt Macy zio->io_error = SET_ERROR(ENXIO); 26117877fdebSMatt Macy } else { 26127877fdebSMatt Macy zio_nowait(zio_vdev_child_io(zio, NULL, cvd, 26137877fdebSMatt Macy offset, zio->io_abd, zio->io_size, 26147877fdebSMatt Macy zio->io_type, zio->io_priority, 0, 26157877fdebSMatt Macy vdev_draid_spare_child_done, zio)); 26167877fdebSMatt Macy } 26177877fdebSMatt Macy } 26187877fdebSMatt Macy break; 26197877fdebSMatt Macy 26207877fdebSMatt Macy case ZIO_TYPE_TRIM: 26217877fdebSMatt Macy /* The vdev label ranges are never trimmed */ 26227877fdebSMatt Macy ASSERT0(VDEV_OFFSET_IS_LABEL(vd, zio->io_offset)); 26237877fdebSMatt Macy 26247877fdebSMatt Macy cvd = vdev_draid_spare_get_child(vd, offset); 26257877fdebSMatt Macy 26267877fdebSMatt Macy if (cvd == NULL || !cvd->vdev_has_trim) { 26277877fdebSMatt Macy zio->io_error = SET_ERROR(ENXIO); 26287877fdebSMatt Macy } else { 26297877fdebSMatt Macy zio_nowait(zio_vdev_child_io(zio, NULL, cvd, 26307877fdebSMatt Macy offset, zio->io_abd, zio->io_size, 26317877fdebSMatt Macy zio->io_type, zio->io_priority, 0, 26327877fdebSMatt Macy vdev_draid_spare_child_done, zio)); 26337877fdebSMatt Macy } 26347877fdebSMatt Macy break; 26357877fdebSMatt Macy 26367877fdebSMatt Macy default: 26377877fdebSMatt Macy zio->io_error = SET_ERROR(ENOTSUP); 26387877fdebSMatt Macy break; 26397877fdebSMatt Macy } 26407877fdebSMatt Macy 26417877fdebSMatt Macy zio_execute(zio); 26427877fdebSMatt Macy } 26437877fdebSMatt Macy 26447877fdebSMatt Macy /* ARGSUSED */ 26457877fdebSMatt Macy static void 26467877fdebSMatt Macy vdev_draid_spare_io_done(zio_t *zio) 26477877fdebSMatt Macy { 26487877fdebSMatt Macy } 26497877fdebSMatt Macy 26507877fdebSMatt Macy /* 26517877fdebSMatt Macy * Lookup the full spare config in spa->spa_spares.sav_config and 26527877fdebSMatt Macy * return the top_guid and spare_id for the named spare. 26537877fdebSMatt Macy */ 26547877fdebSMatt Macy static int 26557877fdebSMatt Macy vdev_draid_spare_lookup(spa_t *spa, nvlist_t *nv, uint64_t *top_guidp, 26567877fdebSMatt Macy uint64_t *spare_idp) 26577877fdebSMatt Macy { 26587877fdebSMatt Macy nvlist_t **spares; 26597877fdebSMatt Macy uint_t nspares; 26607877fdebSMatt Macy int error; 26617877fdebSMatt Macy 26627877fdebSMatt Macy if ((spa->spa_spares.sav_config == NULL) || 26637877fdebSMatt Macy (nvlist_lookup_nvlist_array(spa->spa_spares.sav_config, 26647877fdebSMatt Macy ZPOOL_CONFIG_SPARES, &spares, &nspares) != 0)) { 26657877fdebSMatt Macy return (SET_ERROR(ENOENT)); 26667877fdebSMatt Macy } 26677877fdebSMatt Macy 26687877fdebSMatt Macy char *spare_name; 26697877fdebSMatt Macy error = nvlist_lookup_string(nv, ZPOOL_CONFIG_PATH, &spare_name); 26707877fdebSMatt Macy if (error != 0) 26717877fdebSMatt Macy return (SET_ERROR(EINVAL)); 26727877fdebSMatt Macy 26737877fdebSMatt Macy for (int i = 0; i < nspares; i++) { 26747877fdebSMatt Macy nvlist_t *spare = spares[i]; 26757877fdebSMatt Macy uint64_t top_guid, spare_id; 26767877fdebSMatt Macy char *type, *path; 26777877fdebSMatt Macy 26787877fdebSMatt Macy /* Skip non-distributed spares */ 26797877fdebSMatt Macy error = nvlist_lookup_string(spare, ZPOOL_CONFIG_TYPE, &type); 26807877fdebSMatt Macy if (error != 0 || strcmp(type, VDEV_TYPE_DRAID_SPARE) != 0) 26817877fdebSMatt Macy continue; 26827877fdebSMatt Macy 26837877fdebSMatt Macy /* Skip spares with the wrong name */ 26847877fdebSMatt Macy error = nvlist_lookup_string(spare, ZPOOL_CONFIG_PATH, &path); 26857877fdebSMatt Macy if (error != 0 || strcmp(path, spare_name) != 0) 26867877fdebSMatt Macy continue; 26877877fdebSMatt Macy 26887877fdebSMatt Macy /* Found the matching spare */ 26897877fdebSMatt Macy error = nvlist_lookup_uint64(spare, 26907877fdebSMatt Macy ZPOOL_CONFIG_TOP_GUID, &top_guid); 26917877fdebSMatt Macy if (error == 0) { 26927877fdebSMatt Macy error = nvlist_lookup_uint64(spare, 26937877fdebSMatt Macy ZPOOL_CONFIG_SPARE_ID, &spare_id); 26947877fdebSMatt Macy } 26957877fdebSMatt Macy 26967877fdebSMatt Macy if (error != 0) { 26977877fdebSMatt Macy return (SET_ERROR(EINVAL)); 26987877fdebSMatt Macy } else { 26997877fdebSMatt Macy *top_guidp = top_guid; 27007877fdebSMatt Macy *spare_idp = spare_id; 27017877fdebSMatt Macy return (0); 27027877fdebSMatt Macy } 27037877fdebSMatt Macy } 27047877fdebSMatt Macy 27057877fdebSMatt Macy return (SET_ERROR(ENOENT)); 27067877fdebSMatt Macy } 27077877fdebSMatt Macy 27087877fdebSMatt Macy /* 27097877fdebSMatt Macy * Initialize private dRAID spare specific fields from the nvlist. 27107877fdebSMatt Macy */ 27117877fdebSMatt Macy static int 27127877fdebSMatt Macy vdev_draid_spare_init(spa_t *spa, nvlist_t *nv, void **tsd) 27137877fdebSMatt Macy { 27147877fdebSMatt Macy vdev_draid_spare_t *vds; 27157877fdebSMatt Macy uint64_t top_guid = 0; 27167877fdebSMatt Macy uint64_t spare_id; 27177877fdebSMatt Macy 27187877fdebSMatt Macy /* 27197877fdebSMatt Macy * In the normal case check the list of spares stored in the spa 27207877fdebSMatt Macy * to lookup the top_guid and spare_id for provided spare config. 27217877fdebSMatt Macy * When creating a new pool or adding vdevs the spare list is not 27227877fdebSMatt Macy * yet populated and the values are provided in the passed config. 27237877fdebSMatt Macy */ 27247877fdebSMatt Macy if (vdev_draid_spare_lookup(spa, nv, &top_guid, &spare_id) != 0) { 27257877fdebSMatt Macy if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_TOP_GUID, 27267877fdebSMatt Macy &top_guid) != 0) 27277877fdebSMatt Macy return (SET_ERROR(EINVAL)); 27287877fdebSMatt Macy 27297877fdebSMatt Macy if (nvlist_lookup_uint64(nv, ZPOOL_CONFIG_SPARE_ID, 27307877fdebSMatt Macy &spare_id) != 0) 27317877fdebSMatt Macy return (SET_ERROR(EINVAL)); 27327877fdebSMatt Macy } 27337877fdebSMatt Macy 27347877fdebSMatt Macy vds = kmem_alloc(sizeof (vdev_draid_spare_t), KM_SLEEP); 27357877fdebSMatt Macy vds->vds_draid_vdev = NULL; 27367877fdebSMatt Macy vds->vds_top_guid = top_guid; 27377877fdebSMatt Macy vds->vds_spare_id = spare_id; 27387877fdebSMatt Macy 27397877fdebSMatt Macy *tsd = vds; 27407877fdebSMatt Macy 27417877fdebSMatt Macy return (0); 27427877fdebSMatt Macy } 27437877fdebSMatt Macy 27447877fdebSMatt Macy static void 27457877fdebSMatt Macy vdev_draid_spare_fini(vdev_t *vd) 27467877fdebSMatt Macy { 27477877fdebSMatt Macy kmem_free(vd->vdev_tsd, sizeof (vdev_draid_spare_t)); 27487877fdebSMatt Macy } 27497877fdebSMatt Macy 27507877fdebSMatt Macy static void 27517877fdebSMatt Macy vdev_draid_spare_config_generate(vdev_t *vd, nvlist_t *nv) 27527877fdebSMatt Macy { 27537877fdebSMatt Macy vdev_draid_spare_t *vds = vd->vdev_tsd; 27547877fdebSMatt Macy 27557877fdebSMatt Macy ASSERT3P(vd->vdev_ops, ==, &vdev_draid_spare_ops); 27567877fdebSMatt Macy 27577877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_TOP_GUID, vds->vds_top_guid); 27587877fdebSMatt Macy fnvlist_add_uint64(nv, ZPOOL_CONFIG_SPARE_ID, vds->vds_spare_id); 27597877fdebSMatt Macy } 27607877fdebSMatt Macy 27617877fdebSMatt Macy vdev_ops_t vdev_draid_spare_ops = { 27627877fdebSMatt Macy .vdev_op_init = vdev_draid_spare_init, 27637877fdebSMatt Macy .vdev_op_fini = vdev_draid_spare_fini, 27647877fdebSMatt Macy .vdev_op_open = vdev_draid_spare_open, 27657877fdebSMatt Macy .vdev_op_close = vdev_draid_spare_close, 27667877fdebSMatt Macy .vdev_op_asize = vdev_default_asize, 27677877fdebSMatt Macy .vdev_op_min_asize = vdev_default_min_asize, 27687877fdebSMatt Macy .vdev_op_min_alloc = NULL, 27697877fdebSMatt Macy .vdev_op_io_start = vdev_draid_spare_io_start, 27707877fdebSMatt Macy .vdev_op_io_done = vdev_draid_spare_io_done, 27717877fdebSMatt Macy .vdev_op_state_change = NULL, 27727877fdebSMatt Macy .vdev_op_need_resilver = NULL, 27737877fdebSMatt Macy .vdev_op_hold = NULL, 27747877fdebSMatt Macy .vdev_op_rele = NULL, 27757877fdebSMatt Macy .vdev_op_remap = NULL, 27767877fdebSMatt Macy .vdev_op_xlate = vdev_default_xlate, 27777877fdebSMatt Macy .vdev_op_rebuild_asize = NULL, 27787877fdebSMatt Macy .vdev_op_metaslab_init = NULL, 27797877fdebSMatt Macy .vdev_op_config_generate = vdev_draid_spare_config_generate, 27807877fdebSMatt Macy .vdev_op_nparity = NULL, 27817877fdebSMatt Macy .vdev_op_ndisks = NULL, 27827877fdebSMatt Macy .vdev_op_type = VDEV_TYPE_DRAID_SPARE, 27837877fdebSMatt Macy .vdev_op_leaf = B_TRUE, 27847877fdebSMatt Macy }; 2785