2008-09-29 20:02:50 +04:00
# Copyright (C) 2008 Red Hat, Inc. All rights reserved.
2008-07-17 07:17:01 +04:00
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions
# of the GNU General Public License v.2.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2008-09-29 20:02:50 +04:00
. ./test-utils.sh
2008-07-17 07:17:01 +04:00
2008-09-29 20:02:50 +04:00
aux prepare_devs 4
2008-07-17 07:17:01 +04:00
for mdatype in 1 2
do
2008-11-11 18:46:15 +03:00
# pvcreate (lvm$mdatype) refuses to overwrite an mounted filesystem (bz168330)
test ! -d $G_root_ /mnt && mkdir $G_root_ /mnt
if mke2fs $dev1 ; then
mount $dev1 $G_root_ /mnt
not pvcreate -M$mdatype $dev1 2>err
grep " Can't open $dev1 exclusively. Mounted filesystem? " err
umount $dev1
fi
2008-08-28 14:07:34 +04:00
2008-11-10 15:43:35 +03:00
# pvcreate (lvm$mdatype) succeeds when run repeatedly (pv not in a vg) (bz178216)
2008-09-29 20:02:50 +04:00
pvcreate -M$mdatype $dev1
pvcreate -M$mdatype $dev1
pvremove -f $dev1
2008-08-28 14:07:34 +04:00
2008-09-29 20:02:50 +04:00
# pvcreate (lvm$mdatype) fails when PV belongs to VG" \
pvcreate -M$mdatype $dev1
vgcreate -M$mdatype $vg1 $dev1
not pvcreate -M$mdatype $dev1
2008-07-17 07:17:01 +04:00
2008-09-29 20:02:50 +04:00
vgremove -f $vg1
pvremove -f $dev1
# pvcreate (lvm$mdatype) fails when PV1 does and PV2 does not belong to VG
pvcreate -M$mdatype $dev1
pvcreate -M$mdatype $dev2
vgcreate -M$mdatype $vg1 $dev1
# pvcreate a second time on $dev2 and $dev1
not pvcreate -M$mdatype $dev2 $dev1
vgremove -f $vg1
pvremove -f $dev2
pvremove -f $dev1
2008-07-25 18:59:51 +04:00
2008-07-30 01:05:20 +04:00
# NOTE: Force pvcreate after test completion to ensure clean device
2008-08-01 19:44:53 +04:00
#test_expect_success \
# "pvcreate (lvm$mdatype) fails on md component device" \
2008-09-29 20:02:50 +04:00
# 'mdadm -C -l raid0 -n 2 /dev/md0 $dev1 $dev2 &&
# pvcreate -M$mdatype $dev1;
2008-08-01 19:44:53 +04:00
# status=$?; echo status=$status; test $status != 0 &&
# mdadm --stop /dev/md0 &&
2008-09-29 20:02:50 +04:00
# pvcreate -ff -y -M$mdatype $dev1 $dev2 &&
# pvremove -f $dev1 $dev2'
2008-07-17 07:17:01 +04:00
done
2008-09-29 20:02:50 +04:00
# pvcreate (lvm2) fails without -ff when PV with metadatacopies=0 belongs to VG
pvcreate --metadatacopies 0 $dev1
pvcreate --metadatacopies 1 $dev2
vgcreate $vg1 $dev1 $dev2
not pvcreate $dev1
vgremove -f $vg1
pvremove -f $dev2
pvremove -f $dev1
2008-07-17 07:17:01 +04:00
2008-09-30 21:47:34 +04:00
# pvcreate (lvm2) succeeds with -ff when PV with metadatacopies=0 belongs to VG
pvcreate --metadatacopies 0 $dev1
pvcreate --metadatacopies 1 $dev2
vgcreate $vg1 $dev1 $dev2
pvcreate -ff -y $dev1
vgreduce --removemissing $vg1
vgremove -ff $vg1
pvremove -f $dev2
pvremove -f $dev1
for i in 0 1 2 3
2008-07-21 22:50:10 +04:00
do
2008-09-29 20:02:50 +04:00
# pvcreate (lvm2) succeeds writing LVM label at sector $i
pvcreate --labelsector $i $dev1
2008-12-16 23:02:52 +03:00
dd if = $dev1 bs = 512 skip = $i count = 1 2>/dev/null | strings | grep -q LABELONE;
2008-09-29 20:02:50 +04:00
pvremove -f $dev1
2008-07-21 22:50:10 +04:00
done
2008-09-29 20:02:50 +04:00
# pvcreate (lvm2) fails writing LVM label at sector 4
not pvcreate --labelsector 4 $dev1
2008-07-21 22:50:10 +04:00
2008-07-24 21:33:40 +04:00
backupfile = mybackupfile-$( this_test_)
uuid1 = freddy-fred-fred-fred-fred-fred-freddy
uuid2 = freddy-fred-fred-fred-fred-fred-fredie
bogusuuid = fred
2008-09-29 20:02:50 +04:00
# pvcreate rejects uuid option with less than 32 characters
not pvcreate --uuid $bogusuuid $dev1
2008-07-24 21:33:40 +04:00
2008-09-29 20:02:50 +04:00
# pvcreate rejects uuid already in use
pvcreate --uuid $uuid1 $dev1
not pvcreate --uuid $uuid1 $dev2
2008-07-24 21:33:40 +04:00
2008-09-29 20:02:50 +04:00
# pvcreate rejects non-existent file given with restorefile
not pvcreate --uuid $uuid1 --restorefile $backupfile $dev1
2008-07-24 21:33:40 +04:00
2008-09-29 20:02:50 +04:00
# pvcreate rejects restorefile with uuid not found in file
pvcreate --uuid $uuid1 $dev1
vgcfgbackup -f $backupfile
not pvcreate --uuid $uuid2 --restorefile $backupfile $dev2
2009-03-17 16:59:56 +03:00
# pvcreate wipes swap signature when forced
dd if = /dev/zero of = $dev1 bs = 1024 count = 64
mkswap $dev1
file -s $dev1 | grep "swap file"
pvcreate -f $dev1
file -s $dev1 | not grep "swap file"