backport upstream patches

This commit is contained in:
hao__wangh 2020-09-22 17:11:07 +08:00 committed by Fei Xu
parent 25f331e848
commit f25125ef95
7 changed files with 424 additions and 1 deletions

View File

@ -0,0 +1,100 @@
From 657c7f5d79fe43823ffb4d46e244bea15a65baf6 Mon Sep 17 00:00:00 2001
From: Laine Stump <laine@redhat.com>
Date: Thu, 18 Jun 2020 12:49:09 -0400
Subject: [PATCH 1/6] conf, vmx: check for OOM after calling xmlBufferCreate()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Although libvirt itself uses g_malloc0() and friends, which exit when
there isn't enouogh memory, libxml2 uses standard malloc(), which just
returns NULL on OOM - this means we must check for NULL on return from
any libxml2 functions that allocate memory.
xmlBufferCreate(), for example, might return NULL, and we don't always
check for it. This patch adds checks where it isn't already done.
(NB: Although libxml2 has a provision for changing behavior on OOM (by
calling xmlMemSetup() to change what functions are used to
allocating/freeing memory), we can't use that, since parts of libvirt
code end up in libvirt.so, which is linked and called directly by
applications that may themselves use libxml2 (and may have already set
their own alternate malloc()), e.g. drivers like esx which live totally
in the library rather than a separate process.)
cherry pick from: b7a92bce070fd57844a59bf8b1c30cb4ef4f3acd
Signed-off-by: Laine Stump <laine@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/conf/domain_conf.c | 6 +++++-
src/conf/network_conf.c | 6 +++++-
src/vmx/vmx.c | 11 +++++++----
3 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 914e03c..37c785a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -29022,7 +29022,11 @@ virDomainDefFormatInternalSetRootName(virDomainDefPtr def,
* Thankfully, libxml maps what looks like globals into
* thread-local uses, so we are thread-safe. */
xmlIndentTreeOutput = 1;
- xmlbuf = xmlBufferCreate();
+ if (!(xmlbuf = xmlBufferCreate())) {
+ virReportOOMError();
+ goto error;
+ }
+
if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata,
virBufferGetIndent(buf) / 2, 1) < 0) {
xmlBufferFree(xmlbuf);
diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index 819b645..c379042 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -2478,7 +2478,11 @@ virNetworkDefFormatBuf(virBufferPtr buf,
* Thankfully, libxml maps what looks like globals into
* thread-local uses, so we are thread-safe. */
xmlIndentTreeOutput = 1;
- xmlbuf = xmlBufferCreate();
+ if (!(xmlbuf = xmlBufferCreate())) {
+ virReportOOMError();
+ return -1;
+ }
+
if (xmlNodeDump(xmlbuf, def->metadata->doc, def->metadata,
virBufferGetIndent(buf) / 2, 1) < 0) {
xmlBufferFree(xmlbuf);
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index b1fd118..fbc8366 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -697,8 +697,8 @@ virVMXConvertToUTF8(const char *encoding, const char *string)
{
char *result = NULL;
xmlCharEncodingHandlerPtr handler;
- xmlBufferPtr input;
- xmlBufferPtr utf8;
+ xmlBufferPtr input = NULL;
+ xmlBufferPtr utf8 = NULL;
handler = xmlFindCharEncodingHandler(encoding);
@@ -708,8 +708,11 @@ virVMXConvertToUTF8(const char *encoding, const char *string)
return NULL;
}
- input = xmlBufferCreateStatic((char *)string, strlen(string));
- utf8 = xmlBufferCreate();
+ if (!(input = xmlBufferCreateStatic((char *)string, strlen(string))) ||
+ !(utf8 = xmlBufferCreate())) {
+ virReportOOMError();
+ goto cleanup;
+ }
if (xmlCharEncInFunc(handler, utf8, input) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
--
1.8.3.1

View File

@ -0,0 +1,66 @@
From cc842aa3030697b1a454e15ccfb2a201e57d5602 Mon Sep 17 00:00:00 2001
From: Michal Privoznik <mprivozn@redhat.com>
Date: Mon, 15 Jun 2020 12:53:48 +0200
Subject: [PATCH 3/6] leaseshelper: Report more errors
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Some functions or code paths that may fail don't report error
(e.g. when acquiring PID file fails) leading to a silent quit
of the leaseshelper. This makes it super hard for us and users
to debug what is happening. Fortunately, dnsmasq captures both
stdout and stderr so we can write an error message there.
cherry pick from: 9ed345ac1a035c8cf1de37431de638f4bac41de3
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
src/network/leaseshelper.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c
index 86c847d..2b5fc0f 100644
--- a/src/network/leaseshelper.c
+++ b/src/network/leaseshelper.c
@@ -131,8 +131,10 @@ main(int argc, char **argv)
* events for expired leases. So, libvirtd sets another env var for this
* purpose */
if (!interface &&
- !(interface = getenv("VIR_BRIDGE_NAME")))
- goto cleanup;
+ !(interface = getenv("VIR_BRIDGE_NAME"))) {
+ fprintf(stderr, _("interface not set\n"));
+ exit(EXIT_FAILURE);
+ }
ip = argv[3];
mac = argv[2];
@@ -160,13 +162,21 @@ main(int argc, char **argv)
pid_file = g_strdup(RUNSTATEDIR "/leaseshelper.pid");
/* Try to claim the pidfile, exiting if we can't */
- if ((pid_file_fd = virPidFileAcquirePath(pid_file, true, getpid())) < 0)
+ if ((pid_file_fd = virPidFileAcquirePath(pid_file, true, getpid())) < 0) {
+ fprintf(stderr,
+ _("Unable to acquire PID file: %s\n errno=%d"),
+ pid_file, errno);
goto cleanup;
+ }
/* Since interfaces can be hot plugged, we need to make sure that the
* corresponding custom lease file exists. If not, 'touch' it */
- if (virFileTouch(custom_lease_file, 0644) < 0)
+ if (virFileTouch(custom_lease_file, 0644) < 0) {
+ fprintf(stderr,
+ _("Unable to create: %s\n errno=%d"),
+ custom_lease_file, errno);
goto cleanup;
+ }
switch ((enum virLeaseActionFlags) action) {
case VIR_LEASE_ACTION_ADD:
--
1.8.3.1

View File

@ -0,0 +1,45 @@
From 173b80e8f8103f26438d344e9b97335d4e5036b4 Mon Sep 17 00:00:00 2001
From: Michal Privoznik <mprivozn@redhat.com>
Date: Thu, 11 Jun 2020 16:43:22 +0200
Subject: [PATCH 2/6] leaseshelper: Wait to acquire PID file
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
On a DHCP transaction, dnsmasq runs our leases helper which
updates corresponding JSON files. While one dnsmasq won't run the
leaseshelper in parallel, two dnsmasqs (from two distinct
networks) might. To avoid corrupting JSON file, the leaseshelper
acquires PID file first. Well, the way it's acquiring it is not
ideal - it calls virPidFileAcquirePath(wait = false); which
means, that either it acquires the PID file instantly or returns
an error and does not touch the JSON at all. This in turn means
that there might be a leases record missing. With wait = true,
this won't happen.
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1840307
cherry pick from: 876211ef4a192df1603b45715044ec14567d7e9f
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
---
src/network/leaseshelper.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/network/leaseshelper.c b/src/network/leaseshelper.c
index a1780ca..86c847d 100644
--- a/src/network/leaseshelper.c
+++ b/src/network/leaseshelper.c
@@ -160,7 +160,7 @@ main(int argc, char **argv)
pid_file = g_strdup(RUNSTATEDIR "/leaseshelper.pid");
/* Try to claim the pidfile, exiting if we can't */
- if ((pid_file_fd = virPidFileAcquirePath(pid_file, false, getpid())) < 0)
+ if ((pid_file_fd = virPidFileAcquirePath(pid_file, true, getpid())) < 0)
goto cleanup;
/* Since interfaces can be hot plugged, we need to make sure that the
--
1.8.3.1

View File

@ -0,0 +1,107 @@
From e017f95c7d833c0e9a463a1613d01fe93020606b Mon Sep 17 00:00:00 2001
From: Jonathon Jongsma <jjongsma@redhat.com>
Date: Tue, 23 Jun 2020 13:29:56 -0500
Subject: [PATCH 5/6] qemu: format 'ramfb' attribute for mediated devices
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
It's possible to use ramfb as the boot display of an assigned vgpu
device. This was introduced in 4b95738c, but unfortunately the attribute
was not formatted into the xml output for such a device. This patch
fixes that oversight and adds a xml2xml test to verify proper behavior.
https://bugzilla.redhat.com/show_bug.cgi?id=1847791
cherry pick from: c5815b31976f3982d18c7f6c1367ab6e403eb7eb
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/conf/domain_conf.c | 3 ++
.../hostdev-mdev-display-ramfb.x86_64-latest.xml | 44 ++++++++++++++++++++++
tests/qemuxml2xmltest.c | 1 +
3 files changed, 48 insertions(+)
create mode 100644 tests/qemuxml2xmloutdata/hostdev-mdev-display-ramfb.x86_64-latest.xml
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 37c785a..93e78a0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -27849,6 +27849,9 @@ virDomainHostdevDefFormat(virBufferPtr buf,
if (mdevsrc->display != VIR_TRISTATE_SWITCH_ABSENT)
virBufferAsprintf(buf, " display='%s'",
virTristateSwitchTypeToString(mdevsrc->display));
+ if (mdevsrc->ramfb != VIR_TRISTATE_SWITCH_ABSENT)
+ virBufferAsprintf(buf, " ramfb='%s'",
+ virTristateSwitchTypeToString(mdevsrc->ramfb));
}
}
diff --git a/tests/qemuxml2xmloutdata/hostdev-mdev-display-ramfb.x86_64-latest.xml b/tests/qemuxml2xmloutdata/hostdev-mdev-display-ramfb.x86_64-latest.xml
new file mode 100644
index 0000000..c134400
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/hostdev-mdev-display-ramfb.x86_64-latest.xml
@@ -0,0 +1,44 @@
+<domain type='qemu'>
+ <name>QEMUGuest2</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219136</memory>
+ <currentMemory unit='KiB'>219136</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='i686' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <cpu mode='custom' match='exact' check='none'>
+ <model fallback='forbid'>qemu64</model>
+ </cpu>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu-system-i386</emulator>
+ <controller type='usb' index='0' model='piix3-uhci'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
+ </controller>
+ <controller type='pci' index='0' model='pci-root'/>
+ <controller type='ide' index='0'>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
+ </controller>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <graphics type='vnc' port='-1' autoport='yes'>
+ <listen type='address'/>
+ </graphics>
+ <video>
+ <model type='qxl' ram='65536' vram='65536' vgamem='16384' heads='1' primary='yes'/>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
+ </video>
+ <hostdev mode='subsystem' type='mdev' managed='no' model='vfio-pci' display='on' ramfb='on'>
+ <source>
+ <address uuid='53764d0e-85a0-42b4-af5c-2046b460b1dc'/>
+ </source>
+ <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
+ </hostdev>
+ <memballoon model='none'/>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index a0d27fd..3a25395 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -529,6 +529,7 @@ mymain(void)
QEMU_CAPS_VFIO_PCI_DISPLAY,
QEMU_CAPS_DEVICE_VFIO_PCI,
QEMU_CAPS_VNC);
+ DO_TEST_CAPS_LATEST("hostdev-mdev-display-ramfb");
DO_TEST("pci-rom", NONE);
DO_TEST("pci-rom-disabled", NONE);
DO_TEST("pci-rom-disabled-invalid", NONE);
--
1.8.3.1

View File

@ -0,0 +1,57 @@
From f63d6889b34af9b0b7808566945d6e1720d7c1fd Mon Sep 17 00:00:00 2001
From: Peter Krempa <pkrempa@redhat.com>
Date: Wed, 8 Jul 2020 09:13:42 +0200
Subject: [PATCH 4/6] qemuBuildMemoryBackendProps: Use boolean type for 'pmem'
property
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Commit 82576d8f35e used a string "on" to enable the 'pmem' property.
This is okay for the command line visitor, but the property is declared
as boolean in qemu and thus it will not work when using QMP.
Modify the type to boolean. This changes the command line, but
fortunately the command line visitor in qemu parses both 'yes' and 'on'
as true for the property.
https://bugzilla.redhat.com/show_bug.cgi?id=1854684
cherry pick from: e95da4e5bf53ff977f440903df9f7343f2fb6f0e
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
src/qemu/qemu_command.c | 2 +-
tests/qemuxml2argvdata/memory-hotplug-nvdimm-pmem.x86_64-latest.args | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2f0e919..014a0e4 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -3523,7 +3523,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps,
"with this QEMU binary"));
return -1;
}
- if (virJSONValueObjectAdd(props, "s:pmem", "on", NULL) < 0)
+ if (virJSONValueObjectAdd(props, "b:pmem", true, NULL) < 0)
return -1;
}
diff --git a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-pmem.x86_64-latest.args b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-pmem.x86_64-latest.args
index 5dfba9b..00a78ba 100644
--- a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-pmem.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-pmem.x86_64-latest.args
@@ -19,7 +19,7 @@ file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
-smp 2,sockets=2,dies=1,cores=1,threads=1 \
-numa node,nodeid=0,cpus=0-1,mem=214 \
-object memory-backend-file,id=memnvdimm0,prealloc=yes,mem-path=/tmp/nvdimm,\
-share=no,size=536870912,pmem=on \
+share=no,size=536870912,pmem=yes \
-device nvdimm,node=0,memdev=memnvdimm0,id=nvdimm0,slot=0 \
-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
-display none \
--
1.8.3.1

View File

@ -0,0 +1,40 @@
From 6c4265c15abd446e050f955cccb41d22f8456969 Mon Sep 17 00:00:00 2001
From: Martin Kletzander <mkletzan@redhat.com>
Date: Thu, 9 Jul 2020 09:27:41 +0200
Subject: [PATCH 6/6] resctrl: Do not open directory for writing
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
When preparing for the removal of GNULIB commit 18dca21a32e9 removed the
unneeded O_DIRECTORY, but unfortunately started opening the directory for
writing which fails every time for a directory. There is also no need for that
as flock() works on O_RDONLY file descriptor as well, even for LOCK_EX.
https://bugzilla.redhat.com/1852741
cherry pick from: 9d832813820b948eb508508fb3cbd86c90698119
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Andrea Bolognani <abologna@redhat.com>
---
src/util/virresctrl.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/util/virresctrl.c b/src/util/virresctrl.c
index c537d60..937a053 100644
--- a/src/util/virresctrl.c
+++ b/src/util/virresctrl.c
@@ -456,7 +456,7 @@ VIR_ONCE_GLOBAL_INIT(virResctrl);
static int
virResctrlLockWrite(void)
{
- int fd = open(SYSFS_RESCTRL_PATH, O_RDWR | O_CLOEXEC);
+ int fd = open(SYSFS_RESCTRL_PATH, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
virReportSystemError(errno, "%s", _("Cannot open resctrl"));
--
1.8.3.1

View File

@ -99,7 +99,7 @@
Summary: Library providing a simple virtualization API Summary: Library providing a simple virtualization API
Name: libvirt Name: libvirt
Version: 6.2.0 Version: 6.2.0
Release: 11 Release: 12
License: LGPLv2+ License: LGPLv2+
URL: https://libvirt.org/ URL: https://libvirt.org/
@ -150,6 +150,12 @@ Patch0039: libvirt-virQEMUDriverConfigNew-Add-slash-to-cfg-defaultTLSx5.patch
Patch0040: libvirt-qemuDomainSetNumaParamsLive-set-nodeset-for-root-cgr.patch Patch0040: libvirt-qemuDomainSetNumaParamsLive-set-nodeset-for-root-cgr.patch
Patch0041: libvirt-qemu-do-not-add-model-when-actual-iface-type-is-host.patch Patch0041: libvirt-qemu-do-not-add-model-when-actual-iface-type-is-host.patch
Patch0042: libvirt-qemu-pre-create-the-dbus-directory-in-qemuStateIniti.patch Patch0042: libvirt-qemu-pre-create-the-dbus-directory-in-qemuStateIniti.patch
Patch0043: libvirt-conf-vmx-check-for-OOM-after-calling-xmlBufferCreate.patch
Patch0044: libvirt-leaseshelper-Wait-to-acquire-PID-file.patch
Patch0045: libvirt-leaseshelper-Report-more-errors.patch
Patch0046: libvirt-qemuBuildMemoryBackendProps-Use-boolean-type-for-pme.patch
Patch0047: libvirt-qemu-format-ramfb-attribute-for-mediated-devices.patch
Patch0048: libvirt-resctrl-Do-not-open-directory-for-writing.patch
Requires: libvirt-daemon = %{version}-%{release} Requires: libvirt-daemon = %{version}-%{release}
Requires: libvirt-daemon-config-network = %{version}-%{release} Requires: libvirt-daemon-config-network = %{version}-%{release}
@ -1882,6 +1888,8 @@ exit 0
%changelog %changelog
* Tue Sep 22 2020 Hao Wang <wanghao232@huawei.com> - 6.2.0-12
- backport upstream patches
* Tue Sep 22 2020 Zeyu Jin <jinzeyu@huawei.com> - 6.2.0-11 * Tue Sep 22 2020 Zeyu Jin <jinzeyu@huawei.com> - 6.2.0-11
- bugfix: backport an upstream patch to fix '/run/libvirt/qemu/dbus' racing bug. - bugfix: backport an upstream patch to fix '/run/libvirt/qemu/dbus' racing bug.
* Tue Sep 22 2020 Jin Yan <jinyan12@huawei.com> - 6.2.0-10 * Tue Sep 22 2020 Jin Yan <jinyan12@huawei.com> - 6.2.0-10