fix fail to create lv and pvid file leakage

Signed-off-by: wangzhiqiang <wangzhiqiang95@huawei.com>
(cherry picked from commit 6f33124912129016c7cb1fc847142b64c56ce0f8)
This commit is contained in:
wangzhiqiang 2023-06-08 17:06:35 +08:00 committed by openeuler-sync-bot
parent 6685aa9075
commit ed40e0ee4b
4 changed files with 162 additions and 1 deletions

49
0023-udev-repeat.patch Normal file
View File

@ -0,0 +1,49 @@
From 69a3f4d986a4f5302a35771376a7785b9464889d Mon Sep 17 00:00:00 2001
From: wuguanghao <wuguanghao3@huawei.com>
Date: Sat, 9 Jun 2021 19:07:43 +0800
Subject: [PATCH] udev repeat
systemd-udev exec IMPORT{program} in rules to get stdout of
program for storing some ENV vars. However due to some reasons,
the stdout of program cannot be gotten by systemd-udevd, which
cause some errors due to missing of ENV vars.
lv maybe lost after reboot, now we repeat to exec programs to
avoid lv missing.
Signed-off-by: wuguanghao<wuguanghao3@huawei.com>
Signed-off-by: Zhiqiang Liu<liuzhiqiang26@huawei.com>
---
udev/10-dm.rules.in | 2 ++
udev/11-dm-lvm.rules.in | 2 ++
2 files changed, 4 insertions(+)
diff --git a/udev/10-dm.rules.in b/udev/10-dm.rules.in
index b4fa52a..3ed1242 100644
--- a/udev/10-dm.rules.in
+++ b/udev/10-dm.rules.in
@@ -51,6 +51,8 @@ ACTION!="add|change", GOTO="dm_end"
# kernel version 2.6.31. Therefore, we can use this feature with
# kernels >= 2.6.31 only. Cookie is not decoded for remove event.
ENV{DM_COOKIE}=="?*", IMPORT{program}="(DM_EXEC)/dmsetup udevflags $env{DM_COOKIE}"
+ENV{DM_COOKIE}=="?*", ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}!="?*", IMPORT{program}="(DM_EXEC)/dmsetup udevflags $env{DM_COOKIE}"
+ENV{DM_COOKIE}=="?*", ENV{DM_UDEV_PRIMARY_SOURCE_FLAG}!="?*", IMPORT{program}="(DM_EXEC)/dmsetup udevflags $env{DM_COOKIE}"
# Rule out easy-to-detect inappropriate events first.
ENV{DISK_RO}=="1", GOTO="dm_disable"
diff --git a/udev/11-dm-lvm.rules.in b/udev/11-dm-lvm.rules.in
index 7c58994..33f7d1d 100644
--- a/udev/11-dm-lvm.rules.in
+++ b/udev/11-dm-lvm.rules.in
@@ -19,6 +19,8 @@ ENV{DM_UUID}!="LVM-?*", GOTO="lvm_end"
# Use DM name and split it up into its VG/LV/layer constituents.
IMPORT{program}="(DM_EXEC)/dmsetup splitname --nameprefixes --noheadings --rows $env{DM_NAME}"
+ENV{DM_VG_NAME}!="?*", IMPORT{program}="(DM_EXEC)/dmsetup splitname --nameprefixes --noheadings --rows $env{DM_NAME}"
+ENV{DM_LV_NAME}!="?*", IMPORT{program}="(DM_EXEC)/dmsetup splitname --nameprefixes --noheadings --rows $env{DM_NAME}"
# DM_SUBSYSTEM_UDEV_FLAG0 is the 'NOSCAN' flag for LVM subsystem.
# This flag is used to temporarily disable selected rules to prevent any
--
2.33.0

View File

@ -0,0 +1,31 @@
From b36985754f67c3df89c42ed29250abf6dfaf7890 Mon Sep 17 00:00:00 2001
From: Wu Guanghao <wuguanghao3@huawei.com>
Date: Sat, 4 Jun 2022 03:06:52 +0400
Subject: [PATCH] use sync io read bcache by defaults
Currently lvm2 uses aio to read bcache by default,
but aio is created successfully but read fails,
resulting in lv creation failure. So use sync io
read bcache by default.
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
---
lib/config/defaults.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/config/defaults.h b/lib/config/defaults.h
index faf628f..d039cc7 100644
--- a/lib/config/defaults.h
+++ b/lib/config/defaults.h
@@ -70,7 +70,7 @@
#define DEFAULT_METADATA_READ_ONLY 0
#define DEFAULT_LVDISPLAY_SHOWS_FULL_DEVICE_PATH 0
#define DEFAULT_UNKNOWN_DEVICE_NAME "[unknown]"
-#define DEFAULT_USE_AIO 1
+#define DEFAULT_USE_AIO 0
#define DEFAULT_SANLOCK_LV_EXTEND_MB 256
--
2.33.0

