xref: /freebsd/sys/contrib/openzfs/include/sys/vdev_draid.h (revision 22649d4dba730d46244fd2dff4fd174903c8379f)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * This file and its contents are supplied under the terms of the
4  * Common Development and Distribution License ("CDDL"), version 1.0.
5  * You may only use this file in accordance with the terms of version
6  * 1.0 of the CDDL.
7  *
8  * A full copy of the text of the CDDL should have accompanied this
9  * source.  A copy of the CDDL is also available via the Internet at
10  * https://opensource.org/license/CDDL-1.0.
11  */
12 /*
13  * Copyright (c) 2016, Intel Corporation.
14  * Copyright (c) 2020 by Lawrence Livermore National Security, LLC.
15  */
16 
17 #ifndef _SYS_VDEV_DRAID_H
18 #define	_SYS_VDEV_DRAID_H
19 
20 #include <sys/types.h>
21 #include <sys/abd.h>
22 #include <sys/nvpair.h>
23 #include <sys/zio.h>
24 #include <sys/vdev_impl.h>
25 #include <sys/vdev_raidz_impl.h>
26 #include <sys/vdev.h>
27 
28 #ifdef  __cplusplus
29 extern "C" {
30 #endif
31 
32 /*
33  * Constants required to generate and use dRAID permutations.
34  */
35 #define	VDEV_DRAID_SEED			0xd7a1d5eed
36 #define	VDEV_DRAID_MAX_MAPS		254
37 #define	VDEV_DRAID_ROWSHIFT		SPA_MAXBLOCKSHIFT
38 #define	VDEV_DRAID_ROWHEIGHT		(1ULL << VDEV_DRAID_ROWSHIFT)
39 #define	VDEV_DRAID_REFLOW_RESERVE	(2 * VDEV_DRAID_ROWHEIGHT)
40 
41 /*
42  * dRAID permutation map.
43  */
44 typedef struct draid_map {
45 	uint64_t dm_children;	/* # of permutation columns */
46 	uint64_t dm_nperms;	/* # of permutation rows */
47 	uint64_t dm_seed;	/* dRAID map seed */
48 	uint64_t dm_checksum;	/* Checksum of generated map */
49 	uint8_t *dm_perms;	/* base permutation array */
50 } draid_map_t;
51 
52 /*
53  * dRAID configuration.
54  */
55 typedef struct vdev_draid_config {
56 	/*
57 	 * Values read from the dRAID nvlist configuration.
58 	 */
59 	uint64_t vdc_ndata;		/* # of data devices in group */
60 	uint64_t vdc_nparity;		/* # of parity devices in group */
61 	uint64_t vdc_nspares;		/* # of distributed spares in slice */
62 	uint64_t vdc_children;		/* # of children */
63 	uint64_t vdc_ngroups;		/* # groups per slice */
64 	uint64_t vdc_width;		/* # multiple of children */
65 
66 	/*
67 	 * Immutable derived constants.
68 	 */
69 	uint8_t *vdc_perms;		/* permutation array */
70 	uint64_t vdc_nperms;		/* # of permutations */
71 	uint64_t vdc_groupwidth;	/* = data + parity */
72 	uint64_t vdc_ndisks;		/* = children - spares */
73 	uint64_t vdc_groupsz;		/* = groupwidth * DRAID_ROWSIZE */
74 	uint64_t vdc_devslicesz;	/* = (groupsz * groups) / ndisks */
75 } vdev_draid_config_t;
76 
77 /*
78  * Functions for handling dRAID permutation maps.
79  */
80 extern uint64_t vdev_draid_rand(uint64_t *);
81 extern int vdev_draid_lookup_map(uint64_t, const draid_map_t **);
82 extern int vdev_draid_generate_perms(const draid_map_t *, uint8_t **);
83 
84 /*
85  * General dRAID support functions.
86  */
87 extern boolean_t vdev_draid_readable(vdev_t *, uint64_t);
88 extern boolean_t vdev_draid_missing(vdev_t *, uint64_t, uint64_t, uint64_t);
89 extern uint64_t vdev_draid_asize_to_psize(vdev_t *, uint64_t, uint64_t);
90 extern void vdev_draid_map_alloc_empty(zio_t *, struct raidz_row *);
91 extern int vdev_draid_map_verify_empty(zio_t *, struct raidz_row *);
92 extern nvlist_t *vdev_draid_read_config_spare(vdev_t *);
93 
94 /* Functions for dRAID distributed spares. */
95 extern vdev_t *vdev_draid_spare_get_child(vdev_t *, uint64_t);
96 extern vdev_t *vdev_draid_spare_get_parent(vdev_t *);
97 extern int vdev_draid_spare_create(nvlist_t *, vdev_t *, uint64_t *, uint64_t *,
98     uint64_t);
99 extern boolean_t vdev_draid_fail_domain_allowed(vdev_t *);
100 
101 #ifdef  __cplusplus
102 }
103 #endif
104 
105 #endif /* _SYS_VDEV_DRAID_H */
106