Skip to content

Commit 72d3020

Browse files
mmaybeeallanjude
authored andcommitted
Rename "noalloc" vdev property to "allocating"
Add support for read-only "removing" vdev property Simplify get vdev prop interface to always require pool name Refactor space management for non-allocating devices Add ability to remove user vdev property by setting value to ""
1 parent 2debf5f commit 72d3020

File tree

11 files changed

+162
-111
lines changed

11 files changed

+162
-111
lines changed

cmd/zhack/zhack.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,6 @@ static int
474474
zhack_do_zap(int argc, char **argv)
475475
{
476476
spa_t *spa;
477-
objset_t *os;
478477
uint64_t obj;
479478
char *target;
480479

@@ -493,9 +492,8 @@ zhack_do_zap(int argc, char **argv)
493492
obj = strtoull(argv[1], NULL, 0);
494493

495494
zhack_spa_open(target, B_TRUE, FTAG, &spa);
496-
os = spa->spa_meta_objset;
497495

498-
dump_obj(os, obj, argv[1]);
496+
dump_obj(spa->spa_meta_objset, obj, argv[1]);
499497

500498
spa_close(spa, FTAG);
501499

cmd/zpool/zpool_iter.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,9 @@ for_each_vdev_cb(zpool_handle_t *zhp, nvlist_t *nv, pool_vdev_iter_f func,
304304
if (nvlist_lookup_string(nv, ZPOOL_CONFIG_TYPE, &type) != 0)
305305
return (ret);
306306

307-
/* Don't run our function on root vdevs */
308-
if (strcmp(type, VDEV_TYPE_ROOT) != 0) {
307+
/* Don't run our function on root or indirect vdevs */
308+
if ((strcmp(type, VDEV_TYPE_ROOT) != 0) &&
309+
(strcmp(type, VDEV_TYPE_INDIRECT) != 0)) {
309310
ret |= func(zhp, nv, data);
310311
}
311312

cmd/zpool/zpool_main.c

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ static zpool_command_t command_table[] = {
331331
#define VDEV_ALLOC_CLASS_LOGS "logs"
332332

333333
static zpool_command_t *current_command;
334-
static zfs_type_t current_prop_type = ZFS_TYPE_POOL;
334+
static zfs_type_t current_prop_type = (ZFS_TYPE_POOL | ZFS_TYPE_VDEV);
335335
static char history_str[HIS_MAX_RECORD_LEN];
336336
static boolean_t log_history = B_TRUE;
337337
static uint_t timestamp_fmt = NODATE;
@@ -488,7 +488,7 @@ print_prop_cb(int prop, void *cb)
488488
}
489489

490490
/*
491-
* Callback routine that will print out a pool property value.
491+
* Callback routine that will print out a vdev property value.
492492
*/
493493
static int
494494
print_vdev_prop_cb(int prop, void *cb)
@@ -540,6 +540,7 @@ usage(boolean_t requested)
540540
}
541541

542542
if (current_command != NULL &&
543+
current_prop_type != (ZFS_TYPE_POOL | ZFS_TYPE_VDEV) &&
543544
((strcmp(current_command->name, "set") == 0) ||
544545
(strcmp(current_command->name, "get") == 0) ||
545546
(strcmp(current_command->name, "list") == 0))) {
@@ -826,7 +827,7 @@ add_prop_list(const char *propname, char *propval, nvlist_t **props,
826827
(!zpool_prop_feature(propname) ||
827828
zpool_prop_vdev(propname))) {
828829
(void) fprintf(stderr, gettext("property '%s' is "
829-
"not a valid pool property\n"), propname);
830+
"not a valid pool or vdev property\n"), propname);
830831
return (2);
831832
}
832833

@@ -9886,6 +9887,7 @@ get_callback_vdev(zpool_handle_t *zhp, char *vdevname, void *data)
98869887
zprop_list_t *pl;
98879888

98889889
for (pl = cbp->cb_proplist; pl != NULL; pl = pl->pl_next) {
9890+
char *prop_name;
98899891
/*
98909892
* Skip the special fake placeholder. This will also skip
98919893
* over the name property when 'all' is specified.
@@ -9896,21 +9898,14 @@ get_callback_vdev(zpool_handle_t *zhp, char *vdevname, void *data)
98969898

98979899
if (pl->pl_prop == ZPROP_INVAL) {
98989900
/* User Properties */
9899-
if (zpool_get_vdev_prop(zhp, vdevname, pl->pl_prop,
9900-
pl->pl_user_prop, value, sizeof (value), &srctype,
9901-
cbp->cb_literal) == 0) {
9902-
zprop_print_one_property(
9903-
vdevname, cbp, pl->pl_user_prop, value,
9904-
srctype, NULL, NULL);
9905-
}
9901+
prop_name = pl->pl_user_prop;
99069902
} else {
9907-
if (zpool_get_vdev_prop(zhp, vdevname, pl->pl_prop,
9908-
NULL, value, sizeof (value), &srctype,
9909-
cbp->cb_literal) != 0)
9910-
continue;
9911-
9912-
zprop_print_one_property(
9913-
vdevname, cbp, vdev_prop_to_name(pl->pl_prop),
9903+
prop_name = (char *)vdev_prop_to_name(pl->pl_prop);
9904+
}
9905+
if (zpool_get_vdev_prop(zhp, vdevname, pl->pl_prop,
9906+
prop_name, value, sizeof (value), &srctype,
9907+
cbp->cb_literal) == 0) {
9908+
zprop_print_one_property(vdevname, cbp, prop_name,
99149909
value, srctype, NULL, NULL);
99159910
}
99169911
}
@@ -9956,20 +9951,20 @@ get_callback(zpool_handle_t *zhp, void *data)
99569951
int vid;
99579952

99589953
if (cbp->cb_type == ZFS_TYPE_VDEV) {
9959-
if (strcmp(cbp->cb_vdevs.cb_names[0], "all") == 0) {
9954+
if (strcmp(cbp->cb_vdevs.cb_names[0], "all-vdevs") == 0) {
99609955
for_each_vdev(zhp, get_callback_vdev_width_cb, data);
99619956
for_each_vdev(zhp, get_callback_vdev_cb, data);
99629957
} else {
9958+
/* Adjust column widths for vdev properties */
99639959
for (vid = 0; vid < cbp->cb_vdevs.cb_names_count;
99649960
vid++) {
9965-
/* Adjust column widths for vdev properties */
99669961
vdev_expand_proplist(zhp,
99679962
cbp->cb_vdevs.cb_names[vid],
99689963
&cbp->cb_proplist);
99699964
}
9965+
/* Display the properties */
99709966
for (vid = 0; vid < cbp->cb_vdevs.cb_names_count;
99719967
vid++) {
9972-
/* Display the properties */
99739968
get_callback_vdev(zhp,
99749969
cbp->cb_vdevs.cb_names[vid], data);
99759970
}
@@ -10133,24 +10128,18 @@ zpool_do_get(int argc, char **argv)
1013310128
/* No args, so just print the defaults. */
1013410129
} else if (are_all_pools(argc, argv)) {
1013510130
/* All the args are pool names */
10136-
} else if (are_vdevs_in_pool(argc, argv, NULL, &cb.cb_vdevs)) {
10137-
/* All the args are vdevs */
10138-
cb.cb_vdevs.cb_names = argv;
10139-
cb.cb_vdevs.cb_names_count = argc;
10140-
cb.cb_type = ZFS_TYPE_VDEV;
10141-
argc = 0; /* No pools to process */
1014210131
} else if (are_all_pools(1, argv)) {
1014310132
/* The first arg is a pool name */
10144-
if (are_vdevs_in_pool(argc - 1, argv + 1, argv[0],
10145-
&cb.cb_vdevs) || (strcmp(argv[1], "all") == 0)) {
10146-
/* ...and the rest are vdev names */
10133+
if ((argc == 2 && strcmp(argv[1], "all-vdevs") == 0) ||
10134+
are_vdevs_in_pool(argc - 1, argv + 1, argv[0],
10135+
&cb.cb_vdevs)) {
10136+
/* ... and the rest are vdev names */
1014710137
cb.cb_vdevs.cb_names = argv + 1;
1014810138
cb.cb_vdevs.cb_names_count = argc - 1;
1014910139
cb.cb_type = ZFS_TYPE_VDEV;
1015010140
argc = 1; /* One pool to process */
1015110141
} else {
10152-
fprintf(stderr, gettext("Expected either a list of "));
10153-
fprintf(stderr, gettext("pools, or list of vdevs in"));
10142+
fprintf(stderr, gettext("Expected a list of vdevs in"));
1015410143
fprintf(stderr, " \"%s\", ", argv[0]);
1015510144
fprintf(stderr, gettext("but got:\n"));
1015610145
error_list_unresolved_vdevs(argc - 1, argv + 1,
@@ -10161,11 +10150,11 @@ zpool_do_get(int argc, char **argv)
1016110150
}
1016210151
} else {
1016310152
/*
10164-
* The args don't make sense. The first arg isn't a pool name,
10165-
* nor are all the args vdevs.
10153+
* The first arg isn't a pool name,
1016610154
*/
10167-
fprintf(stderr, gettext("Unable to parse pools/vdevs list.\n"));
10155+
fprintf(stderr, gettext("missing pool name.\n"));
1016810156
fprintf(stderr, "\n");
10157+
usage(B_FALSE);
1016910158
return (1);
1017010159
}
1017110160

include/sys/fs/zfs.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ typedef enum {
347347
VDEV_PROP_BYTES_FREE,
348348
VDEV_PROP_BYTES_CLAIM,
349349
VDEV_PROP_BYTES_TRIM,
350-
VDEV_PROP_NOALLOC,
350+
VDEV_PROP_REMOVING,
351+
VDEV_PROP_ALLOCATING,
351352
VDEV_NUM_PROPS
352353
} vdev_prop_t;
353354

@@ -1152,7 +1153,6 @@ typedef struct vdev_stat {
11521153
uint64_t vs_checksum_errors; /* checksum errors */
11531154
uint64_t vs_initialize_errors; /* initializing errors */
11541155
uint64_t vs_self_healed; /* self-healed bytes */
1155-
uint64_t vs_noalloc; /* allocations halted? */
11561156
uint64_t vs_scan_removing; /* removing? */
11571157
uint64_t vs_scan_processed; /* scan processed bytes */
11581158
uint64_t vs_fragmentation; /* device fragmentation */
@@ -1173,6 +1173,7 @@ typedef struct vdev_stat {
11731173
uint64_t vs_configured_ashift; /* TLV vdev_ashift */
11741174
uint64_t vs_logical_ashift; /* vdev_logical_ashift */
11751175
uint64_t vs_physical_ashift; /* vdev_physical_ashift */
1176+
uint64_t vs_noalloc; /* allocations halted? */
11761177
} vdev_stat_t;
11771178

11781179
/* BEGIN CSTYLED */
@@ -1577,14 +1578,14 @@ typedef enum {
15771578
/*
15781579
* The following are names used when invoking ZFS_IOC_VDEV_GET_PROP.
15791580
*/
1580-
#define ZPOOL_VDEV_GET_PROPS_VDEV "vdevprops_get_vdev"
1581-
#define ZPOOL_VDEV_GET_PROPS_PROPS "vdevprops_get_props"
1581+
#define ZPOOL_VDEV_PROPS_GET_VDEV "vdevprops_get_vdev"
1582+
#define ZPOOL_VDEV_PROPS_GET_PROPS "vdevprops_get_props"
15821583

15831584
/*
15841585
* The following are names used when invoking ZFS_IOC_VDEV_SET_PROP.
15851586
*/
1586-
#define ZPOOL_VDEV_SET_PROPS_VDEV "vdevprops_set_vdev"
1587-
#define ZPOOL_VDEV_SET_PROPS_PROPS "vdevprops_set_props"
1587+
#define ZPOOL_VDEV_PROPS_SET_VDEV "vdevprops_set_vdev"
1588+
#define ZPOOL_VDEV_PROPS_SET_PROPS "vdevprops_set_props"
15881589

15891590
/*
15901591
* The following are names used when invoking ZFS_IOC_WAIT_FS.

include/sys/spa_impl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ struct spa {
305305
uint64_t spa_missing_tvds; /* unopenable tvds on load */
306306
uint64_t spa_missing_tvds_allowed; /* allow loading spa? */
307307

308+
uint64_t spa_nonallocating_dspace;
308309
spa_removing_phys_t spa_removing_phys;
309310
spa_vdev_removal_t *spa_vdev_removal;
310311

lib/libzfs/libzfs_pool.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5074,8 +5074,8 @@ zpool_get_vdev_prop_value(nvlist_t *nvprop, vdev_prop_t prop, char *prop_name,
50745074
verify(nvlist_lookup_string(nv, ZPROP_VALUE,
50755075
&strval) == 0);
50765076
} else {
5077-
src = ZPROP_SRC_NONE;
5078-
strval = "-";
5077+
/* user prop not found */
5078+
return (-1);
50795079
}
50805080
(void) strlcpy(buf, strval, len);
50815081
if (srctype)
@@ -5230,7 +5230,8 @@ zpool_get_vdev_prop(zpool_handle_t *zhp, const char *vdevname, vdev_prop_t prop,
52305230
char *prop_name, char *buf, size_t len, zprop_source_t *srctype,
52315231
boolean_t literal)
52325232
{
5233-
nvlist_t *tgt, *reqnvl, *reqprops, *retprops;
5233+
nvlist_t *tgt, *reqnvl, *reqprops;
5234+
nvlist_t *retprops = NULL;
52345235
uint64_t vdev_guid;
52355236
boolean_t avail_spare, l2cache;
52365237
char errbuf[1024];
@@ -5244,8 +5245,12 @@ zpool_get_vdev_prop(zpool_handle_t *zhp, const char *vdevname, vdev_prop_t prop,
52445245
}
52455246

52465247
if ((tgt = zpool_find_vdev(zhp, vdevname, &avail_spare, &l2cache,
5247-
NULL)) == NULL)
5248-
return (-1);
5248+
NULL)) == NULL) {
5249+
(void) snprintf(errbuf, sizeof (errbuf),
5250+
dgettext(TEXT_DOMAIN, "can not find %s in %s"),
5251+
vdevname, zhp->zpool_name);
5252+
return (zfs_error(zhp->zpool_hdl, EZFS_NODEVICE, errbuf));
5253+
}
52495254

52505255
verify(nvlist_lookup_uint64(tgt, ZPOOL_CONFIG_GUID, &vdev_guid) == 0);
52515256

@@ -5254,19 +5259,26 @@ zpool_get_vdev_prop(zpool_handle_t *zhp, const char *vdevname, vdev_prop_t prop,
52545259
if (nvlist_alloc(&reqprops, NV_UNIQUE_NAME, 0) != 0)
52555260
return (no_memory(zhp->zpool_hdl));
52565261

5257-
fnvlist_add_uint64(reqnvl, ZPOOL_VDEV_GET_PROPS_VDEV, vdev_guid);
5262+
fnvlist_add_uint64(reqnvl, ZPOOL_VDEV_PROPS_GET_VDEV, vdev_guid);
52585263

5259-
if (prop != VDEV_PROP_INVAL && prop_name == NULL)
5260-
prop_name = (char *)vdev_prop_to_name(prop);
5264+
if (prop != VDEV_PROP_INVAL) {
5265+
/* prop_name overrides prop value */
5266+
if (prop_name != NULL)
5267+
prop = vdev_name_to_prop(prop_name);
5268+
else
5269+
prop_name = (char *)vdev_prop_to_name(prop);
5270+
}
52615271

5272+
if (prop != VDEV_PROP_INVAL)
5273+
assert(prop < VDEV_NUM_PROPS);
52625274
assert(prop_name != NULL);
52635275
if (nvlist_add_uint64(reqprops, prop_name, prop) != 0) {
52645276
nvlist_free(reqnvl);
52655277
nvlist_free(reqprops);
52665278
return (no_memory(zhp->zpool_hdl));
52675279
}
52685280

5269-
fnvlist_add_nvlist(reqnvl, ZPOOL_VDEV_GET_PROPS_PROPS, reqprops);
5281+
fnvlist_add_nvlist(reqnvl, ZPOOL_VDEV_PROPS_GET_PROPS, reqprops);
52705282

52715283
(void) snprintf(errbuf, sizeof (errbuf),
52725284
dgettext(TEXT_DOMAIN, "cannot get vdev property %s from %s in %s"),
@@ -5301,7 +5313,7 @@ zpool_get_all_vdev_props(zpool_handle_t *zhp, const char *vdevname,
53015313
uint64_t vdev_guid;
53025314
boolean_t avail_spare, l2cache;
53035315
char errbuf[1024];
5304-
int ret = -1;
5316+
int ret;
53055317

53065318
verify(zhp != NULL);
53075319
if (zpool_get_state(zhp) == POOL_STATE_UNAVAIL) {
@@ -5323,7 +5335,7 @@ zpool_get_all_vdev_props(zpool_handle_t *zhp, const char *vdevname,
53235335
if (nvlist_alloc(&nvl, NV_UNIQUE_NAME, 0) != 0)
53245336
return (no_memory(zhp->zpool_hdl));
53255337

5326-
fnvlist_add_uint64(nvl, ZPOOL_VDEV_GET_PROPS_VDEV, vdev_guid);
5338+
fnvlist_add_uint64(nvl, ZPOOL_VDEV_PROPS_GET_VDEV, vdev_guid);
53275339

53285340
ret = lzc_get_vdev_prop(zhp->zpool_name, nvl, outnvl);
53295341

@@ -5343,7 +5355,7 @@ int
53435355
zpool_set_vdev_prop(zpool_handle_t *zhp, const char *vdevname,
53445356
const char *propname, const char *propval)
53455357
{
5346-
int ret = -1;
5358+
int ret;
53475359
char errbuf[1024];
53485360
vdev_prop_t vprop;
53495361
nvlist_t *nvl = NULL;
@@ -5380,7 +5392,7 @@ zpool_set_vdev_prop(zpool_handle_t *zhp, const char *vdevname,
53805392
if (nvlist_alloc(&props, NV_UNIQUE_NAME, 0) != 0)
53815393
return (no_memory(zhp->zpool_hdl));
53825394

5383-
fnvlist_add_uint64(nvl, ZPOOL_VDEV_SET_PROPS_VDEV, vdev_guid);
5395+
fnvlist_add_uint64(nvl, ZPOOL_VDEV_PROPS_SET_VDEV, vdev_guid);
53845396

53855397
if (nvlist_add_string(props, propname, propval) != 0) {
53865398
nvlist_free(props);
@@ -5399,7 +5411,7 @@ zpool_set_vdev_prop(zpool_handle_t *zhp, const char *vdevname,
53995411
nvlist_free(props);
54005412
props = realprops;
54015413

5402-
fnvlist_add_nvlist(nvl, ZPOOL_VDEV_SET_PROPS_PROPS, props);
5414+
fnvlist_add_nvlist(nvl, ZPOOL_VDEV_PROPS_SET_PROPS, props);
54035415

54045416
ret = lzc_set_vdev_prop(zhp->zpool_name, nvl, &outnvl);
54055417

module/zcommon/zpool_prop.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,16 @@ vdev_prop_init(void)
359359
PROP_READONLY, ZFS_TYPE_VDEV, "<bytes>", "CLAIMBYTE");
360360
zprop_register_number(VDEV_PROP_BYTES_TRIM, "trim_bytes", 0,
361361
PROP_READONLY, ZFS_TYPE_VDEV, "<bytes>", "TRIMBYTE");
362+
/* XXX - register this as an index (yes | no) type? */
363+
zprop_register_number(VDEV_PROP_REMOVING, "removing", 0,
364+
PROP_READONLY, ZFS_TYPE_VDEV, "<boolean>", "REMOVING");
362365

363366
/* default numeric properties */
364367

365368
/* default index (boolean) properties */
366-
zprop_register_index(VDEV_PROP_NOALLOC, "noalloc", 0,
367-
PROP_DEFAULT, ZFS_TYPE_VDEV, "on | off", "NOALLOC", boolean_table);
369+
zprop_register_index(VDEV_PROP_ALLOCATING, "allocating", 1,
370+
PROP_DEFAULT, ZFS_TYPE_VDEV, "on | off", "ALLOCATING",
371+
boolean_table);
368372

369373
/* default index properties */
370374

@@ -400,10 +404,7 @@ vdev_prop_user(const char *name)
400404
foundsep = B_TRUE;
401405
}
402406

403-
if (!foundsep)
404-
return (B_FALSE);
405-
406-
return (B_TRUE);
407+
return (foundsep);
407408
}
408409

409410
/*

0 commit comments

Comments
 (0)