[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] xend: Fix race in vfb/vkbd device setup.

# HG changeset patch
# User kfraser@xxxxxxxxxxxxxxxxxxxxx
# Date 1177490660 -3600
# Node ID 8ca89a9e54a7973e36787878b1fddab436bf003f
# Parent  4677ee247aa9a94ddf787077be12e022a38dd99f
xend: Fix race in vfb/vkbd device setup.

 1. XendDomainInfo._createDevices() gets a list of devices to be
    created from XendConfig.ordered_device_refs().
    On a simple guest, this has 4 devices, vfb, vbd, vif, vkbd - in
    that order.

 2. It iterates over those devices, creating the appropriate
    DevController subclass instance, and then calling createDevice()
    on that object.

 3. When createDevice() is called on the vfb  device, it spawns
    xen-vncfb daemon.

 4. During startup xen-vncfb writes into the backend paths

 5. When createDevice() is called on the vkbd device in XenD, if the
    2nd xenstore path write from step 4 has occurred, then you'll hit
    the 'Device 0 (vkbd) is already connected' error. If the 2nd path
    write didn't complete yet then everything is fine.

I think the reason it often works once after boot is that loading
xen-vncfb from disk the first time around is just enough of a slow
down to ensure step 5 occurs before the 2nd xenstore write in step 4
has occurred.

The key seems to be to ensure the vkbd device is initialized in
xenstore before the vfb device - this ensures all the xenstored setup
from XenD is complete before the xen-vncfb daemon starts. I'm now able
to create & destroy a domain many times over with this patch & never
hit the error message any more.

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
 tools/python/xen/xend/XendConfig.py |   19 +++++++++++++++----
 1 files changed, 15 insertions(+), 4 deletions(-)

diff -r 4677ee247aa9 -r 8ca89a9e54a7 tools/python/xen/xend/XendConfig.py
--- a/tools/python/xen/xend/XendConfig.py       Wed Apr 25 09:40:02 2007 +0100
+++ b/tools/python/xen/xend/XendConfig.py       Wed Apr 25 09:44:20 2007 +0100
@@ -1278,10 +1278,21 @@ class XendConfig(dict):
         return sxpr
     def ordered_device_refs(self):
-        result = (self['console_refs'] +
-                  self['vbd_refs'] +
-                  self['vif_refs'] +
-                  self['vtpm_refs'])
+        result = []
+        # vkbd devices *must* be before vfb devices, otherwise
+        # there is a race condition when setting up devices
+        # where the daemon spawned for the vfb may write stuff
+        # into xenstore vkbd backend, before DevController has
+        # setup permissions on the vkbd backend path. This race
+        # results in domain creation failing with 'device already
+        # connected' messages
+        result.extend([u for u in self['devices'].keys() if 
self['devices'][u][0] == 'vkbd'])
+        result.extend(self['console_refs'] +
+                      self['vbd_refs'] +
+                      self['vif_refs'] +
+                      self['vtpm_refs'])
         result.extend([u for u in self['devices'].keys() if u not in result])
         return result

Xen-changelog mailing list



Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.