[Xen-devel] [PATCH][ioemu] in xenstore_process_dm_command_event(), xs_rm the command node after we read it.

Cui, Dexuan
Tue, 16 Jun 2009 18:28:05 -0000

As Ian Jackson pointed out: "when we start processing a command we should
delete it from xenstore immediately, so that future watch triggerings either
don''t see the command or actually see genuine new invocations".

The patch is used to overcome a race condition that occurs after changeset
19679: ec2bc4b9fa32 (xend: hot-plug PCI devices at boot-time) and could break
the device assignment of hvm guest:
ioemu''s xs_watch() fires the ''command'' for the 1st
time and xend''s signalDeviceModel(''pci-ins'',...)
fires it for the 2nd time -- without the patch, the 2nd time watch handling
would try to invoke xenstore_process_dm_command_event() again and since the
''parameter'' node has been changed to hold vslot by ioemu, the
second time would fail and set ''parameter'' to "no free
hotplug slots" at the end of the 2nd handling;  and, if xend runs slower,
xend would treat the ''parameter'' of the 2nd time as that of
the 1st time and destroy the guest.

Signed-off-by: Dexuan Cui <dexuan.cui@intel.com>

diff --git a/xenstore.c b/xenstore.c
index d2f38d2..0618c80 100644
--- a/xenstore.c
+++ b/xenstore.c
@@ -756,6 +756,9 @@ static void xenstore_process_dm_command_event(void)
     if (!command)
         goto out;

+    if (!xs_rm(xsh, XBT_NULL, path))
+        fprintf(logfile, "xs_rm failed: path=%s\n", path);
+
     if (!strncmp(command, "save", len)) {
         fprintf(logfile, "dm-command: pause and save state\n");
         xen_pause_requested = 1;