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 13 of 27 v2] libxl: separate forced and non-forced de

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 13 of 27 v2] libxl: separate forced and non-forced device remove
From: Ian Campbell <ian.campbell@xxxxxxxxxx>
Date: Thu, 13 Oct 2011 10:53:38 +0100
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Delivery-date: Thu, 13 Oct 2011 03:26:48 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1318499605@xxxxxxxxxxxxxxxxxxxxx>
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.1318499605@xxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.4
# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1318499565 -3600
# Node ID 0584450afaf8c1236f0c0b870fc16629c1233662
# Parent  b8b0e5d41f320124c13bd8d39627b9366ff270f1
libxl: separate forced and non-forced device remove.

The function libxl__device_destroy currently takes a force parameter however:

  * in the forced case we initiate a graceful shutdown and then immediately
    nuke the backend directory, quite likely before anyone got a chance to 
react.
  * the callers all have a "wait" variable and pass in "!wait" as the force
    argument which is confusing since not waiting is not really the same thing
    as forcing the destroy.

Therefore split the function into libxl__device_remove and
libxl__device_destroy. The former initiates a graceful shutdown which
the latter simply nukes the backend directory.

This makes some of the callers look a bit odd but that should fall out as I
continue to pull this piece of string.

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

diff -r b8b0e5d41f32 -r 0584450afaf8 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c        Thu Oct 13 10:52:45 2011 +0100
+++ b/tools/libxl/libxl_device.c        Thu Oct 13 10:52:45 2011 +0100
@@ -365,7 +365,7 @@ int libxl__device_disk_dev_number(const 
     return -1;
 }
 
-int libxl__device_destroy(libxl__gc *gc, char *be_path, int force)
+int libxl__device_remove(libxl__gc *gc, char *be_path)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
     xs_transaction_t t;
@@ -393,17 +393,22 @@ retry_transaction:
             goto out;
         }
     }
-    if (!force) {
-        xs_watch(ctx->xsh, state_path, be_path);
-        rc = 1;
-    } else {
-        xs_rm(ctx->xsh, XBT_NULL, be_path);
-    }
+
+    xs_watch(ctx->xsh, state_path, be_path);
     libxl__device_destroy_tapdisk(gc, be_path);
+    rc = 1;
 out:
     return rc;
 }
 
+int libxl__device_destroy(libxl__gc *gc, char *be_path)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    xs_rm(ctx->xsh, XBT_NULL, be_path);
+    libxl__device_destroy_tapdisk(gc, be_path);
+    return 0;
+}
+
 static int wait_for_dev_destroy(libxl__gc *gc, struct timeval *tv)
 {
     libxl_ctx *ctx = libxl__gc_owner(gc);
@@ -461,7 +466,9 @@ int libxl__devices_destroy(libxl__gc *gc
             fe_path = libxl__sprintf(gc, "/local/domain/%d/device/%s/%s", 
domid, l1[i], l2[j]);
             be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, 
"%s/backend", fe_path));
             if (be_path != NULL) {
-                if (libxl__device_destroy(gc, be_path, force) > 0)
+                int rc = force ? libxl__device_destroy(gc, be_path)
+                               : libxl__device_remove(gc, be_path);
+                if (rc > 0)
                     n_watches++;
             } else {
                 xs_rm(ctx->xsh, XBT_NULL, path);
@@ -473,7 +480,9 @@ int libxl__devices_destroy(libxl__gc *gc
     fe_path = libxl__sprintf(gc, "/local/domain/%d/console", domid);
     be_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, "%s/backend", 
fe_path));
     if (be_path && strcmp(be_path, "")) {
-        if (libxl__device_destroy(gc, be_path, force) > 0)
+        int rc = force ? libxl__device_destroy(gc, be_path)
+                       : libxl__device_remove(gc, be_path);
+        if (rc > 0)
             n_watches++;
     }
 
@@ -506,7 +515,10 @@ int libxl__device_del(libxl__gc *gc, lib
 
     backend_path = libxl__device_backend_path(gc, dev);
 
-    rc = libxl__device_destroy(gc, backend_path, !wait);
+    if (wait)
+        rc = libxl__device_remove(gc, backend_path);
+    else
+        rc = libxl__device_destroy(gc, backend_path);
     if (rc == -1) {
         rc = ERROR_FAIL;
         goto out;
diff -r b8b0e5d41f32 -r 0584450afaf8 tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Thu Oct 13 10:52:45 2011 +0100
+++ b/tools/libxl/libxl_internal.h      Thu Oct 13 10:52:45 2011 +0100
@@ -253,7 +253,8 @@ _hidden int libxl__device_generic_add(li
 _hidden char *libxl__device_backend_path(libxl__gc *gc, libxl__device *device);
 _hidden char *libxl__device_frontend_path(libxl__gc *gc, libxl__device 
*device);
 _hidden int libxl__device_del(libxl__gc *gc, libxl__device *dev, int wait);
-_hidden int libxl__device_destroy(libxl__gc *gc, char *be_path, int force);
+_hidden int libxl__device_remove(libxl__gc *gc, char *be_path);
+_hidden int libxl__device_destroy(libxl__gc *gc, char *be_path);
 _hidden int libxl__devices_destroy(libxl__gc *gc, uint32_t domid, int force);
 _hidden int libxl__wait_for_backend(libxl__gc *gc, char *be_path, char *state);
 
diff -r b8b0e5d41f32 -r 0584450afaf8 tools/libxl/libxl_pci.c
--- a/tools/libxl/libxl_pci.c   Thu Oct 13 10:52:45 2011 +0100
+++ b/tools/libxl/libxl_pci.c   Thu Oct 13 10:52:45 2011 +0100
@@ -411,8 +411,7 @@ retry_transaction2:
 
     if (num == 1) {
         char *fe_path = libxl__xs_read(gc, XBT_NULL, libxl__sprintf(gc, 
"%s/frontend", be_path));
-        libxl__device_destroy(gc, be_path, 1);
-        xs_rm(ctx->xsh, XBT_NULL, be_path);
+        libxl__device_destroy(gc, be_path);
         xs_rm(ctx->xsh, XBT_NULL, fe_path);
         return 0;
     }

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

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