From 191e1ec65ce79b0a2d61874089ad3f2111adf089 Mon Sep 17 00:00:00 2001 From: Matthias Bolte Date: Wed, 18 May 2011 11:33:42 +0200 Subject: [PATCH] Clarify that virDomainGet(Memory|Blkio)Parameters doesn't support subsets Improve invalid argument checks in the size query case. The drivers already relied on this unchecked behavior. Relax the implementation of virDomainGet(Memory|Blkio)MemoryParameters in the drivers and allow to pass more memory than necessary for all parameters. --- src/libvirt.c | 13 ++++++++----- src/lxc/lxc_driver.c | 5 +++-- src/qemu/qemu_driver.c | 5 +++-- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index fa783b76f3..31d65f7863 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -3051,7 +3051,7 @@ error: * @nparams: pointer to number of memory parameters * @flags: currently unused, for future extension * - * Get the memory parameters, the @params array will be filled with the values + * Get all memory parameters, the @params array will be filled with the values * equal to the number of parameters suggested by @nparams * * As the value of @nparams is dynamic, call the API setting @nparams to 0 and @@ -3094,7 +3094,8 @@ virDomainGetMemoryParameters(virDomainPtr domain, virDispatchError(NULL); return -1; } - if ((nparams == NULL) || (*nparams < 0)) { + if ((nparams == NULL) || (*nparams < 0) || + (params == NULL && *nparams != 0)) { virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__); goto error; } @@ -3177,8 +3178,9 @@ error: * @nparams: pointer to number of blkio parameters * @flags: currently unused, for future extension * - * Get the blkio parameters, the @params array will be filled with the values - * equal to the number of parameters suggested by @nparams + * Get all blkio parameters, the @params array will be filled with the values + * equal to the number of parameters suggested by @nparams. + * See virDomainGetMemoryParameters for an equivalent usage example. * * This function requires privileged access to the hypervisor. This function * expects the caller to allocate the @params. @@ -3202,7 +3204,8 @@ virDomainGetBlkioParameters(virDomainPtr domain, virDispatchError(NULL); return -1; } - if ((nparams == NULL) || (*nparams < 0)) { + if ((nparams == NULL) || (*nparams < 0) || + (params == NULL && *nparams != 0)) { virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__); goto error; } diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c index a65299bc17..9e09c956b5 100644 --- a/src/lxc/lxc_driver.c +++ b/src/lxc/lxc_driver.c @@ -871,7 +871,7 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom, ret = 0; goto cleanup; } - if ((*nparams) != LXC_NB_MEM_PARAM) { + if ((*nparams) < LXC_NB_MEM_PARAM) { lxcError(VIR_ERR_INVALID_ARG, "%s", _("Invalid parameter count")); goto cleanup; @@ -883,7 +883,7 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom, goto cleanup; } - for (i = 0; i < *nparams; i++) { + for (i = 0; i < LXC_NB_MEM_PARAM; i++) { virMemoryParameterPtr param = ¶ms[i]; val = 0; param->value.ul = 0; @@ -941,6 +941,7 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom, } } + *nparams = LXC_NB_MEM_PARAM; ret = 0; cleanup: diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9a7286dcfa..2f9c8e7b61 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -4957,7 +4957,7 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom, goto cleanup; } - if ((*nparams) != QEMU_NB_MEM_PARAM) { + if ((*nparams) < QEMU_NB_MEM_PARAM) { qemuReportError(VIR_ERR_INVALID_ARG, "%s", _("Invalid parameter count")); goto cleanup; @@ -4969,7 +4969,7 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom, goto cleanup; } - for (i = 0; i < *nparams; i++) { + for (i = 0; i < QEMU_NB_MEM_PARAM; i++) { virMemoryParameterPtr param = ¶ms[i]; val = 0; param->value.ul = 0; @@ -5027,6 +5027,7 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom, } } + *nparams = QEMU_NB_MEM_PARAM; ret = 0; cleanup: -- GitLab