[PATCH 1/3] qemu_hotplug: remove union for one member

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

 



Currently the union has only one member so remove that union.  If there
is a need to add a new type of source for new bus in the future this
will force the author to add a union and properly check bus type before
any access to union member.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/conf/domain_conf.c  | 23 +++++++++++------------
 src/conf/domain_conf.h  |  4 +---
 src/qemu/qemu_command.c |  2 +-
 src/qemu/qemu_hotplug.c |  4 ++--
 4 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index fd71e88..35cdbc3 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2363,7 +2363,7 @@ void virDomainRedirdevDefFree(virDomainRedirdevDefPtr def)
     if (!def)
         return;
 
-    virDomainChrSourceDefFree(def->source.chr);
+    virDomainChrSourceDefFree(def->source);
     virDomainDeviceInfoClear(&def->info);
 
     VIR_FREE(def);
@@ -12986,7 +12986,7 @@ virDomainRedirdevDefParseXML(virDomainXMLOptionPtr xmlopt,
     if (VIR_ALLOC(def) < 0)
         return NULL;
 
-    if (!(def->source.chr = virDomainChrSourceDefNew(xmlopt)))
+    if (!(def->source = virDomainChrSourceDefNew(xmlopt)))
         goto error;
 
     bus = virXMLPropString(node, "bus");
@@ -13002,7 +13002,7 @@ virDomainRedirdevDefParseXML(virDomainXMLOptionPtr xmlopt,
 
     type = virXMLPropString(node, "type");
     if (type) {
-        if ((def->source.chr->type = virDomainChrTypeFromString(type)) < 0) {
+        if ((def->source->type = virDomainChrTypeFromString(type)) < 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("unknown redirdev character device type '%s'"), type);
             goto error;
@@ -13017,13 +13017,13 @@ virDomainRedirdevDefParseXML(virDomainXMLOptionPtr xmlopt,
     /* boot gets parsed in virDomainDeviceInfoParseXML
      * source gets parsed in virDomainChrSourceDefParseXML
      * we don't know any of the elements that might remain */
-    remaining = virDomainChrSourceDefParseXML(def->source.chr, cur, flags,
+    remaining = virDomainChrSourceDefParseXML(def->source, cur, flags,
                                               NULL, NULL, NULL, 0);
     if (remaining < 0)
         goto error;
 
-    if (def->source.chr->type == VIR_DOMAIN_CHR_TYPE_SPICEVMC)
-        def->source.chr->data.spicevmc = VIR_DOMAIN_CHR_SPICEVMC_USBREDIR;
+    if (def->source->type == VIR_DOMAIN_CHR_TYPE_SPICEVMC)
+        def->source->data.spicevmc = VIR_DOMAIN_CHR_SPICEVMC_USBREDIR;
 
     if (virDomainDeviceInfoParseXML(node, bootHash, &def->info,
                                     flags | VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT) < 0)
@@ -14853,8 +14853,7 @@ virDomainRedirdevDefFind(virDomainDefPtr def,
         if (redirdev->bus != tmp->bus)
             continue;
 
-        if (!virDomainChrSourceDefIsEqual(redirdev->source.chr,
-                                          tmp->source.chr))
+        if (!virDomainChrSourceDefIsEqual(redirdev->source, tmp->source))
             continue;
 
         if (redirdev->info.type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE &&
@@ -18670,12 +18669,12 @@ virDomainRedirdevDefCheckABIStability(virDomainRedirdevDefPtr src,
 
     switch ((virDomainRedirdevBus) src->bus) {
     case VIR_DOMAIN_REDIRDEV_BUS_USB:
-        if (src->source.chr->type != dst->source.chr->type) {
+        if (src->source->type != dst->source->type) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("Target redirected device source type %s does "
                              "not match source device source type %s"),
-                           virDomainChrTypeToString(dst->source.chr->type),
-                           virDomainChrTypeToString(src->source.chr->type));
+                           virDomainChrTypeToString(dst->source->type),
+                           virDomainChrTypeToString(src->source->type));
             return false;
         }
         break;
@@ -22748,7 +22747,7 @@ virDomainRedirdevDefFormat(virBufferPtr buf,
 
     virBufferAsprintf(buf, "<redirdev bus='%s'", bus);
     virBufferAdjustIndent(buf, 2);
-    if (virDomainChrSourceDefFormat(buf, NULL, def->source.chr, false, flags) < 0)
+    if (virDomainChrSourceDefFormat(buf, NULL, def->source, false, flags) < 0)
         return -1;
     if (virDomainDeviceInfoFormat(buf, &def->info,
                                   flags | VIR_DOMAIN_DEF_FORMAT_ALLOW_BOOT) < 0)
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 36c2fa5..7fc1141 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1517,9 +1517,7 @@ typedef enum {
 struct _virDomainRedirdevDef {
     int bus; /* enum virDomainRedirdevBus */
 
-    union {
-        virDomainChrSourceDefPtr chr;
-    } source;
+    virDomainChrSourceDefPtr source;
 
     virDomainDeviceInfo info; /* Guest address */
 };
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 167ab66..5713d18 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8833,7 +8833,7 @@ qemuBuildRedirdevCommandLine(virLogManagerPtr logManager,
         char *devstr;
 
         if (!(devstr = qemuBuildChrChardevStr(logManager, cmd, cfg, def,
-                                              redirdev->source.chr,
+                                              redirdev->source,
                                               redirdev->info.alias,
                                               qemuCaps, true))) {
             return -1;
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 95b2f2a..706b736 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1529,7 +1529,7 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver,
     if (VIR_REALLOC_N(def->redirdevs, def->nredirdevs+1) < 0)
         goto cleanup;
 
-    if (qemuDomainGetChardevTLSObjects(cfg, priv, redirdev->source.chr,
+    if (qemuDomainGetChardevTLSObjects(cfg, priv, redirdev->source,
                                        charAlias, &tlsProps, &tlsAlias) < 0)
         goto cleanup;
 
@@ -1545,7 +1545,7 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver,
 
     if (qemuMonitorAttachCharDev(priv->mon,
                                  charAlias,
-                                 redirdev->source.chr) < 0)
+                                 redirdev->source) < 0)
         goto exit_monitor;
     chardevAdded = true;
 
-- 
2.10.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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]