From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stefano Stabellini Subject: [PATCH 6/6] xl/libxl: implement QDISK libxl_device_disk_local_attach Date: Tue, 27 Mar 2012 14:59:32 +0100 Message-ID: <1332856772-30292-6-git-send-email-stefano.stabellini@eu.citrix.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xensource.com Cc: Ian.Jackson@eu.citrix.com, Ian.Campbell@citrix.com, Stefano Stabellini List-Id: xen-devel@lists.xenproject.org - Spawn a QEMU instance at boot time to handle disk local attach requests. - Implement libxl_device_disk_local_attach for QDISKs in terms of a regular disk attach with the frontend and backend running in the same domain. Signed-off-by: Stefano Stabellini --- tools/hotplug/Linux/init.d/sysconfig.xencommons | 4 ++ tools/hotplug/Linux/init.d/xencommons | 4 ++ tools/libxl/libxl.c | 46 +++++++++++++++++----- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/tools/hotplug/Linux/init.d/sysconfig.xencommons b/tools/hotplug/Linux/init.d/sysconfig.xencommons index 6543204..28cf2eb 100644 --- a/tools/hotplug/Linux/init.d/sysconfig.xencommons +++ b/tools/hotplug/Linux/init.d/sysconfig.xencommons @@ -12,3 +12,7 @@ # Running xenbackendd in debug mode #XENBACKENDD_DEBUG=[yes|on|1] + +# qemu path and log file +#QEMU_XEN=/usr/lib/xen/bin/qemu-system-i386 +#QEMU_XEN_LOG=/var/log/xen/qemu-dm-dom0.log diff --git a/tools/hotplug/Linux/init.d/xencommons b/tools/hotplug/Linux/init.d/xencommons index 6c72dd8..f328492 100644 --- a/tools/hotplug/Linux/init.d/xencommons +++ b/tools/hotplug/Linux/init.d/xencommons @@ -103,6 +103,10 @@ do_start () { xenconsoled --pid-file=$XENCONSOLED_PIDFILE $XENCONSOLED_ARGS test -z "$XENBACKENDD_DEBUG" || XENBACKENDD_ARGS="-d" test "`uname`" != "NetBSD" || xenbackendd $XENBACKENDD_ARGS + echo Starting QEMU as disk backend for dom0 + test -z "$QEMU_XEN" && QEMU_XEN=/usr/lib/xen/bin/qemu-system-i386 + test -z "$QEMU_XEN_LOG" && QEMU_XEN_LOG=/var/log/xen/qemu-dm-dom0.log + $QEMU_XEN -xen-domid 0 -xen-attach -name dom0 -nographic -M xenpv -daemonize &>$QEMU_XEN_LOG } do_stop () { echo Stopping xenconsoled diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c index fa7898a..4c89a56 100644 --- a/tools/libxl/libxl.c +++ b/tools/libxl/libxl.c @@ -1767,13 +1767,30 @@ char * libxl_device_disk_local_attach(libxl_ctx *ctx, const libxl_device_disk *d break; case LIBXL_DISK_BACKEND_QDISK: if (tmpdisk->format != LIBXL_DISK_FORMAT_RAW) { - LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot locally" - " attach a qdisk image if the format is not raw"); - break; + xs_transaction_t t; +retry_transaction: + t = xs_transaction_start(ctx->xsh); + /* use 0 as the domid of the toolstack domain for now */ + tmpdisk->vdev = libxl__alloc_vdev(gc, 0, t, tmpdisk); + if (tmpdisk->vdev == NULL) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "libxl__alloc_vdev failed\n"); + xs_transaction_end(ctx->xsh, t, 1); + goto out; + } + if (libxl__device_disk_add_t(gc, 0, t, tmpdisk)) { + LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "libxl_device_disk_add failed\n"); + xs_transaction_end(ctx->xsh, t, 1); + goto out; + } + if (!xs_transaction_end(ctx->xsh, t, 0)) + if (errno == EAGAIN) + goto retry_transaction; + dev = libxl__sprintf(gc, "/dev/%s", tmpdisk->vdev); + } else { + dev = tmpdisk->pdev_path; } LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching qdisk %s\n", - disk->pdev_path); - dev = tmpdisk->pdev_path; + dev); break; default: LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend " @@ -1792,12 +1809,19 @@ char * libxl_device_disk_local_attach(libxl_ctx *ctx, const libxl_device_disk *d int libxl_device_disk_local_detach(libxl_ctx *ctx, libxl_device_disk *disk) { - /* Nothing to do for PHYSTYPE_PHY. */ - - /* - * For other device types assume that the blktap2 process is - * needed by the soon to be started domain and do nothing. - */ + switch (disk->backend) { + case LIBXL_DISK_BACKEND_QDISK: + if (disk->format != LIBXL_DISK_FORMAT_RAW) + return libxl_device_disk_destroy(ctx, 0, disk); + break; + default: + /* + * Nothing to do for PHYSTYPE_PHY. + * For other device types assume that the blktap2 process is + * needed by the soon to be started domain and do nothing. + */ + break; + } return 0; } -- 1.7.2.5