vdev_to_nvlist_iter: ignore draid parameters when matching names (#17228)

Various tools will display draid vdev names with parameters embedded in
them, but would not accept them as valid vdev names when looking them
up, making it difficult to build pipelines involving draid vdevs.

This commit makes it so that if a full draid name is offered for match,
it gets truncated at the first ':' character.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.

Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
(cherry picked from commit 131df3bbf2)
This commit is contained in:
Rob Norris 2025-04-15 10:10:48 +10:00 committed by Tony Hutter
parent c2424f8d1a
commit 7fde3933fb
4 changed files with 107 additions and 1 deletions

View File

@ -2961,6 +2961,18 @@ vdev_to_nvlist_iter(nvlist_t *nv, nvlist_t *search, boolean_t *avail_spare,
idx = p + 1;
*p = '\0';
/*
* draid names are presented like: draid2:4d:6c:0s
* We match them up to the first ':' so we can still
* do the parity check below, but the other params
* are ignored.
*/
if ((p = strchr(type, ':')) != NULL) {
if (strncmp(type, VDEV_TYPE_DRAID,
strlen(VDEV_TYPE_DRAID)) == 0)
*p = '\0';
}
/*
* If the types don't match then keep looking.
*/

View File

@ -444,7 +444,8 @@ tags = ['functional', 'cli_root', 'zpool_export']
[tests/functional/cli_root/zpool_get]
tests = ['zpool_get_001_pos', 'zpool_get_002_pos', 'zpool_get_003_pos',
'zpool_get_004_neg', 'zpool_get_005_pos', 'vdev_get_001_pos']
'zpool_get_004_neg', 'zpool_get_005_pos', 'vdev_get_001_pos',
'vdev_get_all']
tags = ['functional', 'cli_root', 'zpool_get']
[tests/functional/cli_root/zpool_history]

View File

@ -1101,6 +1101,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
functional/cli_root/zpool_get/cleanup.ksh \
functional/cli_root/zpool_get/setup.ksh \
functional/cli_root/zpool_get/vdev_get_001_pos.ksh \
functional/cli_root/zpool_get/vdev_get_all.ksh \
functional/cli_root/zpool_get/zpool_get_001_pos.ksh \
functional/cli_root/zpool_get/zpool_get_002_pos.ksh \
functional/cli_root/zpool_get/zpool_get_003_pos.ksh \

View File

@ -0,0 +1,92 @@
#!/bin/ksh -p
# SPDX-License-Identifier: CDDL-1.0
#
# 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 https://opensource.org/licenses/CDDL-1.0.
# 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
#
#
# Copyright (c) 2025, Klara, Inc.
#
. $STF_SUITE/include/libtest.shlib
#
# DESCRIPTION:
#
# zpool get name <pool> all-vdevs works as expected
#
# STRATEGY:
#
# 1. create various kinds of pools
# 2. get all vdev names
# 3. make sure we get all the names back and they look correct
#
verify_runnable "global"
function cleanup {
zpool destroy -f $TESTPOOL1
[[ -e $TESTDIR ]] && rm -rf $TESTDIR/*
}
log_onexit cleanup
log_assert "zpool get all-vdevs works as expected"
# map of vdev spec -> summary form
#
# left side is normal args to zpool create; single number will be replaced
# with that number test file
#
# right side is a summary of the vdev tree, one char per vdev
# ! root
# 0-9 file number
# m mirror
# r raidz
# d draid
typeset -A specs=(
["{0..9}"]="!0123456789"
["mirror {0..9}"]="!m0123456789"
["mirror 0 1 mirror 2 3 mirror 4 5 mirror 6 7"]="!m01m23m45m67"
["raidz1 {0..9}"]="!r0123456789"
["raidz1 {0..4} raidz1 {5..9}"]="!r01234r56789"
["raidz2 {0..9}"]="!r0123456789"
["raidz2 {0..4} raidz2 {5..9}"]="!r01234r56789"
["raidz3 {0..9}"]="!r0123456789"
["raidz3 {0..4} raidz3 {5..9}"]="!r01234r56789"
["draid1 {0..9}"]="!d0123456789"
["draid2 {0..9}"]="!d0123456789"
["draid3 {0..9}"]="!d0123456789"
)
for spec in "${!specs[@]}" ; do
log_must truncate -s 100M $TESTDIR/$TESTFILE1.{0..9}
log_must zpool create -f $TESTPOOL1 \
$(echo $spec | sed -E "s#(^| )([0-9])#\1$TESTDIR/$TESTFILE1.\2#g")
typeset desc=$( zpool get -Ho name name $TESTPOOL1 all-vdevs | awk '
/^\// { t = t substr($1,length($1)) ; next }
/^root/ { t = t "!" last ; next }
/^[a-z]/ { t = t substr($1,0,1) last ; next }
END { print t }
')
log_must test "${specs[$spec]}" == "$desc"
cleanup
done
log_pass