[lib] Check number of CPU scheduler parameters.
authorMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 3 Nov 2009 15:08:13 +0000 (16:08 +0100)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Tue, 3 Nov 2009 15:08:13 +0000 (16:08 +0100)
  * It seems to be undefined if the nparams parameter of
    can be NULL virDomainGetSchedulerType(), so pass it.

Signed-off-by: Matthias Bolte <matthias.bolte@googlemail.com>

lib/vm.c

index 1a711fa..f296a2b 100644 (file)
--- a/lib/vm.c
+++ b/lib/vm.c
@@ -380,6 +380,7 @@ _apply_vm_sched_parameters (struct VscError *error, virDomainPtr domain,
        int totalRequestedMhz;
        char *sched_name = NULL;
        virSchedParameter sched_params[3];
+       int num_expected_sched_params = 0;
        int num_sched_params = 0;
        char host_ipv4_string[VSC_MGMT__IPV4__STRING_SIZE] = "";
 
@@ -405,7 +406,7 @@ _apply_vm_sched_parameters (struct VscError *error, virDomainPtr domain,
                 *  100 is 1 physical CPU, 50 is half a CPU, 400 is 4 CPUs,
                 *  etc..."
                 */
-               sched_name = virDomainGetSchedulerType (domain, NULL);
+               sched_name = virDomainGetSchedulerType (domain, &num_expected_sched_params);
                if (! sched_name) {
                        _ERROR_FROM_LIBVIRT (error, virDomainGetConnect (domain));
                        goto cleanup;
@@ -418,6 +419,13 @@ _apply_vm_sched_parameters (struct VscError *error, virDomainPtr domain,
                        goto cleanup;
                }
 
+               if (num_expected_sched_params != 2) {
+                       VSC__ERROR2 (error, VSC__ERROR_CODE__INVALID_CALL,
+                                    "Unexpected '%s' scheduler parameter count %d, expecting 2",
+                                    sched_name, num_expected_sched_params);
+                       goto cleanup;
+               }
+
                totalRequestedMhz = resource_config->num_cores * resource_config->core_clock;
                num_sched_params = 2;
 
@@ -436,7 +444,7 @@ _apply_vm_sched_parameters (struct VscError *error, virDomainPtr domain,
                 * Like Xen, ESX handles CPU allocation per virtual machine, not per
                 * single virtual CPU.
                 */
-               sched_name = virDomainGetSchedulerType (domain, NULL);
+               sched_name = virDomainGetSchedulerType (domain, &num_expected_sched_params);
                if (! sched_name) {
                        _ERROR_FROM_LIBVIRT (error, virDomainGetConnect (domain));
                        goto cleanup;
@@ -449,6 +457,13 @@ _apply_vm_sched_parameters (struct VscError *error, virDomainPtr domain,
                        goto cleanup;
                }
 
+               if (num_expected_sched_params != 3) {
+                       VSC__ERROR2 (error, VSC__ERROR_CODE__INVALID_CALL,
+                                    "Unexpected '%s' scheduler parameter count %d, expecting 3",
+                                    sched_name, num_expected_sched_params);
+                       goto cleanup;
+               }
+
                totalRequestedMhz = resource_config->num_cores * resource_config->core_clock;
                num_sched_params = 3;