diff options
author | Stefano Stabellini <Stefano.Stabellini@eu.citrix.com> | 2011-01-28 16:54:13 +0000 |
---|---|---|
committer | Stefano Stabellini <Stefano.Stabellini@eu.citrix.com> | 2011-01-28 16:54:13 +0000 |
commit | 3146a8a802232659e3264c6b67b0c4195b8c237e (patch) | |
tree | 3379534dc65a4c83122365ab3939c0ad33f640ec | |
parent | a76377f10e9df051a820c55ab83ed9fffa7e9a53 (diff) | |
download | xen-3146a8a802232659e3264c6b67b0c4195b8c237e.tar.gz xen-3146a8a802232659e3264c6b67b0c4195b8c237e.tar.bz2 xen-3146a8a802232659e3264c6b67b0c4195b8c237e.zip |
libxl: when using pygrub, do not segfault if no blktap
Running 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 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 cases where the
device has a name in the host which we can just refer to.
Also improve the error message when QCOW or QCOW2 are specified, and
avoid using an uninitialised value of "ret".
Signed-off-by: M A Young <m.a.young@durham.ac.uk>
Signed-off-by: Stefano Stabellini <Stefano.Stabellini@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
-rw-r--r-- | tools/libxl/libxl.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index ccbc84218b..9658d6714e 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -1021,7 +1021,7 @@ char * libxl_device_disk_local_attach(libxl_ctx *ctx, libxl_device_disk *disk) { 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(libxl_ctx *ctx, libxl_device_disk *disk) /* 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; } |