WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 2 of 2] libxl: add support for booting PV domains fro

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 2 of 2] libxl: add support for booting PV domains from NetBSD using raw files as disks
From: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
Date: Fri, 16 Sep 2011 17:36:59 +0200
Delivery-date: Fri, 16 Sep 2011 08:43:22 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:content-type:mime-version:content-transfer-encoding:subject :x-mercurial-node:message-id:in-reply-to:references:user-agent:date :from:to; bh=qczwEnbx93uxw7ZjO/WbcmnwJmUHcOdAo5sMgOaAZ90=; b=MMnR4KxrQrVhH4XLSFT0aDlDynKaiBimELN6K3Kbmw1h8SmagviRr1J5AzS+N3WS+d L87fNa+pen4EudMuwqQ0QE0pqCrtZWa7RkW1sY3CknpF/l0J5B6PaFZX7f8g282vLPMc nx28HDaVvSgNw1rqpgDdxGysM987Y96FxtE54=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1316187417@loki>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1316187417@loki>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.8.4
# HG changeset patch
# User Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>
# Date 1316187362 -7200
# Node ID aff3960421768180410c8d553acf8881435bc3b4
# Parent  00949e363f6f2c70001da548403475628df93b97
libxl: add support for booting PV domains from NetBSD using raw files as disks.

Used the hotplug-status attribute in xenstore for vbd to check when the device 
is offline.

Signed-off-by: Roger Pau Monne <roger.pau@xxxxxxxxxxxxx>

diff -r 00949e363f6f -r aff396042176 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c        Fri Sep 16 17:29:45 2011 +0200
+++ b/tools/libxl/libxl_device.c        Fri Sep 16 17:36:02 2011 +0200
@@ -136,15 +136,20 @@ static int disk_try_backend(disk_try_bac
               a->disk->format == LIBXL_DISK_FORMAT_EMPTY)) {
             goto bad_format;
         }
-        if (a->disk->format != LIBXL_DISK_FORMAT_EMPTY &&
-            !S_ISBLK(a->stab.st_mode)) {
-            LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Disk vdev=%s, backend phy"
-                       " unsuitable as phys path not a block device",
-                       a->disk->vdev);
-            return 0;
-        }
-
-        return backend;
+        if (S_ISBLK(a->stab.st_mode))
+                return backend;
+#ifdef HAVE_PHY_BACKEND_FILE_SUPPORT
+        if (S_ISREG(a->stab.st_mode))
+            return backend;
+        LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Disk vdev=%s, backend phy"
+                   " unsuitable as phys path not a block device or"
+                   " raw image", a->disk->vdev);
+#else
+        LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Disk vdev=%s, backend phy"
+                   " unsuitable as phys path not a block device",
+                   a->disk->vdev);
+#endif
+        return 0;
 
     case LIBXL_DISK_BACKEND_TAP:
         if (!libxl__blktap_enabled(a->gc)) {
@@ -366,14 +371,26 @@ int libxl__device_destroy(libxl__gc *gc,
     libxl_ctx *ctx = libxl__gc_owner(gc);
     xs_transaction_t t;
     char *state_path = libxl__sprintf(gc, "%s/state", be_path);
+    char *hotplug_path = libxl__sprintf(gc, "%s/hotplug-status", be_path);
     char *state = libxl__xs_read(gc, XBT_NULL, state_path);
+    char *hotplug = libxl__xs_read(gc, XBT_NULL, hotplug_path);
     int rc = 0;
 
     if (!state)
         goto out;
-    if (atoi(state) != 4) {
-        xs_rm(ctx->xsh, XBT_NULL, be_path);
-        goto out;
+
+    if (!strstr(be_path, "vbd")) {
+        if (atoi(state) != 4) {
+            xs_rm(ctx->xsh, XBT_NULL, be_path);
+            goto out;
+        }
+    } else {
+        if (!hotplug)
+            goto out;
+        if (!strcmp(hotplug, "disconnected")) {
+            xs_rm(ctx->xsh, XBT_NULL, be_path);
+            goto out;
+        }
     }
 
 retry_transaction:
@@ -389,8 +406,13 @@ retry_transaction:
         }
     }
     if (!force) {
-        xs_watch(ctx->xsh, state_path, be_path);
-        rc = 1;
+        if (strstr(be_path, "vbd")) {
+            xs_watch(ctx->xsh, hotplug_path, be_path);
+            rc = 1;
+        } else {
+            xs_watch(ctx->xsh, state_path, be_path);
+            rc = 1;
+        }
     } else {
         xs_rm(ctx->xsh, XBT_NULL, be_path);
     }
@@ -405,6 +427,7 @@ static int wait_for_dev_destroy(libxl__g
     unsigned int n;
     fd_set rfds;
     char **l1 = NULL;
+    char *state, *hotplug;
 
     rc = 1;
     nfds = xs_fileno(ctx->xsh) + 1;
@@ -413,15 +436,29 @@ static int wait_for_dev_destroy(libxl__g
     if (select(nfds, &rfds, NULL, NULL, tv) > 0) {
         l1 = xs_read_watch(ctx->xsh, &n);
         if (l1 != NULL) {
-            char *state = libxl__xs_read(gc, XBT_NULL, l1[XS_WATCH_PATH]);
-            if (!state || atoi(state) == 6) {
-                xs_unwatch(ctx->xsh, l1[0], l1[1]);
-                xs_rm(ctx->xsh, XBT_NULL, l1[XS_WATCH_TOKEN]);
-                LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Destroyed device backend at 
%s", l1[XS_WATCH_TOKEN]);
-                rc = 0;
+            if (strstr(l1[XS_WATCH_PATH], "hotplug-status")) {
+                hotplug = libxl__xs_read(gc, XBT_NULL, l1[XS_WATCH_PATH]);
+                if (!hotplug || !strcmp(hotplug, "disconnected")) {
+                    xs_unwatch(ctx->xsh, l1[0], l1[1]);
+                    xs_rm(ctx->xsh, XBT_NULL, l1[XS_WATCH_TOKEN]);
+                    LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Destroyed device 
backend at %s hotplug-status: %s", 
+                               l1[XS_WATCH_TOKEN], hotplug);
+                    rc = 0;
+                }
+            } else {
+                state = libxl__xs_read(gc, XBT_NULL, l1[XS_WATCH_PATH]);
+                if (!state || atoi(state) == 6) {
+                    xs_unwatch(ctx->xsh, l1[0], l1[1]);
+                    xs_rm(ctx->xsh, XBT_NULL, l1[XS_WATCH_TOKEN]);
+                    LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Destroyed device 
backend at %s", l1[XS_WATCH_TOKEN]);
+                    rc = 0;
+                }
             }
             free(l1);
         }
+    } else {
+        /* timeout reached */
+        rc = 0;
     }
     return rc;
 }
@@ -482,7 +519,7 @@ int libxl__devices_destroy(libxl__gc *gc
         tv.tv_usec = 0;
         while (n_watches > 0) {
             if (wait_for_dev_destroy(gc, &tv)) {
-                break;
+                continue;
             } else {
                 n_watches--;
             }
diff -r 00949e363f6f -r aff396042176 tools/libxl/libxl_osdeps.h
--- a/tools/libxl/libxl_osdeps.h        Fri Sep 16 17:29:45 2011 +0200
+++ b/tools/libxl/libxl_osdeps.h        Fri Sep 16 17:36:02 2011 +0200
@@ -25,6 +25,7 @@
 
 #if defined(__NetBSD__) || defined(__OpenBSD__)
 #include <util.h>
+#define HAVE_PHY_BACKEND_FILE_SUPPORT
 #elif defined(__linux__)
 #include <pty.h>
 #elif defined(__sun__)

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel