2020-11-24 02:15:25 +03:00
#!/usr/bin/env bash
# Copyright (C) 2020 Red Hat, Inc. All rights reserved.
#
# 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
test_description = 'devices file with devnames'
. lib/inittest
aux prepare_devs 7
RUNDIR = "/run"
test -d " $RUNDIR " || RUNDIR = "/var/run"
PVS_ONLINE_DIR = " $RUNDIR /lvm/pvs_online "
VGS_ONLINE_DIR = " $RUNDIR /lvm/vgs_online "
PVS_LOOKUP_DIR = " $RUNDIR /lvm/pvs_lookup "
_clear_online_files( ) {
# wait till udev is finished
aux udev_wait
rm -f " $PVS_ONLINE_DIR " /*
rm -f " $VGS_ONLINE_DIR " /*
rm -f " $PVS_LOOKUP_DIR " /*
}
DFDIR = " $LVM_SYSTEM_DIR /devices "
2021-03-28 03:09:42 +03:00
mkdir " $DFDIR " || true
2020-11-24 02:15:25 +03:00
DF = " $DFDIR /system.devices "
ORIG = " $DFDIR /orig.devices "
aux lvmconf 'devices/use_devicesfile = 1'
2021-03-28 03:09:42 +03:00
pvcreate " $dev1 "
ls " $DF "
grep " $dev1 " " $DF "
2020-11-24 02:15:25 +03:00
2021-03-28 03:09:42 +03:00
pvcreate " $dev2 "
grep " $dev2 " " $DF "
2020-11-24 02:15:25 +03:00
2021-03-28 03:09:42 +03:00
pvcreate " $dev3 "
grep " $dev3 " " $DF "
2020-11-24 02:15:25 +03:00
2021-03-28 03:09:42 +03:00
vgcreate $vg1 " $dev1 " " $dev2 "
2020-11-24 02:15:25 +03:00
# PVID with dashes for matching pvs -o+uuid output
2021-03-28 03:09:42 +03:00
OPVID1 = ` pvs " $dev1 " --noheading -o uuid | awk '{print $1}' `
OPVID2 = ` pvs " $dev2 " --noheading -o uuid | awk '{print $1}' `
OPVID3 = ` pvs " $dev3 " --noheading -o uuid | awk '{print $1}' `
2020-11-24 02:15:25 +03:00
# PVID without dashes for matching devices file fields
2021-03-28 03:09:42 +03:00
PVID1 = ` pvs " $dev1 " --noheading -o uuid | tr -d - | awk '{print $1}' `
PVID2 = ` pvs " $dev2 " --noheading -o uuid | tr -d - | awk '{print $1}' `
PVID3 = ` pvs " $dev3 " --noheading -o uuid | tr -d - | awk '{print $1}' `
2020-11-24 02:15:25 +03:00
2021-03-28 03:09:42 +03:00
lvmdevices --deldev " $dev3 "
2020-11-24 02:15:25 +03:00
2021-03-28 03:09:42 +03:00
not grep " $dev3 " " $DF "
not grep " $PVID3 " " $DF "
not pvs " $dev3 "
2020-11-24 02:15:25 +03:00
2021-03-28 03:09:42 +03:00
cp " $DF " " $ORIG "
2020-11-24 02:15:25 +03:00
lvcreate -l4 -an -i2 -n $lv1 $vg1
#
# when wrong idname devname is outside DF it's corrected if search_for=1
# by a general cmd, or by lvmdevices --addpvid
#
# when wrong idname devname is outside DF it's not found or corrected if
# search_for=0 by a general cmd, but will be by lvmdevices --addpvid
#
# when wrong idname devname is inside DF it's corrected if search_for=0|1
# by a general cmd, or by lvmdevices --addpvid
#
# pvscan --cache -aay does not update DF when devname= is wrong
#
# pvscan --cache -aay when idname devname is wrong:
# every dev is read and then skipped if pvid is not in DF
#
# commands still work with incorrect devname=
# . and they automatically correct the devname=
#
#
# idname changes to become incorrect, devname remains unchanged and correct
# . change idname to something outside DF
# . change idname to match another DF entry
# . swap idname of two DF entries
#
# edit DF idname, s/dev1/dev3/, where new dev is not in DF
2021-03-28 03:09:42 +03:00
sed -e " s|IDNAME= $dev1 |IDNAME= $dev3 | " " $ORIG " > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# pvs reports correct info
pvs -o+uuid | tee pvs.out
grep $vg1 pvs.out > out
2021-03-28 03:09:42 +03:00
not grep " $OPVID3 " out
not grep " $dev3 " out
grep " $OPVID1 " out | tee out2
grep " $dev1 " out2
2020-11-24 02:15:25 +03:00
# pvs fixed the DF
2021-03-28 03:09:42 +03:00
not grep " $PVID3 " " $DF "
not grep " $dev3 " " $DF "
grep " $PVID1 " " $DF " | tee out
grep " IDNAME= $dev1 " out
cat " $DF "
sed -e " s|IDNAME= $dev1 |IDNAME= $dev3 | " " $ORIG " > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# lvcreate uses correct dev
2021-03-28 03:09:42 +03:00
lvcreate -l1 -n $lv2 -an $vg1 " $dev1 "
2020-11-24 02:15:25 +03:00
# lvcreate fixed the DF
2021-03-28 03:09:42 +03:00
not grep " $PVID3 " " $DF "
not grep " $dev3 " " $DF "
grep " $PVID1 " " $DF " | tee out
grep " IDNAME= $dev1 " out
2020-11-24 02:15:25 +03:00
# pvs reports correct dev
pvs -o+uuid | tee pvs.out
grep $vg1 pvs.out > out
2021-03-28 03:09:42 +03:00
not grep " $OPVID3 " out
not grep " $dev3 " out
grep " $OPVID1 " out | tee out2
grep " $dev1 " out2
2020-11-24 02:15:25 +03:00
lvremove $vg1 /$lv2
2021-03-28 03:09:42 +03:00
cat " $DF "
2020-11-24 02:15:25 +03:00
2021-03-28 03:09:42 +03:00
sed -e " s|IDNAME= $dev1 |IDNAME= $dev3 | " " $ORIG " > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# lvmdevices fixes the DF
lvmdevices --update
2021-03-28 03:09:42 +03:00
not grep " $PVID3 " " $DF "
not grep " $dev3 " " $DF "
grep " $PVID1 " " $DF " | tee out
grep " IDNAME= $dev1 " out
cat " $DF "
2020-11-24 02:15:25 +03:00
# edit DF idname, s/dev1/dev2/, creating two entries with same idname
2021-03-28 03:09:42 +03:00
sed -e " s|IDNAME= $dev1 |IDNAME= $dev2 | " " $ORIG " > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# pvs reports correct info
pvs -o+uuid | tee pvs.out
grep $vg1 pvs.out > out
2021-03-28 03:09:42 +03:00
grep " $OPVID1 " out | tee out2
grep " $dev1 " out2
grep " $OPVID2 " out | tee out2
grep " $dev2 " out2
2020-11-24 02:15:25 +03:00
# pvs fixed the DF
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " IDNAME= $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " IDNAME= $dev2 " out
cat " $DF "
sed -e " s|IDNAME= $dev1 |IDNAME= $dev2 | " " $ORIG " > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# lvcreate uses correct dev
2021-03-28 03:09:42 +03:00
lvcreate -l1 -n $lv2 -an $vg1 " $dev1 "
2020-11-24 02:15:25 +03:00
# lvcreate fixed the DF
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " IDNAME= $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " IDNAME= $dev2 " out
2020-11-24 02:15:25 +03:00
# pvs reports correct info
pvs -o+uuid | tee pvs.out
grep $vg1 pvs.out > out
2021-03-28 03:09:42 +03:00
grep " $OPVID1 " out | tee out2
grep " $dev1 " out2
grep " $OPVID2 " out | tee out2
grep " $dev2 " out2
2020-11-24 02:15:25 +03:00
lvremove $vg1 /$lv2
2021-03-28 03:09:42 +03:00
cat " $DF "
2020-11-24 02:15:25 +03:00
2021-03-28 03:09:42 +03:00
sed -e " s|IDNAME= $dev1 |IDNAME= $dev2 | " " $ORIG " > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# lvmdevices fixes the DF
lvmdevices --update
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " IDNAME= $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " IDNAME= $dev2 " out
cat " $DF "
2020-11-24 02:15:25 +03:00
# edit DF idname, swap dev1 and dev2
2021-03-28 03:09:42 +03:00
sed -e " s|IDNAME= $dev1 |IDNAME=tmpname| " " $ORIG " > tmp1.devices
2020-11-24 02:15:25 +03:00
sed -e " s|IDNAME= $dev2 |IDNAME= $dev1 | " tmp1.devices > tmp2.devices
2021-03-28 03:09:42 +03:00
sed -e " s|IDNAME=tmpname|IDNAME= $dev2 | " tmp2.devices > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# pvs reports correct info
pvs -o+uuid | tee pvs.out
grep $vg1 pvs.out > out
2021-03-28 03:09:42 +03:00
grep " $OPVID1 " out | tee out2
grep " $dev1 " out2
grep " $OPVID2 " out | tee out2
grep " $dev2 " out2
2020-11-24 02:15:25 +03:00
# pvs fixed the DF
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " IDNAME= $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " IDNAME= $dev2 " out
cat " $DF "
2020-11-24 02:15:25 +03:00
2021-03-28 03:09:42 +03:00
sed -e " s|IDNAME= $dev1 |IDNAME=tmpname| " " $ORIG " > tmp1.devices
2020-11-24 02:15:25 +03:00
sed -e " s|IDNAME= $dev2 |IDNAME= $dev1 | " tmp1.devices > tmp2.devices
2021-03-28 03:09:42 +03:00
sed -e " s|IDNAME=tmpname|IDNAME= $dev2 | " tmp2.devices > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# lvcreate uses correct dev
2021-03-28 03:09:42 +03:00
lvcreate -l1 -n $lv2 -an $vg1 " $dev1 "
2020-11-24 02:15:25 +03:00
# lvcreate fixed the DF
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " IDNAME= $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " IDNAME= $dev2 " out
2020-11-24 02:15:25 +03:00
# pvs reports correct info
pvs -o+uuid | tee pvs.out
grep $vg1 pvs.out > out
2021-03-28 03:09:42 +03:00
grep " $OPVID1 " out | tee out2
grep " $dev1 " out2
grep " $OPVID2 " out | tee out2
grep " $dev2 " out2
2020-11-24 02:15:25 +03:00
lvremove $vg1 /$lv2
2021-03-28 03:09:42 +03:00
cat " $DF "
2020-11-24 02:15:25 +03:00
2021-03-28 03:09:42 +03:00
sed -e " s|IDNAME= $dev1 |IDNAME=tmpname| " " $ORIG " > tmp1.devices
2020-11-24 02:15:25 +03:00
sed -e " s|IDNAME= $dev2 |IDNAME= $dev1 | " tmp1.devices > tmp2.devices
2021-03-28 03:09:42 +03:00
sed -e " s|IDNAME=tmpname|IDNAME= $dev2 | " tmp2.devices > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# lvmdevices fixes the DF
lvmdevices --update
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " IDNAME= $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " IDNAME= $dev2 " out
cat " $DF "
2020-11-24 02:15:25 +03:00
#
# idname remains correct, devname changes to become incorrect
# . change devname to something outside DF
# . change devname to match another DF entry
# . swap devname of two DF entries
#
# edit DF devname, s/dev1/dev3/, where new dev is not in DF
2021-03-28 03:09:42 +03:00
sed -e " s|DEVNAME= $dev1 |DEVNAME= $dev3 | " " $ORIG " > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# pvs reports correct info
pvs -o+uuid | tee pvs.out
grep $vg1 pvs.out > out
2021-03-28 03:09:42 +03:00
not grep " $OPVID3 " out
not grep " $dev3 " out
grep " $OPVID1 " out | tee out2
grep " $dev1 " out2
2020-11-24 02:15:25 +03:00
# pvs fixed the DF
2021-03-28 03:09:42 +03:00
not grep " $PVID3 " " $DF "
not grep " $dev3 " " $DF "
grep " $PVID1 " " $DF " | tee out
grep " DEVNAME= $dev1 " out
cat " $DF "
sed -e " s|DEVNAME= $dev1 |DEVNAME= $dev3 | " " $ORIG " > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# lvmdevices fixes the DF
lvmdevices --update
2021-03-28 03:09:42 +03:00
not grep " $PVID3 " " $DF "
not grep " $dev3 " " $DF "
grep " $PVID1 " " $DF " | tee out
grep " IDNAME= $dev1 " out
cat " $DF "
2020-11-24 02:15:25 +03:00
# edit DF devname, s/dev1/dev2/, creating two entries with same devname
2021-03-28 03:09:42 +03:00
sed -e " s|DEVNAME= $dev1 |DEVNAME= $dev2 | " " $ORIG " > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# pvs reports correct info
pvs -o+uuid | tee pvs.out
grep $vg1 pvs.out > out
2021-03-28 03:09:42 +03:00
grep " $OPVID1 " out | tee out2
grep " $dev1 " out2
grep " $OPVID2 " out | tee out2
grep " $dev2 " out2
2020-11-24 02:15:25 +03:00
# pvs fixed the DF
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " DEVNAME= $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " DEVNAME= $dev2 " out
cat " $DF "
sed -e " s|DEVNAME= $dev1 |DEVNAME= $dev2 | " " $ORIG " > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# lvmdevices fixes the DF
lvmdevices --update
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " IDNAME= $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " IDNAME= $dev2 " out
cat " $DF "
2020-11-24 02:15:25 +03:00
# edit DF devname, swap dev1 and dev2
2021-03-28 03:09:42 +03:00
sed -e " s|DEVNAME= $dev1 |DEVNAME=tmpname| " " $ORIG " > tmp1.devices
2020-11-24 02:15:25 +03:00
sed -e " s|DEVNAME= $dev2 |DEVNAME= $dev1 | " tmp1.devices > tmp2.devices
2021-03-28 03:09:42 +03:00
sed -e " s|DEVNAME=tmpname|DEVNAME= $dev2 | " tmp2.devices > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# pvs reports correct info
pvs -o+uuid | tee pvs.out
grep $vg1 pvs.out > out
2021-03-28 03:09:42 +03:00
grep " $OPVID1 " out | tee out2
grep " $dev1 " out2
grep " $OPVID2 " out | tee out2
grep " $dev2 " out2
2020-11-24 02:15:25 +03:00
# pvs fixed the DF
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " DEVNAME= $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " DEVNAME= $dev2 " out
cat " $DF "
2020-11-24 02:15:25 +03:00
2021-03-28 03:09:42 +03:00
sed -e " s|DEVNAME= $dev1 |DEVNAME=tmpname| " " $ORIG " > tmp1.devices
2020-11-24 02:15:25 +03:00
sed -e " s|DEVNAME= $dev2 |DEVNAME= $dev1 | " tmp1.devices > tmp2.devices
2021-03-28 03:09:42 +03:00
sed -e " s|DEVNAME=tmpname|DEVNAME= $dev2 | " tmp2.devices > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# lvmdevices fixes the DF
lvmdevices --update
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " IDNAME= $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " IDNAME= $dev2 " out
cat " $DF "
2020-11-24 02:15:25 +03:00
#
# idname and devname change, both become incorrect
# . change idname&devname to something outside DF
# . change idname&devname to match another DF entry
# . swap idname&devname of two DF entries
#
# edit DF idname&devname, s/dev1/dev3/, where new dev is not in DF
2021-03-28 03:09:42 +03:00
sed -e " s|DEVNAME= $dev1 |DEVNAME= $dev3 | " " $ORIG " > tmp1.devices
sed -e " s|IDNAME= $dev1 |IDNAME= $dev3 | " tmp1.devices > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# pvs reports correct info
pvs -o+uuid | tee pvs.out
grep $vg1 pvs.out > out
2021-03-28 03:09:42 +03:00
not grep " $OPVID3 " out
not grep " $dev3 " out
grep " $OPVID1 " out | tee out2
grep " $dev1 " out2
2020-11-24 02:15:25 +03:00
# pvs fixed the DF
2021-03-28 03:09:42 +03:00
not grep " $PVID3 " " $DF "
not grep " $dev3 " " $DF "
grep " $PVID1 " " $DF " | tee out
grep " DEVNAME= $dev1 " out
grep " IDNAME= $dev1 " out
cat " $DF "
sed -e " s|DEVNAME= $dev1 |DEVNAME= $dev3 | " " $ORIG " > tmp1.devices
sed -e " s|IDNAME= $dev1 |IDNAME= $dev3 | " tmp1.devices > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# lvmdevices fixes the DF
lvmdevices --update
2021-03-28 03:09:42 +03:00
not grep " $PVID3 " " $DF "
not grep " $dev3 " " $DF "
grep " $PVID1 " " $DF " | tee out
grep " DEVNAME= $dev1 " out
grep " IDNAME= $dev1 " out
cat " $DF "
2020-11-24 02:15:25 +03:00
# edit DF idname&devname, s/dev1/dev2/, creating two entries with same devname
2021-03-28 03:09:42 +03:00
sed -e " s|DEVNAME= $dev1 |DEVNAME= $dev2 | " tmp1.devices > " $DF "
sed -e " s|IDNAME= $dev1 |IDNAME= $dev2 | " tmp1.devices > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# pvs reports correct info
pvs -o+uuid | tee pvs.out
grep $vg1 pvs.out > out
2021-03-28 03:09:42 +03:00
grep " $OPVID1 " out | tee out2
grep " $dev1 " out2
grep " $OPVID2 " out | tee out2
grep " $dev2 " out2
2020-11-24 02:15:25 +03:00
# pvs fixed the DF
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " DEVNAME= $dev1 " out
grep " IDNAME= $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " DEVNAME= $dev2 " out
grep " IDNAME= $dev2 " out
cat " $DF "
sed -e " s|DEVNAME= $dev1 |DEVNAME= $dev2 | " tmp1.devices > " $DF "
sed -e " s|IDNAME= $dev1 |IDNAME= $dev2 | " tmp1.devices > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# lvmdevices fixes the DF
lvmdevices --update
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " DEVNAME= $dev1 " out
grep " IDNAME= $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " DEVNAME= $dev2 " out
grep " IDNAME= $dev2 " out
cat " $DF "
2020-11-24 02:15:25 +03:00
# edit DF devname, swap dev1 and dev2
2021-03-28 03:09:42 +03:00
sed -e " s|DEVNAME= $dev1 |DEVNAME=tmpname| " " $ORIG " > tmp1.devices
2020-11-24 02:15:25 +03:00
sed -e " s|DEVNAME= $dev2 |DEVNAME= $dev1 | " tmp1.devices > tmp2.devices
sed -e " s|DEVNAME=tmpname|DEVNAME= $dev2 | " tmp2.devices > tmp3.devices
sed -e " s|IDNAME= $dev1 |IDNAME=tmpname| " tmp3.devices > tmp4.devices
sed -e " s|IDNAME= $dev2 |IDNAME= $dev1 | " tmp4.devices > tmp5.devices
2021-03-28 03:09:42 +03:00
sed -e " s|IDNAME=tmpname|IDNAME= $dev2 | " tmp5.devices > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# pvs reports correct info
pvs -o+uuid | tee pvs.out
grep $vg1 pvs.out > out
2021-03-28 03:09:42 +03:00
grep " $OPVID1 " out | tee out2
grep " $dev1 " out2
grep " $OPVID2 " out | tee out2
grep " $dev2 " out2
2020-11-24 02:15:25 +03:00
# pvs fixed the DF
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " DEVNAME= $dev1 " out
grep " IDNAME= $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " DEVNAME= $dev2 " out
grep " IDNAME= $dev2 " out
cat " $DF "
sed -e " s|DEVNAME= $dev1 |DEVNAME=tmpname| " " $ORIG " > tmp1.devices
2020-11-24 02:15:25 +03:00
sed -e " s|DEVNAME= $dev2 |DEVNAME= $dev1 | " tmp1.devices > tmp2.devices
sed -e " s|DEVNAME=tmpname|DEVNAME= $dev2 | " tmp2.devices > tmp3.devices
sed -e " s|IDNAME= $dev1 |IDNAME=tmpname| " tmp3.devices > tmp4.devices
sed -e " s|IDNAME= $dev2 |IDNAME= $dev1 | " tmp4.devices > tmp5.devices
2021-03-28 03:09:42 +03:00
sed -e " s|IDNAME=tmpname|IDNAME= $dev2 | " tmp5.devices > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
# lvmdevices fixes the DF
lvmdevices --update
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " DEVNAME= $dev1 " out
grep " IDNAME= $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " DEVNAME= $dev2 " out
grep " IDNAME= $dev2 " out
cat " $DF "
2020-11-24 02:15:25 +03:00
#
# check that pvscan --cache -aay does the right thing:
#
# idname and devname change, both become incorrect
# . change idname&devname to something outside DF
# . swap idname&devname of two DF entries
#
# edit DF idname&devname, s/dev1/dev3/, where new dev is not in DF
2021-03-28 03:09:42 +03:00
sed -e " s|DEVNAME= $dev1 |DEVNAME= $dev3 | " " $ORIG " > tmp1.devices
sed -e " s|IDNAME= $dev1 |IDNAME= $dev3 | " tmp1.devices > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
_clear_online_files
2021-03-28 03:09:42 +03:00
pvscan --cache -aay " $dev1 "
pvscan --cache -aay " $dev2 "
pvscan --cache -aay " $dev3 "
cat " $DF "
2020-11-24 02:15:25 +03:00
# pvscan does not fix DF
2021-03-28 03:09:42 +03:00
grep " $dev3 " " $DF "
not grep " $dev1 " " $DF "
2021-09-21 19:02:50 +03:00
ls " $RUNDIR /lvm/pvs_online/ $PVID1 "
2020-11-24 02:15:25 +03:00
ls " $RUNDIR /lvm/pvs_online/ $PVID2 "
2021-09-21 19:02:50 +03:00
not ls " $RUNDIR /lvm/pvs_online/ $PVID3 "
2020-11-24 02:15:25 +03:00
check lv_field $vg1 /$lv1 lv_active "active"
# pvs updates the DF
pvs | tee out
2021-03-28 03:09:42 +03:00
grep " $dev1 " out
grep " $dev2 " out
not grep " $dev3 " out
grep " $dev1 " " $DF "
grep " $dev2 " " $DF "
not grep " $dev3 " " $DF "
2020-11-24 02:15:25 +03:00
vgchange -an $vg1
# edit DF idname&devname, swap dev1 and dev2
vgremove -y $vg1
2021-03-28 03:09:42 +03:00
vgcreate $vg1 " $dev1 "
2020-11-24 02:15:25 +03:00
lvcreate -n $lv1 -l1 -an $vg1
2021-03-28 03:09:42 +03:00
vgcreate $vg2 " $dev2 "
2020-11-24 02:15:25 +03:00
lvcreate -n $lv2 -l1 -an $vg2
2021-03-28 03:09:42 +03:00
cat " $DF "
sed -e " s|DEVNAME= $dev1 |DEVNAME=tmpname| " " $ORIG " > tmp1.devices
2020-11-24 02:15:25 +03:00
sed -e " s|DEVNAME= $dev2 |DEVNAME= $dev1 | " tmp1.devices > tmp2.devices
sed -e " s|DEVNAME=tmpname|DEVNAME= $dev2 | " tmp2.devices > tmp3.devices
sed -e " s|IDNAME= $dev1 |IDNAME=tmpname| " tmp3.devices > tmp4.devices
sed -e " s|IDNAME= $dev2 |IDNAME= $dev1 | " tmp4.devices > tmp5.devices
2021-03-28 03:09:42 +03:00
sed -e " s|IDNAME=tmpname|IDNAME= $dev2 | " tmp5.devices > " $DF "
cat " $DF "
2020-11-24 02:15:25 +03:00
_clear_online_files
# pvscan creates the correct online files and activates correct vg
2021-03-28 03:09:42 +03:00
pvscan --cache -aay " $dev1 "
2020-11-24 02:15:25 +03:00
ls " $RUNDIR /lvm/pvs_online/ $PVID1 "
ls " $RUNDIR /lvm/vgs_online/ $vg1 "
not ls " $RUNDIR /lvm/pvs_online/ $PVID2 "
not ls " $RUNDIR /lvm/vgs_online/ $vg2 "
# don't use lvs because it would fix DF before we check it
dmsetup status $vg1 -$lv1
not dmsetup status $vg2 -$lv2
2021-03-28 03:09:42 +03:00
pvscan --cache -aay " $dev2 "
2020-11-24 02:15:25 +03:00
ls " $RUNDIR /lvm/pvs_online/ $PVID2 "
ls " $RUNDIR /lvm/vgs_online/ $vg2 "
dmsetup status $vg2 -$lv2
2021-03-28 03:09:42 +03:00
pvscan --cache -aay " $dev3 "
2020-11-24 02:15:25 +03:00
not ls " $RUNDIR /lvm/pvs_online/ $PVID3 "
# pvscan did not correct DF
2021-03-28 03:09:42 +03:00
cat " $DF "
grep " $PVID1 " " $DF " | tee out
grep " $dev2 " out
not grep " $dev1 " out
grep " $PVID2 " " $DF " | tee out
grep " $dev1 " out
not grep " $dev2 " out
2020-11-24 02:15:25 +03:00
# pvs corrects DF
pvs
2021-03-28 03:09:42 +03:00
grep " $PVID1 " " $DF " | tee out
grep " $dev1 " out
not grep " $dev2 " out
grep " $PVID2 " " $DF " | tee out
grep " $dev2 " out
not grep " $dev1 " out
2020-11-24 02:15:25 +03:00
2021-11-16 18:29:24 +03:00
vgchange -an $vg1
vgchange -an $vg2
vgremove -ff $vg1
vgremove -ff $vg2
2022-08-19 21:31:22 +03:00
# bz 2119473
aux lvmconf "devices/search_for_devnames = \"none\""
sed -e " s|DEVNAME= $dev1 |DEVNAME=.| " " $ORIG " > tmp1.devices
sed -e " s|IDNAME= $dev1 |IDNAME=.| " tmp1.devices > " $DF "
pvs
lvmdevices
pvcreate -ff --yes --uuid " $PVID1 " --norestorefile $dev1
grep " $PVID1 " " $DF " | tee out
grep " DEVNAME= $dev1 " out
grep " IDNAME= $dev1 " out
aux lvmconf "devices/search_for_devnames = \"auto\""
2021-11-16 18:29:24 +03:00
# devnames change so the new devname now refers to a filtered device,
# e.g. an mpath or md component, which is not scanned
wait_md_create( ) {
local md = $1
while :; do
if ! grep " $( basename $md ) " /proc/mdstat; then
echo " $md not ready "
cat /proc/mdstat
sleep 2
else
break
fi
done
echo " $md " > WAIT_MD_DEV
}
aux wipefs_a " $dev1 "
aux wipefs_a " $dev2 "
aux wipefs_a " $dev3 "
aux wipefs_a " $dev4 "
mddev = "/dev/md33"
not grep $mddev /proc/mdstat || skip
rm " $DF "
touch " $DF "
vgcreate $vg1 " $dev1 " " $dev2 "
cat " $DF "
cp " $DF " " $ORIG "
# PVID with dashes for matching pvs -o+uuid output
OPVID1 = ` pvs " $dev1 " --noheading -o uuid | awk '{print $1}' `
OPVID2 = ` pvs " $dev2 " --noheading -o uuid | awk '{print $1}' `
# PVID without dashes for matching devices file fields
PVID1 = ` pvs " $dev1 " --noheading -o uuid | tr -d - | awk '{print $1}' `
PVID2 = ` pvs " $dev2 " --noheading -o uuid | tr -d - | awk '{print $1}' `
2021-12-01 17:56:05 +03:00
mdadm --create --metadata= 1.0 " $mddev " --level 1 --raid-devices= 2 " $dev3 " " $dev4 "
2021-11-16 18:29:24 +03:00
wait_md_create " $mddev "
sed -e " s|DEVNAME= $dev1 |DEVNAME= $dev3 | " " $ORIG " > tmp1.devices
sed -e " s|IDNAME= $dev1 |IDNAME= $dev3 | " tmp1.devices > " $DF "
cat " $DF "
pvs -o+uuid | tee out
grep " $dev1 " out
grep " $dev2 " out
grep " $OPVID1 " out
grep " $OPVID2 " out
not grep " $dev3 " out
not grep " $dev4 " out
grep " $dev1 " " $DF "
grep " $dev2 " " $DF "
grep " $PVID1 " " $DF "
grep " $PVID2 " " $DF "
not grep " $dev3 " " $DF "
not grep " $dev4 " " $DF "
mdadm --stop " $mddev "
aux udev_wait
2020-11-24 02:15:25 +03:00
vgremove -ff $vg1