Skip to contentSkip to conversation

Seg fault running xl create with 4.1.0-rc2

PATCH M A Young 3 participants 3 messages Jan 27, 2011 – Jan 28, 2011

lore
Share & tools
lore

M A Young

author
#0 lore raw

If I run xl create configfile where configfile includes the lines bootloader = "/usr/bin/pygrub"
disk = [ 'file:/dev/mapper/vg0-partname,xvda1,w' ]

then xl segfaults at the line

    ret = strdup(dev);

of libxl_device_disk_local_attach() in tools/libxl/libxl.c . The problem is that dev is not set if libxl__blktap_enabled(&gc) is false or if phystype isn't recognized. In the latter case I presume we want to skip that line and return NULL, but if libxl__blktap_enabled(&gc) is false we should be returning something, at least in the case where phystype=PHYSTYPE_FILE, so that we can fall back to qdisk. I think something like the attached patch (not yet tested) should work.

Michael Young

tools/libxl/libxl.c renamed from tools/libxl/libxl.c.orig +6 -1
@@ -988,13 +988,18 @@
         case PHYSTYPE_VHD:
             if (libxl__blktap_enabled(&gc))
                 dev = libxl__blktap_devpath(&gc, disk->physpath, phystype);
+            else
+                dev = disk->physpath;
             break;
 
         default:
             LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk physical type: %d\n", phystype);
             break;
     }
-    ret = strdup(dev);
+    if (dev)
+        ret = strdup(dev);
+    else
+        ret = NULL;
     libxl__free_all(&gc);
     return ret;
 }

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

#1 lore raw
Quoted 7 lines · M A Young

If I run xl create configfile where configfile includes the lines bootloader = "/usr/bin/pygrub"
disk = [ 'file:/dev/mapper/vg0-partname,xvda1,w' ]

then xl segfaults at the line

     ret = strdup(dev);
Quoted 7 lines

of libxl_device_disk_local_attach() in tools/libxl/libxl.c . The problem is that dev is not set if libxl__blktap_enabled(&gc) is false or if phystype isn't recognized. In the latter case I presume we want to skip that line and return NULL, but if libxl__blktap_enabled(&gc) is false we should be returning something, at least in the case where phystype=PHYSTYPE_FILE, so that we can fall back to qdisk. I think something like the attached patch (not yet tested) should work.

Thanks for the patch.
I extended it a bit, covering qcow and qcow2 as well:

tools/libxl/libxl.c +13 -4
diff -r 722f7b7678dc tools/libxl/libxl.c
@@ -1021,7 +1021,7 @@ char * libxl_device_disk_local_attach(li
 {
     libxl__gc gc = LIBXL_INIT_GC(ctx);
     const char *dev = NULL;
-    char *ret;
+    char *ret = NULL;
     int phystype = disk->phystype;
     switch (phystype) {
         case PHYSTYPE_PHY: {
@@ -1033,18 +1033,27 @@ char * libxl_device_disk_local_attach(li
             /* let's pretend is tap:aio for the moment */
             phystype = PHYSTYPE_AIO;
         case PHYSTYPE_AIO:
-        case PHYSTYPE_QCOW:
-        case PHYSTYPE_QCOW2:
+            if (!libxl__blktap_enabled(&gc)) {
+                dev = disk->physpath;
+                break;
+            }
         case PHYSTYPE_VHD:
             if (libxl__blktap_enabled(&gc))
                 dev = libxl__blktap_devpath(&gc, disk->physpath, phystype);
+            else
+                LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "tapdisk2 is required to open a vhd disk\n");
+            break;
+        case PHYSTYPE_QCOW:
+        case PHYSTYPE_QCOW2:
+            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot locally attach a qcow or qcow2 disk image\n");
             break;
 
         default:
             LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk physical type: %d\n", phystype);
             break;
     }
-    ret = strdup(dev);
+    if (dev != NULL)
+        ret = strdup(dev);
     libxl__free_all(&gc);
     return ret;
 }
#2 lore raw

Stefano Stabellini writes ("Re: [Xen-devel] Seg fault running xl create with 4.1.0-rc2"):

Quoted 3 lines · M A Young
Quoted 2 lines

then xl segfaults at the line

     ret = strdup(dev);

Well spotted.

Quoted 2 lines

Thanks for the patch.
I extended it a bit, covering qcow and qcow2 as well:

Thanks, I have applied it.

Ian.