1eda14cbcSMatt Macy#!/bin/ksh -p 2eda14cbcSMatt Macy# 3eda14cbcSMatt Macy# CDDL HEADER START 4eda14cbcSMatt Macy# 5eda14cbcSMatt Macy# The contents of this file are subject to the terms of the 6eda14cbcSMatt Macy# Common Development and Distribution License (the "License"). 7eda14cbcSMatt Macy# You may not use this file except in compliance with the License. 8eda14cbcSMatt Macy# 9eda14cbcSMatt Macy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*271171e0SMartin Matuska# or https://opensource.org/licenses/CDDL-1.0. 11eda14cbcSMatt Macy# See the License for the specific language governing permissions 12eda14cbcSMatt Macy# and limitations under the License. 13eda14cbcSMatt Macy# 14eda14cbcSMatt Macy# When distributing Covered Code, include this CDDL HEADER in each 15eda14cbcSMatt Macy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16eda14cbcSMatt Macy# If applicable, add the following below this CDDL HEADER, with the 17eda14cbcSMatt Macy# fields enclosed by brackets "[]" replaced with your own identifying 18eda14cbcSMatt Macy# information: Portions Copyright [yyyy] [name of copyright owner] 19eda14cbcSMatt Macy# 20eda14cbcSMatt Macy# CDDL HEADER END 21eda14cbcSMatt Macy# 22eda14cbcSMatt Macy 23eda14cbcSMatt Macy# 24eda14cbcSMatt Macy# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 25eda14cbcSMatt Macy# Use is subject to license terms. 26eda14cbcSMatt Macy# 27eda14cbcSMatt Macy 28eda14cbcSMatt Macy# 29eda14cbcSMatt Macy# Copyright (c) 2012, 2016 by Delphix. All rights reserved. 30eda14cbcSMatt Macy# 31eda14cbcSMatt Macy 32eda14cbcSMatt Macy. $STF_SUITE/include/libtest.shlib 33eda14cbcSMatt Macy. $STF_SUITE/tests/functional/cli_root/zfs_mount/zfs_mount.kshlib 34eda14cbcSMatt Macy. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg 35eda14cbcSMatt Macy 36eda14cbcSMatt Macy# 37eda14cbcSMatt Macy# DESCRIPTION: 38eda14cbcSMatt Macy# An exported pool can be imported under a different name. Hence 39eda14cbcSMatt Macy# we test that a previously exported pool can be renamed. 40eda14cbcSMatt Macy# 41eda14cbcSMatt Macy# STRATEGY: 42eda14cbcSMatt Macy# 1. Copy a file into the default test directory. 43eda14cbcSMatt Macy# 2. Umount the default directory. 44eda14cbcSMatt Macy# 3. Export the pool. 45eda14cbcSMatt Macy# 4. Import the pool using the name ${TESTPOOL}-new, 46eda14cbcSMatt Macy# and using the various combinations. 47eda14cbcSMatt Macy# - Regular import 48eda14cbcSMatt Macy# - Alternate Root Specified 49eda14cbcSMatt Macy# 5. Verify it exists in the 'zpool list' output. 50eda14cbcSMatt Macy# 6. Verify the default file system is mounted and that the file 51eda14cbcSMatt Macy# from step (1) is present. 52eda14cbcSMatt Macy# 53eda14cbcSMatt Macy 54eda14cbcSMatt Macyverify_runnable "global" 55eda14cbcSMatt Macy 56eda14cbcSMatt Macyset -A pools "$TESTPOOL" "$TESTPOOL1" 57eda14cbcSMatt Macyset -A devs "" "-d $DEVICE_DIR" 58eda14cbcSMatt Macyset -A options "" "-R $ALTER_ROOT" 59eda14cbcSMatt Macyset -A mtpts "$TESTDIR" "$TESTDIR1" 60eda14cbcSMatt Macy 61eda14cbcSMatt Macy 62eda14cbcSMatt Macyfunction cleanup 63eda14cbcSMatt Macy{ 64eda14cbcSMatt Macy typeset -i i=0 65eda14cbcSMatt Macy while (( i < ${#pools[*]} )); do 66eda14cbcSMatt Macy if poolexists "${pools[i]}-new" ; then 67eda14cbcSMatt Macy log_must zpool export "${pools[i]}-new" 68eda14cbcSMatt Macy 69eda14cbcSMatt Macy [[ -d /${pools[i]}-new ]] && \ 70eda14cbcSMatt Macy log_must rm -rf /${pools[i]}-new 71eda14cbcSMatt Macy 72eda14cbcSMatt Macy log_must zpool import ${devs[i]} \ 73eda14cbcSMatt Macy "${pools[i]}-new" ${pools[i]} 74eda14cbcSMatt Macy fi 75eda14cbcSMatt Macy 76eda14cbcSMatt Macy datasetexists "${pools[i]}" || \ 77eda14cbcSMatt Macy log_must zpool import ${devs[i]} ${pools[i]} 78eda14cbcSMatt Macy 79eda14cbcSMatt Macy ismounted "${pools[i]}/$TESTFS" || \ 80eda14cbcSMatt Macy log_must zfs mount ${pools[i]}/$TESTFS 81eda14cbcSMatt Macy 82eda14cbcSMatt Macy [[ -e ${mtpts[i]}/$TESTFILE0 ]] && \ 83eda14cbcSMatt Macy log_must rm -rf ${mtpts[i]}/$TESTFILE0 84eda14cbcSMatt Macy 85eda14cbcSMatt Macy ((i = i + 1)) 86eda14cbcSMatt Macy 87eda14cbcSMatt Macy done 88eda14cbcSMatt Macy 89eda14cbcSMatt Macy cleanup_filesystem $TESTPOOL1 $TESTFS $TESTDIR1 90eda14cbcSMatt Macy 91eda14cbcSMatt Macy destroy_pool $TESTPOOL1 92eda14cbcSMatt Macy 93eda14cbcSMatt Macy [[ -d $ALTER_ROOT ]] && \ 94eda14cbcSMatt Macy log_must rm -rf $ALTER_ROOT 95eda14cbcSMatt Macy [[ -e $VDEV_FILE ]] && \ 96eda14cbcSMatt Macy log_must rm $VDEV_FILE 97eda14cbcSMatt Macy} 98eda14cbcSMatt Macy 99eda14cbcSMatt Macylog_onexit cleanup 100eda14cbcSMatt Macy 101eda14cbcSMatt Macylog_assert "Verify that an imported pool can be renamed." 102eda14cbcSMatt Macy 103eda14cbcSMatt Macysetup_filesystem "$DEVICE_FILES" $TESTPOOL1 $TESTFS $TESTDIR1 104716fd348SMartin Matuskaread -r checksum1 _ < <(cksum $MYTESTFILE) 105eda14cbcSMatt Macy 106eda14cbcSMatt Macytypeset -i i=0 107eda14cbcSMatt Macytypeset -i j=0 108eda14cbcSMatt Macytypeset basedir 109eda14cbcSMatt Macy 110eda14cbcSMatt Macywhile (( i < ${#pools[*]} )); do 111eda14cbcSMatt Macy guid=$(get_config ${pools[i]} pool_guid) 112eda14cbcSMatt Macy log_must cp $MYTESTFILE ${mtpts[i]}/$TESTFILE0 113eda14cbcSMatt Macy 114eda14cbcSMatt Macy log_must zfs umount ${mtpts[i]} 115eda14cbcSMatt Macy 116eda14cbcSMatt Macy j=0 117eda14cbcSMatt Macy while (( j < ${#options[*]} )); do 118eda14cbcSMatt Macy log_must zpool export ${pools[i]} 119eda14cbcSMatt Macy 120eda14cbcSMatt Macy [[ -d /${pools[i]} ]] && \ 121eda14cbcSMatt Macy log_must rm -rf /${pools[i]} 122eda14cbcSMatt Macy 123eda14cbcSMatt Macy typeset target=${pools[i]} 124eda14cbcSMatt Macy if (( RANDOM % 2 == 0 )) ; then 125eda14cbcSMatt Macy target=$guid 126eda14cbcSMatt Macy log_note "Import by guid." 127eda14cbcSMatt Macy fi 128eda14cbcSMatt Macy 129eda14cbcSMatt Macy log_must zpool import ${devs[i]} ${options[j]} \ 130eda14cbcSMatt Macy $target ${pools[i]}-new 131eda14cbcSMatt Macy 132eda14cbcSMatt Macy log_must poolexists "${pools[i]}-new" 133eda14cbcSMatt Macy 134eda14cbcSMatt Macy log_must ismounted ${pools[i]}-new/$TESTFS 135eda14cbcSMatt Macy 136eda14cbcSMatt Macy basedir=${mtpts[i]} 137eda14cbcSMatt Macy [[ -n ${options[j]} ]] && \ 138eda14cbcSMatt Macy basedir=$ALTER_ROOT/${mtpts[i]} 139eda14cbcSMatt Macy 140eda14cbcSMatt Macy [[ ! -e $basedir/$TESTFILE0 ]] && \ 141eda14cbcSMatt Macy log_fail "$basedir/$TESTFILE0 missing after import." 142eda14cbcSMatt Macy 143716fd348SMartin Matuska read -r checksum2 _ < <(cksum $basedir/$TESTFILE0) 144716fd348SMartin Matuska log_must [ "$checksum1" = "$checksum2" ] 145eda14cbcSMatt Macy 146eda14cbcSMatt Macy log_must zpool export "${pools[i]}-new" 147eda14cbcSMatt Macy 148eda14cbcSMatt Macy [[ -d /${pools[i]}-new ]] && \ 149eda14cbcSMatt Macy log_must rm -rf /${pools[i]}-new 150eda14cbcSMatt Macy 151eda14cbcSMatt Macy target=${pools[i]}-new 152eda14cbcSMatt Macy if (( RANDOM % 2 == 0 )) ; then 153eda14cbcSMatt Macy target=$guid 154eda14cbcSMatt Macy fi 155eda14cbcSMatt Macy log_must zpool import ${devs[i]} $target ${pools[i]} 156eda14cbcSMatt Macy 157eda14cbcSMatt Macy ((j = j + 1)) 158eda14cbcSMatt Macy done 159eda14cbcSMatt Macy 160eda14cbcSMatt Macy ((i = i + 1)) 161eda14cbcSMatt Macydone 162eda14cbcSMatt Macy 163eda14cbcSMatt MacyVDEV_FILE=$(mktemp $TEST_BASE_DIR/tmp.XXXXXX) 164eda14cbcSMatt Macy 165eda14cbcSMatt Macylog_must mkfile -n 128M $VDEV_FILE 166eda14cbcSMatt Macylog_must zpool create overflow $VDEV_FILE 167eda14cbcSMatt Macylog_must zfs create overflow/testfs 168eda14cbcSMatt MacyID=$(zpool get -Ho value guid overflow) 169eda14cbcSMatt Macylog_must zpool export overflow 170eda14cbcSMatt Macylog_mustnot zpool import -d $TEST_BASE_DIR $(echo id) \ 171eda14cbcSMatt Macy $(printf "%*s\n" 250 "" | tr ' ' 'c') 172eda14cbcSMatt Macy 173eda14cbcSMatt Macylog_pass "Successfully imported and renamed a ZPOOL" 174