Skip to content

Commit 82ac409

Browse files
authored
zpool import -m also removing spare and cache when log device is missing
spa_import() relies on a pool config fetched by spa_try_import() for spare/cache devices. Import flags are not passed to spa_tryimport(), which makes it return early due to a missing log device and missing retrieving the cache device and spare eventually. Passing ZFS_IMPORT_MISSING_LOG to spa_tryimport() makes it fetch the correct configuration regardless of the missing log device. Reviewed-by: Alexander Motin <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ameer Hamza <[email protected]> Closes #14794
1 parent a46001a commit 82ac409

File tree

4 files changed

+87
-1
lines changed

4 files changed

+87
-1
lines changed

module/zfs/spa.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6378,6 +6378,16 @@ spa_tryimport(nvlist_t *tryconfig)
63786378
spa->spa_config_source = SPA_CONFIG_SRC_SCAN;
63796379
}
63806380

6381+
/*
6382+
* spa_import() relies on a pool config fetched by spa_try_import()
6383+
* for spare/cache devices. Import flags are not passed to
6384+
* spa_tryimport(), which makes it return early due to a missing log
6385+
* device and missing retrieving the cache device and spare eventually.
6386+
* Passing ZFS_IMPORT_MISSING_LOG to spa_tryimport() makes it fetch
6387+
* the correct configuration regardless of the missing log device.
6388+
*/
6389+
spa->spa_import_flags |= ZFS_IMPORT_MISSING_LOG;
6390+
63816391
error = spa_load(spa, SPA_LOAD_TRYIMPORT, SPA_IMPORT_EXISTING);
63826392

63836393
/*

tests/runfiles/common.run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ tests = ['zpool_import_001_pos', 'zpool_import_002_pos',
422422
'import_cachefile_mirror_detached',
423423
'import_cachefile_paths_changed',
424424
'import_cachefile_shared_device',
425-
'import_devices_missing',
425+
'import_devices_missing', 'import_log_missing',
426426
'import_paths_changed',
427427
'import_rewind_config_changed',
428428
'import_rewind_device_replaced']

tests/zfs-tests/tests/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
10561056
functional/cli_root/zpool_import/import_cachefile_paths_changed.ksh \
10571057
functional/cli_root/zpool_import/import_cachefile_shared_device.ksh \
10581058
functional/cli_root/zpool_import/import_devices_missing.ksh \
1059+
functional/cli_root/zpool_import/import_log_missing.ksh \
10591060
functional/cli_root/zpool_import/import_paths_changed.ksh \
10601061
functional/cli_root/zpool_import/import_rewind_config_changed.ksh \
10611062
functional/cli_root/zpool_import/import_rewind_device_replaced.ksh \
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/bin/ksh -p
2+
3+
#
4+
# This file and its contents are supplied under the terms of the
5+
# Common Development and Distribution License ("CDDL"), version 1.0.
6+
# You may only use this file in accordance with the terms of version
7+
# 1.0 of the CDDL.
8+
#
9+
# A full copy of the text of the CDDL should have accompanied this
10+
# source. A copy of the CDDL is also available via the Internet at
11+
# http://www.illumos.org/license/CDDL.
12+
#
13+
14+
. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.kshlib
15+
16+
#
17+
# DESCRIPTION:
18+
# Import with missing log device should not remove spare/cache.
19+
#
20+
# STRATEGY:
21+
# 1. Create a pool.
22+
# 2. Add spare, cache and log devices to the pool.
23+
# 3. Export the pool.
24+
# 4. Remove the log device.
25+
# 5. Import the pool with -m flag.
26+
# 6. Verify that spare and cache are still present in the pool.
27+
#
28+
29+
verify_runnable "global"
30+
31+
log_onexit cleanup
32+
33+
function test_missing_log
34+
{
35+
typeset poolcreate="$1"
36+
typeset cachevdev="$2"
37+
typeset sparevdev="$3"
38+
typeset logvdev="$4"
39+
typeset missingvdev="$4"
40+
41+
log_note "$0: pool '$poolcreate', adding $cachevdev, $sparevdev," \
42+
"$logvdev then moving away $missingvdev."
43+
44+
log_must zpool create $TESTPOOL1 $poolcreate
45+
46+
log_must zpool add $TESTPOOL1 cache $cachevdev spare $sparevdev \
47+
log $logvdev
48+
49+
log_must_busy zpool export $TESTPOOL1
50+
51+
log_must mv $missingvdev $BACKUP_DEVICE_DIR
52+
53+
log_must zpool import -m -d $DEVICE_DIR $TESTPOOL1
54+
55+
CACHE_PRESENT=$(zpool status -v $TESTPOOL1 | grep $cachevdev)
56+
57+
SPARE_PRESENT=$(zpool status -v $TESTPOOL1 | grep $sparevdev)
58+
59+
if [ -z "$CACHE_PRESENT"] || [ -z "SPARE_PRESENT"]
60+
then
61+
log_fail "cache/spare vdev missing after importing with missing" \
62+
"log device"
63+
fi
64+
65+
# Cleanup
66+
log_must zpool destroy $TESTPOOL1
67+
68+
log_note ""
69+
}
70+
71+
log_must mkdir -p $BACKUP_DEVICE_DIR
72+
73+
test_missing_log "$VDEV0" "$VDEV1" "$VDEV2" "$VDEV3"
74+
75+
log_pass "zpool import succeeded with missing log device"

0 commit comments

Comments
 (0)