1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
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#
15# Copyright 2016 Nexenta Systems, Inc.
16# Copyright (c) 2019 by Lawrence Livermore National Security, LLC.
17#
18
19. $STF_SUITE/tests/functional/cli_root/zpool_labelclear/labelclear.cfg
20
21# DESCRIPTION:
22#    Check that `zpool labelclear` can clear labels on removed devices.
23#
24# STRATEGY:
25# 1. Create a pool with primary, log, spare and cache devices.
26# 2. Remove a top-level vdev, log, spare, and cache device.
27# 3. Run `zpool labelclear` on the removed device.
28# 4. Verify the label has been removed.
29#
30
31verify_runnable "global"
32
33function cleanup
34{
35	poolexists $TESTPOOL && destroy_pool $TESTPOOL
36	rm -f $DEVICE1 $DEVICE2 $DEVICE3 $DEVICE4 $DEVICE5
37}
38
39log_onexit cleanup
40log_assert "zpool labelclear works for removed devices"
41
42DEVICE1="$TEST_BASE_DIR/device-1"
43DEVICE2="$TEST_BASE_DIR/device-2"
44DEVICE3="$TEST_BASE_DIR/device-3"
45DEVICE4="$TEST_BASE_DIR/device-4"
46DEVICE5="$TEST_BASE_DIR/device-5"
47
48log_must truncate -s $((SPA_MINDEVSIZE * 8)) $DEVICE1
49log_must truncate -s $SPA_MINDEVSIZE $DEVICE2 $DEVICE3 $DEVICE4 $DEVICE5
50
51log_must zpool create -f $TESTPOOL $DEVICE1 $DEVICE2 \
52    log $DEVICE3 cache $DEVICE4 spare $DEVICE5
53sync_all_pools
54
55# Remove each type of vdev and verify the label can be cleared.
56for dev in $DEVICE5 $DEVICE4 $DEVICE3 $DEVICE2; do
57	log_must zpool remove $TESTPOOL $dev
58	sync_pool $TESTPOOL true
59	log_must zpool labelclear $dev
60	log_mustnot zdb -lq $dev
61done
62
63log_pass "zpool labelclear works for removed devices"
64