bitkeeper revision 1.1547 (42945455UNorq1ha3va8g7OVydNVmw)

XendDomain.py:
  Improve error handling.
XendCheckpoint.py:
  Switch restore to use os functions to read from the state file.
  Simplify code.
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
This commit is contained in:
cl349@firebug.cl.cam.ac.uk committed 2005-05-25 10:32:53 +00:00
1 parent 42736be47b
commit 1d006bb235
2 files changed
+81 -84

No files matched your search

+71 -74
View File
@@ -23,15 +23,23 @@ PATH_XC_RESTORE = "/usr/libexec/xen/xc_restore"
sizeof_int = calcsize("i")
sizeof_unsigned_long = calcsize("L")
def write_exact(fd, buf, errmsg):
if os.write(fd, buf) != len(buf):
raise XendError(errmsg)
def read_exact(fd, size, errmsg):
buf = os.read(fd, size)
if len(buf) != size:
raise XendError(errmsg)
return buf
def save(xd, fd, dominfo):
if os.write(fd, SIGNATURE) != len(SIGNATURE):
raise XendError("could not write guest state file: signature")
write_exact(fd, SIGNATURE, "could not write guest state file: signature")
config = sxp.to_string(dominfo.sxpr())
if os.write(fd, pack("!i", len(config))) != sizeof_int:
raise XendError("could not write guest state file: config len")
if os.write(fd, config) != len(config):
raise XendError("could not write guest state file: config")
write_exact(fd, pack("!i", len(config)),
"could not write guest state file: config len")
write_exact(fd, config, "could not write guest state file: config")
cmd = [PATH_XC_SAVE, str(xc.handle()), str(fd),
dominfo.id]
@@ -72,72 +80,61 @@ def save(xd, fd, dominfo):
return None
def restore(xd, fd):
try:
signature = fd.read_exact(len(SIGNATURE),
"not a valid guest state file: signature read")
if signature != SIGNATURE:
raise XendError("not a valid guest state file: found '%s'" %
signature)
l = fd.read_exact(sizeof_int,
"not a valid guest state file: config size read")
vmconfig_size = unpack("!i", l)[0]
vmconfig_buf = fd.read_exact(vmconfig_size,
"not a valid guest state file: config read")
p = sxp.Parser()
p.input(vmconfig_buf)
if not p.ready:
raise XendError("not a valid guest state file: config parse")
vmconfig = p.get_val()
dominfo = xd.domain_configure(vmconfig)
l = fd.read_exact(sizeof_unsigned_long,
"not a valid guest state file: pfn count read")
nr_pfns = unpack("=L", l)[0] # XXX endianess
if nr_pfns > 1024*1024: # XXX
raise XendError(
"not a valid guest state file: pfn count out of range")
# XXXcl hack: fd.tell will sync up the object and
# underlying file descriptor
ignore = fd.tell()
cmd = [PATH_XC_RESTORE, str(xc.handle()), str(fd.fileno()),
dominfo.id, str(nr_pfns)]
log.info("[xc_restore] " + join(cmd))
child = xPopen3(cmd, True, -1, [fd.fileno(), xc.handle()])
child.tochild.close()
lasterr = ""
p = select.poll()
p.register(child.fromchild.fileno())
p.register(child.childerr.fileno())
while True:
r = p.poll()
for (fd, event) in r:
if not event & select.POLLIN:
continue
if fd == child.childerr.fileno():
l = child.childerr.readline()
log.error(l.rstrip())
lasterr = l.rstrip()
if fd == child.fromchild.fileno():
l = child.fromchild.readline()
log.info(l.rstrip())
if filter(lambda (fd, event): event & select.POLLHUP, r):
break
if child.wait() >> 8 == 127:
lasterr = "popen %s failed" % PATH_XC_RESTORE
if child.wait() != 0:
raise XendError("xc_restore failed: %s" % lasterr)
return dominfo
signature = read_exact(fd, len(SIGNATURE),
"not a valid guest state file: signature read")
if signature != SIGNATURE:
raise XendError("not a valid guest state file: found '%s'" %
signature)
except IOError, ex:
if ex.errno == errno.ENOENT:
raise XendError("can't open guest state file %s" % src)
else:
raise
l = read_exact(fd, sizeof_int,
"not a valid guest state file: config size read")
vmconfig_size = unpack("!i", l)[0]
vmconfig_buf = read_exact(fd, vmconfig_size,
"not a valid guest state file: config read")
p = sxp.Parser()
p.input(vmconfig_buf)
if not p.ready:
raise XendError("not a valid guest state file: config parse")
vmconfig = p.get_val()
dominfo = xd.domain_configure(vmconfig)
l = read_exact(fd, sizeof_unsigned_long,
"not a valid guest state file: pfn count read")
nr_pfns = unpack("=L", l)[0] # XXX endianess
if nr_pfns > 1024*1024: # XXX
raise XendError(
"not a valid guest state file: pfn count out of range")
cmd = [PATH_XC_RESTORE, str(xc.handle()), str(fd),
dominfo.id, str(nr_pfns)]
log.info("[xc_restore] " + join(cmd))
child = xPopen3(cmd, True, -1, [fd, xc.handle()])
child.tochild.close()
lasterr = ""
p = select.poll()
p.register(child.fromchild.fileno())
p.register(child.childerr.fileno())
while True:
r = p.poll()
for (fd, event) in r:
if not event & select.POLLIN:
continue
if fd == child.childerr.fileno():
l = child.childerr.readline()
log.error(l.rstrip())
lasterr = l.rstrip()
if fd == child.fromchild.fileno():
l = child.fromchild.readline()
log.info(l.rstrip())
if filter(lambda (fd, event): event & select.POLLHUP, r):
break
if child.wait() >> 8 == 127:
lasterr = "popen %s failed" % PATH_XC_RESTORE
if child.wait() != 0:
raise XendError("xc_restore failed: %s" % lasterr)
return dominfo
+10 -10
View File
@@ -5,6 +5,7 @@
Nothing here is persistent (across reboots).
Needs to be persistent for one uptime.
"""
import errno
import os
import scheduler
import sys
@@ -323,16 +324,14 @@ class XendDomain:
@param progress: output progress if true
"""
class XendFile(file):
def read_exact(self, size, error_msg):
buf = self.read(size)
if len(buf) != size:
raise XendError(error_msg)
return buf
try:
fd = os.open(src, os.O_RDONLY)
fd = XendFile(src, 'rb')
return XendCheckpoint.restore(self, fd)
return XendCheckpoint.restore(self, fd)
except OSError, ex:
raise XendError("can't read guest state file %s: %s" %
(src, ex[1]))
def domain_get(self, id):
"""Get up-to-date info about a domain.
@@ -530,8 +529,9 @@ class XendDomain:
return XendCheckpoint.save(self, fd, dominfo)
except:
raise
except OSError, ex:
raise XendError("can't write guest state file %s: %s" %
(dst, ex[1]))
def domain_pincpu(self, id, vcpu, cpumap):
"""Set which cpus vcpu can use
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.