The virDomainTPMDefParseXML() function uses old style of parsing XML (virXMLPropString + str2enum conversion). Use virXMLPropEnumDefault() which encapsulates those steps. Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx> --- src/conf/domain_conf.c | 43 ++++++++++++---------------------------- src/conf/domain_conf.h | 6 +++--- src/qemu/qemu_command.c | 2 +- src/qemu/qemu_domain.c | 2 +- src/qemu/qemu_validate.c | 1 + 5 files changed, 19 insertions(+), 35 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 84a65076b9..1f18bab332 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -11644,9 +11644,6 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt, int nnodes; size_t i; g_autofree char *path = NULL; - g_autofree char *model = NULL; - g_autofree char *backend = NULL; - g_autofree char *version = NULL; g_autofree char *secretuuid = NULL; g_autofree char *persistent_state = NULL; g_autofree xmlNodePtr *backends = NULL; @@ -11655,13 +11652,11 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt, def = g_new0(virDomainTPMDef, 1); - model = virXMLPropString(node, "model"); - if (model != NULL && - (def->model = virDomainTPMModelTypeFromString(model)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown TPM frontend model '%s'"), model); + if (virXMLPropEnum(node, "model", + virDomainTPMModelTypeFromString, + VIR_XML_PROP_NONE, + &def->model) < 0) goto error; - } ctxt->node = node; @@ -11680,30 +11675,18 @@ virDomainTPMDefParseXML(virDomainXMLOption *xmlopt, goto error; } - if (!(backend = virXMLPropString(backends[0], "type"))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing TPM device backend type")); + if (virXMLPropEnum(backends[0], "type", + virDomainTPMBackendTypeFromString, + VIR_XML_PROP_REQUIRED, + &def->type) < 0) goto error; - } - if ((def->type = virDomainTPMBackendTypeFromString(backend)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown TPM backend type '%s'"), - backend); + if (virXMLPropEnumDefault(backends[0], "version", + virDomainTPMVersionTypeFromString, + VIR_XML_PROP_NONE, + &def->version, + VIR_DOMAIN_TPM_VERSION_DEFAULT) < 0) goto error; - } - - version = virXMLPropString(backends[0], "version"); - if (!version) { - def->version = VIR_DOMAIN_TPM_VERSION_DEFAULT; - } else { - if ((def->version = virDomainTPMVersionTypeFromString(version)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unsupported TPM version '%s'"), - version); - goto error; - } - } switch (def->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c500a78680..9891a5e276 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1407,10 +1407,10 @@ typedef enum { #define VIR_DOMAIN_TPM_DEFAULT_DEVICE "/dev/tpm0" struct _virDomainTPMDef { - int type; /* virDomainTPMBackendType */ + virDomainTPMBackendType type; virDomainDeviceInfo info; - int model; /* virDomainTPMModel */ - int version; /* virDomainTPMVersion */ + virDomainTPMModel model; + virDomainTPMVersion version; union { struct { virDomainChrSourceDef *source; diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 3ef062f2e5..4dd803642a 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -9785,7 +9785,7 @@ qemuBuildTPMCommandLine(virCommand *cmd, g_autoptr(qemuFDPass) passtpm = NULL; g_autoptr(qemuFDPass) passcancel = NULL; - switch ((virDomainTPMBackendType) tpm->type) { + switch (tpm->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: { VIR_AUTOCLOSE fdtpm = -1; VIR_AUTOCLOSE fdcancel = -1; diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f8e67e5479..7a5433107a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -11768,7 +11768,7 @@ qemuDomainDeviceBackendChardevForeachOne(virDomainDeviceDef *dev, return cb(dev, dev->data.rng->source.chardev, opaque); case VIR_DOMAIN_DEVICE_TPM: - switch ((virDomainTPMBackendType) dev->data.tpm->type) { + switch (dev->data.tpm->type) { case VIR_DOMAIN_TPM_TYPE_PASSTHROUGH: return cb(dev, dev->data.tpm->data.passthrough.source, opaque); diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 097e35a430..d30ffeb3ea 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -4676,6 +4676,7 @@ qemuValidateDomainDeviceDefTPM(virDomainTPMDef *tpm, flag = QEMU_CAPS_DEVICE_SPAPR_TPM_PROXY; break; + case VIR_DOMAIN_TPM_MODEL_DEFAULT: case VIR_DOMAIN_TPM_MODEL_LAST: default: virReportEnumRangeError(virDomainTPMModel, tpm->model); -- 2.35.1