zfeature_common.c revision 268075
1236884Smm/* 2236884Smm * CDDL HEADER START 3236884Smm * 4236884Smm * The contents of this file are subject to the terms of the 5236884Smm * Common Development and Distribution License (the "License"). 6236884Smm * You may not use this file except in compliance with the License. 7236884Smm * 8236884Smm * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9236884Smm * or http://www.opensolaris.org/os/licensing. 10236884Smm * See the License for the specific language governing permissions 11236884Smm * and limitations under the License. 12236884Smm * 13236884Smm * When distributing Covered Code, include this CDDL HEADER in each 14236884Smm * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15236884Smm * If applicable, add the following below this CDDL HEADER, with the 16236884Smm * fields enclosed by brackets "[]" replaced with your own identifying 17236884Smm * information: Portions Copyright [yyyy] [name of copyright owner] 18236884Smm * 19236884Smm * CDDL HEADER END 20236884Smm */ 21236884Smm 22236884Smm/* 23258717Savg * Copyright (c) 2013 by Delphix. All rights reserved. 24246586Sdelphij * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. 25255750Sdelphij * Copyright (c) 2013, Joyent, Inc. All rights reserved. 26236884Smm */ 27236884Smm 28236884Smm#ifdef _KERNEL 29236884Smm#include <sys/systm.h> 30236884Smm#else 31236884Smm#include <errno.h> 32236884Smm#include <string.h> 33236884Smm#endif 34236884Smm#include <sys/debug.h> 35236884Smm#include <sys/fs/zfs.h> 36236884Smm#include <sys/types.h> 37236884Smm#include "zfeature_common.h" 38236884Smm 39236884Smm/* 40236884Smm * Set to disable all feature checks while opening pools, allowing pools with 41236884Smm * unsupported features to be opened. Set for testing only. 42236884Smm */ 43236884Smmboolean_t zfeature_checks_disable = B_FALSE; 44236884Smm 45236884Smmzfeature_info_t spa_feature_table[SPA_FEATURES]; 46236884Smm 47236884Smm/* 48236884Smm * Valid characters for feature guids. This list is mainly for aesthetic 49236884Smm * purposes and could be expanded in the future. There are different allowed 50236884Smm * characters in the guids reverse dns portion (before the colon) and its 51236884Smm * short name (after the colon). 52236884Smm */ 53236884Smmstatic int 54236884Smmvalid_char(char c, boolean_t after_colon) 55236884Smm{ 56236884Smm return ((c >= 'a' && c <= 'z') || 57236884Smm (c >= '0' && c <= '9') || 58236884Smm c == (after_colon ? '_' : '.')); 59236884Smm} 60236884Smm 61236884Smm/* 62236884Smm * Every feature guid must contain exactly one colon which separates a reverse 63236884Smm * dns organization name from the feature's "short" name (e.g. 64236884Smm * "com.company:feature_name"). 65236884Smm */ 66236884Smmboolean_t 67236884Smmzfeature_is_valid_guid(const char *name) 68236884Smm{ 69236884Smm int i; 70236884Smm boolean_t has_colon = B_FALSE; 71236884Smm 72236884Smm i = 0; 73236884Smm while (name[i] != '\0') { 74236884Smm char c = name[i++]; 75236884Smm if (c == ':') { 76236884Smm if (has_colon) 77236884Smm return (B_FALSE); 78236884Smm has_colon = B_TRUE; 79236884Smm continue; 80236884Smm } 81236884Smm if (!valid_char(c, has_colon)) 82236884Smm return (B_FALSE); 83236884Smm } 84236884Smm 85236884Smm return (has_colon); 86236884Smm} 87236884Smm 88236884Smmboolean_t 89236884Smmzfeature_is_supported(const char *guid) 90236884Smm{ 91236884Smm if (zfeature_checks_disable) 92236884Smm return (B_TRUE); 93236884Smm 94259813Sdelphij for (spa_feature_t i = 0; i < SPA_FEATURES; i++) { 95236884Smm zfeature_info_t *feature = &spa_feature_table[i]; 96259813Sdelphij if (strcmp(guid, feature->fi_guid) == 0) 97259813Sdelphij return (B_TRUE); 98236884Smm } 99259813Sdelphij return (B_FALSE); 100236884Smm} 101236884Smm 102236884Smmint 103259813Sdelphijzfeature_lookup_name(const char *name, spa_feature_t *res) 104236884Smm{ 105259813Sdelphij for (spa_feature_t i = 0; i < SPA_FEATURES; i++) { 106236884Smm zfeature_info_t *feature = &spa_feature_table[i]; 107236884Smm if (strcmp(name, feature->fi_uname) == 0) { 108236884Smm if (res != NULL) 109259813Sdelphij *res = i; 110236884Smm return (0); 111236884Smm } 112236884Smm } 113236884Smm 114236884Smm return (ENOENT); 115236884Smm} 116236884Smm 117260150Sdelphijboolean_t 118260150Sdelphijzfeature_depends_on(spa_feature_t fid, spa_feature_t check) { 119260150Sdelphij zfeature_info_t *feature = &spa_feature_table[fid]; 120260150Sdelphij 121260150Sdelphij for (int i = 0; feature->fi_depends[i] != SPA_FEATURE_NONE; i++) { 122260150Sdelphij if (feature->fi_depends[i] == check) 123260150Sdelphij return (B_TRUE); 124260150Sdelphij } 125260150Sdelphij return (B_FALSE); 126260150Sdelphij} 127260150Sdelphij 128236884Smmstatic void 129259813Sdelphijzfeature_register(spa_feature_t fid, const char *guid, const char *name, 130259813Sdelphij const char *desc, boolean_t readonly, boolean_t mos, 131260150Sdelphij boolean_t activate_on_enable, const spa_feature_t *deps) 132236884Smm{ 133236884Smm zfeature_info_t *feature = &spa_feature_table[fid]; 134259813Sdelphij static spa_feature_t nodeps[] = { SPA_FEATURE_NONE }; 135236884Smm 136236884Smm ASSERT(name != NULL); 137236884Smm ASSERT(desc != NULL); 138236884Smm ASSERT(!readonly || !mos); 139236884Smm ASSERT3U(fid, <, SPA_FEATURES); 140236884Smm ASSERT(zfeature_is_valid_guid(guid)); 141236884Smm 142236884Smm if (deps == NULL) 143236884Smm deps = nodeps; 144236884Smm 145259813Sdelphij feature->fi_feature = fid; 146236884Smm feature->fi_guid = guid; 147236884Smm feature->fi_uname = name; 148236884Smm feature->fi_desc = desc; 149236884Smm feature->fi_can_readonly = readonly; 150236884Smm feature->fi_mos = mos; 151260150Sdelphij feature->fi_activate_on_enable = activate_on_enable; 152236884Smm feature->fi_depends = deps; 153236884Smm} 154236884Smm 155236884Smmvoid 156236884Smmzpool_feature_init(void) 157236884Smm{ 158236884Smm zfeature_register(SPA_FEATURE_ASYNC_DESTROY, 159236884Smm "com.delphix:async_destroy", "async_destroy", 160260150Sdelphij "Destroy filesystems asynchronously.", B_TRUE, B_FALSE, 161260150Sdelphij B_FALSE, NULL); 162260150Sdelphij 163239774Smm zfeature_register(SPA_FEATURE_EMPTY_BPOBJ, 164239774Smm "com.delphix:empty_bpobj", "empty_bpobj", 165260150Sdelphij "Snapshots use less space.", B_TRUE, B_FALSE, 166260150Sdelphij B_FALSE, NULL); 167260150Sdelphij 168246586Sdelphij zfeature_register(SPA_FEATURE_LZ4_COMPRESS, 169246586Sdelphij "org.illumos:lz4_compress", "lz4_compress", 170260150Sdelphij "LZ4 compression algorithm support.", B_FALSE, B_FALSE, 171260150Sdelphij B_FALSE, NULL); 172260150Sdelphij 173255750Sdelphij zfeature_register(SPA_FEATURE_MULTI_VDEV_CRASH_DUMP, 174255750Sdelphij "com.joyent:multi_vdev_crash_dump", "multi_vdev_crash_dump", 175260150Sdelphij "Crash dumps to multiple vdev pools.", B_FALSE, B_FALSE, 176260150Sdelphij B_FALSE, NULL); 177260150Sdelphij 178258717Savg zfeature_register(SPA_FEATURE_SPACEMAP_HISTOGRAM, 179258717Savg "com.delphix:spacemap_histogram", "spacemap_histogram", 180260150Sdelphij "Spacemaps maintain space histograms.", B_TRUE, B_FALSE, 181260150Sdelphij B_FALSE, NULL); 182260150Sdelphij 183260150Sdelphij zfeature_register(SPA_FEATURE_ENABLED_TXG, 184260150Sdelphij "com.delphix:enabled_txg", "enabled_txg", 185260150Sdelphij "Record txg at which a feature is enabled", B_TRUE, B_FALSE, 186260150Sdelphij B_FALSE, NULL); 187260150Sdelphij 188260150Sdelphij static spa_feature_t hole_birth_deps[] = { SPA_FEATURE_ENABLED_TXG, 189260150Sdelphij SPA_FEATURE_NONE }; 190260150Sdelphij zfeature_register(SPA_FEATURE_HOLE_BIRTH, 191260150Sdelphij "com.delphix:hole_birth", "hole_birth", 192260150Sdelphij "Retain hole birth txg for more precise zfs send", 193260150Sdelphij B_FALSE, B_TRUE, B_TRUE, hole_birth_deps); 194260150Sdelphij 195259813Sdelphij zfeature_register(SPA_FEATURE_EXTENSIBLE_DATASET, 196259813Sdelphij "com.delphix:extensible_dataset", "extensible_dataset", 197259813Sdelphij "Enhanced dataset functionality, used by other features.", 198260150Sdelphij B_FALSE, B_FALSE, B_FALSE, NULL); 199260183Sdelphij 200260183Sdelphij static const spa_feature_t bookmarks_deps[] = { 201260183Sdelphij SPA_FEATURE_EXTENSIBLE_DATASET, 202260183Sdelphij SPA_FEATURE_NONE 203260183Sdelphij }; 204260183Sdelphij zfeature_register(SPA_FEATURE_BOOKMARKS, 205260183Sdelphij "com.delphix:bookmarks", "bookmarks", 206260183Sdelphij "\"zfs bookmark\" command", 207260183Sdelphij B_TRUE, B_FALSE, B_FALSE, bookmarks_deps); 208264835Sdelphij 209264835Sdelphij static const spa_feature_t filesystem_limits_deps[] = { 210264835Sdelphij SPA_FEATURE_EXTENSIBLE_DATASET, 211264835Sdelphij SPA_FEATURE_NONE 212264835Sdelphij }; 213264835Sdelphij zfeature_register(SPA_FEATURE_FS_SS_LIMIT, 214264835Sdelphij "com.joyent:filesystem_limits", "filesystem_limits", 215264835Sdelphij "Filesystem and snapshot limits.", B_TRUE, B_FALSE, B_FALSE, 216264835Sdelphij filesystem_limits_deps); 217268075Sdelphij 218268075Sdelphij zfeature_register(SPA_FEATURE_EMBEDDED_DATA, 219268075Sdelphij "com.delphix:embedded_data", "embedded_data", 220268075Sdelphij "Blocks which compress very well use even less space.", 221268075Sdelphij B_FALSE, B_TRUE, B_TRUE, NULL); 222236884Smm} 223