From 99b6be8617e7b674e32890fc19f4a8f65fff4e7e Mon Sep 17 00:00:00 2001 From: Euler Robot Date: Thu, 23 Jul 2020 17:08:46 +0200 Subject: [PATCH 1/5] virDevMapperGetTargets: Don't ignore EBADF MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Privoznik Reviewed-by: Daniel P. Berrangé --- ...vMapperGetTargets-Don-t-ignore-EBADF.patch | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 virDevMapperGetTargets-Don-t-ignore-EBADF.patch diff --git a/virDevMapperGetTargets-Don-t-ignore-EBADF.patch b/virDevMapperGetTargets-Don-t-ignore-EBADF.patch new file mode 100644 index 0000000..30cc221 --- /dev/null +++ b/virDevMapperGetTargets-Don-t-ignore-EBADF.patch @@ -0,0 +1,53 @@ +From 63a6d2b325f4cad831a3bd349bb33359273093f7 Mon Sep 17 00:00:00 2001 +From: Michal Privoznik +Date: Thu, 23 Jul 2020 17:08:46 +0200 +Subject: [PATCH] virDevMapperGetTargets: Don't ignore EBADF +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Signed-off-by: Michal Privoznik +Reviewed-by: Daniel P. Berrangé +--- + src/qemu/qemu_cgroup.c | 2 +- + src/qemu/qemu_domain.c | 4 ++-- + 2 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c +index 057f87124c..aa721df100 100644 +--- a/src/qemu/qemu_cgroup.c ++++ b/src/qemu/qemu_cgroup.c +@@ -91,7 +91,7 @@ qemuSetupImagePathCgroup(virDomainObjPtr vm, + } + + if (virDevMapperGetTargets(path, &targetPaths) < 0 && +- errno != ENOSYS && errno != EBADF) { ++ errno != ENOSYS) { + virReportSystemError(errno, + _("Unable to get devmapper targets for %s"), + path); +diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c +index daab7ebec3..adae36db0e 100644 +--- a/src/qemu/qemu_domain.c ++++ b/src/qemu/qemu_domain.c +@@ -14923,7 +14923,7 @@ qemuDomainSetupDisk(virQEMUDriverConfigPtr cfg G_GNUC_UNUSED, + return -1; + + if (virDevMapperGetTargets(next->path, &targetPaths) < 0 && +- errno != ENOSYS && errno != EBADF) { ++ errno != ENOSYS) { + virReportSystemError(errno, + _("Unable to get devmapper targets for %s"), + next->path); +@@ -15976,7 +15976,7 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, + tmpPath = g_strdup(next->path); + + if (virDevMapperGetTargets(next->path, &targetPaths) < 0 && +- errno != ENOSYS && errno != EBADF) { ++ errno != ENOSYS) { + virReportSystemError(errno, + _("Unable to get devmapper targets for %s"), + next->path); +-- +2.27.0 + -- Gitee From bf8c429e4e19d92cde1f405d5a85c534310c1226 Mon Sep 17 00:00:00 2001 From: Euler Robot Date: Tue, 18 Aug 2020 11:08:15 +0200 Subject: [PATCH 2/5] virdevmapper: Don't cache device-mapper major The device mapper major is needed in virIsDevMapperDevice() which determines whether given device is managed by device-mapper. This number is obtained by parsing /proc/devices and then stored in a global variable so that the file doesn't have to be parsed again. However, as it turns out this logic is flawed - the major number is not static and can change as it can be specified as a parameter when loading the dm-mod module. Unfortunately, I was not able to come up with a good solution and thus the /proc/devices file is being parsed every time we need the device mapper major. Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa Reviewed-by: Christian Ehrhardt Tested-by: Christian Ehrhardt --- ...pper-Don-t-cache-device-mapper-major.patch | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 virdevmapper-Don-t-cache-device-mapper-major.patch diff --git a/virdevmapper-Don-t-cache-device-mapper-major.patch b/virdevmapper-Don-t-cache-device-mapper-major.patch new file mode 100644 index 0000000..b080043 --- /dev/null +++ b/virdevmapper-Don-t-cache-device-mapper-major.patch @@ -0,0 +1,91 @@ +From fb5ac9b0db25984b0d54149dc15b87f513523430 Mon Sep 17 00:00:00 2001 +From: Michal Privoznik +Date: Tue, 18 Aug 2020 11:08:15 +0200 +Subject: [PATCH] virdevmapper: Don't cache device-mapper major + +The device mapper major is needed in virIsDevMapperDevice() which +determines whether given device is managed by device-mapper. This +number is obtained by parsing /proc/devices and then stored in a +global variable so that the file doesn't have to be parsed again. +However, as it turns out this logic is flawed - the major number +is not static and can change as it can be specified as a +parameter when loading the dm-mod module. + +Unfortunately, I was not able to come up with a good solution and +thus the /proc/devices file is being parsed every time we need +the device mapper major. + +Signed-off-by: Michal Privoznik +Reviewed-by: Peter Krempa +Reviewed-by: Christian Ehrhardt +Tested-by: Christian Ehrhardt +--- + src/util/virdevmapper.c | 17 +++++------------ + 1 file changed, 5 insertions(+), 12 deletions(-) + +diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c +index a471504176..b43dbefa9a 100644 +--- a/src/util/virdevmapper.c ++++ b/src/util/virdevmapper.c +@@ -46,11 +46,9 @@ + + G_STATIC_ASSERT(BUF_SIZE > sizeof(struct dm_ioctl)); + +-static unsigned int virDMMajor; +- + + static int +-virDevMapperOnceInit(void) ++virDevMapperGetMajor(unsigned int *major) + { + g_autofree char *buf = NULL; + VIR_AUTOSTRINGLIST lines = NULL; +@@ -69,7 +67,7 @@ virDevMapperOnceInit(void) + + if (sscanf(lines[i], "%u %ms\n", &maj, &dev) == 2 && + STREQ(dev, DM_NAME)) { +- virDMMajor = maj; ++ *major = maj; + break; + } + } +@@ -85,9 +83,6 @@ virDevMapperOnceInit(void) + } + + +-VIR_ONCE_GLOBAL_INIT(virDevMapper); +- +- + static void * + virDMIoctl(int controlFD, int cmd, struct dm_ioctl *dm, char **buf) + { +@@ -305,9 +300,6 @@ virDevMapperGetTargets(const char *path, + * consist of devices or yet another targets. If that's the + * case, we have to stop recursion somewhere. */ + +- if (virDevMapperInitialize() < 0) +- return -1; +- + if ((controlFD = virDMOpen()) < 0) + return -1; + +@@ -319,13 +311,14 @@ bool + virIsDevMapperDevice(const char *dev_name) + { + struct stat buf; ++ unsigned int major; + +- if (virDevMapperInitialize() < 0) ++ if (virDevMapperGetMajor(&major) < 0) + return false; + + if (!stat(dev_name, &buf) && + S_ISBLK(buf.st_mode) && +- major(buf.st_rdev) == virDMMajor) ++ major(buf.st_rdev) == major) + return true; + + return false; +-- +2.27.0 + -- Gitee From ff94cac502dca366b96f28d5b8b84b2f449c0a0d Mon Sep 17 00:00:00 2001 From: Euler Robot Date: Tue, 18 Aug 2020 11:04:24 +0200 Subject: [PATCH 3/5] virdevmapper: Handle kernel without device-mapper support In one of my latest patch (v6.6.0~30) I was trying to remove libdevmapper use in favor of our own implementation. However, the code did not take into account that device mapper can be not compiled into the kernel (e.g. be a separate module that's not loaded) in which case /proc/devices won't have the device-mapper major number and thus virDevMapperGetTargets() and/or virIsDevMapperDevice() fails. However, such failure is safe to ignore, because if device mapper is missing then there can't be any multipath devices and thus we don't need to allow the deps in CGroups, nor create them in the domain private namespace, etc. Fixes: 22494556542c676d1b9e7f1c1f2ea13ac17e1e3e Reported-by: Andrea Bolognani Reported-by: Christian Ehrhardt Signed-off-by: Michal Privoznik Reviewed-by: Peter Krempa Reviewed-by: Christian Ehrhardt Tested-by: Christian Ehrhardt --- ...dle-kernel-without-device-mapper-sup.patch | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 virdevmapper-Handle-kernel-without-device-mapper-sup.patch diff --git a/virdevmapper-Handle-kernel-without-device-mapper-sup.patch b/virdevmapper-Handle-kernel-without-device-mapper-sup.patch new file mode 100644 index 0000000..ba25626 --- /dev/null +++ b/virdevmapper-Handle-kernel-without-device-mapper-sup.patch @@ -0,0 +1,79 @@ +From 83298f3086380c9b3b3ec39a2d6bf7b33592683b Mon Sep 17 00:00:00 2001 +From: Michal Privoznik +Date: Tue, 18 Aug 2020 11:04:24 +0200 +Subject: [PATCH] virdevmapper: Handle kernel without device-mapper support + +In one of my latest patch (v6.6.0~30) I was trying to remove +libdevmapper use in favor of our own implementation. However, the +code did not take into account that device mapper can be not +compiled into the kernel (e.g. be a separate module that's not +loaded) in which case /proc/devices won't have the device-mapper +major number and thus virDevMapperGetTargets() and/or +virIsDevMapperDevice() fails. + +However, such failure is safe to ignore, because if device mapper +is missing then there can't be any multipath devices and thus we +don't need to allow the deps in CGroups, nor create them in the +domain private namespace, etc. + +Fixes: 22494556542c676d1b9e7f1c1f2ea13ac17e1e3e +Reported-by: Andrea Bolognani +Reported-by: Christian Ehrhardt +Signed-off-by: Michal Privoznik +Reviewed-by: Peter Krempa +Reviewed-by: Christian Ehrhardt +Tested-by: Christian Ehrhardt +--- + src/util/virdevmapper.c | 20 ++++++++++++++++++-- + 1 file changed, 18 insertions(+), 2 deletions(-) + +diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c +index b43dbefa9a..a81e2edee4 100644 +--- a/src/util/virdevmapper.c ++++ b/src/util/virdevmapper.c +@@ -54,6 +54,9 @@ virDevMapperGetMajor(unsigned int *major) + VIR_AUTOSTRINGLIST lines = NULL; + size_t i; + ++ if (!virFileExists(CONTROL_PATH)) ++ return -2; ++ + if (virFileReadAll(PROC_DEVICES, BUF_SIZE, &buf) < 0) + return -1; + +@@ -126,8 +129,13 @@ virDMOpen(void) + + memset(&dm, 0, sizeof(dm)); + +- if ((controlFD = open(CONTROL_PATH, O_RDWR)) < 0) ++ if ((controlFD = open(CONTROL_PATH, O_RDWR)) < 0) { ++ if (errno == ENOENT) ++ return -2; ++ ++ virReportSystemError(errno, _("Unable to open %s"), CONTROL_PATH); + return -1; ++ } + + if (!virDMIoctl(controlFD, DM_VERSION, &dm, &tmp)) { + virReportSystemError(errno, "%s", +@@ -300,8 +308,16 @@ virDevMapperGetTargets(const char *path, + * consist of devices or yet another targets. If that's the + * case, we have to stop recursion somewhere. */ + +- if ((controlFD = virDMOpen()) < 0) ++ if ((controlFD = virDMOpen()) < 0) { ++ if (controlFD == -2) { ++ /* The CONTROL_PATH doesn't exist. Probably the ++ * module isn't loaded, yet. Don't error out, just ++ * exit. */ ++ return 0; ++ } ++ + return -1; ++ } + + return virDevMapperGetTargetsImpl(controlFD, path, devPaths, ttl); + } +-- +2.27.0 + -- Gitee From ae46c931fa6f1c6a41c01820c27ff509a4997340 Mon Sep 17 00:00:00 2001 From: Chen Qun Date: Wed, 8 Dec 2021 21:28:22 +0800 Subject: [PATCH 4/5] =?UTF-8?q?spec:=20Update=20patch=20and=20changelog=20?= =?UTF-8?q?with=20!47=20=E5=9B=9E=E5=90=88upstream=20bugfix:=20virdevmappe?= =?UTF-8?q?r:=20Handle=20kernel=20without=20device-mapper=20support=20=20!?= =?UTF-8?q?47?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit virDevMapperGetTargets: Don't ignore EBADF virdevmapper: Don't cache device-mapper major virdevmapper: Handle kernel without device-mapper support Signed-off-by: Michal Privoznik --- libvirt.spec | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libvirt.spec b/libvirt.spec index fc972c4..3ee267a 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -147,6 +147,9 @@ Patch0036: conf-domain_conf-pin-the-retry_interval-and-retry_ti.patch Patch0037: storage_driver-Unlock-object-on-ACL-fail-in-storageP.patch Patch0038: security-fix-SELinux-label-generation-logic.patch Patch0039: add-phytium-2000plus-and-s2500-support-on-arm-archit.patch +Patch0040: virDevMapperGetTargets-Don-t-ignore-EBADF.patch +Patch0041: virdevmapper-Don-t-cache-device-mapper-major.patch +Patch0042: virdevmapper-Handle-kernel-without-device-mapper-sup.patch Requires: libvirt-daemon = %{version}-%{release} Requires: libvirt-daemon-config-network = %{version}-%{release} @@ -1879,6 +1882,11 @@ exit 0 %changelog +* Wed Dec 08 2021 Euler Robot +- virDevMapperGetTargets: Don't ignore EBADF +- virdevmapper: Don't cache device-mapper major +- virdevmapper: Handle kernel without device-mapper support + * Wed Dec 08 2021 Euler Robot - add phytium 2000plus and s2500 support on arm architecture for capability -- Gitee From 9fbaad85d10204f86763bb5a4451733905b5b6d7 Mon Sep 17 00:00:00 2001 From: Chen Qun Date: Wed, 8 Dec 2021 21:28:26 +0800 Subject: [PATCH 5/5] spec: Update release version with !47 increase release verison by one Signed-off-by: Chen Qun --- libvirt.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libvirt.spec b/libvirt.spec index 3ee267a..1b7ad02 100644 --- a/libvirt.spec +++ b/libvirt.spec @@ -99,7 +99,7 @@ Summary: Library providing a simple virtualization API Name: libvirt Version: 6.2.0 -Release: 15 +Release: 16 License: LGPLv2+ URL: https://libvirt.org/ -- Gitee