xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Roger Pau Monne <roger.pau@entel.upc.edu>
To: xen-devel@lists.xensource.com
Subject: [PATCH 01 of 29 RFC] libxl: Atomicaly check backend state and set it to 5 at device_remove
Date: Thu, 02 Feb 2012 14:26:36 +0100	[thread overview]
Message-ID: <e38c059da393c3fa2ee2.1328189196@debian.localdomain> (raw)
In-Reply-To: <patchbomb.1328189195@debian.localdomain>

# HG changeset patch
# User Roger Pau Monne <roger.pau@entel.upc.edu>
# Date 1326548456 -3600
# Node ID e38c059da393c3fa2ee222d2e90275ca88b85d4f
# Parent  e2722b24dc0962de37215320b05d1bb7c4c42864
libxl: Atomicaly check backend state and set it to 5 at device_remove

libxl__device_remove was setting backend state to 5, which could
create a race condition, since the previous check for state != 4 and
setting state to 5 was not done inside the same transaction, so the
kernel could change the state to 6 in the space between the check for
state != 4 and setting it to 5.

The state != 4 check and setting it to 5 should happen in the same
transaction, to assure that nobody is modifying it behind our back.

Changes since v1:

 * Do the check and set in the same transaction, instead of removing
   the set state to 5.

Signed-off-by: Roger Pau Monne <roger.pau@entel.upc.edu>

