xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_import/zpool_import_014_pos.ksh (revision a89c0811c892ec231725fe10817ef95dda813c06)
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 2016, loli10K. All rights reserved.
25#
26
27. $STF_SUITE/include/libtest.shlib
28. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.cfg
29
30#
31# DESCRIPTION:
32#	Temporary pool names should not be persisted on devices.
33#
34# STRATEGY:
35#	1. Create pool A, then export it.
36#	2. Re-import the pool with a temporary name B, then export it.
37#	3. Verify device labels still contain the expected pool name (A).
38#
39
40verify_runnable "global"
41
42function cleanup
43{
44	typeset dt
45	for dt in $poolB $poolA; do
46		destroy_pool $dt
47	done
48
49	log_must rm -rf $DEVICE_DIR/*
50	typeset i=0
51	while (( i < $MAX_NUM )); do
52		log_must mkfile $FILE_SIZE ${DEVICE_DIR}/${DEVICE_FILE}$i
53		((i += 1))
54	done
55}
56
57#
58# Verify name of (exported) pool from device $1 label is equal to $2
59# $1 device
60# $2 pool name
61#
62function verify_pool_name
63{
64	typeset device=$1
65	typeset poolname=$2
66	typeset labelname
67
68	zdb -e -l $device | grep " name:" | {
69		while read labelname ; do
70			if [[ "name: '$poolname'" != "$labelname" ]]; then
71				return 1
72			fi
73		done
74	}
75	return 0
76}
77
78log_assert "Temporary pool names should not be persisted on devices."
79log_onexit cleanup
80
81poolA=poolA.$$; poolB=poolB.$$;
82
83log_must zpool create $poolA $VDEV0
84log_must zpool export $poolA
85
86log_must zpool import -t $poolA $poolB -d $DEVICE_DIR
87log_must zpool export $poolB
88
89log_must eval "verify_pool_name $VDEV0 $poolA"
90
91log_pass "Temporary pool names are not persisted on devices."
92