On Mon, Jul 18, 2022 at 11:30:47 +0200, Michal Privoznik wrote:
When parsing a TPM device plenty of virXMLPropString() +
enum2int() combos are used. These can be replaced with
virXMLPropEnum().
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/domain_conf.c | 39 ++++++++++++---------------------------
src/conf/domain_conf.h | 6 +++---
src/qemu/qemu_command.c | 2 +-
src/qemu/qemu_domain.c | 2 +-
4 files changed, 17 insertions(+), 32 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 28f0e75e60..6263d90fdb 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
[...]
@@ -10358,13 +10355,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_NONZERO,
^^^
+ &def->model) < 0)
goto error;
- }
ctxt->node = node;
[...]
@@ -10407,14 +10395,11 @@ virDomainTPMDefParseXML(virDomainXMLOption
*xmlopt,
def->data.passthrough.source->data.file.path =
g_steal_pointer(&path);
break;
case VIR_DOMAIN_TPM_TYPE_EMULATOR:
- version = virXMLPropString(backends[0], "version");
- if (version &&
- (def->data.emulator.version = virDomainTPMVersionTypeFromString(version))
<= 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("Unsupported TPM version '%s'"),
- version);
+ if (virXMLPropEnum(backends[0], "version",
+ virDomainTPMVersionTypeFromString,
+ VIR_XML_PROP_NONZERO,
^^^
+ &def->data.emulator.version) <
0)
goto error;
- }
if (!(def->data.emulator.source = virDomainChrSourceDefNew(xmlopt)))
goto error;
Lines marked as '^^^' will likely need to be adapted per reasons in
previous replies. Other than that:
Reviewed-by: Peter Krempa <pkrempa(a)redhat.com>