def destroyDevice(self, devid, force): """Destroy the specified device. @param devid The device ID, or something device-specific from which the device ID can be determined (such as a guest-side device name). The implementation here simply deletes the appropriate paths from the store. This may be overridden by subclasses who need to perform other tasks on destruction. The implementation here accepts integer device IDs or paths containg integer deviceIDs, e.g. vfb/0. Subclasses may accept other values and convert them to integers before passing them here. """ dev = self.convertToDeviceNumber(devid) # Modify online status /before/ updating state (latter is watched by # drivers, so this ordering avoids a race). self.writeBackend(dev, 'online', "0") self.writeBackend(dev, 'state', str(xenbusState['Closing'])) if force: frontpath = self.frontendPath(dev) backpath = self.readVm(dev, "backend") if backpath: xstransact.Remove(backpath) xstransact.Remove(frontpath) # xstransact.Remove(self.devicePath()) ?? Below is the same ? self.vm._removeVm("device/%s/%d" % (self.deviceClass, dev))
def cleanupDevice(self, devid): devs = self.readBackendList(devid, "vscsi-devs") vscsipath = "vscsi-devs/" new_num_devs = 0 for dev in devs: new_num_devs = new_num_devs + 1 devpath = vscsipath + dev devstate = self.readBackend(devid, devpath + '/state') if str(xenbusState['Closed']) == devstate: self.removeBackend(devid, devpath) frontpath = self.frontendPath(devid) xstransact.Remove(frontpath + '/' + devpath) new_num_devs = new_num_devs - 1 frontpath = self.frontendPath(devid) front_devstate = xstransact.Read(frontpath + '/' + devpath) if front_devstate is not None: if str(xenbusState['Closed']) == front_devstate: self.removeBackend(devid, devpath) xstransact.Remove(frontpath + '/' + devpath) new_num_devs = new_num_devs - 1 return new_num_devs
def removeBackend(self, devid, *args): frontpath = self.frontendPath(devid) backpath = xstransact.Read(frontpath, "backend") if backpath: return xstransact.Remove(backpath, *args) else: raise VmError("Device %s not connected" % devid)
def delete(self): log.info("Deleting vnet %s", self.id) Brctl.vif_bridge_rem({'bridge': self.bridge, 'vif': self.vnetif}) Brctl.bridge_del(self.bridge) val = vnet_cmd(['vnet.del', self.id]) xstransact.Remove(self.dbpath) return val
def deactivate(self): """ Delete pool in hypervisor Preconditions: - pool is activated - no running VMs in pool Actions: - call hypervisor for deletion - remove path of pool in xenstore """ self.pool_lock.acquire() try: if not self.get_activated(): raise PoolError(XEND_ERROR_BAD_POOL_STATE, 'deactivated') if len(self.get_started_VMs()) != 0: raise PoolError(XEND_ERROR_BAD_POOL_STATE, 'in use') pool_id = self.query_pool_id() # remove cpus from pool cpus = [] for pool_rec in xc.cpupool_getinfo(): if pool_rec['cpupool'] == pool_id: cpus = pool_rec['cpulist'] for cpu_number in cpus: xc.cpupool_removecpu(pool_id, cpu_number) xc.cpupool_destroy(pool_id) # update XenStore xs_path = XS_POOLROOT + "%s/" % pool_id xstransact.Remove(xs_path) finally: self.pool_lock.release()
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 __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 stress(): xstransact.Remove(PATH) xstransact.Mkdir(PATH) xswatch(PATH, watch_callback) def do(f): t = threading.Thread(target=stress_write) t.setDaemon(True) t.start() do(stress_write) do(stress_get_domain_path) do(stress_get_domain_path_xsutil) do(stress_open_close) while True: # Wait for Ctrl-C. time.sleep(100000000)
#!/usr/bin/python # # BANNERSTART # - Copyright 2006-2008, Galois, Inc. # - This software is distributed under a standard, three-clause BSD license. # - Please see the file LICENSE, distributed with this software, for specific # - terms and conditions. # Author: Adam Wick <*****@*****.**> # BANNEREND # import sys sys.path.append("/usr/lib/python") from xen.xend.xenstore.xstransact import xstransact xstransact.Remove("/halvm") xstransact.Mkdir("/halvm") xstransact.SetPermissions("/halvm", {'dom': 0, 'read': True, 'write': True})
if self.device_model is None: return if self.pid: try: os.kill(self.pid, signal.SIGKILL) except OSError, exn: log.exception(exn) try: 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. pass self.pid = None state = xstransact.Remove("/local/domain/0/device-model/%i" % self.vm.getDomid()) class LinuxImageHandler(ImageHandler): ostype = "linux" flags = 0 vhpt = 0 def configure(self, vmConfig): ImageHandler.configure(self, vmConfig) rtc_timeoffset = vmConfig['platform'].get('rtc_timeoffset') if rtc_timeoffset is not None: xc.domain_set_time_offset(self.vm.getDomid(), int(rtc_timeoffset)) def buildDomain(self):