[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] XendDomain.py:
ChangeSet 1.1547, 2005/05/25 11:32:53+01:00, cl349@xxxxxxxxxxxxxxxxxxxx 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@xxxxxxxxxxxx> XendCheckpoint.py | 145 ++++++++++++++++++++++++++---------------------------- XendDomain.py | 20 +++---- 2 files changed, 81 insertions(+), 84 deletions(-) diff -Nru a/tools/python/xen/xend/XendCheckpoint.py b/tools/python/xen/xend/XendCheckpoint.py --- a/tools/python/xen/xend/XendCheckpoint.py 2005-05-25 07:02:10 -04:00 +++ b/tools/python/xen/xend/XendCheckpoint.py 2005-05-25 07:02:10 -04:00 @@ -23,15 +23,23 @@ 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 @@ 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) + + 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) - except IOError, ex: - if ex.errno == errno.ENOENT: - raise XendError("can't open guest state file %s" % src) - else: - raise + return dominfo diff -Nru a/tools/python/xen/xend/XendDomain.py b/tools/python/xen/xend/XendDomain.py --- a/tools/python/xen/xend/XendDomain.py 2005-05-25 07:02:10 -04:00 +++ b/tools/python/xen/xend/XendDomain.py 2005-05-25 07:02:10 -04:00 @@ -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 @@ @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 @@ 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 _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |