Re: [PATCH v2] libxl: add memory attach support

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

 



On 08/31/2016 02:40 AM, Bob Liu wrote:
> Support for VIR_DOMAIN_DEVICE_MEMORY on domainAttachDeviceFlags API in libxl
> driver, using libxl_set_memory_target in xen libxl.
>
> With "virsh attach-device" command we can then hotplug memory to a domain:
> <memory model='dimm'>
>     <target>
>         <size unit='MiB'>128</size>
>         <node>0</node>
>     </target>
> </memory>
>
> $ virsh attach-device domain_name this.xml --live
>
> Signed-off-by: Bob Liu <bob.liu@xxxxxxxxxx>
> ---
> v2:
>  * Unlock virDomainObj while attaching.
>  * Fix memory leak of mem.
> ---
>  src/libxl/libxl_domain.c |  1 +
>  src/libxl/libxl_driver.c | 35 +++++++++++++++++++++++++++++++++++
>  2 files changed, 36 insertions(+)
>
> diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
> index f529a2e..3924ba0 100644
> --- a/src/libxl/libxl_domain.c
> +++ b/src/libxl/libxl_domain.c
> @@ -414,6 +414,7 @@ virDomainDefParserConfig libxlDomainDefParserConfig = {
>      .macPrefix = { 0x00, 0x16, 0x3e },
>      .devicesPostParseCallback = libxlDomainDeviceDefPostParse,
>      .domainPostParseCallback = libxlDomainDefPostParse,
> +    .features = VIR_DOMAIN_DEF_FEATURE_MEMORY_HOTPLUG
>  };
>  
>  
> diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
> index a34eb02..b23c1d4 100644
> --- a/src/libxl/libxl_driver.c
> +++ b/src/libxl/libxl_driver.c
> @@ -3085,6 +3085,34 @@ libxlDomainAttachHostUSBDevice(libxlDriverPrivatePtr driver,
>  #endif
>  
>  static int
> +libxlDomainAttachMemory(libxlDriverPrivatePtr driver,
> +                        virDomainObjPtr vm,
> +                        virDomainMemoryDefPtr mem)
> +{
> +    int res = -1;
> +    libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
> +
> +    if (mem->targetNode != 0) {
> +        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
> +                       _("Non-zero target node is not supported."));
> +        goto out;
> +    }
> +
> +    /* Unlock virDomainObj while attaching memory */
> +    virObjectUnlock(vm);
> +    res = libxl_set_memory_target(cfg->ctx, vm->def->id, mem->size, 1, 1);

As others mentioned in V1, this is just ballooning memory right? The
documentation for attaching memory devices states "In addition to the initial
memory assigned to the guest, memory devices allow additional memory to be
assigned to the guest in the form of memory modules." AFAIK, that is not what
libxl_set_memory_target does. IMO, the same can already be achieved with the
virDomainSetMemory{,Flags} APIs and this patch is not necessary.

Regards,
Jim


> +    virObjectLock(vm);
> +    if (res < 0)
> +        virReportError(VIR_ERR_INTERNAL_ERROR,
> +                       _("Failed to attach %lluKB memory for domain %d"),
> +                       mem->size, vm->def->id);
> +
> + out:
> +    virDomainMemoryDefFree(mem);
> +    return res;
> +}
> +
> +static int
>  libxlDomainAttachHostDevice(libxlDriverPrivatePtr driver,
>                              virDomainObjPtr vm,
>                              virDomainHostdevDefPtr hostdev)
> @@ -3284,6 +3312,13 @@ libxlDomainAttachDeviceLive(libxlDriverPrivatePtr driver,
>                  dev->data.hostdev = NULL;
>              break;
>  
> +        case VIR_DOMAIN_DEVICE_MEMORY:
> +            /* Note that libxlDomainAttachMemory always consumes
> +             * dev->data.memory. */
> +            ret = libxlDomainAttachMemory(driver, vm, dev->data.memory);
> +            dev->data.memory = NULL;
> +            break;
> +
>          default:
>              virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
>                             _("device type '%s' cannot be attached"),

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