1#!/bin/ksh -p
2#
3# This file and its contents are supplied under the terms of the
4# Common Development and Distribution License ("CDDL"), version 1.0.
5# You may only use this file in accordance with the terms of version
6# 1.0 of the CDDL.
7#
8# A full copy of the text of the CDDL should have accompanied this
9# source.  A copy of the CDDL is also available via the Internet at
10# http://www.illumos.org/license/CDDL.
11#
12
13#
14# Copyright 2016 Nexenta Systems, Inc.
15# Copyright (c) 2019 by Lawrence Livermore National Security, LLC.
16#
17
18. $STF_SUITE/tests/functional/cli_root/zpool_labelclear/labelclear.cfg
19
20# DESCRIPTION:
21#    Check that `zpool labelclear` can clear labels on removed devices.
22#
23# STRATEGY:
24# 1. Create a pool with primary, log, spare and cache devices.
25# 2. Remove a top-level vdev, log, spare, and cache device.
26# 3. Run `zpool labelclear` on the removed device.
27# 4. Verify the label has been removed.
28#
29
30verify_runnable "global"
31
32function cleanup
33{
34	poolexists $TESTPOOL && destroy_pool $TESTPOOL
35	rm -f $DEVICE1 $DEVICE2 $DEVICE3 $DEVICE4 $DEVICE5
36}
37
38log_onexit cleanup
39log_assert "zpool labelclear works for removed devices"
40
41DEVICE1="$TEST_BASE_DIR/device-1"
42DEVICE2="$TEST_BASE_DIR/device-2"
43DEVICE3="$TEST_BASE_DIR/device-3"
44DEVICE4="$TEST_BASE_DIR/device-4"
45DEVICE5="$TEST_BASE_DIR/device-5"
46
47log_must truncate -s $((SPA_MINDEVSIZE * 8)) $DEVICE1
48log_must truncate -s $SPA_MINDEVSIZE $DEVICE2 $DEVICE3 $DEVICE4 $DEVICE5
49
50log_must zpool create -f $TESTPOOL $DEVICE1 $DEVICE2 \
51    log $DEVICE3 cache $DEVICE4 spare $DEVICE5
52log_must zpool sync
53
54# Remove each type of vdev and verify the label can be cleared.
55for dev in $DEVICE5 $DEVICE4 $DEVICE3 $DEVICE2; do
56	log_must zpool remove $TESTPOOL $dev
57	log_must zpool sync $TESTPOOL
58	log_must zpool labelclear $dev
59	log_mustnot zdb -lq $dev
60done
61
62log_pass "zpool labelclear works for removed devices"
63