[libvirt] [PATCH 2/9] Use virDomainObjGetDefs in lxcDomainSetMemoryFlags

John Ferlan jferlan at redhat.com
Wed Jun 8 12:44:37 UTC 2016



On 06/06/2016 04:08 AM, Ján Tomko wrote:
> On LXC domain startup we have already called virDomainObjSetDefTransient
> to fill vm->newDef.
> 
> There is no need to call virDomainLiveConfigHelperMethod which has the
> ability to fill newDef if it's NULL.
> ---
>  src/lxc/lxc_driver.c | 26 ++++++++++----------------
>  1 file changed, 10 insertions(+), 16 deletions(-)
> 
> diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
> index e854f35..72a144b 100644
> --- a/src/lxc/lxc_driver.c
> +++ b/src/lxc/lxc_driver.c
> @@ -694,8 +694,7 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
>                                     unsigned int flags)
>  {
>      virDomainObjPtr vm;
> -    virDomainDefPtr persistentDef = NULL;
> -    virCapsPtr caps = NULL;
> +    virDomainDefPtr def = NULL, persistentDef = NULL;

NIT: Other code has these on separate lines

John
>      int ret = -1;
>      virLXCDomainObjPrivatePtr priv;
>      virLXCDriverPtr driver = dom->conn->privateData;
> @@ -718,22 +717,18 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
>      if (virLXCDomainObjBeginJob(driver, vm, LXC_JOB_MODIFY) < 0)
>          goto cleanup;
>  
> -    if (!(caps = virLXCDriverGetCapabilities(driver, false)))
> -        goto endjob;
> -
> -    if (virDomainLiveConfigHelperMethod(caps, driver->xmlopt, vm, &flags,
> -                                        &persistentDef) < 0)
> +    if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
>          goto endjob;
>  
>      if (flags & VIR_DOMAIN_MEM_MAXIMUM) {
> -        if (flags & VIR_DOMAIN_AFFECT_LIVE) {
> +        if (def) {
>              virReportError(VIR_ERR_OPERATION_INVALID, "%s",
>                             _("Cannot resize the max memory "
>                               "on an active domain"));
>              goto endjob;
>          }
>  
> -        if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
> +        if (persistentDef) {
>              virDomainDefSetMemoryTotal(persistentDef, newmem);
>              if (persistentDef->mem.cur_balloon > newmem)
>                  persistentDef->mem.cur_balloon = newmem;
> @@ -744,9 +739,9 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
>      } else {
>          unsigned long oldmax = 0;
>  
> -        if (flags & VIR_DOMAIN_AFFECT_LIVE)
> -            oldmax = virDomainDefGetMemoryActual(vm->def);
> -        if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
> +        if (def)
> +            oldmax = virDomainDefGetMemoryActual(def);
> +        if (persistentDef) {
>              if (!oldmax || oldmax > virDomainDefGetMemoryActual(persistentDef))
>                  oldmax = virDomainDefGetMemoryActual(persistentDef);
>          }
> @@ -757,19 +752,19 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
>              goto endjob;
>          }
>  
> -        if (flags & VIR_DOMAIN_AFFECT_LIVE) {
> +        if (def) {
>              if (virCgroupSetMemory(priv->cgroup, newmem) < 0) {
>                  virReportError(VIR_ERR_OPERATION_FAILED,
>                                 "%s", _("Failed to set memory for domain"));
>                  goto endjob;
>              }
>  
> -            vm->def->mem.cur_balloon = newmem;
> +            def->mem.cur_balloon = newmem;
>              if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0)
>                  goto endjob;
>          }
>  
> -        if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
> +        if (persistentDef) {
>              persistentDef->mem.cur_balloon = newmem;
>              if (virDomainSaveConfig(cfg->configDir, driver->caps,
>                                      persistentDef) < 0)
> @@ -784,7 +779,6 @@ static int lxcDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
>  
>   cleanup:
>      virDomainObjEndAPI(&vm);
> -    virObjectUnref(caps);
>      virObjectUnref(cfg);
>      return ret;
>  }
> 




More information about the libvir-list mailing list