virDomainRNGDef: Convert 'backend' field to proper enum type

Convert the field and adjust the XML parser to use
virXMLPropEnum().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2023-05-02 12:29:18 +02:00
parent 53edfa23f1
commit b691d249d1
6 changed files with 15 additions and 21 deletions

View File

@ -215,7 +215,7 @@ virDomainAuditRNG(virDomainObj *vm,
const char *oldsrcpath = NULL; const char *oldsrcpath = NULL;
if (newDef) { if (newDef) {
switch ((virDomainRNGBackend) newDef->backend) { switch (newDef->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM: case VIR_DOMAIN_RNG_BACKEND_RANDOM:
newsrcpath = newDef->source.file; newsrcpath = newDef->source.file;
break; break;
@ -231,7 +231,7 @@ virDomainAuditRNG(virDomainObj *vm,
} }
if (oldDef) { if (oldDef) {
switch ((virDomainRNGBackend) oldDef->backend) { switch (oldDef->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM: case VIR_DOMAIN_RNG_BACKEND_RANDOM:
oldsrcpath = oldDef->source.file; oldsrcpath = oldDef->source.file;
break; break;

View File

@ -12116,7 +12116,6 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt,
VIR_XPATH_NODE_AUTORESTORE(ctxt) VIR_XPATH_NODE_AUTORESTORE(ctxt)
int nbackends; int nbackends;
g_autofree xmlNodePtr *backends = NULL; g_autofree xmlNodePtr *backends = NULL;
g_autofree char *backend = NULL;
g_autofree char *type = NULL; g_autofree char *type = NULL;
def = g_new0(virDomainRNGDef, 1); def = g_new0(virDomainRNGDef, 1);
@ -12151,19 +12150,14 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt,
goto error; goto error;
} }
if (!(backend = virXMLPropString(backends[0], "model"))) { if (virXMLPropEnum(backends[0], "model",
virReportError(VIR_ERR_XML_ERROR, "%s", virDomainRNGBackendTypeFromString,
_("missing RNG device backend model")); VIR_XML_PROP_REQUIRED,
&def->backend) < 0) {
goto error; goto error;
} }
if ((def->backend = virDomainRNGBackendTypeFromString(backend)) < 0) { switch (def->backend) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown RNG backend model '%1$s'"), backend);
goto error;
}
switch ((virDomainRNGBackend) def->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM: case VIR_DOMAIN_RNG_BACKEND_RANDOM:
def->source.file = virXPathString("string(./backend)", ctxt); def->source.file = virXPathString("string(./backend)", ctxt);
break; break;
@ -15197,7 +15191,7 @@ virDomainRNGFind(virDomainDef *def,
if (rng->rate != tmp->rate || rng->period != tmp->period) if (rng->rate != tmp->rate || rng->period != tmp->period)
continue; continue;
switch ((virDomainRNGBackend) rng->backend) { switch (rng->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM: case VIR_DOMAIN_RNG_BACKEND_RANDOM:
if (STRNEQ_NULLABLE(rng->source.file, tmp->source.file)) if (STRNEQ_NULLABLE(rng->source.file, tmp->source.file))
continue; continue;
@ -25076,7 +25070,7 @@ virDomainRNGDefFormat(virBuffer *buf,
} }
virBufferAsprintf(buf, "<backend model='%s'", backend); virBufferAsprintf(buf, "<backend model='%s'", backend);
switch ((virDomainRNGBackend) def->backend) { switch (def->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM: case VIR_DOMAIN_RNG_BACKEND_RANDOM:
virBufferEscapeString(buf, ">%s</backend>\n", def->source.file); virBufferEscapeString(buf, ">%s</backend>\n", def->source.file);
break; break;
@ -25117,7 +25111,7 @@ virDomainRNGDefFree(virDomainRNGDef *def)
if (!def) if (!def)
return; return;
switch ((virDomainRNGBackend) def->backend) { switch (def->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM: case VIR_DOMAIN_RNG_BACKEND_RANDOM:
g_free(def->source.file); g_free(def->source.file);
break; break;

View File

@ -2610,7 +2610,7 @@ typedef enum {
struct _virDomainRNGDef { struct _virDomainRNGDef {
virDomainRNGModel model; virDomainRNGModel model;
int backend; virDomainRNGBackend backend;
unsigned int rate; /* bytes per period */ unsigned int rate; /* bytes per period */
unsigned int period; /* milliseconds */ unsigned int period; /* milliseconds */

View File

@ -5361,7 +5361,7 @@ qemuBuildRNGBackendChrdev(virCommand *cmd,
{ {
g_autofree char *charAlias = qemuAliasChardevFromDevAlias(rng->info.alias); 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_RANDOM:
case VIR_DOMAIN_RNG_BACKEND_BUILTIN: case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
case VIR_DOMAIN_RNG_BACKEND_LAST: case VIR_DOMAIN_RNG_BACKEND_LAST:
@ -5390,7 +5390,7 @@ qemuBuildRNGBackendProps(virDomainRNGDef *rng,
objAlias = g_strdup_printf("obj%s", rng->info.alias); objAlias = g_strdup_printf("obj%s", rng->info.alias);
switch ((virDomainRNGBackend) rng->backend) { switch (rng->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM: case VIR_DOMAIN_RNG_BACKEND_RANDOM:
if (qemuMonitorCreateObjectProps(props, "rng-random", objAlias, if (qemuMonitorCreateObjectProps(props, "rng-random", objAlias,
"s:filename", rng->source.file, "s:filename", rng->source.file,

View File

@ -574,7 +574,7 @@ static int
qemuDomainSetupRNG(virDomainRNGDef *rng, qemuDomainSetupRNG(virDomainRNGDef *rng,
GSList **paths) GSList **paths)
{ {
switch ((virDomainRNGBackend) rng->backend) { switch (rng->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM: case VIR_DOMAIN_RNG_BACKEND_RANDOM:
*paths = g_slist_prepend(*paths, g_strdup(rng->source.file)); *paths = g_slist_prepend(*paths, g_strdup(rng->source.file));
break; break;

View File

@ -2154,7 +2154,7 @@ qemuValidateDomainRNGDef(const virDomainRNGDef *def,
{ {
virDomainCapsDeviceRNG rngCaps = { 0 }; virDomainCapsDeviceRNG rngCaps = { 0 };
switch ((virDomainRNGBackend) def->backend) { switch (def->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM: case VIR_DOMAIN_RNG_BACKEND_RANDOM:
if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_RANDOM)) { if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_RANDOM)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",