1*22ce4affSfengbojiang /* 2*22ce4affSfengbojiang * CDDL HEADER START 3*22ce4affSfengbojiang * 4*22ce4affSfengbojiang * The contents of this file are subject to the terms of the 5*22ce4affSfengbojiang * Common Development and Distribution License (the "License"). 6*22ce4affSfengbojiang * You may not use this file except in compliance with the License. 7*22ce4affSfengbojiang * 8*22ce4affSfengbojiang * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*22ce4affSfengbojiang * or http://www.opensolaris.org/os/licensing. 10*22ce4affSfengbojiang * See the License for the specific language governing permissions 11*22ce4affSfengbojiang * and limitations under the License. 12*22ce4affSfengbojiang * 13*22ce4affSfengbojiang * When distributing Covered Code, include this CDDL HEADER in each 14*22ce4affSfengbojiang * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*22ce4affSfengbojiang * If applicable, add the following below this CDDL HEADER, with the 16*22ce4affSfengbojiang * fields enclosed by brackets "[]" replaced with your own identifying 17*22ce4affSfengbojiang * information: Portions Copyright [yyyy] [name of copyright owner] 18*22ce4affSfengbojiang * 19*22ce4affSfengbojiang * CDDL HEADER END 20*22ce4affSfengbojiang */ 21*22ce4affSfengbojiang /* 22*22ce4affSfengbojiang * Copyright (c) 2016, Intel Corporation. 23*22ce4affSfengbojiang * Copyright (c) 2020 by Lawrence Livermore National Security, LLC. 24*22ce4affSfengbojiang */ 25*22ce4affSfengbojiang 26*22ce4affSfengbojiang #ifndef _SYS_VDEV_DRAID_H 27*22ce4affSfengbojiang #define _SYS_VDEV_DRAID_H 28*22ce4affSfengbojiang 29*22ce4affSfengbojiang #include <sys/types.h> 30*22ce4affSfengbojiang #include <sys/abd.h> 31*22ce4affSfengbojiang #include <sys/nvpair.h> 32*22ce4affSfengbojiang #include <sys/zio.h> 33*22ce4affSfengbojiang #include <sys/vdev_impl.h> 34*22ce4affSfengbojiang #include <sys/vdev_raidz_impl.h> 35*22ce4affSfengbojiang #include <sys/vdev.h> 36*22ce4affSfengbojiang 37*22ce4affSfengbojiang #ifdef __cplusplus 38*22ce4affSfengbojiang extern "C" { 39*22ce4affSfengbojiang #endif 40*22ce4affSfengbojiang 41*22ce4affSfengbojiang /* 42*22ce4affSfengbojiang * Constants required to generate and use dRAID permutations. 43*22ce4affSfengbojiang */ 44*22ce4affSfengbojiang #define VDEV_DRAID_SEED 0xd7a1d5eed 45*22ce4affSfengbojiang #define VDEV_DRAID_MAX_MAPS 254 46*22ce4affSfengbojiang #define VDEV_DRAID_ROWSHIFT SPA_MAXBLOCKSHIFT 47*22ce4affSfengbojiang #define VDEV_DRAID_ROWHEIGHT (1ULL << VDEV_DRAID_ROWSHIFT) 48*22ce4affSfengbojiang #define VDEV_DRAID_REFLOW_RESERVE (2 * VDEV_DRAID_ROWHEIGHT) 49*22ce4affSfengbojiang 50*22ce4affSfengbojiang /* 51*22ce4affSfengbojiang * dRAID permutation map. 52*22ce4affSfengbojiang */ 53*22ce4affSfengbojiang typedef struct draid_map { 54*22ce4affSfengbojiang uint64_t dm_children; /* # of permuation columns */ 55*22ce4affSfengbojiang uint64_t dm_nperms; /* # of permutation rows */ 56*22ce4affSfengbojiang uint64_t dm_seed; /* dRAID map seed */ 57*22ce4affSfengbojiang uint64_t dm_checksum; /* Checksum of generated map */ 58*22ce4affSfengbojiang uint8_t *dm_perms; /* base permutation array */ 59*22ce4affSfengbojiang } draid_map_t; 60*22ce4affSfengbojiang 61*22ce4affSfengbojiang /* 62*22ce4affSfengbojiang * dRAID configuration. 63*22ce4affSfengbojiang */ 64*22ce4affSfengbojiang typedef struct vdev_draid_config { 65*22ce4affSfengbojiang /* 66*22ce4affSfengbojiang * Values read from the dRAID nvlist configuration. 67*22ce4affSfengbojiang */ 68*22ce4affSfengbojiang uint64_t vdc_ndata; /* # of data devices in group */ 69*22ce4affSfengbojiang uint64_t vdc_nparity; /* # of parity devices in group */ 70*22ce4affSfengbojiang uint64_t vdc_nspares; /* # of distributed spares */ 71*22ce4affSfengbojiang uint64_t vdc_children; /* # of children */ 72*22ce4affSfengbojiang uint64_t vdc_ngroups; /* # groups per slice */ 73*22ce4affSfengbojiang 74*22ce4affSfengbojiang /* 75*22ce4affSfengbojiang * Immutable derived constants. 76*22ce4affSfengbojiang */ 77*22ce4affSfengbojiang uint8_t *vdc_perms; /* permutation array */ 78*22ce4affSfengbojiang uint64_t vdc_nperms; /* # of permutations */ 79*22ce4affSfengbojiang uint64_t vdc_groupwidth; /* = data + parity */ 80*22ce4affSfengbojiang uint64_t vdc_ndisks; /* = children - spares */ 81*22ce4affSfengbojiang uint64_t vdc_groupsz; /* = groupwidth * DRAID_ROWSIZE */ 82*22ce4affSfengbojiang uint64_t vdc_devslicesz; /* = (groupsz * groups) / ndisks */ 83*22ce4affSfengbojiang } vdev_draid_config_t; 84*22ce4affSfengbojiang 85*22ce4affSfengbojiang /* 86*22ce4affSfengbojiang * Functions for handling dRAID permutation maps. 87*22ce4affSfengbojiang */ 88*22ce4affSfengbojiang extern uint64_t vdev_draid_rand(uint64_t *); 89*22ce4affSfengbojiang extern int vdev_draid_lookup_map(uint64_t, const draid_map_t **); 90*22ce4affSfengbojiang extern int vdev_draid_generate_perms(const draid_map_t *, uint8_t **); 91*22ce4affSfengbojiang 92*22ce4affSfengbojiang /* 93*22ce4affSfengbojiang * General dRAID support functions. 94*22ce4affSfengbojiang */ 95*22ce4affSfengbojiang extern boolean_t vdev_draid_readable(vdev_t *, uint64_t); 96*22ce4affSfengbojiang extern boolean_t vdev_draid_missing(vdev_t *, uint64_t, uint64_t, uint64_t); 97*22ce4affSfengbojiang extern uint64_t vdev_draid_asize_to_psize(vdev_t *, uint64_t); 98*22ce4affSfengbojiang extern void vdev_draid_map_alloc_empty(zio_t *, struct raidz_row *); 99*22ce4affSfengbojiang extern nvlist_t *vdev_draid_read_config_spare(vdev_t *); 100*22ce4affSfengbojiang 101*22ce4affSfengbojiang /* Functions for dRAID distributed spares. */ 102*22ce4affSfengbojiang extern vdev_t *vdev_draid_spare_get_child(vdev_t *, uint64_t); 103*22ce4affSfengbojiang extern vdev_t *vdev_draid_spare_get_parent(vdev_t *); 104*22ce4affSfengbojiang extern int vdev_draid_spare_create(nvlist_t *, vdev_t *, uint64_t *, uint64_t); 105*22ce4affSfengbojiang 106*22ce4affSfengbojiang #ifdef __cplusplus 107*22ce4affSfengbojiang } 108*22ce4affSfengbojiang #endif 109*22ce4affSfengbojiang 110*22ce4affSfengbojiang #endif /* _SYS_VDEV_DRAID_H */ 111