Skip to content

Commit

Permalink
VDEV_PROP_NOALLOC plumbing
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaybee authored and allanjude committed Apr 26, 2021
1 parent 0981418 commit 202bd1a
Show file tree
Hide file tree
Showing 8 changed files with 281 additions and 68 deletions.
21 changes: 15 additions & 6 deletions cmd/zpool/zpool_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2426,6 +2426,12 @@ print_status_config(zpool_handle_t *zhp, status_cbdata_t *cb, const char *name,
1 << vs->vs_configured_ashift, 1 << vs->vs_physical_ashift);
}

if (vs->vs_scan_removing != 0) {
(void) printf(gettext(" (removing)"));
} else if (vs->vs_noalloc != 0) {
(void) printf(gettext(" (non-allocating)"));
}

/* The root vdev has the scrub/resilver stats */
root = fnvlist_lookup_nvlist(zpool_get_config(zhp, NULL),
ZPOOL_CONFIG_VDEV_TREE);
Expand Down Expand Up @@ -10212,7 +10218,14 @@ set_callback(zpool_handle_t *zhp, void *data)
int error;
set_cbdata_t *cb = (set_cbdata_t *)data;

<<<<<<< HEAD
if (cb->cb_type == ZFS_TYPE_VDEV) {
error = zpool_set_vdev_prop(zhp, *cb->cb_vdevs.cb_names,
cb->cb_propname, cb->cb_value);
if (!error)
cb->cb_any_successful = B_TRUE;
return (error);
}

/* Check if we have out-of-bounds features */
if (strcmp(cb->cb_propname, ZPOOL_CONFIG_COMPATIBILITY) == 0) {
boolean_t features[SPA_FEATURES];
Expand Down Expand Up @@ -10270,11 +10283,7 @@ set_callback(zpool_handle_t *zhp, void *data)
}
}

if (cb->cb_type == ZFS_TYPE_VDEV)
error = zpool_set_vdev_prop(zhp, *cb->cb_vdevs.cb_names,
cb->cb_propname, cb->cb_value);
else
error = zpool_set_prop(zhp, cb->cb_propname, cb->cb_value);
error = zpool_set_prop(zhp, cb->cb_propname, cb->cb_value);

