1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
  23  */
  24 
  25 #include <sys/zio.h>
  26 #include <sys/spa.h>
  27 #include <sys/zfs_ioctl.h>
  28 #include <sys/fs/zfs.h>
  29 
  30 #include "zfs_prop.h"
  31 
  32 #if defined(_KERNEL)
  33 #include <sys/systm.h>
  34 #else
  35 #include <stdlib.h>
  36 #include <string.h>
  37 #include <ctype.h>
  38 #endif
  39 
  40 static zprop_desc_t vdev_prop_table[VDEV_NUM_PROPS];
  41 
  42 zprop_desc_t *
  43 vdev_prop_get_table(void)
  44 {
  45         return (vdev_prop_table);
  46 }
  47 
  48 void
  49 vdev_prop_init(void)
  50 {
  51         static zprop_index_t boolean_table[] = {
  52                 { "off",        0},
  53                 { "on",         1},
  54                 { NULL }
  55         };
  56 
  57         /* index properties */
  58         zprop_register_index(VDEV_PROP_L2ADDDT, "l2arc_ddt", 0,
  59             PROP_DEFAULT, ZFS_TYPE_VDEV, "on | off",
  60             "<cache DDT on this L2ARC device>", boolean_table);
  61 
  62         /* string properties */
  63         zprop_register_string(VDEV_PROP_PATH, "path", NULL,
  64             PROP_READONLY, ZFS_TYPE_VDEV, "<path>", "PATH");
  65         zprop_register_string(VDEV_PROP_FRU, "fru", NULL,
  66             PROP_READONLY, ZFS_TYPE_VDEV, "<fru>", "FRU");
  67         zprop_register_string(VDEV_PROP_COS, "cos", NULL,
  68             PROP_DEFAULT, ZFS_TYPE_VDEV, "<class of storage>", "COS");
  69         zprop_register_string(VDEV_PROP_SPAREGROUP, "sparegroup", NULL,
  70             PROP_DEFAULT, ZFS_TYPE_VDEV, "<spare device group>", "SPRGRP");
  71 
  72         /* default number properties */
  73         zprop_register_number(VDEV_PROP_GUID, "guid", 0,
  74             PROP_READONLY, ZFS_TYPE_VDEV, "<vdev guid>", "GUID");
  75         zprop_register_number(VDEV_PROP_READ_MINACTIVE, "read_minactive", 0,
  76             PROP_DEFAULT, ZFS_TYPE_VDEV, "<read min active (0..1000)>",
  77             "READ_MINACTIVE");
  78         zprop_register_number(VDEV_PROP_READ_MAXACTIVE, "read_maxactive", 0,
  79             PROP_DEFAULT, ZFS_TYPE_VDEV, "<read max active (0..1000)>",
  80             "READ_MAXACTIVE");
  81         zprop_register_number(VDEV_PROP_AREAD_MINACTIVE, "aread_minactive", 0,
  82             PROP_DEFAULT, ZFS_TYPE_VDEV, "<async read min active (0..1000)>",
  83             "AREAD_MINACTIVE");
  84         zprop_register_number(VDEV_PROP_AREAD_MAXACTIVE, "aread_maxactive", 0,
  85             PROP_DEFAULT, ZFS_TYPE_VDEV, "<async read max active (0..1000)>",
  86             "AREAD_MAXACTIVE");
  87         zprop_register_number(VDEV_PROP_WRITE_MINACTIVE, "write_minactive", 0,
  88             PROP_DEFAULT, ZFS_TYPE_VDEV, "<write min active (0..1000)>",
  89             "WRITE_MINACTIVE");
  90         zprop_register_number(VDEV_PROP_WRITE_MAXACTIVE, "write_maxactive", 0,
  91             PROP_DEFAULT, ZFS_TYPE_VDEV, "<write max active (0..1000)>",
  92             "WRITE_MAXACTIVE");
  93         zprop_register_number(VDEV_PROP_AWRITE_MINACTIVE, "awrite_minactive", 0,
  94             PROP_DEFAULT, ZFS_TYPE_VDEV, "<async write min active (0..1000)>",
  95             "AWRITE_MINACTIVE");
  96         zprop_register_number(VDEV_PROP_AWRITE_MAXACTIVE, "awrite_maxactive", 0,
  97             PROP_DEFAULT, ZFS_TYPE_VDEV, "<async write max active (0..1000)>",
  98             "AWRITE_MAXACTIVE");
  99         zprop_register_number(VDEV_PROP_SCRUB_MINACTIVE, "scrub_minactive", 0,
 100             PROP_DEFAULT, ZFS_TYPE_VDEV, "<scrub min active (0..1000)>",
 101             "SCRUB_MINACTIVE");
 102         zprop_register_number(VDEV_PROP_SCRUB_MAXACTIVE, "scrub_maxactive", 0,
 103             PROP_DEFAULT, ZFS_TYPE_VDEV, "<scrub max active (0..1000)>",
 104             "SCRUB_MAXACTIVE");
 105         zprop_register_number(VDEV_PROP_RESILVER_MINACTIVE,
 106             "resilver_minactive", 0, PROP_DEFAULT, ZFS_TYPE_VDEV,
 107             "<resilver min active (0..1000)>", "RESILVER_MINACTIVE");
 108         zprop_register_number(VDEV_PROP_RESILVER_MAXACTIVE,
 109             "resilver_maxactive", 0, PROP_DEFAULT, ZFS_TYPE_VDEV,
 110             "<resilver max active (0..1000)>", "RESILVER_MAXACTIVE");
 111         zprop_register_number(VDEV_PROP_PREFERRED_READ, "prefread", 0,
 112             PROP_DEFAULT, ZFS_TYPE_VDEV, "<preferred read (0..100)>",
 113             "PREFREAD");
 114 }
 115 
 116 /*
 117  * Given a property name and its type, returns the corresponding property ID.
 118  */
 119 vdev_prop_t
 120 vdev_name_to_prop(const char *propname)
 121 {
 122         return (zprop_name_to_prop(propname, ZFS_TYPE_VDEV));
 123 }
 124 
 125 /*
 126  * Given a vdev property ID, returns the corresponding name.
 127  * Assuming the vdev propety ID is valid.
 128  */
 129 const char *
 130 vdev_prop_to_name(vdev_prop_t prop)
 131 {
 132         return (vdev_prop_table[prop].pd_name);
 133 }
 134 
 135 zprop_type_t
 136 vdev_prop_get_type(vdev_prop_t prop)
 137 {
 138         return (vdev_prop_table[prop].pd_proptype);
 139 }
 140 
 141 boolean_t
 142 vdev_prop_readonly(vdev_prop_t prop)
 143 {
 144         return (vdev_prop_table[prop].pd_attr == PROP_READONLY);
 145 }
 146 
 147 const char *
 148 vdev_prop_default_string(vdev_prop_t prop)
 149 {
 150         return (vdev_prop_table[prop].pd_strdefault);
 151 }
 152 
 153 uint64_t
 154 vdev_prop_default_numeric(vdev_prop_t prop)
 155 {
 156         return (vdev_prop_table[prop].pd_numdefault);
 157 }
 158 
 159 int
 160 vdev_prop_string_to_index(vdev_prop_t prop, const char *string,
 161     uint64_t *index)
 162 {
 163         return (zprop_string_to_index(prop, string, index, ZFS_TYPE_VDEV));
 164 }
 165 
 166 int
 167 vdev_prop_index_to_string(vdev_prop_t prop, uint64_t index,
 168     const char **string)
 169 {
 170         return (zprop_index_to_string(prop, index, string, ZFS_TYPE_VDEV));
 171 }
 172 
 173 uint64_t
 174 vdev_prop_random_value(vdev_prop_t prop, uint64_t seed)
 175 {
 176         return (zprop_random_value(prop, seed, ZFS_TYPE_VDEV));
 177 }
 178 
 179 #ifndef _KERNEL
 180 
 181 const char *
 182 vdev_prop_values(vdev_prop_t prop)
 183 {
 184         return (vdev_prop_table[prop].pd_values);
 185 }
 186 
 187 const char *
 188 vdev_prop_column_name(vdev_prop_t prop)
 189 {
 190         return (vdev_prop_table[prop].pd_colname);
 191 }
 192 
 193 boolean_t
 194 vdev_prop_align_right(vdev_prop_t prop)
 195 {
 196         return (vdev_prop_table[prop].pd_rightalign);
 197 }
 198 #endif