[libvirt] [PATCH 06/12] Implement driver interface domainSetMemoryParamters for QEmu

Daniel P. Berrange berrange at redhat.com
Tue Sep 21 17:21:39 UTC 2010


On Mon, Sep 20, 2010 at 02:16:51PM +0530, Nikunj A. Dadhania wrote:
> Driver interface for setting memory hard_limit, soft_limit and swap
> hard_limit. This patch also NULLs the other HV driver interface structure.
> 
> Signed-off-by: Nikunj A. Dadhania <nikunj at linux.vnet.ibm.com>
> ---
>  src/esx/esx_driver.c       |    1 
>  src/lxc/lxc_driver.c       |    1 
>  src/openvz/openvz_driver.c |    1 
>  src/phyp/phyp_driver.c     |    1 
>  src/qemu/qemu_driver.c     |   93 ++++++++++++++++++++++++++++++++++++++++++++
>  src/remote/remote_driver.c |    1 
>  src/test/test_driver.c     |    1 
>  src/uml/uml_driver.c       |    1 
>  src/xen/xen_driver.c       |    1 
>  9 files changed, 101 insertions(+), 0 deletions(-)
> 
> diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
> index e382950..be55796 100644
> --- a/src/esx/esx_driver.c
> +++ b/src/esx/esx_driver.c
> @@ -4217,6 +4217,7 @@ static virDriver esxDriver = {
>      esxDomainRevertToSnapshot,       /* domainRevertToSnapshot */
>      esxDomainSnapshotDelete,         /* domainSnapshotDelete */
>      NULL,                            /* qemuDomainMonitorCommand */
> +    NULL,                            /* domainSetMemoryParameters */
>  };

All these bits should be in the patch which changes 'driver.h', so that
the code compiles there. 

This patch needs just replace the 'NULL' with the real function for
QEMU.


> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
> index c4aacc9..06666e9 100644
> --- a/src/qemu/qemu_driver.c
> +++ b/src/qemu/qemu_driver.c
> @@ -9365,6 +9365,98 @@ cleanup:
>      return ret;
>  }
>  
> +
> +static int qemuDomainSetMemoryParameters(virDomainPtr dom,
> +                                         virMemoryParameterPtr params,
> +                                         int nparams)
> +{
> +    struct qemud_driver *driver = dom->conn->privateData;
> +    int i;
> +    virCgroupPtr group = NULL;
> +    virDomainObjPtr vm = NULL;
> +    int ret = -1;
> +
> +    qemuDriverLock(driver);
> +    if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_MEMORY)) {
> +        qemuReportError(VIR_ERR_NO_SUPPORT,
> +                        __FUNCTION__);
> +        goto cleanup;
> +    }
> +
> +    vm = virDomainFindByUUID(&driver->domains, dom->uuid);
> +
> +    if (vm == NULL) {
> +        qemuReportError(VIR_ERR_INTERNAL_ERROR,
> +                        _("No such domain %s"), dom->uuid);
> +        goto cleanup;
> +    }
> +
> +    if (virCgroupForDomain(driver->cgroup, vm->def->name, &group, 0) != 0) {
> +        qemuReportError(VIR_ERR_INTERNAL_ERROR,
> +                        _("cannot find cgroup for domain %s"), vm->def->name);
> +        goto cleanup;
> +    }
> +
> +    for (i = 0; i < nparams; i++) {
> +        virMemoryParameterPtr param = &params[i];
> +
> +        if (STREQ(param->field, "hard_limit")) {
> +            int rc;
> +            if (param->type != VIR_DOMAIN_MEMORY_FIELD_ULLONG) {
> +                qemuReportError(VIR_ERR_INVALID_ARG, "%s",
> +                                _("invalid type for memory hard_limit tunable, expected a 'ullong'"));
> +                continue;
> +            }
> +
> +            rc = virCgroupSetMemoryHardLimit(group, params[i].value.ul);
> +            if (rc != 0) {
> +                virReportSystemError(-rc, "%s",
> +                                     _("unable to set memory hard_limit tunable"));
> +            }
> +        } else if (STREQ(param->field, "soft_limit")) {
> +            int rc;
> +            if (param->type != VIR_DOMAIN_MEMORY_FIELD_ULLONG) {
> +                qemuReportError(VIR_ERR_INVALID_ARG, "%s",
> +                                _("invalid type for memory soft_limit tunable, expected a 'ullong'"));
> +                continue;
> +            }
> +
> +            rc = virCgroupSetMemorySoftLimit(group, params[i].value.ul);
> +            if (rc != 0) {
> +                virReportSystemError(-rc, "%s",
> +                                     _("unable to set memory soft_limit tunable"));
> +            }
> +        } else if (STREQ(param->field, "swap_hard_limit")) {
> +            int rc;
> +            if (param->type != VIR_DOMAIN_MEMORY_FIELD_ULLONG) {
> +                qemuReportError(VIR_ERR_INVALID_ARG, "%s",
> +                                _("invalid type for swap_hard_limit tunable, expected a 'ullong'"));
> +                continue;
> +            }
> +
> +            rc = virCgroupSetSwapHardLimit(group, params[i].value.ul);
> +            if (rc != 0) {
> +                virReportSystemError(-rc, "%s",
> +                                     _("unable to set swap_hard_limit tunable"));
> +            }
> +        } else if (STREQ(param->field, "min_gaurantee")) {

Same typo here  s/gaur/guar/

> +            qemuReportError(VIR_ERR_INVALID_ARG,
> +                            _("Memory tunable `%s' not implemented"), param->field);
> +        } else {
> +            qemuReportError(VIR_ERR_INVALID_ARG,
> +                            _("Parameter `%s' not supported"), param->field);
> +        }
> +    }
> +    ret = 0;
> +
> +cleanup:
> +    virCgroupFree(&group);
> +    if (vm)
> +        virDomainObjUnlock(vm);
> +    qemuDriverUnlock(driver);
> +    return ret;
> +}

This looks pretty sane. Just need to swap patches 6 & 7 in order, because
this patch requires the cgroups functions before it will compile

Daniel
-- 
|: Red Hat, Engineering, London    -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org -o- http://virt-manager.org -o- http://deltacloud.org :|
|: http://autobuild.org        -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-   F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the libvir-list mailing list