diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 334152c4ff..7033b4e9fe 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6220,6 +6220,8 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, virDomainHostdevSubsysMediatedDev *mdevsrc = &def->source.subsys.u.mdev; virTristateBool managed; g_autofree char *model = NULL; + virDomainDeviceSGIO sgio; + virTristateBool rawio; int rv; /* @managed can be read from the xml document - it is always an @@ -6259,7 +6261,7 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, if ((rv = virXMLPropEnum(node, "sgio", virDomainDeviceSGIOTypeFromString, VIR_XML_PROP_NONZERO, - &scsisrc->sgio)) < 0) { + &sgio)) < 0) { return -1; } @@ -6269,18 +6271,30 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, _("sgio is only supported for scsi host device")); return -1; } + + /* Set sgio only after checking if hostdev type is 'scsi' to avoid + * clobbering other union structures. + */ + scsisrc->sgio = sgio; } if ((rv = virXMLPropTristateBool(node, "rawio", VIR_XML_PROP_NONE, - &scsisrc->rawio)) < 0) { + &rawio)) < 0) { return -1; } - if (rv > 0 && def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("rawio is only supported for scsi host device")); - return -1; + if (rv > 0) { + if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("rawio is only supported for scsi host device")); + return -1; + } + + /* Set rawio only after checking if hostdev type is 'scsi' to avoid + * clobbering other union structures. + */ + scsisrc->rawio = rawio; } if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV && diff --git a/tests/qemuxmlconfdata/hostdev-scsi-vhost-rawio-invalid.x86_64-latest.err b/tests/qemuxmlconfdata/hostdev-scsi-vhost-rawio-invalid.x86_64-latest.err new file mode 100644 index 0000000000..ddaf449658 --- /dev/null +++ b/tests/qemuxmlconfdata/hostdev-scsi-vhost-rawio-invalid.x86_64-latest.err @@ -0,0 +1 @@ +XML error: rawio is only supported for scsi host device diff --git a/tests/qemuxmlconfdata/hostdev-scsi-vhost-rawio-invalid.xml b/tests/qemuxmlconfdata/hostdev-scsi-vhost-rawio-invalid.xml new file mode 100644 index 0000000000..80760ab941 --- /dev/null +++ b/tests/qemuxmlconfdata/hostdev-scsi-vhost-rawio-invalid.xml @@ -0,0 +1,41 @@ + + QEMUGuest2 + c7a5fdbd-edaf-9466-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + +
+ + +
+ + +
+ + +
+ + + + + + + + +
+ + + diff --git a/tests/qemuxmlconfdata/hostdev-scsi-vhost-sgio-invalid.x86_64-latest.err b/tests/qemuxmlconfdata/hostdev-scsi-vhost-sgio-invalid.x86_64-latest.err new file mode 100644 index 0000000000..32256aad1c --- /dev/null +++ b/tests/qemuxmlconfdata/hostdev-scsi-vhost-sgio-invalid.x86_64-latest.err @@ -0,0 +1 @@ +XML error: sgio is only supported for scsi host device diff --git a/tests/qemuxmlconfdata/hostdev-scsi-vhost-sgio-invalid.xml b/tests/qemuxmlconfdata/hostdev-scsi-vhost-sgio-invalid.xml new file mode 100644 index 0000000000..c549bddc1d --- /dev/null +++ b/tests/qemuxmlconfdata/hostdev-scsi-vhost-sgio-invalid.xml @@ -0,0 +1,41 @@ + + QEMUGuest2 + c7a5fdbd-edaf-9466-926a-d65c16db1809 + 219100 + 219100 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-x86_64 + + + +
+ + +
+ + +
+ + +
+ + + + + + + + +
+ + + diff --git a/tests/qemuxmlconftest.c b/tests/qemuxmlconftest.c index 2ede8cd29d..4a711fceeb 100644 --- a/tests/qemuxmlconftest.c +++ b/tests/qemuxmlconftest.c @@ -2945,6 +2945,8 @@ mymain(void) DO_TEST_CAPS_LATEST("sound-device-virtio") DO_TEST_CAPS_LATEST_FAILURE("disk-network-iscsi-zero-hosts-invalid") + DO_TEST_CAPS_LATEST_PARSE_ERROR("hostdev-scsi-vhost-rawio-invalid") + DO_TEST_CAPS_LATEST_PARSE_ERROR("hostdev-scsi-vhost-sgio-invalid") /* check that all input files were actually used here */ if (testConfXMLCheck(existingTestCases) < 0)