]> granicus.if.org Git - zfs/blob - module/zcommon/zfeature_common.c
OpenZFS 9166 - zfs storage pool checkpoint
[zfs] / module / zcommon / zfeature_common.c
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21
22 /*
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.
27  */
28
29 #ifndef _KERNEL
30 #include <errno.h>
31 #include <string.h>
32 #endif
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"
38
39 /*
40  * Set to disable all feature checks while opening pools, allowing pools with
41  * unsupported features to be opened. Set for testing only.
42  */
43 boolean_t zfeature_checks_disable = B_FALSE;
44
45 zfeature_info_t spa_feature_table[SPA_FEATURES];
46
47 /*
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).
52  */
53 static int
54 valid_char(char c, boolean_t after_colon)
55 {
56         return ((c >= 'a' && c <= 'z') ||
57             (c >= '0' && c <= '9') ||
58             (after_colon && c == '_') ||
59             (!after_colon && (c == '.' || c == '-')));
60 }
61
62 /*
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").
66  */
67 boolean_t
68 zfeature_is_valid_guid(const char *name)
69 {
70         int i;
71         boolean_t has_colon = B_FALSE;
72
73         i = 0;
74         while (name[i] != '\0') {
75                 char c = name[i++];
76                 if (c == ':') {
77                         if (has_colon)
78                                 return (B_FALSE);
79                         has_colon = B_TRUE;
80                         continue;
81                 }
82                 if (!valid_char(c, has_colon))
83                         return (B_FALSE);
84         }
85
86         return (has_colon);
87 }
88
89 boolean_t
90 zfeature_is_supported(const char *guid)
91 {
92         if (zfeature_checks_disable)
93                 return (B_TRUE);
94
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)
98                         return (B_TRUE);
99         }
100         return (B_FALSE);
101 }
102
103 int
104 zfeature_lookup_name(const char *name, spa_feature_t *res)
105 {
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) {
109                         if (res != NULL)
110                                 *res = i;
111                         return (0);
112                 }
113         }
114
115         return (ENOENT);
116 }
117
118 boolean_t
119 zfeature_depends_on(spa_feature_t fid, spa_feature_t check)
120 {
121         zfeature_info_t *feature = &spa_feature_table[fid];
122
123         for (int i = 0; feature->fi_depends[i] != SPA_FEATURE_NONE; i++) {
124                 if (feature->fi_depends[i] == check)
125                         return (B_TRUE);
126         }
127         return (B_FALSE);
128 }
129
130 static boolean_t
131 deps_contains_feature(const spa_feature_t *deps, const spa_feature_t feature)
132 {
133         for (int i = 0; deps[i] != SPA_FEATURE_NONE; i++)
134                 if (deps[i] == feature)
135                         return (B_TRUE);
136
137         return (B_FALSE);
138 }
139
140 static void
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)
143 {
144         zfeature_info_t *feature = &spa_feature_table[fid];
145         static spa_feature_t nodeps[] = { SPA_FEATURE_NONE };
146
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));
153
154         if (deps == NULL)
155                 deps = nodeps;
156
157         VERIFY(((flags & ZFEATURE_FLAG_PER_DATASET) == 0) ||
158             (deps_contains_feature(deps, SPA_FEATURE_EXTENSIBLE_DATASET)));
159
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;
166 }
167
168 void
169 zpool_feature_init(void)
170 {
171         zfeature_register(SPA_FEATURE_ASYNC_DESTROY,
172             "com.delphix:async_destroy", "async_destroy",
173             "Destroy filesystems asynchronously.",
174             ZFEATURE_FLAG_READONLY_COMPAT, NULL);
175
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);
180
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);
185
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.",
189             0, NULL);
190
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);
195
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);
200
201         {
202         static const spa_feature_t hole_birth_deps[] = {
203                 SPA_FEATURE_ENABLED_TXG,
204                 SPA_FEATURE_NONE
205         };
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,
210             hole_birth_deps);
211         }
212
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);
217
218         zfeature_register(SPA_FEATURE_EXTENSIBLE_DATASET,
219             "com.delphix:extensible_dataset", "extensible_dataset",
220             "Enhanced dataset functionality, used by other features.",
221             0, NULL);
222
223         {
224         static const spa_feature_t bookmarks_deps[] = {
225                 SPA_FEATURE_EXTENSIBLE_DATASET,
226                 SPA_FEATURE_NONE
227         };
228
229         zfeature_register(SPA_FEATURE_BOOKMARKS,
230             "com.delphix:bookmarks", "bookmarks",
231             "\"zfs bookmark\" command",
232             ZFEATURE_FLAG_READONLY_COMPAT, bookmarks_deps);
233         }
234
235         {
236         static const spa_feature_t filesystem_limits_deps[] = {
237                 SPA_FEATURE_EXTENSIBLE_DATASET,
238                 SPA_FEATURE_NONE
239         };
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);
244         }
245
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,
250             NULL);
251
252         {
253         static const spa_feature_t large_blocks_deps[] = {
254                 SPA_FEATURE_EXTENSIBLE_DATASET,
255                 SPA_FEATURE_NONE
256         };
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);
261         }
262
263         {
264         static const spa_feature_t large_dnode_deps[] = {
265                 SPA_FEATURE_EXTENSIBLE_DATASET,
266                 SPA_FEATURE_NONE
267         };
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);
272         }
273
274         {
275         static const spa_feature_t sha512_deps[] = {
276                 SPA_FEATURE_EXTENSIBLE_DATASET,
277                 SPA_FEATURE_NONE
278         };
279         zfeature_register(SPA_FEATURE_SHA512,
280             "org.illumos:sha512", "sha512",
281             "SHA-512/256 hash algorithm.",
282             ZFEATURE_FLAG_PER_DATASET, sha512_deps);
283         }
284         {
285         static const spa_feature_t skein_deps[] = {
286                 SPA_FEATURE_EXTENSIBLE_DATASET,
287                 SPA_FEATURE_NONE
288         };
289         zfeature_register(SPA_FEATURE_SKEIN,
290             "org.illumos:skein", "skein",
291             "Skein hash algorithm.",
292             ZFEATURE_FLAG_PER_DATASET, skein_deps);
293         }
294
295         {
296         static const spa_feature_t edonr_deps[] = {
297                 SPA_FEATURE_EXTENSIBLE_DATASET,
298                 SPA_FEATURE_NONE
299         };
300         zfeature_register(SPA_FEATURE_EDONR,
301             "org.illumos:edonr", "edonr",
302             "Edon-R hash algorithm.",
303             ZFEATURE_FLAG_PER_DATASET, edonr_deps);
304         }
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);
309         {
310         static const spa_feature_t obsolete_counts_deps[] = {
311                 SPA_FEATURE_EXTENSIBLE_DATASET,
312                 SPA_FEATURE_DEVICE_REMOVAL,
313                 SPA_FEATURE_NONE
314         };
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);
320         }
321         {
322         static const spa_feature_t userobj_accounting_deps[] = {
323                 SPA_FEATURE_EXTENSIBLE_DATASET,
324                 SPA_FEATURE_NONE
325         };
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);
331         }
332
333         {
334         static const spa_feature_t encryption_deps[] = {
335                 SPA_FEATURE_EXTENSIBLE_DATASET,
336                 SPA_FEATURE_NONE
337         };
338         zfeature_register(SPA_FEATURE_ENCRYPTION,
339             "com.datto:encryption", "encryption",
340             "Support for dataset level encryption",
341             ZFEATURE_FLAG_PER_DATASET, encryption_deps);
342         }
343
344         {
345         static const spa_feature_t project_quota_deps[] = {
346                 SPA_FEATURE_EXTENSIBLE_DATASET,
347                 SPA_FEATURE_NONE
348         };
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,
353             project_quota_deps);
354         }
355 }
356
357 #if defined(_KERNEL)
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);
364 #endif