xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: George Dunlap <george.dunlap@eu.citrix.com>
To: xen-devel@lists.xen.org
Cc: George Dunlap <george.dunlap@eu.citrix.com>,
	Ian Jackson <ian.jackson@citrix.com>,
	Wei Liu <wei.liu2@citrix.com>,
	Ian Campbell <ian.campbell@citrix.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH 1/6] libxl: Make local_initiate_attach more rational
Date: Mon, 6 Jul 2015 11:51:38 +0100	[thread overview]
Message-ID: <1436179903-449-2-git-send-email-george.dunlap@eu.citrix.com> (raw)
In-Reply-To: <1436179903-449-1-git-send-email-george.dunlap@eu.citrix.com>

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>
Acked-by: Roger Pau Monné <roger.pau@citrix.com>
Acked-by: Ian Campbell <ian.campbell@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 is identical to the patch I sent earlier, with the exception that
I have fixed a build by removing the (now) unused ctx variable.  Given
the circumstances I have taken the liberty to retain the Acks above.
---
 tools/libxl/libxl.c | 98 ++++++++++++++---------------------------------------
 1 file changed, 26 insertions(+), 72 deletions(-)

diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index e9a2d26..92563db 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -3058,7 +3058,6 @@ void libxl__device_disk_local_initiate_attach(libxl__egc *egc,
                                      libxl__disk_local_state *dls)
 {
     STATE_AO_GC(dls->ao);
-    libxl_ctx *ctx = CTX;
     char *dev = NULL;
     int rc;
     const libxl_device_disk *in_disk = dls->in_disk;
@@ -3076,55 +3075,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);
 
@@ -3157,7 +3122,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)
@@ -3196,29 +3161,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


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

  reply	other threads:[~2015-07-06 10:51 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-06 10:51 [PATCH 0/6] Use system blktap George Dunlap
2015-07-06 10:51 ` George Dunlap [this message]
2015-07-06 10:51 ` [PATCH 2/6] libxl: Remove linux udev rules George Dunlap
2015-07-07 11:39   ` Wei Liu
2015-07-14 16:13     ` Konrad Rzeszutek Wilk
2015-07-14 16:21       ` Ian Campbell
2015-07-14 16:35         ` George Dunlap
2015-07-14 16:40           ` Wei Liu
2015-07-14 16:48             ` Ian Campbell
2015-07-23 11:55               ` Roger Pau Monné
2015-07-23 12:30                 ` Ian Campbell
2015-07-15 11:07         ` [PATCH for-4.6] tools/hotplug: Add an initscript to start "xl devd" in a driver domain Ian Campbell
2015-07-15 13:26           ` Wei Liu
2015-07-15 13:40             ` Ian Campbell
2015-07-15 15:25           ` George Dunlap
2015-07-15 15:32           ` Ian Jackson
2015-07-15 15:35             ` George Dunlap
2015-07-15 15:37               ` Ian Campbell
2015-07-16 16:58         ` [PATCH for-4.6 v2] " Ian Campbell
2015-07-16 17:09           ` Ian Jackson
2015-07-16 17:48           ` Wei Liu
2015-07-17  9:05           ` Wei Liu
2015-07-17 11:36             ` Ian Campbell
2015-07-20 14:16           ` Roger Pau Monné
2015-07-20 14:28             ` Ian Campbell
2015-07-06 10:51 ` [PATCH 3/6] tools: Add a block-tap script for setting up tapdisks via tap-ctl George Dunlap
2015-07-07 12:03   ` Wei Liu
2015-07-07 12:35     ` Wei Liu
2015-07-06 10:51 ` [PATCH 4/6] libxl: Use the block-tap script for LIBXL_DISK_BACKEND_TAP George Dunlap
2015-07-06 11:01   ` Andrew Cooper
2015-07-06 12:39     ` George Dunlap
2015-07-07 12:29   ` Wei Liu
2015-07-07 13:41     ` George Dunlap
2015-07-07 14:20       ` Ian Campbell
2015-07-07 14:27         ` George Dunlap
2015-07-06 10:51 ` [PATCH 5/6] tools: Remove in-tree blktap2 George Dunlap
2015-07-07 11:55   ` Wei Liu
2015-07-06 10:51 ` [PATCH 6/6] libxl: Add more logging to hotplug script path George Dunlap
2015-07-07 11:55   ` Wei Liu
2015-07-07 14:21 ` [PATCH 0/6] Use system blktap Ian Campbell
2015-07-07 14:24   ` George Dunlap
2015-07-07 14:52     ` Ian Campbell
2015-07-07 14:59       ` George Dunlap
2015-07-07 15:04         ` Ian Campbell
2015-07-07 15:20 ` Ian Campbell

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=1436179903-449-2-git-send-email-george.dunlap@eu.citrix.com \
    --to=george.dunlap@eu.citrix.com \
    --cc=ian.campbell@citrix.com \
    --cc=ian.jackson@citrix.com \
    --cc=roger.pau@citrix.com \
    --cc=wei.liu2@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).