2017-07-02 22:38:32 +03:00
#!/usr/bin/env bash
2012-10-18 16:32:56 +04:00
# Copyright (C) 2008-2012 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,
2016-01-21 13:49:46 +03:00
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2008-07-17 07:17:01 +04:00
2018-05-24 17:49:48 +03:00
2015-10-27 17:10:06 +03:00
SKIP_WITH_LVMPOLLD = 1
2008-07-17 07:17:01 +04:00
2015-10-27 17:10:06 +03:00
. lib/inittest
2015-05-09 02:59:18 +03:00
2012-03-16 17:00:05 +04:00
aux lvmconf 'devices/md_component_detection = 1'
2008-09-29 20:02:50 +04:00
aux prepare_devs 4
2008-07-17 07:17:01 +04:00
2016-03-03 01:49:32 +03:00
if test -n " $LVM_TEST_LVM1 " ; then
mdatypes = '1 2'
else
mdatypes = '2'
fi
for mdatype in $mdatypes
2008-07-17 07:17:01 +04:00
do
2008-11-11 18:46:15 +03:00
# pvcreate (lvm$mdatype) refuses to overwrite an mounted filesystem (bz168330)
2012-03-16 17:00:05 +04:00
test ! -d mnt && mkdir mnt
if mke2fs " $dev1 " ; then
mount " $dev1 " mnt
not pvcreate -M$mdatype " $dev1 " 2>err
2014-03-20 02:32:25 +04:00
grep " Can't open $dev1 exclusively. Mounted filesystem? " err
2012-03-16 17:00:05 +04:00
umount " $dev1 "
2013-11-28 17:10:55 +04:00
# wipe the filesystem signature for next
# pvcreate to not issue any prompts
2014-03-20 02:32:25 +04:00
dd if = /dev/zero of = " $dev1 " bs = 1K count = 2
2008-11-11 18:46:15 +03:00
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)
2012-03-16 17:00:05 +04:00
pvcreate -M$mdatype " $dev1 "
pvcreate -M$mdatype " $dev1 "
pvremove -f " $dev1 "
2008-08-28 14:07:34 +04:00
2012-03-16 17:00:05 +04:00
# pvcreate (lvm$mdatype) fails when PV belongs to VG
# pvcreate -M$mdatype "$dev1"
2018-05-24 17:49:48 +03:00
vgcreate $SHARED -M$mdatype $vg1 " $dev1 "
2012-03-16 17:00:05 +04:00
not pvcreate -M$mdatype " $dev1 "
2008-07-17 07:17:01 +04:00
2008-09-29 20:02:50 +04:00
vgremove -f $vg1
2012-03-16 17:00:05 +04:00
pvremove -f " $dev1 "
2008-09-29 20:02:50 +04:00
# pvcreate (lvm$mdatype) fails when PV1 does and PV2 does not belong to VG
2012-03-16 17:00:05 +04:00
pvcreate -M$mdatype " $dev1 "
pvcreate -M$mdatype " $dev2 "
2018-05-24 17:49:48 +03:00
vgcreate $SHARED -M$mdatype $vg1 " $dev1 "
2008-09-29 20:02:50 +04:00
# pvcreate a second time on $dev2 and $dev1
2012-03-16 17:00:05 +04:00
not pvcreate -M$mdatype " $dev2 " " $dev1 "
2008-09-29 20:02:50 +04:00
vgremove -f $vg1
2012-03-16 17:00:05 +04:00
pvremove -f " $dev2 " " $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
2012-03-16 17:00:05 +04:00
#test_expect_success
# "pvcreate (lvm$mdatype) fails on md component device"
# '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 &&
2012-03-16 17:00:05 +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
2012-03-16 17:00:05 +04:00
pvcreate --metadatacopies 0 " $dev1 "
pvcreate --metadatacopies 1 " $dev2 "
2018-05-24 17:49:48 +03:00
vgcreate $SHARED $vg1 " $dev1 " " $dev2 "
2012-03-16 17:00:05 +04:00
not pvcreate " $dev1 "
2008-09-29 20:02:50 +04:00
vgremove -f $vg1
2012-03-16 17:00:05 +04:00
pvremove -f " $dev2 " " $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
2012-03-16 17:00:05 +04:00
pvcreate --metadatacopies 0 " $dev1 "
pvcreate --metadatacopies 1 " $dev2 "
2018-05-24 17:49:48 +03:00
vgcreate $SHARED $vg1 " $dev1 " " $dev2 "
2012-03-16 17:00:05 +04:00
pvcreate -ff -y " $dev1 "
vgreduce --removemissing $vg1
vgremove -ff $vg1
pvremove -f " $dev2 " " $dev1 "
2008-09-30 21:47:34 +04:00
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
2012-03-16 17:00:05 +04:00
pvcreate --labelsector $i " $dev1 "
dd if = " $dev1 " bs = 512 skip = $i count = 1 2>/dev/null | strings | grep LABELONE >/dev/null
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
2012-03-16 17:00:05 +04:00
not pvcreate --labelsector 4 " $dev1 "
2008-07-21 22:50:10 +04:00
2017-07-10 11:40:09 +03:00
backupfile = " $PREFIX .mybackupfile "
2008-07-24 21:33:40 +04:00
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
2012-03-16 17:00:05 +04:00
not pvcreate --norestorefile --uuid $bogusuuid " $dev1 "
2010-08-12 08:08:59 +04:00
# pvcreate rejects uuid option without restorefile
2012-03-16 17:00:05 +04:00
not pvcreate --uuid $uuid1 " $dev1 "
2008-07-24 21:33:40 +04:00
2008-09-29 20:02:50 +04:00
# pvcreate rejects uuid already in use
2012-03-16 17:00:05 +04:00
pvcreate --norestorefile --uuid $uuid1 " $dev1 "
not pvcreate --norestorefile --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
2017-07-10 11:40:09 +03:00
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
2012-03-16 17:00:05 +04:00
pvcreate --norestorefile --uuid $uuid1 " $dev1 "
2017-07-10 11:40:09 +03:00
vgcfgbackup -f " $backupfile "
not pvcreate --uuid $uuid2 --restorefile " $backupfile " " $dev2 "
2009-03-17 16:59:56 +03:00
2012-05-09 16:30:56 +04:00
# vgcfgrestore of a VG containing a PV with zero PEs (bz #820116)
# (use case: one PV in a VG used solely to keep metadata)
2014-03-20 02:32:25 +04:00
size_mb = $(( $( blockdev --getsz " $dev1 " ) / 2048 ))
pvcreate --metadatasize $size_mb " $dev1 "
2018-05-24 17:49:48 +03:00
vgcreate $SHARED $vg1 " $dev1 "
2017-07-10 11:40:09 +03:00
vgcfgbackup -f " $backupfile "
vgcfgrestore -f " $backupfile " " $vg1 "
2012-05-09 18:44:59 +04:00
vgremove -f $vg1
2014-03-20 02:32:25 +04:00
pvremove -f " $dev1 "
2012-05-09 16:30:56 +04:00
2014-04-10 16:46:40 +04:00
# pvcreate --restorefile should handle --dataalignment and --dataalignmentoffset
# and check it's compatible with pe_start value being restored
# X * dataalignment + dataalignmentoffset == pe_start
2017-07-10 11:40:09 +03:00
pvcreate --norestorefile --uuid " $uuid1 " --dataalignment 600k --dataalignmentoffset 32k " $dev1 "
2018-05-24 17:49:48 +03:00
vgcreate $SHARED $vg1 " $dev1 "
2017-07-10 11:40:09 +03:00
vgcfgbackup -f " $backupfile " " $vg1 "
2014-04-10 16:46:40 +04:00
vgremove -ff $vg1
pvremove -ff " $dev1 "
# the dataalignment and dataalignmentoffset is ignored here since they're incompatible with pe_start
2017-07-10 11:40:09 +03:00
pvcreate --restorefile " $backupfile " --uuid " $uuid1 " --dataalignment 500k --dataalignmentoffset 10k " $dev1 " 2> err
2014-04-10 16:46:40 +04:00
grep "incompatible with restored pe_start value" err
# 300k is multiple of 600k so this should pass
2017-07-10 11:40:09 +03:00
pvcreate --restorefile " $backupfile " --uui " $uuid1 " --dataalignment 300k --dataalignmentoffset 32k " $dev1 " 2> err
2014-04-10 16:46:40 +04:00
not grep "incompatible with restored pe_start value" err
2012-10-18 16:32:56 +04:00
# pvcreate rejects non-existent uuid given with restorefile
2017-08-15 14:23:51 +03:00
not pvcreate --uuid " $uuid2 " --restorefile " $backupfile " " $dev1 " 2> err
grep " Can't find uuid $uuid2 in backup file $backupfile " err
2012-10-18 16:32:56 +04:00
# pvcreate rejects restorefile without uuid
2017-08-15 14:23:51 +03:00
not pvcreate --restorefile " $backupfile " " $dev1 " 2>err
grep -- "--uuid is required with --restorefile" err
2012-10-18 16:32:56 +04:00
# pvcreate rejects uuid restore with multiple volumes specified
2017-08-15 14:23:51 +03:00
not pvcreate --uuid " $uuid1 " --restorefile " $backupfile " " $dev1 " " $dev2 " 2>err
grep "Can only set uuid on one volume at once" err
# --bootloaderareasize not allowed with pvcreate --restorefile
not pvcreate --uuid " $uuid1 " --restorefile " $backupfile " --bootloaderareasize 1m " $dev1 " " $dev2 " 2>err
grep -- "Command does not accept option combination: --bootloaderareasize with --restorefile" err
rm -f " $backupfile "
pvcreate --norestorefile --uuid $uuid1 " $dev1 "
2018-05-24 17:49:48 +03:00
vgcreate $SHARED --physicalextentsize 1m $vg1 " $dev1 "
2017-08-15 14:23:51 +03:00
vgcfgbackup -f " $backupfile " " $vg1 "
vgremove -ff " $vg1 "
pvremove -ff " $dev1 "
# when 2nd mda requested on pvcreate --restorefile and not enough space for it, pvcreate fails
not pvcreate --restorefile " $backupfile " --uuid $uuid1 --metadatacopies 2 " $dev1 " 2>err
grep " Not enough space available for metadata area with index 1 on PV $dev1 " err
rm -f " $backupfile "
2012-10-18 16:32:56 +04:00
2009-03-17 16:59:56 +03:00
# pvcreate wipes swap signature when forced
2020-09-20 00:25:11 +03:00
dd if = /dev/zero of = " $dev1 " bs = 64k count = 1 oflag = direct
2012-03-16 17:00:05 +04:00
mkswap " $dev1 "
blkid -c /dev/null " $dev1 " | grep "swap"
pvcreate -f " $dev1 "
2010-02-22 17:47:55 +03:00
# blkid cannot make up its mind whether not finding anything it knows is a failure or not
2012-03-16 17:00:05 +04:00
( blkid -c /dev/null " $dev1 " || true ) | not grep "swap"