xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] libxl: Make local_initiate_attach more rational
@ 2015-07-02 17:42 George Dunlap
  2015-07-02 17:55 ` Roger Pau Monné
  0 siblings, 1 reply; 4+ messages in thread
From: George Dunlap @ 2015-07-02 17:42 UTC (permalink / raw)
  To: xen-devel
  Cc: George Dunlap, Ian Jackson, Wei Liu, Ian Campbell,
	Roger Pau Monne

There are a lot of paths through
libxl__device_disk_local_initiate_attach(), but they all really boil
down to one thing: Can we just access the file directly, or do we need
to attach it?

The requirements for direct access are fairly simple:
* Is this local (as opposed to a driver domain)?
* Is this a raw format (as opposed to cooked)?
* Does this have no scripts associated with it?

If it meets all those requirements, we can access it directly;
otherwise we need to attach it.

This fixes a bug where bootloader execution fails for disks with
hotplug scripts.

This should fix a theoretical bug when using a qdisk backend in a
driver domain. (Not tested.)

Based on a patch by Roger Pau Monne <roger.pau@citrix.com>.

Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
---
CC: Ian Campbell <ian.campbell@citrix.com>
CC: Ian Jackson <ian.jackson@citrix.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monne <roger.pau@citrix.com>

This has been tested with the in-tree blktap2.

Changes since v1:
- Remove the entire check for recognized disk backend type, since we
  don't use that parameter.
---
 tools/libxl/libxl.c | 97 ++++++++++++++---------------------------------------
 1 file changed, 26 insertions(+), 71 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index d86ea62..791b969 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -3071,55 +3071,21 @@ void libxl__device_disk_local_initiate_attach(libxl__egc *egc,
     rc = libxl__device_disk_setdefault(gc, disk);
     if (rc) goto out;
 
-    switch (disk->backend) {
-        case LIBXL_DISK_BACKEND_PHY:
-            LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching PHY disk %s",
-                       disk->pdev_path);
-            dev = disk->pdev_path;
-            break;
-        case LIBXL_DISK_BACKEND_TAP:
-            switch (disk->format) {
-            case LIBXL_DISK_FORMAT_RAW:
-                /* optimise away the early tapdisk attach in this case */
-                LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "locally attaching"
-                           " tap disk %s directly (ie without using blktap)",
-                           disk->pdev_path);
-                dev = disk->pdev_path;
-                break;
-            case LIBXL_DISK_FORMAT_VHD:
-                dev = libxl__blktap_devpath(gc, disk->pdev_path,
-                                            disk->format);
-                break;
-            case LIBXL_DISK_FORMAT_QCOW:
-            case LIBXL_DISK_FORMAT_QCOW2:
-                abort(); /* prevented by libxl__device_disk_set_backend */
-            default:
-                LIBXL__LOG(ctx, LIBXL__LOG_ERROR,
-                           "unrecognized disk format: %d", disk->format);
-                rc = ERROR_FAIL;
-                goto out;
-            }
-            break;
-        case LIBXL_DISK_BACKEND_QDISK:
-            if (disk->format != LIBXL_DISK_FORMAT_RAW) {
-                libxl__prepare_ao_device(ao, &dls->aodev);
-                dls->aodev.callback = local_device_attach_cb;
-                device_disk_add(egc, LIBXL_TOOLSTACK_DOMID, disk,
-                                &dls->aodev, libxl__alloc_vdev,
-                                (void *) blkdev_start);
-                return;
-            } else {
-                dev = disk->pdev_path;
-            }
-            LOG(DEBUG, "locally attaching qdisk %s", dev);
-            break;
-        default:
-            LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "unrecognized disk backend "
-                "type: %d", disk->backend);
-            rc = ERROR_FAIL;
-            goto out;
+    /* If this is in a driver domain, or it's not a raw format, or it involves
+     * running a script, we have to do a local attach. */
+    if (disk->backend_domname != NULL
+        || disk->format != LIBXL_DISK_FORMAT_RAW
+        || disk->script != NULL) {
+        libxl__prepare_ao_device(ao, &dls->aodev);
+        dls->aodev.callback = local_device_attach_cb;
+        device_disk_add(egc, LIBXL_TOOLSTACK_DOMID, disk, &dls->aodev,
+                        libxl__alloc_vdev, (void *) blkdev_start);
+        return;
     }
 
+    LOG(DEBUG, "locally attaching RAW disk %s", disk->pdev_path);
+    dev = disk->pdev_path;
+
     if (dev != NULL)
         dls->diskpath = libxl__strdup(gc, dev);
 
@@ -3152,7 +3118,7 @@ static void local_device_attach_cb(libxl__egc *egc, libxl__ao_device *aodev)
     }
 
     dev = GCSPRINTF("/dev/%s", disk->vdev);
-    LOG(DEBUG, "locally attaching qdisk %s", dev);
+    LOG(DEBUG, "locally attaching disk %s", dev);
 
     rc = libxl__device_from_disk(gc, LIBXL_TOOLSTACK_DOMID, disk, &device);
     if (rc < 0)
@@ -3191,29 +3157,18 @@ void libxl__device_disk_local_initiate_detach(libxl__egc *egc,
 
     if (!dls->diskpath) goto out;
 
-    switch (disk->backend) {
-        case LIBXL_DISK_BACKEND_QDISK:
-            if (disk->vdev != NULL) {
-                GCNEW(device);
-                rc = libxl__device_from_disk(gc, LIBXL_TOOLSTACK_DOMID,
-                                             disk, device);
-                if (rc != 0) goto out;
-
-                aodev->action = LIBXL__DEVICE_ACTION_REMOVE;
-                aodev->dev = device;
-                aodev->callback = local_device_detach_cb;
-                aodev->force = 0;
-                libxl__initiate_device_remove(egc, aodev);
-                return;
-            }
-            /* disk->vdev == NULL; fall through */
-        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.
-             */
-            goto out;
+    if (disk->vdev != NULL) {
+        GCNEW(device);
+        rc = libxl__device_from_disk(gc, LIBXL_TOOLSTACK_DOMID,
+                                     disk, device);
+        if (rc != 0) goto out;
+        
+        aodev->action = LIBXL__DEVICE_ACTION_REMOVE;
+        aodev->dev = device;
+        aodev->callback = local_device_detach_cb;
+        aodev->force = 0;
+        libxl__initiate_device_remove(egc, aodev);
+        return;
     }
 
 out:
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] libxl: Make local_initiate_attach more rational
  2015-07-02 17:42 [PATCH v2] libxl: Make local_initiate_attach more rational George Dunlap
@ 2015-07-02 17:55 ` Roger Pau Monné
  2015-07-03 14:28   ` Ian Campbell
  0 siblings, 1 reply; 4+ messages in thread
From: Roger Pau Monné @ 2015-07-02 17:55 UTC (permalink / raw)
  To: George Dunlap, xen-devel; +Cc: Ian Jackson, Wei Liu, Ian Campbell

El 02/07/15 a les 19.42, George Dunlap ha escrit:
> There are a lot of paths through
> libxl__device_disk_local_initiate_attach(), but they all really boil
> down to one thing: Can we just access the file directly, or do we need
> to attach it?
> 
> The requirements for direct access are fairly simple:
> * Is this local (as opposed to a driver domain)?
> * Is this a raw format (as opposed to cooked)?
> * Does this have no scripts associated with it?
> 
> If it meets all those requirements, we can access it directly;
> otherwise we need to attach it.
> 
> This fixes a bug where bootloader execution fails for disks with
> hotplug scripts.
> 
> This should fix a theoretical bug when using a qdisk backend in a
> driver domain. (Not tested.)
> 
> Based on a patch by Roger Pau Monne <roger.pau@citrix.com>.
> 
> Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>

LGTM

Acked-by: Roger Pau Monné <roger.pau@citrix.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] libxl: Make local_initiate_attach more rational
  2015-07-02 17:55 ` Roger Pau Monné
@ 2015-07-03 14:28   ` Ian Campbell
  2015-07-06  9:44     ` George Dunlap
  0 siblings, 1 reply; 4+ messages in thread
From: Ian Campbell @ 2015-07-03 14:28 UTC (permalink / raw)
  To: Roger Pau Monné; +Cc: George Dunlap, Ian Jackson, Wei Liu, xen-devel

On Thu, 2015-07-02 at 19:55 +0200, Roger Pau Monné wrote:
> El 02/07/15 a les 19.42, George Dunlap ha escrit:
> > There are a lot of paths through
> > libxl__device_disk_local_initiate_attach(), but they all really boil
> > down to one thing: Can we just access the file directly, or do we need
> > to attach it?
> > 
> > The requirements for direct access are fairly simple:
> > * Is this local (as opposed to a driver domain)?
> > * Is this a raw format (as opposed to cooked)?
> > * Does this have no scripts associated with it?
> > 
> > If it meets all those requirements, we can access it directly;
> > otherwise we need to attach it.
> > 
> > This fixes a bug where bootloader execution fails for disks with
> > hotplug scripts.
> > 
> > This should fix a theoretical bug when using a qdisk backend in a
> > driver domain. (Not tested.)
> > 
> > Based on a patch by Roger Pau Monne <roger.pau@citrix.com>.
> > 
> > Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
> 
> LGTM
> 
> Acked-by: Roger Pau Monné <roger.pau@citrix.com>

