1#!/usr/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# 15# Copyright (c) 2016 by Delphix. All rights reserved. 16# 17 18. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.kshlib 19 20# 21# DESCRIPTION: 22# A pool should be importable when up to 2 top-level devices are missing. 23# 24# STRATEGY: 25# 1. Create a pool. 26# 2. Write some data to the pool and checksum it. 27# 3. Add one or more devices. 28# 4. Write more data to the pool and checksum it. 29# 5. Export the pool. 30# 6. Move added devices out of the devices directory. 31# 7. Import the pool with missing devices. 32# 8. Verify that the first batch of data is intact. 33# 9. Verify that accessing the second batch of data doesn't suspend pool. 34# 10. Export the pool, move back missing devices, Re-import the pool. 35# 11. Verify that all the data is intact. 36# 37 38verify_runnable "global" 39 40function custom_cleanup 41{ 42 log_must set_spa_load_verify_metadata 1 43 log_must set_spa_load_verify_data 1 44 log_must set_zfs_max_missing_tvds 0 45 log_must rm -rf $BACKUP_DEVICE_DIR 46 # Highly damaged pools may fail to be destroyed, so we export them. 47 poolexists $TESTPOOL1 && log_must zpool export $TESTPOOL1 48 cleanup 49} 50 51log_onexit custom_cleanup 52 53function test_devices_missing 54{ 55 typeset poolcreate="$1" 56 typeset addvdevs="$2" 57 typeset missingvdevs="$3" 58 typeset -i missingtvds="$4" 59 60 log_note "$0: pool '$poolcreate', adding $addvdevs, then" \ 61 "moving away $missingvdevs." 62 63 log_must zpool create $TESTPOOL1 $poolcreate 64 65 log_must generate_data $TESTPOOL1 $MD5FILE "first" 66 67 log_must zpool add $TESTPOOL1 $addvdevs 68 69 log_must generate_data $TESTPOOL1 $MD5FILE2 "second" 70 71 log_must zpool export $TESTPOOL1 72 73 log_must mv $missingvdevs $BACKUP_DEVICE_DIR 74 75 # Tell zfs that it is ok to import a pool with missing top-level vdevs 76 log_must set_zfs_max_missing_tvds $missingtvds 77 # Missing devices means that data or metadata may be corrupted. 78 (( missingtvds > 1 )) && log_must set_spa_load_verify_metadata 0 79 log_must set_spa_load_verify_data 0 80 log_must zpool import -o readonly=on -d $DEVICE_DIR $TESTPOOL1 81 82 log_must verify_data_md5sums $MD5FILE 83 84 log_note "Try reading second batch of data, make sure pool doesn't" \ 85 "get suspended." 86 verify_data_md5sums $MD5FILE >/dev/null 2>&1 87 88 log_must zpool export $TESTPOOL1 89 90 typeset newpaths=$(echo "$missingvdevs" | \ 91 sed "s:$DEVICE_DIR:$BACKUP_DEVICE_DIR:g") 92 log_must mv $newpaths $DEVICE_DIR 93 log_must set_spa_load_verify_metadata 1 94 log_must set_spa_load_verify_data 1 95 log_must set_zfs_max_missing_tvds 0 96 log_must zpool import -d $DEVICE_DIR $TESTPOOL1 97 98 log_must verify_data_md5sums $MD5FILE 99 log_must verify_data_md5sums $MD5FILE2 100 101 # Cleanup 102 log_must zpool destroy $TESTPOOL1 103 104 log_note "" 105} 106 107log_must mkdir $BACKUP_DEVICE_DIR 108 109test_devices_missing "$VDEV0" "$VDEV1" "$VDEV1" 1 110test_devices_missing "$VDEV0" "$VDEV1 $VDEV2" "$VDEV1" 1 111test_devices_missing "mirror $VDEV0 $VDEV1" "mirror $VDEV2 $VDEV3" \ 112 "$VDEV2 $VDEV3" 1 113test_devices_missing "$VDEV0 log $VDEV1" "$VDEV2" "$VDEV2" 1 114 115# 116# Note that we are testing for 2 non-consecutive missing devices. 117# Missing consecutive devices results in missing metadata. Because of 118# Missing metadata can cause the root dataset to fail to mount. 119# 120test_devices_missing "$VDEV0" "$VDEV1 $VDEV2 $VDEV3" "$VDEV1 $VDEV3" 2 121 122log_pass "zpool import succeeded with missing devices." 123