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] libxl: attempt to cleanup tapdisk processes on disk

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] libxl: attempt to cleanup tapdisk processes on disk backend destroy
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Wed, 6 Jul 2011 17:14:44 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Wed, 06 Jul 2011 09:15:53 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
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>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1309968705 -3600
# Node ID e4781aedf817c5ab36f6f3077e44c43c566a2812
# Parent  05700ef33648e0777fb48ba965bf723264d56a31
libxl: attempt to cleanup tapdisk processes on disk backend destroy.

Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>

diff -r 05700ef33648 -r e4781aedf817 tools/blktap2/control/tap-ctl-list.c
--- a/tools/blktap2/control/tap-ctl-list.c      Wed Jul 06 14:20:36 2011 +0100
+++ b/tools/blktap2/control/tap-ctl-list.c      Wed Jul 06 17:11:45 2011 +0100
@@ -506,17 +506,15 @@ out:
 }
 
 int
-tap_ctl_find_minor(const char *type, const char *path)
+tap_ctl_find(const char *type, const char *path, tap_list_t *tap)
 {
        tap_list_t **list, **_entry;
-       int minor, err;
+       int ret = -ENOENT, err;
 
        err = tap_ctl_list(&list);
        if (err)
                return err;
 
-       minor = -1;
-
        for (_entry = list; *_entry != NULL; ++_entry) {
                tap_list_t *entry  = *_entry;
 
@@ -526,11 +524,13 @@ tap_ctl_find_minor(const char *type, con
                if (path && (!entry->path || strcmp(entry->path, path)))
                        continue;
 
-               minor = entry->minor;
+               *tap = *entry;
+               tap->type = tap->path = NULL;
+               ret = 0;
                break;
        }
 
        tap_ctl_free_list(list);
 
-       return minor >= 0 ? minor : -ENOENT;
+       return ret;
 }
diff -r 05700ef33648 -r e4781aedf817 tools/blktap2/control/tap-ctl.h
--- a/tools/blktap2/control/tap-ctl.h   Wed Jul 06 14:20:36 2011 +0100
+++ b/tools/blktap2/control/tap-ctl.h   Wed Jul 06 17:11:45 2011 +0100
@@ -76,7 +76,7 @@ int tap_ctl_get_driver_id(const char *ha
 
 int tap_ctl_list(tap_list_t ***list);
 void tap_ctl_free_list(tap_list_t **list);
-int tap_ctl_find_minor(const char *type, const char *path);
+int tap_ctl_find(const char *type, const char *path, tap_list_t *tap);
 
 int tap_ctl_allocate(int *minor, char **devname);
 int tap_ctl_free(const int minor);
diff -r 05700ef33648 -r e4781aedf817 tools/libxl/libxl_blktap2.c
--- a/tools/libxl/libxl_blktap2.c       Wed Jul 06 14:20:36 2011 +0100
+++ b/tools/libxl/libxl_blktap2.c       Wed Jul 06 17:11:45 2011 +0100
@@ -18,6 +18,8 @@
 
 #include "tap-ctl.h"
 
+#include <string.h>
+
 int libxl__blktap_enabled(libxl__gc *gc)
 {
     const char *msg;
@@ -30,12 +32,13 @@ char *libxl__blktap_devpath(libxl__gc *g
 {
     const char *type;
     char *params, *devname = NULL;
-    int minor, err;
+    tap_list_t tap;
+    int err;
 
     type = libxl__device_disk_string_of_format(format);
-    minor = tap_ctl_find_minor(type, disk);
-    if (minor >= 0) {
-        devname = libxl__sprintf(gc, "/dev/xen/blktap-2/tapdev%d", minor);
+    err = tap_ctl_find(type, disk, &tap);
+    if (err == 0) {
+        devname = libxl__sprintf(gc, "/dev/xen/blktap-2/tapdev%d", tap.minor);
         if (devname)
             return devname;
     }
@@ -49,3 +52,28 @@ char *libxl__blktap_devpath(libxl__gc *g
 
     return NULL;
 }
+
+
+void libxl__device_destroy_tapdisk(libxl__gc *gc, char *be_path)
+{
+    char *path, *params, *type, *disk;
+    int err;
+    tap_list_t tap;
+
+    path = libxl__sprintf(gc, "%s/tapdisk-params", be_path);
+    if (!path) return;
+
+    params = libxl__xs_read(gc, XBT_NULL, path);
+    if (!params) return;
+
+    type = params;
+    disk = strchr(params, ':');
+    if (!disk) return;
+
+    *disk++ = '\0';
+
+    err = tap_ctl_find(type, disk, &tap);
+    if (err < 0) return;
+
+    tap_ctl_destroy(tap.id, tap.minor);
+}
diff -r 05700ef33648 -r e4781aedf817 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c        Wed Jul 06 14:20:36 2011 +0100
+++ b/tools/libxl/libxl_device.c        Wed Jul 06 17:11:45 2011 +0100
@@ -254,6 +254,7 @@ int libxl__device_destroy(libxl__gc *gc,
     if (!state)
         goto out;
     if (atoi(state) != 4) {
+        libxl__device_destroy_tapdisk(gc, be_path);
         xs_rm(ctx->xsh, XBT_NULL, be_path);
         goto out;
     }
@@ -276,6 +277,7 @@ retry_transaction:
     } else {
         xs_rm(ctx->xsh, XBT_NULL, be_path);
     }
+    libxl__device_destroy_tapdisk(gc, be_path);
 out:
     return rc;
 }
diff -r 05700ef33648 -r e4781aedf817 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Wed Jul 06 14:20:36 2011 +0100
+++ b/tools/libxl/libxl_internal.h      Wed Jul 06 17:11:45 2011 +0100
@@ -357,6 +357,12 @@ _hidden char *libxl__blktap_devpath(libx
                                     const char *disk,
                                     libxl_disk_format format);
 
+/* libxl__device_destroy_tapdisk:
+ *   Destroys any tapdisk process associated with the backend represented
+ *   by be_path.
+ */
+_hidden void libxl__device_destroy_tapdisk(libxl__gc *gc, char *be_path);
+
 _hidden char *libxl__uuid2string(libxl__gc *gc, const libxl_uuid uuid);
 
 struct libxl__xen_console_reader {
diff -r 05700ef33648 -r e4781aedf817 tools/libxl/libxl_noblktap2.c
--- a/tools/libxl/libxl_noblktap2.c     Wed Jul 06 14:20:36 2011 +0100
+++ b/tools/libxl/libxl_noblktap2.c     Wed Jul 06 17:11:45 2011 +0100
@@ -27,3 +27,7 @@ char *libxl__blktap_devpath(libxl__gc *g
 {
     return NULL;
 }
+
+void libxl__device_destroy_tapdisk(libxl__gc *gc, char *be_path)
+{
+}

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

<Prev in Thread] Current Thread [Next in Thread>