xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Jackson <ian.jackson@eu.citrix.com>
To: xen-devel@lists.xen.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Subject: [PATCH 01/13] libxl: unify libxl__device_destroy and device_hotplug_done
Date: Thu, 2 Aug 2012 18:27:10 +0100	[thread overview]
Message-ID: <1343928442-23966-2-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <1343928442-23966-1-git-send-email-ian.jackson@eu.citrix.com>

device_hotplug_done contains an open-coded but improved version of
libxl__device_destroy.  So move the contents of device_hotplug_done
into libxl__device_destroy, deleting the old code, and replace it at
its old location with a function call.

Add the missing call to libxl__xs_transaction_abort (which was present
in neither version and technically speaking is always a no-op with
this code as it stands at the moment because no-one does "goto out"
other than after libxl__xs_transaction_start or _commit).

Also fix the error handling: the rc from the destroy should be
propagated into the aodev.

Reported-by: Ian Campbell <Ian.Campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>

-
Changes in v5 of series:
 * Also add missing xs abort.
---
 tools/libxl/libxl_device.c |   36 +++++++++++++-----------------------
 1 files changed, 13 insertions(+), 23 deletions(-)

diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index da0c3ea..95b169e 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -513,22 +513,24 @@ int libxl__device_destroy(libxl__gc *gc, libxl__device *dev)
     char *be_path = libxl__device_backend_path(gc, dev);
     char *fe_path = libxl__device_frontend_path(gc, dev);
     xs_transaction_t t = 0;
-    int rc = 0;
+    int rc;
+
+    for (;;) {
+        rc = libxl__xs_transaction_start(gc, &t);
+        if (rc) goto out;
 
-    do {
-        t = xs_transaction_start(CTX->xsh);
         libxl__xs_path_cleanup(gc, t, fe_path);
         libxl__xs_path_cleanup(gc, t, be_path);
-        rc = !xs_transaction_end(CTX->xsh, t, 0);
-    } while (rc && errno == EAGAIN);
-    if (rc) {
-        LOGE(ERROR, "unable to finish transaction");
-        goto out;
+
+        rc = libxl__xs_transaction_commit(gc, &t);
+        if (!rc) break;
+        if (rc < 0) goto out;
     }
 
     libxl__device_destroy_tapdisk(gc, be_path);
 
 out:
+    libxl__xs_transaction_abort(gc, &t);
     return rc;
 }
 
@@ -993,29 +995,17 @@ error:
 static void device_hotplug_done(libxl__egc *egc, libxl__ao_device *aodev)
 {
     STATE_AO_GC(aodev->ao);
-    char *be_path = libxl__device_backend_path(gc, aodev->dev);
-    char *fe_path = libxl__device_frontend_path(gc, aodev->dev);
-    xs_transaction_t t = 0;
     int rc;
 
     device_hotplug_clean(gc, aodev);
 
     /* Clean xenstore if it's a disconnection */
     if (aodev->action == DEVICE_DISCONNECT) {
-        for (;;) {
-            rc = libxl__xs_transaction_start(gc, &t);
-            if (rc) goto out;
-
-            libxl__xs_path_cleanup(gc, t, fe_path);
-            libxl__xs_path_cleanup(gc, t, be_path);
-
-            rc = libxl__xs_transaction_commit(gc, &t);
-            if (!rc) break;
-            if (rc < 0) goto out;
-        }
+        rc = libxl__device_destroy(gc, aodev->dev);
+        if (!aodev->rc)
+            aodev->rc = rc;
     }
 
-out:
     aodev->callback(egc, aodev);
     return;
 }
-- 
1.7.2.5

  reply	other threads:[~2012-08-02 17:27 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-02 17:27 [PATCH v5 00/13] libxl: Assorted bugfixes and cleanups Ian Jackson
2012-08-02 17:27 ` Ian Jackson [this message]
2012-08-02 17:27 ` [PATCH 02/13] libxl: react correctly to bootloader pty master POLLHUP Ian Jackson
2012-08-03  8:32   ` Ian Campbell
2012-08-02 17:27 ` [PATCH 03/13] libxl: fix device counting race in libxl__devices_destroy Ian Jackson
2012-08-02 17:27 ` [PATCH 04/13] libxl: fix formatting of DEFINE_DEVICES_ADD Ian Jackson
2012-08-02 17:27 ` [PATCH 05/13] libxl: abolish useless `start' parameter to libxl__add_* Ian Jackson
2012-08-02 17:27 ` [PATCH 06/13] libxl: rename aodevs to multidev Ian Jackson
2012-08-02 17:27 ` [PATCH 07/13] libxl: do not blunder on if bootloader fails (again) Ian Jackson
2012-08-02 17:27 ` [PATCH 08/13] libxl: remus: mark TODOs more clearly Ian Jackson
2012-08-02 17:27 ` [PATCH 09/13] libxl: remove an unused numainfo parameter Ian Jackson
2012-08-02 17:27 ` [PATCH 10/13] libxl: idl: always initialise KeyedEnum keyvar in member init Ian Jackson
2012-08-02 17:27 ` [PATCH 11/13] libxl: correct some comments regarding event API and fds Ian Jackson
2012-08-03  8:35   ` Ian Campbell
2012-08-03 10:53     ` Ian Jackson
2012-08-02 17:27 ` [PATCH 12/13] libxl: add a comment re the memory management API instability Ian Jackson
2012-08-03  8:35   ` Ian Campbell
2012-08-02 17:27 ` [PATCH 13/13] libxl: -Wunused-parameter Ian Jackson
2012-08-03  8:08   ` Ian Campbell
2012-08-03  8:59 ` [PATCH v5 00/13] libxl: Assorted bugfixes and cleanups Ian Campbell
2012-08-03 11:05   ` Ian Jackson

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=1343928442-23966-2-git-send-email-ian.jackson@eu.citrix.com \
    --to=ian.jackson@eu.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).