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

Re: [libvirt] [PATCH] OpenVZ: implement suspend/resume driver APIs



On Fri, Jul 30, 2010 at 05:48:49PM +0200, Jean-Baptiste Rouault wrote:
> ---
>  src/openvz/openvz_driver.c |   84 ++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 82 insertions(+), 2 deletions(-)
> 
> diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
> index e5bbdd0..bdc0e92 100644
> --- a/src/openvz/openvz_driver.c
> +++ b/src/openvz/openvz_driver.c
> @@ -503,6 +503,86 @@ static void openvzSetProgramSentinal(const char **prog, const char *key)
>      }
>  }
>  
> +static int openvzDomainSuspend(virDomainPtr dom) {
> +    struct openvz_driver *driver = dom->conn->privateData;
> +    virDomainObjPtr vm;
> +    const char *prog[] = {VZCTL, "--quiet", "chkpnt", PROGRAM_SENTINAL, "--suspend", NULL};
> +    int ret = -1;
> +
> +    openvzDriverLock(driver);
> +    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
> +    openvzDriverUnlock(driver);
> +
> +    if (!vm) {
> +        openvzError(VIR_ERR_INVALID_DOMAIN, "%s",
> +                    _("no domain with matching uuid"));
> +        goto cleanup;
> +    }
> +
> +    if (!virDomainObjIsActive(vm)) {
> +        openvzError(VIR_ERR_OPERATION_INVALID, "%s",
> +                    _("Domain is not running"));
> +        goto cleanup;
> +    }
> +
> +    if (vm->state != VIR_DOMAIN_PAUSED) {
> +        openvzSetProgramSentinal(prog, vm->def->name);
> +        if (virRun(prog, NULL) < 0) {
> +            openvzError(VIR_ERR_OPERATION_FAILED, "%s",
> +                        _("Suspend operation failed"));
> +            goto cleanup;
> +        }
> +        vm->state = VIR_DOMAIN_PAUSED;
> +    }
> +
> +    ret = 0;
> +
> +cleanup:
> +    if (vm)
> +        virDomainObjUnlock(vm);
> +    return ret;
> +}
> +
> +static int openvzDomainResume(virDomainPtr dom) {
> +  struct openvz_driver *driver = dom->conn->privateData;
> +  virDomainObjPtr vm;
> +  const char *prog[] = {VZCTL, "--quiet", "chkpnt", PROGRAM_SENTINAL, "--resume", NULL};
> +  int ret = -1;
> +
> +  openvzDriverLock(driver);
> +  vm = virDomainFindByUUID(&driver->domains, dom->uuid);
> +  openvzDriverUnlock(driver);
> +
> +  if (!vm) {
> +      openvzError(VIR_ERR_INVALID_DOMAIN, "%s",
> +                  _("no domain with matching uuid"));
> +      goto cleanup;
> +  }
> +
> +  if (!virDomainObjIsActive(vm)) {
> +      openvzError(VIR_ERR_OPERATION_INVALID, "%s",
> +                  _("Domain is not running"));
> +      goto cleanup;
> +  }
> +
> +  if (vm->state == VIR_DOMAIN_PAUSED) {
> +      openvzSetProgramSentinal(prog, vm->def->name);
> +      if (virRun(prog, NULL) < 0) {
> +          openvzError(VIR_ERR_OPERATION_FAILED, "%s",
> +                      _("Resume operation failed"));
> +          goto cleanup;
> +      }
> +      vm->state = VIR_DOMAIN_RUNNING;
> +  }
> +  ret = 0;
> +
> +cleanup:
> +  if (vm)
> +      virDomainObjUnlock(vm);
> +  return ret;
> +}
> +
>  static int openvzDomainShutdown(virDomainPtr dom) {
>      struct openvz_driver *driver = dom->conn->privateData;
>      virDomainObjPtr vm;
> @@ -1491,8 +1571,8 @@ static virDriver openvzDriver = {
>      openvzDomainLookupByID, /* domainLookupByID */
>      openvzDomainLookupByUUID, /* domainLookupByUUID */
>      openvzDomainLookupByName, /* domainLookupByName */
> -    NULL, /* domainSuspend */
> -    NULL, /* domainResume */
> +    openvzDomainSuspend, /* domainSuspend */
> +    openvzDomainResume, /* domainResume */
>      openvzDomainShutdown, /* domainShutdown */
>      openvzDomainReboot, /* domainReboot */
>      openvzDomainShutdown, /* domainDestroy */

  This patch looks fine, simple enough and should not introduce
  regressions, so I'm pushing it to be part of 0.8.3

   thanks !

Daniel

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


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