Convert the field and adjust the XML parser to use
virXMLPropEnum().
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/conf/domain_audit.c | 4 ++--
src/conf/domain_conf.c | 22 ++++++++--------------
src/conf/domain_conf.h | 2 +-
src/qemu/qemu_command.c | 4 ++--
src/qemu/qemu_namespace.c | 2 +-
src/qemu/qemu_validate.c | 2 +-
6 files changed, 15 insertions(+), 21 deletions(-)
diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index 4294b50c3a..7a6bb02203 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -215,7 +215,7 @@ virDomainAuditRNG(virDomainObj *vm,
const char *oldsrcpath = NULL;
if (newDef) {
- switch ((virDomainRNGBackend) newDef->backend) {
+ switch (newDef->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
newsrcpath = newDef->source.file;
break;
@@ -231,7 +231,7 @@ virDomainAuditRNG(virDomainObj *vm,
}
if (oldDef) {
- switch ((virDomainRNGBackend) oldDef->backend) {
+ switch (oldDef->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
oldsrcpath = oldDef->source.file;
break;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 3b24d0218d..47c4170f29 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -12116,7 +12116,6 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt,
VIR_XPATH_NODE_AUTORESTORE(ctxt)
int nbackends;
g_autofree xmlNodePtr *backends = NULL;
- g_autofree char *backend = NULL;
g_autofree char *type = NULL;
def = g_new0(virDomainRNGDef, 1);
@@ -12151,19 +12150,14 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt,
goto error;
}
- if (!(backend = virXMLPropString(backends[0], "model"))) {
- virReportError(VIR_ERR_XML_ERROR, "%s",
- _("missing RNG device backend model"));
+ if (virXMLPropEnum(backends[0], "model",
+ virDomainRNGBackendTypeFromString,
+ VIR_XML_PROP_REQUIRED,
+ &def->backend) < 0) {
goto error;
}
- if ((def->backend = virDomainRNGBackendTypeFromString(backend)) < 0) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("unknown RNG backend model '%1$s'"),
backend);
- goto error;
- }
-
- switch ((virDomainRNGBackend) def->backend) {
+ switch (def->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
def->source.file = virXPathString("string(./backend)", ctxt);
break;
@@ -15197,7 +15191,7 @@ virDomainRNGFind(virDomainDef *def,
if (rng->rate != tmp->rate || rng->period != tmp->period)
continue;
- switch ((virDomainRNGBackend) rng->backend) {
+ switch (rng->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
if (STRNEQ_NULLABLE(rng->source.file, tmp->source.file))
continue;
@@ -25076,7 +25070,7 @@ virDomainRNGDefFormat(virBuffer *buf,
}
virBufferAsprintf(buf, "<backend model='%s'", backend);
- switch ((virDomainRNGBackend) def->backend) {
+ switch (def->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
virBufferEscapeString(buf, ">%s</backend>\n",
def->source.file);
break;
@@ -25117,7 +25111,7 @@ virDomainRNGDefFree(virDomainRNGDef *def)
if (!def)
return;
- switch ((virDomainRNGBackend) def->backend) {
+ switch (def->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
g_free(def->source.file);
break;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index f56c04ce36..c9b9fbabd3 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2610,7 +2610,7 @@ typedef enum {
struct _virDomainRNGDef {
virDomainRNGModel model;
- int backend;
+ virDomainRNGBackend backend;
unsigned int rate; /* bytes per period */
unsigned int period; /* milliseconds */
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 17d7bfcfd3..11ede25c0b 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5361,7 +5361,7 @@ qemuBuildRNGBackendChrdev(virCommand *cmd,
{
g_autofree char *charAlias = qemuAliasChardevFromDevAlias(rng->info.alias);
- switch ((virDomainRNGBackend) rng->backend) {
+ switch (rng->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
case VIR_DOMAIN_RNG_BACKEND_LAST:
@@ -5390,7 +5390,7 @@ qemuBuildRNGBackendProps(virDomainRNGDef *rng,
objAlias = g_strdup_printf("obj%s", rng->info.alias);
- switch ((virDomainRNGBackend) rng->backend) {
+ switch (rng->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
if (qemuMonitorCreateObjectProps(props, "rng-random", objAlias,
"s:filename", rng->source.file,
diff --git a/src/qemu/qemu_namespace.c b/src/qemu/qemu_namespace.c
index f245712f9a..915d44310f 100644
--- a/src/qemu/qemu_namespace.c
+++ b/src/qemu/qemu_namespace.c
@@ -574,7 +574,7 @@ static int
qemuDomainSetupRNG(virDomainRNGDef *rng,
GSList **paths)
{
- switch ((virDomainRNGBackend) rng->backend) {
+ switch (rng->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
*paths = g_slist_prepend(*paths, g_strdup(rng->source.file));
break;
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index 2fcc86bb22..fc61c489e9 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -2154,7 +2154,7 @@ qemuValidateDomainRNGDef(const virDomainRNGDef *def,
{
virDomainCapsDeviceRNG rngCaps = { 0 };
- switch ((virDomainRNGBackend) def->backend) {
+ switch (def->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_RANDOM)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
--
2.41.0