[libvirt] [PATCH 3/5] setmaxmem: implement the code to address the new API in the qemu driver

Wen Congyang wency at cn.fujitsu.com
Fri Mar 18 03:36:06 UTC 2011


At 03/18/2011 10:45 AM, Taku Izumi Write:
> 
> This patch implements the code to address the new API
> (virDomainSetMaxMemoryFlags) and virDomainSetMaxMemory API
> in the qemu driver.
> 
> 
> 
> Signed-off-by: Taku Izumi <izumi.taku at jp.fujitsu.com>
> ---
>  src/qemu/qemu_driver.c |   63 +++++++++++++++++++++++++++++++++++++++++++++++--
>  1 file changed, 61 insertions(+), 2 deletions(-)
> 
> Index: libvirt/src/qemu/qemu_driver.c
> ===================================================================
> --- libvirt.orig/src/qemu/qemu_driver.c
> +++ libvirt/src/qemu/qemu_driver.c
> @@ -1569,6 +1569,65 @@ cleanup:
>      return ret;
>  }
> 
> +static int qemudDomainSetMaxMemoryFlags(virDomainPtr dom, unsigned long memory,
> +                                        unsigned int flags) {
> +
> +    struct qemud_driver *driver = dom->conn->privateData;
> +    virDomainObjPtr vm = NULL;
> +    virDomainDefPtr persistentDef = NULL;
> +    int ret = -1;
> +
> +    virCheckFlags(VIR_DOMAIN_MEM_LIVE |
> +                  VIR_DOMAIN_MEM_CONFIG, -1);
> +
> +    if (flags & VIR_DOMAIN_MEM_LIVE) {
> +	qemuReportError(VIR_ERR_OPERATION_INVALID,
> +                        _("cannot resize the maximum memory on active domain"));
> +        goto cleanup;
> +    }
> +
> +    qemuDriverLock(driver);
> +    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
> +    qemuDriverUnlock(driver);
> +    if (!vm) {
> +	char uuidstr[VIR_UUID_STRING_BUFLEN];

Please use space instead of tab.

> +        virUUIDFormat(dom->uuid, uuidstr);
> +        qemuReportError(VIR_ERR_NO_DOMAIN,
> +                        _("no domain with matching uuid '%s'"), uuidstr);
> +        goto cleanup;
> +    }
> +
> +    if (qemuDomainObjBeginJob(vm) < 0)
> +        goto cleanup;
> +
> +    if (flags & VIR_DOMAIN_MEM_CONFIG) {
> +        persistentDef = virDomainObjGetPersistentDef(driver->caps, vm);
> +        if (!persistentDef)
> +            goto endjob;
> +
> +        persistentDef->mem.max_balloon = memory;
> +        if (persistentDef->mem.cur_balloon > memory)
> +            persistentDef->mem.cur_balloon = memory;
> +
> +        ret = virDomainSaveConfig(driver->configDir, persistentDef);
> +        goto endjob;
> +    }
> +
> +endjob:
> +    if (qemuDomainObjEndJob(vm) == 0)
> +        vm = NULL;
> +
> +cleanup:
> +    if (vm)
> +        virDomainObjUnlock(vm);
> +    return ret;
> +
> +}
> +
> +static int qemudDomainSetMaxMemory(virDomainPtr dom, unsigned long memory) {
> +	return qemudDomainSetMaxMemoryFlags(dom, memory, VIR_DOMAIN_MEM_LIVE);
> +}
> +
>  static int qemudDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
>                                       unsigned int flags) {
>      struct qemud_driver *driver = dom->conn->privateData;
> @@ -7044,8 +7103,8 @@ static virDriver qemuDriver = {
>      qemudDomainDestroy, /* domainDestroy */
>      qemudDomainGetOSType, /* domainGetOSType */
>      qemudDomainGetMaxMemory, /* domainGetMaxMemory */
> -    NULL, /* domainSetMaxMemory */
> -    NULL, /* domainSetMaxMemoryFlags */
> +    qemudDomainSetMaxMemory, /* domainSetMaxMemory */
> +    qemudDomainSetMaxMemoryFlags, /* domainSetMaxMemoryFlags */
>      qemudDomainSetMemory, /* domainSetMemory */
>      qemudDomainSetMemoryFlags, /* domainSetMemoryFlags */
>      qemuDomainSetMemoryParameters, /* domainSetMemoryParameters */
> 
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list
> 




More information about the libvir-list mailing list