186d7f5d3SJohn Marino# Copyright (C) 2008 Red Hat, Inc. All rights reserved. 286d7f5d3SJohn Marino# 386d7f5d3SJohn Marino# This copyrighted material is made available to anyone wishing to use, 486d7f5d3SJohn Marino# modify, copy, or redistribute it subject to the terms and conditions 586d7f5d3SJohn Marino# of the GNU General Public License v.2. 686d7f5d3SJohn Marino# 786d7f5d3SJohn Marino# You should have received a copy of the GNU General Public License 886d7f5d3SJohn Marino# along with this program; if not, write to the Free Software Foundation, 986d7f5d3SJohn Marino# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1086d7f5d3SJohn Marino 1186d7f5d3SJohn Marino. ./test-utils.sh 1286d7f5d3SJohn Marino 1386d7f5d3SJohn Marinoaux prepare_devs 4 1486d7f5d3SJohn Marino 1586d7f5d3SJohn Marinofor mdatype in 1 2 1686d7f5d3SJohn Marinodo 1786d7f5d3SJohn Marino# pvcreate (lvm$mdatype) refuses to overwrite an mounted filesystem (bz168330) 1886d7f5d3SJohn Marino test ! -d $G_root_/mnt && mkdir $G_root_/mnt 1986d7f5d3SJohn Marino if mke2fs $dev1; then 2086d7f5d3SJohn Marino mount $dev1 $G_root_/mnt 2186d7f5d3SJohn Marino not pvcreate -M$mdatype $dev1 2>err 2286d7f5d3SJohn Marino grep "Can't open $dev1 exclusively. Mounted filesystem?" err 2386d7f5d3SJohn Marino umount $dev1 2486d7f5d3SJohn Marino fi 2586d7f5d3SJohn Marino 2686d7f5d3SJohn Marino# pvcreate (lvm$mdatype) succeeds when run repeatedly (pv not in a vg) (bz178216) 2786d7f5d3SJohn Marino pvcreate -M$mdatype $dev1 2886d7f5d3SJohn Marino pvcreate -M$mdatype $dev1 2986d7f5d3SJohn Marino pvremove -f $dev1 3086d7f5d3SJohn Marino 3186d7f5d3SJohn Marino# pvcreate (lvm$mdatype) fails when PV belongs to VG" \ 3286d7f5d3SJohn Marino pvcreate -M$mdatype $dev1 3386d7f5d3SJohn Marino vgcreate -M$mdatype $vg1 $dev1 3486d7f5d3SJohn Marino not pvcreate -M$mdatype $dev1 3586d7f5d3SJohn Marino 3686d7f5d3SJohn Marino vgremove -f $vg1 3786d7f5d3SJohn Marino pvremove -f $dev1 3886d7f5d3SJohn Marino 3986d7f5d3SJohn Marino# pvcreate (lvm$mdatype) fails when PV1 does and PV2 does not belong to VG 4086d7f5d3SJohn Marino pvcreate -M$mdatype $dev1 4186d7f5d3SJohn Marino pvcreate -M$mdatype $dev2 4286d7f5d3SJohn Marino vgcreate -M$mdatype $vg1 $dev1 4386d7f5d3SJohn Marino 4486d7f5d3SJohn Marino# pvcreate a second time on $dev2 and $dev1 4586d7f5d3SJohn Marino not pvcreate -M$mdatype $dev2 $dev1 4686d7f5d3SJohn Marino 4786d7f5d3SJohn Marino vgremove -f $vg1 4886d7f5d3SJohn Marino pvremove -f $dev2 4986d7f5d3SJohn Marino pvremove -f $dev1 5086d7f5d3SJohn Marino 5186d7f5d3SJohn Marino# NOTE: Force pvcreate after test completion to ensure clean device 5286d7f5d3SJohn Marino#test_expect_success \ 5386d7f5d3SJohn Marino# "pvcreate (lvm$mdatype) fails on md component device" \ 5486d7f5d3SJohn Marino# 'mdadm -C -l raid0 -n 2 /dev/md0 $dev1 $dev2 && 5586d7f5d3SJohn Marino# pvcreate -M$mdatype $dev1; 5686d7f5d3SJohn Marino# status=$?; echo status=$status; test $status != 0 && 5786d7f5d3SJohn Marino# mdadm --stop /dev/md0 && 5886d7f5d3SJohn Marino# pvcreate -ff -y -M$mdatype $dev1 $dev2 && 5986d7f5d3SJohn Marino# pvremove -f $dev1 $dev2' 6086d7f5d3SJohn Marinodone 6186d7f5d3SJohn Marino 6286d7f5d3SJohn Marino# pvcreate (lvm2) fails without -ff when PV with metadatacopies=0 belongs to VG 6386d7f5d3SJohn Marinopvcreate --metadatacopies 0 $dev1 6486d7f5d3SJohn Marinopvcreate --metadatacopies 1 $dev2 6586d7f5d3SJohn Marinovgcreate $vg1 $dev1 $dev2 6686d7f5d3SJohn Marinonot pvcreate $dev1 6786d7f5d3SJohn Marinovgremove -f $vg1 6886d7f5d3SJohn Marinopvremove -f $dev2 6986d7f5d3SJohn Marinopvremove -f $dev1 7086d7f5d3SJohn Marino 7186d7f5d3SJohn Marino# pvcreate (lvm2) succeeds with -ff when PV with metadatacopies=0 belongs to VG 7286d7f5d3SJohn Marinopvcreate --metadatacopies 0 $dev1 7386d7f5d3SJohn Marinopvcreate --metadatacopies 1 $dev2 7486d7f5d3SJohn Marinovgcreate $vg1 $dev1 $dev2 7586d7f5d3SJohn Marinopvcreate -ff -y $dev1 7686d7f5d3SJohn Marinovgreduce --removemissing $vg1 7786d7f5d3SJohn Marinovgremove -ff $vg1 7886d7f5d3SJohn Marinopvremove -f $dev2 7986d7f5d3SJohn Marinopvremove -f $dev1 8086d7f5d3SJohn Marino 8186d7f5d3SJohn Marinofor i in 0 1 2 3 8286d7f5d3SJohn Marinodo 8386d7f5d3SJohn Marino# pvcreate (lvm2) succeeds writing LVM label at sector $i 8486d7f5d3SJohn Marino pvcreate --labelsector $i $dev1 8586d7f5d3SJohn Marino dd if=$dev1 bs=512 skip=$i count=1 2>/dev/null | strings | grep -q LABELONE; 8686d7f5d3SJohn Marino pvremove -f $dev1 8786d7f5d3SJohn Marinodone 8886d7f5d3SJohn Marino 8986d7f5d3SJohn Marino# pvcreate (lvm2) fails writing LVM label at sector 4 9086d7f5d3SJohn Marinonot pvcreate --labelsector 4 $dev1 9186d7f5d3SJohn Marino 9286d7f5d3SJohn Marinobackupfile=mybackupfile-$(this_test_) 9386d7f5d3SJohn Marinouuid1=freddy-fred-fred-fred-fred-fred-freddy 9486d7f5d3SJohn Marinouuid2=freddy-fred-fred-fred-fred-fred-fredie 9586d7f5d3SJohn Marinobogusuuid=fred 9686d7f5d3SJohn Marino 9786d7f5d3SJohn Marino# pvcreate rejects uuid option with less than 32 characters 9886d7f5d3SJohn Marinonot pvcreate --uuid $bogusuuid $dev1 9986d7f5d3SJohn Marino 10086d7f5d3SJohn Marino# pvcreate rejects uuid already in use 10186d7f5d3SJohn Marinopvcreate --uuid $uuid1 $dev1 10286d7f5d3SJohn Marinonot pvcreate --uuid $uuid1 $dev2 10386d7f5d3SJohn Marino 10486d7f5d3SJohn Marino# pvcreate rejects non-existent file given with restorefile 10586d7f5d3SJohn Marinonot pvcreate --uuid $uuid1 --restorefile $backupfile $dev1 10686d7f5d3SJohn Marino 10786d7f5d3SJohn Marino# pvcreate rejects restorefile with uuid not found in file 10886d7f5d3SJohn Marinopvcreate --uuid $uuid1 $dev1 10986d7f5d3SJohn Marinovgcfgbackup -f $backupfile 11086d7f5d3SJohn Marinonot pvcreate --uuid $uuid2 --restorefile $backupfile $dev2 11186d7f5d3SJohn Marino 11286d7f5d3SJohn Marino# pvcreate wipes swap signature when forced 11386d7f5d3SJohn Marinodd if=/dev/zero of=$dev1 bs=1024 count=64 11486d7f5d3SJohn Marinomkswap $dev1 11586d7f5d3SJohn Marinoblkid -c /dev/null $dev1 | grep "swap" 11686d7f5d3SJohn Marinopvcreate -f $dev1 11786d7f5d3SJohn Marinoblkid -c /dev/null $dev1 | not grep "swap" 118