xref: /titanic_52/usr/src/common/zfs/zfeature_common.c (revision b8289d24d866c1af02d7007348f7f057693c15d3)
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 /*
230713e232SGeorge Wilson  * Copyright (c) 2013 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.
26*b8289d24SDaniil Lunev  * Copyright (c) 2014, Nexenta Systems, Inc. All rights reserved.
2753089ab7Seschrock  */
2853089ab7Seschrock 
2953089ab7Seschrock #ifdef _KERNEL
3053089ab7Seschrock #include <sys/systm.h>
3153089ab7Seschrock #else
3253089ab7Seschrock #include <errno.h>
3353089ab7Seschrock #include <string.h>
3453089ab7Seschrock #endif
3553089ab7Seschrock #include <sys/debug.h>
3653089ab7Seschrock #include <sys/fs/zfs.h>
3753089ab7Seschrock #include <sys/inttypes.h>
3853089ab7Seschrock #include <sys/types.h>
3953089ab7Seschrock #include "zfeature_common.h"
4053089ab7Seschrock 
4153089ab7Seschrock /*
4253089ab7Seschrock  * Set to disable all feature checks while opening pools, allowing pools with
4353089ab7Seschrock  * unsupported features to be opened. Set for testing only.
4453089ab7Seschrock  */
4553089ab7Seschrock boolean_t zfeature_checks_disable = B_FALSE;
4653089ab7Seschrock 
4753089ab7Seschrock zfeature_info_t spa_feature_table[SPA_FEATURES];
4853089ab7Seschrock 
4953089ab7Seschrock /*
5053089ab7Seschrock  * Valid characters for feature guids. This list is mainly for aesthetic
5153089ab7Seschrock  * purposes and could be expanded in the future. There are different allowed
5253089ab7Seschrock  * characters in the guids reverse dns portion (before the colon) and its
5353089ab7Seschrock  * short name (after the colon).
5453089ab7Seschrock  */
5553089ab7Seschrock static int
5653089ab7Seschrock valid_char(char c, boolean_t after_colon)
5753089ab7Seschrock {
5853089ab7Seschrock 	return ((c >= 'a' && c <= 'z') ||
5953089ab7Seschrock 	    (c >= '0' && c <= '9') ||
6053089ab7Seschrock 	    c == (after_colon ? '_' : '.'));
6153089ab7Seschrock }
6253089ab7Seschrock 
6353089ab7Seschrock /*
6453089ab7Seschrock  * Every feature guid must contain exactly one colon which separates a reverse
6553089ab7Seschrock  * dns organization name from the feature's "short" name (e.g.
6653089ab7Seschrock  * "com.company:feature_name").
6753089ab7Seschrock  */
6853089ab7Seschrock boolean_t
6953089ab7Seschrock zfeature_is_valid_guid(const char *name)
7053089ab7Seschrock {
7153089ab7Seschrock 	int i;
7253089ab7Seschrock 	boolean_t has_colon = B_FALSE;
7353089ab7Seschrock 
7453089ab7Seschrock 	i = 0;
7553089ab7Seschrock 	while (name[i] != '\0') {
7653089ab7Seschrock 		char c = name[i++];
7753089ab7Seschrock 		if (c == ':') {
7853089ab7Seschrock 			if (has_colon)
7953089ab7Seschrock 				return (B_FALSE);
8053089ab7Seschrock 			has_colon = B_TRUE;
8153089ab7Seschrock 			continue;
8253089ab7Seschrock 		}
8353089ab7Seschrock 		if (!valid_char(c, has_colon))
8453089ab7Seschrock 			return (B_FALSE);
8553089ab7Seschrock 	}
8653089ab7Seschrock 
8753089ab7Seschrock 	return (has_colon);
8853089ab7Seschrock }
8953089ab7Seschrock 
9053089ab7Seschrock boolean_t
9153089ab7Seschrock zfeature_is_supported(const char *guid)
9253089ab7Seschrock {
9353089ab7Seschrock 	if (zfeature_checks_disable)
9453089ab7Seschrock 		return (B_TRUE);
9553089ab7Seschrock 
962acef22dSMatthew Ahrens 	for (spa_feature_t i = 0; i < SPA_FEATURES; i++) {
9753089ab7Seschrock 		zfeature_info_t *feature = &spa_feature_table[i];
982acef22dSMatthew Ahrens 		if (strcmp(guid, feature->fi_guid) == 0)
992acef22dSMatthew Ahrens 			return (B_TRUE);
10053089ab7Seschrock 	}
1012acef22dSMatthew Ahrens 	return (B_FALSE);
10253089ab7Seschrock }
10353089ab7Seschrock 
10453089ab7Seschrock int
1052acef22dSMatthew Ahrens zfeature_lookup_name(const char *name, spa_feature_t *res)
10653089ab7Seschrock {
1072acef22dSMatthew Ahrens 	for (spa_feature_t i = 0; i < SPA_FEATURES; i++) {
10853089ab7Seschrock 		zfeature_info_t *feature = &spa_feature_table[i];
10953089ab7Seschrock 		if (strcmp(name, feature->fi_uname) == 0) {
11053089ab7Seschrock 			if (res != NULL)
1112acef22dSMatthew Ahrens 				*res = i;
11253089ab7Seschrock 			return (0);
11353089ab7Seschrock 		}
11453089ab7Seschrock 	}
11553089ab7Seschrock 
11653089ab7Seschrock 	return (ENOENT);
11753089ab7Seschrock }
11853089ab7Seschrock 
11943466aaeSMax Grossman boolean_t
12043466aaeSMax Grossman zfeature_depends_on(spa_feature_t fid, spa_feature_t check) {
12143466aaeSMax Grossman 	zfeature_info_t *feature = &spa_feature_table[fid];
12243466aaeSMax Grossman 
12343466aaeSMax Grossman 	for (int i = 0; feature->fi_depends[i] != SPA_FEATURE_NONE; i++) {
12443466aaeSMax Grossman 		if (feature->fi_depends[i] == check)
12543466aaeSMax Grossman 			return (B_TRUE);
12643466aaeSMax Grossman 	}
12743466aaeSMax Grossman 	return (B_FALSE);
12843466aaeSMax Grossman }
12943466aaeSMax Grossman 
13053089ab7Seschrock static void
1312acef22dSMatthew Ahrens zfeature_register(spa_feature_t fid, const char *guid, const char *name,
1322acef22dSMatthew Ahrens     const char *desc, boolean_t readonly, boolean_t mos,
13343466aaeSMax Grossman     boolean_t activate_on_enable, const spa_feature_t *deps)
13453089ab7Seschrock {
13553089ab7Seschrock 	zfeature_info_t *feature = &spa_feature_table[fid];
1362acef22dSMatthew Ahrens 	static spa_feature_t nodeps[] = { SPA_FEATURE_NONE };
13753089ab7Seschrock 
13853089ab7Seschrock 	ASSERT(name != NULL);
13953089ab7Seschrock 	ASSERT(desc != NULL);
14053089ab7Seschrock 	ASSERT(!readonly || !mos);
14153089ab7Seschrock 	ASSERT3U(fid, <, SPA_FEATURES);
14253089ab7Seschrock 	ASSERT(zfeature_is_valid_guid(guid));
14353089ab7Seschrock 
14453089ab7Seschrock 	if (deps == NULL)
14553089ab7Seschrock 		deps = nodeps;
14653089ab7Seschrock 
1472acef22dSMatthew Ahrens 	feature->fi_feature = fid;
14853089ab7Seschrock 	feature->fi_guid = guid;
14953089ab7Seschrock 	feature->fi_uname = name;
15053089ab7Seschrock 	feature->fi_desc = desc;
15153089ab7Seschrock 	feature->fi_can_readonly = readonly;
15253089ab7Seschrock 	feature->fi_mos = mos;
15343466aaeSMax Grossman 	feature->fi_activate_on_enable = activate_on_enable;
15453089ab7Seschrock 	feature->fi_depends = deps;
15553089ab7Seschrock }
15653089ab7Seschrock 
15753089ab7Seschrock void
15853089ab7Seschrock zpool_feature_init(void)
15953089ab7Seschrock {
16053089ab7Seschrock 	zfeature_register(SPA_FEATURE_ASYNC_DESTROY,
16153089ab7Seschrock 	    "com.delphix:async_destroy", "async_destroy",
16243466aaeSMax Grossman 	    "Destroy filesystems asynchronously.", B_TRUE, B_FALSE,
16343466aaeSMax Grossman 	    B_FALSE, NULL);
16443466aaeSMax Grossman 
165f1745736SMatthew Ahrens 	zfeature_register(SPA_FEATURE_EMPTY_BPOBJ,
166f1745736SMatthew Ahrens 	    "com.delphix:empty_bpobj", "empty_bpobj",
16743466aaeSMax Grossman 	    "Snapshots use less space.", B_TRUE, B_FALSE,
16843466aaeSMax Grossman 	    B_FALSE, NULL);
16943466aaeSMax Grossman 
170a6f561b4SSašo Kiselkov 	zfeature_register(SPA_FEATURE_LZ4_COMPRESS,
171a6f561b4SSašo Kiselkov 	    "org.illumos:lz4_compress", "lz4_compress",
17243466aaeSMax Grossman 	    "LZ4 compression algorithm support.", B_FALSE, B_FALSE,
173*b8289d24SDaniil Lunev 	    B_TRUE, NULL);
17443466aaeSMax Grossman 
175810e43b2SBill Pijewski 	zfeature_register(SPA_FEATURE_MULTI_VDEV_CRASH_DUMP,
176810e43b2SBill Pijewski 	    "com.joyent:multi_vdev_crash_dump", "multi_vdev_crash_dump",
17743466aaeSMax Grossman 	    "Crash dumps to multiple vdev pools.", B_FALSE, B_FALSE,
17843466aaeSMax Grossman 	    B_FALSE, NULL);
17943466aaeSMax Grossman 
1800713e232SGeorge Wilson 	zfeature_register(SPA_FEATURE_SPACEMAP_HISTOGRAM,
1810713e232SGeorge Wilson 	    "com.delphix:spacemap_histogram", "spacemap_histogram",
18243466aaeSMax Grossman 	    "Spacemaps maintain space histograms.", B_TRUE, B_FALSE,
18343466aaeSMax Grossman 	    B_FALSE, NULL);
18443466aaeSMax Grossman 
18543466aaeSMax Grossman 	zfeature_register(SPA_FEATURE_ENABLED_TXG,
18643466aaeSMax Grossman 	    "com.delphix:enabled_txg", "enabled_txg",
18743466aaeSMax Grossman 	    "Record txg at which a feature is enabled", B_TRUE, B_FALSE,
18843466aaeSMax Grossman 	    B_FALSE, NULL);
18943466aaeSMax Grossman 
19043466aaeSMax Grossman 	static spa_feature_t hole_birth_deps[] = { SPA_FEATURE_ENABLED_TXG,
19143466aaeSMax Grossman 	    SPA_FEATURE_NONE };
19243466aaeSMax Grossman 	zfeature_register(SPA_FEATURE_HOLE_BIRTH,
19343466aaeSMax Grossman 	    "com.delphix:hole_birth", "hole_birth",
19443466aaeSMax Grossman 	    "Retain hole birth txg for more precise zfs send",
19543466aaeSMax Grossman 	    B_FALSE, B_TRUE, B_TRUE, hole_birth_deps);
19643466aaeSMax Grossman 
1972acef22dSMatthew Ahrens 	zfeature_register(SPA_FEATURE_EXTENSIBLE_DATASET,
1982acef22dSMatthew Ahrens 	    "com.delphix:extensible_dataset", "extensible_dataset",
1992acef22dSMatthew Ahrens 	    "Enhanced dataset functionality, used by other features.",
20043466aaeSMax Grossman 	    B_FALSE, B_FALSE, B_FALSE, NULL);
20178f17100SMatthew Ahrens 
20278f17100SMatthew Ahrens 	static const spa_feature_t bookmarks_deps[] = {
20378f17100SMatthew Ahrens 		SPA_FEATURE_EXTENSIBLE_DATASET,
20478f17100SMatthew Ahrens 		SPA_FEATURE_NONE
20578f17100SMatthew Ahrens 	};
20678f17100SMatthew Ahrens 	zfeature_register(SPA_FEATURE_BOOKMARKS,
20778f17100SMatthew Ahrens 	    "com.delphix:bookmarks", "bookmarks",
20878f17100SMatthew Ahrens 	    "\"zfs bookmark\" command",
20978f17100SMatthew Ahrens 	    B_TRUE, B_FALSE, B_FALSE, bookmarks_deps);
210a2afb611SJerry Jelinek 
211a2afb611SJerry Jelinek 	static const spa_feature_t filesystem_limits_deps[] = {
212a2afb611SJerry Jelinek 	    SPA_FEATURE_EXTENSIBLE_DATASET,
213a2afb611SJerry Jelinek 	    SPA_FEATURE_NONE
214a2afb611SJerry Jelinek 	};
215a2afb611SJerry Jelinek 	zfeature_register(SPA_FEATURE_FS_SS_LIMIT,
216a2afb611SJerry Jelinek 	    "com.joyent:filesystem_limits", "filesystem_limits",
217a2afb611SJerry Jelinek 	    "Filesystem and snapshot limits.", B_TRUE, B_FALSE, B_FALSE,
218a2afb611SJerry Jelinek 	    filesystem_limits_deps);
2195d7b4d43SMatthew Ahrens 
2205d7b4d43SMatthew Ahrens 	zfeature_register(SPA_FEATURE_EMBEDDED_DATA,
2215d7b4d43SMatthew Ahrens 	    "com.delphix:embedded_data", "embedded_data",
2225d7b4d43SMatthew Ahrens 	    "Blocks which compress very well use even less space.",
2235d7b4d43SMatthew Ahrens 	    B_FALSE, B_TRUE, B_TRUE, NULL);
22453089ab7Seschrock }
225