zpool/zfs: Add '-a|--all' option to scrub, trim, initialize

Add support for the '-a | --all' option to perform trim,
scrub, and initialize operations on all pools.
Previously, specifying a pool name was mandatory for
these operations. With this enhancement, users can now
execute these operations across all pools at once,
without needing to manually iterate over each pool
from the command line.

Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Tino Reichardt <milky-zfs@mcmilk.de>
Signed-off-by: Akash B <akash-b@hpe.com>
Closes #17524
This commit is contained in:
Akash B
2025-07-30 03:20:44 +05:30
committed by GitHub
parent fc885f308f
commit b6e8db509d
15 changed files with 637 additions and 104 deletions
+4 -2
View File
@@ -497,6 +497,7 @@ tags = ['functional', 'cli_root', 'zpool_labelclear']
tests = ['zpool_initialize_attach_detach_add_remove',
'zpool_initialize_fault_export_import_online',
'zpool_initialize_import_export',
'zpool_initialize_multiple_pools',
'zpool_initialize_offline_export_import_online',
'zpool_initialize_online_offline',
'zpool_initialize_split',
@@ -542,6 +543,7 @@ tests = ['zpool_scrub_001_neg', 'zpool_scrub_002_pos', 'zpool_scrub_003_pos',
'zpool_scrub_004_pos', 'zpool_scrub_005_pos',
'zpool_scrub_encrypted_unloaded', 'zpool_scrub_print_repairing',
'zpool_scrub_offline_device', 'zpool_scrub_multiple_copies',
'zpool_scrub_multiple_pools',
'zpool_error_scrub_001_pos', 'zpool_error_scrub_002_pos',
'zpool_error_scrub_003_pos', 'zpool_error_scrub_004_pos']
tags = ['functional', 'cli_root', 'zpool_scrub']
@@ -574,8 +576,8 @@ tags = ['functional', 'cli_root', 'zpool_sync']
[tests/functional/cli_root/zpool_trim]
tests = ['zpool_trim_attach_detach_add_remove',
'zpool_trim_fault_export_import_online',
'zpool_trim_import_export', 'zpool_trim_multiple', 'zpool_trim_neg',
'zpool_trim_fault_export_import_online', 'zpool_trim_import_export',
'zpool_trim_multiple', 'zpool_trim_multiple_pools', 'zpool_trim_neg',
'zpool_trim_offline_export_import_online', 'zpool_trim_online_offline',
'zpool_trim_partial', 'zpool_trim_rate', 'zpool_trim_rate_neg',
'zpool_trim_secure', 'zpool_trim_split', 'zpool_trim_start_and_cancel_neg',
+3
View File
@@ -1176,6 +1176,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
functional/cli_root/zpool_initialize/zpool_initialize_attach_detach_add_remove.ksh \
functional/cli_root/zpool_initialize/zpool_initialize_fault_export_import_online.ksh \
functional/cli_root/zpool_initialize/zpool_initialize_import_export.ksh \
functional/cli_root/zpool_initialize/zpool_initialize_multiple_pools.ksh \
functional/cli_root/zpool_initialize/zpool_initialize_offline_export_import_online.ksh \
functional/cli_root/zpool_initialize/zpool_initialize_online_offline.ksh \
functional/cli_root/zpool_initialize/zpool_initialize_split.ksh \
@@ -1239,6 +1240,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
functional/cli_root/zpool_scrub/zpool_scrub_005_pos.ksh \
functional/cli_root/zpool_scrub/zpool_scrub_encrypted_unloaded.ksh \
functional/cli_root/zpool_scrub/zpool_scrub_multiple_copies.ksh \
functional/cli_root/zpool_scrub/zpool_scrub_multiple_pools.ksh \
functional/cli_root/zpool_scrub/zpool_scrub_offline_device.ksh \
functional/cli_root/zpool_scrub/zpool_scrub_print_repairing.ksh \
functional/cli_root/zpool_scrub/zpool_scrub_txg_continue_from_last.ksh \
@@ -1291,6 +1293,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
functional/cli_root/zpool_trim/zpool_trim_fault_export_import_online.ksh \
functional/cli_root/zpool_trim/zpool_trim_import_export.ksh \
functional/cli_root/zpool_trim/zpool_trim_multiple.ksh \
functional/cli_root/zpool_trim/zpool_trim_multiple_pools.ksh \
functional/cli_root/zpool_trim/zpool_trim_neg.ksh \
functional/cli_root/zpool_trim/zpool_trim_offline_export_import_online.ksh \
functional/cli_root/zpool_trim/zpool_trim_online_offline.ksh \
@@ -0,0 +1,131 @@
#!/bin/ksh -p
# SPDX-License-Identifier: CDDL-1.0
#
# 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 (c) 2025 Hewlett Packard Enterprise Development LP.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zpool_initialize/zpool_initialize.kshlib
#
# DESCRIPTION:
# Verify 'zpool initialize -a' works correctly with multiple pools
#
# STRATEGY:
# 1. Create multiple pools.
# 2. Start a initialize operation on all pools using 'zpool initialize -a'.
# 3. Verify that the initializing is active on all pools.
# 4. Wait for the initialize operation to complete.
# 5. Verify that the initialize operation is complete on all pools.
# 6. Start a initializing on all pools using 'zpool initialize -w -a'.
# 7. Verify that the initialize operation is complete on all pools.
# 8. Now test the -u, -c and -s options on multiple pools with -a.
# 9. Verify that the initialize status is correctly updated on all pools.
#
verify_runnable "global"
cleanup() {
for pool in {1..4}; do
zpool destroy $TESTPOOL${pool}
rm -rf $TESTDIR${pool}
done
rm -f $DISK1 $DISK2 $DISK3 $DISK4
}
log_onexit cleanup
log_assert "Verify if 'zpool initialize -a' works correctly with multiple pools."
DEVSIZE='5G'
TESTDIR="$TEST_BASE_DIR/zpool_initialize_multiple_pools"
DISK1="$TEST_BASE_DIR/zpool_disk1.dat"
DISK2="$TEST_BASE_DIR/zpool_disk2.dat"
DISK3="$TEST_BASE_DIR/zpool_disk3.dat"
DISK4="$TEST_BASE_DIR/zpool_disk4.dat"
truncate -s $DEVSIZE $DISK1
truncate -s $DEVSIZE $DISK2
truncate -s $DEVSIZE $DISK3
truncate -s $DEVSIZE $DISK4
for pool in {1..4}; do
DISK[$pool]="$TEST_BASE_DIR/zpool_disk${pool}.dat"
truncate -s $DEVSIZE ${DISK[$pool]}
log_must zpool create $TESTPOOL${pool} ${DISK[$pool]}
done
sync_all_pools
# Start an initialize operation on all pools using 'zpool initialize -a'.
log_must zpool initialize -a
# Verify that the initializing is active on all pools.
for pool in {1..4}; do
if [[ -z "$(initialize_progress $TESTPOOL${pool} ${DISK[$pool]})" ]]; then
log_fail "Initializing did not start on pool $TESTPOOL${pool}"
fi
done
# Wait for the initialize operation to complete on all pools.
for pool in {1..4}; do
log_must zpool wait -t initialize $TESTPOOL${pool}
done
# Verify that the initialize operation is complete on all pools.
complete_count=$(zpool status -i | grep -c "completed")
if [[ $complete_count -ne 4 ]]; then
log_fail "Expected 4 pools to have initialize status 'completed', but found ${complete_count}."
fi
# Start an initialize operation on all pools using 'zpool initialize -w -a'.
log_must zpool initialize -w -a
# Verify that the initialize operation is complete on all pools.
complete_count=$(zpool status -i | grep -c "completed")
if [[ $complete_count -ne 4 ]]; then
log_fail "Expected 4 pools to have initialize status 'completed', but found ${complete_count}."
fi
# Now test the -u, -c and -s options on multiple pools with -a.
log_must zpool initialize -u -a
complete_count=$(zpool status -i | grep -c "uninitialized")
if [[ $complete_count -ne 4 ]]; then
log_fail "Expected 4 pools to have initialize status 'uninitialized', but found ${complete_count}."
fi
log_must zpool initialize -a
for pool in {1..4}; do
if [[ -z "$(initialize_progress $TESTPOOL${pool} ${DISK[$pool]})" ]]; then
log_fail "Initializing did not start on pool $TESTPOOL${pool}"
fi
done
log_must zpool initialize -a -s
complete_count=$(zpool status -i | grep -c "suspended")
if [[ $complete_count -ne 4 ]]; then
log_fail "Expected 4 pools to have initialize status 'suspended', but found ${complete_count}."
fi
log_must zpool initialize -a -c
for pool in {1..4}; do
[[ -z "$(initialize_progress $TESTPOOL${pool} ${DISK[$pool]})" ]] || \
log_fail "Initialize did not stop on pool $TESTPOOL${pool}"
done
log_pass "Initialize '-a' works on multiple pools correctly."
@@ -28,6 +28,7 @@
#
# Copyright (c) 2016 by Delphix. All rights reserved.
# Copyright (c) 2025 Hewlett Packard Enterprise Development LP.
#
. $STF_SUITE/include/libtest.shlib
@@ -46,7 +47,7 @@
verify_runnable "global"
set -A args "" "-?" "blah blah" "-%" "--?" "-*" "-=" \
"-a" "-b" "-c" "-d" "-e" "-f" "-g" "-h" "-i" "-j" "-k" "-l" \
"-b" "-c" "-d" "-e" "-f" "-g" "-h" "-i" "-j" "-k" "-l" \
"-m" "-n" "-o" "-p" "-q" "-r" "-s" "-t" "-u" "-v" "-w" "-x" "-y" "-z" \
"-A" "-B" "-C" "-D" "-E" "-F" "-G" "-H" "-I" "-J" "-K" "-L" \
"-M" "-N" "-O" "-P" "-Q" "-R" "-S" "-T" "-U" "-V" "-W" "-X" "-W" "-Z"
@@ -0,0 +1,128 @@
#!/bin/ksh -p
# SPDX-License-Identifier: CDDL-1.0
#
# 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 (c) 2025 Hewlett Packard Enterprise Development LP.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zpool_scrub/zpool_scrub.cfg
#
# DESCRIPTION:
# Verify 'zpool scrub -a' works correctly with multiple pools
#
# STRATEGY:
# 1. Create multiple pools.
# 2. Start a scrub on all pools using 'zpool scrub -a'.
# 3. Verify that the scrub is running on all pools.
# 4. Wait for the scrub to complete.
# 5. Verify that the scrub status is complete on all pools.
# 6. Start a scrub on all pools using 'zpool scrub -w -a'.
# 7. Verify that the scrub status is complete on all pools.
# 8. Now test the -p and -s options on multiple pools with -a.
# 9. Verify that the scrub status is correct for each option.
#
verify_runnable "global"
cleanup() {
log_must set_tunable32 SCAN_SUSPEND_PROGRESS 0
for pool in {1..4}; do
zpool destroy $TESTPOOL${pool}
rm -rf $TESTDIR${pool}
done
rm -f $DISK1 $DISK2 $DISK3 $DISK4
# Import the testpool
zpool import -a
}
log_onexit cleanup
log_assert "Verify if scrubbing multiple pools works correctly."
# Export the testpool created by setup and Import them later.
log_must zpool export -a
DEVSIZE='128m'
FILESIZE='50m'
TESTDIR="$TEST_BASE_DIR/zpool_scrub_multiple_pools"
DISK1="$TEST_BASE_DIR/zpool_disk1.dat"
DISK2="$TEST_BASE_DIR/zpool_disk2.dat"
DISK3="$TEST_BASE_DIR/zpool_disk3.dat"
DISK4="$TEST_BASE_DIR/zpool_disk4.dat"
truncate -s $DEVSIZE $DISK1
truncate -s $DEVSIZE $DISK2
truncate -s $DEVSIZE $DISK3
truncate -s $DEVSIZE $DISK4
for pool in {1..4}; do
DISK[$pool]="$TEST_BASE_DIR/zpool_disk${pool}.dat"
truncate -s $DEVSIZE ${DISK[$pool]}
log_must zpool create -O mountpoint=$TESTDIR${pool} $TESTPOOL${pool} ${DISK[$pool]}
log_must zfs create -o compression=off $TESTPOOL${pool}/testfs${pool}
typeset mntpnt=$(get_prop mountpoint $TESTPOOL${pool}/testfs${pool})
# Fill some data into the filesystem.
log_must mkfile $FILESIZE $mntpnt/file${pool}.dat
done
sync_all_pools
# Start a scrub on all pools using 'zpool scrub -a'.
log_must zpool scrub -a
# Wait for the scrub to complete on all pools.
for pool in {1..4}; do
log_must zpool wait -t scrub $TESTPOOL${pool}
done
# Verify that the scrub status is complete on all pools.
complete_count=$(zpool status -v | grep -c "scrub repaired")
if [[ $complete_count -ne 4 ]]; then
log_fail "Expected 4 pools to have scrub status 'scrub repaired', but found $complete_count."
fi
# Start a error scrub on all pools using 'zpool scrub -w -a'
log_must zpool scrub -w -a
# Verify that the scrub status is complete on all pools.
complete_count=$(zpool status -v | grep -c "scrub repaired")
if [[ $complete_count -ne 4 ]]; then
log_fail "Expected 4 pools to have scrub status 'scrub repaired', but found $complete_count."
fi
# Now test the -p and -s options on multiple pools with -a.
log_must set_tunable32 SCAN_SUSPEND_PROGRESS 1
log_must zpool scrub -a
complete_count=$(zpool status -v | grep -c "scrub in progress since")
if [[ $complete_count -ne 4 ]]; then
log_fail "Expected 4 pools to have scrub status 'scrub in progress since', but found $complete_count."
fi
log_must zpool scrub -a -p
complete_count=$(zpool status -v | grep -c "scrub paused since")
if [[ $complete_count -ne 4 ]]; then
log_fail "Expected 4 pools to have scrub status 'scrub paused since', but found $complete_count."
fi
log_must zpool scrub -a -s
complete_count=$(zpool status -v | grep -c "scrub canceled")
if [[ $complete_count -ne 4 ]]; then
log_fail "Expected 4 pools to have scrub status 'scrub canceled', but found $complete_count."
fi
log_pass "Scrubbing multiple pools works correctly."
@@ -0,0 +1,123 @@
#!/bin/ksh -p
# SPDX-License-Identifier: CDDL-1.0
#
# 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 (c) 2025 Hewlett Packard Enterprise Development LP.
#
. $STF_SUITE/include/libtest.shlib
. $STF_SUITE/tests/functional/cli_root/zpool_trim/zpool_trim.kshlib
#
# DESCRIPTION:
# Verify 'zpool trim -a' works correctly with multiple pools
#
# STRATEGY:
# 1. Create multiple pools.
# 2. Start a trim on all pools using 'zpool trim -a'.
# 3. Verify that the trim is started on all pools.
# 4. Wait for the trim to complete.
# 5. Verify that the trim is complete on all pools.
# 6. Start a trim on all pools using 'zpool trim -w -a'.
# 7. Verify that the trim is complete on all pools.
# 8. Now test the -c and -s options on multiple pools with -a.
# 9. Verify that the trim status is correct for each option.
#
verify_runnable "global"
cleanup() {
for pool in {1..4}; do
zpool destroy $TESTPOOL${pool}
rm -rf $TESTDIR${pool}
done
rm -f $DISK1 $DISK2 $DISK3 $DISK4
}
log_onexit cleanup
log_assert "Verify if trim '-a' works on multiple pools correctly."
DEVSIZE='5G'
TESTDIR="$TEST_BASE_DIR/zpool_trim_multiple_pools"
DISK1="$TEST_BASE_DIR/zpool_disk1.dat"
DISK2="$TEST_BASE_DIR/zpool_disk2.dat"
DISK3="$TEST_BASE_DIR/zpool_disk3.dat"
DISK4="$TEST_BASE_DIR/zpool_disk4.dat"
truncate -s $DEVSIZE $DISK1
truncate -s $DEVSIZE $DISK2
truncate -s $DEVSIZE $DISK3
truncate -s $DEVSIZE $DISK4
for pool in {1..4}; do
DISK[$pool]="$TEST_BASE_DIR/zpool_disk${pool}.dat"
truncate -s $DEVSIZE ${DISK[$pool]}
log_must zpool create $TESTPOOL${pool} ${DISK[$pool]}
done
sync_all_pools
# Start a trim on all pools using 'zpool trim -a'.
log_must zpool trim -a
# Verify that the trim is started on all pools.
for pool in {1..4}; do
[[ -z "$(trim_progress $TESTPOOL${pool} ${DISK[$pool]})" ]] && \
log_fail "Trim did not start on pool $TESTPOOL${pool}"
done
# Wait for the trim to complete on all pools.
for pool in {1..4}; do
log_must zpool wait -t trim $TESTPOOL${pool}
done
# Verify that the trim status is complete on all pools.
complete_count=$(zpool status -t | grep -c "completed")
if [[ $complete_count -ne 4 ]]; then
log_fail "Expected 4 pools to have trim status 'completed', but found ${complete_count}."
fi
# Start a trim on all pools using 'zpool trim -w -a'
log_must zpool trim -w -a
# Verify that the trim status is complete on all pools.
complete_count=$(zpool status -t | grep -c "completed")
if [[ $complete_count -ne 4 ]]; then
log_fail "Expected 4 pools to have trim status 'completed', but found ${complete_count}."
fi
# Now test the -s and -c options on multiple pools with -a.
log_must zpool trim -r 1 -a
for pool in {1..4}; do
[[ -z "$(trim_progress $TESTPOOL${pool} ${DISK[$pool]})" ]] && \
log_fail "Trim did not start"
done
log_must zpool trim -a -s
complete_count=$(zpool status -t | grep -c "suspended")
if [[ $complete_count -ne 4 ]]; then
log_fail "Expected 4 pools to have trim status 'suspended', but found $complete_count."
fi
log_must zpool trim -a -c
for pool in {1..4}; do
[[ -z "$(trim_progress $TESTPOOL${pool} ${DISK[$pool]})" ]] || \
log_fail "TRIM did not stop on pool $TESTPOOL${pool}"
done
log_pass "Trim '-a' works on multiple pools correctly."