]> 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>
Fri, 2 Oct 2009 11:58:56 +0000 (12:58 +0100)
committerSteven Smith <ssmith@weybridge.uk.xensource.com>
Fri, 2 Oct 2009 11:58:56 +0000 (12:58 +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 d6b0911abe0cdcc897bc674a8f5baebb25282d28..db9071bb1c8ec8c108333e876142bf9823fdfe83 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: