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