Home | History | Annotate | Line # | Download | only in zfs
zpool_prop.c revision 1.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  haad  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
     23  1.1  haad  * Use is subject to license terms.
     24  1.1  haad  */
     25  1.1  haad 
     26  1.1  haad #include <sys/zio.h>
     27  1.1  haad #include <sys/spa.h>
     28  1.1  haad #include <sys/zfs_acl.h>
     29  1.1  haad #include <sys/zfs_ioctl.h>
     30  1.1  haad #include <sys/fs/zfs.h>
     31  1.1  haad 
     32  1.1  haad #include "zfs_prop.h"
     33  1.1  haad 
     34  1.1  haad #if defined(_KERNEL)
     35  1.1  haad #include <sys/systm.h>
     36  1.1  haad #else
     37  1.1  haad #include <stdlib.h>
     38  1.1  haad #include <string.h>
     39  1.1  haad #include <ctype.h>
     40  1.1  haad #endif
     41  1.1  haad 
     42  1.1  haad static zprop_desc_t zpool_prop_table[ZPOOL_NUM_PROPS];
     43  1.1  haad 
     44  1.1  haad zprop_desc_t *
     45  1.1  haad zpool_prop_get_table(void)
     46  1.1  haad {
     47  1.1  haad 	return (zpool_prop_table);
     48  1.1  haad }
     49  1.1  haad 
     50  1.1  haad void
     51  1.1  haad zpool_prop_init(void)
     52  1.1  haad {
     53  1.1  haad 	static zprop_index_t boolean_table[] = {
     54  1.1  haad 		{ "off",	0},
     55  1.1  haad 		{ "on",		1},
     56  1.1  haad 		{ NULL }
     57  1.1  haad 	};
     58  1.1  haad 
     59  1.1  haad 	static zprop_index_t failuremode_table[] = {
     60  1.1  haad 		{ "wait",	ZIO_FAILURE_MODE_WAIT },
     61  1.1  haad 		{ "continue",	ZIO_FAILURE_MODE_CONTINUE },
     62  1.1  haad 		{ "panic",	ZIO_FAILURE_MODE_PANIC },
     63  1.1  haad 		{ NULL }
     64  1.1  haad 	};
     65  1.1  haad 
     66  1.1  haad 	/* string properties */
     67  1.1  haad 	register_string(ZPOOL_PROP_ALTROOT, "altroot", NULL, PROP_DEFAULT,
     68  1.1  haad 	    ZFS_TYPE_POOL, "<path>", "ALTROOT");
     69  1.1  haad 	register_string(ZPOOL_PROP_BOOTFS, "bootfs", NULL, PROP_DEFAULT,
     70  1.1  haad 	    ZFS_TYPE_POOL, "<filesystem>", "BOOTFS");
     71  1.1  haad 	register_string(ZPOOL_PROP_CACHEFILE, "cachefile", NULL, PROP_DEFAULT,
     72  1.1  haad 	    ZFS_TYPE_POOL, "<file> | none", "CACHEFILE");
     73  1.1  haad 
     74  1.1  haad 	/* readonly number properties */
     75  1.1  haad 	register_number(ZPOOL_PROP_SIZE, "size", 0, PROP_READONLY,
     76  1.1  haad 	    ZFS_TYPE_POOL, "<size>", "SIZE");
     77  1.1  haad 	register_number(ZPOOL_PROP_USED, "used", 0, PROP_READONLY,
     78  1.1  haad 	    ZFS_TYPE_POOL, "<size>", "USED");
     79  1.1  haad 	register_number(ZPOOL_PROP_AVAILABLE, "available", 0, PROP_READONLY,
     80  1.1  haad 	    ZFS_TYPE_POOL, "<size>", "AVAIL");
     81  1.1  haad 	register_number(ZPOOL_PROP_CAPACITY, "capacity", 0, PROP_READONLY,
     82  1.1  haad 	    ZFS_TYPE_POOL, "<size>", "CAP");
     83  1.1  haad 	register_number(ZPOOL_PROP_GUID, "guid", 0, PROP_READONLY,
     84  1.1  haad 	    ZFS_TYPE_POOL, "<guid>", "GUID");
     85  1.1  haad 	register_number(ZPOOL_PROP_HEALTH, "health", 0, PROP_READONLY,
     86  1.1  haad 	    ZFS_TYPE_POOL, "<state>", "HEALTH");
     87  1.1  haad 
     88  1.1  haad 	/* default number properties */
     89  1.1  haad 	register_number(ZPOOL_PROP_VERSION, "version", SPA_VERSION,
     90  1.1  haad 	    PROP_DEFAULT, ZFS_TYPE_POOL, "<version>", "VERSION");
     91  1.1  haad 
     92  1.1  haad 	/* default index (boolean) properties */
     93  1.1  haad 	register_index(ZPOOL_PROP_DELEGATION, "delegation", 1, PROP_DEFAULT,
     94  1.1  haad 	    ZFS_TYPE_POOL, "on | off", "DELEGATION", boolean_table);
     95  1.1  haad 	register_index(ZPOOL_PROP_AUTOREPLACE, "autoreplace", 0, PROP_DEFAULT,
     96  1.1  haad 	    ZFS_TYPE_POOL, "on | off", "REPLACE", boolean_table);
     97  1.1  haad 	register_index(ZPOOL_PROP_LISTSNAPS, "listsnapshots", 0, PROP_DEFAULT,
     98  1.1  haad 	    ZFS_TYPE_POOL, "on | off", "LISTSNAPS", boolean_table);
     99  1.1  haad 
    100  1.1  haad 	/* default index properties */
    101  1.1  haad 	register_index(ZPOOL_PROP_FAILUREMODE, "failmode",
    102  1.1  haad 	    ZIO_FAILURE_MODE_WAIT, PROP_DEFAULT, ZFS_TYPE_POOL,
    103  1.1  haad 	    "wait | continue | panic", "FAILMODE", failuremode_table);
    104  1.1  haad 
    105  1.1  haad 	/* hidden properties */
    106  1.1  haad 	register_hidden(ZPOOL_PROP_NAME, "name", PROP_TYPE_STRING,
    107  1.1  haad 	    PROP_READONLY, ZFS_TYPE_POOL, "NAME");
    108  1.1  haad }
    109  1.1  haad 
    110  1.1  haad /*
    111  1.1  haad  * Given a property name and its type, returns the corresponding property ID.
    112  1.1  haad  */
    113  1.1  haad zpool_prop_t
    114  1.1  haad zpool_name_to_prop(const char *propname)
    115  1.1  haad {
    116  1.1  haad 	return (zprop_name_to_prop(propname, ZFS_TYPE_POOL));
    117  1.1  haad }
    118  1.1  haad 
    119  1.1  haad /*
    120  1.1  haad  * Given a pool property ID, returns the corresponding name.
    121  1.1  haad  * Assuming the pool propety ID is valid.
    122  1.1  haad  */
    123  1.1  haad const char *
    124  1.1  haad zpool_prop_to_name(zpool_prop_t prop)
    125  1.1  haad {
    126  1.1  haad 	return (zpool_prop_table[prop].pd_name);
    127  1.1  haad }
    128  1.1  haad 
    129  1.1  haad zprop_type_t
    130  1.1  haad zpool_prop_get_type(zpool_prop_t prop)
    131  1.1  haad {
    132  1.1  haad 	return (zpool_prop_table[prop].pd_proptype);
    133  1.1  haad }
    134  1.1  haad 
    135  1.1  haad boolean_t
    136  1.1  haad zpool_prop_readonly(zpool_prop_t prop)
    137  1.1  haad {
    138  1.1  haad 	return (zpool_prop_table[prop].pd_attr == PROP_READONLY);
    139  1.1  haad }
    140  1.1  haad 
    141  1.1  haad const char *
    142  1.1  haad zpool_prop_default_string(zpool_prop_t prop)
    143  1.1  haad {
    144  1.1  haad 	return (zpool_prop_table[prop].pd_strdefault);
    145  1.1  haad }
    146  1.1  haad 
    147  1.1  haad uint64_t
    148  1.1  haad zpool_prop_default_numeric(zpool_prop_t prop)
    149  1.1  haad {
    150  1.1  haad 	return (zpool_prop_table[prop].pd_numdefault);
    151  1.1  haad }
    152  1.1  haad 
    153  1.1  haad int
    154  1.1  haad zpool_prop_string_to_index(zpool_prop_t prop, const char *string,
    155  1.1  haad     uint64_t *index)
    156  1.1  haad {
    157  1.1  haad 	return (zprop_string_to_index(prop, string, index, ZFS_TYPE_POOL));
    158  1.1  haad }
    159  1.1  haad 
    160  1.1  haad int
    161  1.1  haad zpool_prop_index_to_string(zpool_prop_t prop, uint64_t index,
    162  1.1  haad     const char **string)
    163  1.1  haad {
    164  1.1  haad 	return (zprop_index_to_string(prop, index, string, ZFS_TYPE_POOL));
    165  1.1  haad }
    166  1.1  haad 
    167  1.1  haad #ifndef _KERNEL
    168  1.1  haad 
    169  1.1  haad const char *
    170  1.1  haad zpool_prop_values(zpool_prop_t prop)
    171  1.1  haad {
    172  1.1  haad 	return (zpool_prop_table[prop].pd_values);
    173  1.1  haad }
    174  1.1  haad 
    175  1.1  haad const char *
    176  1.1  haad zpool_prop_column_name(zpool_prop_t prop)
    177  1.1  haad {
    178  1.1  haad 	return (zpool_prop_table[prop].pd_colname);
    179  1.1  haad }
    180  1.1  haad 
    181  1.1  haad boolean_t
    182  1.1  haad zpool_prop_align_right(zpool_prop_t prop)
    183  1.1  haad {
    184  1.1  haad 	return (zpool_prop_table[prop].pd_rightalign);
    185  1.1  haad }
    186  1.1  haad #endif
    187