diff -r e2722b24dc09 -r e38c059da393 tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c	Thu Jan 26 17:43:31 2012 +0000
+++ b/tools/libxl/libxl_device.c	Sat Jan 14 14:40:56 2012 +0100
@@ -433,19 +433,23 @@ int libxl__device_remove(libxl__gc *gc, 
     xs_transaction_t t;
     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 *state;
     int rc = 0;
 
-    if (!state)
+retry_transaction:
+    t = xs_transaction_start(ctx->xsh);
+    state = libxl__xs_read(gc, t, state_path);
+    if (!state) {
+        xs_transaction_end(ctx->xsh, t, 0);
         goto out;
+    }
     if (atoi(state) != 4) {
+        xs_transaction_end(ctx->xsh, t, 0);
         libxl__device_destroy_tapdisk(gc, be_path);
         xs_rm(ctx->xsh, XBT_NULL, be_path);
         goto out;
     }
 
-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)) {

  reply	other threads:[~2012-02-02 13:26 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-02 13:26 [PATCH 00 of 29 RFC] libxl: move device plug/unplug to a separate daemon Roger Pau Monne
2012-02-02 13:26 ` Roger Pau Monne [this message]
2012-02-02 13:26 ` [PATCH 02 of 29 RFC] hotplug/block: get the type of block device from file path (NetBSD) Roger Pau Monne
2012-02-02 13:26 ` [PATCH 03 of 29 RFC] libxl: allow libxl__exec to take a parameter containing the env variables Roger Pau Monne
2012-02-02 13:26 ` [PATCH 04 of 29 RFC] libxl: add libxl__forkexec function to libxl_exec Roger Pau Monne
2012-02-02 13:26 ` [PATCH 05 of 29 RFC] libxl: wait for devices to initialize upon addition to the domain Roger Pau Monne
2012-02-02 13:26 ` [PATCH 06 of 29 RFC] hotplug NetBSD: pass an action instead of a state to hotplug scripts Roger Pau Monne
2012-02-02 13:26 ` [PATCH 07 of 29 RFC] libxl: perform xenstore device cleanup from libxl Roger Pau Monne
2012-02-02 13:26 ` [PATCH 08 of 29 RFC] libxl: remove force parameter from libxl__device_remove Roger Pau Monne
2012-02-02 13:26 ` [PATCH 09 of 29 RFC] libxl: add better error checking on libxl__device_remove Roger Pau Monne
2012-02-02 13:26 ` [PATCH 10 of 29 RFC] libxl: destroy devices before device model Roger Pau Monne
2012-02-02 13:26 ` [PATCH 11 of 29 RFC] libxl: execute hotplug scripts directly from libxl Roger Pau Monne
2012-02-02 13:26 ` [PATCH 12 of 29 RFC] libxl: add hotplug script calling for NetBSD Roger Pau Monne
2012-02-02 13:26 ` [PATCH 13 of 29 RFC] libxl: add hotplug script calls for Linux Roger Pau Monne
2012-02-07  7:02   ` Shriram Rajagopalan
2012-02-07  9:04     ` Roger Pau Monné
2012-02-02 13:26 ` [PATCH 14 of 29 RFC] rc.d NetBSD: don't start xenbackendd by default, only when xend needs it Roger Pau Monne
2012-02-02 13:26 ` [PATCH 15 of 29 RFC] NetBSD/xencommons: remove xend precmd folder creation Roger Pau Monne
2012-02-09 15:34   ` Ian Jackson
2012-02-02 13:26 ` [PATCH 16 of 29 RFC] libxl: introduce libxl__device_hotplug_path Roger Pau Monne
2012-02-02 13:26 ` [PATCH 17 of 29 RFC] libxl: add enum with possible hotplug state Roger Pau Monne
2012-02-02 13:26 ` [PATCH 18 of 29 RFC] libxl: introduce libxl__device_generic_hotplug_add Roger Pau Monne
2012-02-02 13:26 ` [PATCH 19 of 29 RFC] libxl: add libxl__device_hotplug_disconnect Roger Pau Monne
2012-02-02 13:26 ` [PATCH 20 of 29 RFC] libxl: introduce libxl hotplug public API functions Roger Pau Monne
2012-02-08 16:42   ` Ian Jackson
2012-02-09 10:02     ` Stefano Stabellini
2012-02-09 15:22       ` Ian Jackson
2012-02-09 15:32         ` Stefano Stabellini
2012-02-09 15:33           ` Ian Jackson
2012-02-09 15:43             ` Stefano Stabellini
2012-02-09 15:41               ` Ian Jackson
2012-02-09 15:49           ` Ian Campbell
2012-02-09 16:00             ` Stefano Stabellini
2012-02-09 16:01               ` Ian Campbell
2012-02-09 16:18                 ` Stefano Stabellini
2012-02-09 16:40                   ` Ian Campbell
2012-02-09 17:28                     ` Stefano Stabellini
2012-02-14 14:38                     ` Roger Pau Monné
2012-02-14 14:23     ` Roger Pau Monné
2012-02-14 15:48       ` Ian Campbell
2012-02-20 18:52         ` Ian Jackson
2012-02-20 18:55           ` Ian Jackson
2012-02-21 11:04             ` Ian Campbell
2012-02-21 10:38         ` Stefano Stabellini
2012-02-21 16:42           ` Ian Jackson
2012-02-21 17:02             ` Ian Campbell
2012-02-08 16:42   ` Ian Jackson
2012-02-14 14:25     ` Roger Pau Monné
2012-02-02 13:26 ` [PATCH 21 of 29 RFC] libxl: add libxl__parse_hotplug_path Roger Pau Monne
2012-02-02 13:26 ` [PATCH 22 of 29 RFC] libxl: add libxl__parse_disk_hotplug_path Roger Pau Monne
2012-02-02 13:26 ` [PATCH 23 of 29 RFC] libxl: add libxl__parse_nic_hotplug_path Roger Pau Monne
2012-02-08 16:43   ` Ian Jackson
2012-02-02 13:26 ` [PATCH 24 of 29 RFC] libxl: add libxl_setup_hotplug_listener Roger Pau Monne
2012-02-02 13:27 ` [PATCH 25 of 29 RFC] libxl: add libxl_hotplug_dispatch Roger Pau Monne
2012-02-02 18:37   ` Stefano Stabellini
2012-02-02 18:45     ` Roger Pau Monné
2012-02-09 10:03       ` Stefano Stabellini
2012-02-02 13:27 ` [PATCH 26 of 29 RFC] xldeviced: new daemon to execute hotplug scripts Roger Pau Monne
2012-02-02 13:27 ` [PATCH 27 of 29 RFC] init: updated Linux and NetBSD init scripts to launch xldeviced Roger Pau Monne
2012-02-02 13:27 ` [PATCH 28 of 29 RFC] libxl: add libxl__find_free_vdev Roger Pau Monne
2012-02-09 15:40   ` Ian Jackson
2012-02-14 13:36     ` Roger Pau Monné
2012-02-15 17:18       ` Ian Jackson
2012-02-16  8:53         ` Roger Pau Monné
2012-02-02 13:27 ` [PATCH 29 of 29 RFC] libxl: delegate plug/unplug of disk and nic devices to xldeviced Roger Pau Monne
2012-02-09 15:43   ` Ian Jackson
2012-02-14 14:05     ` Roger Pau Monné
2012-02-17 15:45       ` Ian Jackson
2012-02-03 14:06 ` [PATCH 00 of 29 RFC] libxl: move device plug/unplug to a separate daemon Roger Pau Monné

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=e38c059da393c3fa2ee2.1328189196@debian.localdomain \
    --to=roger.pau@entel.upc.edu \
    --cc=xen-devel@lists.xensource.com \
    /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).