Re: [PATCH] qemu: Preserve fakeReboot flag in domain status

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

 



On Wed, Sep 28, 2011 at 12:13:35PM +0200, Jiri Denemark wrote:
> Thus, when libvirtd is restarted, it will know if a domain is supposed
> to be killed or reset when it shuts down.
> ---
>  src/qemu/qemu_domain.c  |   21 +++++++++++++++++++++
>  src/qemu/qemu_domain.h  |    4 ++++
>  src/qemu/qemu_driver.c  |   11 +++++------
>  src/qemu/qemu_process.c |    4 ++--
>  4 files changed, 32 insertions(+), 8 deletions(-)
> 
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index 4023648..320a35c 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -302,6 +302,9 @@ static int qemuDomainObjPrivateXMLFormat(virBufferPtr buf, void *data)
>          virBufferAddLit(buf, "/>\n");
>      }
>  
> +    if (priv->fakeReboot)
> +        virBufferAsprintf(buf, "  <fakereboot/>\n");
> +
>      return 0;
>  }
>  
> @@ -445,6 +448,8 @@ static int qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, void *data)
>          }
>      }
>  
> +    priv->fakeReboot = virXPathBoolean("boolean(./fakereboot)", ctxt) == 1;
> +
>      return 0;
>  
>  error:
> @@ -1566,3 +1571,19 @@ qemuDomainRemoveInactive(struct qemud_driver *driver,
>      }
>      virDomainRemoveInactive(&driver->domains, vm);
>  }
> +
> +void
> +qemuDomainSetFakeReboot(struct qemud_driver *driver,
> +                        virDomainObjPtr vm,
> +                        bool value)
> +{
> +    qemuDomainObjPrivatePtr priv = vm->privateData;
> +
> +    if (priv->fakeReboot == value)
> +        return;
> +
> +    priv->fakeReboot = value;
> +
> +    if (virDomainSaveStatus(driver->caps, driver->stateDir, vm) < 0)
> +        VIR_WARN("Failed to save status on vm %s", vm->def->name);
> +}
> diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
> index 00cfa3a..3b09419 100644
> --- a/src/qemu/qemu_domain.h
> +++ b/src/qemu/qemu_domain.h
> @@ -273,4 +273,8 @@ int qemuDomainSnapshotDiscardAllMetadata(struct qemud_driver *driver,
>  void qemuDomainRemoveInactive(struct qemud_driver *driver,
>                                virDomainObjPtr vm);
>  
> +void qemuDomainSetFakeReboot(struct qemud_driver *driver,
> +                             virDomainObjPtr vm,
> +                             bool value);
> +
>  #endif /* __QEMU_DOMAIN_H__ */
> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index 0d0bea2..8cbb850 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -1512,13 +1512,13 @@ static int qemuDomainShutdown(virDomainPtr dom) {
>          goto endjob;
>      }
>  
> +    qemuDomainSetFakeReboot(driver, vm, false);
> +
>      priv = vm->privateData;
>      qemuDomainObjEnterMonitor(driver, vm);
>      ret = qemuMonitorSystemPowerdown(priv->mon);
>      qemuDomainObjExitMonitor(driver, vm);
>  
> -    priv->fakeReboot = false;
> -
>  endjob:
>      if (qemuDomainObjEndJob(driver, vm) == 0)
>          vm = NULL;
> @@ -1575,7 +1575,8 @@ static int qemuDomainReboot(virDomainPtr dom, unsigned int flags) {
>          ret = qemuMonitorSystemPowerdown(priv->mon);
>          qemuDomainObjExitMonitor(driver, vm);
>  
> -        priv->fakeReboot = true;
> +        if (ret == 0)
> +            qemuDomainSetFakeReboot(driver, vm, true);
>  
>      endjob:
>          if (qemuDomainObjEndJob(driver, vm) == 0)
> @@ -1616,7 +1617,6 @@ qemuDomainDestroyFlags(virDomainPtr dom,
>      virDomainObjPtr vm;
>      int ret = -1;
>      virDomainEventPtr event = NULL;
> -    qemuDomainObjPrivatePtr priv;
>  
>      virCheckFlags(0, -1);
>  
> @@ -1630,8 +1630,7 @@ qemuDomainDestroyFlags(virDomainPtr dom,
>          goto cleanup;
>      }
>  
> -    priv = vm->privateData;
> -    priv->fakeReboot = false;
> +    qemuDomainSetFakeReboot(driver, vm, false);
>  
>      /* Although qemuProcessStop does this already, there may
>       * be an outstanding job active. We want to make sure we
> diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
> index 106a47c..4c6b4a4 100644
> --- a/src/qemu/qemu_process.c
> +++ b/src/qemu/qemu_process.c
> @@ -442,7 +442,7 @@ qemuProcessShutdownOrReboot(virDomainObjPtr vm)
>  
>      priv->gotShutdown = true;
>      if (priv->fakeReboot) {
> -        priv->fakeReboot = false;
> +        qemuDomainSetFakeReboot(qemu_driver, vm, false);
>          virDomainObjRef(vm);
>          virThread th;
>          if (virThreadCreate(&th,
> @@ -2846,7 +2846,7 @@ int qemuProcessStart(virConnectPtr conn,
>          goto cleanup;
>  
>      vm->def->id = driver->nextvmid++;
> -    priv->fakeReboot = false;
> +    qemuDomainSetFakeReboot(driver, vm, false);
>      virDomainObjSetState(vm, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_UNKNOWN);
>  
>      /* Run an early hook to set-up missing devices */

  ACK, that sounds right, and look so too :-)

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

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