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, 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) 2014 Integros [integros.com] 28 * Copyright (c) 2017, Intel Corporation. 29 */ 30 31 #ifdef _KERNEL 32 #include <sys/systm.h> 33 #else 34 #include <errno.h> 35 #include <string.h> 36 #endif 37 #include <sys/debug.h> 38 #include <sys/fs/zfs.h> 39 #include <sys/inttypes.h> 40 #include <sys/types.h> 41 #include "zfeature_common.h" 42 43 /* 44 * Set to disable all feature checks while opening pools, allowing pools with 45 * unsupported features to be opened. Set for testing only. 46 */ 47 boolean_t zfeature_checks_disable = B_FALSE; 48 49 zfeature_info_t spa_feature_table[SPA_FEATURES]; 50 51 /* 52 * Valid characters for feature guids. This list is mainly for aesthetic 53 * purposes and could be expanded in the future. There are different allowed 54 * characters in the guids reverse dns portion (before the colon) and its 55 * short name (after the colon). 56 */ 57 static int 58 valid_char(char c, boolean_t after_colon) 59 { 60 return ((c >= 'a' && c <= 'z') || 61 (c >= '0' && c <= '9') || 62 (after_colon && c == '_') || 63 (!after_colon && (c == '.' || c == '-'))); 64 } 65 66 /* 67 * Every feature guid must contain exactly one colon which separates a reverse 68 * dns organization name from the feature's "short" name (e.g. 69 * "com.company:feature_name"). 70 */ 71 boolean_t 72 zfeature_is_valid_guid(const char *name) 73 { 74 int i; 75 boolean_t has_colon = B_FALSE; 76 77 i = 0; 78 while (name[i] != '\0') { 79 char c = name[i++]; 80 if (c == ':') { 81 if (has_colon) 82 return (B_FALSE); 83 has_colon = B_TRUE; 84 continue; 85 } 86 if (!valid_char(c, has_colon)) 87 return (B_FALSE); 88 } 89 90 return (has_colon); 91 } 92 93 boolean_t 94 zfeature_is_supported(const char *guid) 95 { 96 if (zfeature_checks_disable) 97 return (B_TRUE); 98 99 for (spa_feature_t i = 0; i < SPA_FEATURES; i++) { 100 zfeature_info_t *feature = &spa_feature_table[i]; 101 if (strcmp(guid, feature->fi_guid) == 0) 102 return (B_TRUE); 103 } 104 return (B_FALSE); 105 } 106 107 int 108 zfeature_lookup_name(const char *name, spa_feature_t *res) 109 { 110 for (spa_feature_t i = 0; i < SPA_FEATURES; i++) { 111 zfeature_info_t *feature = &spa_feature_table[i]; 112 if (strcmp(name, feature->fi_uname) == 0) { 113 if (res != NULL) 114 *res = i; 115 return (0); 116 } 117 } 118 119 return (ENOENT); 120 } 121 122 boolean_t 123 zfeature_depends_on(spa_feature_t fid, spa_feature_t check) 124 { 125 zfeature_info_t *feature = &spa_feature_table[fid]; 126 127 for (int i = 0; feature->fi_depends[i] != SPA_FEATURE_NONE; i++) { 128 if (feature->fi_depends[i] == check) 129 return (B_TRUE); 130 } 131 return (B_FALSE); 132 } 133 134 static boolean_t 135 deps_contains_feature(const spa_feature_t *deps, const spa_feature_t feature) 136 { 137 for (int i = 0; deps[i] != SPA_FEATURE_NONE; i++) 138 if (deps[i] == feature) 139 return (B_TRUE); 140 141 return (B_FALSE); 142 } 143 144 static void 145 zfeature_register(spa_feature_t fid, const char *guid, const char *name, 146 const char *desc, zfeature_flags_t flags, zfeature_type_t type, 147 const spa_feature_t *deps) 148 { 149 zfeature_info_t *feature = &spa_feature_table[fid]; 150 static spa_feature_t nodeps[] = { SPA_FEATURE_NONE }; 151 152 ASSERT(name != NULL); 153 ASSERT(desc != NULL); 154 ASSERT((flags & ZFEATURE_FLAG_READONLY_COMPAT) == 0 || 155 (flags & ZFEATURE_FLAG_MOS) == 0); 156 ASSERT3U(fid, <, SPA_FEATURES); 157 ASSERT(zfeature_is_valid_guid(guid)); 158 159 if (deps == NULL) 160 deps = nodeps; 161 162 VERIFY(((flags & ZFEATURE_FLAG_PER_DATASET) == 0) || 163 (deps_contains_feature(deps, SPA_FEATURE_EXTENSIBLE_DATASET))); 164 165 feature->fi_feature = fid; 166 feature->fi_guid = guid; 167 feature->fi_uname = name; 168 feature->fi_desc = desc; 169 feature->fi_flags = flags; 170 feature->fi_type = type; 171 feature->fi_depends = deps; 172 } 173 174 void 175 zpool_feature_init(void) 176 { 177 zfeature_register(SPA_FEATURE_ASYNC_DESTROY, 178 "com.delphix:async_destroy", "async_destroy", 179 "Destroy filesystems asynchronously.", 180 ZFEATURE_FLAG_READONLY_COMPAT, ZFEATURE_TYPE_BOOLEAN, NULL); 181 182 zfeature_register(SPA_FEATURE_EMPTY_BPOBJ, 183 "com.delphix:empty_bpobj", "empty_bpobj", 184 "Snapshots use less space.", 185 ZFEATURE_FLAG_READONLY_COMPAT, ZFEATURE_TYPE_BOOLEAN, NULL); 186 187 zfeature_register(SPA_FEATURE_LZ4_COMPRESS, 188 "org.illumos:lz4_compress", "lz4_compress", 189 "LZ4 compression algorithm support.", 190 ZFEATURE_FLAG_ACTIVATE_ON_ENABLE, ZFEATURE_TYPE_BOOLEAN, NULL); 191 192 zfeature_register(SPA_FEATURE_MULTI_VDEV_CRASH_DUMP, 193 "com.joyent:multi_vdev_crash_dump", "multi_vdev_crash_dump", 194 "Crash dumps to multiple vdev pools.", 195 0, ZFEATURE_TYPE_BOOLEAN, NULL); 196 197 zfeature_register(SPA_FEATURE_SPACEMAP_HISTOGRAM, 198 "com.delphix:spacemap_histogram", "spacemap_histogram", 199 "Spacemaps maintain space histograms.", 200 ZFEATURE_FLAG_READONLY_COMPAT, ZFEATURE_TYPE_BOOLEAN, NULL); 201 202 zfeature_register(SPA_FEATURE_ENABLED_TXG, 203 "com.delphix:enabled_txg", "enabled_txg", 204 "Record txg at which a feature is enabled", 205 ZFEATURE_FLAG_READONLY_COMPAT, ZFEATURE_TYPE_BOOLEAN, NULL); 206 207 { 208 static spa_feature_t hole_birth_deps[] = { 209 SPA_FEATURE_ENABLED_TXG, 210 SPA_FEATURE_NONE 211 }; 212 zfeature_register(SPA_FEATURE_HOLE_BIRTH, 213 "com.delphix:hole_birth", "hole_birth", 214 "Retain hole birth txg for more precise zfs send", 215 ZFEATURE_FLAG_MOS | ZFEATURE_FLAG_ACTIVATE_ON_ENABLE, 216 ZFEATURE_TYPE_BOOLEAN, hole_birth_deps); 217 } 218 219 zfeature_register(SPA_FEATURE_POOL_CHECKPOINT, 220 "com.delphix:zpool_checkpoint", "zpool_checkpoint", 221 "Pool state can be checkpointed, allowing rewind later.", 222 ZFEATURE_FLAG_READONLY_COMPAT, ZFEATURE_TYPE_BOOLEAN, NULL); 223 224 zfeature_register(SPA_FEATURE_SPACEMAP_V2, 225 "com.delphix:spacemap_v2", "spacemap_v2", 226 "Space maps representing large segments are more efficient.", 227 ZFEATURE_FLAG_READONLY_COMPAT | ZFEATURE_FLAG_ACTIVATE_ON_ENABLE, 228 ZFEATURE_TYPE_BOOLEAN, NULL); 229 230 zfeature_register(SPA_FEATURE_EXTENSIBLE_DATASET, 231 "com.delphix:extensible_dataset", "extensible_dataset", 232 "Enhanced dataset functionality, used by other features.", 233 0, ZFEATURE_TYPE_BOOLEAN, NULL); 234 235 { 236 static const spa_feature_t bookmarks_deps[] = { 237 SPA_FEATURE_EXTENSIBLE_DATASET, 238 SPA_FEATURE_NONE 239 }; 240 zfeature_register(SPA_FEATURE_BOOKMARKS, 241 "com.delphix:bookmarks", "bookmarks", 242 "\"zfs bookmark\" command", 243 ZFEATURE_FLAG_READONLY_COMPAT, ZFEATURE_TYPE_BOOLEAN, 244 bookmarks_deps); 245 } 246 247 { 248 static const spa_feature_t filesystem_limits_deps[] = { 249 SPA_FEATURE_EXTENSIBLE_DATASET, 250 SPA_FEATURE_NONE 251 }; 252 zfeature_register(SPA_FEATURE_FS_SS_LIMIT, 253 "com.joyent:filesystem_limits", "filesystem_limits", 254 "Filesystem and snapshot limits.", 255 ZFEATURE_FLAG_READONLY_COMPAT, ZFEATURE_TYPE_BOOLEAN, 256 filesystem_limits_deps); 257 } 258 259 zfeature_register(SPA_FEATURE_EMBEDDED_DATA, 260 "com.delphix:embedded_data", "embedded_data", 261 "Blocks which compress very well use even less space.", 262 ZFEATURE_FLAG_MOS | ZFEATURE_FLAG_ACTIVATE_ON_ENABLE, 263 ZFEATURE_TYPE_BOOLEAN, NULL); 264 265 /* Slot for SPA_FEATURE_LIVELIST */ 266 267 { 268 static const spa_feature_t log_spacemap_deps[] = { 269 SPA_FEATURE_SPACEMAP_V2, 270 SPA_FEATURE_NONE 271 }; 272 zfeature_register(SPA_FEATURE_LOG_SPACEMAP, 273 "com.delphix:log_spacemap", "log_spacemap", 274 "Log metaslab changes on a single spacemap and " 275 "flush them periodically.", 276 ZFEATURE_FLAG_READONLY_COMPAT, ZFEATURE_TYPE_BOOLEAN, 277 log_spacemap_deps); 278 } 279 280 { 281 static const spa_feature_t large_blocks_deps[] = { 282 SPA_FEATURE_EXTENSIBLE_DATASET, 283 SPA_FEATURE_NONE 284 }; 285 zfeature_register(SPA_FEATURE_LARGE_BLOCKS, 286 "org.open-zfs:large_blocks", "large_blocks", 287 "Support for blocks larger than 128KB.", 288 ZFEATURE_FLAG_PER_DATASET, ZFEATURE_TYPE_BOOLEAN, 289 large_blocks_deps); 290 } 291 292 { 293 static const spa_feature_t large_dnode_deps[] = { 294 SPA_FEATURE_EXTENSIBLE_DATASET, 295 SPA_FEATURE_NONE 296 }; 297 zfeature_register(SPA_FEATURE_LARGE_DNODE, 298 "org.zfsonlinux:large_dnode", "large_dnode", 299 "Variable on-disk size of dnodes.", 300 ZFEATURE_FLAG_PER_DATASET, ZFEATURE_TYPE_BOOLEAN, 301 large_dnode_deps); 302 } 303 304 { 305 static const spa_feature_t sha512_deps[] = { 306 SPA_FEATURE_EXTENSIBLE_DATASET, 307 SPA_FEATURE_NONE 308 }; 309 zfeature_register(SPA_FEATURE_SHA512, 310 "org.illumos:sha512", "sha512", 311 "SHA-512/256 hash algorithm.", 312 ZFEATURE_FLAG_PER_DATASET, ZFEATURE_TYPE_BOOLEAN, 313 sha512_deps); 314 } 315 316 { 317 static const spa_feature_t skein_deps[] = { 318 SPA_FEATURE_EXTENSIBLE_DATASET, 319 SPA_FEATURE_NONE 320 }; 321 zfeature_register(SPA_FEATURE_SKEIN, 322 "org.illumos:skein", "skein", 323 "Skein hash algorithm.", 324 ZFEATURE_FLAG_PER_DATASET, ZFEATURE_TYPE_BOOLEAN, 325 skein_deps); 326 } 327 328 { 329 static const spa_feature_t edonr_deps[] = { 330 SPA_FEATURE_EXTENSIBLE_DATASET, 331 SPA_FEATURE_NONE 332 }; 333 zfeature_register(SPA_FEATURE_EDONR, 334 "org.illumos:edonr", "edonr", 335 "Edon-R hash algorithm.", 336 ZFEATURE_FLAG_PER_DATASET, ZFEATURE_TYPE_BOOLEAN, 337 edonr_deps); 338 } 339 340 /* Slot for SPA_FEATURE_REDACTION_BOOKMARKS */ 341 342 /* Slot for SPA_FEATURE_REDACTED_DATASETS */ 343 344 /* Slot for SPA_FEATURE_BOOKMARK_WRITTEN */ 345 346 zfeature_register(SPA_FEATURE_DEVICE_REMOVAL, 347 "com.delphix:device_removal", "device_removal", 348 "Top-level vdevs can be removed, reducing logical pool size.", 349 ZFEATURE_FLAG_MOS, ZFEATURE_TYPE_BOOLEAN, NULL); 350 351 { 352 static const spa_feature_t obsolete_counts_deps[] = { 353 SPA_FEATURE_EXTENSIBLE_DATASET, 354 SPA_FEATURE_DEVICE_REMOVAL, 355 SPA_FEATURE_NONE 356 }; 357 zfeature_register(SPA_FEATURE_OBSOLETE_COUNTS, 358 "com.delphix:obsolete_counts", "obsolete_counts", 359 "Reduce memory used by removed devices when their " 360 "blocks are freed or remapped.", 361 ZFEATURE_FLAG_READONLY_COMPAT, ZFEATURE_TYPE_BOOLEAN, 362 obsolete_counts_deps); 363 } 364 365 { 366 static const spa_feature_t userobj_accounting_deps[] = { 367 SPA_FEATURE_EXTENSIBLE_DATASET, 368 SPA_FEATURE_NONE 369 }; 370 zfeature_register(SPA_FEATURE_USEROBJ_ACCOUNTING, 371 "org.zfsonlinux:userobj_accounting", "userobj_accounting", 372 "User/Group object accounting.", 373 ZFEATURE_FLAG_READONLY_COMPAT | ZFEATURE_FLAG_PER_DATASET, 374 ZFEATURE_TYPE_BOOLEAN, userobj_accounting_deps); 375 } 376 377 { 378 static const spa_feature_t bookmark_v2_deps[] = { 379 SPA_FEATURE_EXTENSIBLE_DATASET, 380 SPA_FEATURE_BOOKMARKS, 381 SPA_FEATURE_NONE 382 }; 383 zfeature_register(SPA_FEATURE_BOOKMARK_V2, 384 "com.datto:bookmark_v2", "bookmark_v2", 385 "Support for larger bookmarks", 386 0, ZFEATURE_TYPE_BOOLEAN, bookmark_v2_deps); 387 } 388 389 { 390 static const spa_feature_t encryption_deps[] = { 391 SPA_FEATURE_EXTENSIBLE_DATASET, 392 SPA_FEATURE_BOOKMARK_V2, 393 SPA_FEATURE_NONE 394 }; 395 zfeature_register(SPA_FEATURE_ENCRYPTION, 396 "com.datto:encryption", "encryption", 397 "Support for dataset level encryption", 398 ZFEATURE_FLAG_PER_DATASET, ZFEATURE_TYPE_BOOLEAN, 399 encryption_deps); 400 } 401 402 { 403 static const spa_feature_t project_quota_deps[] = { 404 SPA_FEATURE_EXTENSIBLE_DATASET, 405 SPA_FEATURE_NONE 406 }; 407 zfeature_register(SPA_FEATURE_PROJECT_QUOTA, 408 "org.zfsonlinux:project_quota", "project_quota", 409 "space/object accounting based on project ID.", 410 ZFEATURE_FLAG_READONLY_COMPAT | ZFEATURE_FLAG_PER_DATASET, 411 ZFEATURE_TYPE_BOOLEAN, project_quota_deps); 412 } 413 414 zfeature_register(SPA_FEATURE_ALLOCATION_CLASSES, 415 "org.zfsonlinux:allocation_classes", "allocation_classes", 416 "Support for separate allocation classes.", 417 ZFEATURE_FLAG_READONLY_COMPAT, ZFEATURE_TYPE_BOOLEAN, NULL); 418 419 zfeature_register(SPA_FEATURE_RESILVER_DEFER, 420 "com.datto:resilver_defer", "resilver_defer", 421 "Support for defering new resilvers when one is already running.", 422 ZFEATURE_FLAG_READONLY_COMPAT, ZFEATURE_TYPE_BOOLEAN, NULL); 423 424 /* 425 * Slots for: 426 * SPA_FEATURE_DEVICE_REBUILD 427 * SPA_FEATURE_ZSTD_COMPRESS 428 * SPA_FEATURE_DRAID 429 * SPA_FEATURE_ZILSAXATTR 430 * SPA_FEATURE_HEAD_ERRLOG 431 * SPA_FEATURE_BLAKE3 432 * SPA_FEATURE_BLOCK_CLONING 433 * SPA_FEATURE_AVZ_V2 434 * SPA_FEATURE_REDACTION_LIST_SPILL 435 * SPA_FEATURE_RAIDZ_EXPANSION 436 * SPA_FEATURE_FAST_DEDUP 437 * SPA_FEATURE_LONGNAME 438 * SPA_FEATURE_LARGE_MICROZAP 439 */ 440 } 441