2008-11-20 20:01:55 +00:00
|
|
|
/*
|
|
|
|
* CDDL HEADER START
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the terms of the
|
|
|
|
* Common Development and Distribution License (the "License").
|
|
|
|
* You may not use this file except in compliance with the License.
|
|
|
|
*
|
|
|
|
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
|
|
|
* or http://www.opensolaris.org/os/licensing.
|
|
|
|
* See the License for the specific language governing permissions
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* When distributing Covered Code, include this CDDL HEADER in each
|
|
|
|
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
|
|
|
* If applicable, add the following below this CDDL HEADER, with the
|
|
|
|
* fields enclosed by brackets "[]" replaced with your own identifying
|
|
|
|
* information: Portions Copyright [yyyy] [name of copyright owner]
|
|
|
|
*
|
|
|
|
* CDDL HEADER END
|
|
|
|
*/
|
|
|
|
/*
|
2010-08-26 21:24:34 +00:00
|
|
|
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
|
2011-11-15 19:01:27 +00:00
|
|
|
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
|
2012-01-24 02:43:32 +00:00
|
|
|
* Copyright (c) 2012 by Delphix. All rights reserved.
|
2008-11-20 20:01:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/zio.h>
|
|
|
|
#include <sys/spa.h>
|
|
|
|
#include <sys/zfs_acl.h>
|
|
|
|
#include <sys/zfs_ioctl.h>
|
|
|
|
#include <sys/fs/zfs.h>
|
|
|
|
|
|
|
|
#include "zfs_prop.h"
|
|
|
|
|
|
|
|
#if defined(_KERNEL)
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#else
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static zprop_desc_t zpool_prop_table[ZPOOL_NUM_PROPS];
|
|
|
|
|
|
|
|
zprop_desc_t *
|
|
|
|
zpool_prop_get_table(void)
|
|
|
|
{
|
|
|
|
return (zpool_prop_table);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
zpool_prop_init(void)
|
|
|
|
{
|
|
|
|
static zprop_index_t boolean_table[] = {
|
|
|
|
{ "off", 0},
|
|
|
|
{ "on", 1},
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static zprop_index_t failuremode_table[] = {
|
|
|
|
{ "wait", ZIO_FAILURE_MODE_WAIT },
|
|
|
|
{ "continue", ZIO_FAILURE_MODE_CONTINUE },
|
|
|
|
{ "panic", ZIO_FAILURE_MODE_PANIC },
|
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* string properties */
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_string(ZPOOL_PROP_ALTROOT, "altroot", NULL, PROP_DEFAULT,
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_TYPE_POOL, "<path>", "ALTROOT");
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_string(ZPOOL_PROP_BOOTFS, "bootfs", NULL, PROP_DEFAULT,
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_TYPE_POOL, "<filesystem>", "BOOTFS");
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_string(ZPOOL_PROP_CACHEFILE, "cachefile", NULL,
|
|
|
|
PROP_DEFAULT, ZFS_TYPE_POOL, "<file> | none", "CACHEFILE");
|
2011-11-15 19:01:27 +00:00
|
|
|
zprop_register_string(ZPOOL_PROP_COMMENT, "comment", NULL,
|
|
|
|
PROP_DEFAULT, ZFS_TYPE_POOL, "<comment-string>", "COMMENT");
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/* readonly number properties */
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_number(ZPOOL_PROP_SIZE, "size", 0, PROP_READONLY,
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_TYPE_POOL, "<size>", "SIZE");
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_number(ZPOOL_PROP_FREE, "free", 0, PROP_READONLY,
|
|
|
|
ZFS_TYPE_POOL, "<size>", "FREE");
|
2012-12-13 23:24:15 +00:00
|
|
|
zprop_register_number(ZPOOL_PROP_FREEING, "freeing", 0, PROP_READONLY,
|
|
|
|
ZFS_TYPE_POOL, "<size>", "FREEING");
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_number(ZPOOL_PROP_ALLOCATED, "allocated", 0,
|
|
|
|
PROP_READONLY, ZFS_TYPE_POOL, "<size>", "ALLOC");
|
2012-01-24 02:43:32 +00:00
|
|
|
zprop_register_number(ZPOOL_PROP_EXPANDSZ, "expandsize", 0,
|
|
|
|
PROP_READONLY, ZFS_TYPE_POOL, "<size>", "EXPANDSZ");
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_number(ZPOOL_PROP_CAPACITY, "capacity", 0, PROP_READONLY,
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_TYPE_POOL, "<size>", "CAP");
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_number(ZPOOL_PROP_GUID, "guid", 0, PROP_READONLY,
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_TYPE_POOL, "<guid>", "GUID");
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_number(ZPOOL_PROP_HEALTH, "health", 0, PROP_READONLY,
|
2008-11-20 20:01:55 +00:00
|
|
|
ZFS_TYPE_POOL, "<state>", "HEALTH");
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_number(ZPOOL_PROP_DEDUPRATIO, "dedupratio", 0,
|
|
|
|
PROP_READONLY, ZFS_TYPE_POOL, "<1.00x or higher if deduped>",
|
|
|
|
"DEDUP");
|
2008-11-20 20:01:55 +00:00
|
|
|
|
2011-06-16 19:56:38 +00:00
|
|
|
/* readonly onetime number properties */
|
|
|
|
zprop_register_number(ZPOOL_PROP_ASHIFT, "ashift", 0, PROP_ONETIME,
|
2012-02-13 15:38:58 +00:00
|
|
|
ZFS_TYPE_POOL, "<ashift, 9-13, or 0=default>", "ASHIFT");
|
2011-06-16 19:56:38 +00:00
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
/* default number properties */
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_number(ZPOOL_PROP_VERSION, "version", SPA_VERSION,
|
2008-11-20 20:01:55 +00:00
|
|
|
PROP_DEFAULT, ZFS_TYPE_POOL, "<version>", "VERSION");
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_number(ZPOOL_PROP_DEDUPDITTO, "dedupditto", 0,
|
|
|
|
PROP_DEFAULT, ZFS_TYPE_POOL, "<threshold (min 100)>", "DEDUPDITTO");
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/* default index (boolean) properties */
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_index(ZPOOL_PROP_DELEGATION, "delegation", 1,
|
|
|
|
PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "DELEGATION",
|
|
|
|
boolean_table);
|
|
|
|
zprop_register_index(ZPOOL_PROP_AUTOREPLACE, "autoreplace", 0,
|
|
|
|
PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "REPLACE", boolean_table);
|
|
|
|
zprop_register_index(ZPOOL_PROP_LISTSNAPS, "listsnapshots", 0,
|
|
|
|
PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "LISTSNAPS",
|
|
|
|
boolean_table);
|
|
|
|
zprop_register_index(ZPOOL_PROP_AUTOEXPAND, "autoexpand", 0,
|
|
|
|
PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "EXPAND", boolean_table);
|
2010-08-26 21:24:34 +00:00
|
|
|
zprop_register_index(ZPOOL_PROP_READONLY, "readonly", 0,
|
|
|
|
PROP_DEFAULT, ZFS_TYPE_POOL, "on | off", "RDONLY", boolean_table);
|
2008-11-20 20:01:55 +00:00
|
|
|
|
|
|
|
/* default index properties */
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_index(ZPOOL_PROP_FAILUREMODE, "failmode",
|
2008-11-20 20:01:55 +00:00
|
|
|
ZIO_FAILURE_MODE_WAIT, PROP_DEFAULT, ZFS_TYPE_POOL,
|
|
|
|
"wait | continue | panic", "FAILMODE", failuremode_table);
|
|
|
|
|
|
|
|
/* hidden properties */
|
2010-05-28 20:45:14 +00:00
|
|
|
zprop_register_hidden(ZPOOL_PROP_NAME, "name", PROP_TYPE_STRING,
|
2008-11-20 20:01:55 +00:00
|
|
|
PROP_READONLY, ZFS_TYPE_POOL, "NAME");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a property name and its type, returns the corresponding property ID.
|
|
|
|
*/
|
|
|
|
zpool_prop_t
|
|
|
|
zpool_name_to_prop(const char *propname)
|
|
|
|
{
|
|
|
|
return (zprop_name_to_prop(propname, ZFS_TYPE_POOL));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a pool property ID, returns the corresponding name.
|
|
|
|
* Assuming the pool propety ID is valid.
|
|
|
|
*/
|
|
|
|
const char *
|
|
|
|
zpool_prop_to_name(zpool_prop_t prop)
|
|
|
|
{
|
|
|
|
return (zpool_prop_table[prop].pd_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
zprop_type_t
|
|
|
|
zpool_prop_get_type(zpool_prop_t prop)
|
|
|
|
{
|
|
|
|
return (zpool_prop_table[prop].pd_proptype);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean_t
|
|
|
|
zpool_prop_readonly(zpool_prop_t prop)
|
|
|
|
{
|
|
|
|
return (zpool_prop_table[prop].pd_attr == PROP_READONLY);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
zpool_prop_default_string(zpool_prop_t prop)
|
|
|
|
{
|
|
|
|
return (zpool_prop_table[prop].pd_strdefault);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t
|
|
|
|
zpool_prop_default_numeric(zpool_prop_t prop)
|
|
|
|
{
|
|
|
|
return (zpool_prop_table[prop].pd_numdefault);
|
|
|
|
}
|
|
|
|
|
2012-12-13 23:24:15 +00:00
|
|
|
/*
|
|
|
|
* Returns true if this is a valid feature@ property.
|
|
|
|
*/
|
|
|
|
boolean_t
|
|
|
|
zpool_prop_feature(const char *name)
|
|
|
|
{
|
|
|
|
static const char *prefix = "feature@";
|
|
|
|
return (strncmp(name, prefix, strlen(prefix)) == 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns true if this is a valid unsupported@ property.
|
|
|
|
*/
|
|
|
|
boolean_t
|
|
|
|
zpool_prop_unsupported(const char *name)
|
|
|
|
{
|
|
|
|
static const char *prefix = "unsupported@";
|
|
|
|
return (strncmp(name, prefix, strlen(prefix)) == 0);
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
int
|
|
|
|
zpool_prop_string_to_index(zpool_prop_t prop, const char *string,
|
|
|
|
uint64_t *index)
|
|
|
|
{
|
|
|
|
return (zprop_string_to_index(prop, string, index, ZFS_TYPE_POOL));
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
zpool_prop_index_to_string(zpool_prop_t prop, uint64_t index,
|
|
|
|
const char **string)
|
|
|
|
{
|
|
|
|
return (zprop_index_to_string(prop, index, string, ZFS_TYPE_POOL));
|
|
|
|
}
|
|
|
|
|
2010-05-28 20:45:14 +00:00
|
|
|
uint64_t
|
|
|
|
zpool_prop_random_value(zpool_prop_t prop, uint64_t seed)
|
|
|
|
{
|
|
|
|
return (zprop_random_value(prop, seed, ZFS_TYPE_POOL));
|
|
|
|
}
|
|
|
|
|
2008-11-20 20:01:55 +00:00
|
|
|
#ifndef _KERNEL
|
|
|
|
|
|
|
|
const char *
|
|
|
|
zpool_prop_values(zpool_prop_t prop)
|
|
|
|
{
|
|
|
|
return (zpool_prop_table[prop].pd_values);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
zpool_prop_column_name(zpool_prop_t prop)
|
|
|
|
{
|
|
|
|
return (zpool_prop_table[prop].pd_colname);
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean_t
|
|
|
|
zpool_prop_align_right(zpool_prop_t prop)
|
|
|
|
{
|
|
|
|
return (zpool_prop_table[prop].pd_rightalign);
|
|
|
|
}
|
|
|
|
#endif
|
2010-08-26 18:49:16 +00:00
|
|
|
|
|
|
|
#if defined(_KERNEL) && defined(HAVE_SPL)
|
|
|
|
/* zpool property functions */
|
|
|
|
EXPORT_SYMBOL(zpool_prop_init);
|
|
|
|
EXPORT_SYMBOL(zpool_prop_get_type);
|
|
|
|
EXPORT_SYMBOL(zpool_prop_get_table);
|
|
|
|
|
|
|
|
/* Pool property functions shared between libzfs and kernel. */
|
|
|
|
EXPORT_SYMBOL(zpool_name_to_prop);
|
|
|
|
EXPORT_SYMBOL(zpool_prop_to_name);
|
|
|
|
EXPORT_SYMBOL(zpool_prop_default_string);
|
|
|
|
EXPORT_SYMBOL(zpool_prop_default_numeric);
|
|
|
|
EXPORT_SYMBOL(zpool_prop_readonly);
|
2012-12-13 23:24:15 +00:00
|
|
|
EXPORT_SYMBOL(zpool_prop_feature);
|
|
|
|
EXPORT_SYMBOL(zpool_prop_unsupported);
|
2010-08-26 18:49:16 +00:00
|
|
|
EXPORT_SYMBOL(zpool_prop_index_to_string);
|
|
|
|
EXPORT_SYMBOL(zpool_prop_string_to_index);
|
|
|
|
#endif
|