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.
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: