Initial import of binutils 2.22 on the new vendor branch
[dragonfly.git] / contrib / lvm2 / dist / test / t-pvcreate-operation.sh
1 # Copyright (C) 2008 Red Hat, Inc. All rights reserved.
2 #
3 # This copyrighted material is made available to anyone wishing to use,
4 # modify, copy, or redistribute it subject to the terms and conditions
5 # of the GNU General Public License v.2.
6 #
7 # You should have received a copy of the GNU General Public License
8 # along with this program; if not, write to the Free Software Foundation,
9 # Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
10
11 . ./test-utils.sh
12
13 aux prepare_devs 4
14
15 for mdatype in 1 2
16 do
17 # pvcreate (lvm$mdatype) refuses to overwrite an mounted filesystem (bz168330)
18         test ! -d $G_root_/mnt && mkdir $G_root_/mnt 
19         if mke2fs $dev1; then
20                 mount $dev1 $G_root_/mnt
21                 not pvcreate -M$mdatype $dev1 2>err
22                 grep "Can't open $dev1 exclusively.  Mounted filesystem?" err
23                 umount $dev1
24         fi
25
26 # pvcreate (lvm$mdatype) succeeds when run repeatedly (pv not in a vg) (bz178216)
27     pvcreate -M$mdatype $dev1
28     pvcreate -M$mdatype $dev1
29     pvremove -f $dev1
30
31 # pvcreate (lvm$mdatype) fails when PV belongs to VG" \
32     pvcreate -M$mdatype $dev1
33     vgcreate -M$mdatype $vg1 $dev1
34     not pvcreate -M$mdatype $dev1
35
36     vgremove -f $vg1
37     pvremove -f $dev1
38
39 # pvcreate (lvm$mdatype) fails when PV1 does and PV2 does not belong to VG
40     pvcreate -M$mdatype $dev1
41     pvcreate -M$mdatype $dev2
42     vgcreate -M$mdatype $vg1 $dev1
43
44 # pvcreate a second time on $dev2 and $dev1
45     not pvcreate -M$mdatype $dev2 $dev1
46
47     vgremove -f $vg1
48     pvremove -f $dev2
49     pvremove -f $dev1
50
51 # NOTE: Force pvcreate after test completion to ensure clean device
52 #test_expect_success \
53 #  "pvcreate (lvm$mdatype) fails on md component device" \
54 #  'mdadm -C -l raid0 -n 2 /dev/md0 $dev1 $dev2 &&
55 #   pvcreate -M$mdatype $dev1;
56 #   status=$?; echo status=$status; test $status != 0 &&
57 #   mdadm --stop /dev/md0 &&
58 #   pvcreate -ff -y -M$mdatype $dev1 $dev2 &&
59 #   pvremove -f $dev1 $dev2'
60 done
61
62 # pvcreate (lvm2) fails without -ff when PV with metadatacopies=0 belongs to VG
63 pvcreate --metadatacopies 0 $dev1
64 pvcreate --metadatacopies 1 $dev2
65 vgcreate $vg1 $dev1 $dev2
66 not pvcreate $dev1
67 vgremove -f $vg1
68 pvremove -f $dev2
69 pvremove -f $dev1
70
71 # pvcreate (lvm2) succeeds with -ff when PV with metadatacopies=0 belongs to VG
72 pvcreate --metadatacopies 0 $dev1 
73 pvcreate --metadatacopies 1 $dev2
74 vgcreate $vg1 $dev1 $dev2 
75 pvcreate -ff -y $dev1 
76 vgreduce --removemissing $vg1 
77 vgremove -ff $vg1 
78 pvremove -f $dev2 
79 pvremove -f $dev1
80
81 for i in 0 1 2 3
82 do
83 # pvcreate (lvm2) succeeds writing LVM label at sector $i
84     pvcreate --labelsector $i $dev1
85     dd if=$dev1 bs=512 skip=$i count=1 2>/dev/null | strings | grep -q LABELONE;
86     pvremove -f $dev1
87 done
88
89 # pvcreate (lvm2) fails writing LVM label at sector 4
90 not pvcreate --labelsector 4 $dev1
91
92 backupfile=mybackupfile-$(this_test_)
93 uuid1=freddy-fred-fred-fred-fred-fred-freddy
94 uuid2=freddy-fred-fred-fred-fred-fred-fredie
95 bogusuuid=fred
96
97 # pvcreate rejects uuid option with less than 32 characters
98 not pvcreate --uuid $bogusuuid $dev1
99
100 # pvcreate rejects uuid already in use
101 pvcreate --uuid $uuid1 $dev1
102 not pvcreate --uuid $uuid1 $dev2
103
104 # pvcreate rejects non-existent file given with restorefile
105 not pvcreate --uuid $uuid1 --restorefile $backupfile $dev1
106
107 # pvcreate rejects restorefile with uuid not found in file
108 pvcreate --uuid $uuid1 $dev1
109 vgcfgbackup -f $backupfile
110 not pvcreate --uuid $uuid2 --restorefile $backupfile $dev2
111
112 # pvcreate wipes swap signature when forced
113 dd if=/dev/zero of=$dev1 bs=1024 count=64
114 mkswap $dev1
115 blkid -c /dev/null $dev1 | grep "swap"
116 pvcreate -f $dev1
117 blkid -c /dev/null $dev1 | not grep "swap"