]> xenbits.xensource.com Git - people/ssmith/nc2-2.6.27.git/commitdiff
CA-27974: Fix blktap shutdown race due to improper event ordering.
authorSteven Smith <ssmith@weybridge.uk.xensource.com>
Tue, 30 Jun 2009 11:55:47 +0000 (12:55 +0100)
committerSteven Smith <ssmith@weybridge.uk.xensource.com>
Tue, 30 Jun 2009 11:55:47 +0000 (12:55 +0100)
Writing shutdown-done before switching device state to closed (6)
opens a remarkably small race window to fall through: The agent
removes the device directory just before the write to the 'state'
field will recreate it again. This in turn leads to xenbus failing to
remove the device, since removal is guided by directory existence.

With shutdown-done and connection state being rather independent,
trivially fixing event ordering to write shutdown-done last appears
safe but mandatory. Comment this tiny detail.

drivers/xen/blktap/xenbus.c

index 28de0f33d8e05f94bcc75ada5cf58e23d4edd61b..7935d0cded1531c151a1cae1eb0492db54600605 100644 (file)
@@ -309,14 +309,18 @@ static void signal_shutdown(struct backend_info *be)
        if (be->blkif)
                disassociate_blkif(be->blkif->domid, be->xenbus_id);
 
+       if (be->dev)
+               xenbus_switch_state(be->dev, XenbusStateClosed);
+
+       /* NB. shutdown-done goes last: it triggers our deletion by
+          the agent. any later write would risk recreating the
+          xenstore directory, racing against xenbus. */
+
        err = xenbus_write(XBT_NIL, be->nodename, "shutdown-done", "");
        if (err)
                WPRINTK("Error writing shutdown-done for %s: %d\n", 
                        be->nodename, err);
 
-       if (be->dev)
-               xenbus_switch_state(be->dev, XenbusStateClosed);
-
        be->shutdown_signalled = 1;
 
  out: