xref: /freebsd/sys/contrib/openzfs/include/zfeature_common.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 /*
14  * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
15  * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
16  * Copyright (c) 2013, Joyent, Inc. All rights reserved.
17  * Copyright (c) 2017, Intel Corporation.
18  * Copyright (c) 2024, Klara, Inc.
19  */
20 
21 #ifndef _ZFEATURE_COMMON_H
22 #define	_ZFEATURE_COMMON_H extern __attribute__((visibility("default")))
23 
24 #include <sys/fs/zfs.h>
25 #include <sys/inttypes.h>
26 #include <sys/types.h>
27 
28 #ifdef	__cplusplus
29 extern "C" {
30 #endif
31 
32 struct zfeature_info;
33 
34 typedef enum spa_feature {
35 	SPA_FEATURE_NONE = -1,
36 	SPA_FEATURE_ASYNC_DESTROY,
37 	SPA_FEATURE_EMPTY_BPOBJ,
38 	SPA_FEATURE_LZ4_COMPRESS,
39 	SPA_FEATURE_MULTI_VDEV_CRASH_DUMP,
40 	SPA_FEATURE_SPACEMAP_HISTOGRAM,
41 	SPA_FEATURE_ENABLED_TXG,
42 	SPA_FEATURE_HOLE_BIRTH,
43 	SPA_FEATURE_EXTENSIBLE_DATASET,
44 	SPA_FEATURE_EMBEDDED_DATA,
45 	SPA_FEATURE_BOOKMARKS,
46 	SPA_FEATURE_FS_SS_LIMIT,
47 	SPA_FEATURE_LARGE_BLOCKS,
48 	SPA_FEATURE_LARGE_DNODE,
49 	SPA_FEATURE_SHA512,
50 	SPA_FEATURE_SKEIN,
51 	SPA_FEATURE_EDONR,
52 	SPA_FEATURE_USEROBJ_ACCOUNTING,
53 	SPA_FEATURE_ENCRYPTION,
54 	SPA_FEATURE_PROJECT_QUOTA,
55 	SPA_FEATURE_DEVICE_REMOVAL,
56 	SPA_FEATURE_OBSOLETE_COUNTS,
57 	SPA_FEATURE_POOL_CHECKPOINT,
58 	SPA_FEATURE_SPACEMAP_V2,
59 	SPA_FEATURE_ALLOCATION_CLASSES,
60 	SPA_FEATURE_RESILVER_DEFER,
61 	SPA_FEATURE_BOOKMARK_V2,
62 	SPA_FEATURE_REDACTION_BOOKMARKS,
63 	SPA_FEATURE_REDACTED_DATASETS,
64 	SPA_FEATURE_BOOKMARK_WRITTEN,
65 	SPA_FEATURE_LOG_SPACEMAP,
66 	SPA_FEATURE_LIVELIST,
67 	SPA_FEATURE_DEVICE_REBUILD,
68 	SPA_FEATURE_ZSTD_COMPRESS,
69 	SPA_FEATURE_DRAID,
70 	SPA_FEATURE_ZILSAXATTR,
71 	SPA_FEATURE_HEAD_ERRLOG,
72 	SPA_FEATURE_BLAKE3,
73 	SPA_FEATURE_BLOCK_CLONING,
74 	SPA_FEATURE_AVZ_V2,
75 	SPA_FEATURE_REDACTION_LIST_SPILL,
76 	SPA_FEATURE_RAIDZ_EXPANSION,
77 	SPA_FEATURE_FAST_DEDUP,
78 	SPA_FEATURE_LONGNAME,
79 	SPA_FEATURE_LARGE_MICROZAP,
80 	SPA_FEATURE_DYNAMIC_GANG_HEADER,
81 	SPA_FEATURE_BLOCK_CLONING_ENDIAN,
82 	SPA_FEATURE_PHYSICAL_REWRITE,
83 	SPA_FEATURE_DRAID_FAIL_DOMAINS,
84 	SPA_FEATURES
85 } spa_feature_t;
86 
87 #define	SPA_FEATURE_DISABLED	(-1ULL)
88 
89 typedef enum zfeature_flags {
90 	/* Can open pool readonly even if this feature is not supported. */
91 	ZFEATURE_FLAG_READONLY_COMPAT =		(1 << 0),
92 	/*
93 	 * Is this feature necessary to load the pool? i.e. do we need this
94 	 * feature to read the full feature list out of the MOS?
95 	 */
96 	ZFEATURE_FLAG_MOS =			(1 << 1),
97 	/* Activate this feature at the same time it is enabled. */
98 	ZFEATURE_FLAG_ACTIVATE_ON_ENABLE =	(1 << 2),
99 	/* Each dataset has a field set if it has ever used this feature. */
100 	ZFEATURE_FLAG_PER_DATASET =		(1 << 3),
101 	/*
102 	 * This feature isn't enabled by zpool upgrade; it must be explicitly
103 	 * listed to be enabled. It will also be applied if listed in an
104 	 * explicitly provided compatibility list. This flag can be removed
105 	 * from a given feature once support is sufficiently widespread, or
106 	 * worries about backwards compatibility are no longer relevant.
107 	 */
108 	ZFEATURE_FLAG_NO_UPGRADE = 		(1 << 4)
109 } zfeature_flags_t;
110 
111 typedef enum zfeature_type {
112 	ZFEATURE_TYPE_BOOLEAN,
113 	ZFEATURE_TYPE_UINT64_ARRAY,
114 	ZFEATURE_NUM_TYPES
115 } zfeature_type_t;
116 
117 typedef struct zfeature_info {
118 	spa_feature_t fi_feature;
119 	const char *fi_uname;	/* User-facing feature name */
120 	const char *fi_guid;	/* On-disk feature identifier */
121 	const char *fi_desc;	/* Feature description */
122 	zfeature_flags_t fi_flags;
123 	boolean_t fi_zfs_mod_supported;	/* supported by running zfs module */
124 	zfeature_type_t fi_type; /* Only relevant for PER_DATASET features */
125 	/* array of dependencies, terminated by SPA_FEATURE_NONE */
126 	const spa_feature_t *fi_depends;
127 } zfeature_info_t;
128 
129 typedef int (zfeature_func_t)(zfeature_info_t *, void *);
130 
131 #define	ZFS_FEATURE_DEBUG
132 
133 _ZFEATURE_COMMON_H zfeature_info_t spa_feature_table[SPA_FEATURES];
134 _ZFEATURE_COMMON_H boolean_t zfeature_checks_disable;
135 
136 _ZFEATURE_COMMON_H boolean_t zfeature_is_valid_guid(const char *);
137 
138 _ZFEATURE_COMMON_H boolean_t zfeature_is_supported(const char *);
139 _ZFEATURE_COMMON_H int zfeature_lookup_guid(const char *, spa_feature_t *);
140 _ZFEATURE_COMMON_H int zfeature_lookup_name(const char *, spa_feature_t *);
141 _ZFEATURE_COMMON_H boolean_t zfeature_depends_on(spa_feature_t, spa_feature_t);
142 
143 _ZFEATURE_COMMON_H void zpool_feature_init(void);
144 
145 #ifdef	__cplusplus
146 }
147 #endif
148 
149 #endif	/* _ZFEATURE_COMMON_H */
150