if (!error)
cb->cb_any_successful = B_TRUE;
Expand Down
2 changes: 2 additions & 0 deletions include/sys/fs/zfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ typedef struct zpool_load_policy {
#define ZPOOL_CONFIG_ORIG_GUID "orig_guid"
#define ZPOOL_CONFIG_SPLIT_GUID "split_guid"
#define ZPOOL_CONFIG_SPLIT_LIST "guid_list"
#define ZPOOL_CONFIG_NONALLOCATING "non_allocating"
#define ZPOOL_CONFIG_REMOVING "removing"
#define ZPOOL_CONFIG_RESILVER_TXG "resilver_txg"
#define ZPOOL_CONFIG_REBUILD_TXG "rebuild_txg"
Expand Down Expand Up @@ -1148,6 +1149,7 @@ typedef struct vdev_stat {
uint64_t vs_checksum_errors; /* checksum errors */
uint64_t vs_initialize_errors; /* initializing errors */
uint64_t vs_self_healed; /* self-healed bytes */
uint64_t vs_noalloc; /* allocations halted? */
uint64_t vs_scan_removing; /* removing? */
uint64_t vs_scan_processed; /* scan processed bytes */
uint64_t vs_fragmentation; /* device fragmentation */
Expand Down
3 changes: 2 additions & 1 deletion include/sys/spa.h
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,8 @@ extern int spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot,
int replacing, int rebuild);
extern int spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid,
int replace_done);
extern int spa_vdev_remove(spa_t *spa, uint64_t guid, boolean_t unspare);
extern int spa_vdev_alloc(spa_t *spa, uint64_t guid);
extern int spa_vdev_noalloc(spa_t *spa, uint64_t guid);
extern boolean_t spa_vdev_remove_active(spa_t *spa);
extern int spa_vdev_initialize(spa_t *spa, nvlist_t *nv, uint64_t cmd_type,
nvlist_t *vdev_errlist);
Expand Down
1 change: 1 addition & 0 deletions include/sys/vdev_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ struct vdev {
list_node_t vdev_state_dirty_node; /* state dirty list */
uint64_t vdev_deflate_ratio; /* deflation ratio (x512) */
uint64_t vdev_islog; /* is an intent log device */
uint64_t vdev_noalloc; /* device is passivated? */
uint64_t vdev_removing; /* device is being removed? */
boolean_t vdev_ishole; /* is a hole in the namespace */
uint64_t vdev_top_zap;
Expand Down
64 changes: 41 additions & 23 deletions module/zfs/vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,8 @@ vdev_alloc(spa_t *spa, vdev_t **vdp, nvlist_t *nv, vdev_t *parent, uint_t id,
&vd->vdev_ms_shift);
(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_ASIZE,
&vd->vdev_asize);
(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_NONALLOCATING,
&vd->vdev_noalloc);
(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_REMOVING,
&vd->vdev_removing);
(void) nvlist_lookup_uint64(nv, ZPOOL_CONFIG_VDEV_TOP_ZAP,
Expand Down Expand Up @@ -1184,8 +1186,10 @@ vdev_top_transfer(vdev_t *svd, vdev_t *tvd)
ASSERT3P(tvd->vdev_indirect_mapping, ==, NULL);
ASSERT3P(tvd->vdev_indirect_births, ==, NULL);
ASSERT3P(tvd->vdev_obsolete_sm, ==, NULL);
ASSERT0(tvd->vdev_noalloc);
ASSERT0(tvd->vdev_removing);
ASSERT0(tvd->vdev_rebuilding);
tvd->vdev_noalloc = svd->vdev_noalloc;
tvd->vdev_removing = svd->vdev_removing;
tvd->vdev_rebuilding = svd->vdev_rebuilding;
tvd->vdev_rebuild_config = svd->vdev_rebuild_config;
Expand All @@ -1201,6 +1205,7 @@ vdev_top_transfer(vdev_t *svd, vdev_t *tvd)
svd->vdev_indirect_mapping = NULL;
svd->vdev_indirect_births = NULL;
svd->vdev_obsolete_sm = NULL;
svd->vdev_noalloc = 0;
svd->vdev_removing = 0;
svd->vdev_rebuilding = 0;

Expand Down Expand Up @@ -1499,11 +1504,11 @@ vdev_metaslab_init(vdev_t *vd, uint64_t txg)
spa_config_enter(spa, SCL_ALLOC, FTAG, RW_WRITER);

/*
* If the vdev is being removed we don't activate
* the metaslabs since we want to ensure that no new
* allocations are performed on this device.
* If the vdev is marked as non-allocating then don't
* activate the metaslabs since we want to ensure that
* no allocations are performed on this device.
*/
if (!expanding && !vd->vdev_removing) {
if (!expanding && !vd->vdev_noalloc) {
metaslab_group_activate(vd->vdev_mg);
if (vd->vdev_log_mg != NULL)
metaslab_group_activate(vd->vdev_log_mg);
Expand Down Expand Up @@ -4439,6 +4444,7 @@ vdev_get_stats_ex(vdev_t *vd, vdev_stat_t *vs, vdev_stat_ex_t *vsx)
vs->vs_fragmentation = (vd->vdev_mg != NULL) ?
vd->vdev_mg->mg_fragmentation : 0;
}
vs->vs_noalloc = vd->vdev_noalloc;
}

vdev_get_stats_ex_impl(vd, vs, vsx);
Expand Down Expand Up @@ -5515,6 +5521,7 @@ vdev_prop_set(vdev_t *vd, nvlist_t *innvl, nvlist_t *outnvl)
nvpair_t *elem = NULL;
uint64_t vdev_guid;
nvlist_t *nvprops;
int error;

ASSERT(vd != NULL);

Expand All @@ -5527,7 +5534,7 @@ vdev_prop_set(vdev_t *vd, nvlist_t *innvl, nvlist_t *outnvl)

#if 0
if ((error = vdev_prop_validate(spa, nvprops)) != 0)
return;
return (error);
#endif

while ((elem = nvlist_next_nvpair(nvprops, elem)) != NULL) {
Expand All @@ -5537,44 +5544,55 @@ vdev_prop_set(vdev_t *vd, nvlist_t *innvl, nvlist_t *outnvl)
char *strval = NULL;

if (prop == VDEV_PROP_INVAL && !vdev_prop_user(propname)) {
intval = EINVAL;
vdev_prop_add_list(outnvl, propname, strval, intval, 0);
continue;
error = EINVAL;
goto end;
}

if (vdev_prop_readonly(prop) == B_TRUE) {
intval = EROFS;
vdev_prop_add_list(outnvl, propname, strval, intval, 0);
continue;
if (vdev_prop_readonly(prop)) {
error = EROFS;
goto end;
}

/* Special Processing */
switch (prop) {
case VDEV_PROP_PATH:
strval = vd->vdev_path;
if (strval == NULL)
intval = EROFS;
if (nvpair_type(elem) != DATA_TYPE_STRING)
intval = EINVAL;
if (intval == 0)
strval = fnvpair_value_string(elem);
error = EROFS;
else if (nvpair_type(elem) != DATA_TYPE_STRING)
error = EINVAL;
if (error != 0)
break;
strval = fnvpair_value_string(elem);
if (strval == NULL)
intval = EINVAL;
if (intval != 0) {
vdev_prop_add_list(outnvl, propname, strval,
intval, 0);
continue;
}
error = EINVAL;
if (error != 0)
break;
spa_strfree(vd->vdev_path);
vd->vdev_path = spa_strdup(strval);
spa_config_enter(spa, SCL_CONFIG, FTAG, RW_WRITER);
vdev_config_dirty(vd->vdev_top);
spa_config_exit(spa, SCL_CONFIG, FTAG);
break;
case VDEV_PROP_NOALLOC:
intval = fnvpair_value_uint64(elem);
if (intval == vd->vdev_noalloc)
return (0); /* noop */
if (intval == 1)
error = spa_vdev_noalloc(spa, vdev_guid);
else
error = spa_vdev_alloc(spa, vdev_guid);
break;
default:
/* Most processing is done in vdev_sync_props */
break;
}
end:
if (error != 0) {
intval = error;
vdev_prop_add_list(outnvl, propname, strval, intval, 0);
return (error);
}
}

return (dsl_sync_task(spa->spa_name, NULL, vdev_sync_props,
Expand Down
4 changes: 4 additions & 0 deletions module/zfs/vdev_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ vdev_config_generate(spa_t *spa, vdev_t *vd, boolean_t getstats,
fnvlist_add_uint64(nv, ZPOOL_CONFIG_ASIZE,
vd->vdev_asize);
fnvlist_add_uint64(nv, ZPOOL_CONFIG_IS_LOG, vd->vdev_islog);
if (vd->vdev_noalloc) {
fnvlist_add_uint64(nv, ZPOOL_CONFIG_NONALLOCATING,
vd->vdev_noalloc);
}
if (vd->vdev_removing) {
fnvlist_add_uint64(nv, ZPOOL_CONFIG_REMOVING,
vd->vdev_removing);
Expand Down
Loading

0 comments on commit 202bd1a

Please sign in to comment.