Re: [PATCH v7 6/6] qemu: Implement oncrash 'rename-resart' event when guest panicked

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

 



On Fri, Jun 14, 2013 at 06:14:40PM +0800, Chen Fan wrote:
> Implements 'rename-restart' behavior of the 'on_crash'
> in the XML when domain crashed.
> ---
>  src/qemu/qemu_driver.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 67 insertions(+)
> 
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index eefe7a2..a166468 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -3566,6 +3566,55 @@ cleanup:
>      return ret;
>  }
>  
> +static int
> +qemuProcessVmRenameAlive(virQEMUDriverPtr driver,
> +                         virDomainObjPtr vm, char *alias)
> +{
> +    int ret = -1;
> +    char *oldname = NULL;
> +    char *newDefname = NULL;
> +    char ebuf[1024];
> +    char *statefile = NULL;
> +    virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
> +
> +    if (strstr(vm->def->name, "-crashed")) {
> +        ret = 0;
> +        goto cleanup;
> +    }
> +
> +    oldname = vm->def->name;
> +    vm->def->name = alias;
> +
> +    if (vm->newDef) {
> +        if (VIR_STRDUP(newDefname, oldname) < 0) {
> +            virReportOOMError();
> +            goto cleanup;
> +        }
> +        VIR_FREE(vm->newDef->name);
> +        vm->newDef->name = newDefname;
> +    }
> +
> +    if (virAsprintf(&statefile, "%s/%s.xml", cfg->stateDir, oldname) < 0) {
> +        virReportOOMError();
> +        goto cleanup;
> +    }
> +
> +    if (unlink(statefile) < 0 && errno != ENOENT && errno != ENOTDIR)
> +        VIR_WARN("Failed to remove domain XML for %s: %s",
> +                 oldname, virStrerror(errno, ebuf, sizeof(ebuf)));
> +
> +    if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
> +        VIR_WARN("Failed to save status on vm %s", vm->def->name);
> +
> +    ret = 0;
> +
> +cleanup:
> +    VIR_FREE(statefile);
> +    VIR_FREE(oldname);
> +    virObjectUnref(cfg);
> +    return ret;
> +}
> +
>  static void
>  processGuestPanicEvent(virQEMUDriverPtr driver,
>                         virDomainObjPtr vm,
> @@ -3650,6 +3699,24 @@ processGuestPanicEvent(virQEMUDriverPtr driver,
>          qemuProcessShutdownOrReboot(driver, vm);
>          break;
>  
> +    case VIR_DOMAIN_LIFECYCLE_CRASH_RESTART_RENAME:
> +        {
> +            char *alias = NULL;
> +            if (virAsprintf(&alias, "%s-crashed",

The doc doesn't say how to rename a domain on crash, I'm not sure
whether oldname + "-crashed" is reasonable. While changing the name,
should we change the UUID at the same time?

> +                            vm->def->name) < 0) {
> +                virReportOOMError();
> +                goto cleanup;
> +            }
> +            if (qemuProcessVmRenameAlive(driver, vm, alias) < 0) {

BTW, seems there can be a API for changing domain name.

> +                VIR_FREE(alias);
> +                goto cleanup;
> +            }
> +
> +            qemuDomainSetFakeReboot(driver, vm, true);
> +            qemuProcessShutdownOrReboot(driver, vm);
> +        }
> +        break;
> +
>      case VIR_DOMAIN_LIFECYCLE_CRASH_PRESERVE:
>          break;
>  
> -- 
> 1.8.1.4
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list

--
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]