xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@citrix.com>
To: xen-devel@lists.xen.org
Cc: Ian Jackson <ian.jackson@eu.citrix.com>,
	Roger Pau Monne <roger.pau@citrix.com>
Subject: [PATCH v10 01/19] libxl: check backend state before setting it to "closing"
Date: Fri, 20 Jul 2012 15:12:10 +0100	[thread overview]
Message-ID: <1342793548-10239-2-git-send-email-roger.pau@citrix.com> (raw)
In-Reply-To: <1342793548-10239-1-git-send-email-roger.pau@citrix.com>

Check backend state before unconditionally setting it to "closing"
(5), since it might already be in "closed" (6).

Cc: Ian Jackson <ian.jackson@eu.citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Signed-off-by: Roger Pau Monne <roger.pau@citrix.com>
---
 tools/libxl/libxl_device.c |   59 ++++++++++++++++++++++++++-----------------
 1 files changed, 36 insertions(+), 23 deletions(-)

diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index 3da60e1..d33ac68 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -451,33 +451,48 @@ int libxl__initiate_device_remove(libxl__egc *egc, libxl__ao *ao,
                                   libxl__device *dev)
 {
     AO_GC;
-    libxl_ctx *ctx = libxl__gc_owner(gc);
-    xs_transaction_t t;
+    xs_transaction_t t = 0;
     char *be_path = libxl__device_backend_path(gc, dev);
     char *state_path = libxl__sprintf(gc, "%s/state", be_path);
-    char *state = libxl__xs_read(gc, XBT_NULL, state_path);
+    char *online_path = GCSPRINTF("%s/online", be_path);
+    const char *state;
+
     int rc = 0;
     libxl__ao_device_remove *aorm = 0;
 
-    if (!state)
-        goto out_ok;
-    if (atoi(state) != 4) {
-        libxl__device_destroy_tapdisk(gc, be_path);
-        xs_rm(ctx->xsh, XBT_NULL, be_path);
-        goto out_ok;
-    }
+    for (;;) {
+        rc = libxl__xs_transaction_start(gc, &t);
+        if (rc) {
+            LOG(ERROR, "unable to start transaction");
+            goto out_fail;
+        }
 
-retry_transaction:
-    t = xs_transaction_start(ctx->xsh);
-    xs_write(ctx->xsh, t, libxl__sprintf(gc, "%s/online", be_path), "0", strlen("0"));
-    xs_write(ctx->xsh, t, state_path, "5", strlen("5"));
-    if (!xs_transaction_end(ctx->xsh, t, 0)) {
-        if (errno == EAGAIN)
-            goto retry_transaction;
-        else {
-            rc = ERROR_FAIL;
+        rc = libxl__xs_read_checked(gc, t, state_path, &state);
+        if (rc) {
+            LOG(ERROR, "unable to read device state from path %s", state_path);
             goto out_fail;
         }
+
+        /*
+         * Check if device is already in "closed" state, in which case
+         * it should not be changed.
+         */
+         if (state && atoi(state) != XenbusStateClosed) {
+            rc = libxl__xs_write_checked(gc, t, online_path, "0");
+            if (rc) {
+                LOG(ERROR, "unable to write to xenstore path %s", online_path);
+                goto out_fail;
+            }
+            rc = libxl__xs_write_checked(gc, t, state_path, "5");
+            if (rc) {
+                LOG(ERROR, "unable to write to xenstore path %s", state_path);
+                goto out_fail;
+            }
+        }
+
+        rc = libxl__xs_transaction_commit(gc, &t);
+        if (!rc) break;
+        if (rc < 0) goto out_fail;
     }
 
     libxl__device_destroy_tapdisk(gc, be_path);
@@ -491,16 +506,14 @@ retry_transaction:
                                  LIBXL_DESTROY_TIMEOUT * 1000);
     if (rc) goto out_fail;
 
+    libxl__ao_complete(egc, ao, 0);
     return 0;
 
  out_fail:
     assert(rc);
+    libxl__xs_transaction_abort(gc, &t);
     device_remove_cleanup(gc, aorm);
     return rc;
-
- out_ok:
-    libxl__ao_complete(egc, ao, 0);
-    return 0;
 }
 
 static void device_remove_callback(libxl__egc *egc, libxl__ev_devstate *ds,
-- 
1.7.7.5 (Apple Git-26)

  reply	other threads:[~2012-07-20 14:12 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-20 14:12 [PATCH v10 01/19] execute hotplug scripts from libxl v10 Roger Pau Monne
2012-07-20 14:12 ` Roger Pau Monne [this message]
2012-07-20 14:12 ` [PATCH v10 02/19] libxl: change ao_device_remove to ao_device Roger Pau Monne
2012-07-20 16:35   ` Ian Jackson
2012-07-20 14:12 ` [PATCH v10 03/19] libxl: move device model creation prototypes Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 04/19] libxl: convert libxl_domain_destroy to an async op Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 05/19] libxl: move bootloader data strucutres and prototypes Roger Pau Monne
2012-07-20 17:21   ` Ian Jackson
2012-07-20 14:12 ` [PATCH v10 06/19] libxl: refactor disk addition to take a helper Roger Pau Monne
2012-07-20 17:24   ` Ian Jackson
2012-07-20 14:12 ` [PATCH v10 07/19] libxl: convert libxl__device_disk_local_attach to an async op Roger Pau Monne
2012-07-20 18:03   ` Ian Jackson
2012-07-23 11:32     ` Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 08/19] libxl: rename vifs to nics Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 09/19] libxl: convert libxl_device_disk_add to an async op Roger Pau Monne
2012-07-20 18:04   ` Ian Jackson
2012-07-20 14:12 ` [PATCH v10 10/19] libxl: convert libxl_device_nic_add to an async operation Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 11/19] libxl: add option to choose who executes hotplug scripts Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 12/19] libxl: rename _IOEMU nic type to VIF_IOEMU Roger Pau Monne
2012-07-20 16:34   ` Ian Campbell
2012-07-20 16:39     ` Ian Campbell
2012-07-20 14:12 ` [PATCH v10 13/19] libxl: set correct nic type depending on the guest Roger Pau Monne
2012-07-20 18:06   ` Ian Jackson
2012-07-20 14:12 ` [PATCH v10 14/19] libxl: use libxl__xs_path_cleanup on device_destroy Roger Pau Monne
2012-07-20 15:38   ` Ian Campbell
2012-07-20 14:12 ` [PATCH v10 15/19] libxl: call hotplug scripts for disk devices from libxl Roger Pau Monne
2012-07-20 15:20   ` Ian Campbell
2012-07-20 14:12 ` [PATCH v10 16/19] libxl: call hotplug scripts for nic " Roger Pau Monne
2012-07-20 16:01   ` Ian Campbell
2012-07-20 16:12     ` Ian Campbell
2012-07-20 16:36     ` Ian Campbell
2012-07-23  9:22     ` Roger Pau Monne
2012-07-20 16:03   ` Ian Campbell
2012-07-20 14:12 ` [PATCH v10 17/19] libxl: convert libxl_device_vkb_add to an async operation Roger Pau Monne
2012-07-20 18:08   ` Ian Jackson
2012-07-23  8:58     ` Roger Pau Monne
2012-07-23  9:26       ` Ian Campbell
2012-07-23 11:44       ` Ian Jackson
2012-07-20 14:12 ` [PATCH v10 18/19] libxl: convert libxl_device_vfb_add " Roger Pau Monne
2012-07-20 18:11   ` Ian Jackson
2012-07-23 11:58     ` Roger Pau Monne
2012-07-20 14:12 ` [PATCH v10 19/19] xl: main_blockdetach don't call destroy if remove succeeds Roger Pau Monne
2012-07-20 14:55   ` Ian Campbell
2012-07-23 12:17 ` [PATCH v10 01/19] execute hotplug scripts from libxl v10 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=1342793548-10239-2-git-send-email-roger.pau@citrix.com \
    --to=roger.pau@citrix.com \
    --cc=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).