/bugzilla3/ Bug 1680 – Xend fails to start if /var/lib/xend/state/*.xml are empty
Bug 1680 - Xend fails to start if /var/lib/xend/state/*.xml are empty
: Xend fails to start if /var/lib/xend/state/*.xml are empty
Status: RESOLVED FIXED
Product: Xen
Tools
: unstable
: Other Linux
: P2 normal
Assigned To: Xen Bug List
:
:
:
  Show dependency treegraph
 
Reported: 2010-11-02 23:26 CDT by Anthony Low
Modified: 2011-11-03 10:35 CDT (History)
0 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anthony Low 2010-11-02 23:26:02 CDT
When attempting to start Xend, an ExpatError will be thrown if any of
/var/lib/xend/state/*.xml are empty.

Steps to reproduce:
    1. Stop Xend
    2. Truncate a /var/lib/xend/state/*.xml file to 0 bytes
    3. Start Xend

Actual results:
    An ExpatError is thrown

Expected results:
    Xend starts

Build information:
    Xend changeset: Wed Aug 25 09:22:42 2010 +0100 21324:b536ebfba183.
    Python 2.6.6 (r266:84292, Nov  3 2010, 03:49:31)
    Gentoo Linux (x86_64)



Fix:

The problem is at xen/xend/XendStateStore.py:101:

        if not os.path.exists(xml_path):
            return {}

        dom = minidom.parse(xml_path)

The code checks that the file exists, but minidom.parse() can still fail with
an ExpatError if the file is empty. A quick fix could be to add after exists()
check (untested, maybe the file needs to be removed for later code to recreate
it?):

        if os.path.getsize(xml_path) == 0:
            return {}

but perhaps a more thorough solution that catches invalid XML files might be
more appropriate.



xend.log excerpt:

[2010-11-03 05:34:57 2565] INFO (SrvDaemon:332) Xend Daemon started
[2010-11-03 05:34:57 2565] INFO (SrvDaemon:336) Xend changeset: Wed Aug 25
09:22:42 2010 +0100 21324:b536ebfba183.
[2010-11-03 05:34:57 2565] ERROR (SrvDaemon:349) Exception starting xend (no
element found: line 1, column 0)
Traceback (most recent call last):
  File "/usr/lib64/python2.6/site-packages/xen/xend/server/SrvDaemon.py", line
341, in run
    servers = SrvServer.create()
  File "/usr/lib64/python2.6/site-packages/xen/xend/server/SrvServer.py", line
251, in create
    root.putChild('xend', SrvRoot())
  File "/usr/lib64/python2.6/site-packages/xen/xend/server/SrvRoot.py", line
40, in __init__
    self.get(name)
  File "/usr/lib64/python2.6/site-packages/xen/web/SrvDir.py", line 84, in get
    val = val.getobj()
  File "/usr/lib64/python2.6/site-packages/xen/web/SrvDir.py", line 52, in
getobj
    self.obj = klassobj()
  File "/usr/lib64/python2.6/site-packages/xen/xend/server/SrvNode.py", line
30, in __init__
    self.xn = XendNode.instance()
  File "/usr/lib64/python2.6/site-packages/xen/xend/XendNode.py", line 1140, in
instance
    inst = XendNode()
  File "/usr/lib64/python2.6/site-packages/xen/xend/XendNode.py", line 70, in
__init__
    saved_host = self.state_store.load_state('host')
Comment 1 Konrad Rzeszutek Wilk 2011-11-03 09:01:54 CDT
Reproduced under Fedora Core 16.
Comment 2 Konrad Rzeszutek Wilk 2011-11-03 10:35:45 CDT
Patch posted on xen-devel
http://lists.xensource.com/archives/html/xen-devel/2011-11/msg00218.html