The bhyve driver currently supports redefining 'onPoweroff' and 'onReboot', and possible actions are 'destroy' and 'restart'.
Redefining 'onCrash' is not supported. Validate all these in bhyveDomainDefValidate(). Signed-off-by: Roman Bogorodskiy <[email protected]> --- src/bhyve/bhyve_domain.c | 36 ++++++++++++++++++++++++++++++++++++ src/bhyve/bhyve_domain.h | 3 +++ 2 files changed, 39 insertions(+) diff --git a/src/bhyve/bhyve_domain.c b/src/bhyve/bhyve_domain.c index d5bb22501c..a215e562e7 100644 --- a/src/bhyve/bhyve_domain.c +++ b/src/bhyve/bhyve_domain.c @@ -462,6 +462,39 @@ bhyveDomainDeviceDefValidate(const virDomainDeviceDef *dev, } +int +bhyveValidateLifecycleAction(virDomainLifecycleAction onPoweroff, + virDomainLifecycleAction onReboot, + virDomainLifecycleAction onCrash) +{ + if ((onPoweroff != VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY && + onPoweroff != VIR_DOMAIN_LIFECYCLE_ACTION_RESTART) || + (onReboot != VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY && + onReboot != VIR_DOMAIN_LIFECYCLE_ACTION_RESTART)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("bhyve driver supports only 'restart' and 'destroy' actions for 'on_reboot'/'on_poweroff'")); + return -1; + } + + if (onCrash != VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("bhyve driver does not support 'on_crash' actions other than 'destroy'")); + return -1; + } + + return 0; +} + + +static int +bhyveValidateDomainLifecycleAction(const virDomainDef *def) +{ + return bhyveValidateLifecycleAction(def->onPoweroff, + def->onReboot, + def->onCrash); +} + + static int bhyveDomainDefValidate(const virDomainDef *def, void *opaque G_GNUC_UNUSED, @@ -549,6 +582,9 @@ bhyveDomainDefValidate(const virDomainDef *def, return -1; } + if (bhyveValidateDomainLifecycleAction(def) < 0) + return -1; + if (!def->os.loader) return 0; diff --git a/src/bhyve/bhyve_domain.h b/src/bhyve/bhyve_domain.h index fa7a685d59..c9fa776651 100644 --- a/src/bhyve/bhyve_domain.h +++ b/src/bhyve/bhyve_domain.h @@ -55,3 +55,6 @@ extern virXMLNamespace virBhyveDriverDomainXMLNamespace; int virBhyveDomainObjStartWorker(virDomainObj *dom); void virBhyveDomainObjStopWorker(virDomainObj *dom); int bhyveDomainNamePathsCleanup(const char *name, bool bestEffort); +int bhyveValidateLifecycleAction(virDomainLifecycleAction onPoweroff, + virDomainLifecycleAction onReboot, + virDomainLifecycleAction onCrash); -- 2.52.0
