[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH RFC 3/4] libxl: Use XenServer's blktap2.5
Switch to installing blktap2.5 and not building or installing in-tree blktap2. Port libxl to run on the newest blktap2.5. tap_ctl_find() has gone away, so in some cases we use tap_ctl_find_minor(), and in other cases we use a locally-reimplemented version of tap_ctl_find(). tap_ctl_create() has an extra three parameters, including a flags parameter which can be used to designate a disk image as read-only. Pass the readwrite disk flag here so we can now open backends on read-only storage. tap_ctl_destroy() now has two extra arguments as well; add sensible default values. Signed-off-by: George Dunlap <george.dunlap@xxxxxxxxxxxxx> --- NOTE: I'm pretty sure this won't build from a source tarball at the moment, since XEN_BLKTAP2 is set to tools/blktap-dir, which (IIRC) will be just an empty directory if tools/bltkap exists. (And tools/blktap is where the release tarball script will put the blktap subdir.) If this gets traction, I'll figure out how to do fix that before I send a non-RFC series. CC: Ian Campbell <ian.campbell@xxxxxxxxxx> CC: Ian Jackson <ian.jackson@xxxxxxxxxx> CC: Wei Liu <wei.liu2@xxxxxxxxxx> CC: Dave Scott <Dave.Scott@xxxxxxxxxxxxx> CC: Jonathan Ludlam <Jonathan.Ludlam@xxxxxxxxxxxxx> CC: Wen Congyang <wency@xxxxxxxxxxxxxx> CC: Yang Hongyang <yanghy@xxxxxxxxxxxxxx> --- tools/Makefile | 7 ++---- tools/Rules.mk | 8 +++--- tools/libxl/libxl.c | 6 +++-- tools/libxl/libxl_blktap2.c | 58 ++++++++++++++++++++++++++++++++++++-------- tools/libxl/libxl_dm.c | 3 ++- tools/libxl/libxl_internal.h | 3 ++- 6 files changed, 62 insertions(+), 23 deletions(-) diff --git a/tools/Makefile b/tools/Makefile index b0b2a02..06374bf 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -16,7 +16,6 @@ SUBDIRS-y += console SUBDIRS-y += xenmon SUBDIRS-y += xenstat SUBDIRS-$(CONFIG_Linux) += memshr -SUBDIRS-$(CONFIG_BLKTAP2) += blktap2 SUBDIRS-$(CONFIG_NetBSD) += xenbackendd SUBDIRS-y += libfsimage SUBDIRS-$(CONFIG_Linux) += libvchan @@ -309,11 +308,9 @@ subdir-all-blktap-dir: blktap-dir-find --libexecdir=$(LIBEXEC) ; \ $(MAKE) all -# Don't install upstream blktap for now. subdir-install-blktap-dir: subdir-all-blktap-dir - if false ; do cd blktap-dir; \ - $(MAKE) install \ - fi + cd blktap-dir; \ + $(MAKE) install subdir-clean-blktap-dir: set -e; if test -d blktap-dir/.; then \ diff --git a/tools/Rules.mk b/tools/Rules.mk index 3c29d07..f104072 100644 --- a/tools/Rules.mk +++ b/tools/Rules.mk @@ -14,7 +14,7 @@ XEN_LIBXC = $(XEN_ROOT)/tools/libxc XEN_XENLIGHT = $(XEN_ROOT)/tools/libxl XEN_XENSTORE = $(XEN_ROOT)/tools/xenstore XEN_LIBXENSTAT = $(XEN_ROOT)/tools/xenstat/libxenstat/src -XEN_BLKTAP2 = $(XEN_ROOT)/tools/blktap2 +XEN_BLKTAP2 = $(XEN_ROOT)/tools/blktap-dir XEN_LIBVCHAN = $(XEN_ROOT)/tools/libvchan CFLAGS_xeninclude = -I$(XEN_INCLUDE) @@ -64,9 +64,9 @@ endif LIBXL_BLKTAP ?= $(CONFIG_BLKTAP2) ifeq ($(LIBXL_BLKTAP),y) -CFLAGS_libblktapctl = -I$(XEN_BLKTAP2)/control -I$(XEN_BLKTAP2)/include $(CFLAGS_xeninclude) -LDLIBS_libblktapctl = -L$(XEN_BLKTAP2)/control -lblktapctl -SHLIB_libblktapctl = -Wl,-rpath-link=$(XEN_BLKTAP2)/control +CFLAGS_libblktapctl = -I$(XEN_BLKTAP2)/include $(CFLAGS_xeninclude) +LDLIBS_libblktapctl = -L$(XEN_BLKTAP2)/control/.libs -lblktapctl +SHLIB_libblktapctl = -Wl,-rpath-link=$(XEN_BLKTAP2)/control/.libs else CFLAGS_libblktapctl = LDLIBS_libblktapctl = diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index 94b4d59..0270753 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -2437,7 +2437,8 @@ static void device_disk_add(libxl__egc *egc, uint32_t domid, case LIBXL_DISK_BACKEND_TAP: if (dev == NULL) { dev = libxl__blktap_devpath(gc, disk->pdev_path, - disk->format); + disk->format, + disk->readwrite); if (!dev) { LOG(ERROR, "failed to get blktap devpath for %p\n", disk->pdev_path); @@ -3031,7 +3032,8 @@ void libxl__device_disk_local_initiate_attach(libxl__egc *egc, break; case LIBXL_DISK_FORMAT_VHD: dev = libxl__blktap_devpath(gc, disk->pdev_path, - disk->format); + disk->format, + disk->readwrite); break; case LIBXL_DISK_FORMAT_QCOW: case LIBXL_DISK_FORMAT_QCOW2: diff --git a/tools/libxl/libxl_blktap2.c b/tools/libxl/libxl_blktap2.c index 2053403..24939d7 100644 --- a/tools/libxl/libxl_blktap2.c +++ b/tools/libxl/libxl_blktap2.c @@ -23,26 +23,62 @@ int libxl__blktap_enabled(libxl__gc *gc) return !tap_ctl_check(&msg); } +static int tap_ctl_find(const char *type, const char *disk, tap_list_t *tap) +{ + int err; + struct list_head list = LIST_HEAD_INIT(list); + tap_list_t *entry; + + err = tap_ctl_list(&list); + if (err) + return err; + + err = ERROR_FAIL; + + tap_list_for_each_entry(entry, &list) { + if (type && (!entry->type || strcmp(entry->type, type))) + continue; + + if (disk && (!entry->path || strcmp(entry->path, disk))) + continue; + + tap->minor = entry->minor; + tap->pid = entry->pid; + err = 0; + break; + } + tap_ctl_list_free(&list); + + return err; +} + char *libxl__blktap_devpath(libxl__gc *gc, const char *disk, - libxl_disk_format format) + libxl_disk_format format, + int readwrite) { const char *type; char *params, *devname = NULL; - tap_list_t tap; int err; + int minor; + int flags; type = libxl__device_disk_string_of_format(format); - err = tap_ctl_find(type, disk, &tap); - if (err == 0) { - devname = libxl__sprintf(gc, "/dev/xen/blktap-2/tapdev%d", tap.minor); + + minor = tap_ctl_find_minor(type, disk); + if (minor >= 0) { + devname = libxl__sprintf(gc, "/dev/xen/blktap-2/tapdev%d", minor); if (devname) return devname; } params = libxl__sprintf(gc, "%s:%s", type, disk); - err = tap_ctl_create(params, &devname); + fprintf(stderr, "DEBUG %s %d %s\n", __func__, __LINE__, params); + flags = readwrite ? 0 : TAPDISK_MESSAGE_FLAG_RDONLY; + + err = tap_ctl_create(params, &devname, flags, -1, 0, 0); if (!err) { + fprintf(stderr, "DEBUG %s %d %s\n", __func__, __LINE__, devname); libxl__ptr_add(gc, devname); return devname; } @@ -55,7 +91,8 @@ int libxl__device_destroy_tapdisk(libxl__gc *gc, const char *params) { char *type, *disk; int err; - tap_list_t tap; + struct list_head list = LIST_HEAD_INIT(list); + tap_list_t tap = { .minor=-1, .pid=-1 }; type = libxl__strdup(gc, params); @@ -65,19 +102,20 @@ int libxl__device_destroy_tapdisk(libxl__gc *gc, const char *params) return ERROR_INVAL; } + fprintf(stderr, "DEBUG %s %d type=%s disk=%s\n",__func__,__LINE__,type,disk); *disk++ = '\0'; err = tap_ctl_find(type, disk, &tap); - if (err < 0) { + if (err) { /* returns -errno */ LOGEV(ERROR, -err, "Unable to find type %s disk %s", type, disk); return ERROR_FAIL; } - err = tap_ctl_destroy(tap.id, tap.minor); + err = tap_ctl_destroy(tap.pid, tap.minor, 1, NULL); if (err < 0) { LOGEV(ERROR, -err, "Failed to destroy tap device id %d minor %d", - tap.id, tap.minor); + tap.pid, tap.minor); return ERROR_FAIL; } diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index a8b08f2..0d91b54 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -826,7 +826,8 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc, if (disks[i].backend == LIBXL_DISK_BACKEND_TAP) { format = qemu_disk_format_string(LIBXL_DISK_FORMAT_RAW); pdev_path = libxl__blktap_devpath(gc, disks[i].pdev_path, - disks[i].format); + disks[i].format, + disks[i].readwrite); } else { pdev_path = disks[i].pdev_path; } diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 934465a..441d722 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -1550,7 +1550,8 @@ _hidden int libxl__blktap_enabled(libxl__gc *gc); */ _hidden char *libxl__blktap_devpath(libxl__gc *gc, const char *disk, - libxl_disk_format format); + libxl_disk_format format, + int readwrite); /* libxl__device_destroy_tapdisk: * Destroys any tapdisk process associated with the backend represented -- 1.9.1 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx http://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |