Don't panic if setting vdev properties is unsupported for this vdev type

Check that vdev has valid zap and bail out early.

While here, move objid selection out of the loop, it's not going to
change.

Reviewed-by: Allan Jude <allan@klarasystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Yuri Pankov <yuripv@FreeBSD.org>
Closes #15063
This commit is contained in:
Yuri Pankov 2023-07-20 19:21:47 +02:00 committed by GitHub
parent 4d2dad04aa
commit 929173ab42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 17 deletions

View File

@ -5694,6 +5694,7 @@ vdev_props_set_sync(void *arg, dmu_tx_t *tx)
objset_t *mos = spa->spa_meta_objset; objset_t *mos = spa->spa_meta_objset;
nvpair_t *elem = NULL; nvpair_t *elem = NULL;
uint64_t vdev_guid; uint64_t vdev_guid;
uint64_t objid;
nvlist_t *nvprops; nvlist_t *nvprops;
vdev_guid = fnvlist_lookup_uint64(nvp, ZPOOL_VDEV_PROPS_SET_VDEV); vdev_guid = fnvlist_lookup_uint64(nvp, ZPOOL_VDEV_PROPS_SET_VDEV);
@ -5704,31 +5705,28 @@ vdev_props_set_sync(void *arg, dmu_tx_t *tx)
if (vd == NULL) if (vd == NULL)
return; return;
/*
* Set vdev property values in the vdev props mos object.
*/
if (vd->vdev_root_zap != 0) {
objid = vd->vdev_root_zap;
} else if (vd->vdev_top_zap != 0) {
objid = vd->vdev_top_zap;
} else if (vd->vdev_leaf_zap != 0) {
objid = vd->vdev_leaf_zap;
} else {
panic("unexpected vdev type");
}
mutex_enter(&spa->spa_props_lock); mutex_enter(&spa->spa_props_lock);
while ((elem = nvlist_next_nvpair(nvprops, elem)) != NULL) { while ((elem = nvlist_next_nvpair(nvprops, elem)) != NULL) {
uint64_t intval, objid = 0; uint64_t intval;
const char *strval; const char *strval;
vdev_prop_t prop; vdev_prop_t prop;
const char *propname = nvpair_name(elem); const char *propname = nvpair_name(elem);
zprop_type_t proptype; zprop_type_t proptype;
/*
* Set vdev property values in the vdev props mos object.
*/
if (vd->vdev_root_zap != 0) {
objid = vd->vdev_root_zap;
} else if (vd->vdev_top_zap != 0) {
objid = vd->vdev_top_zap;
} else if (vd->vdev_leaf_zap != 0) {
objid = vd->vdev_leaf_zap;
} else {
/*
* XXX: implement vdev_props_set_check()
*/
panic("vdev not root/top/leaf");
}
switch (prop = vdev_name_to_prop(propname)) { switch (prop = vdev_name_to_prop(propname)) {
case VDEV_PROP_USERPROP: case VDEV_PROP_USERPROP:
if (vdev_prop_user(propname)) { if (vdev_prop_user(propname)) {
@ -5797,6 +5795,12 @@ vdev_prop_set(vdev_t *vd, nvlist_t *innvl, nvlist_t *outnvl)
ASSERT(vd != NULL); ASSERT(vd != NULL);
/* Check that vdev has a zap we can use */
if (vd->vdev_root_zap == 0 &&
vd->vdev_top_zap == 0 &&
vd->vdev_leaf_zap == 0)
return (SET_ERROR(EINVAL));
if (nvlist_lookup_uint64(innvl, ZPOOL_VDEV_PROPS_SET_VDEV, if (nvlist_lookup_uint64(innvl, ZPOOL_VDEV_PROPS_SET_VDEV,
&vdev_guid) != 0) &vdev_guid) != 0)
return (SET_ERROR(EINVAL)); return (SET_ERROR(EINVAL));