diff -r 4f39505426cb tools/Rules.mk --- a/tools/Rules.mk Wed Jul 28 11:53:38 2010 +0200 +++ b/tools/Rules.mk Wed Jul 28 13:25:50 2010 +0200 @@ -26,6 +26,8 @@ LDFLAGS_libxenguest = -L$(XEN_LIBXC) -lx CFLAGS_libxenstore = -I$(XEN_XENSTORE) $(CFLAGS_include) LDFLAGS_libxenstore = -L$(XEN_XENSTORE) -lxenstore +LIBXL_BLKTAP = y + CFLAGS_libblktapctl = -I$(XEN_BLKTAP2)/control -I$(XEN_BLKTAP2)/include $(CFLAGS_include) LDFLAGS_libblktapctl = -L$(XEN_BLKTAP2)/control -lblktapctl diff -r 4f39505426cb tools/libxl/Makefile --- a/tools/libxl/Makefile Wed Jul 28 11:53:38 2010 +0200 +++ b/tools/libxl/Makefile Wed Jul 28 13:25:50 2010 +0200 @@ -18,6 +18,10 @@ CFLAGS += $(CFLAGS_libxenctrl) $(CFLAGS_ LIBS = $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenguest) $(LDFLAGS_libxenstore) $(LDFLAGS_libblktapctl) $(UTIL_LIBS) LIBXL_OBJS-y = osdeps.o libxl_paths.o libxl_bootloader.o +ifeq ($(LIBXL_BLKTAP),y) +LIBXL_OBJS-y += libxl_blktap2.c +endif + LIBXL_OBJS = flexarray.o libxl.o libxl_pci.o libxl_dom.o libxl_exec.o libxl_xshelp.o libxl_device.o libxl_internal.o xenguest.o libxl_utils.o $(LIBXL_OBJS-y) AUTOINCS= libxlu_cfg_y.h libxlu_cfg_l.h diff -r 4f39505426cb tools/libxl/libxl.c --- a/tools/libxl/libxl.c Wed Jul 28 11:53:38 2010 +0200 +++ b/tools/libxl/libxl.c Wed Jul 28 13:25:50 2010 +0200 @@ -34,7 +34,6 @@ #include "libxl_utils.h" #include "libxl_internal.h" #include "flexarray.h" -#include "tap-ctl.h" #define PAGE_TO_MEMKB(pages) ((pages) * 4) @@ -1430,27 +1429,6 @@ int libxl_confirm_device_model_startup(s /******************************************************************************/ -static char *get_blktap2_device(struct libxl_ctx *ctx, - const char *name, const char *type) -{ - int minor = tap_ctl_find_minor(type, name); - if (minor < 0) - return NULL; - return libxl_sprintf(ctx, "/dev/xen/blktap-2/tapdev%d", minor); -} - -static char *make_blktap2_device(struct libxl_ctx *ctx, - const char *name, const char *type) -{ - char *params, *devname = NULL; - int err; - params = libxl_sprintf(ctx, "%s:%s", type, name); - err = tap_ctl_create(params, &devname); - if (!err) - libxl_ptr_add(ctx, devname); - return err ? NULL : devname; -} - int libxl_device_disk_add(struct libxl_ctx *ctx, uint32_t domid, libxl_device_disk *disk) { flexarray_t *front; @@ -1499,14 +1477,13 @@ int libxl_device_disk_add(struct libxl_c case PHYSTYPE_FILE: /* let's pretend is tap:aio for the moment */ disk->phystype = PHYSTYPE_AIO; - case PHYSTYPE_AIO: case PHYSTYPE_QCOW: case PHYSTYPE_QCOW2: case PHYSTYPE_VHD: { - const char *msg; - if (!tap_ctl_check(&msg)) { - const char *type = device_disk_string_of_phystype(disk->phystype); - char *dev; - dev = get_blktap2_device(ctx, disk->physpath, type); - if (!dev) - dev = make_blktap2_device(ctx, disk->physpath, type); + case PHYSTYPE_AIO: + case PHYSTYPE_QCOW: + case PHYSTYPE_QCOW2: + case PHYSTYPE_VHD: + if (libxl_blktap_enabled(ctx)) { + const char *dev = libxl_blktap_devpath(ctx, + disk->physpath, disk->phystype); if (!dev) return ERROR_FAIL; flexarray_set(back, boffset++, "tapdisk-params"); @@ -1527,7 +1504,7 @@ int libxl_device_disk_add(struct libxl_c device.backend_kind = DEVICE_TAP; break; - } + default: XL_LOG(ctx, XL_LOG_ERROR, "unrecognized disk physical type: %d\n", disk->phystype); return ERROR_INVAL; @@ -1591,7 +1568,7 @@ int libxl_device_disk_del(struct libxl_c const char * libxl_device_disk_local_attach(struct libxl_ctx *ctx, libxl_device_disk *disk) { - char *dev = NULL; + const char *dev = NULL; int phystype = disk->phystype; switch (phystype) { case PHYSTYPE_PHY: { @@ -1602,16 +1579,14 @@ const char * libxl_device_disk_local_att case PHYSTYPE_FILE: /* let's pretend is tap:aio for the moment */ phystype = PHYSTYPE_AIO; - case PHYSTYPE_AIO: case PHYSTYPE_QCOW: case PHYSTYPE_QCOW2: case PHYSTYPE_VHD: { - const char *msg; - if (!tap_ctl_check(&msg)) { - const char *type = device_disk_string_of_phystype(phystype); - dev = get_blktap2_device(ctx, disk->physpath, type); - if (!dev) - dev = make_blktap2_device(ctx, disk->physpath, type); - } + case PHYSTYPE_AIO: + case PHYSTYPE_QCOW: + case PHYSTYPE_QCOW2: + case PHYSTYPE_VHD: + if (libxl_blktap_enabled(ctx)) + dev = libxl_blktap_devpath(ctx, disk->physpath, phystype); break; - } + default: XL_LOG(ctx, XL_LOG_ERROR, "unrecognized disk physical type: %d\n", phystype); break; diff -r 4f39505426cb tools/libxl/libxl_blktap2.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/libxl/libxl_blktap2.c Wed Jul 28 13:25:50 2010 +0200 @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2010 Advanced Micro Devices + * Author Christoph Egger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; version 2.1 only. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + */ + +#include "libxl.h" +#include "libxl_osdeps.h" +#include "libxl_internal.h" + +#include "tap-ctl.h" + +int libxl_blktap_enabled(struct libxl_ctx *ctx) +{ + const char *msg; + return !tap_ctl_check(&msg); +} + +const char *libxl_blktap_devpath(struct libxl_ctx *ctx, + const char *disk, + libxl_disk_phystype phystype) +{ + const char *type; + char *params, *devname; + int minor, err; + + type = device_disk_string_of_phystype(phystype); + minor = tap_ctl_find_minor(type, disk); + if (minor >= 0) { + devname = libxl_sprintf(ctx, "/dev/xen/blktap-2/tapdev%d", minor); + if (devname) + return devname; + } + + params = libxl_sprintf(ctx, "%s:%s", type, disk); + err = tap_ctl_create(params, &devname); + if (!err) { + libxl_ptr_add(ctx, devname); + return devname; + } + + return NULL; +} diff -r 4f39505426cb tools/libxl/libxl_internal.h --- a/tools/libxl/libxl_internal.h Wed Jul 28 11:53:38 2010 +0200 +++ b/tools/libxl/libxl_internal.h Wed Jul 28 13:25:50 2010 +0200 @@ -225,5 +225,24 @@ char *libxl_abs_path(struct libxl_ctx *c /* Error handling */ int libxl_xc_error(int xc_err); +/* + * blktap2 support + */ + +/* libxl_blktap_enabled: + * return true if blktap/blktap2 support is available. + */ +int libxl_blktap_enabled(struct libxl_ctx *ctx); + +/* libxl_blktap_devpath: + * Argument: path and disk image as specified in config file. + * The type specifies whether this is aio, qcow, qcow2, etc. + * returns device path xenstore wants to have. returns NULL + * if no device corresponds to the disk. + */ +const char *libxl_blktap_devpath(struct libxl_ctx *ctx, + const char *disk, + libxl_disk_phystype phystype); + #endif