1#!/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. $STF_SUITE/tests/functional/cli_root/zpool_import/zpool_import.kshlib
15
16#
17# DESCRIPTION:
18#	Import with missing log device should not remove spare/cache.
19#
20# STRATEGY:
21#	1. Create a pool.
22#	2. Add spare, cache and log devices to the pool.
23#	3. Export the pool.
24#	4. Remove the log device.
25#	5. Import the pool with -m flag.
26#	6. Verify that spare and cache are still present in the pool.
27#
28
29verify_runnable "global"
30
31log_onexit cleanup
32
33function test_missing_log
34{
35	typeset poolcreate="$1"
36	typeset cachevdev="$2"
37	typeset sparevdev="$3"
38	typeset logvdev="$4"
39	typeset missingvdev="$4"
40
41	log_note "$0: pool '$poolcreate', adding $cachevdev, $sparevdev," \
42		"$logvdev then moving away $missingvdev."
43
44	log_must zpool create $TESTPOOL1 $poolcreate
45
46	log_must zpool add $TESTPOOL1 cache $cachevdev spare $sparevdev \
47		log $logvdev
48
49	log_must_busy zpool export $TESTPOOL1
50
51	log_must mv $missingvdev $BACKUP_DEVICE_DIR
52
53	log_must zpool import -m -d $DEVICE_DIR $TESTPOOL1
54
55	CACHE_PRESENT=$(zpool status -v $TESTPOOL1 | grep $cachevdev)
56
57	SPARE_PRESENT=$(zpool status -v $TESTPOOL1 | grep $sparevdev)
58
59	if [ -z "$CACHE_PRESENT"] || [ -z "SPARE_PRESENT"]
60	then
61		log_fail "cache/spare vdev missing after importing with missing" \
62			"log device"
63	fi
64
65	# Cleanup
66	log_must zpool destroy $TESTPOOL1
67
68	log_note ""
69}
70
71log_must mkdir -p $BACKUP_DEVICE_DIR
72
73test_missing_log "$VDEV0" "$VDEV1" "$VDEV2" "$VDEV3"
74
75log_pass "zpool import succeeded with missing log device"
76