conf: Use proper enum types for 'onReboot', 'onPoweroff', 'onCrash', and 'onLockFailure'

This ensures that 'switch' statements work correctly.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa committed 2026-07-27 13:38:37 +02:00
1 parent 0f18f6813c
commit 997b9816dc
4 files changed
+19 -12

No files matched your search

+6 -4
View File
@@ -14168,21 +14168,23 @@ static int
virDomainEventActionParseXML(xmlXPathContextPtr ctxt,
const char *name,
const char *xpath,
int *val,
int defaultVal,
unsigned int *val,
unsigned int defaultVal,
virEventActionFromStringFunc convFunc)
{
g_autofree char *tmp = virXPathString(xpath, ctxt);
int tmpval;
if (tmp == NULL) {
*val = defaultVal;
} else {
*val = convFunc(tmp);
if (*val < 0) {
tmpval = convFunc(tmp);
if (tmpval < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("unknown %1$s action: %2$s"), name, tmp);
return -1;
}
*val = tmpval;
}
return 0;
}
+4 -5
View File
@@ -3250,12 +3250,11 @@ struct _virDomainDef {
virDomainResourceDef *resource;
virDomainIdMapDef idmap;
/* These 3 are based on virDomainLifecycleAction enum flags */
int onReboot;
int onPoweroff;
int onCrash;
virDomainLifecycleAction onReboot;
virDomainLifecycleAction onPoweroff;
virDomainLifecycleAction onCrash;
int onLockFailure; /* enum virDomainLockFailureAction */
virDomainLockFailureAction onLockFailure;
virDomainPowerManagement pm;
+7 -3
View File
@@ -336,33 +336,37 @@ xenParseEventsActions(virConf *conf, virDomainDef *def)
g_autofree char *on_poweroff = NULL;
g_autofree char *on_reboot = NULL;
g_autofree char *on_crash = NULL;
int tmp;
if (xenConfigGetString(conf, "on_poweroff", &on_poweroff, "destroy") < 0)
return -1;
if ((def->onPoweroff = virDomainLifecycleActionTypeFromString(on_poweroff)) < 0) {
if ((tmp = virDomainLifecycleActionTypeFromString(on_poweroff)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected value %1$s for on_poweroff"), on_poweroff);
return -1;
}
def->onPoweroff = tmp;
if (xenConfigGetString(conf, "on_reboot", &on_reboot, "restart") < 0)
return -1;
if ((def->onReboot = virDomainLifecycleActionTypeFromString(on_reboot)) < 0) {
if ((tmp = virDomainLifecycleActionTypeFromString(on_reboot)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected value %1$s for on_reboot"), on_reboot);
return -1;
}
def->onReboot = tmp;
if (xenConfigGetString(conf, "on_crash", &on_crash, "restart") < 0)
return -1;
if ((def->onCrash = virDomainLifecycleActionTypeFromString(on_crash)) < 0) {
if ((tmp = virDomainLifecycleActionTypeFromString(on_crash)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("unexpected value %1$s for on_crash"), on_crash);
return -1;
}
def->onCrash = tmp;
return 0;
}
+2
View File
@@ -3680,6 +3680,8 @@ processGuestPanicEvent(virQEMUDriver *driver,
/* the VM is kept around for debugging */
break;
case VIR_DOMAIN_LIFECYCLE_ACTION_RESTART_RENAME:
case VIR_DOMAIN_LIFECYCLE_ACTION_LAST:
default:
break;
}