Skip to contentSkip to conversation

Bug fix patch of libxl

PATCH Jun Zhu (Intern) 2 participants 2 messages Aug 19, 2010

lore
Share & tools
lore
#0 lore raw

Hi,

A small bug in libxl. Fixed in attatched patch.

Jun Zhu

tools/libxl/libxl.c +19 -1
diff -r 5218db847b58 tools/libxl/libxl.c
@@ -897,6 +897,24 @@
     char *vm_path;
     int rc, dm_present;
 
+    switch (is_hvm(ctx, domid)) {
+        case 1: {
+            dm_present = 1;
+            break;
+        }
+        case 0: {
+            char *pid;
+            pid = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "/local/domain/%d/image/device-model-pid", domid));
+            dm_present = (pid != NULL);
+            libxl_free(ctx, pid);
+            break;
+        }
+        default: {
+            XL_LOG(ctx, XL_LOG_ERROR, "Get domain %d info failed, are you privileged domain?", domid);
+            return ERROR_FAIL;
+        }
+    }
+/*
     if (is_hvm(ctx, domid)) {
         dm_present = 1;
     } else {
@@ -904,7 +922,7 @@
         pid = libxl_xs_read(&gc, XBT_NULL, libxl_sprintf(&gc, "/local/domain/%d/image/device-model-pid", domid));
         dm_present = (pid != NULL);
     }
-
+*/
     dom_path = libxl_xs_get_dompath(&gc, domid);
     if (!dom_path) {
         rc = ERROR_FAIL;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

Jun Zhu (Intern) writes ("[Xen-devel] Bug fix patch of libxl"):

Quoted 1 line

A small bug in libxl. Fixed in attatched patch.

Thanks for the report and the patch. I'm not entirely convinced about your fix, however.

Firstly, this is only one of many callers of is_hvm. Secondly, the error logging should probably be in is_hvm, not in the caller. Thirdly I think replacing the if() with a switch makes matters much less clear; it would be better to do
hvm = is_hvm(...);
if (hvm<0) return hvm;
if (hvm) {
....
or some such.

And fourthly when you submit a patch you should just delete the old code from the file, not comment it out. Our version control system will let us retrieve the old version if we want to read it.

This is probably all a bit much so I'll see if I can do a better fix.

Regards,
Ian.