View File

@ -0,0 +1,75 @@
From 65927e86669e702b8b76f8af81c040c666bc3260 Mon Sep 17 00:00:00 2001
From: miaoguanqin <miaoguanqin@huawei.com>
Date: Thu, 8 Sep 2022 19:59:44 +0800
Subject: [PATCH] vgremove: PVID file leakage in /run/lvm/pvs_online
We found PVID file leakage problem when exec the following test;
pvcreate /dev/sdb
vgcreate -s 1G docker /dev/sdb
lvcreate -L 10M docker
pvscan --cache --listvg --checkcomplete --vgonline --udevoutput --journal=output /dev/sdb
vgremove -ff docker
pvcreate operation generates a new PVID, which is used to create PVID pvid file
when exec pvscan. However vgremove does not delete the old PVID file.
Here, we will delete all PVID files of each PV in current vg, when exec vgremove.
Signed-off-by: miaoguanqin <miaoguanqin@huawei.com>
---
lib/metadata/metadata.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/lib/metadata/metadata.c b/lib/metadata/metadata.c
index 30b2c17..ea02629 100644
--- a/lib/metadata/metadata.c
+++ b/lib/metadata/metadata.c
@@ -38,6 +38,29 @@
#include <time.h>
#include <math.h>
+static const char *_pvs_online_dir = DEFAULT_RUN_DIR "/pvs_online";
+
+static int remove_pvid_file(struct physical_volume *pv)
+{
+ char pvid[ID_LEN + 1] __attribute__((aligned(8))) = { 0 };
+ char path[PATH_MAX] __attribute__((aligned(8)))={ 0 };
+
+ memcpy(pvid, &pv->id.uuid, ID_LEN);
+
+ if (dm_snprintf(path, sizeof(path), "%s/%s", _pvs_online_dir, pvid) < 0) {
+ log_warn("WARNING:pvid file path is %s", path);
+ return 0;
+ }
+
+ log_warn("unlink pvid file, path is %s", path);
+
+ if (unlink(path) && (errno != ENOENT)) {
+ log_warn("WARNING:unlink pvid file path error, path is %s", path);
+ return 0;
+ }
+ return 1;
+}
+
static struct physical_volume *_pv_read(struct cmd_context *cmd,
const struct format_type *fmt,
struct volume_group *vg,
@@ -665,6 +688,15 @@ int vg_remove_direct(struct volume_group *vg)
" from volume group \"%s\"",
pv_dev_name(pv), vg->name);
ret = 0;
+ continue;
+ }
+
+ /* Remove pvid files */
+ if (!remove_pvid_file(pv)) {
+ log_error("Failed to remove pvid files \"%s\""
+ " from volume group \"%s\"",
+ _pvs_online_dir, vg->name);
+ ret = 0;
}
}
--
2.33.0

View File

@ -43,7 +43,7 @@
Name: lvm2
Version: 2.03.14
Release: 7
Release: 8
Epoch: 8
Summary: Tools for logical volume management
License: GPLv2+ and LGPLv2.1 and BSD
@ -71,6 +71,9 @@ Patch19: 0019-dmsetup-check-also-for-ouf-of-range-value.patch
Patch20: 0020-toollib-do-not-process-just-created-historical-LV.patch
Patch21: 0021-pvscan-match-device-arg-to-filter-symlink.patch
Patch22: 0022-pvscan-fix-filter-symlink-checks.patch
Patch23: 0023-udev-repeat.patch
Patch24: 0024-use-sync-io-read-bcache-by-defaults.patch
Patch25: 0025-vgremove-PVID-file-leakage-in-run-lvm-pvs_online.patch
BuildRequires: gcc
BuildRequires: gcc-c++
@ -497,6 +500,9 @@ fi
%changelog
* Thu Jun 8 2023 wangzhiqiang <wangzhiqiang95@huawei.com> - 8:2.03.14-8
- fix fail to create lv and pvid file leakage
* Sat Dec 17 2022 volcanodragon<linfeilong@huawei.com> - 8:2.03.14-7
- backport some bugfix patches from upstream