Skip to content

Commit a03a950

Browse files
committed
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 openzfs#14794
1 parent 90ee0f9 commit a03a950

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
@@ -6261,6 +6261,16 @@ spa_tryimport(nvlist_t *tryconfig)
62616261
spa->spa_config_source = SPA_CONFIG_SRC_SCAN;
62626262
}
62636263

6264+
/*
6265+
* spa_import() relies on a pool config fetched by spa_try_import()
6266+
* for spare/cache devices. Import flags are not passed to
6267+
* spa_tryimport(), which makes it return early due to a missing log
6268+
* device and missing retrieving the cache device and spare eventually.
6269+
* Passing ZFS_IMPORT_MISSING_LOG to spa_tryimport() makes it fetch
6270+
* the correct configuration regardless of the missing log device.
6271+
*/
6272+
spa->spa_import_flags |= ZFS_IMPORT_MISSING_LOG;
6273+
62646274
error = spa_load(spa, SPA_LOAD_TRYIMPORT, SPA_IMPORT_EXISTING);
62656275

62666276
/*

tests/runfiles/common.run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ tests = ['zpool_import_001_pos', 'zpool_import_002_pos',
407407
'import_cachefile_mirror_detached',
408408
'import_cachefile_paths_changed',
409409
'import_cachefile_shared_device',
410-
'import_devices_missing',
410+
'import_devices_missing', 'import_log_missing',
411411
'import_paths_changed',
412412
'import_rewind_config_changed',
413413
'import_rewind_device_replaced']

tests/zfs-tests/tests/functional/cli_root/zpool_import/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ dist_pkgdata_SCRIPTS = \
1212
import_cachefile_paths_changed.ksh \
1313
import_cachefile_shared_device.ksh \
1414
import_devices_missing.ksh \
15+
import_log_missing.ksh \
1516
import_paths_changed.ksh \
1617
import_rewind_config_changed.ksh \
1718
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)