Home | History | Annotate | Line # | Download | only in zfs
zpool_prop.c revision 1.1.1.2.44.1
      1           1.1      haad /*
      2           1.1      haad  * CDDL HEADER START
      3           1.1      haad  *
      4           1.1      haad  * The contents of this file are subject to the terms of the
      5           1.1      haad  * Common Development and Distribution License (the "License").
      6           1.1      haad  * You may not use this file except in compliance with the License.
      7           1.1      haad  *
      8           1.1      haad  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
      9           1.1      haad  * or http://www.opensolaris.org/os/licensing.
     10           1.1      haad  * See the License for the specific language governing permissions
     11           1.1      haad  * and limitations under the License.
     12           1.1      haad  *
     13           1.1      haad  * When distributing Covered Code, include this CDDL HEADER in each
     14           1.1      haad  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
     15           1.1      haad  * If applicable, add the following below this CDDL HEADER, with the
     16           1.1      haad  * fields enclosed by brackets "[]" replaced with your own identifying
     17           1.1      haad  * information: Portions Copyright [yyyy] [name of copyright owner]
     18           1.1      haad  *
     19           1.1      haad  * CDDL HEADER END
     20           1.1      haad  */
     21           1.1      haad /*
     22  1.1.1.2.44.1  pgoyette  * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
     23  1.1.1.2.44.1  pgoyette  * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
     24  1.1.1.2.44.1  pgoyette  * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
     25  1.1.1.2.44.1  pgoyette  * Copyright (c) 2014 Integros [integros.com]
     26           1.1      haad  */
     27           1.1      haad 
     28           1.1      haad #include <sys/zio.h>
     29           1.1      haad #include <sys/spa.h>
     30           1.1      haad #include <sys/zfs_acl.h>
     31           1.1      haad #include <sys/zfs_ioctl.h>
     32           1.1      haad #include <sys/fs/zfs.h>
     33           1.1      haad 
     34           1.1      haad #include "zfs_prop.h"
     35           1.1      haad 
     36           1.1      haad #if defined(_KERNEL)
     37           1.1      haad #include <sys/systm.h>
     38           1.1      haad #else
     39           1.1      haad #include <stdlib.h>
     40           1.1      haad #include <string.h>
     41           1.1      haad #include <ctype.h>
     42           1.1      haad #endif
     43           1.1      haad 
     44           1.1      haad static zprop_desc_t zpool_prop_table[ZPOOL_NUM_PROPS];
     45           1.1      haad 
     46           1.1      haad zprop_desc_t *
     47           1.1      haad zpool_prop_get_table(void)
     48           1.1      haad {
     49           1.1      haad 	return (zpool_prop_table);
     50           1.1      haad }
     51           1.1      haad 
     52           1.1      haad void
     53           1.1      haad zpool_prop_init(void)
     54           1.1      haad {
     55           1.1      haad 	static zprop_index_t boolean_table[] = {
     56           1.1      haad 		{ "off",	0},
     57           1.1      haad 		{ "on",		1},
     58           1.1      haad 		{ NULL }
     59           1.1      haad 	};
     60           1.1      haad 
     61           1.1      haad 	static zprop_index_t failuremode_table[] = {
     62           1.1      haad 		{ "wait",	ZIO_FAILURE_MODE_WAIT },
     63           1.1      haad 		{ "continue",	ZIO_FAILURE_MODE_CONTINUE },
     64           1.1      haad 		{ "panic",	ZIO_FAILURE_MODE_PANIC },
     65           1.1      haad 		{ NULL }
     66           1.1      haad 	};
     67           1.1      haad 
     68           1.1      haad 	/* string properties */
     69  1.1.1.2.44.1  pgoyette 	zprop_register_string(ZPOOL_PROP_ALTROOT, "altroot", NULL, PROP_DEFAULT,
     70           1.1      haad 	    ZFS_TYPE_POOL, "<path>", "ALTROOT");
     71  1.1.1.2.44.1  pgoyette 	zprop_register_string(ZPOOL_PROP_BOOTFS, "bootfs", NULL, PROP_DEFAULT,
     72           1.1      haad 	    ZFS_TYPE_POOL, "<filesystem>", "BOOTFS");
     73  1.1.1.2.44.1  pgoyette 	zprop_register_string(ZPOOL_PROP_CACHEFILE, "cachefile", NULL,
     74  1.1.1.2.44.1  pgoyette 	    PROP_DEFAULT, ZFS_TYPE_POOL, "<file> | none", "CACHEFILE");
     75  1.1.1.2.44.1  pgoyette 	zprop_register_string(ZPOOL_PROP_COMMENT, "comment", NULL,
     76  1.1.1.2.44.1  pgoyette 	    PROP_DEFAULT, ZFS_TYPE_POOL, "<comment-string>", "COMMENT");
     77           1.1      haad 
     78           1.1      haad 	/* readonly number properties */
     79  1.1.1.2.44.1  pgoyette 	zprop_register_number(ZPOOL_PROP_SIZE, "size", 0, PROP_READONLY,
     80           1.1      haad 	    ZFS_TYPE_POOL, "<size>", "SIZE");
     81  1.1.1.2.44.1  pgoyette 	zprop_register_number(ZPOOL_PROP_FREE, "free", 0, PROP_READONLY,
     82       1.1.1.2      haad 	    ZFS_TYPE_POOL, "<size>", "FREE");
     83  1.1.1.2.44.1  pgoyette 	zprop_register_number(ZPOOL_PROP_FREEING, "freeing", 0, PROP_READONLY,
     84  1.1.1.2.44.1  pgoyette 	    ZFS_TYPE_POOL, "<size>", "FREEING");
     85  1.1.1.2.44.1  pgoyette 	zprop_register_number(ZPOOL_PROP_LEAKED, "leaked", 0, PROP_READONLY,
     86  1.1.1.2.44.1  pgoyette 	    ZFS_TYPE_POOL, "<size>", "LEAKED");
     87  1.1.1.2.44.1  pgoyette 	zprop_register_number(ZPOOL_PROP_ALLOCATED, "allocated", 0,
     88  1.1.1.2.44.1  pgoyette 	    PROP_READONLY, ZFS_TYPE_POOL, "<size>", "ALLOC");
     89  1.1.1.2.44.1  pgoyette 	zprop_register_number(ZPOOL_PROP_EXPANDSZ, "expandsize", 0,
     90  1.1.1.2.44.1  pgoyette 	    PROP_READONLY, ZFS_TYPE_POOL, "<size>", "EXPANDSZ");
     91  1.1.1.2.44.1  pgoyette 	zprop_register_number(ZPOOL_PROP_FRAGMENTATION, "fragmentation", 0,
     92  1.1.1.2.44.1  pgoyette 	    PROP_READONLY, ZFS_TYPE_POOL, "<percent>", "FRAG");
     93  1.1.1.2.44.1  pgoyette 	zprop_register_number(ZPOOL_PROP_CAPACITY, "capacity", 0, PROP_READONLY,
     94           1.1      haad 	    ZFS_TYPE_POOL, "<size>", "CAP");
     95  1.1.1.2.44.1  pgoyette 	zprop_register_number(ZPOOL_PROP_GUID, "guid", 0, PROP_READONLY,
     96           1.1      haad 	    ZFS_TYPE_POOL, "<guid>", "GUID");
     97  1.1.1.2.44.1  pgoyette 	zprop_register_number(ZPOOL_PROP_HEALTH, "health", 0, PROP_READONLY,
     98           1.1      haad 	    ZFS_TYPE_POOL, "<state>", "HEALTH");
     99  1.1.1.2.44.1  pgoyette 	zprop_register_number(ZPOOL_PROP_DEDUPRATIO, "dedupratio", 0,
    100  1.1.1.2.44.1  pgoyette 	    PROP_READONLY, ZFS_TYPE_POOL, "<1.00x or higher if deduped>",
    101  1.1.1.2.44.1  pgoyette 	    "DEDUP");
    102           1.1      haad 
    103           1.1      haad 	/* default number properties */
    104  1.1.1.2.44.1  pgoyette 	zprop_register_number(ZPOOL_PROP_VERSION, "version", SPA_VERSION,
    105           1.1      haad 	    PROP_DEFAULT, ZFS_TYPE_POOL, "<version>", "VERSION");
    106  1.1.1.2.44.1  pgoyette 	zprop_register_number(ZPOOL_PROP_DEDUPDITTO, "dedupditto", 0,
    107       1.1.1.2      haad 	    PROP_DEFAULT, ZFS_TYPE_POOL, "<threshold (min 100)>", "DEDUPDITTO");
    108           1.1      haad 
    109           1.1      haad 	/* default index (boolean) properties */
    110  1.1.1.2.44.1  pgoyette 	zprop_register_index(ZPOOL_PROP_DELEGATION, "delegation", 1,
    111  1.1.1.2.44.1  pgoyette 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "DELEGATION",
    112  1.1.1.2.44.1  pgoyette 	    boolean_table);
    113  1.1.1.2.44.1  pgoyette 	zprop_register_index(ZPOOL_PROP_AUTOREPLACE, "autoreplace", 0,
    114  1.1.1.2.44.1  pgoyette 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "REPLACE", boolean_table);
    115  1.1.1.2.44.1  pgoyette 	zprop_register_index(ZPOOL_PROP_LISTSNAPS, "listsnapshots", 0,
    116  1.1.1.2.44.1  pgoyette 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "LISTSNAPS",
    117  1.1.1.2.44.1  pgoyette 	    boolean_table);
    118  1.1.1.2.44.1  pgoyette 	zprop_register_index(ZPOOL_PROP_AUTOEXPAND, "autoexpand", 0,
    119  1.1.1.2.44.1  pgoyette 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "EXPAND", boolean_table);
    120  1.1.1.2.44.1  pgoyette 	zprop_register_index(ZPOOL_PROP_READONLY, "readonly", 0,
    121  1.1.1.2.44.1  pgoyette 	    PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "RDONLY", boolean_table);
    122           1.1      haad 
    123           1.1      haad 	/* default index properties */
    124  1.1.1.2.44.1  pgoyette 	zprop_register_index(ZPOOL_PROP_FAILUREMODE, "failmode",
    125           1.1      haad 	    ZIO_FAILURE_MODE_WAIT, PROP_DEFAULT, ZFS_TYPE_POOL,
    126           1.1      haad 	    "wait | continue | panic", "FAILMODE", failuremode_table);
    127           1.1      haad 
    128           1.1      haad 	/* hidden properties */
    129  1.1.1.2.44.1  pgoyette 	zprop_register_hidden(ZPOOL_PROP_NAME, "name", PROP_TYPE_STRING,
    130           1.1      haad 	    PROP_READONLY, ZFS_TYPE_POOL, "NAME");
    131  1.1.1.2.44.1  pgoyette 	zprop_register_hidden(ZPOOL_PROP_MAXBLOCKSIZE, "maxblocksize",
    132  1.1.1.2.44.1  pgoyette 	    PROP_TYPE_NUMBER, PROP_READONLY, ZFS_TYPE_POOL, "MAXBLOCKSIZE");
    133           1.1      haad }
    134           1.1      haad 
    135           1.1      haad /*
    136           1.1      haad  * Given a property name and its type, returns the corresponding property ID.
    137           1.1      haad  */
    138           1.1      haad zpool_prop_t
    139           1.1      haad zpool_name_to_prop(const char *propname)
    140           1.1      haad {
    141           1.1      haad 	return (zprop_name_to_prop(propname, ZFS_TYPE_POOL));
    142           1.1      haad }
    143           1.1      haad 
    144           1.1      haad /*
    145           1.1      haad  * Given a pool property ID, returns the corresponding name.
    146           1.1      haad  * Assuming the pool propety ID is valid.
    147           1.1      haad  */
    148           1.1      haad const char *
    149           1.1      haad zpool_prop_to_name(zpool_prop_t prop)
    150           1.1      haad {
    151           1.1      haad 	return (zpool_prop_table[prop].pd_name);
    152           1.1      haad }
    153           1.1      haad 
    154           1.1      haad zprop_type_t
    155           1.1      haad zpool_prop_get_type(zpool_prop_t prop)
    156           1.1      haad {
    157           1.1      haad 	return (zpool_prop_table[prop].pd_proptype);
    158           1.1      haad }
    159           1.1      haad 
    160           1.1      haad boolean_t
    161           1.1      haad zpool_prop_readonly(zpool_prop_t prop)
    162           1.1      haad {
    163           1.1      haad 	return (zpool_prop_table[prop].pd_attr == PROP_READONLY);
    164           1.1      haad }
    165           1.1      haad 
    166           1.1      haad const char *
    167           1.1      haad zpool_prop_default_string(zpool_prop_t prop)
    168           1.1      haad {
    169           1.1      haad 	return (zpool_prop_table[prop].pd_strdefault);
    170           1.1      haad }
    171           1.1      haad 
    172           1.1      haad uint64_t
    173           1.1      haad zpool_prop_default_numeric(zpool_prop_t prop)
    174           1.1      haad {
    175           1.1      haad 	return (zpool_prop_table[prop].pd_numdefault);
    176           1.1      haad }
    177           1.1      haad 
    178  1.1.1.2.44.1  pgoyette /*
    179  1.1.1.2.44.1  pgoyette  * Returns true if this is a valid feature@ property.
    180  1.1.1.2.44.1  pgoyette  */
    181  1.1.1.2.44.1  pgoyette boolean_t
    182  1.1.1.2.44.1  pgoyette zpool_prop_feature(const char *name)
    183  1.1.1.2.44.1  pgoyette {
    184  1.1.1.2.44.1  pgoyette 	static const char *prefix = "feature@";
    185  1.1.1.2.44.1  pgoyette 	return (strncmp(name, prefix, strlen(prefix)) == 0);
    186  1.1.1.2.44.1  pgoyette }
    187  1.1.1.2.44.1  pgoyette 
    188  1.1.1.2.44.1  pgoyette /*
    189  1.1.1.2.44.1  pgoyette  * Returns true if this is a valid unsupported@ property.
    190  1.1.1.2.44.1  pgoyette  */
    191  1.1.1.2.44.1  pgoyette boolean_t
    192  1.1.1.2.44.1  pgoyette zpool_prop_unsupported(const char *name)
    193  1.1.1.2.44.1  pgoyette {
    194  1.1.1.2.44.1  pgoyette 	static const char *prefix = "unsupported@";
    195  1.1.1.2.44.1  pgoyette 	return (strncmp(name, prefix, strlen(prefix)) == 0);
    196  1.1.1.2.44.1  pgoyette }
    197  1.1.1.2.44.1  pgoyette 
    198           1.1      haad int
    199           1.1      haad zpool_prop_string_to_index(zpool_prop_t prop, const char *string,
    200           1.1      haad     uint64_t *index)
    201           1.1      haad {
    202           1.1      haad 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_POOL));
    203           1.1      haad }
    204           1.1      haad 
    205           1.1      haad int
    206           1.1      haad zpool_prop_index_to_string(zpool_prop_t prop, uint64_t index,
    207           1.1      haad     const char **string)
    208           1.1      haad {
    209           1.1      haad 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_POOL));
    210           1.1      haad }
    211           1.1      haad 
    212       1.1.1.2      haad uint64_t
    213       1.1.1.2      haad zpool_prop_random_value(zpool_prop_t prop, uint64_t seed)
    214       1.1.1.2      haad {
    215       1.1.1.2      haad 	return (zprop_random_value(prop, seed, ZFS_TYPE_POOL));
    216       1.1.1.2      haad }
    217       1.1.1.2      haad 
    218           1.1      haad #ifndef _KERNEL
    219           1.1      haad 
    220           1.1      haad const char *
    221           1.1      haad zpool_prop_values(zpool_prop_t prop)
    222           1.1      haad {
    223           1.1      haad 	return (zpool_prop_table[prop].pd_values);
    224           1.1      haad }
    225           1.1      haad 
    226           1.1      haad const char *
    227           1.1      haad zpool_prop_column_name(zpool_prop_t prop)
    228           1.1      haad {
    229           1.1      haad 	return (zpool_prop_table[prop].pd_colname);
    230           1.1      haad }
    231           1.1      haad 
    232           1.1      haad boolean_t
    233           1.1      haad zpool_prop_align_right(zpool_prop_t prop)
    234           1.1      haad {
    235           1.1      haad 	return (zpool_prop_table[prop].pd_rightalign);
    236           1.1      haad }
    237           1.1      haad #endif
    238