mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-06 17:17:56 +03:00
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:
parent
af5a7dba78
commit
bdb95b520c
@ -7293,14 +7293,12 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
|
|||||||
virDomainXMLOption *xmlopt)
|
virDomainXMLOption *xmlopt)
|
||||||
{
|
{
|
||||||
xmlNodePtr sourcenode;
|
xmlNodePtr sourcenode;
|
||||||
int backend;
|
xmlNodePtr driver_node = NULL;
|
||||||
virDomainHostdevSubsysPCI *pcisrc = &def->source.subsys.u.pci;
|
virDomainHostdevSubsysPCI *pcisrc = &def->source.subsys.u.pci;
|
||||||
virDomainHostdevSubsysSCSI *scsisrc = &def->source.subsys.u.scsi;
|
virDomainHostdevSubsysSCSI *scsisrc = &def->source.subsys.u.scsi;
|
||||||
virDomainHostdevSubsysSCSIVHost *scsihostsrc = &def->source.subsys.u.scsi_host;
|
virDomainHostdevSubsysSCSIVHost *scsihostsrc = &def->source.subsys.u.scsi_host;
|
||||||
virDomainHostdevSubsysMediatedDev *mdevsrc = &def->source.subsys.u.mdev;
|
virDomainHostdevSubsysMediatedDev *mdevsrc = &def->source.subsys.u.mdev;
|
||||||
virTristateBool managed;
|
virTristateBool managed;
|
||||||
g_autofree char *sgio = NULL;
|
|
||||||
g_autofree char *backendStr = NULL;
|
|
||||||
g_autofree char *model = NULL;
|
g_autofree char *model = NULL;
|
||||||
int rv;
|
int rv;
|
||||||
|
|
||||||
@ -7313,7 +7311,6 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
|
|||||||
VIR_XML_PROP_NONE, &managed));
|
VIR_XML_PROP_NONE, &managed));
|
||||||
virTristateBoolToBool(managed, &def->managed);
|
virTristateBoolToBool(managed, &def->managed);
|
||||||
|
|
||||||
sgio = virXMLPropString(node, "sgio");
|
|
||||||
model = virXMLPropString(node, "model");
|
model = virXMLPropString(node, "model");
|
||||||
|
|
||||||
/* @type is passed in from the caller rather than read from the
|
/* @type is passed in from the caller rather than read from the
|
||||||
@ -7352,18 +7349,17 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
|
|||||||
return -1;
|
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) {
|
if (def->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI) {
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virReportError(VIR_ERR_XML_ERROR, "%s",
|
||||||
_("sgio is only supported for scsi host device"));
|
_("sgio is only supported for scsi host device"));
|
||||||
return -1;
|
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",
|
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 (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST) {
|
||||||
if (model &&
|
if (virXMLPropEnum(node, "model",
|
||||||
((scsihostsrc->model = virDomainHostdevSubsysSCSIVHostModelTypeFromString(model)) < 0)) {
|
virDomainHostdevSubsysSCSIVHostModelTypeFromString,
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
VIR_XML_PROP_NONE,
|
||||||
_("unknown hostdev model '%s'"),
|
&scsihostsrc->model) < 0)
|
||||||
model);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
} else if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
|
} else if (def->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV) {
|
||||||
if (!model) {
|
if (virXMLPropEnum(node, "model",
|
||||||
virReportError(VIR_ERR_XML_ERROR, "%s",
|
virMediatedDeviceModelTypeFromString,
|
||||||
_("Missing 'model' attribute in mediated device's "
|
VIR_XML_PROP_REQUIRED,
|
||||||
"<hostdev> element"));
|
&mdevsrc->model) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
if ((mdevsrc->model = virMediatedDeviceModelTypeFromString(model)) < 0) {
|
|
||||||
virReportError(VIR_ERR_XML_ERROR,
|
|
||||||
_("unknown hostdev model '%s'"),
|
|
||||||
model);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virXMLPropTristateSwitch(node, "display",
|
if (virXMLPropTristateSwitch(node, "display",
|
||||||
VIR_XML_PROP_NONE,
|
VIR_XML_PROP_NONE,
|
||||||
@ -7427,16 +7413,12 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node,
|
|||||||
if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, ctxt, def, flags) < 0)
|
if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, ctxt, def, flags) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT;
|
driver_node = virXPathNode("./driver", ctxt);
|
||||||
if ((backendStr = virXPathString("string(./driver/@name)", ctxt)) &&
|
if (virXMLPropEnum(driver_node, "name",
|
||||||
(((backend = virDomainHostdevSubsysPCIBackendTypeFromString(backendStr)) < 0) ||
|
virDomainHostdevSubsysPCIBackendTypeFromString,
|
||||||
backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT)) {
|
VIR_XML_PROP_NONZERO,
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
&pcisrc->backend) < 0)
|
||||||
_("Unknown PCI device <driver name='%s'/> "
|
|
||||||
"has been specified"), backendStr);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
pcisrc->backend = backend;
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -30559,7 +30541,7 @@ virDomainNetDefActualToNetworkPort(virDomainDef *dom,
|
|||||||
}
|
}
|
||||||
port->plug.hostdevpci.managed = virTristateBoolFromBool(actual->data.hostdev.def.managed);
|
port->plug.hostdevpci.managed = virTristateBoolFromBool(actual->data.hostdev.def.managed);
|
||||||
port->plug.hostdevpci.addr = actual->data.hostdev.def.source.subsys.u.pci.addr;
|
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:
|
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT:
|
||||||
port->plug.hostdevpci.driver = VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT;
|
port->plug.hostdevpci.driver = VIR_NETWORK_FORWARD_DRIVER_NAME_DEFAULT;
|
||||||
break;
|
break;
|
||||||
|
@ -214,7 +214,7 @@ typedef enum {
|
|||||||
|
|
||||||
/* the backend driver used for PCI hostdev devices */
|
/* the backend driver used for PCI hostdev devices */
|
||||||
typedef enum {
|
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_KVM, /* force legacy kvm style */
|
||||||
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO, /* force vfio */
|
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO, /* force vfio */
|
||||||
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN, /* force legacy xen style, use pciback */
|
VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN, /* force legacy xen style, use pciback */
|
||||||
@ -245,7 +245,7 @@ struct _virDomainHostdevSubsysUSB {
|
|||||||
|
|
||||||
struct _virDomainHostdevSubsysPCI {
|
struct _virDomainHostdevSubsysPCI {
|
||||||
virPCIDeviceAddress addr; /* host address */
|
virPCIDeviceAddress addr; /* host address */
|
||||||
int backend; /* enum virDomainHostdevSubsysPCIBackendType */
|
virDomainHostdevSubsysPCIBackendType backend;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _virDomainHostdevSubsysSCSIHost {
|
struct _virDomainHostdevSubsysSCSIHost {
|
||||||
@ -260,9 +260,17 @@ struct _virDomainHostdevSubsysSCSIiSCSI {
|
|||||||
virStorageSource *src;
|
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 {
|
struct _virDomainHostdevSubsysSCSI {
|
||||||
int protocol; /* enum virDomainHostdevSCSIProtocolType */
|
int protocol; /* enum virDomainHostdevSCSIProtocolType */
|
||||||
int sgio; /* enum virDomainDeviceSGIO */
|
virDomainDeviceSGIO sgio;
|
||||||
virTristateBool rawio;
|
virTristateBool rawio;
|
||||||
union {
|
union {
|
||||||
virDomainHostdevSubsysSCSIHost host;
|
virDomainHostdevSubsysSCSIHost host;
|
||||||
@ -271,7 +279,7 @@ struct _virDomainHostdevSubsysSCSI {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct _virDomainHostdevSubsysMediatedDev {
|
struct _virDomainHostdevSubsysMediatedDev {
|
||||||
int model; /* enum virMediatedDeviceModelType */
|
virMediatedDeviceModelType model;
|
||||||
virTristateSwitch display;
|
virTristateSwitch display;
|
||||||
char uuidstr[VIR_UUID_STRING_BUFLEN]; /* mediated device's uuid string */
|
char uuidstr[VIR_UUID_STRING_BUFLEN]; /* mediated device's uuid string */
|
||||||
virTristateSwitch ramfb;
|
virTristateSwitch ramfb;
|
||||||
@ -300,7 +308,7 @@ VIR_ENUM_DECL(virDomainHostdevSubsysSCSIVHostModel);
|
|||||||
struct _virDomainHostdevSubsysSCSIVHost {
|
struct _virDomainHostdevSubsysSCSIVHost {
|
||||||
int protocol; /* enum virDomainHostdevSubsysSCSIHostProtocolType */
|
int protocol; /* enum virDomainHostdevSubsysSCSIHostProtocolType */
|
||||||
char *wwpn;
|
char *wwpn;
|
||||||
int model; /* enum virDomainHostdevSubsysSCSIVHostModelType */
|
virDomainHostdevSubsysSCSIVHostModelType model;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _virDomainHostdevSubsys {
|
struct _virDomainHostdevSubsys {
|
||||||
@ -449,14 +457,6 @@ typedef enum {
|
|||||||
VIR_DOMAIN_DISK_IO_LAST
|
VIR_DOMAIN_DISK_IO_LAST
|
||||||
} virDomainDiskIo;
|
} 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 {
|
typedef enum {
|
||||||
VIR_DOMAIN_DISK_DISCARD_DEFAULT = 0,
|
VIR_DOMAIN_DISK_DISCARD_DEFAULT = 0,
|
||||||
VIR_DOMAIN_DISK_DISCARD_UNMAP,
|
VIR_DOMAIN_DISK_DISCARD_UNMAP,
|
||||||
|
@ -4967,7 +4967,7 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def,
|
|||||||
const char *failover_pair_id = NULL;
|
const char *failover_pair_id = NULL;
|
||||||
|
|
||||||
/* caller has to assign proper passthrough backend type */
|
/* caller has to assign proper passthrough backend type */
|
||||||
switch ((virDomainHostdevSubsysPCIBackendType) pcisrc->backend) {
|
switch (pcisrc->backend) {
|
||||||
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO:
|
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -5480,7 +5480,7 @@ qemuBuildHostdevCommandLine(virCommand *cmd,
|
|||||||
|
|
||||||
/* MDEV */
|
/* MDEV */
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_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_PCI:
|
||||||
case VIR_MDEV_MODEL_TYPE_VFIO_CCW:
|
case VIR_MDEV_MODEL_TYPE_VFIO_CCW:
|
||||||
case VIR_MDEV_MODEL_TYPE_VFIO_AP:
|
case VIR_MDEV_MODEL_TYPE_VFIO_AP:
|
||||||
|
@ -169,14 +169,14 @@ qemuHostdevPreparePCIDevicesCheckSupport(virDomainHostdevDef **hostdevs,
|
|||||||
/* assign defaults for hostdev passthrough */
|
/* assign defaults for hostdev passthrough */
|
||||||
for (i = 0; i < nhostdevs; i++) {
|
for (i = 0; i < nhostdevs; i++) {
|
||||||
virDomainHostdevDef *hostdev = hostdevs[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)
|
if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
|
||||||
continue;
|
continue;
|
||||||
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
|
if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
switch ((virDomainHostdevSubsysPCIBackendType)*backend) {
|
switch (*backend) {
|
||||||
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT:
|
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT:
|
||||||
if (supportsPassthroughVFIO &&
|
if (supportsPassthroughVFIO &&
|
||||||
virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
|
virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
|
||||||
|
@ -1622,7 +1622,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriver *driver,
|
|||||||
/* this could have been changed by qemuHostdevPreparePCIDevices */
|
/* this could have been changed by qemuHostdevPreparePCIDevices */
|
||||||
backend = hostdev->source.subsys.u.pci.backend;
|
backend = hostdev->source.subsys.u.pci.backend;
|
||||||
|
|
||||||
switch ((virDomainHostdevSubsysPCIBackendType)backend) {
|
switch (backend) {
|
||||||
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO:
|
case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO:
|
||||||
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
|
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) {
|
||||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
||||||
@ -2814,6 +2814,7 @@ qemuDomainAttachMediatedDevice(virQEMUDriver *driver,
|
|||||||
if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev) < 0)
|
if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
} break;
|
} break;
|
||||||
|
case VIR_MDEV_MODEL_TYPE_VFIO_AP:
|
||||||
case VIR_MDEV_MODEL_TYPE_LAST:
|
case VIR_MDEV_MODEL_TYPE_LAST:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2357,7 +2357,7 @@ qemuValidateDomainMdevDef(const virDomainHostdevDef *hostdev,
|
|||||||
const virDomainHostdevSubsysMediatedDev *mdevsrc;
|
const virDomainHostdevSubsysMediatedDev *mdevsrc;
|
||||||
|
|
||||||
mdevsrc = &hostdev->source.subsys.u.mdev;
|
mdevsrc = &hostdev->source.subsys.u.mdev;
|
||||||
switch ((virMediatedDeviceModelType) mdevsrc->model) {
|
switch (mdevsrc->model) {
|
||||||
case VIR_MDEV_MODEL_TYPE_VFIO_PCI:
|
case VIR_MDEV_MODEL_TYPE_VFIO_PCI:
|
||||||
return qemuValidateDomainMdevDefVFIOPCI(hostdev, def, qemuCaps);
|
return qemuValidateDomainMdevDefVFIOPCI(hostdev, def, qemuCaps);
|
||||||
case VIR_MDEV_MODEL_TYPE_VFIO_AP:
|
case VIR_MDEV_MODEL_TYPE_VFIO_AP:
|
||||||
|
@ -1070,7 +1070,7 @@ get_files(vahControl * ctl)
|
|||||||
|
|
||||||
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: {
|
||||||
virDomainHostdevSubsysMediatedDev *mdevsrc = &dev->source.subsys.u.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_PCI:
|
||||||
case VIR_MDEV_MODEL_TYPE_VFIO_AP:
|
case VIR_MDEV_MODEL_TYPE_VFIO_AP:
|
||||||
case VIR_MDEV_MODEL_TYPE_VFIO_CCW:
|
case VIR_MDEV_MODEL_TYPE_VFIO_CCW:
|
||||||
|
Loading…
Reference in New Issue
Block a user