zpool: Provide GUID to zpool-reguid(8) with -g (#16239)

This commit extends the zpool-reguid(8) command with a -g flag, which
allows the user to specify the GUID to set.

This change also adds some general tests for zpool-reguid(8).

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

Signed-off-by: Mateusz Piotrowski <0mp@FreeBSD.org>
Reviewed-by: Rob Norris <rob.norris@klarasystems.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Tony Hutter <hutter2@llnl.gov>
This commit is contained in:
Mateusz Piotrowski
2024-08-26 18:27:24 +02:00
committed by GitHub
parent 2420ee6e12
commit 6be8bf5552
16 changed files with 342 additions and 16 deletions
+4
View File
@@ -514,6 +514,10 @@ tags = ['functional', 'cli_root', 'zpool_offline']
tests = ['zpool_online_001_pos', 'zpool_online_002_neg']
tags = ['functional', 'cli_root', 'zpool_online']
[tests/functional/cli_root/zpool_reguid]
tests = ['zpool_reguid_001_pos', 'zpool_reguid_002_neg']
tags = ['functional', 'cli_root', 'zpool_reguid']
[tests/functional/cli_root/zpool_remove]
tests = ['zpool_remove_001_neg', 'zpool_remove_002_pos',
'zpool_remove_003_pos']
@@ -0,0 +1,6 @@
pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cli_root/zpool_reguid
dist_pkgdata_SCRIPTS = \
setup.ksh \
cleanup.ksh \
zpool_reguid_001_pos.ksh \
zpool_reguid_002_neg.ksh
@@ -0,0 +1,32 @@
#!/bin/ksh -p
#
# 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 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
. $STF_SUITE/include/libtest.shlib
verify_runnable "global"
default_cleanup
@@ -0,0 +1,34 @@
#!/bin/ksh -p
#
# 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 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
. $STF_SUITE/include/libtest.shlib
verify_runnable "global"
DISK=${DISKS%% *}
default_setup $DISK
@@ -0,0 +1,73 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# CDDL HEADER END
#
# Copyright 2023 Mateusz Piotrowski
#
. $STF_SUITE/include/libtest.shlib
#
# DESCRIPTION:
# Verify 'zpool reguid' can change pool's GUID.
#
# STRATEGY:
# 1. Use zpool get to obtain the initial GUID of a pool.
# 2. Change pool's GUID with zpool reguid.
# 3. Verify the GUID has changed to a random GUID.
#
# 4. Change pool's GUID with zpool reguid -g.
# 5. Verify the GUID has changed to the specified GUID.
#
# set_guid guid [expected_guid]
set_guid() {
gflag_guid="$1"
expected_guid="${2:-"$gflag_guid"}"
initial_guid="$(zpool get -H -o value guid "$TESTPOOL")"
log_assert "Verify 'zpool reguid -g \"$gflag_guid\"' sets GUID as expected."
log_must zpool reguid -g "$gflag_guid" "$TESTPOOL"
retrieved_guid="$(zpool get -H -o value guid "$TESTPOOL")"
if [[ "$retrieved_guid" == "" ]]; then
log_fail "Unable to obtain the new GUID of pool $TESTPOOL"
fi
if [[ "$expected_guid" != "$retrieved_guid" ]]; then
log_fail "GUID set to '$retrieved_guid' instead of '$expected_guid'"
fi
}
log_assert "Verify 'zpool reguid' picks a new random GUID for the pool."
initial_guid="$(zpool get -H -o value guid "$TESTPOOL")"
if [[ $initial_guid == "" ]]; then
log_fail "Unable to obtain the initial GUID of pool $TESTPOOL"
fi
log_must zpool reguid "$TESTPOOL"
new_guid="$(zpool get -H -o value guid "$TESTPOOL")"
if [[ "$new_guid" == "" ]]; then
log_fail "Unable to obtain the new GUID of pool $TESTPOOL"
fi
if [[ "$initial_guid" == "$new_guid" ]]; then
log_fail "GUID change failed; GUID has not changed: $initial_guid"
fi
for g in "$(bc -e '2^64 - 1')" 0; do
set_guid "$g"
done
# zpool-reguid(8) will strip the leading 0.
set_guid 0123 "123"
# GUID "-1" is effectively 2^64 - 1 in value.
set_guid -1 "$(bc -e '2^64 - 1')"
log_pass "'zpool reguid' changes GUID as expected."
@@ -0,0 +1,60 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
# CDDL HEADER END
#
# Copyright 2023 Mateusz Piotrowski
#
. $STF_SUITE/include/libtest.shlib
#
# DESCRIPTION:
# Verify 'zpool reguid' does not accept invalid GUIDs.
#
# STRATEGY:
# 1. Call zpool reguid with an invalid GUID.
# 2. Verify that the call fails.
# 3. Verify that the pool GUID did not change.
#
# 4. Call zpool reguid with a GUID that is already in use.
# 5. Verify that the call fails.
#
check_guid() {
invalid_guid="$1"
initial_guid="$(zpool get -H -o value guid "$TESTPOOL")"
log_assert "'zpool reguid' will not accept invalid GUID '$invalid_guid'"
if zpool reguid -g "$invalid_guid" "$TESTPOOL"; then
log_fail "'zpool reguid' accepted invalid GUID: $invalid_guid"
fi
final_guid="$(zpool get -H -o value guid "$TESTPOOL")"
if [[ "$initial_guid" != "$final_guid" ]]; then
log_fail "Invalid GUID change from '$initial_guid' to '$final_guid'"
fi
}
log_assert "Verify 'zpool reguid' does not accept invalid GUIDs"
for ig in "$(bc -e '2^64')" 0xA 0xa; do
check_guid "$ig"
done
guid="42"
log_assert "Verify 'zpool reguid -g' does not accept GUID which are already in use"
log_must zpool reguid -g "$guid" "$TESTPOOL"
if zpool reguid -g "$guid" "$TESTPOOL"; then
log_fail "'zpool reguid' accepted GUID that was already in use: $invalid_guid"
fi
log_pass "'zpool reguid' does not accept invalid GUIDs."