1*53089ab7Seschrock /* 2*53089ab7Seschrock * CDDL HEADER START 3*53089ab7Seschrock * 4*53089ab7Seschrock * The contents of this file are subject to the terms of the 5*53089ab7Seschrock * Common Development and Distribution License (the "License"). 6*53089ab7Seschrock * You may not use this file except in compliance with the License. 7*53089ab7Seschrock * 8*53089ab7Seschrock * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*53089ab7Seschrock * or http://www.opensolaris.org/os/licensing. 10*53089ab7Seschrock * See the License for the specific language governing permissions 11*53089ab7Seschrock * and limitations under the License. 12*53089ab7Seschrock * 13*53089ab7Seschrock * When distributing Covered Code, include this CDDL HEADER in each 14*53089ab7Seschrock * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*53089ab7Seschrock * If applicable, add the following below this CDDL HEADER, with the 16*53089ab7Seschrock * fields enclosed by brackets "[]" replaced with your own identifying 17*53089ab7Seschrock * information: Portions Copyright [yyyy] [name of copyright owner] 18*53089ab7Seschrock * 19*53089ab7Seschrock * CDDL HEADER END 20*53089ab7Seschrock */ 21*53089ab7Seschrock 22*53089ab7Seschrock /* 23*53089ab7Seschrock * Copyright (c) 2012 by Delphix. All rights reserved. 24*53089ab7Seschrock */ 25*53089ab7Seschrock 26*53089ab7Seschrock #ifdef _KERNEL 27*53089ab7Seschrock #include <sys/systm.h> 28*53089ab7Seschrock #else 29*53089ab7Seschrock #include <errno.h> 30*53089ab7Seschrock #include <string.h> 31*53089ab7Seschrock #endif 32*53089ab7Seschrock #include <sys/debug.h> 33*53089ab7Seschrock #include <sys/fs/zfs.h> 34*53089ab7Seschrock #include <sys/inttypes.h> 35*53089ab7Seschrock #include <sys/types.h> 36*53089ab7Seschrock #include "zfeature_common.h" 37*53089ab7Seschrock 38*53089ab7Seschrock /* 39*53089ab7Seschrock * Set to disable all feature checks while opening pools, allowing pools with 40*53089ab7Seschrock * unsupported features to be opened. Set for testing only. 41*53089ab7Seschrock */ 42*53089ab7Seschrock boolean_t zfeature_checks_disable = B_FALSE; 43*53089ab7Seschrock 44*53089ab7Seschrock zfeature_info_t spa_feature_table[SPA_FEATURES]; 45*53089ab7Seschrock 46*53089ab7Seschrock /* 47*53089ab7Seschrock * Valid characters for feature guids. This list is mainly for aesthetic 48*53089ab7Seschrock * purposes and could be expanded in the future. There are different allowed 49*53089ab7Seschrock * characters in the guids reverse dns portion (before the colon) and its 50*53089ab7Seschrock * short name (after the colon). 51*53089ab7Seschrock */ 52*53089ab7Seschrock static int 53*53089ab7Seschrock valid_char(char c, boolean_t after_colon) 54*53089ab7Seschrock { 55*53089ab7Seschrock return ((c >= 'a' && c <= 'z') || 56*53089ab7Seschrock (c >= '0' && c <= '9') || 57*53089ab7Seschrock c == (after_colon ? '_' : '.')); 58*53089ab7Seschrock } 59*53089ab7Seschrock 60*53089ab7Seschrock /* 61*53089ab7Seschrock * Every feature guid must contain exactly one colon which separates a reverse 62*53089ab7Seschrock * dns organization name from the feature's "short" name (e.g. 63*53089ab7Seschrock * "com.company:feature_name"). 64*53089ab7Seschrock */ 65*53089ab7Seschrock boolean_t 66*53089ab7Seschrock zfeature_is_valid_guid(const char *name) 67*53089ab7Seschrock { 68*53089ab7Seschrock int i; 69*53089ab7Seschrock boolean_t has_colon = B_FALSE; 70*53089ab7Seschrock 71*53089ab7Seschrock i = 0; 72*53089ab7Seschrock while (name[i] != '\0') { 73*53089ab7Seschrock char c = name[i++]; 74*53089ab7Seschrock if (c == ':') { 75*53089ab7Seschrock if (has_colon) 76*53089ab7Seschrock return (B_FALSE); 77*53089ab7Seschrock has_colon = B_TRUE; 78*53089ab7Seschrock continue; 79*53089ab7Seschrock } 80*53089ab7Seschrock if (!valid_char(c, has_colon)) 81*53089ab7Seschrock return (B_FALSE); 82*53089ab7Seschrock } 83*53089ab7Seschrock 84*53089ab7Seschrock return (has_colon); 85*53089ab7Seschrock } 86*53089ab7Seschrock 87*53089ab7Seschrock boolean_t 88*53089ab7Seschrock zfeature_is_supported(const char *guid) 89*53089ab7Seschrock { 90*53089ab7Seschrock if (zfeature_checks_disable) 91*53089ab7Seschrock return (B_TRUE); 92*53089ab7Seschrock 93*53089ab7Seschrock return (0 == zfeature_lookup_guid(guid, NULL)); 94*53089ab7Seschrock } 95*53089ab7Seschrock 96*53089ab7Seschrock int 97*53089ab7Seschrock zfeature_lookup_guid(const char *guid, zfeature_info_t **res) 98*53089ab7Seschrock { 99*53089ab7Seschrock for (int i = 0; i < SPA_FEATURES; i++) { 100*53089ab7Seschrock zfeature_info_t *feature = &spa_feature_table[i]; 101*53089ab7Seschrock if (strcmp(guid, feature->fi_guid) == 0) { 102*53089ab7Seschrock if (res != NULL) 103*53089ab7Seschrock *res = feature; 104*53089ab7Seschrock return (0); 105*53089ab7Seschrock } 106*53089ab7Seschrock } 107*53089ab7Seschrock 108*53089ab7Seschrock return (ENOENT); 109*53089ab7Seschrock } 110*53089ab7Seschrock 111*53089ab7Seschrock int 112*53089ab7Seschrock zfeature_lookup_name(const char *name, zfeature_info_t **res) 113*53089ab7Seschrock { 114*53089ab7Seschrock for (int i = 0; i < SPA_FEATURES; i++) { 115*53089ab7Seschrock zfeature_info_t *feature = &spa_feature_table[i]; 116*53089ab7Seschrock if (strcmp(name, feature->fi_uname) == 0) { 117*53089ab7Seschrock if (res != NULL) 118*53089ab7Seschrock *res = feature; 119*53089ab7Seschrock return (0); 120*53089ab7Seschrock } 121*53089ab7Seschrock } 122*53089ab7Seschrock 123*53089ab7Seschrock return (ENOENT); 124*53089ab7Seschrock } 125*53089ab7Seschrock 126*53089ab7Seschrock static void 127*53089ab7Seschrock zfeature_register(int fid, const char *guid, const char *name, const char *desc, 128*53089ab7Seschrock boolean_t readonly, boolean_t mos, zfeature_info_t **deps) 129*53089ab7Seschrock { 130*53089ab7Seschrock zfeature_info_t *feature = &spa_feature_table[fid]; 131*53089ab7Seschrock static zfeature_info_t *nodeps[] = { NULL }; 132*53089ab7Seschrock 133*53089ab7Seschrock ASSERT(name != NULL); 134*53089ab7Seschrock ASSERT(desc != NULL); 135*53089ab7Seschrock ASSERT(!readonly || !mos); 136*53089ab7Seschrock ASSERT3U(fid, <, SPA_FEATURES); 137*53089ab7Seschrock ASSERT(zfeature_is_valid_guid(guid)); 138*53089ab7Seschrock 139*53089ab7Seschrock if (deps == NULL) 140*53089ab7Seschrock deps = nodeps; 141*53089ab7Seschrock 142*53089ab7Seschrock feature->fi_guid = guid; 143*53089ab7Seschrock feature->fi_uname = name; 144*53089ab7Seschrock feature->fi_desc = desc; 145*53089ab7Seschrock feature->fi_can_readonly = readonly; 146*53089ab7Seschrock feature->fi_mos = mos; 147*53089ab7Seschrock feature->fi_depends = deps; 148*53089ab7Seschrock } 149*53089ab7Seschrock 150*53089ab7Seschrock void 151*53089ab7Seschrock zpool_feature_init(void) 152*53089ab7Seschrock { 153*53089ab7Seschrock zfeature_register(SPA_FEATURE_ASYNC_DESTROY, 154*53089ab7Seschrock "com.delphix:async_destroy", "async_destroy", 155*53089ab7Seschrock "Destroy filesystems asynchronously.", B_TRUE, B_FALSE, NULL); 156*53089ab7Seschrock } 157