Re: [PATCH 1/4] libxl: honor domain lifecycle event configuration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Jim Fehlig wrote:
> The libxl driver was ignoring the <on_*> domain event configuration,
> causing e.g. a domain to be rebooted even when on_reboot is set to
> destroy.
>
> This patch honors the <on_*> configuration in the shutdown event
> handler.
>
> Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx>
> ---
>  src/libxl/libxl_driver.c | 83 +++++++++++++++++++++++++++++++++---------------
>  1 file changed, 57 insertions(+), 26 deletions(-)
>
> diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
> index c7c7b4f..721577d 100644
> --- a/src/libxl/libxl_driver.c
> +++ b/src/libxl/libxl_driver.c
> @@ -372,38 +372,69 @@ libxlDomainShutdownThread(void *opaque)
>  
>      virObjectLock(vm);
>  
> -    switch (xl_reason) {
> -        case LIBXL_SHUTDOWN_REASON_POWEROFF:
> -        case LIBXL_SHUTDOWN_REASON_CRASH:
> -            if (xl_reason == LIBXL_SHUTDOWN_REASON_CRASH) {
> -                dom_event = virDomainEventLifecycleNewFromObj(vm,
> +    if (xl_reason == LIBXL_SHUTDOWN_REASON_POWEROFF) {
> +        dom_event = virDomainEventLifecycleNewFromObj(vm,
> +                                           VIR_DOMAIN_EVENT_STOPPED,
> +                                           VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
> +        switch (vm->def->onPoweroff) {
> +        case VIR_DOMAIN_LIFECYCLE_DESTROY:
> +            reason = VIR_DOMAIN_SHUTOFF_SHUTDOWN;
> +            goto destroy;
> +        case VIR_DOMAIN_LIFECYCLE_RESTART:
> +        case VIR_DOMAIN_LIFECYCLE_RESTART_RENAME:
> +            goto restart;
> +        case VIR_DOMAIN_LIFECYCLE_PRESERVE:
> +            goto cleanup;
> +        }
> +    } else if (xl_reason == LIBXL_SHUTDOWN_REASON_CRASH) {
> +        dom_event = virDomainEventLifecycleNewFromObj(vm,
>                                             VIR_DOMAIN_EVENT_STOPPED,
>                                             VIR_DOMAIN_EVENT_STOPPED_CRASHED);
> -                reason = VIR_DOMAIN_SHUTOFF_CRASHED;
> -            } else {
> -                dom_event = virDomainEventLifecycleNewFromObj(vm,
> +        switch (vm->def->onCrash) {
> +        case VIR_DOMAIN_LIFECYCLE_CRASH_DESTROY:
> +            reason = VIR_DOMAIN_SHUTOFF_CRASHED;
> +            goto destroy;
> +        case VIR_DOMAIN_LIFECYCLE_CRASH_RESTART:
> +        case VIR_DOMAIN_LIFECYCLE_CRASH_RESTART_RENAME:
> +            goto restart;
> +        case VIR_DOMAIN_LIFECYCLE_CRASH_PRESERVE:
> +            goto cleanup;
> +        }
> +    } else if (xl_reason == LIBXL_SHUTDOWN_REASON_REBOOT) {
> +        dom_event = virDomainEventLifecycleNewFromObj(vm,
>                                             VIR_DOMAIN_EVENT_STOPPED,
>                                             VIR_DOMAIN_EVENT_STOPPED_SHUTDOWN);
> -                reason = VIR_DOMAIN_SHUTOFF_SHUTDOWN;
> -            }
> -            libxl_domain_destroy(ctx, vm->def->id, NULL);
> -            if (libxlVmCleanupJob(driver, vm, reason)) {
> -                if (!vm->persistent) {
> -                    virDomainObjListRemove(driver->domains, vm);
> -                    vm = NULL;
> -                }
> -            }
> -            break;
> -        case LIBXL_SHUTDOWN_REASON_REBOOT:
> -            libxl_domain_destroy(ctx, vm->def->id, NULL);
> -            libxlVmCleanupJob(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
> -            libxlVmStart(driver, vm, 0, -1);
> -            break;
> -        default:
> -            VIR_INFO("Unhandled shutdown_reason %d", xl_reason);
> -            break;
> +        switch (vm->def->onReboot) {
> +        case VIR_DOMAIN_LIFECYCLE_DESTROY:
> +            reason = VIR_DOMAIN_SHUTOFF_SHUTDOWN;
> +            goto destroy;
> +        case VIR_DOMAIN_LIFECYCLE_RESTART:
> +        case VIR_DOMAIN_LIFECYCLE_RESTART_RENAME:
> +            goto restart;
> +        case VIR_DOMAIN_LIFECYCLE_PRESERVE:
> +            goto cleanup;
> +        }
> +    } else {
> +        VIR_INFO("Unhandled shutdown_reason %d", xl_reason);
> +        goto cleanup;
>      }
>  
> +destroy:
> +    libxl_domain_destroy(ctx, vm->def->id, NULL);
> +    if (libxlVmCleanupJob(driver, vm, reason)) {
> +        if (!vm->persistent) {
> +            virDomainObjListRemove(driver->domains, vm);
> +            vm = NULL;
> +        }
> +    }
> +    goto cleanup;
> +
> +restart:
> +    libxl_domain_destroy(ctx, vm->def->id, NULL);
> +    libxlVmCleanup(driver, vm, VIR_DOMAIN_SHUTOFF_SHUTDOWN);
>   

Opps, botched rebasing of my own branches.  This should be
libxlVmCleanupJob.  I've fixed it in my local branch.

Regards,
Jim


> +    libxlVmStart(driver, vm, 0, -1);
> +
> +cleanup:
>      if (vm)
>          virObjectUnlock(vm);
>      if (dom_event)
>   

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]