1#!/bin/sh
2# Copyright (C) 2008 Red Hat, Inc. All rights reserved.
3#
4# This copyrighted material is made available to anyone wishing to use,
5# modify, copy, or redistribute it subject to the terms and conditions
6# of the GNU General Public License v.2.
7#
8# You should have received a copy of the GNU General Public License
9# along with this program; if not, write to the Free Software Foundation,
10# Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
11
12. ./test-utils.sh
13
14aux prepare_devs 3
15pvcreate $dev1
16pvcreate --metadatacopies 0 $dev2
17pvcreate --metadatacopies 2 $dev3
18pvremove $dev2
19
20# failing, but still removing everything what can be removed
21# is somewhat odd as default, what do we have -f for?
22pvs | not grep $dev2
23pvcreate  --metadatacopies 0 $dev2
24
25# check pvremove refuses to remove pv in a vg
26vgcreate -c n $vg $dev1 $dev2
27not pvremove $dev2 $dev3
28
29for mdacp in 0 1 2; do
30    # check pvremove truly wipes the label (pvscan wont find) (---metadatacopies $mdacp)
31    pvcreate --metadatacopies $mdacp $dev3
32    pvremove $dev3
33    # try to remove agail - should fail cleanly
34    not pvremove $dev3
35    pvscan | not grep $dev3
36
37	# bz179473 refuse to wipe non-PV device without -f
38    not pvremove $dev3
39    pvremove -f $dev3
40
41    # reset setup
42    vgremove -ff $vg
43    pvcreate --metadatacopies $mdacp $dev1
44    pvcreate $dev2
45    vgcreate $vg $dev1 $dev2
46
47    # pvremove -f fails when pv in a vg (---metadatacopies $mdacp)
48    not pvremove -f $dev1
49    pvs $dev1
50
51    # pvremove -ff fails without confirmation when pv in a vg (---metadatacopies $mdacp)
52    echo n | not pvremove -ff $dev1
53
54    # pvremove -ff succeds with confirmation when pv in a vg (---metadatacopies $mdacp)
55    yes | pvremove -ff $dev1
56    not pvs $dev1
57
58    vgreduce --removemissing $vg
59    pvcreate --metadatacopies $mdacp $dev1
60    vgextend $vg $dev1
61
62    # pvremove -ff -y is sufficient when pv in a vg (---metadatacopies $mdacp)" '
63    echo n | pvremove -ff -y $dev1
64
65    vgreduce --removemissing $vg
66    pvcreate --metadatacopies $mdacp $dev1
67    vgextend $vg $dev1
68done
69