From: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian.Jackson@eu.citrix.com, Ian.Campbell@citrix.com,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH v7 08/11] xl/libxl: implement QDISK libxl_device_disk_local_attach
Date: Mon, 21 May 2012 19:05:36 +0100 [thread overview]
Message-ID: <1337623539-29834-8-git-send-email-stefano.stabellini@eu.citrix.com> (raw)
In-Reply-To: <alpine.DEB.2.00.1205211852180.26786@kaball-desktop>
- 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.
Changes in v6:
- introduce xs_ret for xs_* error codes.
Changes in v5:
- replace LIBXL__LOG with LOG.
Changes on v4:
- improve error handling and exit paths in libxl__device_disk_local_attach.
Signed-off-by: Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Acked-by:Ian Campbell <ian.campbell@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
---
tools/hotplug/Linux/init.d/sysconfig.xencommons | 3 +
tools/hotplug/Linux/init.d/xencommons | 3 +
tools/libxl/libxl_internal.c | 60 ++++++++++++++++++-----
3 files changed, 54 insertions(+), 12 deletions(-)
diff --git a/tools/hotplug/Linux/init.d/sysconfig.xencommons b/tools/hotplug/Linux/init.d/sysconfig.xencommons
index 6543204..38ea85a 100644
--- a/tools/hotplug/Linux/init.d/sysconfig.xencommons
+++ b/tools/hotplug/Linux/init.d/sysconfig.xencommons
@@ -12,3 +12,6 @@
# Running xenbackendd in debug mode
#XENBACKENDD_DEBUG=[yes|on|1]
+
+# qemu path
+#QEMU_XEN=/usr/lib/xen/bin/qemu-system-i386
diff --git a/tools/hotplug/Linux/init.d/xencommons b/tools/hotplug/Linux/init.d/xencommons
index 2f81ea2..9dda6e2 100644
--- a/tools/hotplug/Linux/init.d/xencommons
+++ b/tools/hotplug/Linux/init.d/xencommons
@@ -104,6 +104,9 @@ 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
+ $QEMU_XEN -xen-domid 0 -xen-attach -name dom0 -nographic -M xenpv -daemonize -monitor /dev/null
}
do_stop () {
echo Stopping xenconsoled
diff --git a/tools/libxl/libxl_internal.c b/tools/libxl/libxl_internal.c
index 3961701..9bbb75d 100644
--- a/tools/libxl/libxl_internal.c
+++ b/tools/libxl/libxl_internal.c
@@ -363,7 +363,8 @@ char * libxl__device_disk_local_attach(libxl__gc *gc,
libxl_ctx *ctx = gc->owner;
char *dev = NULL;
char *ret = NULL;
- int rc;
+ int rc, xs_ret;
+ xs_transaction_t t = XBT_NULL;
if (in_disk->pdev_path == NULL)
return NULL;
@@ -407,13 +408,35 @@ char * libxl__device_disk_local_attach(libxl__gc *gc,
break;
case LIBXL_DISK_BACKEND_QDISK:
if (disk->format != LIBXL_DISK_FORMAT_RAW) {
- LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "cannot locally"
- " attach a qdisk image if the format is not raw");
- break;
+ do {
+ t = xs_transaction_start(ctx->xsh);
+ if (t == XBT_NULL) {
+ LOG(ERROR, "failed to start a xenstore transaction");
+ goto out;
+ }
+ disk->vdev = libxl__alloc_vdev(gc, blkdev_start, t);
+ if (disk->vdev == NULL) {
+ LOG(ERROR, "libxl__alloc_vdev failed");
+ goto out;
+ }
+ if (libxl__device_disk_add(gc, LIBXL_TOOLSTACK_DOMID,
+ t, disk)) {
+ LOG(ERROR, "libxl_device_disk_add failed");
+ goto out;
+ }
+ xs_ret = xs_transaction_end(ctx->xsh, t, 0);
+ } while (xs_ret == 0 && errno == EAGAIN);
+ t = XBT_NULL;
+ if (xs_ret == 0) {
+ LOGE(ERROR, "xenstore transaction failed");
+ goto out;
+ }
+ dev = GCSPRINTF("/dev/%s", disk->vdev);
+ } else {
+ dev = disk->pdev_path;
}
LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching qdisk %s",
- in_disk->pdev_path);
- dev = disk->pdev_path;
+ dev);
break;
default:
LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend "
@@ -422,6 +445,8 @@ char * libxl__device_disk_local_attach(libxl__gc *gc,
}
out:
+ if (t != XBT_NULL)
+ xs_transaction_end(ctx->xsh, t, 1);
if (dev != NULL)
ret = strdup(dev);
return ret;
@@ -429,12 +454,23 @@ char * libxl__device_disk_local_attach(libxl__gc *gc,
int libxl__device_disk_local_detach(libxl__gc *gc, 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->vdev != NULL) {
+ libxl_device_disk_remove(gc->owner, LIBXL_TOOLSTACK_DOMID,
+ disk, 0);
+ return libxl_device_disk_destroy(gc->owner,
+ LIBXL_TOOLSTACK_DOMID, 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
next prev parent reply other threads:[~2012-05-21 18:05 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-21 18:04 [PATCH v7 0/11] qdisk local attach Stefano Stabellini
2012-05-21 18:05 ` [PATCH v7 01/11] libxl: make libxl_device_disk_local_attach/detach internal functions Stefano Stabellini
2012-05-22 14:05 ` Ian Jackson
2012-05-21 18:05 ` [PATCH v7 02/11] libxl: libxl__device_disk_local_attach return a new libxl_device_disk Stefano Stabellini
2012-05-22 14:12 ` Ian Jackson
2012-05-28 11:31 ` Stefano Stabellini
2012-05-21 18:05 ` [PATCH v7 03/11] libxl: add a transaction parameter to libxl__device_generic_add Stefano Stabellini
2012-05-21 18:05 ` [PATCH v7 04/11] libxl: export libxl__device_from_disk Stefano Stabellini
2012-05-22 14:12 ` Ian Jackson
2012-05-21 18:05 ` [PATCH v7 05/11] libxl: introduce libxl__device_disk_add Stefano Stabellini
2012-05-22 14:14 ` Ian Jackson
2012-05-21 18:05 ` [PATCH v7 06/11] xl/libxl: add a blkdev_start parameter Stefano Stabellini
2012-05-21 18:05 ` [PATCH v7 07/11] libxl: introduce libxl__alloc_vdev Stefano Stabellini
2012-05-22 14:16 ` Ian Jackson
2012-05-21 18:05 ` Stefano Stabellini [this message]
2012-05-21 18:05 ` [PATCH v7 09/11] libxl__device_disk_local_attach: wait for state "connected" Stefano Stabellini
2012-05-21 18:05 ` [PATCH v7 10/11] libxl_string_to_backend: add qdisk Stefano Stabellini
2012-05-21 18:05 ` [PATCH v7 11/11] main_blockdetach: destroy the disk on successful removal Stefano Stabellini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1337623539-29834-8-git-send-email-stefano.stabellini@eu.citrix.com \
--to=stefano.stabellini@eu.citrix.com \
--cc=Ian.Campbell@citrix.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).