import lvm2-2.03.14-6.el8

This commit is contained in:
CentOS Sources 2022-11-08 02:03:39 -05:00 committed by Stepan Oksanichenko
parent 58231ff489
commit fb0d6e5158
57 changed files with 6282 additions and 138 deletions

View File

@ -1,7 +1,7 @@
From 63c4458aaf67d114c677baf657a7e9e43440f349 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Mon, 20 Dec 2021 14:22:02 -0600
Subject: [PATCH 01/23] Revert "new udev autoactivation"
Subject: [PATCH 01/54] Revert "new udev autoactivation"
This reverts commit 67722b312390cdab29c076c912e14bd739c5c0f6.
---
@ -541,5 +541,5 @@ index e777dda16..e32cba921 100644
DM_DIR=$(shell $(GREP) "\#define DM_DIR" $(top_srcdir)/libdm/misc/dm-ioctl.h | $(AWK) '{print $$3}')
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 2091305b796d5552fd991c527a0359a0b4d8fde0 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Mon, 20 Dec 2021 13:38:23 -0600
Subject: [PATCH 02/23] Revert "pvscan: only add device args to dev cache"
Subject: [PATCH 02/54] Revert "pvscan: only add device args to dev cache"
This reverts commit 33e47182f773c1a902b533580b63a803906de55d.
---
@ -446,5 +446,5 @@ index 95d593d57..8e2611361 100644
if (cmd->enable_devices_file && device_ids_use_devname(cmd)) {
relax_deviceid_filter = 1;
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From a5a2d5fa1ec47a5a548db4cf435dc84de7ce7c31 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Wed, 20 Oct 2021 16:12:41 -0500
Subject: [PATCH 03/23] pvscan: fix messages from coverity changes
Subject: [PATCH 03/54] pvscan: fix messages from coverity changes
---
tools/pvscan.c | 4 ++--
@ -30,5 +30,5 @@ index 8e2611361..f60c4a2ca 100644
continue;
}
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 074fce5c73c55e7a1547d5efff65a9f96e6db3b1 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Mon, 25 Oct 2021 12:11:17 -0500
Subject: [PATCH 04/23] vgimportdevices: skip lvmlockd locking
Subject: [PATCH 04/54] vgimportdevices: skip lvmlockd locking
Help bootstrapping existing shared vgs into the devices file.
Reading the vg in vgimportdevices would require locking to be
@ -35,5 +35,5 @@ index 3f315f98f..2580613c4 100644
* For each VG:
* device_id_add() each PV in the VG
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 00ebabfe6e1ebfceffcef335d44a6156a1c15418 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Mon, 1 Nov 2021 16:01:09 -0500
Subject: [PATCH 05/23] hints: remove the cmd hints list
Subject: [PATCH 05/54] hints: remove the cmd hints list
which is no longer used after commit
"toollib: remove all devices list from process_each_pv"
@ -91,5 +91,5 @@ index 3cd912270..479a5037a 100644
* Check if the devices_file content is up to date and
* if not update it.
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From f73be4480a5dd104a77e3ef84d7dcc80b834e593 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Tue, 2 Nov 2021 15:42:26 -0500
Subject: [PATCH 06/23] filter-sysfs: skip when device id is set
Subject: [PATCH 06/54] filter-sysfs: skip when device id is set
When a device id is set for a device, using an idtype other
than devname, it means that sysfs has been used with the device
@ -418,5 +418,5 @@ index 32ac324dd..672211057 100644
}
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From f732f3d53faee3732d0f4a666c378709e6c2f5e9 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Fri, 29 Oct 2021 14:49:36 -0500
Subject: [PATCH 07/23] lvmdevices: increase open file limit
Subject: [PATCH 07/54] lvmdevices: increase open file limit
---
lib/label/label.c | 4 ++--
@ -57,5 +57,5 @@ index 8d9634848..3f104f7de 100644
device_ids_match(cmd);
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From fad2b3dc8c44ba1222508ee78b5f161994efe638 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Tue, 9 Nov 2021 11:54:48 -0600
Subject: [PATCH 08/23] filter-sysfs: support old kernels without sys/dev/block
Subject: [PATCH 08/54] filter-sysfs: support old kernels without sys/dev/block
rhel5 for example doesn't have /sys/dev/block
---
@ -69,5 +69,5 @@ index 672211057..d8de7940b 100644
goto_bad;
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 459d931a9bfe4c9adcbbf2e76fdf35fda5b13c61 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Fri, 12 Nov 2021 16:42:51 -0600
Subject: [PATCH 09/23] device_id: match different dm device names
Subject: [PATCH 09/54] device_id: match different dm device names
If a devices file entry for a dm device is using the devname
for the device id, then recognize different dm names as matching.
@ -151,5 +151,5 @@ index eb06109ff..dea739fc4 100644
return 0;
}
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 5533cd7bf4c1edc5d8fb0e95d2f83b2b2d446339 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Tue, 16 Nov 2021 09:29:24 -0600
Subject: [PATCH 10/23] device_id: fix search on filtered device
Subject: [PATCH 10/54] device_id: fix search on filtered device
When devnames are used as device ids and devnames change,
then new devices need to be located for the PVs. If the old
@ -130,5 +130,5 @@ index f95be52b1..a99fe3e9a 100644
+
vgremove -ff $vg1
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 39adf3e513ac7b1cbbbf0189f973573ade3c8939 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Tue, 16 Nov 2021 11:26:41 -0600
Subject: [PATCH 11/23] device_id: searched_devnames improvements
Subject: [PATCH 11/54] device_id: searched_devnames improvements
Remove the searched_devnames file in a couple more places:
. When hints need refreshing it's possible that a missing
@ -98,5 +98,5 @@ index e444a0c82..3ce9634f2 100644
return 0;
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 9c9bf13186d387d807f279c112745768c8b32513 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Tue, 16 Nov 2021 14:21:07 -0600
Subject: [PATCH 12/23] tests pv-ext-flags: work with devices file
Subject: [PATCH 12/54] tests pv-ext-flags: work with devices file
---
test/shell/pv-ext-flags.sh | 4 ++++
@ -36,5 +36,5 @@ index 3e6bcff76..ae4d6b7ff 100644
# prepare a VG with $dev1 and $dev both having 1 MDA
aux enable_dev "$dev2"
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 594c1fec1644fdf291aa0ff23de20db65c4cfadf Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Wed, 17 Nov 2021 10:40:27 -0600
Subject: [PATCH 13/23] display: ignore --reportformat
Subject: [PATCH 13/54] display: ignore --reportformat
Using the option would do nothing useful but would
print extraneous braces.
@ -87,5 +87,5 @@ index 1e12bedca..1727ba089 100644
* Remaining position args after command name and --options are removed.
*/
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 7ac0b3c119b1cbb8e0b4969ece0b279637ace8c3 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Fri, 19 Nov 2021 12:02:35 -0600
Subject: [PATCH 14/23] fix spelling of pruning
Subject: [PATCH 14/54] fix spelling of pruning
---
lib/format_text/archive.c | 2 +-
@ -21,5 +21,5 @@ index 09a472b4c..2e8792a93 100644
}
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 25dbe3dd825a629ff7f67cb43342cc345071d3f7 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Wed, 24 Nov 2021 16:03:39 -0600
Subject: [PATCH 15/23] man: lvmautoactivation
Subject: [PATCH 15/54] man: lvmautoactivation
new topical man page describing autoactivation
---
@ -412,5 +412,5 @@ index b20b987da..4c5929955 100644
+.BR lvmautoactivation (7)
+for more information about how pvscan is used for autoactivation.
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 10a4478e9b778dd8d4ff9737a503474b00ce9510 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Wed, 1 Dec 2021 08:56:05 -0600
Subject: [PATCH 17/23] tests devicesfile-devname.sh drop mdadm chunk
Subject: [PATCH 17/54] tests devicesfile-devname.sh drop mdadm chunk
---
test/shell/devicesfile-devname.sh | 2 +-
@ -21,5 +21,5 @@ index a99fe3e9a..338637275 100644
sed -e "s|DEVNAME=$dev1|DEVNAME=$dev3|" "$ORIG" > tmp1.devices
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 04770589b49effdb064c9b3790e8dd2fee2c3547 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Wed, 1 Dec 2021 10:08:08 -0600
Subject: [PATCH 18/23] devices file: don't write in test mode
Subject: [PATCH 18/54] devices file: don't write in test mode
---
lib/device/device_id.c | 3 +++
@ -22,5 +22,5 @@ index ce7ded154..4c2b5a3dd 100644
if (sscanf(_devices_file_version, "%u.%u.%u", &df_major, &df_minor, &df_counter) != 3) {
/* don't update a file we can't parse */
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 604fd528fb4f00a9f77e084a1b22eff2aeef0259 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Thu, 2 Dec 2021 12:40:52 -0600
Subject: [PATCH 19/23] print warning about unrecognized journal option value
Subject: [PATCH 19/54] print warning about unrecognized journal option value
---
lib/log/log.c | 1 +
@ -20,5 +20,5 @@ index 7b4d537b3..5771a1d01 100644
}
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 357a807e81bbd1430b045eb2601a64b17d588400 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Thu, 2 Dec 2021 13:30:36 -0600
Subject: [PATCH 20/23] device_id: handle wwid with spaces or control
Subject: [PATCH 20/54] device_id: handle wwid with spaces or control
characters
non-standard wwid can be reported from sysfs with spaces/etc.
@ -46,5 +46,5 @@ index 4c2b5a3dd..0621bc858 100644
goto_bad;
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 7631c5b826b5a3eddfcd22db9b80574b249794c1 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Mon, 6 Dec 2021 13:20:32 -0600
Subject: [PATCH 21/23] man: add section about static autoactivation
Subject: [PATCH 21/54] man: add section about static autoactivation
---
man/lvmautoactivation.7_main | 48 ++++++++++++++++++++++++++++++------
@ -92,5 +92,5 @@ index 87c15a3d1..bf885991d 100644
.P
VG "vg" contains two PVs:
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From af4bfa1f1f84194000bc50f43ddc906c0cd4b104 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Mon, 13 Dec 2021 08:59:31 -0600
Subject: [PATCH 22/23] lvcreate: include recent options
Subject: [PATCH 22/54] lvcreate: include recent options
The permitted option list in lvcreate has not kept
up with command-lines.in.
@ -31,5 +31,5 @@ index 0121c09a8..79af42685 100644
permission_ARG,\
persistent_ARG,\
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 61833dd5b6117e8ace84289cff656d1dfb0ed123 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Tue, 14 Dec 2021 12:02:08 -0600
Subject: [PATCH 23/23] man lvmautoactivation: replace systemctl with
Subject: [PATCH 23/54] man lvmautoactivation: replace systemctl with
journalctl
---
@ -22,5 +22,5 @@ index bf885991d..54dab718b 100644
.
.SS pvscan options
--
2.31.1
2.34.3

View File

@ -1,7 +1,7 @@
From 4b26fb3543049f3d179b620ff937c44e922ada58 Mon Sep 17 00:00:00 2001
From: Marian Csontos <mcsontos@redhat.com>
Date: Tue, 4 Jan 2022 17:15:56 +0100
Subject: [PATCH] make: generate
Subject: [PATCH 24/54] make: generate
---
man/lvdisplay.8_pregen | 12 --------
@ -192,5 +192,5 @@ index 9c694921d..0a12b3c39 100644
.br
Select objects for processing and reporting based on specified criteria.
--
2.31.1
2.34.3

View File

@ -0,0 +1,141 @@
From a5c37afdca97d6565ea02bc4bc7d52f360823cd3 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Wed, 8 Sep 2021 16:30:11 -0500
Subject: [PATCH 25/54] pvcreate: overwrite partition header with -f
$ pvcreate /dev/sdc
Cannot use /dev/sdc: device is partitioned
$ pvcreate -f /dev/sdc
Physical volume "/dev/sdc" successfully created.
---
lib/commands/toolcontext.h | 1 +
lib/filters/filter-partitioned.c | 3 +++
man/pvcreate.8_des | 7 ++++---
test/shell/test-partition.sh | 12 ++++++++++--
tools/toollib.c | 10 ++++++++++
5 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index 356c79f8a..b83883fb8 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -201,6 +201,7 @@ struct cmd_context {
unsigned ignore_device_name_mismatch:1; /* skip updating devices file names */
unsigned backup_disabled:1; /* skip repeated debug message */
unsigned event_activation:1; /* whether event_activation is set */
+ unsigned filter_partitioned_skip:1; /* don't use filter-partitioned */
/*
* Devices and filtering.
diff --git a/lib/filters/filter-partitioned.c b/lib/filters/filter-partitioned.c
index 642553ef2..8f468a567 100644
--- a/lib/filters/filter-partitioned.c
+++ b/lib/filters/filter-partitioned.c
@@ -27,6 +27,9 @@ static int _passes_partitioned_filter(struct cmd_context *cmd, struct dev_filter
if (cmd->filter_nodata_only)
return 1;
+ if (cmd->filter_partitioned_skip)
+ return 1;
+
dev->filtered_flags &= ~DEV_FILTERED_PARTITIONED;
ret = dev_is_partitioned(cmd, dev);
diff --git a/man/pvcreate.8_des b/man/pvcreate.8_des
index 69bd133aa..4048eb71c 100644
--- a/man/pvcreate.8_des
+++ b/man/pvcreate.8_des
@@ -7,9 +7,10 @@ Use \fBvgcreate\fP(8) to create a new VG on the PV, or \fBvgextend\fP(8)
to add the PV to an existing VG. Use \fBpvremove\fP(8) to remove the LVM
disk label from the device.
.P
-The force option will create a PV without confirmation. Repeating the
-force option (\fB-ff\fP) will forcibly create a PV, overriding checks that
-normally prevent it, e.g. if the PV is already in a VG.
+The force option will create a PV without confirmation, and will overwrite
+partition headers. Repeating the force option (\fB-ff\fP) will override other
+checks that would normally prevent a pvcreate, e.g. if the PV is already in a
+VG.
.P
.B Metadata location, size, and alignment
.P
diff --git a/test/shell/test-partition.sh b/test/shell/test-partition.sh
index 0e92f00db..3a45f9089 100644
--- a/test/shell/test-partition.sh
+++ b/test/shell/test-partition.sh
@@ -16,7 +16,6 @@
#
-
SKIP_WITH_LVMPOLLD=1
LVM_TEST_CONFIG_DEVICES="types = [\"device-mapper\", 142]"
@@ -25,7 +24,7 @@ LVM_TEST_CONFIG_DEVICES="types = [\"device-mapper\", 142]"
which sfdisk || skip
-aux prepare_pvs 1 30
+aux prepare_pvs 2 30
pvs "$dev1"
@@ -33,3 +32,12 @@ pvs "$dev1"
echo "1 2" | sfdisk --force "$dev1"
not pvs "$dev1"
+
+wipefs -a "$dev2"
+echo "1 2" | sfdisk --force "$dev2"
+partprobe
+not pvcreate "$dev2"
+pvcreate -f "$dev2"
+pvs "$dev2"
+pvremove "$dev2"
+
diff --git a/tools/toollib.c b/tools/toollib.c
index d6f48aad2..80d3de57c 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -5243,6 +5243,10 @@ int pvcreate_each_device(struct cmd_context *cmd,
if (cmd->enable_devices_file && !pp->is_remove)
cmd->filter_deviceid_skip = 1;
+ /* pvcreate -f overwrites partitions */
+ if (pp->force && !pp->is_remove)
+ cmd->filter_partitioned_skip = 1;
+
log_debug("Scanning and filtering device args (%u).", dm_list_size(&scan_devs));
label_scan_devs(cmd, cmd->filter, &scan_devs);
@@ -5257,6 +5261,7 @@ int pvcreate_each_device(struct cmd_context *cmd,
}
}
cmd->filter_deviceid_skip = 0;
+ cmd->filter_partitioned_skip = 0;
/*
* Can the command continue if some specified devices were not found?
@@ -5469,6 +5474,9 @@ do_command:
if (cmd->enable_devices_file && !pp->is_remove)
cmd->filter_deviceid_skip = 1;
+ if (pp->force && !pp->is_remove)
+ cmd->filter_partitioned_skip = 1;
+
log_debug("Rescanning and filtering device args with exclusive open");
if (!label_scan_devs_excl(cmd, cmd->filter, &rescan_devs)) {
log_debug("Failed to rescan devs excl");
@@ -5482,7 +5490,9 @@ do_command:
dm_list_add(&pp->arg_fail, &pd->list);
}
}
+
cmd->filter_deviceid_skip = 0;
+ cmd->filter_partitioned_skip = 0;
if (dm_list_empty(&pp->arg_process) && dm_list_empty(&remove_duplicates)) {
log_debug("No devices to process.");
--
2.34.3

View File

@ -0,0 +1,166 @@
From bb477d63e336a10e5959962a9f26a028ea9e55eb Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Thu, 13 Jan 2022 14:52:54 -0600
Subject: [PATCH 26/54] lvmdevices check: error exit if update is needed
. error exit means that lvmdevices --update would make a change.
. remove check of PART field from --check because it isn't used.
. unlink searched_devnames file to ensure check|update will search
---
lib/device/device_id.c | 3 ++-
test/shell/devicesfile-realdevs.sh | 8 +++----
tools/args.h | 3 ++-
tools/lvmdevices.c | 37 +++++++++++++-----------------
4 files changed, 24 insertions(+), 27 deletions(-)
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index 0621bc858..a33dcebe0 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -2271,7 +2271,8 @@ void device_ids_find_renamed_devs(struct cmd_context *cmd, struct dm_list *dev_l
continue;
}
- log_warn("Devices file PVID %s updating IDNAME to %s.", dev->pvid, devname);
+ if (!noupdate)
+ log_warn("Devices file PVID %s updating IDNAME to %s.", dev->pvid, devname);
free(du->idname);
free(du->devname);
diff --git a/test/shell/devicesfile-realdevs.sh b/test/shell/devicesfile-realdevs.sh
index 8d4aa3e67..23d4bedb4 100644
--- a/test/shell/devicesfile-realdevs.sh
+++ b/test/shell/devicesfile-realdevs.sh
@@ -423,7 +423,7 @@ sed "s/$pvid1/badpvid/" "$DF.orig" |tee $DF
not grep $pvid1 $DF
grep $did1 $DF
-lvmdevices --check 2>&1|tee out
+not lvmdevices --check 2>&1|tee out
grep $dev1 out
grep badpvid out
grep $pvid1 out
@@ -493,7 +493,7 @@ rm $DF
d1=$(basename $dev1)
d3=$(basename $dev3)
sed "s/$d1/$d3/" "$DF.orig" |tee $DF
-lvmdevices --check 2>&1 |tee out
+not lvmdevices --check 2>&1 |tee out
grep $dev1 out
lvmdevices --update
@@ -515,7 +515,7 @@ sed "s/$d1/tmp/" "$DF.orig" |tee ${DF}_1
sed "s/$d2/$d1/" "${DF}_1" |tee ${DF}_2
sed "s/tmp/$d2/" "${DF}_2" |tee $DF
rm ${DF}_1 ${DF}_2
-lvmdevices --check 2>&1 |tee out
+not lvmdevices --check 2>&1 |tee out
grep $dev1 out
grep $dev2 out
@@ -536,7 +536,7 @@ rm $DF
d1=$(basename $dev1)
d3=$(basename $dev3)
sed "s/$d1/$d3/" "$DF.orig" |tee $DF
-lvmdevices --check 2>&1 |tee out
+not lvmdevices --check 2>&1 |tee out
grep $dev1 out
pvs -o+uuid,deviceid | grep $vg |tee out
diff --git a/tools/args.h b/tools/args.h
index 774ce33f4..9a7bf81b2 100644
--- a/tools/args.h
+++ b/tools/args.h
@@ -153,7 +153,8 @@ arg(cachesize_ARG, '\0', "cachesize", sizemb_VAL, 0, 0,
"The size of cache to use.\n")
arg(check_ARG, '\0', "check", 0, 0, 0,
- "Check the content of the devices file.\n")
+ "Checks the content of the devices file.\n"
+ "Reports incorrect device names or PVIDs for entries.\n")
arg(commandprofile_ARG, '\0', "commandprofile", string_VAL, 0, 0,
"The command profile to use for command configuration.\n"
diff --git a/tools/lvmdevices.c b/tools/lvmdevices.c
index 3f104f7de..c50c09f90 100644
--- a/tools/lvmdevices.c
+++ b/tools/lvmdevices.c
@@ -128,7 +128,6 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
struct device *dev;
struct dev_use *du, *du2;
const char *deviceidtype;
- int changes = 0;
dm_list_init(&search_pvids);
dm_list_init(&found_devs);
@@ -184,8 +183,11 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
if (arg_is_set(cmd, check_ARG) || arg_is_set(cmd, update_ARG)) {
int search_count = 0;
+ int update_needed = 0;
int invalid = 0;
+ unlink_searched_devnames(cmd);
+
label_scan_setup_bcache();
dm_list_iterate_items(du, &cmd->use_devices) {
@@ -225,6 +227,8 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
* run just above.
*/
device_ids_validate(cmd, NULL, &invalid, 1);
+ if (invalid)
+ update_needed = 1;
/*
* Find and fix any devname entries that have moved to a
@@ -240,33 +244,24 @@ int lvmdevices(struct cmd_context *cmd, int argc, char **argv)
label_scan_invalidate(du->dev);
}
- /*
- * check du->part
- */
- dm_list_iterate_items(du, &cmd->use_devices) {
- int part = 0;
- if (!du->dev)
- continue;
- dev = du->dev;
-
- dev_get_partition_number(dev, &part);
-
- if (part != du->part) {
- log_warn("Device %s partition %u has incorrect PART in devices file (%u)",
- dev_name(dev), part, du->part);
- du->part = part;
- changes++;
- }
- }
-
if (arg_is_set(cmd, update_ARG)) {
- if (invalid || !dm_list_empty(&found_devs)) {
+ if (update_needed || !dm_list_empty(&found_devs)) {
if (!device_ids_write(cmd))
goto_bad;
log_print("Updated devices file to version %s", devices_file_version());
} else {
log_print("No update for devices file is needed.");
}
+ } else {
+ /*
+ * --check exits with an error if the devices file
+ * needs updates, i.e. running --update would make
+ * changes.
+ */
+ if (update_needed) {
+ log_error("Updates needed for devices file.");
+ goto bad;
+ }
}
goto out;
}
--
2.34.3

View File

@ -0,0 +1,140 @@
From 9375aebad1db72267dd67e3ed768aa3b0e698d52 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Tue, 18 Jan 2022 12:16:52 -0600
Subject: [PATCH 27/54] Revert "pvcreate: overwrite partition header with -f"
This reverts commit a5c37afdca97d6565ea02bc4bc7d52f360823cd3.
This commit did not properly recognize GPT cases.
---
lib/commands/toolcontext.h | 1 -
lib/filters/filter-partitioned.c | 3 ---
man/pvcreate.8_des | 7 +++----
test/shell/test-partition.sh | 12 ++----------
tools/toollib.c | 10 ----------
5 files changed, 5 insertions(+), 28 deletions(-)
diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h
index b83883fb8..356c79f8a 100644
--- a/lib/commands/toolcontext.h
+++ b/lib/commands/toolcontext.h
@@ -201,7 +201,6 @@ struct cmd_context {
unsigned ignore_device_name_mismatch:1; /* skip updating devices file names */
unsigned backup_disabled:1; /* skip repeated debug message */
unsigned event_activation:1; /* whether event_activation is set */
- unsigned filter_partitioned_skip:1; /* don't use filter-partitioned */
/*
* Devices and filtering.
diff --git a/lib/filters/filter-partitioned.c b/lib/filters/filter-partitioned.c
index 8f468a567..642553ef2 100644
--- a/lib/filters/filter-partitioned.c
+++ b/lib/filters/filter-partitioned.c
@@ -27,9 +27,6 @@ static int _passes_partitioned_filter(struct cmd_context *cmd, struct dev_filter
if (cmd->filter_nodata_only)
return 1;
- if (cmd->filter_partitioned_skip)
- return 1;
-
dev->filtered_flags &= ~DEV_FILTERED_PARTITIONED;
ret = dev_is_partitioned(cmd, dev);
diff --git a/man/pvcreate.8_des b/man/pvcreate.8_des
index 4048eb71c..69bd133aa 100644
--- a/man/pvcreate.8_des
+++ b/man/pvcreate.8_des
@@ -7,10 +7,9 @@ Use \fBvgcreate\fP(8) to create a new VG on the PV, or \fBvgextend\fP(8)
to add the PV to an existing VG. Use \fBpvremove\fP(8) to remove the LVM
disk label from the device.
.P
-The force option will create a PV without confirmation, and will overwrite
-partition headers. Repeating the force option (\fB-ff\fP) will override other
-checks that would normally prevent a pvcreate, e.g. if the PV is already in a
-VG.
+The force option will create a PV without confirmation. Repeating the
+force option (\fB-ff\fP) will forcibly create a PV, overriding checks that
+normally prevent it, e.g. if the PV is already in a VG.
.P
.B Metadata location, size, and alignment
.P
diff --git a/test/shell/test-partition.sh b/test/shell/test-partition.sh
index 3a45f9089..0e92f00db 100644
--- a/test/shell/test-partition.sh
+++ b/test/shell/test-partition.sh
@@ -16,6 +16,7 @@
#
+
SKIP_WITH_LVMPOLLD=1
LVM_TEST_CONFIG_DEVICES="types = [\"device-mapper\", 142]"
@@ -24,7 +25,7 @@ LVM_TEST_CONFIG_DEVICES="types = [\"device-mapper\", 142]"
which sfdisk || skip
-aux prepare_pvs 2 30
+aux prepare_pvs 1 30
pvs "$dev1"
@@ -32,12 +33,3 @@ pvs "$dev1"
echo "1 2" | sfdisk --force "$dev1"
not pvs "$dev1"
-
-wipefs -a "$dev2"
-echo "1 2" | sfdisk --force "$dev2"
-partprobe
-not pvcreate "$dev2"
-pvcreate -f "$dev2"
-pvs "$dev2"
-pvremove "$dev2"
-
diff --git a/tools/toollib.c b/tools/toollib.c
index 80d3de57c..d6f48aad2 100644
--- a/tools/toollib.c
+++ b/tools/toollib.c
@@ -5243,10 +5243,6 @@ int pvcreate_each_device(struct cmd_context *cmd,
if (cmd->enable_devices_file && !pp->is_remove)
cmd->filter_deviceid_skip = 1;
- /* pvcreate -f overwrites partitions */
- if (pp->force && !pp->is_remove)
- cmd->filter_partitioned_skip = 1;
-
log_debug("Scanning and filtering device args (%u).", dm_list_size(&scan_devs));
label_scan_devs(cmd, cmd->filter, &scan_devs);
@@ -5261,7 +5257,6 @@ int pvcreate_each_device(struct cmd_context *cmd,
}
}
cmd->filter_deviceid_skip = 0;
- cmd->filter_partitioned_skip = 0;
/*
* Can the command continue if some specified devices were not found?
@@ -5474,9 +5469,6 @@ do_command:
if (cmd->enable_devices_file && !pp->is_remove)
cmd->filter_deviceid_skip = 1;
- if (pp->force && !pp->is_remove)
- cmd->filter_partitioned_skip = 1;
-
log_debug("Rescanning and filtering device args with exclusive open");
if (!label_scan_devs_excl(cmd, cmd->filter, &rescan_devs)) {
log_debug("Failed to rescan devs excl");
@@ -5490,9 +5482,7 @@ do_command:
dm_list_add(&pp->arg_fail, &pd->list);
}
}
-
cmd->filter_deviceid_skip = 0;
- cmd->filter_partitioned_skip = 0;
if (dm_list_empty(&pp->arg_process) && dm_list_empty(&remove_duplicates)) {
log_debug("No devices to process.");
--
2.34.3

View File

@ -0,0 +1,462 @@
From 5403a6f05987b21addb50c9b056e36567d631df7 Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Wed, 17 Nov 2021 17:10:45 -0600
Subject: [PATCH 28/54] devices: exclude multipath components based on matching
wwid
If multipath component devices get through the filter and
cause lvm to see duplicate PVs, then check the wwid of the
devs and drop the component devices as if they had been
filtered. If a dm mpath device was found among the duplicates
then use that as the PV, otherwise do not use any of the
components as the PV.
"duplicate PVs" associated with multipath configs will no
longer stop commands from working.
---
lib/cache/lvmcache.c | 186 +++++++++++++++++++++++++-
lib/device/dev-mpath.c | 71 ++++++++++
lib/device/dev-type.h | 2 +
lib/device/device_id.c | 4 +-
lib/device/device_id.h | 2 +
test/shell/duplicate-pvs-multipath.sh | 67 ++++++++++
6 files changed, 323 insertions(+), 9 deletions(-)
create mode 100644 test/shell/duplicate-pvs-multipath.sh
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index bee63ebb4..a0811d4ea 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -625,6 +625,102 @@ static void _warn_unused_duplicates(struct cmd_context *cmd)
}
}
+static int _all_multipath_components(struct cmd_context *cmd, struct lvmcache_info *info, const char *pvid,
+ struct dm_list *altdevs, struct device **dev_mpath)
+{
+ struct device_list *devl;
+ struct device *dev_mp = NULL;
+ struct device *dev1 = NULL;
+ struct device *dev;
+ const char *wwid1 = NULL;
+ const char *wwid;
+ int diff_wwid = 0;
+ int same_wwid = 0;
+ int dev_is_mp;
+
+ *dev_mpath = NULL;
+
+ /* This function only makes sense with more than one dev. */
+ if ((info && dm_list_empty(altdevs)) || (!info && (dm_list_size(altdevs) == 1))) {
+ log_debug("Skip multipath component checks with single device for PVID %s", pvid);
+ return 0;
+ }
+
+ log_debug("Checking for multipath components for duplicate PVID %s", pvid);
+
+ if (info) {
+ dev = info->dev;
+ dev_is_mp = (cmd->dev_types->device_mapper_major == MAJOR(dev->dev)) && dev_has_mpath_uuid(cmd, dev, NULL);
+
+ if (dev_is_mp) {
+ if ((wwid1 = dev_mpath_component_wwid(cmd, dev))) {
+ dev_mp = dev;
+ dev1 = dev;
+ }
+ } else {
+ if ((wwid1 = device_id_system_read(cmd, dev, DEV_ID_TYPE_SYS_WWID)))
+ dev1 = dev;
+ }
+ }
+
+ dm_list_iterate_items(devl, altdevs) {
+ dev = devl->dev;
+ dev_is_mp = (cmd->dev_types->device_mapper_major == MAJOR(dev->dev)) && dev_has_mpath_uuid(cmd, dev, NULL);
+
+ if (dev_is_mp)
+ wwid = dev_mpath_component_wwid(cmd, dev);
+ else
+ wwid = device_id_system_read(cmd, dev, DEV_ID_TYPE_SYS_WWID);
+
+ if (!wwid && wwid1) {
+ log_print("Different wwids for duplicate PVs %s %s %s none",
+ dev_name(dev1), wwid1, dev_name(dev));
+ diff_wwid++;
+ continue;
+ }
+
+ if (!wwid)
+ continue;
+
+ if (!wwid1) {
+ wwid1 = wwid;
+ dev1 = dev;
+ continue;
+ }
+
+ /* Different wwids indicates these are not multipath components. */
+ if (strcmp(wwid1, wwid)) {
+ log_print("Different wwids for duplicate PVs %s %s %s %s",
+ dev_name(dev1), wwid1, dev_name(dev), wwid);
+ diff_wwid++;
+ continue;
+ }
+
+ /* Different mpath devs with the same wwid shouldn't happen. */
+ if (dev_is_mp && dev_mp) {
+ log_print("Found multiple multipath devices for PVID %s WWID %s: %s %s",
+ pvid, wwid1, dev_name(dev_mp), dev_name(dev));
+ continue;
+ }
+
+ log_debug("Same wwids for duplicate PVs %s %s", dev_name(dev1), dev_name(dev));
+ same_wwid++;
+
+ /* Save the mpath device so it can be used as the PV. */
+ if (dev_is_mp)
+ dev_mp = dev;
+ }
+
+ if (diff_wwid || !same_wwid)
+ return 0;
+
+ if (dev_mp)
+ log_debug("Found multipath device %s for PVID %s WWID %s.", dev_name(dev_mp), pvid, wwid1);
+
+ *dev_mpath = dev_mp;
+ return 1;
+}
+
/*
* If we've found devices with the same PVID, decide which one
* to use.
@@ -680,6 +776,8 @@ static void _choose_duplicates(struct cmd_context *cmd,
struct device_list *devl, *devl_safe, *devl_add, *devl_del;
struct lvmcache_info *info;
struct device *dev1, *dev2;
+ struct device *dev_mpath;
+ struct device *dev_drop;
const char *device_id = NULL, *device_id_type = NULL;
const char *idname1 = NULL, *idname2 = NULL;
uint32_t dev1_major, dev1_minor, dev2_major, dev2_minor;
@@ -702,6 +800,7 @@ static void _choose_duplicates(struct cmd_context *cmd,
next:
dm_list_init(&altdevs);
pvid = NULL;
+ dev_mpath = NULL;
dm_list_iterate_items_safe(devl, devl_safe, &_initial_duplicates) {
if (!pvid) {
@@ -720,23 +819,97 @@ next:
return;
}
+ info = lvmcache_info_from_pvid(pvid, NULL, 0);
+
/*
- * 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.)
+ * Usually and ideally, components of md and multipath devs should have
+ * been excluded by filters, and not scanned for a PV. In some unusual
+ * cases the components can get through the filters, and a PV can be
+ * found on them. Detecting the same PVID on both the component and
+ * the md/mpath device gives us a last chance to drop the component.
+ * An md/mpath component device is completely ignored, as if it had
+ * been filtered, and not kept in the list unused duplicates.
*/
- info = lvmcache_info_from_pvid(pvid, NULL, 0);
+ /*
+ * Get rid of multipath components based on matching wwids.
+ */
+ if (_all_multipath_components(cmd, info, pvid, &altdevs, &dev_mpath)) {
+ if (info && dev_mpath && (info->dev != dev_mpath)) {
+ /*
+ * info should be dropped from lvmcache and info->dev
+ * should be treated as if it had been excluded by a filter.
+ * dev_mpath should be added to lvmcache by the caller.
+ */
+ dev_drop = info->dev;
+
+ /* Have caller add dev_mpath to lvmcache. */
+ log_debug("Using multipath device %s for PVID %s.", dev_name(dev_mpath), pvid);
+ if ((devl_add = zalloc(sizeof(*devl_add)))) {
+ devl_add->dev = dev_mpath;
+ dm_list_add(add_cache_devs, &devl_add->list);
+ }
+
+ /* Remove dev_mpath from altdevs. */
+ if ((devl = _get_devl_in_device_list(dev_mpath, &altdevs)))
+ dm_list_del(&devl->list);
+
+ /* Remove info from lvmcache that came from the component dev. */
+ log_debug("Ignoring multipath component %s with PVID %s (dropping info)", dev_name(dev_drop), pvid);
+ lvmcache_del(info);
+ info = NULL;
+
+ /* Make the component dev look like it was filtered. */
+ cmd->filter->wipe(cmd, cmd->filter, dev_drop, NULL);
+ dev_drop->flags &= ~DEV_SCAN_FOUND_LABEL;
+ }
+
+ if (info && !dev_mpath) {
+ /*
+ * Only mpath component devs were found and no actual
+ * multipath dev, so drop the component from lvmcache.
+ */
+ dev_drop = info->dev;
+
+ log_debug("Ignoring multipath component %s with PVID %s (dropping info)", dev_name(dev_drop), pvid);
+ lvmcache_del(info);
+ info = NULL;
+
+ /* Make the component dev look like it was filtered. */
+ cmd->filter->wipe(cmd, cmd->filter, dev_drop, NULL);
+ dev_drop->flags &= ~DEV_SCAN_FOUND_LABEL;
+ }
+
+ dm_list_iterate_items_safe(devl, devl_safe, &altdevs) {
+ /*
+ * The altdevs are all mpath components that should look
+ * like they were filtered, they are not in lvmcache.
+ */
+ dev_drop = devl->dev;
+
+ log_debug("Ignoring multipath component %s with PVID %s (dropping duplicate)", dev_name(dev_drop), pvid);
+ dm_list_del(&devl->list);
+
+ cmd->filter->wipe(cmd, cmd->filter, dev_drop, NULL);
+ dev_drop->flags &= ~DEV_SCAN_FOUND_LABEL;
+ }
+ goto next;
+ }
+
+ /*
+ * Get rid of any md components.
+ * FIXME: use a function like _all_multipath_components to pick the actual md device.
+ */
if (info && dev_is_md_component(cmd, 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));
+ log_debug("Ignoring md component %s with PVID %s (dropping info)", dev_name(info->dev), pvid);
lvmcache_del(info);
info = NULL;
}
dm_list_iterate_items_safe(devl, devl_safe, &altdevs) {
if (dev_is_md_component(cmd, devl->dev, NULL, 1)) {
- log_debug_cache("PV %s drop MD component from scan duplicates %s", pvid, dev_name(devl->dev));
+ log_debug("Ignoring md component %s with PVID %s (dropping duplicate)", dev_name(devl->dev), pvid);
dm_list_del(&devl->list);
}
}
@@ -744,7 +917,6 @@ next:
if (dm_list_empty(&altdevs))
goto next;
-
/*
* Find the device for the pvid that's currently in lvmcache.
*/
diff --git a/lib/device/dev-mpath.c b/lib/device/dev-mpath.c
index ba7bf9740..cbbad9dc9 100644
--- a/lib/device/dev-mpath.c
+++ b/lib/device/dev-mpath.c
@@ -482,3 +482,74 @@ found:
return 1;
}
+const char *dev_mpath_component_wwid(struct cmd_context *cmd, struct device *dev)
+{
+ char slaves_path[PATH_MAX];
+ char wwid_path[PATH_MAX];
+ char sysbuf[PATH_MAX] = { 0 };
+ char *slave_name;
+ const char *wwid = NULL;
+ struct stat info;
+ DIR *dr;
+ struct dirent *de;
+
+ /* /sys/dev/block/253:7/slaves/sda/device/wwid */
+
+ if (dm_snprintf(slaves_path, sizeof(slaves_path), "%s/dev/block/%d:%d/slaves",
+ dm_sysfs_dir(), (int)MAJOR(dev->dev), (int)MINOR(dev->dev)) < 0) {
+ log_warn("Sysfs path to check mpath components is too long.");
+ return NULL;
+ }
+
+ if (stat(slaves_path, &info))
+ return NULL;
+
+ if (!S_ISDIR(info.st_mode)) {
+ log_warn("Path %s is not a directory.", slaves_path);
+ return NULL;
+ }
+
+ /* Get wwid from first component */
+
+ if (!(dr = opendir(slaves_path))) {
+ log_debug("Device %s has no slaves dir", dev_name(dev));
+ return NULL;
+ }
+
+ while ((de = readdir(dr))) {
+ if (!strcmp(de->d_name, ".") || !strcmp(de->d_name, ".."))
+ continue;
+
+ /* slave_name "sda" */
+ slave_name = de->d_name;
+
+ /* read /sys/block/sda/device/wwid */
+
+ if (dm_snprintf(wwid_path, sizeof(wwid_path), "%s/block/%s/device/wwid",
+ dm_sysfs_dir(), slave_name) < 0) {
+ log_warn("Failed to create sysfs wwid path for %s", slave_name);
+ continue;
+ }
+
+ get_sysfs_value(wwid_path, sysbuf, sizeof(sysbuf), 0);
+ if (!sysbuf[0])
+ continue;
+
+ if (strstr(sysbuf, "scsi_debug")) {
+ int i;
+ for (i = 0; i < strlen(sysbuf); i++) {
+ if (sysbuf[i] == ' ')
+ sysbuf[i] = '_';
+ }
+ }
+
+ if ((wwid = dm_pool_strdup(cmd->mem, sysbuf)))
+ break;
+ }
+ if (closedir(dr))
+ stack;
+
+ return wwid;
+}
+
+
diff --git a/lib/device/dev-type.h b/lib/device/dev-type.h
index f3521c6e0..36fb8f258 100644
--- a/lib/device/dev-type.h
+++ b/lib/device/dev-type.h
@@ -63,6 +63,8 @@ int dev_is_swap(struct cmd_context *cmd, struct device *dev, uint64_t *signature
int dev_is_luks(struct cmd_context *cmd, struct device *dev, uint64_t *signature, int full);
int dasd_is_cdl_formatted(struct device *dev);
+const char *dev_mpath_component_wwid(struct cmd_context *cmd, struct device *dev);
+
int dev_is_lvm1(struct device *dev, char *buf, int buflen);
int dev_is_pool(struct device *dev, char *buf, int buflen);
diff --git a/lib/device/device_id.c b/lib/device/device_id.c
index a33dcebe0..625576ec6 100644
--- a/lib/device/device_id.c
+++ b/lib/device/device_id.c
@@ -243,7 +243,7 @@ static int _dm_uuid_has_prefix(char *sysbuf, const char *prefix)
}
/* the dm uuid uses the wwid of the underlying dev */
-static int _dev_has_mpath_uuid(struct cmd_context *cmd, struct device *dev, const char **idname_out)
+int dev_has_mpath_uuid(struct cmd_context *cmd, struct device *dev, const char **idname_out)
{
char sysbuf[PATH_MAX] = { 0 };
const char *idname;
@@ -988,7 +988,7 @@ int device_id_add(struct cmd_context *cmd, struct device *dev, const char *pvid_
}
if (MAJOR(dev->dev) == cmd->dev_types->device_mapper_major) {
- if (_dev_has_mpath_uuid(cmd, dev, &idname)) {
+ if (dev_has_mpath_uuid(cmd, dev, &idname)) {
idtype = DEV_ID_TYPE_MPATH_UUID;
goto id_done;
}
diff --git a/lib/device/device_id.h b/lib/device/device_id.h
index 939b3a0f4..4cf1374c8 100644
--- a/lib/device/device_id.h
+++ b/lib/device/device_id.h
@@ -55,4 +55,6 @@ void unlink_searched_devnames(struct cmd_context *cmd);
int read_sys_block(struct cmd_context *cmd, struct device *dev, const char *suffix, char *sysbuf, int sysbufsize);
+int dev_has_mpath_uuid(struct cmd_context *cmd, struct device *dev, const char **idname_out);
+
#endif
diff --git a/test/shell/duplicate-pvs-multipath.sh b/test/shell/duplicate-pvs-multipath.sh
new file mode 100644
index 000000000..a145e4afb
--- /dev/null
+++ b/test/shell/duplicate-pvs-multipath.sh
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+
+# Copyright (C) 2021 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions
+# of the GNU General Public License v.2.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+test_description='udev rule and systemd unit run vgchange'
+
+SKIP_WITH_LVMPOLLD=1
+SKIP_WITH_LVMLOCKD=1
+
+. lib/inittest
+
+# FIXME: skip until mpath/scsi_debug cleanup works after a failure
+skip
+
+modprobe --dry-run scsi_debug || skip
+multipath -l || skip
+multipath -l | grep scsi_debug && skip
+
+# Turn off multipath_component_detection so that the duplicate
+# resolution of mpath components is used.
+aux lvmconf 'devices/multipath_component_detection = 0'
+# Prevent wwids from being used for filtering.
+aux lvmconf 'devices/multipath_wwids_file = "/dev/null"'
+# Need to use /dev/mapper/mpath
+aux lvmconf 'devices/dir = "/dev"'
+aux lvmconf 'devices/scan = "/dev"'
+# Could set filter to $MP and the component /dev/sd devs
+aux lvmconf "devices/filter = [ \"a|.*|\" ]"
+aux lvmconf "devices/global_filter = [ \"a|.*|\" ]"
+
+modprobe scsi_debug dev_size_mb=100 num_tgts=1 vpd_use_hostno=0 add_host=4 delay=20 max_luns=2 no_lun_0=1
+sleep 2
+
+multipath -r
+sleep 2
+
+MPB=$(multipath -l | grep scsi_debug | cut -f1 -d ' ')
+echo $MPB
+MP=/dev/mapper/$MPB
+echo $MP
+
+pvcreate $MP
+vgcreate $vg1 $MP
+lvcreate -l1 $vg1
+vgchange -an $vg1
+
+pvs |tee out
+grep $MP out
+for i in $(grep -H scsi_debug /sys/block/sd*/device/model | cut -f4 -d /); do
+ not grep /dev/$i out;
+done
+
+vgchange -an $vg1
+vgremove -y $vg1
+
+sleep 2
+multipath -f $MP
+sleep 1
+rmmod scsi_debug
--
2.34.3

View File

@ -0,0 +1,268 @@
From 7b79acc6161b2cff81a03848c160dd6993a4477b Mon Sep 17 00:00:00 2001
From: David Teigland <teigland@redhat.com>
Date: Mon, 22 Nov 2021 15:10:43 -0600
Subject: [PATCH 29/54] devices: exclude md components when duplicate pvs are
seen
Improve handling of md components that get through the
filter, like the previous improvement for multipath.
If md components get through the filter and trigger
duplicate PV code, then eliminate any devs entirely
that are not an md device.
---
lib/cache/lvmcache.c | 168 ++++++++++++++++++++++++++++++++++++++-----
1 file changed, 149 insertions(+), 19 deletions(-)
diff --git a/lib/cache/lvmcache.c b/lib/cache/lvmcache.c
index a0811d4ea..0e62cd267 100644
--- a/lib/cache/lvmcache.c
+++ b/lib/cache/lvmcache.c
@@ -673,7 +673,7 @@ static int _all_multipath_components(struct cmd_context *cmd, struct lvmcache_in
wwid = device_id_system_read(cmd, dev, DEV_ID_TYPE_SYS_WWID);
if (!wwid && wwid1) {
- log_print("Different wwids for duplicate PVs %s %s %s none",
+ log_debug("Different wwids for duplicate PVs %s %s %s none",
dev_name(dev1), wwid1, dev_name(dev));
diff_wwid++;
continue;
@@ -690,7 +690,7 @@ static int _all_multipath_components(struct cmd_context *cmd, struct lvmcache_in
/* Different wwids indicates these are not multipath components. */
if (strcmp(wwid1, wwid)) {
- log_print("Different wwids for duplicate PVs %s %s %s %s",
+ log_debug("Different wwids for duplicate PVs %s %s %s %s",
dev_name(dev1), wwid1, dev_name(dev), wwid);
diff_wwid++;
continue;
@@ -721,6 +721,52 @@ static int _all_multipath_components(struct cmd_context *cmd, struct lvmcache_in
return 1;
}
+static int _all_md_components(struct cmd_context *cmd, struct lvmcache_info *info, const char *pvid,
+ struct dm_list *altdevs, struct device **dev_md_out)
+{
+ struct device_list *devl;
+ struct device *dev_md = NULL;
+ struct device *dev;
+ int real_dup = 0;
+
+ *dev_md_out = NULL;
+
+ /* There will often be no info struct because of the extra_md_checks function. */
+
+ if (info && (cmd->dev_types->md_major == MAJOR(info->dev->dev)))
+ dev_md = info->dev;
+
+ dm_list_iterate_items(devl, altdevs) {
+ dev = devl->dev;
+
+ if (cmd->dev_types->md_major == MAJOR(dev->dev)) {
+ if (dev_md) {
+ /* md devs themselves are dups */
+ log_debug("Found multiple md devices for PVID %s: %s %s",
+ pvid, dev_name(dev_md), dev_name(dev));
+ real_dup = 1;
+ break;
+ } else
+ dev_md = dev;
+ } else {
+ if (!dev_is_md_component(cmd, dev, NULL, 1)) {
+ /* md dev copied to another device */
+ real_dup = 1;
+ break;
+ }
+ }
+ }
+
+ if (real_dup)
+ return 0;
+
+ if (dev_md)
+ log_debug("Found md device %s for PVID %s.", dev_name(dev_md), pvid);
+
+ *dev_md_out = dev_md;
+ return 1;
+}
+
/*
* If we've found devices with the same PVID, decide which one
* to use.
@@ -776,7 +822,7 @@ static void _choose_duplicates(struct cmd_context *cmd,
struct device_list *devl, *devl_safe, *devl_add, *devl_del;
struct lvmcache_info *info;
struct device *dev1, *dev2;
- struct device *dev_mpath;
+ struct device *dev_mpath, *dev_md;
struct device *dev_drop;
const char *device_id = NULL, *device_id_type = NULL;
const char *idname1 = NULL, *idname2 = NULL;
@@ -801,6 +847,7 @@ next:
dm_list_init(&altdevs);
pvid = NULL;
dev_mpath = NULL;
+ dev_md = NULL;
dm_list_iterate_items_safe(devl, devl_safe, &_initial_duplicates) {
if (!pvid) {
@@ -829,6 +876,11 @@ next:
* the md/mpath device gives us a last chance to drop the component.
* An md/mpath component device is completely ignored, as if it had
* been filtered, and not kept in the list unused duplicates.
+ *
+ * One issue related to eliminating mpath/md duplicate PVs here is
+ * that it occurs after label_scan, and hints are created based
+ * on what label_scan finds, so hints are disabled due to duplicate
+ * PVs that are later resolved here.
*/
/*
@@ -898,24 +950,89 @@ next:
/*
* Get rid of any md components.
- * FIXME: use a function like _all_multipath_components to pick the actual md device.
*/
- if (info && dev_is_md_component(cmd, info->dev, NULL, 1)) {
- /* does not go in del_cache_devs which become unused_duplicates */
- log_debug("Ignoring md component %s with PVID %s (dropping info)", dev_name(info->dev), pvid);
- lvmcache_del(info);
- info = NULL;
- }
+ if (_all_md_components(cmd, info, pvid, &altdevs, &dev_md)) {
+ if (info && dev_md && (info->dev != dev_md)) {
+ /*
+ * info should be dropped from lvmcache and info->dev
+ * should be treated as if it had been excluded by a filter.
+ * dev_md should be added to lvmcache by the caller.
+ * Often this info struct has been removed by
+ * lvmcache_extra_md_component_checks.
+ */
+ dev_drop = info->dev;
- dm_list_iterate_items_safe(devl, devl_safe, &altdevs) {
- if (dev_is_md_component(cmd, devl->dev, NULL, 1)) {
- log_debug("Ignoring md component %s with PVID %s (dropping duplicate)", dev_name(devl->dev), pvid);
- dm_list_del(&devl->list);
+ /* Have caller add dev_md to lvmcache. */
+ log_debug("Using md device %s for PVID %s.", dev_name(dev_md), pvid);
+ if ((devl_add = zalloc(sizeof(*devl_add)))) {
+ devl_add->dev = dev_md;
+ dm_list_add(add_cache_devs, &devl_add->list);
+ }
+
+ /* Remove dev_md from altdevs. */
+ if ((devl = _get_devl_in_device_list(dev_md, &altdevs)))
+ dm_list_del(&devl->list);
+
+ /* Remove info from lvmcache that came from the component dev. */
+ log_debug("Ignoring md component %s with PVID %s (dropping info)", dev_name(dev_drop), pvid);
+ lvmcache_del(info);
+ info = NULL;
+
+ /* Make the component dev look like it was filtered. */
+ cmd->filter->wipe(cmd, cmd->filter, dev_drop, NULL);
+ dev_drop->flags &= ~DEV_SCAN_FOUND_LABEL;
}
- }
- if (dm_list_empty(&altdevs))
+ if (!info && dev_md) {
+ /*
+ * The info struct was from a component and was dropped
+ * and the actual md dev was found on initial_duplicates
+ * and the caller should add it to lvmcache.
+ */
+
+ /* Have caller add dev_md to lvmcache. */
+ log_debug("Using md device %s for PVID %s.", dev_name(dev_md), pvid);
+ if ((devl_add = zalloc(sizeof(*devl_add)))) {
+ devl_add->dev = dev_md;
+ dm_list_add(add_cache_devs, &devl_add->list);
+ }
+
+ /* Remove dev_md from altdevs. */
+ if ((devl = _get_devl_in_device_list(dev_md, &altdevs)))
+ dm_list_del(&devl->list);
+ }
+
+ if (info && !dev_md) {
+ /*
+ * Only md component devs were found and no actual
+ * md dev, so drop the component from lvmcache.
+ */
+ dev_drop = info->dev;
+
+ log_debug("Ignoring md component %s with PVID %s (dropping info)", dev_name(dev_drop), pvid);
+ lvmcache_del(info);
+ info = NULL;
+
+ /* Make the component dev look like it was filtered. */
+ cmd->filter->wipe(cmd, cmd->filter, dev_drop, NULL);
+ dev_drop->flags &= ~DEV_SCAN_FOUND_LABEL;
+ }
+
+ dm_list_iterate_items_safe(devl, devl_safe, &altdevs) {
+ /*
+ * The altdevs are all md components that should look
+ * like they were filtered, they are not in lvmcache.
+ */
+ dev_drop = devl->dev;
+
+ log_debug("Ignoring md component %s with PVID %s (dropping duplicate)", dev_name(dev_drop), pvid);
+ dm_list_del(&devl->list);
+
+ cmd->filter->wipe(cmd, cmd->filter, dev_drop, NULL);
+ dev_drop->flags &= ~DEV_SCAN_FOUND_LABEL;
+ }
goto next;
+ }
/*
* Find the device for the pvid that's currently in lvmcache.
@@ -1321,6 +1438,18 @@ int lvmcache_label_reopen_vg_rw(struct cmd_context *cmd, const char *vgname, con
* times it can be a clue that label_scan mistakenly read the pv from an md
* component device instead of from the md device itself. So for unmatching
* sizes, we do a full md component check on the device.
+ *
+ * It might be nice to do this checking in the filter (when passes_filter is
+ * called after the initial read), but that doesn't work because passes_filter
+ * is called before _text_read so metadata/pvsummary info is not yet available
+ * which this function uses.
+ *
+ * The unique value of this function is that it can eliminate md components
+ * without there being duplicate PVs. But, there will often be duplicate PVs,
+ * handled by _all_md_components(), where other devs with the same pvid will be
+ * in _initial_duplicates. One could be the md device itself which will be
+ * added to lvmcache by choose_duplicates, and other duplicates that are
+ * components will be dropped.
*/
void lvmcache_extra_md_component_checks(struct cmd_context *cmd)
@@ -1382,7 +1511,8 @@ void lvmcache_extra_md_component_checks(struct cmd_context *cmd)
*/
if (pvsize && devsize && (pvsize != devsize))
do_check_size = 1;
- if (device_hint && !strncmp(device_hint, "/dev/md", 7))
+ if (device_hint && !strncmp(device_hint, "/dev/md", 7) &&
+ (MAJOR(info->dev->dev) != cmd->dev_types->md_major))
do_check_name = 1;
if (!do_check_size && !do_check_name)
@@ -1412,11 +1542,11 @@ void lvmcache_extra_md_component_checks(struct cmd_context *cmd)
device_hint ?: "none", dev_name(dev));
if (dev_is_md_component(cmd, dev, NULL, 1)) {
- log_debug("dropping PV from md component %s", dev_name(dev));
+ log_debug("Ignoring PV from md component %s with PVID %s (metadata %s %llu)",
+ dev_name(dev), dev->pvid, device_hint ?: "none", (unsigned long long)pvsize);
dev->flags &= ~DEV_SCAN_FOUND_LABEL;
/* lvmcache_del will also delete vginfo if info was last one */
lvmcache_del(info);