]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: domain: Add helper for generating 'fdset' ids for VM startup
authorPeter Krempa <pkrempa@redhat.com>
Mon, 24 Jan 2022 15:53:27 +0000 (16:53 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 14 Feb 2022 12:13:59 +0000 (13:13 +0100)
When starting a VM we must assign unique IDs for fdsets we add via
'-add-fd'. For now it was done by using the index of the filedescriptor
passed to the virCommand. That approach is not very flexible, because
you need to have already passed the 'fd' to virCommand before generating
the fdset path, and also won't nicely work with fdsets containing two or
more fds.

This patch introduces a counter into the private data of a qemu domain
so that we can allocate unique ids without relying on virCommand.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_domain.c
src/qemu/qemu_domain.h

index ee1cf6f9bbcf33f990db7af2e2d5abf55e734306..c096e5bb9ab24733b0cd3641a98af14420edc961 100644 (file)
@@ -683,6 +683,33 @@ qemuDomainStorageIDReset(qemuDomainObjPrivate *priv)
 }
 
 
+/**
+ * qemuDomainFDSetIDNew:
+ * @priv: qemu VM private data object.
+ *
+ * Generate a new unique id for a fdset. Note that this is necessary only for
+ * startup. When running qemu auto-assigns id for added fdset.
+ */
+unsigned int
+qemuDomainFDSetIDNew(qemuDomainObjPrivate *priv)
+{
+    return priv->fdsetindex++;
+}
+
+
+/**
+ * qemuDomainFDSetIDReset:
+ * @priv: qemu VM private data object.
+ *
+ * Resets the data for the fdset ID generator.
+ */
+static void
+qemuDomainFDSetIDReset(qemuDomainObjPrivate *priv)
+{
+    priv->fdsetindex = 0;
+}
+
+
 static void
 qemuDomainSecretInfoClear(qemuDomainSecretInfo *secinfo,
                           bool keepAlias)
@@ -1683,6 +1710,8 @@ qemuDomainObjPrivateDataClear(qemuDomainObjPrivate *priv)
     /* reset node name allocator */
     qemuDomainStorageIDReset(priv);
 
+    qemuDomainFDSetIDReset(priv);
+
     priv->dbusDaemonRunning = false;
 
     if (priv->dbusVMStateIds)
index 0a9d312b65d78d53d44aad6440feb386560355c8..52b500f2946dbf8761d26e72b8e0774d30c8dc44 100644 (file)
@@ -207,6 +207,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 */
+    unsigned int fdsetindex;
+
     /* qemuProcessStartCPUs stores the reason for starting vCPUs here for the
      * RESUME event handler to use it */
     virDomainRunningReason runningReason;
@@ -969,6 +972,8 @@ char * qemuDomainGetManagedPRSocketPath(qemuDomainObjPrivate *priv);
 
 bool qemuDomainDefHasManagedPR(virDomainObj *vm);
 
+unsigned int qemuDomainFDSetIDNew(qemuDomainObjPrivate *priv);
+
 virDomainEventResumedDetailType
 qemuDomainRunningReasonToResumeEvent(virDomainRunningReason reason);