From: "Daniel P. Berrange" Subject: PATCH: Re: Error: Device 0 (vkbd) is already connected. Date: Tue, 24 Apr 2007 23:47:26 +0100 Message-ID: <20070424224726.GB31537@redhat.com> References: <1176327139.6776.10.camel@lappy> Reply-To: "Daniel P. Berrange" Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="3V7upXqbjpZ4EhLz" Return-path: Content-Disposition: inline In-Reply-To: <1176327139.6776.10.camel@lappy> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: Alex Williamson Cc: xen-devel List-Id: xen-devel@lists.xenproject.org --3V7upXqbjpZ4EhLz Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Apr 11, 2007 at 03:32:19PM -0600, Alex Williamson wrote: > Hi, > > Is vfb working well lately? I thought I'd test it out on ia64 and it > works great, but only once per boot. If I stop the domain and restart > it, I get the following: > > Error: Device 0 (vkbd) is already connected. > > To make sure this isn't an ia64 anomaly, I tried it on an x86_64 system. > Same thing, works the first time, reboot the domain and it's broken. I > see someone reported a similar issue last month, but there was no > response: > > http://lists.xensource.com/archives/html/xen-devel/2007-03/msg01141.html > > The backtrace in xend.log looks like this: > > [2007-04-11 15:23:07 2659] ERROR (__init__:1072) XendDomainInfo.initDomain: exce > ption occurred > Traceback (most recent call last): > File "//usr/lib/python/xen/xend/XendDomainInfo.py", line 1518, in _initDomain > self._createDevices() > File "//usr/lib/python/xen/xend/XendDomainInfo.py", line 1316, in _createDevices > devid = self._createDevice(devclass, config) > File "//usr/lib/python/xen/xend/XendDomainInfo.py", line 1292, in _createDevice > return self.getDeviceController(deviceClass).createDevice(devConfig) > File "//usr/lib/python/xen/xend/server/DevController.py", line 111, in createDevice > raise VmError("Device %s is already connected." % dev_str) > VmError: Device 0 (vkbd) is already connected. > > My domain config file has the following options to enable vfb: > > vfb = [ 'type=vnc, vnclisten=0.0.0.0, vncunused=1' ] > extra = "console=ttyS0 xencons=ttyS video=xenfb" > > Is anyone able to make this work reliably more than once? Thanks, I've done some testing & this is (reasonably) reproducable on x86 too. On some occassions I can't even get it to start once, other times it works a couple of times. After some debugging I think I've identified a race condition: 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 attaching a patch which implements this - I've been able to create & destroy a domain many times over with this patch & never hit the error message anymore. Signed-off-by: Daniel P. Berrange Regards, Dan. -- |=- Red Hat, Engineering, Emerging Technologies, Boston. +1 978 392 2496 -=| |=- Perl modules: http://search.cpan.org/~danberr/ -=| |=- Projects: http://freshmeat.net/~danielpb/ -=| |=- GnuPG: 7D3B9505 F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 -=| --3V7upXqbjpZ4EhLz Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="xen-vkbd-order.patch" --- tools/python/xen/xend/XendConfig.py 2007-04-24 14:35:27.000000000 -0400 +++ /usr/lib64/python2.5/site-packages/xen/xend/XendConfig.py 2007-04-24 18:48:52.000000000 -0400 @@ -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 --3V7upXqbjpZ4EhLz Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel --3V7upXqbjpZ4EhLz--