ia64/xen-unstable

view tools/misc/xend @ 19648:f0e2df69a8eb

x86 hvm: Allow cross-vendor migration

Intercept #UD and emulate SYSCALL/SYSENTER/SYSEXIT as necessary.

Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Tue May 26 15:01:36 2009 +0100 (2009-05-26)
parents 0e24e9674ded
children
line source
1 #!/usr/bin/env python
2 # -*- mode: python; -*-
3 #============================================================================
4 # Copyright (C) 2004 Mike Wray <mike.wray@hp.com>
5 # Copyright (C) 2005-2006 XenSource Inc
6 #============================================================================
8 """Xen management daemon.
9 Provides console server and HTTP management api.
11 Run:
12 xend start
14 Restart:
15 xend restart
17 The daemon is stopped with:
18 xend stop
20 The daemon should reconnect to device control interfaces
21 and recover its state when restarted.
23 On Solaris, the daemons are SMF managed, and you should not attempt
24 to start xend by hand.
25 """
26 import fcntl
27 import glob
28 import os
29 import os.path
30 import sys
31 import socket
32 import signal
33 import time
34 import commands
36 from xen.xend.server import SrvDaemon
38 class CheckError(ValueError):
39 pass
41 def hline():
42 print >>sys.stderr, "*" * 70
44 def msg(message):
45 print >>sys.stderr, "*" * 3, message
47 def check_logging():
48 """Check python logging is installed and raise an error if not.
49 Logging is standard from Python 2.3 on.
50 """
51 try:
52 import logging
53 except ImportError:
54 hline()
55 msg("Python logging is not installed.")
56 msg("Use 'make install-logging' at the xen root to install.")
57 msg("")
58 msg("Alternatively download and install from")
59 msg("http://www.red-dove.com/python_logging.html")
60 hline()
61 raise CheckError("logging is not installed")
63 def check_user():
64 """Check that the effective user id is 0 (root).
65 """
66 if os.geteuid() != 0:
67 hline()
68 msg("Xend must be run as root.")
69 hline()
70 raise CheckError("invalid user")
72 def start_daemon(daemon, *args):
73 if os.fork() == 0:
74 os.execvp(daemon, (daemon,) + args)
76 def start_xenstored():
77 pidfname = "/var/run/xenstore.pid"
78 try:
79 f = open(pidfname, "a")
80 try:
81 fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
82 rootdir = os.getenv("XENSTORED_ROOTDIR") or "/var/lib/xenstored"
83 for i in glob.glob(rootdir + "/tdb*"):
84 try:
85 os.unlink(i)
86 except:
87 pass
88 os.unlink(pidfname)
89 except:
90 pass
91 f.close()
92 except:
93 pass
94 XENSTORED_TRACE = os.getenv("XENSTORED_TRACE")
95 cmd = "xenstored --pid-file /var/run/xenstore.pid"
96 if XENSTORED_TRACE:
97 cmd += " -T /var/log/xen/xenstored-trace.log"
98 s,o = commands.getstatusoutput(cmd)
100 def start_consoled():
101 XENCONSOLED_TRACE = os.getenv("XENCONSOLED_TRACE")
102 args = ""
103 if XENCONSOLED_TRACE:
104 args += "--log=" + XENCONSOLED_TRACE
105 start_daemon("xenconsoled", args)
107 def start_blktapctrl():
108 start_daemon("blktapctrl", "")
110 def main():
111 try:
112 check_logging()
113 check_user()
114 except CheckError:
115 sys.exit(1)
117 daemon = SrvDaemon.instance()
118 if not sys.argv[1:]:
119 print 'usage: %s {start|stop|reload|restart}' % sys.argv[0]
120 elif sys.argv[1] == 'start':
121 if os.uname()[0] != "SunOS":
122 start_xenstored()
123 start_consoled()
124 start_blktapctrl()
125 return daemon.start()
126 elif sys.argv[1] == 'trace_start':
127 start_xenstored()
128 start_consoled()
129 start_blktapctrl()
130 return daemon.start(trace=1)
131 elif sys.argv[1] == 'stop':
132 return daemon.stop()
133 elif sys.argv[1] == 'reload':
134 return daemon.reloadConfig()
135 elif sys.argv[1] == 'restart':
136 start_xenstored()
137 start_consoled()
138 start_blktapctrl()
139 return daemon.stop() or daemon.start()
140 elif sys.argv[1] == 'status':
141 return daemon.status()
142 else:
143 print 'not an option:', sys.argv[1]
144 return 1
146 if __name__ == '__main__':
147 sys.exit(main())