[PATCH 06/24] qemu: domain: Refactor chardev definition preparing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use the qemuDomainDeviceBackendChardevForeach helper to iterate all
eligible structs and convert the setup of the TLS defaults from the
config.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_domain.c  | 103 +++++++++++++++++++---------------------
 src/qemu/qemu_domain.h  |  13 ++---
 src/qemu/qemu_driver.c  |   7 +++
 src/qemu/qemu_hotplug.c |   3 --
 src/qemu/qemu_process.c |  23 ++++++++-
 5 files changed, 85 insertions(+), 64 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index cbaa39b618..550afca36e 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -9720,66 +9720,63 @@ qemuDomainPrepareChannel(virDomainChrDef *channel,
 }


-/* qemuDomainPrepareChardevSourceTLS:
- * @source: pointer to host interface data for char devices
- * @cfg: driver configuration
- *
- * Updates host interface TLS encryption setting based on qemu.conf
- * for char devices.  This will be presented as "tls='yes|no'" in
- * live XML of a guest.
- */
-void
-qemuDomainPrepareChardevSourceTLS(virDomainChrSourceDef *source,
-                                  virQEMUDriverConfig *cfg)
-{
-    if (source->type == VIR_DOMAIN_CHR_TYPE_TCP) {
-        if (source->data.tcp.haveTLS == VIR_TRISTATE_BOOL_ABSENT) {
-            if (cfg->chardevTLS)
-                source->data.tcp.haveTLS = VIR_TRISTATE_BOOL_YES;
-            else
-                source->data.tcp.haveTLS = VIR_TRISTATE_BOOL_NO;
-            source->data.tcp.tlsFromConfig = true;
-        }
-    }
-}
-
-
-/* qemuDomainPrepareChardevSource:
- * @def: live domain definition
- * @cfg: driver configuration
+/* qemuDomainPrepareChardevSourceOne:
+ * @dev: device definition
+ * @charsrc: chardev source definition
+ * @opaque: pointer to struct qemuDomainPrepareChardevSourceData
  *
- * Iterate through all devices that use virDomainChrSourceDef *as host
- * interface part.
+ * Updates the config of a chardev source based on the qemu driver configuration.
+ * Note that this is meant to be called via
+ * qemuDomainDeviceBackendChardevForeach(One).
  */
-void
-qemuDomainPrepareChardevSource(virDomainDef *def,
-                               virQEMUDriverConfig *cfg)
+int
+qemuDomainPrepareChardevSourceOne(virDomainDeviceDef *dev,
+                                  virDomainChrSourceDef *charsrc,
+                                  void *opaque)
 {
-    size_t i;
-
-    for (i = 0; i < def->nserials; i++)
-        qemuDomainPrepareChardevSourceTLS(def->serials[i]->source, cfg);
-
-    for (i = 0; i < def->nparallels; i++)
-        qemuDomainPrepareChardevSourceTLS(def->parallels[i]->source, cfg);
+    struct qemuDomainPrepareChardevSourceData *data = opaque;

-    for (i = 0; i < def->nchannels; i++)
-        qemuDomainPrepareChardevSourceTLS(def->channels[i]->source, cfg);
-
-    for (i = 0; i < def->nconsoles; i++)
-        qemuDomainPrepareChardevSourceTLS(def->consoles[i]->source, cfg);
+    switch ((virDomainDeviceType) dev->type) {

-    for (i = 0; i < def->nrngs; i++)
-        if (def->rngs[i]->backend == VIR_DOMAIN_RNG_BACKEND_EGD)
-            qemuDomainPrepareChardevSourceTLS(def->rngs[i]->source.chardev, cfg);
+    case VIR_DOMAIN_DEVICE_CHR:
+    case VIR_DOMAIN_DEVICE_RNG:
+    case VIR_DOMAIN_DEVICE_SMARTCARD:
+    case VIR_DOMAIN_DEVICE_REDIRDEV:
+        if (charsrc->type == VIR_DOMAIN_CHR_TYPE_TCP) {
+            if (charsrc->data.tcp.haveTLS == VIR_TRISTATE_BOOL_ABSENT) {
+                charsrc->data.tcp.haveTLS = virTristateBoolFromBool(data->cfg->chardevTLS);
+                charsrc->data.tcp.tlsFromConfig = true;
+            }
+        }
+        break;

-    for (i = 0; i < def->nsmartcards; i++)
-        if (def->smartcards[i]->type == VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH)
-            qemuDomainPrepareChardevSourceTLS(def->smartcards[i]->data.passthru,
-                                              cfg);
+    case VIR_DOMAIN_DEVICE_DISK:
+    case VIR_DOMAIN_DEVICE_NET:
+    case VIR_DOMAIN_DEVICE_SHMEM:
+    case VIR_DOMAIN_DEVICE_LEASE:
+    case VIR_DOMAIN_DEVICE_FS:
+    case VIR_DOMAIN_DEVICE_INPUT:
+    case VIR_DOMAIN_DEVICE_SOUND:
+    case VIR_DOMAIN_DEVICE_VIDEO:
+    case VIR_DOMAIN_DEVICE_HOSTDEV:
+    case VIR_DOMAIN_DEVICE_WATCHDOG:
+    case VIR_DOMAIN_DEVICE_CONTROLLER:
+    case VIR_DOMAIN_DEVICE_GRAPHICS:
+    case VIR_DOMAIN_DEVICE_HUB:
+    case VIR_DOMAIN_DEVICE_NONE:
+    case VIR_DOMAIN_DEVICE_MEMBALLOON:
+    case VIR_DOMAIN_DEVICE_NVRAM:
+    case VIR_DOMAIN_DEVICE_TPM:
+    case VIR_DOMAIN_DEVICE_PANIC:
+    case VIR_DOMAIN_DEVICE_LAST:
+    case VIR_DOMAIN_DEVICE_MEMORY:
+    case VIR_DOMAIN_DEVICE_IOMMU:
+    case VIR_DOMAIN_DEVICE_VSOCK:
+    case VIR_DOMAIN_DEVICE_AUDIO:
+        break;
+    }

-    for (i = 0; i < def->nredirdevs; i++)
-        qemuDomainPrepareChardevSourceTLS(def->redirdevs[i]->source, cfg);
+    return 0;
 }


diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 61704fdae7..f84acf408b 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -864,13 +864,14 @@ int qemuDomainPrepareChannel(virDomainChrDef *chr,
                              const char *domainChannelTargetDir)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);

-void qemuDomainPrepareChardevSourceTLS(virDomainChrSourceDef *source,
-                                       virQEMUDriverConfig *cfg)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+struct qemuDomainPrepareChardevSourceData {
+    virQEMUDriverConfig *cfg;
+};

-void qemuDomainPrepareChardevSource(virDomainDef *def,
-                                    virQEMUDriverConfig *cfg)
-    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+int
+qemuDomainPrepareChardevSourceOne(virDomainDeviceDef *dev,
+                                  virDomainChrSourceDef *charsrc,
+                                  void *opaque);

 void  qemuDomainPrepareShmemChardev(virDomainShmemDef *shmem)
     ATTRIBUTE_NONNULL(1);
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 8093b8f69b..10feb606ad 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -6793,6 +6793,13 @@ qemuDomainAttachDeviceLive(virDomainObj *vm,
 {
     int ret = -1;
     const char *alias = NULL;
+    g_autoptr(virQEMUDriverConfig) cfg = virQEMUDriverGetConfig(driver);
+    struct qemuDomainPrepareChardevSourceData chardevBackendData = { .cfg = cfg };
+
+    if (qemuDomainDeviceBackendChardevForeachOne(dev,
+                                                 qemuDomainPrepareChardevSourceOne,
+                                                 &chardevBackendData) < 0)
+        return -1;

     switch ((virDomainDeviceType)dev->type) {
     case VIR_DOMAIN_DEVICE_DISK:
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 2e1d18c633..66961eba70 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1852,9 +1852,6 @@ qemuDomainAddChardevTLSObjects(virQEMUDriver *driver,
     g_autoptr(virJSONValue) tlsProps = NULL;
     g_autoptr(virJSONValue) secProps = NULL;

-    /* NB: This may alter haveTLS based on cfg */
-    qemuDomainPrepareChardevSourceTLS(dev, cfg);
-
     if (dev->type != VIR_DOMAIN_CHR_TYPE_TCP ||
         dev->data.tcp.haveTLS != VIR_TRISTATE_BOOL_YES)
         return 0;
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 866b6b9ed6..be49cc9360 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6498,6 +6498,24 @@ qemuProcessUpdateSEVInfo(virDomainObj *vm)
 }


+/* qemuProcessPrepareChardevSource:
+ * @def: live domain definition
+ * @cfg: driver configuration
+ *
+ * Iterate through all devices that use virDomainChrSourceDef as backend.
+ */
+static int
+qemuProcessPrepareChardevSource(virDomainDef *def,
+                                virQEMUDriverConfig *cfg)
+{
+    struct qemuDomainPrepareChardevSourceData data = { .cfg = cfg };
+
+    return qemuDomainDeviceBackendChardevForeach(def,
+                                                 qemuDomainPrepareChardevSourceOne,
+                                                 &data);
+}
+
+
 /**
  * qemuProcessPrepareDomain:
  * @driver: qemu driver
@@ -6586,8 +6604,9 @@ qemuProcessPrepareDomain(virQEMUDriver *driver,
     if (qemuProcessPrepareDomainHostdevs(vm, priv) < 0)
         return -1;

-    VIR_DEBUG("Prepare chardev source backends for TLS");
-    qemuDomainPrepareChardevSource(vm->def, cfg);
+    VIR_DEBUG("Prepare chardev source backends");
+    if (qemuProcessPrepareChardevSource(vm->def, cfg) < 0)
+        return -1;

     VIR_DEBUG("Prepare device secrets");
     if (qemuDomainSecretPrepare(driver, vm) < 0)
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux