[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH RFC 07/10] libxl: add local attach support for new hotplug scripts



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@xxxxxxxxxx>
---
 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@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.