[libvirt] [PATCH] [libvirt-java] Fix JNA passing of scheduler parameters

Daniel Veillard veillard at redhat.com
Thu Jun 28 09:00:27 UTC 2012


trying to use setSchedulerParameters for the cpu_share was always
ending up setting the value to 2. in practice the JNA code was not
passing the parameter value, letting it uninitialized to zero and
the kernel accepts 2 as the closest value leading to that behaviour.
The code was actually telling JNA which type to use from the enum
but the JNA refused to take it into account possibly because multiple
C types maps to the same Java types and in that case it refuses to
accept setType(class) and simply act as if the information had not
been given (no warning/no error at runtime) !
The workaround is to actually tell it the field name in the enum,
that is accepted and the function works properly once done.

diff --git a/src/main/java/org/libvirt/SchedParameter.java b/src/main/java/org/libvirt/SchedParameter.java
index ab988e9..1dece56 100644
--- a/src/main/java/org/libvirt/SchedParameter.java
+++ b/src/main/java/org/libvirt/SchedParameter.java
@@ -52,33 +52,33 @@ public abstract class SchedParameter {
         switch (param.getType()) {
             case (1):
                 returnValue.value.i = ((SchedIntParameter) param).value;
-                returnValue.value.setType(int.class);
+                returnValue.value.setType("i");
                 break;
             case (2):
                 returnValue.value.ui = ((SchedUintParameter) param).value;
-                returnValue.value.setType(int.class);
+                returnValue.value.setType("ui");
                 break;
             case (3):
                 returnValue.value.l = ((SchedLongParameter) param).value;
-                returnValue.value.setType(long.class);
+                returnValue.value.setType("l");
                 break;
             case (4):
                 returnValue.value.ul = ((SchedUlongParameter) param).value;
-                returnValue.value.setType(long.class);
+                returnValue.value.setType("ul");
                 break;
             case (5):
                 returnValue.value.d = ((SchedDoubleParameter) param).value;
-                returnValue.value.setType(double.class);
+                returnValue.value.setType("d");
                 break;
             case (6):
                 returnValue.value.b = (byte) (((SchedBooleanParameter) param).value ? 1 : 0);
-                returnValue.value.setType(byte.class);
+                returnValue.value.setType("b");
                 break;
 
         }
         return returnValue;
     }
-    
+
     public static byte[] copyOf(byte[] original, int length) {
         byte[] returnValue = new byte[length];
         int originalLength = original.length ;

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list