Bug 600819

Summary: Incorrect scheduler parameter value passed to native API
Product: [Community] Virtualization Tools Reporter: andrea.sansottera
Component: libvirtAssignee: Bryan Kearney <bkearney>
Status: CLOSED UPSTREAM QA Contact:
Severity: medium Docs Contact:
Priority: low    
Version: unspecifiedCC: berrange, crobinso, xen-maint
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-06-24 16:07:27 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description andrea.sansottera 2010-06-06 07:45:59 UTC
Description of problem:
When setting scheduler parameter using the Java bindings, the incorrect value is passed to the native API.

Version-Release number of selected component (if applicable):
libvirt-java-0.4.5

How reproducible:
SchedUintParameter weight = new SchedUintParameter();
weight.field = "weight";
weight.value = 100;
SchedParameter[] parametersToSet = new SchedParameter[1];
parametersToSet[0] = weight;
domain.setSchedulerParameters(parametersToSet);

Steps to Reproduce:
Execute the above code using the XEN driver. XEN will complain that the weight is 0 and should be in the range 1-65535.
  
Actual results:
Sets weight = 100.

Expected results:
Tries to set weight = 0.

Additional info:
You have to tell JNA which field of the Union virSchedParameterValue you want to be written to native memory. For instance, when you want to write the field value.i, you have to invoke value.setType(int.class). As you can see the field is specified by type, therefore you cannot distinguish between the fields i and ui, which have the same Java type. This is the fix to include in the SchedParameter class:
switch (param.getType()) {
        case (1):
        returnValue.value.i = ((SchedIntParameter) param).value;
	// need to set the field
	returnValue.value.setType(int.class);
        break;
        case (2):
	// first int field is wrote to native memory therefore set i instead of ui
        returnValue.value.i = ((SchedUintParameter) param).value;
	// need to set the field
	returnValue.value.setType(int.class);
        break;
        case (3):
        returnValue.value.l = ((SchedLongParameter) param).value;
	// need to set the field
	returnValue.value.setType(long.class);
        break;
        case (4):
	// first long field is wrote to native memory, therefore set l instead of ul
        returnValue.value.l = ((SchedUlongParameter) param).value;
	// need to set the field
	returnValue.value.setType(long.class);
        break;
        case (5):
        returnValue.value.d = ((SchedDoubleParameter) param).value;
	// need to set the field
	returnValue.value.setType(double.class);
        break;
        case (6):
        returnValue.value.b = (byte) (((SchedBooleanParameter) param).value ? 1 : 0);
	// need to set the field
	returnValue.value.setType(byte.class);
        break;
}

Comment 1 andrea.sansottera 2010-06-06 07:49:52 UTC
Sorry, in the description I inverted actual and expected results.

Actual: tries to set weight = 0.
Expected: sets weight = 100.

Basically, it tries to set weight = 0 because it's passing value.i to the native API instead of value.ui.

Comment 2 Bryan Kearney 2010-07-13 14:48:16 UTC
Patch is applied at [1]. Thank you for the patch. If you could verify, that would be great.


[1] http://libvirt.org/git/?p=libvirt-java.git;a=commit;h=38a85ba51668b78fac47e4fbdd33bef5d0b2f76c