ia64/xen-unstable

changeset 16323:468a30d74bd6

xenstored: Recover from corrupt tdb on reboot

Xen cannot work when xenstored's tdb is corrupt. When that happens
somehow (and we've seen it happen), even reboot doesn't recover from
it. It could: there is no state in tdb that needs to be persisted
across reboots.

This patch arranges that tdb is removed before xenstored is started,
provided it doesn't already run. This is safe, because:

* xenstored cannot be restarted. If it dies, Xen's screwed until
reboot.

* /usr/sbin/xend always starts xenstored anyway.

* xenstored locks its pid-file (see write_pidfile() in
tools/xenstore/xenstored_core.c), and refuses to start when it
can't.

* My patch makes /usr/sbin/xend remove tdb iff it can lock the
pid-file. In other words, it removes tdb only when xenstored is not
running, and locks it out until it is done.

Bonus fix: it also removes stale copies of the tdb xenstored tends
to leave behind when it exits uncleanly.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
author Keir Fraser <keir@xensource.com>
date Tue Nov 06 09:40:44 2007 +0000 (2007-11-06)
parents ed20c4232e16
children e2445c775efc
files tools/misc/xend
line diff
     1.1 --- a/tools/misc/xend	Tue Nov 06 09:39:25 2007 +0000
     1.2 +++ b/tools/misc/xend	Tue Nov 06 09:40:44 2007 +0000
     1.3 @@ -23,6 +23,8 @@
     1.4     On Solaris, the daemons are SMF managed, and you should not attempt
     1.5     to start xend by hand.
     1.6  """
     1.7 +import fcntl
     1.8 +import glob
     1.9  import os
    1.10  import os.path
    1.11  import sys
    1.12 @@ -76,6 +78,23 @@ def check_user():
    1.13          raise CheckError("invalid user")
    1.14  
    1.15  def start_xenstored():
    1.16 +    pidfname = "/var/run/xenstore.pid"
    1.17 +    try:
    1.18 +        f = open(pidfname, "a")
    1.19 +        try:
    1.20 +            fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
    1.21 +            rootdir = os.getenv("XENSTORED_ROOTDIR") or "/var/lib/xenstored"
    1.22 +            for i in glob.glob(rootdir + "/tdb*"):
    1.23 +                try:
    1.24 +                    os.unlink(i)
    1.25 +                except:
    1.26 +                    pass
    1.27 +            os.unlink(pidfname)
    1.28 +        except:
    1.29 +            pass
    1.30 +        f.close()
    1.31 +    except:
    1.32 +        pass
    1.33      XENSTORED_TRACE = os.getenv("XENSTORED_TRACE")
    1.34      cmd = "xenstored --pid-file /var/run/xenstore.pid"
    1.35      if XENSTORED_TRACE: