master - configure: Fix the default in help string
by Marian Csontos
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=9b63f590168b14d0e99...
Commit: 9b63f590168b14d0e996f62519edb27f24ab83e2
Parent: 0534cd9cd4066c88a7dd815f2f3206a177169334
Author: Marian Csontos <mcsontos(a)redhat.com>
AuthorDate: Wed Jul 31 16:24:18 2019 +0200
Committer: Marian Csontos <mcsontos(a)redhat.com>
CommitterDate: Mon Aug 19 15:28:01 2019 +0200
configure: Fix the default in help string
---
configure.ac | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/configure.ac b/configure.ac
index 1e45c0e..5da6946 100644
--- a/configure.ac
+++ b/configure.ac
@@ -653,7 +653,7 @@ dnl -- writecache inclusion type
AC_MSG_CHECKING(whether to include writecache)
AC_ARG_WITH(writecache,
AC_HELP_STRING([--with-writecache=TYPE],
- [writecache support: internal/none [internal]]),
+ [writecache support: internal/none [none]]),
WRITECACHE=$withval, WRITECACHE="none")
AC_MSG_RESULT($WRITECACHE)
4 years, 8 months
master - pvscan: disable sleeping and retrying for udev
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=0534cd9cd4066c88a7d...
Commit: 0534cd9cd4066c88a7dd815f2f3206a177169334
Parent: 61fce72a114d23b98bfd4a9d457e3d55297455ef
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Aug 16 14:35:17 2019 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Aug 16 14:41:26 2019 -0500
pvscan: disable sleeping and retrying for udev
When systemd is running pvscans, udev may not be
entirely initialized, so the pvscan should not
sleep and retry waiting for udev info.
---
lib/device/dev-type.c | 3 +++
lib/misc/lvm-globals.c | 11 +++++++++++
lib/misc/lvm-globals.h | 2 ++
tools/pvscan.c | 7 +++++++
4 files changed, 23 insertions(+), 0 deletions(-)
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
index 4e35220..ebe0f99 100644
--- a/lib/device/dev-type.c
+++ b/lib/device/dev-type.c
@@ -1118,6 +1118,9 @@ static struct udev_device *_udev_get_dev(struct device *dev)
i + 1, UDEV_DEV_IS_COMPONENT_ITERATION_COUNT,
i * UDEV_DEV_IS_COMPONENT_USLEEP);
+ if (!udev_sleeping())
+ break;
+
usleep(UDEV_DEV_IS_COMPONENT_USLEEP);
i++;
}
diff --git a/lib/misc/lvm-globals.c b/lib/misc/lvm-globals.c
index eb99cf5..06855ff 100644
--- a/lib/misc/lvm-globals.c
+++ b/lib/misc/lvm-globals.c
@@ -47,6 +47,7 @@ static int _ignore_lvm_mirrors = DEFAULT_IGNORE_LVM_MIRRORS;
static int _error_message_produced = 0;
static unsigned _is_static = 0;
static int _udev_checking = 1;
+static int _udev_sleeping = 1;
static int _retry_deactivation = DEFAULT_RETRY_DEACTIVATION;
static int _activation_checks = 0;
static char _sysfs_dir_path[PATH_MAX] = "";
@@ -186,6 +187,11 @@ void init_udev_checking(int checking)
log_debug_activation("LVM udev checking disabled");
}
+void init_udev_sleeping(int sleeping)
+{
+ _udev_sleeping = sleeping;
+}
+
void init_retry_deactivation(int retry)
{
_retry_deactivation = retry;
@@ -353,6 +359,11 @@ int udev_checking(void)
return _udev_checking;
}
+int udev_sleeping(void)
+{
+ return _udev_sleeping;
+}
+
int retry_deactivation(void)
{
return _retry_deactivation;
diff --git a/lib/misc/lvm-globals.h b/lib/misc/lvm-globals.h
index 921ae7e..a54001c 100644
--- a/lib/misc/lvm-globals.h
+++ b/lib/misc/lvm-globals.h
@@ -46,6 +46,7 @@ void init_ignore_lvm_mirrors(int scan);
void init_error_message_produced(int produced);
void init_is_static(unsigned value);
void init_udev_checking(int checking);
+void init_udev_sleeping(int sleeping);
void init_pv_min_size(uint64_t sectors);
void init_activation_checks(int checks);
void init_retry_deactivation(int retry);
@@ -77,6 +78,7 @@ const char *log_command_info(void);
const char *log_command_file(void);
unsigned is_static(void);
int udev_checking(void);
+int udev_sleeping(void);
const char *sysfs_dir_path(void);
uint64_t pv_min_size(void);
int activation_checks(void);
diff --git a/tools/pvscan.c b/tools/pvscan.c
index ac41500..bfa5a83 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -914,6 +914,13 @@ int pvscan_cache_cmd(struct cmd_context *cmd, int argc, char **argv)
dm_list_init(&rem_devs);
dm_list_init(&vgnames);
+ /*
+ * When systemd/udev run pvscan --cache commands, those commands
+ * should not wait on udev info since the udev info may not be
+ * complete until the pvscan --cache command is done.
+ */
+ init_udev_sleeping(0);
+
if (do_activate)
complete_vgnames = &vgnames;
4 years, 8 months
master - bcache: increase max allowed bcache size
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=61fce72a114d23b98bf...
Commit: 61fce72a114d23b98bfd4a9d457e3d55297455ef
Parent: 987f2733c76cff60eaf71b01f33ec8126121d792
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Aug 16 13:35:09 2019 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Aug 16 13:35:09 2019 -0500
bcache: increase max allowed bcache size
from 128MB to 512MB (the default remains 8MB)
---
lib/label/label.c | 4 ++--
1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/label/label.c b/lib/label/label.c
index 3c8e10c..e786c89 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -808,8 +808,8 @@ out:
* the metadata size.)
*/
-#define MIN_BCACHE_BLOCKS 32 /* 4MB */
-#define MAX_BCACHE_BLOCKS 1024
+#define MIN_BCACHE_BLOCKS 32 /* 4MB (32 * 128KB) */
+#define MAX_BCACHE_BLOCKS 4096 /* 512MB (4096 * 128KB) */
static int _setup_bcache(void)
{
4 years, 8 months
master - tests: duplicate-pvs-md
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=987f2733c76cff60eaf...
Commit: 987f2733c76cff60eaf71b01f33ec8126121d792
Parent: 83261b79b578f213127af6350c555ec347b7211a
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri Aug 16 13:22:58 2019 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Aug 16 13:26:12 2019 -0500
tests: duplicate-pvs-md
Testing duplicate PV handling for various md device setups/states.
---
test/shell/duplicate-pvs-md0.sh | 438 ++++++++++++++++++++++++++++
test/shell/duplicate-pvs-md1.sh | 602 +++++++++++++++++++++++++++++++++++++++
2 files changed, 1040 insertions(+), 0 deletions(-)
diff --git a/test/shell/duplicate-pvs-md0.sh b/test/shell/duplicate-pvs-md0.sh
new file mode 100644
index 0000000..5578a0c
--- /dev/null
+++ b/test/shell/duplicate-pvs-md0.sh
@@ -0,0 +1,438 @@
+#!/usr/bin/env bash
+
+# Copyright (C) 2012 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
+
+SKIP_WITH_LVMPOLLD=1
+
+RUNDIR="/run"
+test -d "$RUNDIR" || RUNDIR="/var/run"
+PVS_ONLINE_DIR="$RUNDIR/lvm/pvs_online"
+VGS_ONLINE_DIR="$RUNDIR/lvm/vgs_online"
+HINTS="$RUNDIR/lvm/hints"
+
+_clear_online_files() {
+ # wait till udev is finished
+ aux udev_wait
+ rm -f "$PVS_ONLINE_DIR"/*
+ rm -f "$VGS_ONLINE_DIR"/*
+}
+
+. lib/inittest
+
+test -f /proc/mdstat && grep -q raid0 /proc/mdstat || \
+ modprobe raid0 || skip
+
+aux lvmconf 'devices/md_component_detection = 1'
+
+# 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.
+aux lvmconf 'devices/obtain_device_list_from_udev = 0'
+
+aux extend_filter_LVMTEST "a|/dev/md|"
+
+aux prepare_devs 4
+
+# 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"
+
+## Test variations:
+# PV on md raid1|raid0, md_component_checks auto|start, mddev start|stopped,
+# one raid dev disabled when mddev is stopped.
+
+
+##########################################
+# PV on an md raid0 device, auto+started
+# md_component_checks: auto (not start)
+# mddev: started (not stopped)
+#
+
+aux lvmconf 'devices/md_component_checks = "auto"'
+
+aux prepare_md_dev 0 64 2 "$dev1" "$dev2"
+cat /proc/mdstat
+mddev=$(< MD_DEV)
+pvdev=$(< MD_DEV_PV)
+pvcreate "$mddev"
+PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'`
+echo $PVIDMD
+vgcreate $vg "$mddev"
+lvcreate -n $lv1 -l 2 -an $vg
+
+# pvs shows only the md dev as PV
+pvs "$mddev"
+not pvs "$dev1"
+not pvs "$dev2"
+pvs > out
+grep $mddev out
+not grep "$dev1" out
+not grep "$dev2" out
+grep "$mddev" $HINTS
+not grep "$dev1" $HINTS
+not grep "$dev2" $HINTS
+
+# normal activation works
+lvchange -ay $vg/$lv1
+lvs -o active $vg |tee out || true
+grep "active" out
+vgchange -an $vg
+
+# pvscan activation all works
+_clear_online_files
+pvscan --cache -aay
+ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+ls "$RUNDIR/lvm/vgs_online/$vg"
+lvs -o active $vg |tee out || true
+grep "active" out
+vgchange -an $vg
+
+# pvscan activation from mddev works
+_clear_online_files
+pvscan --cache -aay "$mddev"
+ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+ls "$RUNDIR/lvm/vgs_online/$vg"
+lvs -o active $vg |tee out || true
+grep "active" out
+vgchange -an $vg
+
+# pvscan activation from md components does nothing
+_clear_online_files
+pvscan --cache -aay "$dev1"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+pvscan --cache -aay "$dev2"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+lvs -o active $vg |tee out || true
+not grep "active" out
+
+vgchange -an $vg
+vgremove -f $vg
+aux cleanup_md_dev
+
+
+##########################################
+# PV on an md raid0 device, start+started
+# md_component_checks: start (not auto)
+# mddev: started (not stopped)
+#
+
+aux lvmconf 'devices/md_component_checks = "start"'
+
+aux prepare_md_dev 0 64 2 "$dev1" "$dev2"
+cat /proc/mdstat
+mddev=$(< MD_DEV)
+pvdev=$(< MD_DEV_PV)
+pvcreate "$mddev"
+PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'`
+echo $PVIDMD
+vgcreate $vg "$mddev"
+lvcreate -n $lv1 -l 2 -an $vg
+
+# pvs shows only the md dev as PV
+pvs "$mddev"
+not pvs "$dev1"
+not pvs "$dev2"
+pvs > out
+grep $mddev out
+not grep "$dev1" out
+not grep "$dev2" out
+# N.B. in this case hints are disabled for duplicate pvs seen by scan
+# it would be preferrable if this didn't happen as in auto mode, but it's ok.
+# grep "$mddev" $HINTS
+not grep "$dev1" $HINTS
+not grep "$dev2" $HINTS
+
+# normal activation works
+lvchange -ay $vg/$lv1
+lvs -o active $vg |tee out || true
+grep "active" out
+vgchange -an $vg
+
+# pvscan activation all works
+_clear_online_files
+pvscan --cache -aay
+ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+ls "$RUNDIR/lvm/vgs_online/$vg"
+lvs -o active $vg |tee out || true
+grep "active" out
+vgchange -an $vg
+
+# pvscan activation from mddev works
+_clear_online_files
+pvscan --cache -aay "$mddev"
+ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+ls "$RUNDIR/lvm/vgs_online/$vg"
+lvs -o active $vg |tee out || true
+grep "active" out
+vgchange -an $vg
+
+# N.B. with raid0 the component because the PV/size difference
+# triggers and md component check, whereas with raid1 it doesn't.
+_clear_online_files
+pvscan --cache -aay "$dev1"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+lvs -o active $vg |tee out || true
+not grep "active" out
+
+vgchange -an $vg
+vgremove -f $vg
+aux cleanup_md_dev
+
+
+##########################################
+# PV on an md raid0 device, auto+stopped
+# md_component_checks: auto (not start)
+# mddev: stopped (not started)
+#
+
+aux lvmconf 'devices/md_component_checks = "auto"'
+
+aux prepare_md_dev 0 64 2 "$dev1" "$dev2"
+cat /proc/mdstat
+mddev=$(< MD_DEV)
+pvdev=$(< MD_DEV_PV)
+pvcreate "$mddev"
+PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'`
+echo $PVIDMD
+vgcreate $vg "$mddev"
+lvcreate -n $lv1 -l 2 -an $vg
+
+mdadm --stop "$mddev"
+cat /proc/mdstat
+
+# pvs does not show the PV
+not pvs "$mddev"
+not pvs "$dev1"
+not pvs "$dev2"
+pvs > out
+not grep $mddev out
+not grep "$dev1" out
+not grep "$dev2" out
+pvscan --cache
+not grep "$mddev" $HINTS
+not grep "$dev1" $HINTS
+not grep "$dev2" $HINTS
+
+# the vg is not seen, normal activation does nothing
+not lvchange -ay $vg/$lv1
+not lvs $vg
+
+# pvscan activation all does nothing
+_clear_online_files
+pvscan --cache -aay
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+# pvscan activation from md components does nothing
+_clear_online_files
+pvscan --cache -aay "$dev1"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+pvscan --cache -aay "$dev2"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+aux cleanup_md_dev
+
+##########################################
+# PV on an md raid0 device, start+stopped
+# md_component_checks: start (not auto)
+# mddev: stopped (not started)
+#
+
+aux lvmconf 'devices/md_component_checks = "start"'
+
+wipefs -a "$dev1" "$dev2"
+aux prepare_md_dev 0 64 2 "$dev1" "$dev2"
+cat /proc/mdstat
+mddev=$(< MD_DEV)
+pvdev=$(< MD_DEV_PV)
+pvcreate "$mddev"
+PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'`
+echo $PVIDMD
+vgcreate $vg "$mddev"
+lvcreate -n $lv1 -l 2 -an $vg
+
+mdadm --stop "$mddev"
+cat /proc/mdstat
+
+# pvs does not show the PV
+not pvs "$mddev"
+not pvs "$dev1"
+not pvs "$dev2"
+pvs > out
+not grep $mddev out
+not grep "$dev1" out
+not grep "$dev2" out
+pvscan --cache
+not grep "$mddev" $HINTS
+# N.B. it would be preferrable if dev1 did not appear in hints but it's ok
+# not grep "$dev1" $HINTS
+not grep "$dev2" $HINTS
+
+# the vg is not seen, normal activation does nothing
+not lvchange -ay $vg/$lv1
+not lvs $vg
+
+# pvscan activation all does nothing
+_clear_online_files
+pvscan --cache -aay
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+# pvscan activation from md components does nothing
+_clear_online_files
+pvscan --cache -aay "$dev1" || true
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+pvscan --cache -aay "$dev2" || true
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+lvs -o active $vg |tee out || true
+not grep "active" out
+
+aux cleanup_md_dev
+
+
+##########################################
+# PV on an md raid0 device, start+stopped
+# md_component_checks: start (not auto)
+# mddev: stopped (not started)
+# only one raid dev online
+#
+
+aux lvmconf 'devices/md_component_checks = "start"'
+
+wipefs -a "$dev1" "$dev2"
+aux prepare_md_dev 0 64 2 "$dev1" "$dev2"
+cat /proc/mdstat
+mddev=$(< MD_DEV)
+pvdev=$(< MD_DEV_PV)
+pvcreate "$mddev"
+PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'`
+echo $PVIDMD
+vgcreate $vg "$mddev"
+lvcreate -n $lv1 -l 2 -an $vg
+
+mdadm --stop "$mddev"
+cat /proc/mdstat
+
+# disable one dev of the md device
+aux disable_dev "$dev2"
+
+# pvs does not show the PV
+not pvs "$mddev"
+not pvs "$dev1"
+not pvs "$dev2"
+pvs > out
+not grep $mddev out
+not grep "$dev1" out
+not grep "$dev2" out
+pvscan --cache
+not grep "$mddev" $HINTS
+# N.B. would be preferrable for this md component to not be in hints
+# grep "$dev1" $HINTS
+not grep "$dev2" $HINTS
+
+not lvchange -ay $vg/$lv1
+not lvs $vg
+
+_clear_online_files
+pvscan --cache -aay
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+_clear_online_files
+pvscan --cache -aay "$dev1"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+aux enable_dev "$dev2"
+aux udev_wait
+cat /proc/mdstat
+# for some reason enabling dev2 starts an odd md dev
+mdadm --stop "$mddev" || true
+mdadm --stop --scan
+cat /proc/mdstat
+wipefs -a "$dev1" || true
+wipefs -a "$dev2" || true
+
+##########################################
+# PV on an md raid0 device, auto+stopped
+# md_component_checks: auto (not start)
+# mddev: stopped (not started)
+# only one raid dev online
+#
+
+aux lvmconf 'devices/md_component_checks = "auto"'
+
+aux prepare_md_dev 0 64 2 "$dev1" "$dev2"
+cat /proc/mdstat
+mddev=$(< MD_DEV)
+pvdev=$(< MD_DEV_PV)
+pvcreate "$mddev"
+PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'`
+echo $PVIDMD
+vgcreate $vg "$mddev"
+lvcreate -n $lv1 -l 2 -an $vg
+
+mdadm --stop "$mddev"
+cat /proc/mdstat
+
+# disable one leg
+aux disable_dev "$dev2"
+
+# pvs does not show the PV
+not pvs "$mddev"
+not pvs "$dev1"
+not pvs "$dev2"
+pvs > out
+not grep $mddev out
+not grep "$dev1" out
+not grep "$dev2" out
+pvscan --cache
+not grep "$mddev" $HINTS
+not grep "$dev1" $HINTS
+not grep "$dev2" $HINTS
+
+# the vg is not seen, normal activation does nothing
+not lvchange -ay $vg/$lv1
+not lvs $vg
+
+# pvscan activation all does nothing
+_clear_online_files
+pvscan --cache -aay
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+# pvscan activation from md components does nothing
+_clear_online_files
+pvscan --cache -aay "$dev1"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+pvscan --cache -aay "$dev2"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+aux enable_dev "$dev2"
+aux udev_wait
+cat /proc/mdstat
+# for some reason enabling dev2 starts an odd md dev
+mdadm --stop "$mddev" || true
+mdadm --stop --scan
+cat /proc/mdstat
+wipefs -a "$dev1" || true
+wipefs -a "$dev2" || true
diff --git a/test/shell/duplicate-pvs-md1.sh b/test/shell/duplicate-pvs-md1.sh
new file mode 100644
index 0000000..47b5bac
--- /dev/null
+++ b/test/shell/duplicate-pvs-md1.sh
@@ -0,0 +1,602 @@
+#!/usr/bin/env bash
+
+# Copyright (C) 2012 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
+
+# . different PV/VG's that happen to have the same PVID
+# . a single PV/VG cloned to another device
+# . dm wrapper around a PV
+# . a single PV/VG cloned plus a dm wrapper (two separate dups of a PV)
+
+SKIP_WITH_LVMPOLLD=1
+
+RUNDIR="/run"
+test -d "$RUNDIR" || RUNDIR="/var/run"
+PVS_ONLINE_DIR="$RUNDIR/lvm/pvs_online"
+VGS_ONLINE_DIR="$RUNDIR/lvm/vgs_online"
+HINTS="$RUNDIR/lvm/hints"
+
+_clear_online_files() {
+ # wait till udev is finished
+ aux udev_wait
+ rm -f "$PVS_ONLINE_DIR"/*
+ rm -f "$VGS_ONLINE_DIR"/*
+}
+
+. lib/inittest
+
+test -f /proc/mdstat && grep -q raid1 /proc/mdstat || \
+ modprobe raid1 || skip
+
+aux lvmconf 'devices/md_component_detection = 1'
+
+# 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.
+aux lvmconf 'devices/obtain_device_list_from_udev = 0'
+
+aux extend_filter_LVMTEST "a|/dev/md|"
+
+aux prepare_devs 4
+
+# 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"
+
+## Test variations:
+# PV on md raid1|raid0, md_component_checks auto|start, mddev start|stopped,
+# one leg disabled when mddev is stopped.
+
+
+##########################################
+# PV on an md raid1 device, auto+started
+# md_component_checks: auto (not start)
+# mddev: started (not stopped)
+#
+
+aux lvmconf 'devices/md_component_checks = "auto"'
+
+aux prepare_md_dev 1 64 2 "$dev1" "$dev2"
+sleep 4
+cat /proc/mdstat
+mddev=$(< MD_DEV)
+pvdev=$(< MD_DEV_PV)
+pvcreate "$mddev"
+PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'`
+echo $PVIDMD
+vgcreate $vg "$mddev"
+lvcreate -n $lv1 -l 2 -an $vg
+
+# pvs shows only the md dev as PV
+pvs "$mddev"
+not pvs "$dev1"
+not pvs "$dev2"
+pvs > out
+grep $mddev out
+not grep "$dev1" out
+not grep "$dev2" out
+grep "$mddev" $HINTS
+not grep "$dev1" $HINTS
+not grep "$dev2" $HINTS
+
+# normal activation works
+lvchange -ay $vg/$lv1
+lvs -o active $vg |tee out || true
+grep "active" out
+vgchange -an $vg
+
+# pvscan activation all works
+_clear_online_files
+pvscan --cache -aay
+ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+ls "$RUNDIR/lvm/vgs_online/$vg"
+lvs -o active $vg |tee out || true
+grep "active" out
+vgchange -an $vg
+
+# pvscan activation from mddev works
+_clear_online_files
+pvscan --cache -aay "$mddev"
+ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+ls "$RUNDIR/lvm/vgs_online/$vg"
+lvs -o active $vg |tee out || true
+grep "active" out
+vgchange -an $vg
+
+# pvscan activation from md components does nothing
+_clear_online_files
+pvscan --cache -aay "$dev1"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+pvscan --cache -aay "$dev2"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+lvs -o active $vg |tee out || true
+not grep "active" out
+
+vgchange -an $vg
+vgremove -f $vg
+aux cleanup_md_dev
+
+
+##########################################
+# PV on an md raid1 device, start+started
+# md_component_checks: start (not auto)
+# mddev: started (not stopped)
+#
+
+aux lvmconf 'devices/md_component_checks = "start"'
+
+aux prepare_md_dev 1 64 2 "$dev1" "$dev2"
+sleep 4
+cat /proc/mdstat
+mddev=$(< MD_DEV)
+pvdev=$(< MD_DEV_PV)
+pvcreate "$mddev"
+PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'`
+echo $PVIDMD
+vgcreate $vg "$mddev"
+lvcreate -n $lv1 -l 2 -an $vg
+
+# pvs shows only the md dev as PV
+pvs "$mddev"
+not pvs "$dev1"
+not pvs "$dev2"
+pvs > out
+grep $mddev out
+not grep "$dev1" out
+not grep "$dev2" out
+# N.B. in this case hints are disabled for duplicate pvs seen by scan
+# it would be preferrable if this didn't happen as in auto mode, but it's ok.
+# grep "$mddev" $HINTS
+not grep "$dev1" $HINTS
+not grep "$dev2" $HINTS
+
+# normal activation works
+lvchange -ay $vg/$lv1
+lvs -o active $vg |tee out || true
+grep "active" out
+vgchange -an $vg
+
+# pvscan activation all works
+_clear_online_files
+pvscan --cache -aay
+ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+ls "$RUNDIR/lvm/vgs_online/$vg"
+lvs -o active $vg |tee out || true
+grep "active" out
+vgchange -an $vg
+
+# pvscan activation from mddev works
+_clear_online_files
+pvscan --cache -aay "$mddev"
+ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+ls "$RUNDIR/lvm/vgs_online/$vg"
+lvs -o active $vg |tee out || true
+grep "active" out
+vgchange -an $vg
+
+# N.B. pvscan --cache on the md component does not detect it's
+# a md component, and marks the PVID online, then does activation,
+# but the activation phase scans all devs, finds duplicates between
+# components and the actual md dev, chooses the md dev, and activates
+# the VG using the md dev.
+# The behavior with auto mode is preferable in which this does nothing,
+# but this is ok.
+_clear_online_files
+pvscan --cache -aay "$dev1"
+ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+ls "$RUNDIR/lvm/vgs_online/$vg"
+lvs -o active $vg |tee out || true
+grep "active" out
+# FIXME: verify the LV is using the md dev and not the component
+
+vgchange -an $vg
+vgremove -f $vg
+aux cleanup_md_dev
+
+
+##########################################
+# PV on an md raid1 device, auto+stopped
+# md_component_checks: auto (not start)
+# mddev: stopped (not started)
+#
+
+aux lvmconf 'devices/md_component_checks = "auto"'
+
+aux prepare_md_dev 1 64 2 "$dev1" "$dev2"
+sleep 4
+cat /proc/mdstat
+mddev=$(< MD_DEV)
+pvdev=$(< MD_DEV_PV)
+pvcreate "$mddev"
+PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'`
+echo $PVIDMD
+vgcreate $vg "$mddev"
+lvcreate -n $lv1 -l 2 -an $vg
+
+mdadm --stop "$mddev"
+cat /proc/mdstat
+
+# pvs does not show the PV
+not pvs "$mddev"
+not pvs "$dev1"
+not pvs "$dev2"
+pvs > out
+not grep $mddev out
+not grep "$dev1" out
+not grep "$dev2" out
+pvscan --cache
+not grep "$mddev" $HINTS
+not grep "$dev1" $HINTS
+not grep "$dev2" $HINTS
+
+# the vg is not seen, normal activation does nothing
+not lvchange -ay $vg/$lv1
+not lvs $vg
+
+# pvscan activation all does nothing
+_clear_online_files
+pvscan --cache -aay
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+# pvscan activation from md components does nothing
+_clear_online_files
+pvscan --cache -aay "$dev1"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+pvscan --cache -aay "$dev2"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+aux cleanup_md_dev
+
+##########################################
+# PV on an md raid1 device, start+stopped
+# md_component_checks: start (not auto)
+# mddev: stopped (not started)
+#
+
+aux lvmconf 'devices/md_component_checks = "start"'
+
+wipefs -a "$dev1" "$dev2"
+aux prepare_md_dev 1 64 2 "$dev1" "$dev2"
+sleep 4
+cat /proc/mdstat
+mddev=$(< MD_DEV)
+pvdev=$(< MD_DEV_PV)
+pvcreate "$mddev"
+PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'`
+echo $PVIDMD
+vgcreate $vg "$mddev"
+lvcreate -n $lv1 -l 2 -an $vg
+
+mdadm --stop "$mddev"
+cat /proc/mdstat
+
+# pvs does not show the PV
+not pvs "$mddev"
+not pvs "$dev1"
+not pvs "$dev2"
+pvs > out
+not grep $mddev out
+not grep "$dev1" out
+not grep "$dev2" out
+pvscan --cache
+not grep "$mddev" $HINTS
+not grep "$dev1" $HINTS
+not grep "$dev2" $HINTS
+
+# the vg is not seen, normal activation does nothing
+not lvchange -ay $vg/$lv1
+not lvs $vg
+
+# pvscan activation all does nothing
+_clear_online_files
+pvscan --cache -aay
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+# pvscan activation from md components does nothing
+_clear_online_files
+pvscan --cache -aay "$dev1" || true
+# N.B it would be preferrable if this did not recognize the PV on the
+# component and attempt to activate, like auto mode, but this is ok,
+# the activation scans all devs, sees duplicates, which triggers md
+# component detection which eliminates both devs, leaving no vg to activate.
+ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+ls "$RUNDIR/lvm/vgs_online/$vg"
+pvscan --cache -aay "$dev2" || true
+lvs -o active $vg |tee out || true
+not grep "active" out
+
+aux cleanup_md_dev
+
+
+##########################################
+# PV on an md raid1 device, start+stopped
+# md_component_checks: start (not auto)
+# mddev: stopped (not started)
+# only one raid image online
+#
+# N.B. This test case is just characterizing the current behavior, even
+# though the behavior it's testing for is not what we'd want to happen.
+# In this scenario, we have disabled/avoided everything that would
+# lead lvm to discover that dev1 is an md component, so dev1 is used
+# as the PV. Multiple default settings need to be changed to get to
+# this unwanted behavior (md_component_checks,
+# obtain_device_list_from_udev), and multiple other conditions also
+# need to be true (md device stopped, only one leg visible).
+
+aux lvmconf 'devices/md_component_checks = "start"'
+
+wipefs -a "$dev1" "$dev2"
+aux prepare_md_dev 1 64 2 "$dev1" "$dev2"
+sleep 4
+cat /proc/mdstat
+mddev=$(< MD_DEV)
+pvdev=$(< MD_DEV_PV)
+pvcreate "$mddev"
+PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'`
+echo $PVIDMD
+vgcreate $vg "$mddev"
+lvcreate -n $lv1 -l 2 -an $vg
+
+mdadm --stop "$mddev"
+cat /proc/mdstat
+
+# disable one leg of the md device, with raid1 this means duplicates
+# will not be seen for the legs. duplicate handling can trigger
+# md component detection, so no duplicates means md components may
+# not be detected as easily.
+aux disable_dev "$dev2"
+
+# pvs does not show the PV
+not pvs "$mddev"
+pvs "$dev1"
+not pvs "$dev2"
+pvs > out
+not grep $mddev out
+grep "$dev1" out
+not grep "$dev2" out
+pvscan --cache
+not grep "$mddev" $HINTS
+grep "$dev1" $HINTS
+not grep "$dev2" $HINTS
+
+lvchange -ay $vg/$lv1
+lvs $vg
+vgchange -an $vg
+
+_clear_online_files
+pvscan --cache -aay
+ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+ls "$RUNDIR/lvm/vgs_online/$vg"
+vgchange -an $vg
+
+_clear_online_files
+pvscan --cache -aay "$dev1"
+ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+ls "$RUNDIR/lvm/vgs_online/$vg"
+vgchange -an $vg
+
+aux enable_dev "$dev2"
+aux udev_wait
+cat /proc/mdstat
+# for some reason enabling dev2 starts an odd md dev
+mdadm --stop "$mddev" || true
+mdadm --stop --scan
+cat /proc/mdstat
+wipefs -a "$dev1" || true
+wipefs -a "$dev2" || true
+
+##########################################
+# PV on an md raid1 device, auto+stopped
+# md_component_checks: auto (not start)
+# mddev: stopped (not started)
+# only one raid image online
+#
+
+aux lvmconf 'devices/md_component_checks = "auto"'
+
+aux prepare_md_dev 1 64 2 "$dev1" "$dev2"
+sleep 4
+cat /proc/mdstat
+mddev=$(< MD_DEV)
+pvdev=$(< MD_DEV_PV)
+pvcreate "$mddev"
+PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'`
+echo $PVIDMD
+vgcreate $vg "$mddev"
+lvcreate -n $lv1 -l 2 -an $vg
+
+mdadm --stop "$mddev"
+cat /proc/mdstat
+
+# disable one leg
+aux disable_dev "$dev2"
+
+# pvs does not show the PV
+not pvs "$mddev"
+not pvs "$dev1"
+not pvs "$dev2"
+pvs > out
+not grep $mddev out
+not grep "$dev1" out
+not grep "$dev2" out
+pvscan --cache
+not grep "$mddev" $HINTS
+not grep "$dev1" $HINTS
+not grep "$dev2" $HINTS
+
+# the vg is not seen, normal activation does nothing
+not lvchange -ay $vg/$lv1
+not lvs $vg
+
+# pvscan activation all does nothing
+_clear_online_files
+pvscan --cache -aay
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+# pvscan activation from md components does nothing
+_clear_online_files
+pvscan --cache -aay "$dev1"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+pvscan --cache -aay "$dev2"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+aux enable_dev "$dev2"
+aux udev_wait
+cat /proc/mdstat
+# for some reason enabling dev2 starts an odd md dev
+mdadm --stop "$mddev" || true
+mdadm --stop --scan
+cat /proc/mdstat
+wipefs -a "$dev1" || true
+wipefs -a "$dev2" || true
+
+
+##########################################
+# PV on an md raid1 device, auto+stopped
+# md_component_checks: auto (not start)
+# mddev: stopped (not started)
+# three raid images
+#
+
+aux lvmconf 'devices/md_component_checks = "auto"'
+
+aux prepare_md_dev 1 64 3 "$dev1" "$dev2" "$dev4"
+sleep 4
+cat /proc/mdstat
+mddev=$(< MD_DEV)
+pvdev=$(< MD_DEV_PV)
+pvcreate "$mddev"
+PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'`
+echo $PVIDMD
+vgcreate $vg "$mddev"
+lvcreate -n $lv1 -l 2 -an $vg
+
+mdadm --stop "$mddev"
+cat /proc/mdstat
+
+# pvs does not show the PV
+not pvs "$mddev"
+not pvs "$dev1"
+not pvs "$dev2"
+not pvs "$dev4"
+pvs > out
+not grep $mddev out
+not grep "$dev1" out
+not grep "$dev2" out
+not grep "$dev4" out
+pvscan --cache
+not grep "$mddev" $HINTS
+not grep "$dev1" $HINTS
+not grep "$dev2" $HINTS
+not grep "$dev4" $HINTS
+
+# the vg is not seen, normal activation does nothing
+not lvchange -ay $vg/$lv1
+not lvs $vg
+
+# pvscan activation all does nothing
+_clear_online_files
+pvscan --cache -aay
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+# pvscan activation from md components does nothing
+_clear_online_files
+pvscan --cache -aay "$dev1"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+pvscan --cache -aay "$dev2"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+pvscan --cache -aay "$dev4"
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+aux cleanup_md_dev
+
+
+##########################################
+# PV on an md raid1 device, start+stopped
+# md_component_checks: start (not auto)
+# mddev: stopped (not started)
+# three raid images
+
+aux lvmconf 'devices/md_component_checks = "start"'
+
+wipefs -a "$dev1" "$dev2" "$dev4"
+aux prepare_md_dev 1 64 3 "$dev1" "$dev2" "$dev4"
+sleep 4
+cat /proc/mdstat
+mddev=$(< MD_DEV)
+pvdev=$(< MD_DEV_PV)
+pvcreate "$mddev"
+PVIDMD=`pvs $mddev --noheading -o uuid | tr -d - | awk '{print $1}'`
+echo $PVIDMD
+vgcreate $vg "$mddev"
+lvcreate -n $lv1 -l 2 -an $vg
+
+mdadm --stop "$mddev"
+cat /proc/mdstat
+
+# pvs does not show the PV
+not pvs "$mddev"
+not pvs "$dev1"
+not pvs "$dev2"
+not pvs "$dev4"
+pvs > out
+not grep $mddev out
+not grep "$dev1" out
+not grep "$dev2" out
+not grep "$dev4" out
+pvscan --cache
+not grep "$mddev" $HINTS
+not grep "$dev1" $HINTS
+not grep "$dev2" $HINTS
+not grep "$dev4" $HINTS
+
+# the vg is not seen, normal activation does nothing
+not lvchange -ay $vg/$lv1
+not lvs $vg
+
+# pvscan activation all does nothing
+_clear_online_files
+pvscan --cache -aay
+not ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+not ls "$RUNDIR/lvm/vgs_online/$vg"
+
+# pvscan activation from md components does nothing
+_clear_online_files
+pvscan --cache -aay "$dev1" || true
+# N.B it would be preferrable if this did not recognize the PV on the
+# component and attempt to activate, like auto mode, but this is ok,
+# the activation scans all devs, sees duplicates, which triggers md
+# component detection which eliminates both devs, leaving no vg to activate.
+ls "$RUNDIR/lvm/pvs_online/$PVIDMD"
+ls "$RUNDIR/lvm/vgs_online/$vg"
+pvscan --cache -aay "$dev2" || true
+lvs -o active $vg |tee out || true
+not grep "active" out
+pvscan --cache -aay "$dev4" || true
+lvs -o active $vg |tee out || true
+not grep "active" out
+
+aux cleanup_md_dev
+
4 years, 8 months
master - pvscan cache: use lvmcache_label_scan
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=83261b79b578f213127...
Commit: 83261b79b578f213127af6350c555ec347b7211a
Parent: e01fddc5789b10d1bd15e8aee8985f14e81d3087
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Aug 1 15:07:59 2019 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Aug 16 13:26:12 2019 -0500
pvscan cache: use lvmcache_label_scan
instead of the lower level label_scan. The lvmcache wrapper
around label_scan checks for and eliminates more duplicate devs
and md components.
---
tools/pvscan.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/tools/pvscan.c b/tools/pvscan.c
index 168d509..ac41500 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -759,7 +759,7 @@ static void _online_pvscan_all_devs(struct cmd_context *cmd,
dm_list_init(&all_vgs);
- label_scan(cmd);
+ lvmcache_label_scan(cmd);
if (!(iter = dev_iter_create(cmd->filter, 1))) {
log_error("dev_iter creation failed");
4 years, 8 months
master - improve duplicate pv handling for md components
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=e01fddc5789b10d1bd1...
Commit: e01fddc5789b10d1bd15e8aee8985f14e81d3087
Parent: ee4a32e99224a0d4d2156c55d195e217967490b1
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Aug 1 15:04:10 2019 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Aug 16 13:26:12 2019 -0500
improve duplicate pv handling for md components
Eliminate md components at the start so they don't
interfere with actual duplicates, and don't need
to be removed later. This also allows for choosing
no copy of a PVID if they all happen to be md
components.
---
lib/cache/lvmcache.c | 287 +++++++++++++++++++++++++++++---------------------
lib/cache/lvmcache.h | 14 +--
lib/label/label.c | 5 +-
3 files changed, 175 insertions(+), 131 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index f2503b2..87c0021 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -116,6 +116,11 @@ void lvmcache_unlock_vgname(const char *vgname)
}
}
+int lvmcache_found_duplicate_vgnames(void)
+{
+ return _found_duplicate_vgnames;
+}
+
static struct device_list *_get_devl_in_device_list(struct device *dev, struct dm_list *head)
{
struct device_list *devl;
@@ -145,11 +150,6 @@ bool lvmcache_has_duplicate_devs(void)
return true;
}
-int lvmcache_found_duplicate_vgnames(void)
-{
- return _found_duplicate_vgnames;
-}
-
int lvmcache_get_unused_duplicates(struct cmd_context *cmd, struct dm_list *head)
{
struct device_list *devl, *devl2;
@@ -169,6 +169,10 @@ void lvmcache_del_dev_from_duplicates(struct device *dev)
{
struct device_list *devl;
+ if ((devl = _get_devl_in_device_list(dev, &_initial_duplicates))) {
+ log_debug_cache("delete dev from initial duplicates %s", dev_name(dev));
+ dm_list_del(&devl->list);
+ }
if ((devl = _get_devl_in_device_list(dev, &_unused_duplicates))) {
log_debug_cache("delete dev from unused duplicates %s", dev_name(dev));
dm_list_del(&devl->list);
@@ -384,7 +388,7 @@ const char *lvmcache_vgname_from_info(struct lvmcache_info *info)
/*
* Check if any PVs in vg->pvs have the same PVID as any
- * entries in _unused_duplicate_devices.
+ * entries in _unused_duplicates.
*/
int vg_has_duplicate_pvs(struct volume_group *vg)
@@ -406,65 +410,20 @@ bool lvmcache_dev_is_unused_duplicate(struct device *dev)
return dev_in_device_list(dev, &_unused_duplicates) ? true : false;
}
-/*
- * Treat some duplicate devs as if they were filtered out by filters.
- * The actual filters are evaluated too early, before a complete
- * picture of all PVs is available, to eliminate these duplicates.
- *
- * By removing some duplicates from unused_duplicate_devs here, we remove
- * the restrictions that are placed on using duplicate devs or VGs with
- * duplicate devs.
- *
- * In cases where we know that two duplicates refer to the same underlying
- * storage, and we know which dev path to use, it's best for us to just
- * use that one preferred device path and ignore the others. It is the cases
- * where we are unsure whether dups refer to the same underlying storage where
- * we need to keep the unused duplicate referenced in the
- * unused_duplicate_devs list, and restrict what we allow done with it.
- *
- * In the case of md components, we usually filter these out in filter-md,
- * but in the special case of md superblock version 1.0 where the superblock
- * is at the end of the device, filter-md doesn't always eliminate them
- * first, so we eliminate them here.
- *
- * There may other kinds of duplicates that we want to eliminate at
- * this point (using the knowledge from the scan) that we couldn't
- * eliminate in the filters prior to the scan.
- */
-
-static void _filter_duplicate_devs(struct cmd_context *cmd)
-{
- struct dev_types *dt = cmd->dev_types;
- struct lvmcache_info *info;
- struct device_list *devl, *devl2;
-
- dm_list_iterate_items_safe(devl, devl2, &_unused_duplicates) {
-
- if (!(info = lvmcache_info_from_pvid(devl->dev->pvid, NULL, 0)))
- continue;
-
- if (MAJOR(info->dev->dev) == dt->md_major) {
- log_debug_devs("Ignoring md component duplicate %s", dev_name(devl->dev));
- dm_list_del(&devl->list);
- free(devl);
- }
- }
-}
-
static void _warn_unused_duplicates(struct cmd_context *cmd)
{
char uuid[64] __attribute__((aligned(8)));
struct lvmcache_info *info;
- struct device_list *devl, *devl2;
+ struct device_list *devl;
- dm_list_iterate_items_safe(devl, devl2, &_unused_duplicates) {
+ dm_list_iterate_items(devl, &_unused_duplicates) {
if (!id_write_format((const struct id *)devl->dev->pvid, uuid, sizeof(uuid)))
stack;
log_warn("WARNING: Not using device %s for PV %s.", dev_name(devl->dev), uuid);
}
- dm_list_iterate_items_safe(devl, devl2, &_unused_duplicates) {
+ dm_list_iterate_items(devl, &_unused_duplicates) {
/* info for the preferred device that we're actually using */
if (!(info = lvmcache_info_from_pvid(devl->dev->pvid, NULL, 0)))
continue;
@@ -478,18 +437,42 @@ static void _warn_unused_duplicates(struct cmd_context *cmd)
}
/*
- * Compare _initial_duplicates entries with the corresponding duplicate dev
- * in lvmcache. There may be multiple duplicates in _initial_duplicates for
- * a given pvid. If a dev from _initial_duplicates is preferred over the dev
- * in lvmcache, then drop the dev in lvmcache and rescan the preferred dev to
- * add it to lvmcache.
+ * If we've found devices with the same PVID, decide which one
+ * to use.
+ *
+ * Compare _initial_duplicates entries with the corresponding
+ * dev (matching PVID) in lvmcache. There may be multiple
+ * entries in _initial_duplicates for a given PVID. If a dev
+ * from _initial is preferred over the comparable dev in lvmcache,
+ * then drop the comparable dev from lvmcache and rescan the dev
+ * from _initial (rescanning adds it to lvmcache.)
*
- * _initial_duplicates: duplicate devs found during initial scan.
- * These are compared to lvmcache devs to see if any are preferred.
+ * When a preferred dev is chosen, the dispreferred duplicate for
+ * it is kept in _unused_duplicates.
+ *
+ * For some duplicate entries, like a PV detected on an MD dev and
+ * on a component of that MD dev, we simply ignore the component
+ * dev, like it was excluded by a filter. In this case we do not
+ * keep the ignored dev on the _unused list.
+ *
+ * _initial_duplicates: duplicate devs found during label_scan.
+ * The first dev with a given PVID is added to lvmcache, and any
+ * subsequent devs with that PVID are not added to lvmcache, but
+ * are kept in the _initial_duplicates list. When label_scan is
+ * done, the caller (lvmcache_label_scan) compares the dev in
+ * lvmcache with the matching entries in _initial_duplicates to
+ * decide which dev should be the one used by the command (which
+ * will be the one kept in lvmcache.)
*
* _unused_duplicates: duplicate devs not chosen to be used.
- * These are _initial_duplicates entries that were not chosen,
- * or unpreferred lvmcache devs that were dropped.
+ * After label_scan adds entries to _initial_duplicates, the
+ * _initial entries are processed. If the current lvmcache dev is
+ * preferred over the _initial entry, then the _initial entry is
+ * moved to _unused_duplicates. If the current lvmcache dev
+ * is dispreferred vs the _initial duplicate, then the current
+ * lvmcache dev is added to _unused, the lvmcache info for it is
+ * dropped, the _initial dev is removed, that _initial dev is
+ * scanned and added to lvmcache.
*
* del_cache_devs: devices to drop from lvmcache
* add_cache_devs: devices to scan to add to lvmcache
@@ -499,11 +482,12 @@ static void _choose_duplicates(struct cmd_context *cmd,
struct dm_list *del_cache_devs,
struct dm_list *add_cache_devs)
{
+ char *pvid;
const char *reason;
struct dm_list altdevs;
struct dm_list new_unused;
struct dev_types *dt = cmd->dev_types;
- struct device_list *devl, *devl_safe, *alt, *del;
+ struct device_list *devl, *devl_safe, *devl_add, *devl_del;
struct lvmcache_info *info;
struct device *dev1, *dev2;
uint32_t dev1_major, dev1_minor, dev2_major, dev2_minor;
@@ -523,54 +507,91 @@ static void _choose_duplicates(struct cmd_context *cmd,
*/
next:
dm_list_init(&altdevs);
- alt = NULL;
+ pvid = NULL;
dm_list_iterate_items_safe(devl, devl_safe, &_initial_duplicates) {
- if (!alt) {
+ if (!pvid) {
dm_list_move(&altdevs, &devl->list);
- alt = devl;
+ pvid = devl->dev->pvid;
} else {
- if (!strcmp(alt->dev->pvid, devl->dev->pvid))
+ if (!strcmp(pvid, devl->dev->pvid))
dm_list_move(&altdevs, &devl->list);
}
}
- if (!alt) {
+ /* done, no more entries to process */
+ if (!pvid) {
_destroy_device_list(&_unused_duplicates);
dm_list_splice(&_unused_duplicates, &new_unused);
return;
}
/*
+ * Get rid of any md components before comparing alternatives.
+ * (Since an md component can never be used, it's not an
+ * option to use like other kinds of alternatives.)
+ */
+
+ info = lvmcache_info_from_pvid(pvid, NULL, 0);
+ if (info && dev_is_md_component(info->dev, NULL, 1)) {
+ /* does not go in del_cache_devs which become unused_duplicates */
+ log_debug_cache("PV %s drop MD component from scan selection %s", pvid, dev_name(info->dev));
+ lvmcache_del(info);
+ info = NULL;
+ }
+
+ dm_list_iterate_items_safe(devl, devl_safe, &altdevs) {
+ if (dev_is_md_component(devl->dev, NULL, 1)) {
+ log_debug_cache("PV %s drop MD component from scan duplicates %s", pvid, dev_name(devl->dev));
+ dm_list_del(&devl->list);
+ }
+ }
+
+ if (dm_list_empty(&altdevs))
+ goto next;
+
+
+ /*
* Find the device for the pvid that's currently in lvmcache.
*/
- if (!(info = lvmcache_info_from_pvid(alt->dev->pvid, NULL, 0))) {
+ if (!(info = lvmcache_info_from_pvid(pvid, NULL, 0))) {
/*
- * This will happen if a duplicate dev has been dropped already,
- * e.g. it was found to be an md component.
+ * This will happen if the lvmcache dev was already recognized
+ * as an md component and already dropped from lvmcache.
+ * One of the altdev entries for the PVID should be added to
+ * lvmcache.
*/
- log_debug("PVID %s on duplicate device %s not found in cache.",
- alt->dev->pvid, dev_name(alt->dev));
- goto next;
+ if (dm_list_size(&altdevs) == 1) {
+ devl = dm_list_item(dm_list_first(&altdevs), struct device_list);
+ dm_list_del(&devl->list);
+ dm_list_add(add_cache_devs, &devl->list);
+
+ log_debug_cache("PV %s with duplicates unselected using %s.",
+ pvid, dev_name(devl->dev));
+ goto next;
+ } else {
+ devl = dm_list_item(dm_list_first(&altdevs), struct device_list);
+ dev1 = devl->dev;
+
+ log_debug_cache("PV %s with duplicates unselected comparing alternatives", pvid);
+ }
+ } else {
+ log_debug_cache("PV %s with duplicates comparing alternatives for %s",
+ pvid, dev_name(info->dev));
+ dev1 = info->dev;
}
/*
* Compare devices for the given pvid to find one that's preferred.
- * "dev1" is the currently preferred device, starting with the device
- * currently in lvmcache.
*/
- dev1 = info->dev;
-
dm_list_iterate_items(devl, &altdevs) {
dev2 = devl->dev;
- if (dev1 == dev2) {
- /* This shouldn't happen */
- log_warn("Same duplicate device repeated %s", dev_name(dev1));
+ /* Took the first altdev to start with above. */
+ if (dev1 == dev2)
continue;
- }
prev_unchosen1 = dev_in_device_list(dev1, &_unused_duplicates);
prev_unchosen2 = dev_in_device_list(dev2, &_unused_duplicates);
@@ -697,43 +718,75 @@ next:
reason = "device was seen first";
}
- if (change) {
+ if (change)
dev1 = dev2;
- alt = devl;
- }
dev1->duplicate_prefer_reason = reason;
}
- if (dev1 != info->dev) {
- log_debug_cache("PV %s: switching to device %s instead of device %s.",
- dev1->pvid, dev_name(dev1), dev_name(info->dev));
+ /*
+ * At the end of the loop, dev1 is the device we prefer to
+ * use. If there's no info struct, it means there's no dev
+ * currently in lvmcache for this PVID, so just add the
+ * preferred one (dev1). If dev1 is different from the dev
+ * currently in lvmcache, then drop the dev in lvmcache and
+ * add dev1 to lvmcache. If dev1 is the same as the dev
+ * in lvmcache already, then no changes are needed and the
+ * altdevs all become unused duplicates.
+ */
+
+ if (!info) {
+ log_debug_cache("PV %s with duplicates will use %s.", pvid, dev_name(dev1));
+
+ if (!(devl_add = _get_devl_in_device_list(dev1, &altdevs))) {
+ /* shouldn't happen */
+ log_error(INTERNAL_ERROR "PV %s with duplicates no alternate list entry for %s", pvid, dev_name(dev1));
+ dm_list_splice(&new_unused, &altdevs);
+ goto next;
+ }
+
+ dm_list_move(add_cache_devs, &devl_add->list);
+
+ } else if (dev1 != info->dev) {
+ log_debug_cache("PV %s with duplicates will change from %s to %s.",
+ pvid, dev_name(info->dev), dev_name(dev1));
+
/*
- * Move the preferred device from altdevs to add_cache_devs.
- * Create a del_cache_devs entry for the current lvmcache
- * device to drop.
+ * Move the preferred device (dev1) from altdevs
+ * to add_cache_devs. Create a del_cache_devs entry
+ * for the current lvmcache device to drop.
*/
- dm_list_move(add_cache_devs, &alt->list);
+ if (!(devl_add = _get_devl_in_device_list(dev1, &altdevs))) {
+ /* shouldn't happen */
+ log_error(INTERNAL_ERROR "PV %s with duplicates no alternate list entry for %s", pvid, dev_name(dev1));
+ dm_list_splice(&new_unused, &altdevs);
+ goto next;
+ }
- if ((del = zalloc(sizeof(*del)))) {
- del->dev = info->dev;
- dm_list_add(del_cache_devs, &del->list);
+ dm_list_move(add_cache_devs, &devl_add->list);
+
+ if ((devl_del = zalloc(sizeof(*devl_del)))) {
+ devl_del->dev = info->dev;
+ dm_list_add(del_cache_devs, &devl_del->list);
}
} else {
- log_debug_cache("PV %s: keeping current device %s.", dev1->pvid, dev_name(info->dev));
+ /*
+ * Keeping existing dev in lvmcache for this PVID.
+ */
+ log_debug_cache("PV %s with duplicates will continue using %s.",
+ pvid, dev_name(info->dev));
}
/*
- * alt devs not chosen are moved to _unused_duplicates.
+ * Any altdevs entries not chosen are moved to _unused_duplicates.
* del_cache_devs being dropped are moved to _unused_duplicates
* after being dropped. So, _unused_duplicates represents all
* duplicates not being used in lvmcache.
*/
dm_list_splice(&new_unused, &altdevs);
-
goto next;
}
@@ -795,9 +848,6 @@ static int _label_rescan_vg(struct cmd_context *cmd, const char *vgname, const c
if ((vginfo = lvmcache_vginfo_from_vgname(vgname, vgid)))
log_warn("VG info not dropped before rescan of %s", vgname);
- /* FIXME: should we also rescan unused_duplicate_devs for devs
- being rescanned here and then repeat resolving the duplicates? */
-
if (rw)
label_scan_devs_rw(cmd, cmd->filter, &devs);
else
@@ -873,9 +923,10 @@ int lvmcache_label_scan(struct cmd_context *cmd)
log_error("Scan failed to refresh device filter.");
/*
- * Duplicates found during this label scan are added to _initial_duplicates().
+ * Duplicates found during this label scan are added to _initial_duplicates.
*/
_destroy_device_list(&_initial_duplicates);
+ _destroy_device_list(&_unused_duplicates);
/*
* Do the actual scanning. This populates lvmcache
@@ -915,28 +966,19 @@ int lvmcache_label_scan(struct cmd_context *cmd)
_choose_duplicates(cmd, &del_cache_devs, &add_cache_devs);
dm_list_iterate_items(devl, &del_cache_devs) {
- log_debug_cache("Drop duplicate device %s in lvmcache", dev_name(devl->dev));
+ log_debug_cache("Dropping unchosen duplicate %s", dev_name(devl->dev));
if ((info = lvmcache_info_from_pvid(devl->dev->pvid, NULL, 0)))
lvmcache_del(info);
}
dm_list_iterate_items(devl, &add_cache_devs) {
- log_debug_cache("Rescan preferred device %s for lvmcache", dev_name(devl->dev));
+ log_debug_cache("Adding chosen duplicate %s", dev_name(devl->dev));
label_read(devl->dev);
}
dm_list_splice(&_unused_duplicates, &del_cache_devs);
- /*
- * This may remove some entries from the unused_duplicates list for
- * devs that we know are the same underlying dev.
- */
- _filter_duplicate_devs(cmd);
-
- /*
- * Warn about remaining duplicates that may actually be separate copies of
- * the same device.
- */
+ /* Warn about unused duplicates that the user might want to resolve. */
_warn_unused_duplicates(cmd);
}
@@ -1839,8 +1881,8 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller,
*/
if (!created) {
if (info->dev != dev) {
- log_debug_cache("PV %s on %s was already found on %s.",
- uuid, dev_name(dev), dev_name(info->dev));
+ log_debug_cache("Saving initial duplicate device %s previously seen on %s with PVID %s.",
+ dev_name(dev), dev_name(info->dev), uuid);
strncpy(dev->pvid, pvid_s, sizeof(dev->pvid));
@@ -1857,7 +1899,12 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller,
return_NULL;
devl->dev = dev;
- dm_list_add(&_initial_duplicates, &devl->list);
+ /* shouldn't happen */
+ if (dev_in_device_list(dev, &_initial_duplicates))
+ log_debug_cache("Initial duplicate already in list %s", dev_name(dev));
+ else
+ dm_list_add(&_initial_duplicates, &devl->list);
+
if (is_duplicate)
*is_duplicate = 1;
return NULL;
@@ -1865,8 +1912,8 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller,
if (info->dev->pvid[0] && pvid[0] && strcmp(pvid_s, info->dev->pvid)) {
/* This happens when running pvcreate on an existing PV. */
- log_verbose("Changing pvid on dev %s from %s to %s",
- dev_name(info->dev), info->dev->pvid, pvid_s);
+ log_debug_cache("Changing pvid on dev %s from %s to %s",
+ dev_name(info->dev), info->dev->pvid, pvid_s);
}
if (info->label->labeller != labeller) {
diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h
index c831d0e..89fbe6f 100644
--- a/lib/cache/lvmcache.h
+++ b/lib/cache/lvmcache.h
@@ -170,12 +170,14 @@ struct metadata_area *lvmcache_get_mda(struct cmd_context *cmd,
int use_mda_num);
bool lvmcache_has_duplicate_devs(void);
-int lvmcache_found_duplicate_vgnames(void);
-
+void lvmcache_del_dev_from_duplicates(struct device *dev);
+bool lvmcache_dev_is_unused_duplicate(struct device *dev);
+int lvmcache_pvid_in_unused_duplicates(const char *pvid);
int lvmcache_get_unused_duplicates(struct cmd_context *cmd, struct dm_list *head);
-
int vg_has_duplicate_pvs(struct volume_group *vg);
+int lvmcache_found_duplicate_vgnames(void);
+
int lvmcache_contains_lock_type_sanlock(struct cmd_context *cmd);
void lvmcache_get_max_name_lengths(struct cmd_context *cmd,
@@ -183,12 +185,6 @@ void lvmcache_get_max_name_lengths(struct cmd_context *cmd,
int lvmcache_vg_is_foreign(struct cmd_context *cmd, const char *vgname, const char *vgid);
-bool lvmcache_dev_is_unused_duplicate(struct device *dev);
-
-void lvmcache_del_dev_from_duplicates(struct device *dev);
-
-int lvmcache_pvid_in_unused_duplicates(const char *pvid);
-
bool lvmcache_scan_mismatch(struct cmd_context *cmd, const char *vgname, const char *vgid);
int lvmcache_vginfo_has_pvid(struct lvmcache_vginfo *vginfo, char *pvid);
diff --git a/lib/label/label.c b/lib/label/label.c
index 9454fc8..3c8e10c 100644
--- a/lib/label/label.c
+++ b/lib/label/label.c
@@ -441,7 +441,7 @@ static int _process_block(struct cmd_context *cmd, struct dev_filter *f,
* struct for this dev, but added this dev to the list
* of duplicate devs.
*/
- log_warn("WARNING: scan found duplicate PVID %s on %s", dev->pvid, dev_name(dev));
+ log_debug("label scan found duplicate PVID %s on %s", dev->pvid, dev_name(dev));
} else {
/*
* Leave the info in lvmcache because the device is
@@ -1117,9 +1117,10 @@ int label_scan(struct cmd_context *cmd)
log_debug_devs("Scanning end of PVs with no udev info for MD components");
if (dev_is_md_component(devl->dev, NULL, 1)) {
- log_debug_devs("Drop PV from MD component %s", dev_name(devl->dev));
+ log_debug_devs("Scan dropping PV from MD component %s", dev_name(devl->dev));
devl->dev->flags &= ~DEV_SCAN_FOUND_LABEL;
lvmcache_del_dev(devl->dev);
+ lvmcache_del_dev_from_duplicates(devl->dev);
}
}
}
4 years, 8 months
master - lvmcache: use devl list helper
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ee4a32e99224a0d4d21...
Commit: ee4a32e99224a0d4d2156c55d195e217967490b1
Parent: 96dfad50224e7e8d3168bd0db93452e819d052b5
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Aug 1 13:58:14 2019 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Aug 16 13:26:12 2019 -0500
lvmcache: use devl list helper
---
lib/cache/lvmcache.c | 41 +++++++++++++++++++++++++----------------
1 files changed, 25 insertions(+), 16 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index da83b84..f2503b2 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -116,6 +116,28 @@ void lvmcache_unlock_vgname(const char *vgname)
}
}
+static struct device_list *_get_devl_in_device_list(struct device *dev, struct dm_list *head)
+{
+ struct device_list *devl;
+
+ dm_list_iterate_items(devl, head) {
+ if (devl->dev == dev)
+ return devl;
+ }
+ return NULL;
+}
+
+int dev_in_device_list(struct device *dev, struct dm_list *head)
+{
+ struct device_list *devl;
+
+ dm_list_iterate_items(devl, head) {
+ if (devl->dev == dev)
+ return 1;
+ }
+ return 0;
+}
+
bool lvmcache_has_duplicate_devs(void)
{
if (dm_list_empty(&_unused_duplicates) && dm_list_empty(&_initial_duplicates))
@@ -147,11 +169,9 @@ void lvmcache_del_dev_from_duplicates(struct device *dev)
{
struct device_list *devl;
- dm_list_iterate_items(devl, &_unused_duplicates) {
- if (devl->dev == dev) {
- dm_list_del(&devl->list);
- return;
- }
+ if ((devl = _get_devl_in_device_list(dev, &_unused_duplicates))) {
+ log_debug_cache("delete dev from unused duplicates %s", dev_name(dev));
+ dm_list_del(&devl->list);
}
}
@@ -381,17 +401,6 @@ int vg_has_duplicate_pvs(struct volume_group *vg)
return 0;
}
-int dev_in_device_list(struct device *dev, struct dm_list *head)
-{
- struct device_list *devl;
-
- dm_list_iterate_items(devl, head) {
- if (devl->dev == dev)
- return 1;
- }
- return 0;
-}
-
bool lvmcache_dev_is_unused_duplicate(struct device *dev)
{
return dev_in_device_list(dev, &_unused_duplicates) ? true : false;
4 years, 8 months
master - lvmcache: replace found_duplicates variable
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=96dfad50224e7e8d316...
Commit: 96dfad50224e7e8d3168bd0db93452e819d052b5
Parent: 677833ce6fcd7596f8dd5857bde90610cd6500c7
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Aug 1 13:53:20 2019 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Aug 16 13:26:11 2019 -0500
lvmcache: replace found_duplicates variable
With just checking if the duplicates lists are empty.
---
lib/cache/lvmcache.c | 10 +++-------
1 files changed, 3 insertions(+), 7 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index 2634f07..da83b84 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -76,7 +76,6 @@ static DM_LIST_INIT(_initial_duplicates);
static DM_LIST_INIT(_unused_duplicates);
static DM_LIST_INIT(_prev_unused_duplicate_devs);
static int _vgs_locked = 0;
-static int _found_duplicate_pvs = 0; /* If we never see a duplicate PV we can skip checking for them later. */
static int _found_duplicate_vgnames = 0;
int lvmcache_init(struct cmd_context *cmd)
@@ -119,7 +118,9 @@ void lvmcache_unlock_vgname(const char *vgname)
bool lvmcache_has_duplicate_devs(void)
{
- return _found_duplicate_pvs ? true : false;
+ if (dm_list_empty(&_unused_duplicates) && dm_list_empty(&_initial_duplicates))
+ return false;
+ return true;
}
int lvmcache_found_duplicate_vgnames(void)
@@ -439,9 +440,6 @@ static void _filter_duplicate_devs(struct cmd_context *cmd)
free(devl);
}
}
-
- if (dm_list_empty(&_unused_duplicates))
- _found_duplicate_pvs = 0;
}
static void _warn_unused_duplicates(struct cmd_context *cmd)
@@ -1851,7 +1849,6 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller,
devl->dev = dev;
dm_list_add(&_initial_duplicates, &devl->list);
- _found_duplicate_pvs = 1;
if (is_duplicate)
*is_duplicate = 1;
return NULL;
@@ -1971,7 +1968,6 @@ void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans, int reset)
dm_list_splice(&_prev_unused_duplicate_devs, &_unused_duplicates);
_destroy_device_list(&_unused_duplicates);
_destroy_device_list(&_initial_duplicates); /* should be empty anyway */
- _found_duplicate_pvs = 0;
if (retain_orphans) {
struct format_type *fmt;
4 years, 8 months
master - lvmcache: renaming functions and variables
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=677833ce6fcd7596f8d...
Commit: 677833ce6fcd7596f8dd5857bde90610cd6500c7
Parent: 65bcd16be2cb46c73f6243e553b4a8685c159b7a
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Aug 1 13:50:04 2019 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Aug 16 13:26:11 2019 -0500
lvmcache: renaming functions and variables
related to duplicates, no functional changes.
---
lib/cache/lvmcache.c | 119 +++++++++++++++++++++--------------------------
lib/cache/lvmcache.h | 10 ++--
lib/label/hints.c | 8 ++--
lib/metadata/metadata.c | 2 +-
lib/metadata/pv.c | 2 +-
lib/report/report.c | 2 +-
tools/pvchange.c | 2 +-
tools/toollib.c | 14 +++---
8 files changed, 73 insertions(+), 86 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index e2d19e8..2634f07 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -72,8 +72,8 @@ static struct dm_hash_table *_pvid_hash = NULL;
static struct dm_hash_table *_vgid_hash = NULL;
static struct dm_hash_table *_vgname_hash = NULL;
static DM_LIST_INIT(_vginfos);
-static DM_LIST_INIT(_found_duplicate_devs);
-static DM_LIST_INIT(_unused_duplicate_devs);
+static DM_LIST_INIT(_initial_duplicates);
+static DM_LIST_INIT(_unused_duplicates);
static DM_LIST_INIT(_prev_unused_duplicate_devs);
static int _vgs_locked = 0;
static int _found_duplicate_pvs = 0; /* If we never see a duplicate PV we can skip checking for them later. */
@@ -88,8 +88,8 @@ int lvmcache_init(struct cmd_context *cmd)
_vgs_locked = 0;
dm_list_init(&_vginfos);
- dm_list_init(&_found_duplicate_devs);
- dm_list_init(&_unused_duplicate_devs);
+ dm_list_init(&_initial_duplicates);
+ dm_list_init(&_unused_duplicates);
dm_list_init(&_prev_unused_duplicate_devs);
if (!(_vgname_hash = dm_hash_create(128)))
@@ -117,22 +117,9 @@ void lvmcache_unlock_vgname(const char *vgname)
}
}
-/*
- * When lvmcache sees a duplicate PV, this is set.
- * process_each_pv() can avoid searching for duplicates
- * by checking this and seeing that no duplicate PVs exist.
- *
- *
- * found_duplicate_pvs tells the process_each_pv code
- * to search the devices list for duplicates, so that
- * devices can be processed together with their
- * duplicates (while processing the VG, rather than
- * reporting pv->dev under the VG, and its duplicate
- * outside the VG context.)
- */
-int lvmcache_found_duplicate_pvs(void)
+bool lvmcache_has_duplicate_devs(void)
{
- return _found_duplicate_pvs;
+ return _found_duplicate_pvs ? true : false;
}
int lvmcache_found_duplicate_vgnames(void)
@@ -140,11 +127,11 @@ int lvmcache_found_duplicate_vgnames(void)
return _found_duplicate_vgnames;
}
-int lvmcache_get_unused_duplicate_devs(struct cmd_context *cmd, struct dm_list *head)
+int lvmcache_get_unused_duplicates(struct cmd_context *cmd, struct dm_list *head)
{
struct device_list *devl, *devl2;
- dm_list_iterate_items(devl, &_unused_duplicate_devs) {
+ dm_list_iterate_items(devl, &_unused_duplicates) {
if (!(devl2 = dm_pool_alloc(cmd->mem, sizeof(*devl2)))) {
log_error("device_list element allocation failed");
return 0;
@@ -155,11 +142,11 @@ int lvmcache_get_unused_duplicate_devs(struct cmd_context *cmd, struct dm_list *
return 1;
}
-void lvmcache_remove_unchosen_duplicate(struct device *dev)
+void lvmcache_del_dev_from_duplicates(struct device *dev)
{
struct device_list *devl;
- dm_list_iterate_items(devl, &_unused_duplicate_devs) {
+ dm_list_iterate_items(devl, &_unused_duplicates) {
if (devl->dev == dev) {
dm_list_del(&devl->list);
return;
@@ -167,7 +154,7 @@ void lvmcache_remove_unchosen_duplicate(struct device *dev)
}
}
-static void _destroy_duplicate_device_list(struct dm_list *head)
+static void _destroy_device_list(struct dm_list *head)
{
struct device_list *devl, *devl2;
@@ -385,7 +372,7 @@ int vg_has_duplicate_pvs(struct volume_group *vg)
struct device_list *devl;
dm_list_iterate_items(pvl, &vg->pvs) {
- dm_list_iterate_items(devl, &_unused_duplicate_devs) {
+ dm_list_iterate_items(devl, &_unused_duplicates) {
if (id_equal(&pvl->pv->id, (const struct id *)devl->dev->pvid))
return 1;
}
@@ -404,9 +391,9 @@ int dev_in_device_list(struct device *dev, struct dm_list *head)
return 0;
}
-int lvmcache_dev_is_unchosen_duplicate(struct device *dev)
+bool lvmcache_dev_is_unused_duplicate(struct device *dev)
{
- return dev_in_device_list(dev, &_unused_duplicate_devs);
+ return dev_in_device_list(dev, &_unused_duplicates) ? true : false;
}
/*
@@ -441,7 +428,7 @@ static void _filter_duplicate_devs(struct cmd_context *cmd)
struct lvmcache_info *info;
struct device_list *devl, *devl2;
- dm_list_iterate_items_safe(devl, devl2, &_unused_duplicate_devs) {
+ dm_list_iterate_items_safe(devl, devl2, &_unused_duplicates) {
if (!(info = lvmcache_info_from_pvid(devl->dev->pvid, NULL, 0)))
continue;
@@ -453,24 +440,24 @@ static void _filter_duplicate_devs(struct cmd_context *cmd)
}
}
- if (dm_list_empty(&_unused_duplicate_devs))
+ if (dm_list_empty(&_unused_duplicates))
_found_duplicate_pvs = 0;
}
-static void _warn_duplicate_devs(struct cmd_context *cmd)
+static void _warn_unused_duplicates(struct cmd_context *cmd)
{
char uuid[64] __attribute__((aligned(8)));
struct lvmcache_info *info;
struct device_list *devl, *devl2;
- dm_list_iterate_items_safe(devl, devl2, &_unused_duplicate_devs) {
+ dm_list_iterate_items_safe(devl, devl2, &_unused_duplicates) {
if (!id_write_format((const struct id *)devl->dev->pvid, uuid, sizeof(uuid)))
stack;
log_warn("WARNING: Not using device %s for PV %s.", dev_name(devl->dev), uuid);
}
- dm_list_iterate_items_safe(devl, devl2, &_unused_duplicate_devs) {
+ dm_list_iterate_items_safe(devl, devl2, &_unused_duplicates) {
/* info for the preferred device that we're actually using */
if (!(info = lvmcache_info_from_pvid(devl->dev->pvid, NULL, 0)))
continue;
@@ -484,26 +471,26 @@ static void _warn_duplicate_devs(struct cmd_context *cmd)
}
/*
- * Compare _found_duplicate_devs entries with the corresponding duplicate dev
- * in lvmcache. There may be multiple duplicates in _found_duplicate_devs for
- * a given pvid. If a dev from _found_duplicate_devs is preferred over the dev
+ * Compare _initial_duplicates entries with the corresponding duplicate dev
+ * in lvmcache. There may be multiple duplicates in _initial_duplicates for
+ * a given pvid. If a dev from _initial_duplicates is preferred over the dev
* in lvmcache, then drop the dev in lvmcache and rescan the preferred dev to
* add it to lvmcache.
*
- * _found_duplicate_devs: duplicate devs found during initial scan.
+ * _initial_duplicates: duplicate devs found during initial scan.
* These are compared to lvmcache devs to see if any are preferred.
*
- * _unused_duplicate_devs: duplicate devs not chosen to be used.
- * These are _found_duplicate_devs entries that were not chosen,
+ * _unused_duplicates: duplicate devs not chosen to be used.
+ * These are _initial_duplicates entries that were not chosen,
* or unpreferred lvmcache devs that were dropped.
*
* del_cache_devs: devices to drop from lvmcache
* add_cache_devs: devices to scan to add to lvmcache
*/
-static void _choose_preferred_devs(struct cmd_context *cmd,
- struct dm_list *del_cache_devs,
- struct dm_list *add_cache_devs)
+static void _choose_duplicates(struct cmd_context *cmd,
+ struct dm_list *del_cache_devs,
+ struct dm_list *add_cache_devs)
{
const char *reason;
struct dm_list altdevs;
@@ -531,7 +518,7 @@ next:
dm_list_init(&altdevs);
alt = NULL;
- dm_list_iterate_items_safe(devl, devl_safe, &_found_duplicate_devs) {
+ dm_list_iterate_items_safe(devl, devl_safe, &_initial_duplicates) {
if (!alt) {
dm_list_move(&altdevs, &devl->list);
alt = devl;
@@ -542,8 +529,8 @@ next:
}
if (!alt) {
- _destroy_duplicate_device_list(&_unused_duplicate_devs);
- dm_list_splice(&_unused_duplicate_devs, &new_unused);
+ _destroy_device_list(&_unused_duplicates);
+ dm_list_splice(&_unused_duplicates, &new_unused);
return;
}
@@ -578,8 +565,8 @@ next:
continue;
}
- prev_unchosen1 = dev_in_device_list(dev1, &_unused_duplicate_devs);
- prev_unchosen2 = dev_in_device_list(dev2, &_unused_duplicate_devs);
+ prev_unchosen1 = dev_in_device_list(dev1, &_unused_duplicates);
+ prev_unchosen2 = dev_in_device_list(dev2, &_unused_duplicates);
if (!prev_unchosen1 && !prev_unchosen2) {
/*
@@ -732,9 +719,9 @@ next:
}
/*
- * alt devs not chosen are moved to _unused_duplicate_devs.
- * del_cache_devs being dropped are moved to _unused_duplicate_devs
- * after being dropped. So, _unused_duplicate_devs represents all
+ * alt devs not chosen are moved to _unused_duplicates.
+ * del_cache_devs being dropped are moved to _unused_duplicates
+ * after being dropped. So, _unused_duplicates represents all
* duplicates not being used in lvmcache.
*/
@@ -879,9 +866,9 @@ int lvmcache_label_scan(struct cmd_context *cmd)
log_error("Scan failed to refresh device filter.");
/*
- * Duplicates found during this label scan are added to _found_duplicate_devs().
+ * Duplicates found during this label scan are added to _initial_duplicates().
*/
- _destroy_duplicate_device_list(&_found_duplicate_devs);
+ _destroy_device_list(&_initial_duplicates);
/*
* Do the actual scanning. This populates lvmcache
@@ -895,7 +882,7 @@ int lvmcache_label_scan(struct cmd_context *cmd)
label_scan(cmd);
/*
- * _choose_preferred_devs() returns:
+ * _choose_duplicates() returns:
*
* . del_cache_devs: a list of devs currently in lvmcache that should
* be removed from lvmcache because they will be replaced with
@@ -909,16 +896,16 @@ int lvmcache_label_scan(struct cmd_context *cmd)
* the devs that are preferred to add them to lvmcache.
*
* Keep a complete list of all devs that are unused by moving the
- * del_cache_devs onto _unused_duplicate_devs.
+ * del_cache_devs onto _unused_duplicates.
*/
- if (!dm_list_empty(&_found_duplicate_devs)) {
+ if (!dm_list_empty(&_initial_duplicates)) {
dm_list_init(&del_cache_devs);
dm_list_init(&add_cache_devs);
log_debug_cache("Resolving duplicate devices");
- _choose_preferred_devs(cmd, &del_cache_devs, &add_cache_devs);
+ _choose_duplicates(cmd, &del_cache_devs, &add_cache_devs);
dm_list_iterate_items(devl, &del_cache_devs) {
log_debug_cache("Drop duplicate device %s in lvmcache", dev_name(devl->dev));
@@ -931,7 +918,7 @@ int lvmcache_label_scan(struct cmd_context *cmd)
label_read(devl->dev);
}
- dm_list_splice(&_unused_duplicate_devs, &del_cache_devs);
+ dm_list_splice(&_unused_duplicates, &del_cache_devs);
/*
* This may remove some entries from the unused_duplicates list for
@@ -943,7 +930,7 @@ int lvmcache_label_scan(struct cmd_context *cmd)
* Warn about remaining duplicates that may actually be separate copies of
* the same device.
*/
- _warn_duplicate_devs(cmd);
+ _warn_unused_duplicates(cmd);
}
r = 1;
@@ -1028,11 +1015,11 @@ struct device *lvmcache_device_from_pvid(struct cmd_context *cmd, const struct i
return NULL;
}
-int lvmcache_pvid_in_unchosen_duplicates(const char *pvid)
+int lvmcache_pvid_in_unused_duplicates(const char *pvid)
{
struct device_list *devl;
- dm_list_iterate_items(devl, &_unused_duplicate_devs) {
+ dm_list_iterate_items(devl, &_unused_duplicates) {
if (!strncmp(devl->dev->pvid, pvid, ID_LEN))
return 1;
}
@@ -1863,7 +1850,7 @@ struct lvmcache_info *lvmcache_add(struct labeller *labeller,
return_NULL;
devl->dev = dev;
- dm_list_add(&_found_duplicate_devs, &devl->list);
+ dm_list_add(&_initial_duplicates, &devl->list);
_found_duplicate_pvs = 1;
if (is_duplicate)
*is_duplicate = 1;
@@ -1971,8 +1958,8 @@ void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans, int reset)
dm_list_init(&_vginfos);
/*
- * Move the current _unused_duplicate_devs to _prev_unused_duplicate_devs
- * before destroying _unused_duplicate_devs.
+ * Move the current _unused_duplicates to _prev_unused_duplicate_devs
+ * before destroying _unused_duplicates.
*
* One command can init/populate/destroy lvmcache multiple times. Each
* time it will encounter duplicates and choose the preferrred devs.
@@ -1980,10 +1967,10 @@ void lvmcache_destroy(struct cmd_context *cmd, int retain_orphans, int reset)
* the unpreferred devs here so that _choose_preferred_devs can use
* this to make the same choice each time.
*/
- _destroy_duplicate_device_list(&_prev_unused_duplicate_devs);
- dm_list_splice(&_prev_unused_duplicate_devs, &_unused_duplicate_devs);
- _destroy_duplicate_device_list(&_unused_duplicate_devs);
- _destroy_duplicate_device_list(&_found_duplicate_devs); /* should be empty anyway */
+ _destroy_device_list(&_prev_unused_duplicate_devs);
+ dm_list_splice(&_prev_unused_duplicate_devs, &_unused_duplicates);
+ _destroy_device_list(&_unused_duplicates);
+ _destroy_device_list(&_initial_duplicates); /* should be empty anyway */
_found_duplicate_pvs = 0;
if (retain_orphans) {
diff --git a/lib/cache/lvmcache.h b/lib/cache/lvmcache.h
index e2d967c..c831d0e 100644
--- a/lib/cache/lvmcache.h
+++ b/lib/cache/lvmcache.h
@@ -169,10 +169,10 @@ struct metadata_area *lvmcache_get_mda(struct cmd_context *cmd,
struct device *dev,
int use_mda_num);
-int lvmcache_found_duplicate_pvs(void);
+bool lvmcache_has_duplicate_devs(void);
int lvmcache_found_duplicate_vgnames(void);
-int lvmcache_get_unused_duplicate_devs(struct cmd_context *cmd, struct dm_list *head);
+int lvmcache_get_unused_duplicates(struct cmd_context *cmd, struct dm_list *head);
int vg_has_duplicate_pvs(struct volume_group *vg);
@@ -183,11 +183,11 @@ void lvmcache_get_max_name_lengths(struct cmd_context *cmd,
int lvmcache_vg_is_foreign(struct cmd_context *cmd, const char *vgname, const char *vgid);
-int lvmcache_dev_is_unchosen_duplicate(struct device *dev);
+bool lvmcache_dev_is_unused_duplicate(struct device *dev);
-void lvmcache_remove_unchosen_duplicate(struct device *dev);
+void lvmcache_del_dev_from_duplicates(struct device *dev);
-int lvmcache_pvid_in_unchosen_duplicates(const char *pvid);
+int lvmcache_pvid_in_unused_duplicates(const char *pvid);
bool lvmcache_scan_mismatch(struct cmd_context *cmd, const char *vgname, const char *vgid);
diff --git a/lib/label/hints.c b/lib/label/hints.c
index 72dc91e..6de54bc 100644
--- a/lib/label/hints.c
+++ b/lib/label/hints.c
@@ -450,7 +450,7 @@ int validate_hints(struct cmd_context *cmd, struct dm_list *hints)
if (!cmd->use_hints && !cmd->pvscan_recreate_hints)
return 0;
- if (lvmcache_found_duplicate_pvs()) {
+ if (lvmcache_has_duplicate_devs()) {
log_debug("Hints not used with duplicate pvs");
ret = 0;
goto out;
@@ -820,7 +820,7 @@ int write_hint_file(struct cmd_context *cmd, int newhints)
if (!cmd->use_hints && !cmd->pvscan_recreate_hints)
return 0;
- if (lvmcache_found_duplicate_pvs() || lvmcache_found_duplicate_vgnames()) {
+ if (lvmcache_has_duplicate_devs() || lvmcache_found_duplicate_vgnames()) {
/*
* When newhints is EMPTY, it means get_hints() found an empty
* hint file. So we scanned all devs and found duplicate pvids
@@ -841,11 +841,11 @@ int write_hint_file(struct cmd_context *cmd, int newhints)
t = time(NULL);
- if (lvmcache_found_duplicate_pvs() || lvmcache_found_duplicate_vgnames()) {
+ if (lvmcache_has_duplicate_devs() || lvmcache_found_duplicate_vgnames()) {
fprintf(fp, "# Created empty by %s pid %d %s", cmd->name, getpid(), ctime(&t));
/* leave a comment about why it's empty in case someone is curious */
- if (lvmcache_found_duplicate_pvs())
+ if (lvmcache_has_duplicate_devs())
fprintf(fp, "# info: duplicate_pvs\n");
if (lvmcache_found_duplicate_vgnames())
fprintf(fp, "# info: duplicate_vgnames\n");
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 09000de..2c61bde 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -2962,7 +2962,7 @@ int vg_write(struct volume_group *vg)
return 0;
}
- if (lvmcache_found_duplicate_pvs() && vg_has_duplicate_pvs(vg) &&
+ if (lvmcache_has_duplicate_devs() && vg_has_duplicate_pvs(vg) &&
!find_config_tree_bool(vg->cmd, devices_allow_changes_with_duplicate_pvs_CFG, NULL)) {
log_error("Cannot update volume group %s with duplicate PV devices.",
vg->name);
diff --git a/lib/metadata/pv.c b/lib/metadata/pv.c
index 7b6f778..9cebbac 100644
--- a/lib/metadata/pv.c
+++ b/lib/metadata/pv.c
@@ -236,7 +236,7 @@ char *pv_attr_dup(struct dm_pool *mem, const struct physical_volume *pv)
{
char *repstr;
int used = is_used_pv(pv);
- int duplicate = lvmcache_dev_is_unchosen_duplicate(pv->dev);
+ int duplicate = lvmcache_dev_is_unused_duplicate(pv->dev);
if (!(repstr = dm_pool_zalloc(mem, 4))) {
log_error("dm_pool_alloc failed");
diff --git a/lib/report/report.c b/lib/report/report.c
index e1150f6..730b0af 100644
--- a/lib/report/report.c
+++ b/lib/report/report.c
@@ -3354,7 +3354,7 @@ static int _pvduplicate_disp(struct dm_report *rh, struct dm_pool *mem,
const void *data, void *private)
{
const struct physical_volume *pv = (const struct physical_volume *) data;
- int duplicate = lvmcache_dev_is_unchosen_duplicate(pv->dev);
+ int duplicate = lvmcache_dev_is_unused_duplicate(pv->dev);
return _binary_disp(rh, mem, field, duplicate, GET_FIRST_RESERVED_NAME(pv_duplicate_y), private);
}
diff --git a/tools/pvchange.c b/tools/pvchange.c
index 1ece34a..dd72bf1 100644
--- a/tools/pvchange.c
+++ b/tools/pvchange.c
@@ -40,7 +40,7 @@ static int _pvchange_single(struct cmd_context *cmd, struct volume_group *vg,
* to be copied here to prevent the pv_write() which is called before
* the vg_write().
*/
- if (vg && lvmcache_found_duplicate_pvs() && vg_has_duplicate_pvs(vg)) {
+ if (vg && lvmcache_has_duplicate_devs() && vg_has_duplicate_pvs(vg)) {
if (!find_config_tree_bool(vg->cmd, devices_allow_changes_with_duplicate_pvs_CFG, NULL)) {
log_error("Cannot update volume group %s with duplicate PV devices.",
vg->name);
diff --git a/tools/toollib.c b/tools/toollib.c
index 155528c..1f41feb 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -1048,7 +1048,7 @@ int lv_change_activate(struct cmd_context *cmd, struct logical_volume *lv,
}
if (is_change_activating(activate) &&
- lvmcache_found_duplicate_pvs() &&
+ lvmcache_has_duplicate_devs() &&
vg_has_duplicate_pvs(lv->vg) &&
!find_config_tree_bool(cmd, devices_allow_changes_with_duplicate_pvs_CFG, NULL)) {
log_error("Cannot activate LVs in VG %s while PVs appear on duplicate devices.",
@@ -1499,7 +1499,7 @@ int process_each_label(struct cmd_context *cmd, int argc, char **argv,
}
if (!(label = lvmcache_get_dev_label(dev))) {
- if (!lvmcache_dev_is_unchosen_duplicate(dev)) {
+ if (!lvmcache_dev_is_unused_duplicate(dev)) {
log_error("No physical volume label read from %s.", argv[opt]);
ret_max = ECMD_FAILED;
} else {
@@ -4089,7 +4089,7 @@ static int _process_duplicate_pvs(struct cmd_context *cmd,
dm_list_init(&unused_duplicate_devs);
- if (!lvmcache_get_unused_duplicate_devs(cmd, &unused_duplicate_devs))
+ if (!lvmcache_get_unused_duplicates(cmd, &unused_duplicate_devs))
return_ECMD_FAILED;
dm_list_iterate_items(devl, &unused_duplicate_devs) {
@@ -5016,7 +5016,7 @@ static int _pvcreate_check_single(struct cmd_context *cmd,
/*
* Don't allow using a device with duplicates.
*/
- if (lvmcache_pvid_in_unchosen_duplicates(pd->dev->pvid)) {
+ if (lvmcache_pvid_in_unused_duplicates(pd->dev->pvid)) {
log_error("Cannot use device %s with duplicates.", pd->name);
dm_list_move(&pp->arg_fail, &pd->list);
return 1;
@@ -5473,9 +5473,9 @@ int pvcreate_each_device(struct cmd_context *cmd,
* erase them below without going through the normal processing code.
*/
if (pp->is_remove && (pp->force == DONT_PROMPT_OVERRIDE) &&
- !dm_list_empty(&pp->arg_devices) && lvmcache_found_duplicate_pvs()) {
+ !dm_list_empty(&pp->arg_devices) && lvmcache_has_duplicate_devs()) {
dm_list_iterate_items_safe(pd, pd2, &pp->arg_devices) {
- if (lvmcache_dev_is_unchosen_duplicate(pd->dev)) {
+ if (lvmcache_dev_is_unused_duplicate(pd->dev)) {
log_debug("Found pvremove arg %s: device is a duplicate.", pd->name);
dm_list_move(&remove_duplicates, &pd->list);
}
@@ -5806,7 +5806,7 @@ do_command:
continue;
}
- lvmcache_remove_unchosen_duplicate(pd->dev);
+ lvmcache_del_dev_from_duplicates(pd->dev);
log_print_unless_silent("Labels on physical volume \"%s\" successfully wiped.",
pd->name);
4 years, 8 months
master - md component detection addition in vg_read
by David Teigland
Gitweb: https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=65bcd16be2cb46c73f6...
Commit: 65bcd16be2cb46c73f6243e553b4a8685c159b7a
Parent: ad560a286a0b5d08086324e6194b060c136e9353
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Thu Aug 1 14:43:19 2019 -0500
Committer: David Teigland <teigland(a)redhat.com>
CommitterDate: Fri Aug 16 13:24:34 2019 -0500
md component detection addition in vg_read
Usually md components are eliminated in label scan and/or
duplicate resolution, but they could sometimes get into
the vg_read stage, where set_pv_devices compares the
device to the PV.
If set_pv_devices runs an md component check and finds
one, vg_read should eliminate the components.
In set_pv_devices, run an md component check always
if the PV is smaller than the device (this is not
very common.) If the PV is larger than the device,
(more common), do the component check when the config
setting is "auto" (the default).
---
lib/format_text/archiver.c | 2 +-
lib/format_text/import.c | 2 +-
lib/metadata/metadata.c | 80 ++++++++++++++++++++++++++++++++++++--------
lib/metadata/metadata.h | 2 +-
tools/pvscan.c | 2 +-
5 files changed, 70 insertions(+), 18 deletions(-)
diff --git a/lib/format_text/archiver.c b/lib/format_text/archiver.c
index 052c2bd..3a741da 100644
--- a/lib/format_text/archiver.c
+++ b/lib/format_text/archiver.c
@@ -321,7 +321,7 @@ struct volume_group *backup_read_vg(struct cmd_context *cmd,
}
if (vg)
- set_pv_devices(tf, vg);
+ set_pv_devices(tf, vg, NULL);
if (!vg)
tf->fmt->ops->destroy_instance(tf);
diff --git a/lib/format_text/import.c b/lib/format_text/import.c
index 743077b..79276dd 100644
--- a/lib/format_text/import.c
+++ b/lib/format_text/import.c
@@ -230,7 +230,7 @@ static struct volume_group *_import_vg_from_config_tree(const struct dm_config_t
if (!(vg = (*vsn)->read_vg(fid, cft, allow_lvmetad_extensions)))
stack;
else {
- set_pv_devices(fid, vg);
+ set_pv_devices(fid, vg, NULL);
if ((vg_missing = vg_missing_pv_count(vg)))
log_verbose("There are %d physical volumes missing.", vg_missing);
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 0f5154d..09000de 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -3546,12 +3546,14 @@ bad:
*/
static void _set_pv_device(struct format_instance *fid,
struct volume_group *vg,
- struct physical_volume *pv)
+ struct physical_volume *pv,
+ int *found_md_component)
{
char buffer[64] __attribute__((aligned(8)));
struct cmd_context *cmd = fid->fmt->cmd;
struct device *dev;
uint64_t size;
+ int do_check = 0;
if (!(dev = lvmcache_device_from_pvid(cmd, &pv->id, &pv->label_sector))) {
if (!id_write_format(&pv->id, buffer, sizeof(buffer)))
@@ -3565,19 +3567,26 @@ static void _set_pv_device(struct format_instance *fid,
/*
* If the device and PV are not the size, it's a clue that we might
- * be reading an MD component (but not necessarily). Skip this check:
- * . if md component detection is disabled
- * . if we are already doing full a md check in label scan
- * . if md_component_checks is auto, not none (full means use_full_md_check is set)
+ * be reading an MD component (but not necessarily). Skip this check
+ * if md component detection is disabled or if we are already doing
+ * full a md check in label scan
*/
- if (dev && (pv->size != dev->size) && cmd &&
- cmd->md_component_detection &&
- !cmd->use_full_md_check &&
- !strcmp(cmd->md_component_checks, "auto")) {
- if (dev_is_md_component(dev, NULL, 1)) {
+ if (dev && cmd && cmd->md_component_detection && !cmd->use_full_md_check) {
+
+ /* PV larger than dev not common, check for md component */
+ if (pv->size > dev->size)
+ do_check = 1;
+
+ /* dev larger than PV can be common, limit check to auto mode */
+ else if ((pv->size < dev->size) && !strcmp(cmd->md_component_checks, "auto"))
+ do_check = 1;
+
+ if (do_check && dev_is_md_component(dev, NULL, 1)) {
log_warn("WARNING: device %s is an md component, not setting device for PV.",
dev_name(dev));
dev = NULL;
+ if (found_md_component)
+ *found_md_component = 1;
}
}
@@ -3622,12 +3631,12 @@ static void _set_pv_device(struct format_instance *fid,
* Finds the 'struct device' that correponds to each PV in the metadata,
* and may make some adjustments to vg fields based on the dev properties.
*/
-void set_pv_devices(struct format_instance *fid, struct volume_group *vg)
+void set_pv_devices(struct format_instance *fid, struct volume_group *vg, int *found_md_component)
{
struct pv_list *pvl;
dm_list_iterate_items(pvl, &vg->pvs)
- _set_pv_device(fid, vg, pvl->pv);
+ _set_pv_device(fid, vg, pvl->pv, found_md_component);
}
int pv_write(struct cmd_context *cmd,
@@ -4565,9 +4574,11 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
struct volume_group *vg, *vg_ret = NULL;
struct metadata_area *mda, *mda2;
unsigned use_precommitted = precommitted;
- struct device *mda_dev, *dev_ret;
+ struct device *mda_dev, *dev_ret, *dev;
struct cached_vg_fmtdata *vg_fmtdata = NULL; /* Additional format-specific data about the vg */
+ struct pv_list *pvl;
int found_old_metadata = 0;
+ int found_md_component = 0;
unsigned use_previous_vg;
log_debug_metadata("Reading VG %s %s", vgname ?: "<no name>", vgid ?: "<no vgid>");
@@ -4780,7 +4791,7 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
vg = NULL;
if (vg_ret)
- set_pv_devices(fid, vg_ret);
+ set_pv_devices(fid, vg_ret, &found_md_component);
fid->ref_count--;
@@ -4790,6 +4801,47 @@ static struct volume_group *_vg_read(struct cmd_context *cmd,
}
/*
+ * Usually md components are eliminated during label scan, or duplicate
+ * resolution, but sometimes an md component can get through and be
+ * detected in set_pv_device() (which will do an md component check if
+ * the device/PV sizes don't match.) In this case we need to fix up
+ * lvmcache to drop the component dev and fix up metadata_areas_in_use
+ * to drop it also.
+ */
+ if (found_md_component) {
+ dm_list_iterate_items(pvl, &vg_ret->pvs) {
+ if (!(dev = lvmcache_device_from_pvid(cmd, &pvl->pv->id, NULL)))
+ continue;
+
+ /* dev_is_md_component set this flag if it was found */
+ if (!(dev->flags & DEV_IS_MD_COMPONENT))
+ continue;
+
+ log_debug_metadata("Drop dev for MD component from cache %s", dev_name(dev));
+ lvmcache_del_dev(dev);
+
+ dm_list_iterate_items(mda, &fid->metadata_areas_in_use) {
+ if (mda_get_device(mda) != dev)
+ continue;
+ log_debug_metadata("Drop mda from MD component from mda list %s", dev_name(dev));
+ dm_list_del(&mda->list);
+ break;
+ }
+ }
+ }
+
+ /*
+ * After dropping MD components there may be no remaining legitimate
+ * devices for this VG.
+ */
+ if (!lvmcache_vginfo_from_vgid(vgid)) {
+ log_debug_metadata("VG %s not found on any remaining devices.", vgname);
+ release_vg(vg_ret);
+ vg_ret = NULL;
+ goto out;
+ }
+
+ /*
* Correct the lvmcache representation of the VG using the metadata
* that we have chosen above (vg_ret).
*
diff --git a/lib/metadata/metadata.h b/lib/metadata/metadata.h
index 2fc0015..6516e62 100644
--- a/lib/metadata/metadata.h
+++ b/lib/metadata/metadata.h
@@ -517,6 +517,6 @@ struct id pv_vgid(const struct physical_volume *pv);
uint64_t find_min_mda_size(struct dm_list *mdas);
char *tags_format_and_copy(struct dm_pool *mem, const struct dm_list *tagsl);
-void set_pv_devices(struct format_instance *fid, struct volume_group *vg);
+void set_pv_devices(struct format_instance *fid, struct volume_group *vg, int *found_md_component);
#endif
diff --git a/tools/pvscan.c b/tools/pvscan.c
index 2a88eaa..168d509 100644
--- a/tools/pvscan.c
+++ b/tools/pvscan.c
@@ -618,7 +618,7 @@ static int _online_pvscan_one(struct cmd_context *cmd, struct device *dev,
*pvid_without_metadata = dm_pool_strdup(cmd->mem, dev->pvid);
fmt->ops->destroy_instance(baton.fid);
} else {
- set_pv_devices(baton.fid, baton.vg);
+ set_pv_devices(baton.fid, baton.vg, NULL);
}
/* This check repeated because set_pv_devices can do new md check. */
4 years, 8 months