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, 2017 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.
33 #include <sys/debug.h>
34 #include <sys/fs/zfs.h>
35 #include <sys/inttypes.h>
36 #include <sys/types.h>
37 #include "zfeature_common.h"
40 * Set to disable all feature checks while opening pools, allowing pools with
41 * unsupported features to be opened. Set for testing only.
43 boolean_t zfeature_checks_disable = B_FALSE;
45 zfeature_info_t spa_feature_table[SPA_FEATURES];
48 * Valid characters for feature guids. This list is mainly for aesthetic
49 * purposes and could be expanded in the future. There are different allowed
50 * characters in the guids reverse dns portion (before the colon) and its
51 * short name (after the colon).
54 valid_char(char c, boolean_t after_colon)
56 return ((c >= 'a' && c <= 'z') ||
57 (c >= '0' && c <= '9') ||
58 (after_colon && c == '_') ||
59 (!after_colon && (c == '.' || c == '-')));
63 * Every feature guid must contain exactly one colon which separates a reverse
64 * dns organization name from the feature's "short" name (e.g.
65 * "com.company:feature_name").
68 zfeature_is_valid_guid(const char *name)
71 boolean_t has_colon = B_FALSE;
74 while (name[i] != '\0') {
82 if (!valid_char(c, has_colon))
90 zfeature_is_supported(const char *guid)
92 if (zfeature_checks_disable)
95 for (spa_feature_t i = 0; i < SPA_FEATURES; i++) {
96 zfeature_info_t *feature = &spa_feature_table[i];
97 if (strcmp(guid, feature->fi_guid) == 0)
104 zfeature_lookup_name(const char *name, spa_feature_t *res)
106 for (spa_feature_t i = 0; i < SPA_FEATURES; i++) {
107 zfeature_info_t *feature = &spa_feature_table[i];
108 if (strcmp(name, feature->fi_uname) == 0) {
119 zfeature_depends_on(spa_feature_t fid, spa_feature_t check)
121 zfeature_info_t *feature = &spa_feature_table[fid];
123 for (int i = 0; feature->fi_depends[i] != SPA_FEATURE_NONE; i++) {
124 if (feature->fi_depends[i] == check)
131 deps_contains_feature(const spa_feature_t *deps, const spa_feature_t feature)
133 for (int i = 0; deps[i] != SPA_FEATURE_NONE; i++)
134 if (deps[i] == feature)
141 zfeature_register(spa_feature_t fid, const char *guid, const char *name,
142 const char *desc, zfeature_flags_t flags, const spa_feature_t *deps)
144 zfeature_info_t *feature = &spa_feature_table[fid];
145 static spa_feature_t nodeps[] = { SPA_FEATURE_NONE };
147 ASSERT(name != NULL);
148 ASSERT(desc != NULL);
149 ASSERT((flags & ZFEATURE_FLAG_READONLY_COMPAT) == 0 ||
150 (flags & ZFEATURE_FLAG_MOS) == 0);
151 ASSERT3U(fid, <, SPA_FEATURES);
152 ASSERT(zfeature_is_valid_guid(guid));
157 VERIFY(((flags & ZFEATURE_FLAG_PER_DATASET) == 0) ||
158 (deps_contains_feature(deps, SPA_FEATURE_EXTENSIBLE_DATASET)));
160 feature->fi_feature = fid;
161 feature->fi_guid = guid;
162 feature->fi_uname = name;
163 feature->fi_desc = desc;
164 feature->fi_flags = flags;
165 feature->fi_depends = deps;
169 zpool_feature_init(void)
171 zfeature_register(SPA_FEATURE_ASYNC_DESTROY,
172 "com.delphix:async_destroy", "async_destroy",
173 "Destroy filesystems asynchronously.",
174 ZFEATURE_FLAG_READONLY_COMPAT, NULL);
176 zfeature_register(SPA_FEATURE_EMPTY_BPOBJ,
177 "com.delphix:empty_bpobj", "empty_bpobj",
178 "Snapshots use less space.",
179 ZFEATURE_FLAG_READONLY_COMPAT, NULL);
181 zfeature_register(SPA_FEATURE_LZ4_COMPRESS,
182 "org.illumos:lz4_compress", "lz4_compress",
183 "LZ4 compression algorithm support.",
184 ZFEATURE_FLAG_ACTIVATE_ON_ENABLE, NULL);
186 zfeature_register(SPA_FEATURE_MULTI_VDEV_CRASH_DUMP,
187 "com.joyent:multi_vdev_crash_dump", "multi_vdev_crash_dump",
188 "Crash dumps to multiple vdev pools.",
191 zfeature_register(SPA_FEATURE_SPACEMAP_HISTOGRAM,
192 "com.delphix:spacemap_histogram", "spacemap_histogram",
193 "Spacemaps maintain space histograms.",
194 ZFEATURE_FLAG_READONLY_COMPAT, NULL);
196 zfeature_register(SPA_FEATURE_ENABLED_TXG,
197 "com.delphix:enabled_txg", "enabled_txg",
198 "Record txg at which a feature is enabled",
199 ZFEATURE_FLAG_READONLY_COMPAT, NULL);
202 static const spa_feature_t hole_birth_deps[] = {
203 SPA_FEATURE_ENABLED_TXG,
206 zfeature_register(SPA_FEATURE_HOLE_BIRTH,
207 "com.delphix:hole_birth", "hole_birth",
208 "Retain hole birth txg for more precise zfs send",
209 ZFEATURE_FLAG_MOS | ZFEATURE_FLAG_ACTIVATE_ON_ENABLE,
213 zfeature_register(SPA_FEATURE_POOL_CHECKPOINT,
214 "com.delphix:zpool_checkpoint", "zpool_checkpoint",
215 "Pool state can be checkpointed, allowing rewind later.",
216 ZFEATURE_FLAG_READONLY_COMPAT, NULL);
218 zfeature_register(SPA_FEATURE_EXTENSIBLE_DATASET,
219 "com.delphix:extensible_dataset", "extensible_dataset",
220 "Enhanced dataset functionality, used by other features.",
224 static const spa_feature_t bookmarks_deps[] = {
225 SPA_FEATURE_EXTENSIBLE_DATASET,
229 zfeature_register(SPA_FEATURE_BOOKMARKS,
230 "com.delphix:bookmarks", "bookmarks",
231 "\"zfs bookmark\" command",
232 ZFEATURE_FLAG_READONLY_COMPAT, bookmarks_deps);
236 static const spa_feature_t filesystem_limits_deps[] = {
237 SPA_FEATURE_EXTENSIBLE_DATASET,
240 zfeature_register(SPA_FEATURE_FS_SS_LIMIT,
241 "com.joyent:filesystem_limits", "filesystem_limits",
242 "Filesystem and snapshot limits.",
243 ZFEATURE_FLAG_READONLY_COMPAT, filesystem_limits_deps);
246 zfeature_register(SPA_FEATURE_EMBEDDED_DATA,
247 "com.delphix:embedded_data", "embedded_data",
248 "Blocks which compress very well use even less space.",
249 ZFEATURE_FLAG_MOS | ZFEATURE_FLAG_ACTIVATE_ON_ENABLE,
253 static const spa_feature_t large_blocks_deps[] = {
254 SPA_FEATURE_EXTENSIBLE_DATASET,
257 zfeature_register(SPA_FEATURE_LARGE_BLOCKS,
258 "org.open-zfs:large_blocks", "large_blocks",
259 "Support for blocks larger than 128KB.",
260 ZFEATURE_FLAG_PER_DATASET, large_blocks_deps);
264 static const spa_feature_t large_dnode_deps[] = {
265 SPA_FEATURE_EXTENSIBLE_DATASET,
268 zfeature_register(SPA_FEATURE_LARGE_DNODE,
269 "org.zfsonlinux:large_dnode", "large_dnode",
270 "Variable on-disk size of dnodes.",
271 ZFEATURE_FLAG_PER_DATASET, large_dnode_deps);
275 static const spa_feature_t sha512_deps[] = {
276 SPA_FEATURE_EXTENSIBLE_DATASET,
279 zfeature_register(SPA_FEATURE_SHA512,
280 "org.illumos:sha512", "sha512",
281 "SHA-512/256 hash algorithm.",
282 ZFEATURE_FLAG_PER_DATASET, sha512_deps);
285 static const spa_feature_t skein_deps[] = {
286 SPA_FEATURE_EXTENSIBLE_DATASET,
289 zfeature_register(SPA_FEATURE_SKEIN,
290 "org.illumos:skein", "skein",
291 "Skein hash algorithm.",
292 ZFEATURE_FLAG_PER_DATASET, skein_deps);
296 static const spa_feature_t edonr_deps[] = {
297 SPA_FEATURE_EXTENSIBLE_DATASET,
300 zfeature_register(SPA_FEATURE_EDONR,
301 "org.illumos:edonr", "edonr",
302 "Edon-R hash algorithm.",
303 ZFEATURE_FLAG_PER_DATASET, edonr_deps);
305 zfeature_register(SPA_FEATURE_DEVICE_REMOVAL,
306 "com.delphix:device_removal", "device_removal",
307 "Top-level vdevs can be removed, reducing logical pool size.",
308 ZFEATURE_FLAG_MOS, NULL);
310 static const spa_feature_t obsolete_counts_deps[] = {
311 SPA_FEATURE_EXTENSIBLE_DATASET,
312 SPA_FEATURE_DEVICE_REMOVAL,
315 zfeature_register(SPA_FEATURE_OBSOLETE_COUNTS,
316 "com.delphix:obsolete_counts", "obsolete_counts",
317 "Reduce memory used by removed devices when their blocks are "
318 "freed or remapped.",
319 ZFEATURE_FLAG_READONLY_COMPAT, obsolete_counts_deps);
322 static const spa_feature_t userobj_accounting_deps[] = {
323 SPA_FEATURE_EXTENSIBLE_DATASET,
326 zfeature_register(SPA_FEATURE_USEROBJ_ACCOUNTING,
327 "org.zfsonlinux:userobj_accounting", "userobj_accounting",
328 "User/Group object accounting.",
329 ZFEATURE_FLAG_READONLY_COMPAT | ZFEATURE_FLAG_PER_DATASET,
330 userobj_accounting_deps);
334 static const spa_feature_t encryption_deps[] = {
335 SPA_FEATURE_EXTENSIBLE_DATASET,
338 zfeature_register(SPA_FEATURE_ENCRYPTION,
339 "com.datto:encryption", "encryption",
340 "Support for dataset level encryption",
341 ZFEATURE_FLAG_PER_DATASET, encryption_deps);
345 static const spa_feature_t project_quota_deps[] = {
346 SPA_FEATURE_EXTENSIBLE_DATASET,
349 zfeature_register(SPA_FEATURE_PROJECT_QUOTA,
350 "org.zfsonlinux:project_quota", "project_quota",
351 "space/object accounting based on project ID.",
352 ZFEATURE_FLAG_READONLY_COMPAT | ZFEATURE_FLAG_PER_DATASET,
358 EXPORT_SYMBOL(zfeature_lookup_name);
359 EXPORT_SYMBOL(zfeature_is_supported);
360 EXPORT_SYMBOL(zfeature_is_valid_guid);
361 EXPORT_SYMBOL(zfeature_depends_on);
362 EXPORT_SYMBOL(zpool_feature_init);
363 EXPORT_SYMBOL(spa_feature_table);