153089ab7Seschrock /*
253089ab7Seschrock * CDDL HEADER START
353089ab7Seschrock *
453089ab7Seschrock * The contents of this file are subject to the terms of the
553089ab7Seschrock * Common Development and Distribution License (the "License").
653089ab7Seschrock * You may not use this file except in compliance with the License.
753089ab7Seschrock *
853089ab7Seschrock * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
953089ab7Seschrock * or http://www.opensolaris.org/os/licensing.
1053089ab7Seschrock * See the License for the specific language governing permissions
1153089ab7Seschrock * and limitations under the License.
1253089ab7Seschrock *
1353089ab7Seschrock * When distributing Covered Code, include this CDDL HEADER in each
1453089ab7Seschrock * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1553089ab7Seschrock * If applicable, add the following below this CDDL HEADER, with the
1653089ab7Seschrock * fields enclosed by brackets "[]" replaced with your own identifying
1753089ab7Seschrock * information: Portions Copyright [yyyy] [name of copyright owner]
1853089ab7Seschrock *
1953089ab7Seschrock * CDDL HEADER END
2053089ab7Seschrock */
2153089ab7Seschrock
2253089ab7Seschrock /*
23ca0cc391SMatthew Ahrens * Copyright (c) 2011, 2015 by Delphix. All rights reserved.
24a6f561b4SSašo Kiselkov * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
25810e43b2SBill Pijewski * Copyright (c) 2013, Joyent, Inc. All rights reserved.
26b8289d24SDaniil Lunev * Copyright (c) 2014, Nexenta Systems, Inc. All rights reserved.
27c3d26abcSMatthew Ahrens * Copyright (c) 2014 Integros [integros.com]
2853089ab7Seschrock */
2953089ab7Seschrock
3053089ab7Seschrock #ifdef _KERNEL
3153089ab7Seschrock #include <sys/systm.h>
3253089ab7Seschrock #else
3353089ab7Seschrock #include <errno.h>
3453089ab7Seschrock #include <string.h>
3553089ab7Seschrock #endif
3653089ab7Seschrock #include <sys/debug.h>
3753089ab7Seschrock #include <sys/fs/zfs.h>
3853089ab7Seschrock #include <sys/inttypes.h>
3953089ab7Seschrock #include <sys/types.h>
4053089ab7Seschrock #include "zfeature_common.h"
4153089ab7Seschrock
4253089ab7Seschrock /*
4353089ab7Seschrock * Set to disable all feature checks while opening pools, allowing pools with
4453089ab7Seschrock * unsupported features to be opened. Set for testing only.
4553089ab7Seschrock */
4653089ab7Seschrock boolean_t zfeature_checks_disable = B_FALSE;
4753089ab7Seschrock
4853089ab7Seschrock zfeature_info_t spa_feature_table[SPA_FEATURES];
4953089ab7Seschrock
5053089ab7Seschrock /*
5153089ab7Seschrock * Valid characters for feature guids. This list is mainly for aesthetic
5253089ab7Seschrock * purposes and could be expanded in the future. There are different allowed
5353089ab7Seschrock * characters in the guids reverse dns portion (before the colon) and its
5453089ab7Seschrock * short name (after the colon).
5553089ab7Seschrock */
5653089ab7Seschrock static int
valid_char(char c,boolean_t after_colon)5753089ab7Seschrock valid_char(char c, boolean_t after_colon)
5853089ab7Seschrock {
5953089ab7Seschrock return ((c >= 'a' && c <= 'z') ||
6053089ab7Seschrock (c >= '0' && c <= '9') ||
61b5152584SMatthew Ahrens (after_colon && c == '_') ||
62b5152584SMatthew Ahrens (!after_colon && (c == '.' || c == '-')));
6353089ab7Seschrock }
6453089ab7Seschrock
6553089ab7Seschrock /*
6653089ab7Seschrock * Every feature guid must contain exactly one colon which separates a reverse
6753089ab7Seschrock * dns organization name from the feature's "short" name (e.g.
6853089ab7Seschrock * "com.company:feature_name").
6953089ab7Seschrock */
7053089ab7Seschrock boolean_t
zfeature_is_valid_guid(const char * name)7153089ab7Seschrock zfeature_is_valid_guid(const char *name)
7253089ab7Seschrock {
7353089ab7Seschrock int i;
7453089ab7Seschrock boolean_t has_colon = B_FALSE;
7553089ab7Seschrock
7653089ab7Seschrock i = 0;
7753089ab7Seschrock while (name[i] != '\0') {
7853089ab7Seschrock char c = name[i++];
7953089ab7Seschrock if (c == ':') {
8053089ab7Seschrock if (has_colon)
8153089ab7Seschrock return (B_FALSE);
8253089ab7Seschrock has_colon = B_TRUE;
8353089ab7Seschrock continue;
8453089ab7Seschrock }
8553089ab7Seschrock if (!valid_char(c, has_colon))
8653089ab7Seschrock return (B_FALSE);
8753089ab7Seschrock }
8853089ab7Seschrock
8953089ab7Seschrock return (has_colon);
9053089ab7Seschrock }
9153089ab7Seschrock
9253089ab7Seschrock boolean_t
zfeature_is_supported(const char * guid)9353089ab7Seschrock zfeature_is_supported(const char *guid)
9453089ab7Seschrock {
9553089ab7Seschrock if (zfeature_checks_disable)
9653089ab7Seschrock return (B_TRUE);
9753089ab7Seschrock
982acef22dSMatthew Ahrens for (spa_feature_t i = 0; i < SPA_FEATURES; i++) {
9953089ab7Seschrock zfeature_info_t *feature = &spa_feature_table[i];
1002acef22dSMatthew Ahrens if (strcmp(guid, feature->fi_guid) == 0)
1012acef22dSMatthew Ahrens return (B_TRUE);
10253089ab7Seschrock }
1032acef22dSMatthew Ahrens return (B_FALSE);
10453089ab7Seschrock }
10553089ab7Seschrock
10653089ab7Seschrock int
zfeature_lookup_name(const char * name,spa_feature_t * res)1072acef22dSMatthew Ahrens zfeature_lookup_name(const char *name, spa_feature_t *res)
10853089ab7Seschrock {
1092acef22dSMatthew Ahrens for (spa_feature_t i = 0; i < SPA_FEATURES; i++) {
11053089ab7Seschrock zfeature_info_t *feature = &spa_feature_table[i];
11153089ab7Seschrock if (strcmp(name, feature->fi_uname) == 0) {
11253089ab7Seschrock if (res != NULL)
1132acef22dSMatthew Ahrens *res = i;
11453089ab7Seschrock return (0);
11553089ab7Seschrock }
11653089ab7Seschrock }
11753089ab7Seschrock
11853089ab7Seschrock return (ENOENT);
11953089ab7Seschrock }
12053089ab7Seschrock
12143466aaeSMax Grossman boolean_t
zfeature_depends_on(spa_feature_t fid,spa_feature_t check)1229a686fbcSPaul Dagnelie zfeature_depends_on(spa_feature_t fid, spa_feature_t check)
1239a686fbcSPaul Dagnelie {
12443466aaeSMax Grossman zfeature_info_t *feature = &spa_feature_table[fid];
12543466aaeSMax Grossman
12643466aaeSMax Grossman for (int i = 0; feature->fi_depends[i] != SPA_FEATURE_NONE; i++) {
12743466aaeSMax Grossman if (feature->fi_depends[i] == check)
12843466aaeSMax Grossman return (B_TRUE);
12943466aaeSMax Grossman }
13043466aaeSMax Grossman return (B_FALSE);
13143466aaeSMax Grossman }
13243466aaeSMax Grossman
133*0803e914Silovezfs static boolean_t
deps_contains_feature(const spa_feature_t * deps,const spa_feature_t feature)134*0803e914Silovezfs deps_contains_feature(const spa_feature_t *deps, const spa_feature_t feature)
135*0803e914Silovezfs {
136*0803e914Silovezfs for (int i = 0; deps[i] != SPA_FEATURE_NONE; i++)
137*0803e914Silovezfs if (deps[i] == feature)
138*0803e914Silovezfs return (B_TRUE);
139*0803e914Silovezfs
140*0803e914Silovezfs return (B_FALSE);
141*0803e914Silovezfs }
142*0803e914Silovezfs
14353089ab7Seschrock static void
zfeature_register(spa_feature_t fid,const char * guid,const char * name,const char * desc,zfeature_flags_t flags,const spa_feature_t * deps)1442acef22dSMatthew Ahrens zfeature_register(spa_feature_t fid, const char *guid, const char *name,
145ca0cc391SMatthew Ahrens const char *desc, zfeature_flags_t flags, const spa_feature_t *deps)
14653089ab7Seschrock {
14753089ab7Seschrock zfeature_info_t *feature = &spa_feature_table[fid];
1482acef22dSMatthew Ahrens static spa_feature_t nodeps[] = { SPA_FEATURE_NONE };
14953089ab7Seschrock
15053089ab7Seschrock ASSERT(name != NULL);
15153089ab7Seschrock ASSERT(desc != NULL);
152ca0cc391SMatthew Ahrens ASSERT((flags & ZFEATURE_FLAG_READONLY_COMPAT) == 0 ||
153ca0cc391SMatthew Ahrens (flags & ZFEATURE_FLAG_MOS) == 0);
15453089ab7Seschrock ASSERT3U(fid, <, SPA_FEATURES);
15553089ab7Seschrock ASSERT(zfeature_is_valid_guid(guid));
15653089ab7Seschrock
15753089ab7Seschrock if (deps == NULL)
15853089ab7Seschrock deps = nodeps;
15953089ab7Seschrock
160*0803e914Silovezfs VERIFY(((flags & ZFEATURE_FLAG_PER_DATASET) == 0) ||
161*0803e914Silovezfs (deps_contains_feature(deps, SPA_FEATURE_EXTENSIBLE_DATASET)));
162*0803e914Silovezfs
1632acef22dSMatthew Ahrens feature->fi_feature = fid;
16453089ab7Seschrock feature->fi_guid = guid;
16553089ab7Seschrock feature->fi_uname = name;
16653089ab7Seschrock feature->fi_desc = desc;
167ca0cc391SMatthew Ahrens feature->fi_flags = flags;
16853089ab7Seschrock feature->fi_depends = deps;
16953089ab7Seschrock }
17053089ab7Seschrock
17153089ab7Seschrock void
zpool_feature_init(void)17253089ab7Seschrock zpool_feature_init(void)
17353089ab7Seschrock {
17453089ab7Seschrock zfeature_register(SPA_FEATURE_ASYNC_DESTROY,
17553089ab7Seschrock "com.delphix:async_destroy", "async_destroy",
176ca0cc391SMatthew Ahrens "Destroy filesystems asynchronously.",
177ca0cc391SMatthew Ahrens ZFEATURE_FLAG_READONLY_COMPAT, NULL);
17843466aaeSMax Grossman
179f1745736SMatthew Ahrens zfeature_register(SPA_FEATURE_EMPTY_BPOBJ,
180f1745736SMatthew Ahrens "com.delphix:empty_bpobj", "empty_bpobj",
181ca0cc391SMatthew Ahrens "Snapshots use less space.",
182ca0cc391SMatthew Ahrens ZFEATURE_FLAG_READONLY_COMPAT, NULL);
18343466aaeSMax Grossman
184a6f561b4SSašo Kiselkov zfeature_register(SPA_FEATURE_LZ4_COMPRESS,
185a6f561b4SSašo Kiselkov "org.illumos:lz4_compress", "lz4_compress",
186ca0cc391SMatthew Ahrens "LZ4 compression algorithm support.",
187ca0cc391SMatthew Ahrens ZFEATURE_FLAG_ACTIVATE_ON_ENABLE, NULL);
18843466aaeSMax Grossman
189810e43b2SBill Pijewski zfeature_register(SPA_FEATURE_MULTI_VDEV_CRASH_DUMP,
190810e43b2SBill Pijewski "com.joyent:multi_vdev_crash_dump", "multi_vdev_crash_dump",
191ca0cc391SMatthew Ahrens "Crash dumps to multiple vdev pools.",
192ca0cc391SMatthew Ahrens 0, NULL);
19343466aaeSMax Grossman
1940713e232SGeorge Wilson zfeature_register(SPA_FEATURE_SPACEMAP_HISTOGRAM,
1950713e232SGeorge Wilson "com.delphix:spacemap_histogram", "spacemap_histogram",
196ca0cc391SMatthew Ahrens "Spacemaps maintain space histograms.",
197ca0cc391SMatthew Ahrens ZFEATURE_FLAG_READONLY_COMPAT, NULL);
19843466aaeSMax Grossman
19943466aaeSMax Grossman zfeature_register(SPA_FEATURE_ENABLED_TXG,
20043466aaeSMax Grossman "com.delphix:enabled_txg", "enabled_txg",
201ca0cc391SMatthew Ahrens "Record txg at which a feature is enabled",
202ca0cc391SMatthew Ahrens ZFEATURE_FLAG_READONLY_COMPAT, NULL);
20343466aaeSMax Grossman
20422b6687eSilovezfs static spa_feature_t hole_birth_deps[] = {
20522b6687eSilovezfs SPA_FEATURE_ENABLED_TXG,
20622b6687eSilovezfs SPA_FEATURE_NONE
20722b6687eSilovezfs };
20843466aaeSMax Grossman zfeature_register(SPA_FEATURE_HOLE_BIRTH,
20943466aaeSMax Grossman "com.delphix:hole_birth", "hole_birth",
21043466aaeSMax Grossman "Retain hole birth txg for more precise zfs send",
211ca0cc391SMatthew Ahrens ZFEATURE_FLAG_MOS | ZFEATURE_FLAG_ACTIVATE_ON_ENABLE,
212ca0cc391SMatthew Ahrens hole_birth_deps);
21343466aaeSMax Grossman
2142acef22dSMatthew Ahrens zfeature_register(SPA_FEATURE_EXTENSIBLE_DATASET,
2152acef22dSMatthew Ahrens "com.delphix:extensible_dataset", "extensible_dataset",
2162acef22dSMatthew Ahrens "Enhanced dataset functionality, used by other features.",
217ca0cc391SMatthew Ahrens 0, NULL);
21878f17100SMatthew Ahrens
21978f17100SMatthew Ahrens static const spa_feature_t bookmarks_deps[] = {
22078f17100SMatthew Ahrens SPA_FEATURE_EXTENSIBLE_DATASET,
22178f17100SMatthew Ahrens SPA_FEATURE_NONE
22278f17100SMatthew Ahrens };
22378f17100SMatthew Ahrens zfeature_register(SPA_FEATURE_BOOKMARKS,
22478f17100SMatthew Ahrens "com.delphix:bookmarks", "bookmarks",
22578f17100SMatthew Ahrens "\"zfs bookmark\" command",
226ca0cc391SMatthew Ahrens ZFEATURE_FLAG_READONLY_COMPAT, bookmarks_deps);
227a2afb611SJerry Jelinek
228a2afb611SJerry Jelinek static const spa_feature_t filesystem_limits_deps[] = {
229a2afb611SJerry Jelinek SPA_FEATURE_EXTENSIBLE_DATASET,
230a2afb611SJerry Jelinek SPA_FEATURE_NONE
231a2afb611SJerry Jelinek };
232a2afb611SJerry Jelinek zfeature_register(SPA_FEATURE_FS_SS_LIMIT,
233a2afb611SJerry Jelinek "com.joyent:filesystem_limits", "filesystem_limits",
234ca0cc391SMatthew Ahrens "Filesystem and snapshot limits.",
235ca0cc391SMatthew Ahrens ZFEATURE_FLAG_READONLY_COMPAT, filesystem_limits_deps);
2365d7b4d43SMatthew Ahrens
2375d7b4d43SMatthew Ahrens zfeature_register(SPA_FEATURE_EMBEDDED_DATA,
2385d7b4d43SMatthew Ahrens "com.delphix:embedded_data", "embedded_data",
2395d7b4d43SMatthew Ahrens "Blocks which compress very well use even less space.",
240ca0cc391SMatthew Ahrens ZFEATURE_FLAG_MOS | ZFEATURE_FLAG_ACTIVATE_ON_ENABLE,
241ca0cc391SMatthew Ahrens NULL);
242b5152584SMatthew Ahrens
243b5152584SMatthew Ahrens static const spa_feature_t large_blocks_deps[] = {
244b5152584SMatthew Ahrens SPA_FEATURE_EXTENSIBLE_DATASET,
245b5152584SMatthew Ahrens SPA_FEATURE_NONE
246b5152584SMatthew Ahrens };
247b5152584SMatthew Ahrens zfeature_register(SPA_FEATURE_LARGE_BLOCKS,
248b5152584SMatthew Ahrens "org.open-zfs:large_blocks", "large_blocks",
249ca0cc391SMatthew Ahrens "Support for blocks larger than 128KB.",
250ca0cc391SMatthew Ahrens ZFEATURE_FLAG_PER_DATASET, large_blocks_deps);
25145818ee1SMatthew Ahrens
252892586e8Silovezfs static const spa_feature_t sha512_deps[] = {
253892586e8Silovezfs SPA_FEATURE_EXTENSIBLE_DATASET,
254892586e8Silovezfs SPA_FEATURE_NONE
255892586e8Silovezfs };
25645818ee1SMatthew Ahrens zfeature_register(SPA_FEATURE_SHA512,
25745818ee1SMatthew Ahrens "org.illumos:sha512", "sha512",
25845818ee1SMatthew Ahrens "SHA-512/256 hash algorithm.",
259892586e8Silovezfs ZFEATURE_FLAG_PER_DATASET, sha512_deps);
260892586e8Silovezfs
261892586e8Silovezfs static const spa_feature_t skein_deps[] = {
262892586e8Silovezfs SPA_FEATURE_EXTENSIBLE_DATASET,
263892586e8Silovezfs SPA_FEATURE_NONE
264892586e8Silovezfs };
26545818ee1SMatthew Ahrens zfeature_register(SPA_FEATURE_SKEIN,
26645818ee1SMatthew Ahrens "org.illumos:skein", "skein",
26745818ee1SMatthew Ahrens "Skein hash algorithm.",
268892586e8Silovezfs ZFEATURE_FLAG_PER_DATASET, skein_deps);
269892586e8Silovezfs
270892586e8Silovezfs static const spa_feature_t edonr_deps[] = {
271892586e8Silovezfs SPA_FEATURE_EXTENSIBLE_DATASET,
272892586e8Silovezfs SPA_FEATURE_NONE
273892586e8Silovezfs };
27445818ee1SMatthew Ahrens zfeature_register(SPA_FEATURE_EDONR,
27545818ee1SMatthew Ahrens "org.illumos:edonr", "edonr",
27645818ee1SMatthew Ahrens "Edon-R hash algorithm.",
277892586e8Silovezfs ZFEATURE_FLAG_PER_DATASET, edonr_deps);
27853089ab7Seschrock }
279