Tizen 2.1 base
[external/device-mapper.git] / 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 $TESTDIR/mnt && mkdir $TESTDIR/mnt
19         if mke2fs $dev1; then
20                 mount $dev1 $TESTDIR/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=$PREFIX.mybackupfile
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 --norestorefile --uuid $bogusuuid $dev1
99
100 # pvcreate rejects uuid option without restorefile
101 not pvcreate --uuid $uuid1 $dev1
102
103 # pvcreate rejects uuid already in use
104 pvcreate --norestorefile --uuid $uuid1 $dev1
105 not pvcreate --norestorefile --uuid $uuid1 $dev2
106
107 # pvcreate rejects non-existent file given with restorefile
108 not pvcreate --uuid $uuid1 --restorefile $backupfile $dev1
109
110 # pvcreate rejects restorefile with uuid not found in file
111 pvcreate --norestorefile --uuid $uuid1 $dev1
112 vgcfgbackup -f $backupfile
113 not pvcreate --uuid $uuid2 --restorefile $backupfile $dev2
114
115 # pvcreate wipes swap signature when forced
116 dd if=/dev/zero of=$dev1 bs=1024 count=64
117 mkswap $dev1
118 blkid -c /dev/null $dev1 | grep "swap"
119 pvcreate -f $dev1
120 # blkid cannot make up its mind whether not finding anything it knows is a failure or not
121 (blkid -c /dev/null $dev1 || true) | not grep "swap"