This service will be undergoing maintenance at 00:00 UTC, 2016-08-01. It is expected to last about 1 hours
Bug 600819 - Incorrect scheduler parameter value passed to native API
Incorrect scheduler parameter value passed to native API
Status: CLOSED UPSTREAM
Product: Virtualization Tools
Classification: Community
Component: libvirt (Show other bugs)
unspecified
All Linux
low Severity medium
: ---
: ---
Assigned To: Bryan Kearney
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2010-06-06 03:45 EDT by andrea.sansottera
Modified: 2013-06-24 12:07 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-06-24 12:07:27 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description andrea.sansottera 2010-06-06 03:45:59 EDT
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 03:49:52 EDT
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 10:48:16 EDT
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

Note You need to log in before you can comment on or make changes to this bug.