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) 2017, Intel Corporation.
35 #include <sys/debug.h>
36 #include <sys/fs/zfs.h>
37 #include <sys/inttypes.h>
38 #include <sys/types.h>
39 #include <sys/zfs_sysfs.h>
40 #include "zfeature_common.h"
43 * Set to disable all feature checks while opening pools, allowing pools with
44 * unsupported features to be opened. Set for testing only.
46 boolean_t zfeature_checks_disable
= B_FALSE
;
48 zfeature_info_t spa_feature_table
[SPA_FEATURES
];
51 * Valid characters for feature guids. This list is mainly for aesthetic
52 * purposes and could be expanded in the future. There are different allowed
53 * characters in the guids reverse dns portion (before the colon) and its
54 * short name (after the colon).
57 valid_char(char c
, boolean_t after_colon
)
59 return ((c
>= 'a' && c
<= 'z') ||
60 (c
>= '0' && c
<= '9') ||
61 (after_colon
&& c
== '_') ||
62 (!after_colon
&& (c
== '.' || c
== '-')));
66 * Every feature guid must contain exactly one colon which separates a reverse
67 * dns organization name from the feature's "short" name (e.g.
68 * "com.company:feature_name").
71 zfeature_is_valid_guid(const char *name
)
74 boolean_t has_colon
= B_FALSE
;
77 while (name
[i
] != '\0') {
85 if (!valid_char(c
, has_colon
))
93 zfeature_is_supported(const char *guid
)
95 if (zfeature_checks_disable
)
98 for (spa_feature_t i
= 0; i
< SPA_FEATURES
; i
++) {
99 zfeature_info_t
*feature
= &spa_feature_table
[i
];
100 if (strcmp(guid
, feature
->fi_guid
) == 0)
107 zfeature_lookup_guid(const char *guid
, spa_feature_t
*res
)
109 for (spa_feature_t i
= 0; i
< SPA_FEATURES
; i
++) {
110 zfeature_info_t
*feature
= &spa_feature_table
[i
];
111 if (!feature
->fi_zfs_mod_supported
)
113 if (strcmp(guid
, feature
->fi_guid
) == 0) {
124 zfeature_lookup_name(const char *name
, spa_feature_t
*res
)
126 for (spa_feature_t i
= 0; i
< SPA_FEATURES
; i
++) {
127 zfeature_info_t
*feature
= &spa_feature_table
[i
];
128 if (!feature
->fi_zfs_mod_supported
)
130 if (strcmp(name
, feature
->fi_uname
) == 0) {
141 zfeature_depends_on(spa_feature_t fid
, spa_feature_t check
)
143 zfeature_info_t
*feature
= &spa_feature_table
[fid
];
145 for (int i
= 0; feature
->fi_depends
[i
] != SPA_FEATURE_NONE
; i
++) {
146 if (feature
->fi_depends
[i
] == check
)
153 deps_contains_feature(const spa_feature_t
*deps
, const spa_feature_t feature
)
155 for (int i
= 0; deps
[i
] != SPA_FEATURE_NONE
; i
++)
156 if (deps
[i
] == feature
)
162 #if !defined(_KERNEL) && !defined(LIB_ZPOOL_BUILD)
164 zfs_mod_supported_impl(const char *scope
, const char *name
, const char *sysfs
)
166 boolean_t supported
= B_FALSE
;
169 int len
= asprintf(&path
, "%s%s%s%s%s", sysfs
,
170 scope
== NULL
? "" : "/", scope
== NULL
? "" : scope
,
171 name
== NULL
? "" : "/", name
== NULL
? "" : name
);
173 struct stat64 statbuf
;
174 supported
= !!(stat64(path
, &statbuf
) == 0);
182 zfs_mod_supported(const char *scope
, const char *name
)
187 * Check both the primary and alternate sysfs locations to determine
188 * if the required functionality is supported.
190 supported
= (zfs_mod_supported_impl(scope
, name
, ZFS_SYSFS_DIR
) ||
191 zfs_mod_supported_impl(scope
, name
, ZFS_SYSFS_ALT_DIR
));
194 * For backwards compatibility with kernel modules that predate
195 * supported feature/property checking. Report the feature/property
196 * as supported if the kernel module is loaded but the requested
197 * scope directory does not exist.
199 if (supported
== B_FALSE
) {
200 struct stat64 statbuf
;
201 if ((stat64(ZFS_SYSFS_DIR
, &statbuf
) == 0) &&
202 !zfs_mod_supported_impl(scope
, NULL
, ZFS_SYSFS_DIR
) &&
203 !zfs_mod_supported_impl(scope
, NULL
, ZFS_SYSFS_ALT_DIR
)) {
213 zfs_mod_supported_feature(const char *name
)
216 * The zfs module spa_feature_table[], whether in-kernel or in
217 * libzpool, always supports all the features. libzfs needs to
218 * query the running module, via sysfs, to determine which
219 * features are supported.
221 #if defined(_KERNEL) || defined(LIB_ZPOOL_BUILD)
224 return (zfs_mod_supported(ZFS_SYSFS_POOL_FEATURES
, name
));
229 zfeature_register(spa_feature_t fid
, const char *guid
, const char *name
,
230 const char *desc
, zfeature_flags_t flags
, zfeature_type_t type
,
231 const spa_feature_t
*deps
)
233 zfeature_info_t
*feature
= &spa_feature_table
[fid
];
234 static spa_feature_t nodeps
[] = { SPA_FEATURE_NONE
};
236 ASSERT(name
!= NULL
);
237 ASSERT(desc
!= NULL
);
238 ASSERT((flags
& ZFEATURE_FLAG_READONLY_COMPAT
) == 0 ||
239 (flags
& ZFEATURE_FLAG_MOS
) == 0);
240 ASSERT3U(fid
, <, SPA_FEATURES
);
241 ASSERT(zfeature_is_valid_guid(guid
));
246 VERIFY(((flags
& ZFEATURE_FLAG_PER_DATASET
) == 0) ||
247 (deps_contains_feature(deps
, SPA_FEATURE_EXTENSIBLE_DATASET
)));
249 feature
->fi_feature
= fid
;
250 feature
->fi_guid
= guid
;
251 feature
->fi_uname
= name
;
252 feature
->fi_desc
= desc
;
253 feature
->fi_flags
= flags
;
254 feature
->fi_type
= type
;
255 feature
->fi_depends
= deps
;
256 feature
->fi_zfs_mod_supported
= zfs_mod_supported_feature(guid
);
260 zpool_feature_init(void)
262 zfeature_register(SPA_FEATURE_ASYNC_DESTROY
,
263 "com.delphix:async_destroy", "async_destroy",
264 "Destroy filesystems asynchronously.",
265 ZFEATURE_FLAG_READONLY_COMPAT
, ZFEATURE_TYPE_BOOLEAN
, NULL
);
267 zfeature_register(SPA_FEATURE_EMPTY_BPOBJ
,
268 "com.delphix:empty_bpobj", "empty_bpobj",
269 "Snapshots use less space.",
270 ZFEATURE_FLAG_READONLY_COMPAT
, ZFEATURE_TYPE_BOOLEAN
, NULL
);
272 zfeature_register(SPA_FEATURE_LZ4_COMPRESS
,
273 "org.illumos:lz4_compress", "lz4_compress",
274 "LZ4 compression algorithm support.",
275 ZFEATURE_FLAG_ACTIVATE_ON_ENABLE
, ZFEATURE_TYPE_BOOLEAN
, NULL
);
277 zfeature_register(SPA_FEATURE_MULTI_VDEV_CRASH_DUMP
,
278 "com.joyent:multi_vdev_crash_dump", "multi_vdev_crash_dump",
279 "Crash dumps to multiple vdev pools.",
280 0, ZFEATURE_TYPE_BOOLEAN
, NULL
);
282 zfeature_register(SPA_FEATURE_SPACEMAP_HISTOGRAM
,
283 "com.delphix:spacemap_histogram", "spacemap_histogram",
284 "Spacemaps maintain space histograms.",
285 ZFEATURE_FLAG_READONLY_COMPAT
, ZFEATURE_TYPE_BOOLEAN
, NULL
);
287 zfeature_register(SPA_FEATURE_ENABLED_TXG
,
288 "com.delphix:enabled_txg", "enabled_txg",
289 "Record txg at which a feature is enabled",
290 ZFEATURE_FLAG_READONLY_COMPAT
, ZFEATURE_TYPE_BOOLEAN
, NULL
);
293 static const spa_feature_t hole_birth_deps
[] = {
294 SPA_FEATURE_ENABLED_TXG
,
297 zfeature_register(SPA_FEATURE_HOLE_BIRTH
,
298 "com.delphix:hole_birth", "hole_birth",
299 "Retain hole birth txg for more precise zfs send",
300 ZFEATURE_FLAG_MOS
| ZFEATURE_FLAG_ACTIVATE_ON_ENABLE
,
301 ZFEATURE_TYPE_BOOLEAN
, hole_birth_deps
);
304 zfeature_register(SPA_FEATURE_POOL_CHECKPOINT
,
305 "com.delphix:zpool_checkpoint", "zpool_checkpoint",
306 "Pool state can be checkpointed, allowing rewind later.",
307 ZFEATURE_FLAG_READONLY_COMPAT
, ZFEATURE_TYPE_BOOLEAN
, NULL
);
309 zfeature_register(SPA_FEATURE_SPACEMAP_V2
,
310 "com.delphix:spacemap_v2", "spacemap_v2",
311 "Space maps representing large segments are more efficient.",
312 ZFEATURE_FLAG_READONLY_COMPAT
| ZFEATURE_FLAG_ACTIVATE_ON_ENABLE
,
313 ZFEATURE_TYPE_BOOLEAN
, NULL
);
315 zfeature_register(SPA_FEATURE_EXTENSIBLE_DATASET
,
316 "com.delphix:extensible_dataset", "extensible_dataset",
317 "Enhanced dataset functionality, used by other features.",
318 0, ZFEATURE_TYPE_BOOLEAN
, NULL
);
321 static const spa_feature_t bookmarks_deps
[] = {
322 SPA_FEATURE_EXTENSIBLE_DATASET
,
326 zfeature_register(SPA_FEATURE_BOOKMARKS
,
327 "com.delphix:bookmarks", "bookmarks",
328 "\"zfs bookmark\" command",
329 ZFEATURE_FLAG_READONLY_COMPAT
, ZFEATURE_TYPE_BOOLEAN
,
334 static const spa_feature_t filesystem_limits_deps
[] = {
335 SPA_FEATURE_EXTENSIBLE_DATASET
,
338 zfeature_register(SPA_FEATURE_FS_SS_LIMIT
,
339 "com.joyent:filesystem_limits", "filesystem_limits",
340 "Filesystem and snapshot limits.",
341 ZFEATURE_FLAG_READONLY_COMPAT
, ZFEATURE_TYPE_BOOLEAN
,
342 filesystem_limits_deps
);
345 zfeature_register(SPA_FEATURE_EMBEDDED_DATA
,
346 "com.delphix:embedded_data", "embedded_data",
347 "Blocks which compress very well use even less space.",
348 ZFEATURE_FLAG_MOS
| ZFEATURE_FLAG_ACTIVATE_ON_ENABLE
,
349 ZFEATURE_TYPE_BOOLEAN
, NULL
);
352 static const spa_feature_t large_blocks_deps
[] = {
353 SPA_FEATURE_EXTENSIBLE_DATASET
,
356 zfeature_register(SPA_FEATURE_LARGE_BLOCKS
,
357 "org.open-zfs:large_blocks", "large_blocks",
358 "Support for blocks larger than 128KB.",
359 ZFEATURE_FLAG_PER_DATASET
, ZFEATURE_TYPE_BOOLEAN
,
364 static const spa_feature_t large_dnode_deps
[] = {
365 SPA_FEATURE_EXTENSIBLE_DATASET
,
368 zfeature_register(SPA_FEATURE_LARGE_DNODE
,
369 "org.zfsonlinux:large_dnode", "large_dnode",
370 "Variable on-disk size of dnodes.",
371 ZFEATURE_FLAG_PER_DATASET
, ZFEATURE_TYPE_BOOLEAN
,
376 static const spa_feature_t sha512_deps
[] = {
377 SPA_FEATURE_EXTENSIBLE_DATASET
,
380 zfeature_register(SPA_FEATURE_SHA512
,
381 "org.illumos:sha512", "sha512",
382 "SHA-512/256 hash algorithm.",
383 ZFEATURE_FLAG_PER_DATASET
, ZFEATURE_TYPE_BOOLEAN
,
388 static const spa_feature_t skein_deps
[] = {
389 SPA_FEATURE_EXTENSIBLE_DATASET
,
392 zfeature_register(SPA_FEATURE_SKEIN
,
393 "org.illumos:skein", "skein",
394 "Skein hash algorithm.",
395 ZFEATURE_FLAG_PER_DATASET
, ZFEATURE_TYPE_BOOLEAN
,
400 static const spa_feature_t edonr_deps
[] = {
401 SPA_FEATURE_EXTENSIBLE_DATASET
,
404 zfeature_register(SPA_FEATURE_EDONR
,
405 "org.illumos:edonr", "edonr",
406 "Edon-R hash algorithm.",
407 ZFEATURE_FLAG_PER_DATASET
, ZFEATURE_TYPE_BOOLEAN
,
411 zfeature_register(SPA_FEATURE_DEVICE_REMOVAL
,
412 "com.delphix:device_removal", "device_removal",
413 "Top-level vdevs can be removed, reducing logical pool size.",
414 ZFEATURE_FLAG_MOS
, ZFEATURE_TYPE_BOOLEAN
, NULL
);
417 static const spa_feature_t obsolete_counts_deps
[] = {
418 SPA_FEATURE_EXTENSIBLE_DATASET
,
419 SPA_FEATURE_DEVICE_REMOVAL
,
422 zfeature_register(SPA_FEATURE_OBSOLETE_COUNTS
,
423 "com.delphix:obsolete_counts", "obsolete_counts",
424 "Reduce memory used by removed devices when their blocks are "
425 "freed or remapped.",
426 ZFEATURE_FLAG_READONLY_COMPAT
, ZFEATURE_TYPE_BOOLEAN
,
427 obsolete_counts_deps
);
431 static const spa_feature_t userobj_accounting_deps
[] = {
432 SPA_FEATURE_EXTENSIBLE_DATASET
,
435 zfeature_register(SPA_FEATURE_USEROBJ_ACCOUNTING
,
436 "org.zfsonlinux:userobj_accounting", "userobj_accounting",
437 "User/Group object accounting.",
438 ZFEATURE_FLAG_READONLY_COMPAT
| ZFEATURE_FLAG_PER_DATASET
,
439 ZFEATURE_TYPE_BOOLEAN
, userobj_accounting_deps
);
443 static const spa_feature_t bookmark_v2_deps
[] = {
444 SPA_FEATURE_EXTENSIBLE_DATASET
,
445 SPA_FEATURE_BOOKMARKS
,
448 zfeature_register(SPA_FEATURE_BOOKMARK_V2
,
449 "com.datto:bookmark_v2", "bookmark_v2",
450 "Support for larger bookmarks",
451 0, ZFEATURE_TYPE_BOOLEAN
, bookmark_v2_deps
);
455 static const spa_feature_t encryption_deps
[] = {
456 SPA_FEATURE_EXTENSIBLE_DATASET
,
457 SPA_FEATURE_BOOKMARK_V2
,
460 zfeature_register(SPA_FEATURE_ENCRYPTION
,
461 "com.datto:encryption", "encryption",
462 "Support for dataset level encryption",
463 ZFEATURE_FLAG_PER_DATASET
, ZFEATURE_TYPE_BOOLEAN
,
468 static const spa_feature_t project_quota_deps
[] = {
469 SPA_FEATURE_EXTENSIBLE_DATASET
,
472 zfeature_register(SPA_FEATURE_PROJECT_QUOTA
,
473 "org.zfsonlinux:project_quota", "project_quota",
474 "space/object accounting based on project ID.",
475 ZFEATURE_FLAG_READONLY_COMPAT
| ZFEATURE_FLAG_PER_DATASET
,
476 ZFEATURE_TYPE_BOOLEAN
, project_quota_deps
);
480 zfeature_register(SPA_FEATURE_ALLOCATION_CLASSES
,
481 "org.zfsonlinux:allocation_classes", "allocation_classes",
482 "Support for separate allocation classes.",
483 ZFEATURE_FLAG_READONLY_COMPAT
, ZFEATURE_TYPE_BOOLEAN
, NULL
);
486 zfeature_register(SPA_FEATURE_RESILVER_DEFER
,
487 "com.datto:resilver_defer", "resilver_defer",
488 "Support for defering new resilvers when one is already running.",
489 ZFEATURE_FLAG_READONLY_COMPAT
, ZFEATURE_TYPE_BOOLEAN
, NULL
);
493 EXPORT_SYMBOL(zfeature_lookup_guid
);
494 EXPORT_SYMBOL(zfeature_lookup_name
);
495 EXPORT_SYMBOL(zfeature_is_supported
);
496 EXPORT_SYMBOL(zfeature_is_valid_guid
);
497 EXPORT_SYMBOL(zfeature_depends_on
);
498 EXPORT_SYMBOL(zpool_feature_init
);
499 EXPORT_SYMBOL(spa_feature_table
);