ia64/xen-unstable

changeset 14926:8ca89a9e54a7

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
/local/domain/0/backend/vfb/0
And
/local/domain/0/backend/vkbd/0

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@redhat.com>
author kfraser@localhost.localdomain
date Wed Apr 25 09:44:20 2007 +0100 (2007-04-25)
parents 4677ee247aa9
children 23d1ef48e332
files tools/python/xen/xend/XendConfig.py
line diff
     1.1 --- a/tools/python/xen/xend/XendConfig.py	Wed Apr 25 09:40:02 2007 +0100
     1.2 +++ b/tools/python/xen/xend/XendConfig.py	Wed Apr 25 09:44:20 2007 +0100
     1.3 @@ -1278,10 +1278,21 @@ class XendConfig(dict):
     1.4          return sxpr
     1.5  
     1.6      def ordered_device_refs(self):
     1.7 -        result = (self['console_refs'] +
     1.8 -                  self['vbd_refs'] +
     1.9 -                  self['vif_refs'] +
    1.10 -                  self['vtpm_refs'])
    1.11 +        result = []
    1.12 +        # vkbd devices *must* be before vfb devices, otherwise
    1.13 +        # there is a race condition when setting up devices
    1.14 +        # where the daemon spawned for the vfb may write stuff
    1.15 +        # into xenstore vkbd backend, before DevController has
    1.16 +        # setup permissions on the vkbd backend path. This race
    1.17 +        # results in domain creation failing with 'device already
    1.18 +        # connected' messages
    1.19 +        result.extend([u for u in self['devices'].keys() if self['devices'][u][0] == 'vkbd'])
    1.20 +
    1.21 +        result.extend(self['console_refs'] +
    1.22 +                      self['vbd_refs'] +
    1.23 +                      self['vif_refs'] +
    1.24 +                      self['vtpm_refs'])
    1.25 +
    1.26          result.extend([u for u in self['devices'].keys() if u not in result])
    1.27          return result
    1.28