While 'add-fd' qmp command gives the possibility to find an unused fdset
ID when hot-adding fdsets, such usage is extremely inconvenient.
This patch allows us to track the used fdset id so that we can avoid the
need to check results and thus employ simpler code flow when hot-adding
devices which use FD passing.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_domain.c | 5 +++
src/qemu/qemu_domain.h | 3 +-
src/qemu/qemu_process.c | 31 +++++++++++++++++++
.../qemustatusxml2xmldata/backup-pull-in.xml | 1 +
.../blockjob-blockdev-in.xml | 1 +
.../blockjob-mirror-in.xml | 1 +
.../migration-in-params-in.xml | 1 +
.../migration-out-nbd-bitmaps-in.xml | 1 +
.../migration-out-nbd-out.xml | 1 +
.../migration-out-nbd-tls-out.xml | 1 +
.../migration-out-params-in.xml | 1 +
tests/qemustatusxml2xmldata/modern-in.xml | 1 +
tests/qemustatusxml2xmldata/upgrade-out.xml | 1 +
.../qemustatusxml2xmldata/vcpus-multi-in.xml | 1 +
14 files changed, 49 insertions(+), 1 deletion(-)
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 7974cdb00b..a726e2624a 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2372,6 +2372,8 @@ qemuDomainObjPrivateXMLFormat(virBuffer *buf,
if (virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV))
virBufferAsprintf(buf, "<nodename index='%llu'/>\n",
priv->nodenameindex);
+ virBufferAsprintf(buf, "<fdset index='%u'/>\n",
priv->fdsetindex);
+
if (priv->memPrealloc)
virBufferAddLit(buf, "<memPrealloc/>\n");
@@ -3100,6 +3102,9 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
goto error;
}
+ if (virXPathUInt("string(./fdset/@index)", ctxt, &priv->fdsetindex)
== 0)
+ priv->fdsetindexParsed = true;
+
priv->memPrealloc = virXPathBoolean("boolean(./memPrealloc)", ctxt) ==
1;
return 0;
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index c7125722e0..358f1c163f 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -204,8 +204,9 @@ struct _qemuDomainObjPrivate {
/* counter for generating node names for qemu disks */
unsigned long long nodenameindex;
- /* counter for generating IDs of fdsets - only relevant during startup */
+ /* counter for generating IDs of fdsets */
unsigned int fdsetindex;
+ bool fdsetindexParsed;
/* qemuProcessStartCPUs stores the reason for starting vCPUs here for the
* RESUME event handler to use it */
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 39ed10ee41..be10d2f3ac 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -2261,6 +2261,34 @@ qemuRefreshPRManagerState(virQEMUDriver *driver,
}
+static int
+qemuProcessRefreshFdsetIndex(virDomainObj *vm)
+{
+ qemuDomainObjPrivate *priv = vm->privateData;
+ g_autoptr(qemuMonitorFdsets) fdsets = NULL;
+ size_t i;
+ int rc;
+
+ /* if the previous index was in the status XML we don't need to update it */
+ if (priv->fdsetindexParsed)
+ return 0;
+
+ qemuDomainObjEnterMonitor(priv->driver, vm);
+ rc = qemuMonitorQueryFdsets(priv->mon, &fdsets);
+ qemuDomainObjExitMonitor(vm);
+
+ if (rc < 0)
+ return -1;
+
+ for (i = 0; i < fdsets->nfdsets; i++) {
+ if (fdsets->fdsets[i].id >= priv->fdsetindex)
+ priv->fdsetindex = fdsets->fdsets[i].id + 1;
+ }
+
+ return 0;
+}
+
+
static void
qemuRefreshRTC(virQEMUDriver *driver,
virDomainObj *vm)
@@ -8923,6 +8951,9 @@ qemuProcessReconnect(void *opaque)
if (qemuRefreshPRManagerState(driver, obj) < 0)
goto error;
+ if (qemuProcessRefreshFdsetIndex(obj) < 0)
+ goto error;
+
qemuProcessReconnectCheckMemAliasOrderMismatch(obj);
if (qemuConnectAgent(driver, obj) < 0)
diff --git a/tests/qemustatusxml2xmldata/backup-pull-in.xml
b/tests/qemustatusxml2xmldata/backup-pull-in.xml
index 59c934d4f7..e7fdc6c478 100644
--- a/tests/qemustatusxml2xmldata/backup-pull-in.xml
+++ b/tests/qemustatusxml2xmldata/backup-pull-in.xml
@@ -234,6 +234,7 @@
<chardevStdioLogd/>
<allowReboot value='yes'/>
<nodename index='0'/>
+ <fdset index='0'/>
<blockjobs active='yes'>
<blockjob name='backup-vda-libvirt-3-format' type='backup'
state='running' jobflags='0x0'>
<disk dst='vda'/>
diff --git a/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml
b/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml
index 52024f242c..b62b3149c2 100644
--- a/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml
+++ b/tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml
@@ -233,6 +233,7 @@
<chardevStdioLogd/>
<allowReboot value='yes'/>
<nodename index='0'/>
+ <fdset index='0'/>
<blockjobs active='yes'>
<blockjob name='broken-test' type='broken' state='ready'
brokentype='commit'/>
<blockjob name='commit-vdc-libvirt-9-format' type='commit'
state='running' jobflags='0x0'>
diff --git a/tests/qemustatusxml2xmldata/blockjob-mirror-in.xml
b/tests/qemustatusxml2xmldata/blockjob-mirror-in.xml
index 00c8e69adc..73fe437f87 100644
--- a/tests/qemustatusxml2xmldata/blockjob-mirror-in.xml
+++ b/tests/qemustatusxml2xmldata/blockjob-mirror-in.xml
@@ -22,6 +22,7 @@
<libDir path='/tmp'/>
<channelTargetDir path='/tmp/channel'/>
<allowReboot value='yes'/>
+ <fdset index='0'/>
<blockjobs active='yes'/>
<agentTimeout>-2</agentTimeout>
<domain type='qemu' id='1'>
diff --git a/tests/qemustatusxml2xmldata/migration-in-params-in.xml
b/tests/qemustatusxml2xmldata/migration-in-params-in.xml
index f4bc5753c4..8b0878c82e 100644
--- a/tests/qemustatusxml2xmldata/migration-in-params-in.xml
+++ b/tests/qemustatusxml2xmldata/migration-in-params-in.xml
@@ -256,6 +256,7 @@
<channelTargetDir
path='/var/lib/libvirt/qemu/channel/target/domain-1-nest'/>
<chardevStdioLogd/>
<allowReboot value='yes'/>
+ <fdset index='0'/>
<blockjobs active='no'/>
<agentTimeout>-2</agentTimeout>
<domain type='kvm' id='1'>
diff --git a/tests/qemustatusxml2xmldata/migration-out-nbd-bitmaps-in.xml
b/tests/qemustatusxml2xmldata/migration-out-nbd-bitmaps-in.xml
index c88996f923..7d55db0996 100644
--- a/tests/qemustatusxml2xmldata/migration-out-nbd-bitmaps-in.xml
+++ b/tests/qemustatusxml2xmldata/migration-out-nbd-bitmaps-in.xml
@@ -343,6 +343,7 @@
<rememberOwner/>
<allowReboot value='yes'/>
<nodename index='3'/>
+ <fdset index='0'/>
<blockjobs active='yes'>
<blockjob name='drive-virtio-disk0' type='copy'
state='ready' jobflags='0x0'>
<disk dst='vda'/>
diff --git a/tests/qemustatusxml2xmldata/migration-out-nbd-out.xml
b/tests/qemustatusxml2xmldata/migration-out-nbd-out.xml
index 039dcacc58..1a918c0b5a 100644
--- a/tests/qemustatusxml2xmldata/migration-out-nbd-out.xml
+++ b/tests/qemustatusxml2xmldata/migration-out-nbd-out.xml
@@ -259,6 +259,7 @@
<channelTargetDir
path='/var/lib/libvirt/qemu/channel/target/domain-4-upstream'/>
<chardevStdioLogd/>
<allowReboot value='yes'/>
+ <fdset index='0'/>
<blockjobs active='no'/>
<agentTimeout>-2</agentTimeout>
<domain type='kvm' id='4'>
diff --git a/tests/qemustatusxml2xmldata/migration-out-nbd-tls-out.xml
b/tests/qemustatusxml2xmldata/migration-out-nbd-tls-out.xml
index 3d1ddd5771..87c67f8300 100644
--- a/tests/qemustatusxml2xmldata/migration-out-nbd-tls-out.xml
+++ b/tests/qemustatusxml2xmldata/migration-out-nbd-tls-out.xml
@@ -288,6 +288,7 @@
<channelTargetDir
path='/var/lib/libvirt/qemu/channel/target/domain-3-upstream'/>
<chardevStdioLogd/>
<allowReboot value='yes'/>
+ <fdset index='0'/>
<blockjobs active='no'/>
<agentTimeout>-2</agentTimeout>
<domain type='kvm' id='3'>
diff --git a/tests/qemustatusxml2xmldata/migration-out-params-in.xml
b/tests/qemustatusxml2xmldata/migration-out-params-in.xml
index cd9dbccd3a..73ac09fb92 100644
--- a/tests/qemustatusxml2xmldata/migration-out-params-in.xml
+++ b/tests/qemustatusxml2xmldata/migration-out-params-in.xml
@@ -270,6 +270,7 @@
<channelTargetDir
path='/var/lib/libvirt/qemu/channel/target/domain-7-nest'/>
<chardevStdioLogd/>
<allowReboot value='yes'/>
+ <fdset index='0'/>
<blockjobs active='no'/>
<agentTimeout>-2</agentTimeout>
<domain type='kvm' id='7'>
diff --git a/tests/qemustatusxml2xmldata/modern-in.xml
b/tests/qemustatusxml2xmldata/modern-in.xml
index cc5fd1cb74..7759034f7a 100644
--- a/tests/qemustatusxml2xmldata/modern-in.xml
+++ b/tests/qemustatusxml2xmldata/modern-in.xml
@@ -261,6 +261,7 @@
<chardevStdioLogd/>
<allowReboot value='yes'/>
<nodename index='123'/>
+ <fdset index='321'/>
<blockjobs active='no'/>
<agentTimeout>-2</agentTimeout>
<domain type='kvm' id='1'>
diff --git a/tests/qemustatusxml2xmldata/upgrade-out.xml
b/tests/qemustatusxml2xmldata/upgrade-out.xml
index 5218092cb9..ac2ffeddc2 100644
--- a/tests/qemustatusxml2xmldata/upgrade-out.xml
+++ b/tests/qemustatusxml2xmldata/upgrade-out.xml
@@ -258,6 +258,7 @@
<channelTargetDir
path='/var/lib/libvirt/qemu/channel/target/domain-1-upstream'/>
<chardevStdioLogd/>
<allowReboot value='yes'/>
+ <fdset index='0'/>
<blockjobs active='no'/>
<agentTimeout>-2</agentTimeout>
<domain type='kvm' id='1'>
diff --git a/tests/qemustatusxml2xmldata/vcpus-multi-in.xml
b/tests/qemustatusxml2xmldata/vcpus-multi-in.xml
index 7f0208453f..0b8bc37c15 100644
--- a/tests/qemustatusxml2xmldata/vcpus-multi-in.xml
+++ b/tests/qemustatusxml2xmldata/vcpus-multi-in.xml
@@ -308,6 +308,7 @@
<libDir path='/tmp'/>
<channelTargetDir path='/tmp/channel'/>
<allowReboot value='yes'/>
+ <fdset index='0'/>
<blockjobs active='no'/>
<agentTimeout>-2</agentTimeout>
<domain type='kvm' id='1729'>
--
2.35.1