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