1#!/bin/ksh -p 2# 3# CDDL HEADER START 4# 5# The contents of this file are subject to the terms of the 6# Common Development and Distribution License (the "License"). 7# You may not use this file except in compliance with the License. 8# 9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10# or http://www.opensolaris.org/os/licensing. 11# See the License for the specific language governing permissions 12# and limitations under the License. 13# 14# When distributing Covered Code, include this CDDL HEADER in each 15# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16# If applicable, add the following below this CDDL HEADER, with the 17# fields enclosed by brackets "[]" replaced with your own identifying 18# information: Portions Copyright [yyyy] [name of copyright owner] 19# 20# CDDL HEADER END 21# 22 23# 24# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 25# Use is subject to license terms. 26# 27 28# 29# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 30# 31 32. $STF_SUITE/include/libtest.shlib 33. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib 34. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg 35 36# 37# DESCRIPTION: 38# Once a pool has been exported, it should be recreated after a 39# successful import. Verify that is true. 40# 41# STRATEGY: 42# 1. Populate the default test directory and unmount it. 43# 2. Export the default test pool. 44# 3. Import it using the various combinations. 45# - Regular import 46# - Alternate Root Specified 47# Try to import it by name or guid randomly. 48# 4. Verify it shows up under 'zpool list'. 49# 5. Verify it can be mounted again and contains a file. 50# 51 52verify_runnable "global" 53 54set -A pools "$TESTPOOL" "$TESTPOOL1" 55set -A devs "" "-d $DEVICE_DIR" 56set -A options "" "-R $ALTER_ROOT" 57set -A mtpts "$TESTDIR" "$TESTDIR1" 58 59 60function cleanup 61{ 62 typeset -i i=0 63 64 while (( i < ${#pools[*]} )); do 65 poolexists ${pools[i]} && \ 66 log_must zpool export ${pools[i]} 67 68 datasetexists "${pools[i]}/$TESTFS" || \ 69 log_must zpool import ${devs[i]} ${pools[i]} 70 71 ismounted "${pools[i]}/$TESTFS" || \ 72 log_must zfs mount ${pools[i]}/$TESTFS 73 74 [[ -e ${mtpts[i]}/$TESTFILE0 ]] && \ 75 log_must rm -rf ${mtpts[i]}/$TESTFILE0 76 77 ((i = i + 1)) 78 done 79 80 cleanup_filesystem $TESTPOOL1 $TESTFS 81 82 destroy_pool $TESTPOOL1 83 84 [[ -d $ALTER_ROOT ]] && \ 85 log_must rm -rf $ALTER_ROOT 86} 87 88log_onexit cleanup 89 90log_assert "Verify that an exported pool can be imported." 91 92setup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1 93 94checksum1=$(sum $MYTESTFILE | awk '{print $1}') 95 96typeset -i i=0 97typeset -i j=0 98typeset basedir 99 100while (( i < ${#pools[*]} )); do 101 guid=$(get_config ${pools[i]} pool_guid) 102 log_must cp $MYTESTFILE ${mtpts[i]}/$TESTFILE0 103 104 log_must zfs umount ${mtpts[i]} 105 106 j=0 107 while (( j < ${#options[*]} )); do 108 log_must zpool export ${pools[i]} 109 110 typeset target=${pools[i]} 111 if (( RANDOM % 2 == 0 )) ; then 112 target=$guid 113 log_note "Import by guid." 114 fi 115 log_must zpool import ${devs[i]} ${options[j]} $target 116 117 log_must poolexists ${pools[i]} 118 119 log_must ismounted ${pools[i]}/$TESTFS 120 121 basedir=${mtpts[i]} 122 [[ -n ${options[j]} ]] && \ 123 basedir=$ALTER_ROOT/${mtpts[i]} 124 125 [[ ! -e $basedir/$TESTFILE0 ]] && \ 126 log_fail "$basedir/$TESTFILE0 missing after import." 127 128 checksum2=$(sum $basedir/$TESTFILE0 | awk '{print $1}') 129 [[ "$checksum1" != "$checksum2" ]] && \ 130 log_fail "Checksums differ ($checksum1 != $checksum2)" 131 132 ((j = j + 1)) 133 done 134 135 ((i = i + 1)) 136done 137 138log_pass "Successfully imported a ZPOOL" 139