From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xen.org
Cc: Ian Jackson <ian.jackson@citrix.com>,
Ian Campbell <ian.campbell@citrix.com>,
Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v2 6/7] libxl: add local attach support for new hotplug scripts
Date: Mon, 18 Mar 2013 12:47:10 +0100 [thread overview]
Message-ID: <1363607231-35228-7-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1363607231-35228-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>
Cc: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian Jackson <ian.jackson@citrix.com>
---
tools/libxl/libxl.c | 86 ++++++++++++++++++++++++++++++++++------
tools/libxl/libxl_bootloader.c | 1 +
tools/libxl/libxl_internal.h | 1 +
3 files changed, 76 insertions(+), 12 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index 987723b..9d0d15a 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -2718,6 +2718,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);
@@ -2734,6 +2735,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 == 2) {
+ 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 = LIBXL__DEVICE_ACTION_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:
@@ -2796,7 +2814,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;
@@ -2809,20 +2828,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;
@@ -2846,11 +2890,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 == 2) {
+ 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 = LIBXL__DEVICE_ACTION_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);
diff --git a/tools/libxl/libxl_bootloader.c b/tools/libxl/libxl_bootloader.c
index ed12b2c..5d889fe 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 d957ed2..3228ab2 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -2151,6 +2151,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:[~2013-03-18 11:47 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-17 15:47 [PATCH v3 0/7] libxl: new hotplug calling convention Roger Pau Monne
2013-04-17 15:47 ` [PATCH v3 1/7] libxl: group hotplug related variables Roger Pau Monne
2013-04-17 15:47 ` [PATCH v3 2/7] libxl: add new hotplug interface support to hotplug script callers Roger Pau Monne
2013-03-18 11:47 ` [PATCH v2] libxl: new hotplug calling convention Roger Pau Monne
2013-03-18 11:47 ` [PATCH v2 1/7] libxl: group hotplug related variables Roger Pau Monne
2013-03-18 11:47 ` [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers Roger Pau Monne
2013-04-11 16:25 ` Ian Jackson
2013-04-16 11:30 ` Roger Pau Monné
2013-04-16 12:06 ` Ian Campbell
2013-04-16 14:42 ` Roger Pau Monné
2013-04-16 15:04 ` Ian Jackson
2013-04-11 16:33 ` Ian Jackson
2013-04-12 13:51 ` Roger Pau Monné
2013-04-18 17:23 ` [PATCH v2 2/7] libxl: add new hotplug interface support to hotplug script callers [and 1 more messages] Ian Jackson
2013-04-18 17:40 ` Roger Pau Monné
2013-04-18 17:52 ` Ian Jackson
2013-04-19 8:10 ` Roger Pau Monné
2013-03-18 11:47 ` [PATCH v2 3/7] libxl: add support for hotplug interface v2 in domain creation/destroy Roger Pau Monne
2013-03-18 11:47 ` [PATCH v2 4/7] libxl: chain prepare and attach in libxl_device_disk_add Roger Pau Monne
2013-03-18 11:47 ` [PATCH v2 5/7] libxl: add disk specific remove functions Roger Pau Monne
2013-01-23 17:48 ` [PATCH v1 0/12] libxl: new hotplug calling convention Roger Pau Monne
2013-01-23 17:48 ` [PATCH v1 01/12] libxl: libxl__prepare_ao_device should reset num_exec Roger Pau Monne
2013-01-25 8:57 ` Ian Campbell
2013-01-23 17:48 ` [PATCH v1 02/12] libxl: remove double check in NetBSD hotplug Roger Pau Monne
2013-03-13 14:45 ` Ian Jackson
2013-01-23 17:48 ` [PATCH v1 03/12] libxl: move libxl_device_action to idl Roger Pau Monne
2013-03-13 14:48 ` Ian Jackson
2013-01-23 17:48 ` [PATCH v1 04/12] libxl: pack hotplug related variables Roger Pau Monne
2013-03-13 14:49 ` Ian Jackson
2013-03-14 16:44 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 05/12] libxl: add new hotplug interface support to hotplug script callers Roger Pau Monne
2013-03-13 14:53 ` Ian Jackson
2013-03-13 16:04 ` Roger Pau Monné
2013-03-13 16:10 ` Ian Jackson
2013-03-14 17:03 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 06/12] libxl: add support for different hotplug interfaces Roger Pau Monne
2013-03-13 16:17 ` Ian Jackson
2013-03-15 11:03 ` Roger Pau Monné
2013-03-15 11:24 ` Ian Jackson
2013-03-15 11:36 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 07/12] libxl: add prepare/unprepare operations to the libxl public interface Roger Pau Monne
2013-03-13 16:19 ` Ian Jackson
2013-03-15 11:33 ` Roger Pau Monné
2013-03-15 11:42 ` Roger Pau Monné
2013-03-15 12:20 ` Ian Jackson
2013-03-15 12:39 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 08/12] libxl: add disk specific remove functions Roger Pau Monne
2013-03-13 16:22 ` Ian Jackson
2013-03-15 11:52 ` Roger Pau Monné
2013-04-11 16:17 ` [PATCH v1 08/12] libxl: add disk specific remove functions [and 1 more messages] Ian Jackson
2013-04-15 7:33 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 09/12] xl: add support for new hotplug interface to block-attach/detach Roger Pau Monne
2013-03-13 16:22 ` Ian Jackson
2013-03-15 11:54 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 10/12] libxl: add local attach support for new hotplug scripts Roger Pau Monne
2013-03-13 16:25 ` Ian Jackson
2013-03-15 11:59 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 11/12] hotplug: document new hotplug interface Roger Pau Monne
2013-03-13 16:29 ` Ian Jackson
2013-03-15 12:29 ` Roger Pau Monné
2013-01-23 17:48 ` [PATCH v1 12/12] hotplug/Linux: add iscsi block hotplug script Roger Pau Monne
2013-03-13 16:31 ` Ian Jackson
2013-03-15 12:08 ` Roger Pau Monné
2013-03-15 12:24 ` Ian Jackson
2013-03-04 11:13 ` [PATCH v1 0/12] libxl: new hotplug calling convention Roger Pau Monné
2013-03-18 11:47 ` Roger Pau Monne [this message]
2013-03-18 11:47 ` [PATCH v2 7/7] hotplug/Linux: add iscsi block hotplug script Roger Pau Monne
2013-04-17 15:47 ` [PATCH v3 3/7] libxl: add support for hotplug interface v2 in domain creation/destroy Roger Pau Monne
2013-04-18 17:30 ` Ian Jackson
2013-04-17 15:47 ` [PATCH v3 4/7] libxl: chain prepare and attach in libxl_device_disk_add Roger Pau Monne
2013-04-17 15:47 ` [PATCH v3 5/7] libxl: add disk specific remove functions Roger Pau Monne
2013-04-17 15:47 ` [PATCH v3 6/7] libxl: add local attach support for new hotplug scripts Roger Pau Monne
2013-04-17 15:47 ` [PATCH v3 7/7] hotplug/Linux: add iscsi block hotplug script Roger Pau Monne
2013-04-18 16:28 ` [PATCH v3 0/7] libxl: new hotplug calling convention George Dunlap
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=1363607231-35228-7-git-send-email-roger.pau@citrix.com \
--to=roger.pau@citrix.com \
--cc=ian.campbell@citrix.com \
--cc=ian.jackson@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).