2018-10-18 21:06:42 +03:00
#!/usr/bin/env bash
2021-03-22 23:45:39 +03:00
# Copyright (C) 2018-2021 Red Hat, Inc. All rights reserved.
2018-10-18 21:06:42 +03: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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
SKIP_WITH_LVMPOLLD = 1
2019-09-11 21:26:41 +03:00
SKIP_WITH_LVMLOCKD = 1
2018-10-18 21:06:42 +03:00
2021-08-23 23:01:26 +03:00
. lib/inittest
2019-05-03 22:05:40 +03:00
RUNDIR = "/run"
test -d " $RUNDIR " || RUNDIR = "/var/run"
PVS_ONLINE_DIR = " $RUNDIR /lvm/pvs_online "
VGS_ONLINE_DIR = " $RUNDIR /lvm/vgs_online "
2019-07-13 00:51:49 +03:00
HINTS = " $RUNDIR /lvm/hints "
2019-05-03 22:05:40 +03:00
2021-08-23 23:01:26 +03:00
DFDIR = " $LVM_SYSTEM_DIR /devices "
DF = " $DFDIR /system.devices "
2019-05-03 22:05:40 +03:00
_clear_online_files( ) {
# wait till udev is finished
aux udev_wait
2021-03-22 23:45:39 +03:00
rm -f " $PVS_ONLINE_DIR " /* " $VGS_ONLINE_DIR " /*
2019-05-03 22:05:40 +03:00
}
2018-10-18 21:06:42 +03:00
2019-05-21 20:06:34 +03:00
# This stops lvm from taking advantage of hints which
# will have already excluded md components.
2019-05-03 22:05:40 +03:00
# This stops lvm from asking udev if a dev is an md component.
# LVM will ask udev if a dev is an md component, but we don't
# want to rely on that ability in this test.
2021-03-22 23:45:39 +03:00
aux lvmconf "devices/md_component_detection = 1" \
"devices/hints = \"none\"" \
2021-08-23 23:01:26 +03:00
"devices/obtain_device_list_from_udev = 0" \
"devices/search_for_devnames = \"none\""
2019-05-03 22:05:40 +03:00
2019-09-11 21:26:41 +03:00
aux extend_filter_md "a|/dev/md|"
2018-10-18 21:06:42 +03:00
2019-07-10 22:13:01 +03:00
aux prepare_devs 3
2018-10-18 21:06:42 +03:00
2021-03-22 23:45:39 +03:00
for level in 1 0 ; do
2019-05-03 22:05:40 +03:00
2021-03-22 23:45:39 +03:00
# create 2 disk MD raid1 array
2019-05-03 22:05:40 +03:00
# by default using metadata format 1.0 with data at the end of device
2021-03-22 23:45:39 +03:00
#
2019-05-03 22:05:40 +03:00
# When a raid0 md array is stopped, the components will not look like
# duplicate PVs as they do with raid1.
2023-02-23 17:30:50 +03:00
# mdadm does not seem to like --chunk=64 with raid1
case " $level " in
0) CHUNK = "--chunk=64" ; ;
*) CHUNK = "" ; ;
esac
aux mdadm_create --metadata= 1.0 --level= $level $CHUNK --raid-devices= 2 " $dev1 " " $dev2 "
2021-03-22 23:45:39 +03:00
mddev = $( < MD_DEV)
2019-05-03 22:05:40 +03:00
vgcreate $vg " $mddev "
2021-08-23 23:01:26 +03:00
lvmdevices || true
pvs -o+deviceidtype,deviceid
2021-03-22 23:45:39 +03:00
PVIDMD = $( get pv_field " $mddev " uuid | tr -d - )
2018-10-18 21:06:42 +03:00
2019-05-03 22:05:40 +03:00
lvcreate -n $lv1 -l 2 $vg
lvcreate -n $lv2 -l 2 -an $vg
lvchange -ay $vg /$lv2
check lv_field $vg /$lv1 lv_active "active"
# lvm does not show md components as PVs
pvs " $mddev "
not pvs " $dev1 "
not pvs " $dev2 "
2021-03-22 23:45:39 +03:00
pvs | tee out
2019-05-21 20:06:34 +03:00
not grep " $dev1 " out
not grep " $dev2 " out
2019-05-03 22:05:40 +03:00
vgchange -an $vg
# When the md device is started, lvm will see that and know to
# scan for md components, so stop the md device to remove this
# advantage so we will test the fallback detection.
mdadm --stop " $mddev "
aux udev_wait
2019-05-21 20:06:34 +03:00
# The md components should still be detected and excluded.
not pvs " $dev1 "
not pvs " $dev2 "
2021-03-22 23:45:39 +03:00
pvs | tee out
2019-05-21 20:06:34 +03:00
not grep " $dev1 " out
not grep " $dev2 " out
2019-07-10 22:13:01 +03:00
pvs 2>& 1| tee out
not grep "Not using device" out
2019-05-03 22:05:40 +03:00
# should not activate from the md legs
not vgchange -ay $vg
# should not show an active lv
2021-03-24 02:37:24 +03:00
not dmsetup info $vg -$lv1
2019-05-03 22:05:40 +03:00
# should not allow updating vg
not lvcreate -l1 $vg
# should not activate from the md legs
_clear_online_files
pvscan --cache -aay " $dev1 "
pvscan --cache -aay " $dev2 "
2021-03-22 23:45:39 +03:00
test ! -f " $RUNDIR /lvm/pvs_online/ $PVIDMD "
test ! -f " $RUNDIR /lvm/vgs_online/ $vg "
2019-07-10 22:13:01 +03:00
2019-05-03 22:05:40 +03:00
# should not show an active lv
2021-03-24 02:37:24 +03:00
not dmsetup info $vg -$lv1
2019-05-03 22:05:40 +03:00
2021-03-26 18:07:24 +03:00
aux mdadm_assemble " $mddev " " $dev1 " " $dev2 "
2018-10-18 21:06:42 +03:00
2019-07-10 22:13:01 +03:00
not pvs " $dev1 "
not pvs " $dev2 "
2021-03-22 23:45:39 +03:00
pvs | tee out
2019-07-10 22:13:01 +03:00
not grep " $dev1 " out
not grep " $dev2 " out
lvs $vg
vgchange -an $vg
# should not activate from the md legs
_clear_online_files
pvscan --cache -aay " $dev1 "
pvscan --cache -aay " $dev2 "
2021-03-22 23:45:39 +03:00
test ! -f " $RUNDIR /lvm/pvs_online/ $PVIDMD "
test ! -f " $RUNDIR /lvm/vgs_online/ $vg "
2019-07-10 22:13:01 +03:00
# should not show an active lv
2021-03-24 02:37:24 +03:00
not dmsetup info $vg -$lv1
2019-07-10 22:13:01 +03:00
vgchange -ay $vg
check lv_field $vg /$lv1 lv_active "active"
vgchange -an $vg
_clear_online_files
pvscan --cache -aay " $mddev "
2021-03-22 23:45:39 +03:00
test -f " $RUNDIR /lvm/pvs_online/ $PVIDMD "
test -f " $RUNDIR /lvm/vgs_online/ $vg "
2019-07-10 22:13:01 +03:00
2021-03-22 23:45:39 +03:00
check active $vg $lv1
2019-07-10 22:13:01 +03:00
vgchange -an $vg
vgremove -f $vg
2021-03-22 23:45:39 +03:00
aux cleanup_md_dev
2023-07-15 11:39:56 +03:00
aux wipefs_a " $dev1 " " $dev2 "
2019-09-11 21:26:41 +03:00
2021-03-22 23:45:39 +03:00
done
2019-07-10 22:13:01 +03:00
# Repeat tests using the default config settings
2021-03-22 23:45:39 +03:00
aux lvmconf "devices/hints = \"all\"" \
2021-08-23 23:01:26 +03:00
"devices/obtain_device_list_from_udev = 1" \
"devices/search_for_devnames = \"none\""
rm $DF || true
2019-07-10 22:13:01 +03:00
# create 2 disk MD raid0 array
# by default using metadata format 1.0 with data at the end of device
# When a raid0 md array is stopped, the components will not look like
# duplicate PVs as they do with raid1.
2021-03-22 23:45:39 +03:00
aux mdadm_create --metadata= 1.0 --level= 0 --chunk= 64 --raid-devices= 2 " $dev1 " " $dev2 "
mddev = $( < MD_DEV)
2019-07-10 22:13:01 +03:00
# Create an unused PV so that there is at least one PV in the hints
# when the MD dev is stopped. If there are no PVs, the hints are
# empty, and the code falls back to scanning all, and we do not end
# up testing the code with hints actively used.
pvcreate " $dev3 "
vgcreate $vg " $mddev "
2021-03-22 23:45:39 +03:00
PVIDMD = $( get pv_field " $mddev " uuid | tr -d - )
2019-07-10 22:13:01 +03:00
lvcreate -n $lv1 -l 2 $vg
lvcreate -n $lv2 -l 2 -an $vg
lvchange -ay $vg /$lv2
check lv_field $vg /$lv1 lv_active "active"
# lvm does not show md components as PVs
pvs " $mddev "
not pvs " $dev1 "
not pvs " $dev2 "
pvs > out
not grep " $dev1 " out
not grep " $dev2 " out
2021-03-22 23:45:39 +03:00
grep " $mddev " " $HINTS "
grep " $dev3 " " $HINTS "
not grep " $dev1 " " $HINTS "
not grep " $dev2 " " $HINTS "
2019-07-10 22:13:01 +03:00
vgchange -an $vg
# When the md device is started, lvm will see that and know to
# scan for md components, so stop the md device to remove this
# advantage so we will test the fallback detection.
mdadm --stop " $mddev "
aux udev_wait
# A WARNING indicating duplicate PVs is printed by 'pvs' in this
# case. It's printed during the scan, but after the scan, the
# md component detection is run on the devs and they are dropped
# when we see they are md components. So, we ignore the warning
# containing the word duplicate, and look for the "Not using device"
# message, which shouldn't appear, as it would indicate that
# we didn't drop the md components.
# FIXME: we should avoid printing the premature warning indicating
# duplicate PVs which are eventually recognized as md components
# and dropped.
pvs 2>& 1| tee out1
2021-08-23 23:01:26 +03:00
grep -v -e WARNING -e "Devices file PVID" out1 > out2
2019-07-10 22:13:01 +03:00
not grep "Not using device" out2
not grep " $mddev " out2
not grep " $dev1 " out2
not grep " $dev2 " out2
grep " $dev3 " out2
2021-03-22 23:45:39 +03:00
cat " $HINTS "
2019-07-10 22:13:01 +03:00
pvs 2>& 1| tee out1
2021-08-23 23:01:26 +03:00
grep -v -e WARNING -e "Devices file PVID" out1 > out2
2019-07-10 22:13:01 +03:00
not grep "Not using device" out2
not grep " $mddev " out2
not grep " $dev1 " out2
not grep " $dev2 " out2
grep " $dev3 " out2
2021-03-22 23:45:39 +03:00
cat " $HINTS "
2018-10-18 21:06:42 +03:00
2019-07-10 22:13:01 +03:00
# The md components should still be detected and excluded.
2019-05-21 20:06:34 +03:00
not pvs " $dev1 "
not pvs " $dev2 "
2021-03-22 23:45:39 +03:00
pvs | tee out
2019-05-21 20:06:34 +03:00
not grep " $dev1 " out
not grep " $dev2 " out
2019-07-10 22:13:01 +03:00
grep " $dev3 " out
2018-10-18 21:06:42 +03:00
2019-07-10 22:13:01 +03:00
# should not activate from the md legs
not vgchange -ay $vg
# should not show an active lv
2021-03-24 02:37:24 +03:00
not dmsetup info $vg -$lv1
2019-07-10 22:13:01 +03:00
# should not allow updating vg
not lvcreate -l1 $vg
# should not activate from the md legs
_clear_online_files
pvscan --cache -aay " $dev1 "
pvscan --cache -aay " $dev2 "
2021-03-22 23:45:39 +03:00
test ! -f " $RUNDIR /lvm/pvs_online/ $PVIDMD "
test ! -f " $RUNDIR /lvm/vgs_online/ $vg "
2019-07-10 22:13:01 +03:00
# should not show an active lv
2021-03-24 02:37:24 +03:00
not dmsetup info $vg -$lv1
2019-07-10 22:13:01 +03:00
# start the md dev
2021-03-26 18:07:24 +03:00
aux mdadm_assemble " $mddev " " $dev1 " " $dev2 "
2019-07-10 22:13:01 +03:00
not pvs " $dev1 "
not pvs " $dev2 "
2021-03-22 23:45:39 +03:00
pvs | tee out
2019-07-10 22:13:01 +03:00
not grep " $dev1 " out
not grep " $dev2 " out
lvs $vg
vgchange -an $vg
# should not activate from the md legs
_clear_online_files
pvscan --cache -aay " $dev1 "
pvscan --cache -aay " $dev2 "
2021-03-22 23:45:39 +03:00
test ! -f " $RUNDIR /lvm/pvs_online/ $PVIDMD "
test ! -f " $RUNDIR /lvm/vgs_online/ $vg "
2019-07-10 22:13:01 +03:00
# should not show an active lv
2021-03-24 02:37:24 +03:00
not dmsetup info $vg -$lv1
2019-07-10 22:13:01 +03:00
vgchange -ay $vg
2018-10-18 21:06:42 +03:00
2019-05-03 22:05:40 +03:00
check lv_field $vg /$lv1 lv_active "active"
2018-10-18 21:06:42 +03:00
vgchange -an $vg
2019-07-10 22:13:01 +03:00
_clear_online_files
pvscan --cache -aay " $mddev "
2021-03-22 23:45:39 +03:00
test -f " $RUNDIR /lvm/pvs_online/ $PVIDMD "
test -f " $RUNDIR /lvm/vgs_online/ $vg "
2019-07-10 22:13:01 +03:00
2021-03-22 23:45:39 +03:00
check active $vg $lv1
2019-07-10 22:13:01 +03:00
vgchange -an $vg
2019-05-03 22:05:40 +03:00
vgremove -f $vg
2021-03-22 23:45:39 +03:00
aux cleanup_md_dev