From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xen.org
Cc: Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH RFC 07/10] libxl: add local attach support for new hotplug scripts
Date: Fri, 21 Dec 2012 18:00:05 +0100 [thread overview]
Message-ID: <1356109208-6830-8-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1356109208-6830-1-git-send-email-roger.pau@citrix.com>
Adds support for locally attaching disks that use the new hotplug
script interface, by calling the localattach/localdetach operations
and returning a block device that can be used to execute pygrub.
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
tools/libxl/libxl.c | 88 ++++++++++++++++++++++++++++++++++------
tools/libxl/libxl_bootloader.c | 1 +
tools/libxl/libxl_internal.h | 1 +
3 files changed, 77 insertions(+), 13 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 29b2765..b21eefc 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2657,6 +2657,7 @@ void libxl__device_disk_local_initiate_attach(libxl__egc *egc,
const libxl_device_disk *in_disk = dls->in_disk;
libxl_device_disk *disk = &dls->disk;
const char *blkdev_start = dls->blkdev_start;
+ uint32_t domid = dls->domid;
assert(in_disk->pdev_path);
@@ -2673,6 +2674,23 @@ void libxl__device_disk_local_initiate_attach(libxl__egc *egc,
case LIBXL_DISK_BACKEND_PHY:
LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching PHY disk %s",
disk->pdev_path);
+ if (disk->hotplug_version != 0) {
+ disk->vdev = libxl__strdup(gc, in_disk->vdev);
+ libxl__prepare_ao_device(ao, &dls->aodev);
+ GCNEW(dls->aodev.dev);
+ rc = libxl__device_from_disk(gc, domid, disk,
+ dls->aodev.dev);
+ if (rc != 0) {
+ LOG(ERROR, "Invalid or unsupported virtual disk "
+ "identifier %s", disk->vdev);
+ goto out;
+ }
+ dls->aodev.action = DEVICE_LOCALATTACH;
+ dls->aodev.hotplug_version = disk->hotplug_version;
+ dls->aodev.callback = local_device_attach_cb;
+ libxl__device_hotplug(egc, &dls->aodev);
+ return;
+ }
dev = disk->pdev_path;
break;
case LIBXL_DISK_BACKEND_TAP:
@@ -2735,7 +2753,8 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev)
{
STATE_AO_GC(aodev->ao);
libxl__disk_local_state *dls = CONTAINER_OF(aodev, *dls, aodev);
- char *dev = NULL, *be_path = NULL;
+ char *dev = NULL, *be_path = NULL, *hotplug_path;
+ const char *pdev = NULL;
int rc;
libxl__device device;
libxl_device_disk *disk = &dls->disk;
@@ -2748,20 +2767,45 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev)
aodev->dev->devid);
goto out;
}
+ switch (disk->backend) {
+ case LIBXL_DISK_BACKEND_PHY:
+ /* Fetch hotplug output to obtain the block device */
+ rc = libxl__device_from_disk(gc, dls->domid, disk, &device);
+ if (rc)
+ goto out;
+ hotplug_path = libxl__device_xs_hotplug_path(gc, &device);
+ rc = libxl__xs_read_checked(gc, XBT_NULL,
+ GCSPRINTF("%s/pdev", hotplug_path),
+ &pdev);
+ if (rc)
+ goto out;
+ if (!pdev) {
+ rc = ERROR_FAIL;
+ goto out;
+ }
+ LOG(DEBUG, "attached local block device %s", pdev);
+ dls->diskpath = libxl__strdup(gc, pdev);
+ break;
+ case LIBXL_DISK_BACKEND_QDISK:
+ dev = GCSPRINTF("/dev/%s", disk->vdev);
+ LOG(DEBUG, "locally attaching qdisk %s", dev);
- dev = GCSPRINTF("/dev/%s", disk->vdev);
- LOG(DEBUG, "locally attaching qdisk %s", dev);
+ rc = libxl__device_from_disk(gc, LIBXL_TOOLSTACK_DOMID, disk, &device);
+ if (rc < 0)
+ goto out;
+ be_path = libxl__device_backend_path(gc, &device);
+ rc = libxl__wait_for_backend(gc, be_path, "4");
+ if (rc < 0)
+ goto out;
- rc = libxl__device_from_disk(gc, LIBXL_TOOLSTACK_DOMID, disk, &device);
- if (rc < 0)
- goto out;
- be_path = libxl__device_backend_path(gc, &device);
- rc = libxl__wait_for_backend(gc, be_path, "4");
- if (rc < 0)
+ if (dev != NULL)
+ dls->diskpath = libxl__strdup(gc, dev);
+ break;
+ default:
+ LOG(ERROR, "invalid disk backend for local attach callback");
+ rc = ERROR_FAIL;
goto out;
-
- if (dev != NULL)
- dls->diskpath = libxl__strdup(gc, dev);
+ }
dls->callback(egc, dls, 0);
return;
@@ -2785,11 +2829,29 @@ void libxl__device_disk_local_initiate_detach(libxl__egc *egc,
libxl_device_disk *disk = &dls->disk;
libxl__device *device;
libxl__ao_device *aodev = &dls->aodev;
+ uint32_t domid = dls->domid;
libxl__prepare_ao_device(ao, aodev);
if (!dls->diskpath) goto out;
switch (disk->backend) {
+ case LIBXL_DISK_BACKEND_PHY:
+ if (disk->hotplug_version != 0) {
+ GCNEW(aodev->dev);
+ rc = libxl__device_from_disk(gc, domid, disk,
+ aodev->dev);
+ if (rc != 0) {
+ LOG(ERROR, "Invalid or unsupported virtual disk "
+ "identifier %s", disk->vdev);
+ goto out;
+ }
+ aodev->action = DEVICE_LOCALDETACH;
+ aodev->hotplug_version = disk->hotplug_version;
+ aodev->callback = local_device_detach_cb;
+ libxl__device_hotplug(egc, aodev);
+ return;
+ }
+ break;
case LIBXL_DISK_BACKEND_QDISK:
if (disk->vdev != NULL) {
GCNEW(device);
@@ -2828,7 +2890,7 @@ static void local_device_detach_cb(libxl__egc *egc, libxl__ao_device *aodev)
if (aodev->rc) {
LOGE(ERROR, "unable to %s %s with id %u",
- aodev->action == DEVICE_CONNECT ? "add" : "remove",
+ libxl__device_hotplug_action(gc, aodev->action),
libxl__device_kind_to_string(aodev->dev->kind),
aodev->dev->devid);
goto out;
diff --git a/tools/libxl/libxl_bootloader.c b/tools/libxl/libxl_bootloader.c
index e103ee9..ff2e48c 100644
--- a/tools/libxl/libxl_bootloader.c
+++ b/tools/libxl/libxl_bootloader.c
@@ -381,6 +381,7 @@ void libxl__bootloader_run(libxl__egc *egc, libxl__bootloader_state *bl)
bl->dls.ao = ao;
bl->dls.in_disk = bl->disk;
bl->dls.blkdev_start = info->blkdev_start;
+ bl->dls.domid = domid;
bl->dls.callback = bootloader_disk_attached_cb;
libxl__device_disk_local_initiate_attach(egc, &bl->dls);
return;
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 16907ff..67c56a6 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -2130,6 +2130,7 @@ struct libxl__disk_local_state {
libxl_device_disk disk;
const char *blkdev_start;
libxl__disk_local_state_callback *callback;
+ uint32_t domid;
/* filled by libxl__device_disk_local_initiate_attach */
char *diskpath;
/* private for implementation of local detach */
--
1.7.7.5 (Apple Git-26)
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2012-12-21 17:00 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-21 16:59 [PATCH RFC 00/10] libxl: new hotplug calling convention Roger Pau Monne
2012-12-21 16:59 ` [PATCH RFC 01/10] libxl: libxl__prepare_ao_device should reset num_exec Roger Pau Monne
2013-01-17 13:57 ` Ian Campbell
2012-12-21 17:00 ` [PATCH RFC 02/10] libxl: add new hotplug interface support to hotplug script callers Roger Pau Monne
2013-01-18 13:29 ` Ian Campbell
2013-01-18 16:24 ` Roger Pau Monné
2013-01-21 10:07 ` Ian Campbell
2013-01-21 12:11 ` Roger Pau Monné
2013-01-21 12:18 ` Ian Campbell
2013-01-22 9:30 ` Roger Pau Monné
2012-12-21 17:00 ` [PATCH RFC 03/10] libxl: add new "method" parameter to xl disk config Roger Pau Monne
2013-01-17 15:49 ` Ian Campbell
2012-12-21 17:00 ` [PATCH RFC 04/10] libxl: add prepare/unprepare operations to the libxl public interface Roger Pau Monne
2012-12-21 17:00 ` [PATCH RFC 05/10] libxl: add disk specific remove functions Roger Pau Monne
2012-12-21 17:00 ` [PATCH RFC 06/10] xl: add support for new hotplug interface to block-attach/detach Roger Pau Monne
2012-12-21 17:00 ` Roger Pau Monne [this message]
2012-12-21 17:00 ` [PATCH RFC 08/10] libxl: add new hotplug interface support for HVM guests Roger Pau Monne
2012-12-21 17:00 ` [PATCH RFC 09/10] hotplug: document new hotplug interface Roger Pau Monne
2012-12-21 17:00 ` [PATCH RFC 10/10] hotplug/Linux: add iscsi block hotplug script Roger Pau Monne
2013-01-15 16:56 ` [PATCH RFC 00/10] libxl: new hotplug calling convention Roger Pau Monné
2013-01-17 13:56 ` Ian Campbell
2013-01-17 15:30 ` Roger Pau Monné
2013-01-17 15:40 ` Ian Campbell
2013-01-17 15:47 ` Roger Pau Monné
2013-01-17 15:57 ` Ian Campbell
2013-01-17 16:10 ` Roger Pau Monné
2013-01-17 16:15 ` Ian Campbell
2013-01-17 16:45 ` Roger Pau Monné
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=1356109208-6830-8-git-send-email-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=xen-devel@lists.xen.org \
/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).