domain_conf: remove union for one member from redirdev struct

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@redhat.com>
This commit is contained in:
Pavel Hrdina 2016-10-24 14:24:51 +02:00
parent ccd5665fb1
commit e4501244a0
4 changed files with 15 additions and 18 deletions

View File

@ -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)

View File

@ -1517,9 +1517,7 @@ typedef enum {
struct _virDomainRedirdevDef {
int bus; /* enum virDomainRedirdevBus */
union {
virDomainChrSourceDefPtr chr;
} source;
virDomainChrSourceDefPtr source;
virDomainDeviceInfo info; /* Guest address */
};

View File

@ -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;

View File

@ -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;