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.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
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]
23 * Copyright (c) 2011, 2018 by Delphix. All rights reserved.
24 * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
25 * Copyright (c) 2013, Joyent, Inc. All rights reserved.
26 * Copyright (c) 2014, Nexenta Systems, Inc. All rights reserved.
27 * Copyright (c) 2014 Integros [integros.com]
28 * Copyright (c) 2017, Intel Corporation.
32 #include <sys/systm.h>
37 #include <sys/debug.h>
38 #include <sys/fs/zfs.h>
39 #include <sys/inttypes.h>
40 #include <sys/types.h>
41 #include "zfeature_common.h"
44 * Set to disable all feature checks while opening pools, allowing pools with
45 * unsupported features to be opened. Set for testing only.
47 boolean_t zfeature_checks_disable
= B_FALSE
;
49 zfeature_info_t spa_feature_table
[SPA_FEATURES
];
52 * Valid characters for feature guids. This list is mainly for aesthetic
53 * purposes and could be expanded in the future. There are different allowed
54 * characters in the guids reverse dns portion (before the colon) and its
55 * short name (after the colon).
58 valid_char(char c
, boolean_t after_colon
)
60 return ((c
>= 'a' && c
<= 'z') ||
61 (c
>= '0' && c
<= '9') ||
62 (after_colon
&& c
== '_') ||
63 (!after_colon
&& (c
== '.' || c
== '-')));
67 * Every feature guid must contain exactly one colon which separates a reverse
68 * dns organization name from the feature's "short" name (e.g.
69 * "com.company:feature_name").
72 zfeature_is_valid_guid(const char *name
)
75 boolean_t has_colon
= B_FALSE
;
78 while (name
[i
] != '\0') {
86 if (!valid_char(c
, has_colon
))
94 zfeature_is_supported(const char *guid
)
96 if (zfeature_checks_disable
)
99 for (spa_feature_t i
= 0; i
< SPA_FEATURES
; i
++) {
100 zfeature_info_t
*feature
= &spa_feature_table
[i
];
101 if (strcmp(guid
, feature
->fi_guid
) == 0)
108 zfeature_lookup_name(const char *name
, spa_feature_t
*res
)
110 for (spa_feature_t i
= 0; i
< SPA_FEATURES
; i
++) {
111 zfeature_info_t
*feature
= &spa_feature_table
[i
];
112 if (strcmp(name
, feature
->fi_uname
) == 0) {
123 zfeature_depends_on(spa_feature_t fid
, spa_feature_t check
)
125 zfeature_info_t
*feature
= &spa_feature_table
[fid
];
127 for (int i
= 0; feature
->fi_depends
[i
] != SPA_FEATURE_NONE
; i
++) {
128 if (feature
->fi_depends
[i
] == check
)
135 deps_contains_feature(const spa_feature_t
*deps
, const spa_feature_t feature
)
137 for (int i
= 0; deps
[i
] != SPA_FEATURE_NONE
; i
++)
138 if (deps
[i
] == feature
)
145 zfeature_register(spa_feature_t fid
, const char *guid
, const char *name
,
146 const char *desc
, zfeature_flags_t flags
, const spa_feature_t
*deps
)
148 zfeature_info_t
*feature
= &spa_feature_table
[fid
];
149 static spa_feature_t nodeps
[] = { SPA_FEATURE_NONE
};
151 ASSERT(name
!= NULL
);
152 ASSERT(desc
!= NULL
);
153 ASSERT((flags
& ZFEATURE_FLAG_READONLY_COMPAT
) == 0 ||
154 (flags
& ZFEATURE_FLAG_MOS
) == 0);
155 ASSERT3U(fid
, <, SPA_FEATURES
);
156 ASSERT(zfeature_is_valid_guid(guid
));
161 VERIFY(((flags
& ZFEATURE_FLAG_PER_DATASET
) == 0) ||
162 (deps_contains_feature(deps
, SPA_FEATURE_EXTENSIBLE_DATASET
)));
164 feature
->fi_feature
= fid
;
165 feature
->fi_guid
= guid
;
166 feature
->fi_uname
= name
;
167 feature
->fi_desc
= desc
;
168 feature
->fi_flags
= flags
;
169 feature
->fi_depends
= deps
;
173 zpool_feature_init(void)
175 zfeature_register(SPA_FEATURE_ASYNC_DESTROY
,
176 "com.delphix:async_destroy", "async_destroy",
177 "Destroy filesystems asynchronously.",
178 ZFEATURE_FLAG_READONLY_COMPAT
, NULL
);
180 zfeature_register(SPA_FEATURE_EMPTY_BPOBJ
,
181 "com.delphix:empty_bpobj", "empty_bpobj",
182 "Snapshots use less space.",
183 ZFEATURE_FLAG_READONLY_COMPAT
, NULL
);
185 zfeature_register(SPA_FEATURE_LZ4_COMPRESS
,
186 "org.illumos:lz4_compress", "lz4_compress",
187 "LZ4 compression algorithm support.",
188 ZFEATURE_FLAG_ACTIVATE_ON_ENABLE
, NULL
);
190 zfeature_register(SPA_FEATURE_MULTI_VDEV_CRASH_DUMP
,
191 "com.joyent:multi_vdev_crash_dump", "multi_vdev_crash_dump",
192 "Crash dumps to multiple vdev pools.",
195 zfeature_register(SPA_FEATURE_SPACEMAP_HISTOGRAM
,
196 "com.delphix:spacemap_histogram", "spacemap_histogram",
197 "Spacemaps maintain space histograms.",
198 ZFEATURE_FLAG_READONLY_COMPAT
, NULL
);
200 zfeature_register(SPA_FEATURE_ENABLED_TXG
,
201 "com.delphix:enabled_txg", "enabled_txg",
202 "Record txg at which a feature is enabled",
203 ZFEATURE_FLAG_READONLY_COMPAT
, NULL
);
205 static spa_feature_t hole_birth_deps
[] = {
206 SPA_FEATURE_ENABLED_TXG
,
209 zfeature_register(SPA_FEATURE_HOLE_BIRTH
,
210 "com.delphix:hole_birth", "hole_birth",
211 "Retain hole birth txg for more precise zfs send",
212 ZFEATURE_FLAG_MOS
| ZFEATURE_FLAG_ACTIVATE_ON_ENABLE
,
215 zfeature_register(SPA_FEATURE_EXTENSIBLE_DATASET
,
216 "com.delphix:extensible_dataset", "extensible_dataset",
217 "Enhanced dataset functionality, used by other features.",
220 static const spa_feature_t bookmarks_deps
[] = {
221 SPA_FEATURE_EXTENSIBLE_DATASET
,
224 zfeature_register(SPA_FEATURE_BOOKMARKS
,
225 "com.delphix:bookmarks", "bookmarks",
226 "\"zfs bookmark\" command",
227 ZFEATURE_FLAG_READONLY_COMPAT
, bookmarks_deps
);
229 static const spa_feature_t filesystem_limits_deps
[] = {
230 SPA_FEATURE_EXTENSIBLE_DATASET
,
233 zfeature_register(SPA_FEATURE_FS_SS_LIMIT
,
234 "com.joyent:filesystem_limits", "filesystem_limits",
235 "Filesystem and snapshot limits.",
236 ZFEATURE_FLAG_READONLY_COMPAT
, filesystem_limits_deps
);
238 zfeature_register(SPA_FEATURE_EMBEDDED_DATA
,
239 "com.delphix:embedded_data", "embedded_data",
240 "Blocks which compress very well use even less space.",
241 ZFEATURE_FLAG_MOS
| ZFEATURE_FLAG_ACTIVATE_ON_ENABLE
,
244 zfeature_register(SPA_FEATURE_POOL_CHECKPOINT
,
245 "com.delphix:zpool_checkpoint", "zpool_checkpoint",
246 "Pool state can be checkpointed, allowing rewind later.",
247 ZFEATURE_FLAG_READONLY_COMPAT
, NULL
);
249 zfeature_register(SPA_FEATURE_SPACEMAP_V2
,
250 "com.delphix:spacemap_v2", "spacemap_v2",
251 "Space maps representing large segments are more efficient.",
252 ZFEATURE_FLAG_READONLY_COMPAT
| ZFEATURE_FLAG_ACTIVATE_ON_ENABLE
,
255 static const spa_feature_t large_blocks_deps
[] = {
256 SPA_FEATURE_EXTENSIBLE_DATASET
,
259 zfeature_register(SPA_FEATURE_LARGE_BLOCKS
,
260 "org.open-zfs:large_blocks", "large_blocks",
261 "Support for blocks larger than 128KB.",
262 ZFEATURE_FLAG_PER_DATASET
, large_blocks_deps
);
265 static const spa_feature_t bookmark_v2_deps
[] = {
266 SPA_FEATURE_EXTENSIBLE_DATASET
,
267 SPA_FEATURE_BOOKMARKS
,
270 zfeature_register(SPA_FEATURE_BOOKMARK_V2
,
271 "com.datto:bookmark_v2", "bookmark_v2",
272 "Support for larger bookmarks",
273 ZFEATURE_FLAG_PER_DATASET
, bookmark_v2_deps
);
277 static const spa_feature_t large_dnode_deps
[] = {
278 SPA_FEATURE_EXTENSIBLE_DATASET
,
281 zfeature_register(SPA_FEATURE_LARGE_DNODE
,
282 "org.zfsonlinux:large_dnode", "large_dnode",
283 "Variable on-disk size of dnodes.",
284 ZFEATURE_FLAG_PER_DATASET
, large_dnode_deps
);
287 static const spa_feature_t sha512_deps
[] = {
288 SPA_FEATURE_EXTENSIBLE_DATASET
,
291 zfeature_register(SPA_FEATURE_SHA512
,
292 "org.illumos:sha512", "sha512",
293 "SHA-512/256 hash algorithm.",
294 ZFEATURE_FLAG_PER_DATASET
, sha512_deps
);
296 static const spa_feature_t skein_deps
[] = {
297 SPA_FEATURE_EXTENSIBLE_DATASET
,
300 zfeature_register(SPA_FEATURE_SKEIN
,
301 "org.illumos:skein", "skein",
302 "Skein hash algorithm.",
303 ZFEATURE_FLAG_PER_DATASET
, skein_deps
);
305 static const spa_feature_t edonr_deps
[] = {
306 SPA_FEATURE_EXTENSIBLE_DATASET
,
309 zfeature_register(SPA_FEATURE_EDONR
,
310 "org.illumos:edonr", "edonr",
311 "Edon-R hash algorithm.",
312 ZFEATURE_FLAG_PER_DATASET
, edonr_deps
);
314 zfeature_register(SPA_FEATURE_DEVICE_REMOVAL
,
315 "com.delphix:device_removal", "device_removal",
316 "Top-level vdevs can be removed, reducing logical pool size.",
317 ZFEATURE_FLAG_MOS
, NULL
);
319 static const spa_feature_t obsolete_counts_deps
[] = {
320 SPA_FEATURE_EXTENSIBLE_DATASET
,
321 SPA_FEATURE_DEVICE_REMOVAL
,
324 zfeature_register(SPA_FEATURE_OBSOLETE_COUNTS
,
325 "com.delphix:obsolete_counts", "obsolete_counts",
326 "Reduce memory used by removed devices when their blocks are "
327 "freed or remapped.",
328 ZFEATURE_FLAG_READONLY_COMPAT
, obsolete_counts_deps
);
330 zfeature_register(SPA_FEATURE_ALLOCATION_CLASSES
,
331 "org.zfsonlinux:allocation_classes", "allocation_classes",
332 "Support for separate allocation classes.",
333 ZFEATURE_FLAG_READONLY_COMPAT
, NULL
);
335 zfeature_register(SPA_FEATURE_RESILVER_DEFER
,
336 "com.datto:resilver_defer", "resilver_defer",
337 "Support for defering new resilvers when one is already running.",
338 ZFEATURE_FLAG_READONLY_COMPAT
, NULL
);
340 static const spa_feature_t encryption_deps
[] = {
341 SPA_FEATURE_EXTENSIBLE_DATASET
,
342 SPA_FEATURE_BOOKMARK_V2
,
345 zfeature_register(SPA_FEATURE_ENCRYPTION
,
346 "com.datto:encryption", "encryption",
347 "Support for dataset level encryption",
348 ZFEATURE_FLAG_PER_DATASET
, encryption_deps
);
350 static const spa_feature_t userobj_accounting_deps
[] = {
351 SPA_FEATURE_EXTENSIBLE_DATASET
,
354 zfeature_register(SPA_FEATURE_USEROBJ_ACCOUNTING
,
355 "org.zfsonlinux:userobj_accounting", "userobj_accounting",
356 "User/Group object accounting.",
357 ZFEATURE_FLAG_READONLY_COMPAT
| ZFEATURE_FLAG_PER_DATASET
,
358 userobj_accounting_deps
);
360 static const spa_feature_t project_quota_deps
[] = {
361 SPA_FEATURE_EXTENSIBLE_DATASET
,
364 zfeature_register(SPA_FEATURE_PROJECT_QUOTA
,
365 "org.zfsonlinux:project_quota", "project_quota",
366 "space/object accounting based on project ID.",
367 ZFEATURE_FLAG_READONLY_COMPAT
| ZFEATURE_FLAG_PER_DATASET
,
370 static const spa_feature_t log_spacemap_deps
[] = {
371 SPA_FEATURE_SPACEMAP_V2
,
374 zfeature_register(SPA_FEATURE_LOG_SPACEMAP
,
375 "com.delphix:log_spacemap", "log_spacemap",
376 "Log metaslab changes on a single spacemap and "
377 "flush them periodically.",
378 ZFEATURE_FLAG_READONLY_COMPAT
,