- kvm-s390x-Fix-leak-in-machine_set_loadparm.patch [RHEL-98554] - kvm-hw-s390x-ccw-device-Fix-memory-leak-in-loadparm-sett.patch [RHEL-98554] - kvm-amd_iommu-Rename-variable-mmio-to-mr_mmio.patch [RHEL-66202] - kvm-amd_iommu-Add-support-for-pass-though-mode.patch [RHEL-66202] - kvm-amd_iommu-Use-shared-memory-region-for-Interrupt-Rem.patch [RHEL-66202] - kvm-amd_iommu-Send-notification-when-invalidate-interrup.patch [RHEL-66202] - kvm-amd_iommu-Check-APIC-ID-255-for-XTSup.patch [RHEL-66202] - kvm-io-Fix-partial-struct-copy-in-qio_dns_resolver_looku.patch [RHEL-67104] - kvm-util-qemu-sockets-Refactor-setting-client-sockopts-i.patch [RHEL-67104] - kvm-util-qemu-sockets-Refactor-success-and-failure-paths.patch [RHEL-67104] - kvm-util-qemu-sockets-Add-support-for-keep-alive-flag-to.patch [RHEL-67104] - kvm-util-qemu-sockets-Refactor-inet_parse-to-use-QemuOpt.patch [RHEL-67104] - kvm-util-qemu-sockets-Introduce-inet-socket-options-cont.patch [RHEL-67104] - kvm-tests-unit-test-util-sockets-fix-mem-leak-on-error-o.patch [RHEL-67104] - kvm-target-i386-Expose-bits-related-to-SRSO-vulnerabilit.patch [RHEL-52649] - kvm-target-i386-Add-PerfMonV2-feature-bit.patch [RHEL-52649] - kvm-target-i386-Update-EPYC-CPU-model-for-Cache-property.patch [RHEL-52649] - kvm-target-i386-Update-EPYC-Rome-CPU-model-for-Cache-pro.patch [RHEL-52649] - kvm-target-i386-Update-EPYC-Milan-CPU-model-for-Cache-pr.patch [RHEL-52649] - kvm-target-i386-Add-couple-of-feature-bits-in-CPUID_Fn80.patch [RHEL-52649] - kvm-target-i386-Update-EPYC-Genoa-for-Cache-property-per.patch [RHEL-52649] - kvm-target-i386-Add-support-for-EPYC-Turin-model.patch [RHEL-52649] - kvm-hw-i386-amd_iommu-Assign-pci-id-0x1419-for-the-AMD-I.patch [RHEL-70926] - kvm-hw-i386-amd_iommu-Isolate-AMDVI-PCI-from-amd-iommu-d.patch [RHEL-70925] - kvm-hw-i386-amd_iommu-Allow-migration-when-explicitly-cr.patch [RHEL-70925] - kvm-Enable-amd-iommu-device.patch [RHEL-70925] - kvm-include-qemu-compiler-add-QEMU_UNINITIALIZED-attribu.patch [RHEL-99888] - kvm-hw-virtio-virtio-avoid-cost-of-ftrivial-auto-var-ini.patch [RHEL-99888] - kvm-block-skip-automatic-zero-init-of-large-array-in-ioq.patch [RHEL-99888] - kvm-chardev-char-fd-skip-automatic-zero-init-of-large-ar.patch [RHEL-99888] - kvm-chardev-char-pty-skip-automatic-zero-init-of-large-a.patch [RHEL-99888] - kvm-chardev-char-socket-skip-automatic-zero-init-of-larg.patch [RHEL-99888] - kvm-hw-audio-ac97-skip-automatic-zero-init-of-large-arra.patch [RHEL-99888] - kvm-hw-audio-cs4231a-skip-automatic-zero-init-of-large-a.patch [RHEL-99888] - kvm-hw-audio-es1370-skip-automatic-zero-init-of-large-ar.patch [RHEL-99888] - kvm-hw-audio-gus-skip-automatic-zero-init-of-large-array.patch [RHEL-99888] - kvm-hw-audio-marvell_88w8618-skip-automatic-zero-init-of.patch [RHEL-99888] - kvm-hw-audio-sb16-skip-automatic-zero-init-of-large-arra.patch [RHEL-99888] - kvm-hw-audio-via-ac97-skip-automatic-zero-init-of-large-.patch [RHEL-99888] - kvm-hw-char-sclpconsole-lm-skip-automatic-zero-init-of-l.patch [RHEL-99888] - kvm-hw-dma-xlnx_csu_dma-skip-automatic-zero-init-of-larg.patch [RHEL-99888] - kvm-hw-display-vmware_vga-skip-automatic-zero-init-of-la.patch [RHEL-99888] - kvm-hw-hyperv-syndbg-skip-automatic-zero-init-of-large-a.patch [RHEL-99888] - kvm-hw-misc-aspeed_hace-skip-automatic-zero-init-of-larg.patch [RHEL-99888] - kvm-hw-net-rtl8139-skip-automatic-zero-init-of-large-arr.patch [RHEL-99888] - kvm-hw-net-tulip-skip-automatic-zero-init-of-large-array.patch [RHEL-99888] - kvm-hw-net-virtio-net-skip-automatic-zero-init-of-large-.patch [RHEL-99888] - kvm-hw-net-xgamc-skip-automatic-zero-init-of-large-array.patch [RHEL-99888] - kvm-hw-nvme-ctrl-skip-automatic-zero-init-of-large-array.patch [RHEL-99888] - kvm-hw-ppc-spapr_tpm_proxy-skip-automatic-zero-init-of-l.patch [RHEL-99888] - kvm-hw-usb-hcd-ohci-skip-automatic-zero-init-of-large-ar.patch [RHEL-99888] - kvm-hw-scsi-lsi53c895a-skip-automatic-zero-init-of-large.patch [RHEL-99888] - kvm-hw-scsi-megasas-skip-automatic-zero-init-of-large-ar.patch [RHEL-99888] - kvm-hw-ufs-lu-skip-automatic-zero-init-of-large-array.patch [RHEL-99888] - kvm-net-socket-skip-automatic-zero-init-of-large-array.patch [RHEL-99888] - kvm-net-stream-skip-automatic-zero-init-of-large-array.patch [RHEL-99888] - kvm-ui-vnc-Update-display-update-interval-when-VM-state-.patch [RHEL-100741] - Resolves: RHEL-98554 ([s390x][RHEL9.7.0][virtio_block] there would be memory leak with virtio_blk disks) - Resolves: RHEL-66202 ([AMDSERVER 9.6 Feature] qemu: Interrupt Remap support for emulated amd viommu) - Resolves: RHEL-67104 (postcopy on the destination host can't switch into pause status under the network issue if boot VM with '-S') - Resolves: RHEL-52649 ([AMDSERVER 9.6 Feature] Turin: Qemu EPYC-Turin Model) - Resolves: RHEL-70926 (Qemu/amd-iommu: Advertise a suitable device id) - Resolves: RHEL-70925 (Qemu/amd-iommu: Add ability to manually specify the AMDVI-PCI device) - Resolves: RHEL-99888 (-ftrivial-auto-var-init=zero reduced performance [rhel-9]) - Resolves: RHEL-100741 (Video stuck after switchover phase when play one video during migration [rhel-9])
142 lines
5.4 KiB
Diff
142 lines
5.4 KiB
Diff
From 17af9176a1fff5af0d4c1bf1beb52228f7fc324d Mon Sep 17 00:00:00 2001
|
|
From: Juraj Marcin <jmarcin@redhat.com>
|
|
Date: Wed, 21 May 2025 15:52:32 +0200
|
|
Subject: [PATCH 10/57] util/qemu-sockets: Refactor success and failure paths
|
|
in inet_listen_saddr()
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
RH-Author: Juraj Marcin <None>
|
|
RH-MergeRequest: 369: util/qemu-sockets: Introduce inet socket options controlling TCP keep-alive
|
|
RH-Jira: RHEL-67104
|
|
RH-Acked-by: Peter Xu <peterx@redhat.com>
|
|
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
RH-Commit: [3/7] 5d5f0e704cdf3454a3c402ea7b130aa42705eb9f (JurajMarcin/centos-src-qemu-kvm)
|
|
|
|
To get a listening socket, we need to first create a socket, try binding
|
|
it to a certain port, and lastly starting listening to it. Each of these
|
|
operations can fail due to various reasons, one of them being that the
|
|
requested address/port is already in use. In such case, the function
|
|
tries the same process with a new port number.
|
|
|
|
This patch refactors the port number loop, so the success path is no
|
|
longer buried inside the 'if' statements in the middle of the loop. Now,
|
|
the success path is not nested and ends at the end of the iteration
|
|
after successful socket creation, binding, and listening. In case any of
|
|
the operations fails, it either continues to the next iteration (and the
|
|
next port) or jumps out of the loop to handle the error and exits the
|
|
function.
|
|
|
|
Signed-off-by: Juraj Marcin <jmarcin@redhat.com>
|
|
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
|
|
|
|
(cherry picked from commit 911e0f2c6e2d00c985affa75ec188c8edcf480f2)
|
|
|
|
JIRA: https://issues.redhat.com/browse/RHEL-67104
|
|
|
|
Signed-off-by: Juraj Marcin <jmarcin@redhat.com>
|
|
---
|
|
util/qemu-sockets.c | 51 ++++++++++++++++++++++++---------------------
|
|
1 file changed, 27 insertions(+), 24 deletions(-)
|
|
|
|
diff --git a/util/qemu-sockets.c b/util/qemu-sockets.c
|
|
index 2c0e4883ce..631d0c4023 100644
|
|
--- a/util/qemu-sockets.c
|
|
+++ b/util/qemu-sockets.c
|
|
@@ -303,11 +303,20 @@ static int inet_listen_saddr(InetSocketAddress *saddr,
|
|
port_min = inet_getport(e);
|
|
port_max = saddr->has_to ? saddr->to + port_offset : port_min;
|
|
for (p = port_min; p <= port_max; p++) {
|
|
+ if (slisten >= 0) {
|
|
+ /*
|
|
+ * We have a socket we tried with the previous port. It cannot
|
|
+ * be rebound, we need to close it and create a new one.
|
|
+ */
|
|
+ close(slisten);
|
|
+ slisten = -1;
|
|
+ }
|
|
inet_setport(e, p);
|
|
|
|
slisten = create_fast_reuse_socket(e);
|
|
if (slisten < 0) {
|
|
- /* First time we expect we might fail to create the socket
|
|
+ /*
|
|
+ * First time we expect we might fail to create the socket
|
|
* eg if 'e' has AF_INET6 but ipv6 kmod is not loaded.
|
|
* Later iterations should always succeed if first iteration
|
|
* worked though, so treat that as fatal.
|
|
@@ -317,40 +326,38 @@ static int inet_listen_saddr(InetSocketAddress *saddr,
|
|
} else {
|
|
error_setg_errno(errp, errno,
|
|
"Failed to recreate failed listening socket");
|
|
- goto listen_failed;
|
|
+ goto fail;
|
|
}
|
|
}
|
|
socket_created = true;
|
|
|
|
rc = try_bind(slisten, saddr, e);
|
|
if (rc < 0) {
|
|
- if (errno != EADDRINUSE) {
|
|
- error_setg_errno(errp, errno, "Failed to bind socket");
|
|
- goto listen_failed;
|
|
- }
|
|
- } else {
|
|
- if (!listen(slisten, num)) {
|
|
- goto listen_ok;
|
|
+ if (errno == EADDRINUSE) {
|
|
+ /* This port is already used, try the next one */
|
|
+ continue;
|
|
}
|
|
- if (errno != EADDRINUSE) {
|
|
- error_setg_errno(errp, errno, "Failed to listen on socket");
|
|
- goto listen_failed;
|
|
+ error_setg_errno(errp, errno, "Failed to bind socket");
|
|
+ goto fail;
|
|
+ }
|
|
+ if (listen(slisten, num)) {
|
|
+ if (errno == EADDRINUSE) {
|
|
+ /* This port is already used, try the next one */
|
|
+ continue;
|
|
}
|
|
+ error_setg_errno(errp, errno, "Failed to listen on socket");
|
|
+ goto fail;
|
|
}
|
|
- /* Someone else managed to bind to the same port and beat us
|
|
- * to listen on it! Socket semantics does not allow us to
|
|
- * recover from this situation, so we need to recreate the
|
|
- * socket to allow bind attempts for subsequent ports:
|
|
- */
|
|
- close(slisten);
|
|
- slisten = -1;
|
|
+ /* We have a listening socket */
|
|
+ freeaddrinfo(res);
|
|
+ return slisten;
|
|
}
|
|
}
|
|
error_setg_errno(errp, errno,
|
|
socket_created ?
|
|
"Failed to find an available port" :
|
|
"Failed to create a socket");
|
|
-listen_failed:
|
|
+fail:
|
|
saved_errno = errno;
|
|
if (slisten >= 0) {
|
|
close(slisten);
|
|
@@ -358,10 +365,6 @@ listen_failed:
|
|
freeaddrinfo(res);
|
|
errno = saved_errno;
|
|
return -1;
|
|
-
|
|
-listen_ok:
|
|
- freeaddrinfo(res);
|
|
- return slisten;
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
--
|
|
2.39.3
|
|
|