def unlink(self, f): if not f: return try: os.unlink(f) except OSError, ex: log.warning("error removing bootloader file '%s': %s", f, ex)
def destroyXenPaging(self): if self.actmem == "0": return if self.xenpaging_pid: try: os.kill(self.xenpaging_pid, signal.SIGHUP) except OSError, exn: log.exception(exn) for i in xrange(100): try: (p, rv) = os.waitpid(self.xenpaging_pid, os.WNOHANG) if p == self.xenpaging_pid: break except OSError: # This is expected if Xend has been restarted within # the life of this domain. In this case, we can kill # the process, but we can't wait for it because it's # not our child. We continue this loop, and after it is # terminated make really sure the process is going away # (SIGKILL). pass time.sleep(0.1) else: log.warning("xenpaging %d took more than 10s " "to terminate: sending SIGKILL" % self.xenpaging_pid) try: os.kill(self.xenpaging_pid, signal.SIGKILL) os.waitpid(self.xenpaging_pid, 0) except OSError: # This happens if the process doesn't exist. pass
def cleanup_stale_sentinel_fifos(): for path in glob.glob(sentinel_path_prefix + '*.fifo'): if path in sentinel_fifos_inuse: continue try: os.unlink(path) except OSError, e: log.warning('could not delete stale fifo %s: %s', path, utils.exception_string(e))
def vifctl(self, op, vif, vmac): try: fn = self.vifctl_ops[op] return vnet_cmd( [fn, ['vnet', self.id], ['vif', vif], ['vmac', vmac]]) except XendError: log.warning("vifctl failed: op=%s vif=%s mac=%s", op, vif, vmac)
def destroyDeviceModel(self): if self.device_model is None: return if self.pid: self.sentinel_lock.acquire() try: try: os.kill(self.pid, signal.SIGHUP) except OSError, exn: log.exception(exn) try: # Try to reap the child every 100ms for 10s. Then SIGKILL it. for i in xrange(100): (p, rv) = os.waitpid(self.pid, os.WNOHANG) if p == self.pid: break time.sleep(0.1) else: log.warning("DeviceModel %d took more than 10s " "to terminate: sending SIGKILL" % self.pid) os.kill(self.pid, signal.SIGKILL) os.waitpid(self.pid, 0) except OSError, exn: # This is expected if Xend has been restarted within the # life of this domain. In this case, we can kill the process, # but we can't wait for it because it's not our child. # We just make really sure it's going away (SIGKILL) first. os.kill(self.pid, signal.SIGKILL) state = xstransact.Remove("/local/domain/0/device-model/%i" % self.vm.getDomid())
def destroyDeviceModel(self): if self.device_model is None: return self.sentinel_lock.acquire() try: stubdomid = self.vm.getStubdomDomid() if stubdomid is not None : from xen.xend import XendDomain XendDomain.instance().domain_destroy(stubdomid) elif self.pid: try: os.kill(self.pid, signal.SIGHUP) except OSError, exn: log.exception(exn) # Try to reap the child every 100ms for 10s. Then SIGKILL it. for i in xrange(100): try: (p, rv) = os.waitpid(self.pid, os.WNOHANG) if p == self.pid: break except OSError: # This is expected if Xend has been restarted within # the life of this domain. In this case, we can kill # the process, but we can't wait for it because it's # not our child. We continue this loop, and after it is # terminated make really sure the process is going away # (SIGKILL). pass time.sleep(0.1) else: log.warning("DeviceModel %d took more than 10s " "to terminate: sending SIGKILL" % self.pid) try: os.kill(self.pid, signal.SIGKILL) os.waitpid(self.pid, 0) except OSError: # This happens if the process doesn't exist. pass finally: self.pid = None self.sentinel_lock.release() state = xstransact.Remove("/local/domain/0/device-model/%i" % self.vm.getDomid()) try: os.unlink('/var/run/tap/qemu-read-%d' % self.vm.getDomid()) os.unlink('/var/run/tap/qemu-write-%d' % self.vm.getDomid()) except: pass try: del sentinel_fifos_inuse[self.sentinel_path_fifo] os.unlink(self.sentinel_path_fifo) except: pass
def destroyDeviceModel(self): if self.device_model is None: return self.sentinel_lock.acquire() try: stubdomid = self.vm.getStubdomDomid() if stubdomid is not None: from xen.xend import XendDomain XendDomain.instance().domain_destroy(stubdomid) elif self.pid: try: os.kill(self.pid, signal.SIGHUP) except OSError, exn: log.exception(exn) # Try to reap the child every 100ms for 10s. Then SIGKILL it. for i in xrange(100): try: (p, rv) = os.waitpid(self.pid, os.WNOHANG) if p == self.pid: break except OSError: # This is expected if Xend has been restarted within # the life of this domain. In this case, we can kill # the process, but we can't wait for it because it's # not our child. We continue this loop, and after it is # terminated make really sure the process is going away # (SIGKILL). pass time.sleep(0.1) else: log.warning("DeviceModel %d took more than 10s " "to terminate: sending SIGKILL" % self.pid) try: os.kill(self.pid, signal.SIGKILL) os.waitpid(self.pid, 0) except OSError: # This happens if the process doesn't exist. pass finally: self.pid = None self.sentinel_lock.release() state = xstransact.Remove("/local/domain/0/device-model/%i" % self.vm.getDomid()) try: os.unlink('/var/run/tap/qemu-read-%d' % self.vm.getDomid()) os.unlink('/var/run/tap/qemu-write-%d' % self.vm.getDomid()) except: pass try: del sentinel_fifos_inuse[self.sentinel_path_fifo] os.unlink(self.sentinel_path_fifo) except: pass
def __init__(self): # Table of vnet info indexed by vnet id. self.vnet = {} listing = xstransact.List(self.dbpath) for entry in listing: try: info = XendVnetInfo(self.dbpath + '/' + entry) self.vnet[info.id] = info info.configure() except XendError, ex: log.warning("Failed to configure vnet %s: %s", str(info.id), str(ex)) except Exception, ex: log.exception("Vnet error") xstransact.Remove(self.dbpath + '/' + entry)
def createDomain(self): """Build the domain boot image. """ # Set params and call buildDomain(). if self.kernel and not os.path.isfile(self.kernel): raise VmError("Kernel image does not exist: %s" % self.kernel) if self.ramdisk and not os.path.isfile(self.ramdisk): raise VmError("Kernel ramdisk does not exist: %s" % self.ramdisk) if len(self.cmdline) >= MAX_GUEST_CMDLINE: log.warning("kernel cmdline too long, domain %d", self.vm.getDomid()) log.info("buildDomain os=%s dom=%d vcpus=%d", self.ostype, self.vm.getDomid(), self.vm.getVCpuCount()) result = self.buildDomain() if isinstance(result, dict): return result else: raise VmError( "Building domain failed: ostype=%s dom=%d err=%s" % (self.ostype, self.vm.getDomid(), str(result)) )
def createDomain(self): """Build the domain boot image. """ # Set params and call buildDomain(). if self.kernel and not os.path.isfile(self.kernel): raise VmError('Kernel image does not exist: %s' % self.kernel) if self.ramdisk and not os.path.isfile(self.ramdisk): raise VmError('Kernel ramdisk does not exist: %s' % self.ramdisk) if len(self.cmdline) >= MAX_GUEST_CMDLINE: log.warning('kernel cmdline too long, domain %d', self.vm.getDomid()) log.info("buildDomain os=%s dom=%d vcpus=%d", self.ostype, self.vm.getDomid(), self.vm.getVCpuCount()) result = self.buildDomain() if isinstance(result, dict): return result else: raise VmError('Building domain failed: ostype=%s dom=%d err=%s' % (self.ostype, self.vm.getDomid(), str(result)))
def _dmfailed(self, message): log.warning("domain %s: %s", self.vm.getName(), message)
def vifctl(self, op, vif, vmac): try: fn = self.vifctl_ops[op] return vnet_cmd([fn, ['vnet', self.id], ['vif', vif], ['vmac', vmac]]) except XendError: log.warning("vifctl failed: op=%s vif=%s mac=%s", op, vif, vmac)
def _dmfailed(self, message): log.warning("domain %s: %s", self.vm.getName(), message) try: xc.domain_shutdown(self.vm.getDomid(), DOMAIN_CRASH) except: pass