Acked-by: Ian Campbell <ian.campbell@citrix.com>



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] libxl: Make local_initiate_attach more rational
  2015-07-03 14:28   ` Ian Campbell
@ 2015-07-06  9:44     ` George Dunlap
  0 siblings, 0 replies; 4+ messages in thread
From: George Dunlap @ 2015-07-06  9:44 UTC (permalink / raw)
  To: Ian Campbell, Roger Pau Monné; +Cc: Ian Jackson, Wei Liu, xen-devel

On 07/03/2015 03:28 PM, Ian Campbell wrote:
> On Thu, 2015-07-02 at 19:55 +0200, Roger Pau Monné wrote:
>> El 02/07/15 a les 19.42, George Dunlap ha escrit:
>>> There are a lot of paths through
>>> libxl__device_disk_local_initiate_attach(), but they all really boil
>>> down to one thing: Can we just access the file directly, or do we need
>>> to attach it?
>>>
>>> The requirements for direct access are fairly simple:
>>> * Is this local (as opposed to a driver domain)?
>>> * Is this a raw format (as opposed to cooked)?
>>> * Does this have no scripts associated with it?
>>>
>>> If it meets all those requirements, we can access it directly;
>>> otherwise we need to attach it.
>>>
>>> This fixes a bug where bootloader execution fails for disks with
>>> hotplug scripts.
>>>
>>> This should fix a theoretical bug when using a qdisk backend in a
>>> driver domain. (Not tested.)
>>>
>>> Based on a patch by Roger Pau Monne <roger.pau@citrix.com>.
>>>
>>> Signed-off-by: George Dunlap <george.dunlap@eu.citrix.com>
>>
>> LGTM
>>
>> Acked-by: Roger Pau Monné <roger.pau@citrix.com>
> 
> Acked-by: Ian Campbell <ian.campbell@citrix.com>

Hmm, this one seems somehow not to build because now ctx isn't used
anywhere.

I'm going to re-send this in a bit as part of a longer series switching
to blktap -- I'll take the liberty to retain both of your Acks.

 -George


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-07-06  9:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-02 17:42 [PATCH v2] libxl: Make local_initiate_attach more rational George Dunlap
2015-07-02 17:55 ` Roger Pau Monné
2015-07-03 14:28   ` Ian Campbell
2015-07-06  9:44     ` George Dunlap

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).