conf: Convert virDomainHostdevDefParseXMLSubsys() to virXMLProp*()

After previous cleanups, the virDomainHostdevDefParseXMLSubsys()
function uses a mixture of virXMLProp*() and the old
virXMLPropString() + virXXXTypeFromString() patterns. Rework it
so that virXMLProp*() is used.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2022-01-20 13:58:59 +01:00
parent af5a7dba78
commit bdb95b520c
7 changed files with 42 additions and 59 deletions

View File

@ -7293,14 +7293,12 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
virDomainXMLOption *xmlopt)
{
xmlNodePtr sourcenode;
int backend;
xmlNodePtr driver_node = NULL;
virDomainHostdevSubsysPCI *pcisrc = &def->source.subsys.u.pci;
virDomainHostdevSubsysSCSI *scsisrc = &def->source.subsys.u.scsi;
virDomainHostdevSubsysSCSIVHost *scsihostsrc = &def->source.subsys.u.scsi_host;
virDomainHostdevSubsysMediatedDev *mdevsrc = &def->source.subsys.u.mdev;
virTristateBool managed;
g_autofree char *sgio = NULL;
g_autofree char *backendStr = NULL;
g_autofree char *model = NULL;
int rv;
@ -7313,7 +7311,6 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
VIR_XML_PROP_NONE, &managed));
virTristateBoolToBool(managed, &def->managed);
sgio = virXMLPropString(node, "sgio");
model = virXMLPropString(node, "model");
/* @type is passed in from the caller rather than read from the
@ -7352,18 +7349,17 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
return -1;
}
if (sgio) {
if ((rv = virXMLPropEnum(node, "sgio",
virDomainDeviceSGIOTypeFromString,
VIR_XML_PROP_NONZERO,
&scsisrc->sgio)) < 0) {
return -1;
} else if (rv > 0) {
if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("sgio is only supported for scsi host device"));
return -1;
}
if ((scsisrc->sgio = virDomainDeviceSGIOTypeFromString(sgio)) <= 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown sgio mode '%s'"), sgio);
return -1;
}
}
if ((rv = virXMLPropTristateBool(node, "rawio",
@ -7389,27 +7385,17 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
}
if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST) {
if (model &&
((scsihostsrc->model = virDomainHostdevSubsysSCSIVHostModelTypeFromString(model)) < 0)) {
virReportError(VIR_ERR_XML_ERROR,
_("unknown hostdev model '%s'"),
model);
if (virXMLPropEnum(node, "model",
virDomainHostdevSubsysSCSIVHostModelTypeFromString,
VIR_XML_PROP_NONE,
&scsihostsrc->model) < 0)
return -1;
}
} else if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
if (!model) {
virReportError(VIR_ERR_XML_ERROR, "%s",
_("Missing 'model' attribute in mediated device's "
"<hostdev> element"));
if (virXMLPropEnum(node, "model",
virMediatedDeviceModelTypeFromString,
VIR_XML_PROP_REQUIRED,
&mdevsrc->model) < 0)
return -1;
}
if ((mdevsrc->model = virMediatedDeviceModelTypeFromString(model)) < 0) {
virReportError(VIR_ERR_XML_ERROR,
_("unknown hostdev model '%s'"),
model);
return -1;
}
if (virXMLPropTristateSwitch(node, "display",
VIR_XML_PROP_NONE,
@ -7427,16 +7413,12 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, ctxt, def, flags) < 0)
return -1;
backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT;
if ((backendStr = virXPathString("string(./driver/@name)", ctxt)) &&
(((backend = virDomainHostdevSubsysPCIBackendTypeFromString(backendStr)) < 0) ||
backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Unknown PCI device <driver name='%s'/> "
"has been specified"), backendStr);
driver_node = virXPathNode("./driver", ctxt);
if (virXMLPropEnum(driver_node, "name",
virDomainHostdevSubsysPCIBackendTypeFromString,
VIR_XML_PROP_NONZERO,
&pcisrc->backend) < 0)
return -1;
}
pcisrc->backend = backend;
break;
@ -30559,7 +30541,7 @@ virDomainNetDefActualToNetworkPort(virDomainDef *dom,
}
port->plug.hostdevpci.managed = virTristateBoolFromBool(actual->data.hostdev.def.managed);
port->plug.hostdevpci.addr = actual->data.hostdev.def.source.subsys.u.pci.addr;
switch ((virDomainHostdevSubsysPCIBackendType)actual->data.hostdev.def.source.subsys.u.pci.backend) {
switch (actual->data.hostdev.def.source.subsys.u.pci.backend) {
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT:
port->plug.hostdevpci.driver = VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT;
break;

View File

@ -214,7 +214,7 @@ typedef enum {
/* the backend driver used for PCI hostdev devices */
typedef enum {
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT, /* detect automatically, prefer VFIO */
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT = 0, /* detect automatically, prefer VFIO */
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM, /* force legacy kvm style */
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO, /* force vfio */
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN, /* force legacy xen style, use pciback */
@ -245,7 +245,7 @@ struct _virDomainHostdevSubsysUSB {
struct _virDomainHostdevSubsysPCI {
virPCIDeviceAddress addr; /* host address */
int backend; /* enum virDomainHostdevSubsysPCIBackendType */
virDomainHostdevSubsysPCIBackendType backend;
};
struct _virDomainHostdevSubsysSCSIHost {
@ -260,9 +260,17 @@ struct _virDomainHostdevSubsysSCSIiSCSI {
virStorageSource *src;
};
typedef enum {
VIR_DOMAIN_DEVICE_SGIO_DEFAULT = 0,
VIR_DOMAIN_DEVICE_SGIO_FILTERED,
VIR_DOMAIN_DEVICE_SGIO_UNFILTERED,
VIR_DOMAIN_DEVICE_SGIO_LAST
} virDomainDeviceSGIO;
struct _virDomainHostdevSubsysSCSI {
int protocol; /* enum virDomainHostdevSCSIProtocolType */
int sgio; /* enum virDomainDeviceSGIO */
virDomainDeviceSGIO sgio;
virTristateBool rawio;
union {
virDomainHostdevSubsysSCSIHost host;
@ -271,7 +279,7 @@ struct _virDomainHostdevSubsysSCSI {
};
struct _virDomainHostdevSubsysMediatedDev {
int model; /* enum virMediatedDeviceModelType */
virMediatedDeviceModelType model;
virTristateSwitch display;
char uuidstr[VIR_UUID_STRING_BUFLEN]; /* mediated device's uuid string */
virTristateSwitch ramfb;
@ -300,7 +308,7 @@ VIR_ENUM_DECL(virDomainHostdevSubsysSCSIVHostModel);
struct _virDomainHostdevSubsysSCSIVHost {
int protocol; /* enum virDomainHostdevSubsysSCSIHostProtocolType */
char *wwpn;
int model; /* enum virDomainHostdevSubsysSCSIVHostModelType */
virDomainHostdevSubsysSCSIVHostModelType model;
};
struct _virDomainHostdevSubsys {
@ -449,14 +457,6 @@ typedef enum {
VIR_DOMAIN_DISK_IO_LAST
} virDomainDiskIo;
typedef enum {
VIR_DOMAIN_DEVICE_SGIO_DEFAULT = 0,
VIR_DOMAIN_DEVICE_SGIO_FILTERED,
VIR_DOMAIN_DEVICE_SGIO_UNFILTERED,
VIR_DOMAIN_DEVICE_SGIO_LAST
} virDomainDeviceSGIO;
typedef enum {
VIR_DOMAIN_DISK_DISCARD_DEFAULT = 0,
VIR_DOMAIN_DISK_DISCARD_UNMAP,

View File

@ -4967,7 +4967,7 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def,
const char *failover_pair_id = NULL;
/* caller has to assign proper passthrough backend type */
switch ((virDomainHostdevSubsysPCIBackendType) pcisrc->backend) {
switch (pcisrc->backend) {
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO:
break;
@ -5480,7 +5480,7 @@ qemuBuildHostdevCommandLine(virCommand *cmd,
/* MDEV */
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
switch ((virMediatedDeviceModelType) mdevsrc->model) {
switch (mdevsrc->model) {
case VIR_MDEV_MODEL_TYPE_VFIO_PCI:
case VIR_MDEV_MODEL_TYPE_VFIO_CCW:
case VIR_MDEV_MODEL_TYPE_VFIO_AP:

View File

@ -169,14 +169,14 @@ qemuHostdevPreparePCIDevicesCheckSupport(virDomainHostdevDef **hostdevs,
/* assign defaults for hostdev passthrough */
for (i = 0; i < nhostdevs; i++) {
virDomainHostdevDef *hostdev = hostdevs[i];
int *backend = &hostdev->source.subsys.u.pci.backend;
virDomainHostdevSubsysPCIBackendType *backend = &hostdev->source.subsys.u.pci.backend;
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
continue;
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
continue;
switch ((virDomainHostdevSubsysPCIBackendType)*backend) {
switch (*backend) {
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT:
if (supportsPassthroughVFIO &&
virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {

View File

@ -1622,7 +1622,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriver *driver,
/* this could have been changed by qemuHostdevPreparePCIDevices */
backend = hostdev->source.subsys.u.pci.backend;
switch ((virDomainHostdevSubsysPCIBackendType)backend) {
switch (backend) {
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO:
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
@ -2814,6 +2814,7 @@ qemuDomainAttachMediatedDevice(virQEMUDriver *driver,
if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev) < 0)
return -1;
} break;
case VIR_MDEV_MODEL_TYPE_VFIO_AP:
case VIR_MDEV_MODEL_TYPE_LAST:
break;
}

View File

@ -2357,7 +2357,7 @@ qemuValidateDomainMdevDef(const virDomainHostdevDef *hostdev,
const virDomainHostdevSubsysMediatedDev *mdevsrc;
mdevsrc = &hostdev->source.subsys.u.mdev;
switch ((virMediatedDeviceModelType) mdevsrc->model) {
switch (mdevsrc->model) {
case VIR_MDEV_MODEL_TYPE_VFIO_PCI:
return qemuValidateDomainMdevDefVFIOPCI(hostdev, def, qemuCaps);
case VIR_MDEV_MODEL_TYPE_VFIO_AP:

View File

@ -1070,7 +1070,7 @@ get_files(vahControl * ctl)
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
virDomainHostdevSubsysMediatedDev *mdevsrc = &dev->source.subsys.u.mdev;
switch ((virMediatedDeviceModelType) mdevsrc->model) {
switch (mdevsrc->model) {
case VIR_MDEV_MODEL_TYPE_VFIO_PCI:
case VIR_MDEV_MODEL_TYPE_VFIO_AP:
case VIR_MDEV_MODEL_TYPE_VFIO_CCW: