aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cli_root/zpool_import/import_devices_missing.ksh
blob: 53828c912ca32a8c484e393d43325e1a15286d45 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/ksh -p

#
# 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.
#

#
# Copyright (c) 2016 by Delphix. All rights reserved.
#

. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.kshlib

#
# DESCRIPTION:
#	A pool should be importable when up to 2 top-level devices are missing.
#
# STRATEGY:
#	1. Create a pool.
#	2. Write some data to the pool and checksum it.
#	3. Add one or more devices.
#	4. Write more data to the pool and checksum it.
#	5. Export the pool.
#	6. Move added devices out of the devices directory.
#	7. Import the pool with missing devices.
#	8. Verify that the first batch of data is intact.
#	9. Verify that accessing the second batch of data doesn't suspend pool.
#	10. Export the pool, move back missing devices, Re-import the pool.
#	11. Verify that all the data is intact.
#

verify_runnable "global"

function custom_cleanup
{
	log_must set_spa_load_verify_metadata 1
	log_must set_spa_load_verify_data 1
	log_must set_zfs_max_missing_tvds 0
	log_must rm -rf $BACKUP_DEVICE_DIR
	# Highly damaged pools may fail to be destroyed, so we export them.
	poolexists $TESTPOOL1 && log_must zpool export $TESTPOOL1
	cleanup
}

log_onexit custom_cleanup

function test_devices_missing
{
	typeset poolcreate="$1"
	typeset addvdevs="$2"
	typeset missingvdevs="$3"
	typeset -i missingtvds="$4"

	log_note "$0: pool '$poolcreate', adding $addvdevs, then" \
	    "moving away $missingvdevs."

	log_must zpool create $TESTPOOL1 $poolcreate

	log_must generate_data $TESTPOOL1 $MD5FILE "first"

	log_must zpool add $TESTPOOL1 $addvdevs

	log_must generate_data $TESTPOOL1 $MD5FILE2 "second"

	log_must zpool export $TESTPOOL1

	log_must mv $missingvdevs $BACKUP_DEVICE_DIR

	# Tell zfs that it is ok to import a pool with missing top-level vdevs
	log_must set_zfs_max_missing_tvds $missingtvds
	# Missing devices means that data or metadata may be corrupted.
	(( missingtvds > 1 )) && log_must set_spa_load_verify_metadata 0
	log_must set_spa_load_verify_data 0
	log_must zpool import -o readonly=on -d $DEVICE_DIR $TESTPOOL1

	log_must verify_data_md5sums $MD5FILE

	log_note "Try reading second batch of data, make sure pool doesn't" \
	    "get suspended."
	verify_data_md5sums $MD5FILE >/dev/null 2>&1

	log_must zpool export $TESTPOOL1

	typeset newpaths=$(echo "$missingvdevs" | \
		sed "s:$DEVICE_DIR:$BACKUP_DEVICE_DIR:g")
	log_must mv $newpaths $DEVICE_DIR
	log_must set_spa_load_verify_metadata 1
	log_must set_spa_load_verify_data 1
	log_must set_zfs_max_missing_tvds 0
	log_must zpool import -d $DEVICE_DIR $TESTPOOL1

	log_must verify_data_md5sums $MD5FILE
	log_must verify_data_md5sums $MD5FILE2

	# Cleanup
	log_must zpool destroy $TESTPOOL1

	log_note ""
}

log_must mkdir -p $BACKUP_DEVICE_DIR

test_devices_missing "$VDEV0" "$VDEV1" "$VDEV1" 1
test_devices_missing "$VDEV0" "$VDEV1 $VDEV2" "$VDEV1" 1
test_devices_missing "mirror $VDEV0 $VDEV1" "mirror $VDEV2 $VDEV3" \
    "$VDEV2 $VDEV3" 1
test_devices_missing "$VDEV0 log $VDEV1" "$VDEV2" "$VDEV2" 1

#
# Note that we are testing for 2 non-consecutive missing devices.
# Missing consecutive devices results in missing metadata. Because of
# Missing metadata can cause the root dataset to fail to mount.
#
test_devices_missing "$VDEV0" "$VDEV1 $VDEV2 $VDEV3" "$VDEV1 $VDEV3" 2

log_pass "zpool import succeeded with missing devices."