]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: domain: Store and update 'fdsetindex' across libvirtd restarts
authorPeter Krempa <pkrempa@redhat.com>
Thu, 5 May 2022 13:45:55 +0000 (15:45 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 16 May 2022 07:15:45 +0000 (09:15 +0200)
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@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
14 files changed:
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h
src/qemu/qemu_process.c
tests/qemustatusxml2xmldata/backup-pull-in.xml
tests/qemustatusxml2xmldata/blockjob-blockdev-in.xml
tests/qemustatusxml2xmldata/blockjob-mirror-in.xml
tests/qemustatusxml2xmldata/migration-in-params-in.xml
tests/qemustatusxml2xmldata/migration-out-nbd-bitmaps-in.xml
tests/qemustatusxml2xmldata/migration-out-nbd-out.xml
tests/qemustatusxml2xmldata/migration-out-nbd-tls-out.xml
tests/qemustatusxml2xmldata/migration-out-params-in.xml
tests/qemustatusxml2xmldata/modern-in.xml
tests/qemustatusxml2xmldata/upgrade-out.xml
tests/qemustatusxml2xmldata/vcpus-multi-in.xml

index 4d4be0683a9f4d2cb6a030c42c2838c5ee335572..9d090204fed8d95ed32b413da2fa57150a191d0b 100644 (file)
@@ -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");
 
@@ -3106,6 +3108,9 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
         return -1;
     }
 
+    if (virXPathUInt("string(./fdset/@index)", ctxt, &priv->fdsetindex) == 0)
+        priv->fdsetindexParsed = true;
+
     priv->memPrealloc = virXPathBoolean("boolean(./memPrealloc)", ctxt) == 1;
 
     if (virXPathULongLong("string(./originalMemlock)",
index 248af9264947463be76f2a552681df1b79d8e1d7..3d1447178cb7cece88469d5f86226b21ed96749f 100644 (file)
@@ -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 */
index 3128d6cac073ec560f004bbab400e98f306c5965..a023e6eb4c626f080dbccf6f7a7fa2f5f915b5c9 100644 (file)
@@ -2265,6 +2265,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)
@@ -8928,6 +8956,9 @@ qemuProcessReconnect(void *opaque)
     if (qemuRefreshPRManagerState(driver, obj) < 0)
         goto error;
 
+    if (qemuProcessRefreshFdsetIndex(obj) < 0)
+        goto error;
+
     qemuProcessReconnectCheckMemAliasOrderMismatch(obj);
 
     if (qemuConnectAgent(driver, obj) < 0)
index 59c934d4f73a4ad6ef154f50a6e61f63c19195e0..e7fdc6c4783266a7a257a2cfa76e133795279d24 100644 (file)
   <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'/>
index 52024f242c6aace8170aad23b4ad5e457d68b6f7..b62b3149c23503d2cb60b68672f7801698afc29d 100644 (file)
   <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'>
index 00c8e69adceb3da1853829abab9c3f4d6d82d3f3..73fe437f87d0a1b01a249465b9f9c4d9b7358a51 100644 (file)
@@ -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'>
index f4bc5753c469d2e797068cf29b1d1fbd728e1711..8b0878c82e2812a800f8bf8e6d12e036c40673cb 100644 (file)
   <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'>
index c88996f923bf149265ff587787c7d52117afce41..7d55db0996af0d16fc75898a624a64e72f1083df 100644 (file)
   <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'/>
index 039dcacc58af62ab1ad9d79ad4ac602bb81c5e5f..1a918c0b5ae5bd1d47f25d97b1c352a3d742fd1c 100644 (file)
   <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'>
index 3d1ddd5771a9f3063c043f29507aee1761d61da0..87c67f83000933672e302866b16cf4ad1e3bc06d 100644 (file)
   <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'>
index cd9dbccd3a56ca7e57aa248ded6ebfcdebef07ad..73ac09fb920929e4146b4a038d42bfb7b8e075b7 100644 (file)
   <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'>
index cc5fd1cb74b6f7cc25576c794840a404cd0eda99..7759034f7a636637122a99d9d0f4bf3684a23b51 100644 (file)
   <chardevStdioLogd/>
   <allowReboot value='yes'/>
   <nodename index='123'/>
+  <fdset index='321'/>
   <blockjobs active='no'/>
   <agentTimeout>-2</agentTimeout>
   <domain type='kvm' id='1'>
index 5218092cb942b169f7e58101e1ba3e29ecf16fc7..ac2ffeddc22dacff95d066f75549138e8e850000 100644 (file)
   <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'>
index 7f0208453f1f04bd857c941a63d8e5ac048cfa17..0b8bc37c152f258c63095d6c723ac23ccb3930d9 100644 (file)
   <libDir path='/tmp'/>
   <channelTargetDir path='/tmp/channel'/>
   <allowReboot value='yes'/>
+  <fdset index='0'/>
   <blockjobs active='no'/>
   <agentTimeout>-2</agentTimeout>
   <domain type='kvm' id='1729'>