Skip to content

vdev_to_nvlist_iter: ignore draid parameters when matching names #17228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/libzfs/libzfs_pool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down
3 changes: 2 additions & 1 deletion tests/runfiles/common.run
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions tests/zfs-tests/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,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 \
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Loading