]> xenbits.xensource.com Git - libvirt.git/commitdiff
Clarify that virDomainGet(Memory|Blkio)Parameters doesn't support subsets
authorMatthias Bolte <matthias.bolte@googlemail.com>
Wed, 18 May 2011 09:33:42 +0000 (11:33 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Wed, 18 May 2011 16:20:47 +0000 (18:20 +0200)
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
src/lxc/lxc_driver.c
src/qemu/qemu_driver.c

index fa783b76f3e8b9e3381f24cf25cb3947c5b249e8..31d65f7863be428ae43a873cdcee33c5800d86f6 100644 (file)
@@ -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;
     }
index a65299bc17e20c6a779373f718baecd1c158048e..9e09c956b5ca0293aaeefb7d66322bef45aa1dd6 100644 (file)
@@ -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 = &params[i];
         val = 0;
         param->value.ul = 0;
@@ -941,6 +941,7 @@ static int lxcDomainGetMemoryParameters(virDomainPtr dom,
         }
     }
 
+    *nparams = LXC_NB_MEM_PARAM;
     ret = 0;
 
 cleanup:
index 9a7286dcfa4d532280f777fc18a407f24c8416b2..2f9c8e7b613e41a273cd05454a8ff08d492dd2d2 100644 (file)
@@ -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 = &params[i];
         val = 0;
         param->value.ul = 0;
@@ -5027,6 +5027,7 @@ static int qemuDomainGetMemoryParameters(virDomainPtr dom,
         }
     }
 
+    *nparams = QEMU_NB_MEM_PARAM;
     ret = 0;
 
 cleanup: