Ejemplo n.º 1
0
    def waitForBackend(self, devid):
        frontpath = self.frontendPath(devid)
        # lookup a phantom
        phantomPath = xstransact.Read(frontpath, 'phantom_vbd')
        if phantomPath is not None:
            log.debug("Waiting for %s's phantom %s.", devid, phantomPath)
            statusPath = phantomPath + '/' + HOTPLUG_STATUS_NODE
            ev = Event()
            result = {'status': Timeout}
            xswatch(statusPath, hotplugStatusCallback, ev, result)
            ev.wait(DEVICE_CREATE_TIMEOUT)
            err = xstransact.Read(statusPath, HOTPLUG_ERROR_NODE)
            if result['status'] != Connected:
                return (result['status'], err)

        backpath = self.readVm(devid, "backend")

        if backpath:
            statusPath = backpath + '/' + HOTPLUG_STATUS_NODE
            ev = Event()
            result = {'status': Timeout}

            xswatch(statusPath, hotplugStatusCallback, ev, result)

            ev.wait(DEVICE_CREATE_TIMEOUT)

            err = xstransact.Read(backpath, HOTPLUG_ERROR_NODE)

            return (result['status'], err)
        else:
            return (Missing, None)
Ejemplo n.º 2
0
    def waitForBackend(self, devid):

        frontpath = self.frontendPath(devid)
        # lookup a phantom 
        phantomPath = xstransact.Read(frontpath, 'phantom_vbd')
        if phantomPath is not None:
            log.debug("Waiting for %s's phantom %s.", devid, phantomPath)
            statusPath = phantomPath + '/' + HOTPLUG_STATUS_NODE
            ev = Event()
            result = { 'status': Timeout }
            xswatch(statusPath, hotplugStatusCallback, ev, result)
            ev.wait(DEVICE_CREATE_TIMEOUT)
            err = xstransact.Read(statusPath, HOTPLUG_ERROR_NODE)
            if result['status'] != 'Connected':
                return (result['status'], err)
            
        backpath = xstransact.Read(frontpath, "backend")


        if backpath:
            statusPath = backpath + '/' + HOTPLUG_STATUS_NODE
            ev = Event()
            result = { 'status': Timeout }

            xswatch(statusPath, hotplugStatusCallback, ev, result)

            ev.wait(DEVICE_CREATE_TIMEOUT)

            err = xstransact.Read(backpath, HOTPLUG_ERROR_NODE)

            return (result['status'], err)
        else:
            return (Missing, None)
Ejemplo n.º 3
0
    def waitForBackend_destroy(self, backpath):

        statusPath = backpath + '/' + HOTPLUG_STATUS_NODE
        ev = Event()
        result = {'status': Timeout}

        xswatch(statusPath, deviceDestroyCallback, ev, result)

        ev.wait(DEVICE_DESTROY_TIMEOUT)

        return result['status']
Ejemplo n.º 4
0
    def waitForBackend_destroy(self, backpath):

        statusPath = backpath + '/' + HOTPLUG_STATUS_NODE
        ev = Event()
        result = { 'status': Timeout }

        xswatch(statusPath, deviceDestroyCallback, ev, result)

        ev.wait(DEVICE_DESTROY_TIMEOUT)

        return result['status']
    def waitForBackend_reconfigure(self, devid):
        frontpath = self.frontendPath(devid)
        backpath = xstransact.Read(frontpath, "backend")
        if backpath:
            statusPath = backpath + '/' + "state"
            ev = Event()
            result = { 'status': Timeout }

            xswatch(statusPath, xenbusStatusCallback, ev, result)

            ev.wait(DEVICE_CREATE_TIMEOUT)

            return (result['status'], None)
        else:
            return (Missing, None)
Ejemplo n.º 6
0
    def waitForBackend_reconfigure(self, devid):
        frontpath = self.frontendPath(devid)
        backpath = xstransact.Read(frontpath, "backend")
        if backpath:
            statusPath = backpath + '/' + "state"
            ev = Event()
            result = {'status': Timeout}

            xswatch(statusPath, xenbusStatusCallback, ev, result)

            ev.wait(DEVICE_CREATE_TIMEOUT)

            return (result['status'], None)
        else:
            return (Missing, None)
Ejemplo n.º 7
0
    def waitForBackend_destroy(self, backpath):

        statusPath = backpath + '/' + HOTPLUG_STATUS_NODE
        ev = Event()
        result = {'status': Timeout}

        xswatch(statusPath, deviceDestroyCallback, ev, result)

        for i in range(1, 50):
            ev.wait(DEVICE_DESTROY_TIMEOUT / 50)
            status = xstransact.Read(statusPath)
            if status is None:
                result['status'] = Disconnected
                break

        return result['status']
Ejemplo n.º 8
0
    def waitForBackend_destroy(self, backpath):

        statusPath = backpath + '/' + HOTPLUG_STATUS_NODE
        ev = Event()
        result = { 'status': Timeout }

        xswatch(statusPath, deviceDestroyCallback, ev, result)

        for i in range(1, 50):
            ev.wait(DEVICE_DESTROY_TIMEOUT/50)
            status = xstransact.Read(statusPath)
            if status is None:
                result['status'] = Disconnected
                break 

        return result['status']
Ejemplo n.º 9
0
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)
Ejemplo n.º 10
0
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)
Ejemplo n.º 11
0
 def setupDevice(self, config):
     """Setup devices from config
     """
     pci_dev_list = config.get('devs', [])
     for d in pci_dev_list:
         self.setupOneDevice(d)
     wPath = '/local/domain/0/backend/pci/%u/0/aerState' % (self.getDomid())
     self.aerStateWatch = xswatch(wPath, self._handleAerStateWatch)
     log.debug('pci: register aer watch %s', wPath)
     return
Ejemplo n.º 12
0
 def setupDevice(self, config):
     """Setup devices from config
     """
     pci_dev_list = config.get('devs', [])
     for d in pci_dev_list:
         self.setupOneDevice(d)
     wPath = '/local/domain/0/backend/pci/%u/0/aerState' % (self.getDomid())
     self.aerStateWatch = xswatch(wPath, self._handleAerStateWatch)
     log.debug('pci: register aer watch %s', wPath)
     return
Ejemplo n.º 13
0
    def waitForBackend(self, devid):
        
        # FIXME!!! We haven't udev daemon...
        #result = { 'status': Connected }
        #return result['status']

        frontpath = self.frontendPath(devid)
        backpath = xstransact.Read(frontpath, "backend")

        if backpath:
            statusPath = backpath + '/' + HOTPLUG_STATUS_NODE
            ev = Event()
            result = { 'status': Timeout }
            
            xswatch(statusPath, hotplugStatusCallback, ev, result)

            ev.wait(DEVICE_CREATE_TIMEOUT)
            return result['status']
        else:
            return Missing
Ejemplo n.º 14
0
    def __init__(self, receive_prefix = "data/host", send_prefix = "data/guest", data_prefix = "vm-data", *args, **kwargs): # pylint: disable=C0301
        """Initialize a communication "bus" with the Xen Hypervisor.

        ### Description

        Sets up watches on paths we'll be receiving data on in xenstore and 
        initializes pathing information used elsewhere.

        """

        super(XenCommunicator, self).__init__(*args, **kwargs)

        self._receive_prefix = receive_prefix
        self._send_prefix = send_prefix
        self._network_prefix = data_prefix + "/networking"
        self._hostname_prefix = data_prefix + "/hostname"

        self._queue = Queue.Queue()

        self.xs = xs.xshandle() # pylint: disable=C0103

        def xs_watch(path):
            logger.info("Received a watch even on %s", path)

            if path in [ self._receive_prefix, data_prefix ]:
                return True

            transaction = self.xs.transaction_start()
            message = self.xs.read(transaction, path)
            self.xs.transaction_end(transaction)

            logger.info("Received message, %s", message)

            self._queue.put((path, message))

            transaction = self.xs.transaction_start()
            message = self.xs.rm(transaction, path)
            self.xs.transaction_end(transaction)

            return True

        self.watches = []
        self.watches.append(xswatch(self._receive_prefix, xs_watch))

        transaction = self.xs.transaction_start()
        entries = self.xs.ls(transaction, self._receive_prefix)
        self.xs.transaction_end(transaction)

        logger.debug("Missed messages: %s", entries)

        if entries is not None:
            for path in [ self._receive_prefix + "/" + entry for entry in entries ]: # pylint: disable=C0301
                xs_watch(path)
Ejemplo n.º 15
0
    def init(self):
        xstransact.Mkdir(VMROOT)
        xstransact.SetPermissions(VMROOT, { 'dom' : PRIV_DOMAIN })

        self.domains_lock.acquire()
        try:
            self._add_domain(
                XendDomainInfo.recreate(self.xen_domains()[PRIV_DOMAIN],
                                        True))
            self.dom0_setup()

            # This watch registration needs to be before the refresh call, so
            # that we're sure that we haven't missed any releases, but inside
            # the domains_lock, as we don't want the watch to fire until after
            # the refresh call has completed.
            xswatch("@introduceDomain", self.onChangeDomain)
            xswatch("@releaseDomain",   self.onChangeDomain)
            
            self.refresh(True)
        finally:
            self.domains_lock.release()
Ejemplo n.º 16
0
 def waitForFrontend(self, devid):
     def frontendStatusCallback(statusPath, ev, result):
         status = xstransact.Read(statusPath)
         log.debug("frontendStatusCallback %s = %s" % (statusPath, status))
         try:
             status = int(status)
             if status == xenbusState['Connected']:
                 result['status'] = Connected
             elif status == xenbusState['Closed']:
                 result['status'] = Error
             else:
                 raise
         except:
             return 1
         ev.set()
         return 0
     frontpath = self.frontendPath(devid)
     statusPath = frontpath + '/state'
     ev = Event()
     result = { 'status': Timeout }
     xswatch(statusPath, frontendStatusCallback, ev, result)
     ev.wait(5)
     return result['status']
Ejemplo n.º 17
0
    def waitForFrontend(self, devid):
        def frontendStatusCallback(statusPath, ev, result):
            status = xstransact.Read(statusPath)
            log.debug("frontendStatusCallback %s = %s" % (statusPath, status))
            try:
                status = int(status)
                if status == xenbusState['Connected']:
                    result['status'] = Connected
                elif status == xenbusState['Closed']:
                    result['status'] = Error
                else:
                    raise
            except:
                return 1
            ev.set()
            return 0

        frontpath = self.frontendPath(devid)
        statusPath = frontpath + '/state'
        ev = Event()
        result = {'status': Timeout}
        xswatch(statusPath, frontendStatusCallback, ev, result)
        ev.wait(5)
        return result['status']
Ejemplo n.º 18
0
 def register_shutdown_watch(self):
     """ add xen store watch on control/shutdown """
     self.shutdownWatch = xswatch(self.vm.dompath + "/control/shutdown", \
                                 self.hvm_shutdown)
     log.debug("hvm shutdown watch registered")
Ejemplo n.º 19
0
                    devs_str = dev.find_coassigned_pci_devices(True)
                    # Remove the element 0 which is a bridge
                    del devs_str[0]

                    dev.devs_check_driver(devs_str)
                    for s in devs_str:
                        if not s in pci_str_list:
                            s_pci_str = pci_dict_to_bdf_str(parse_pci_name(s))
                            # s has been assigned to other guest?
                            if xc.test_assign_device(0, s_pci_str) != 0:
                                err_msg = 'pci: %s must be co-assigned to the'+\
                                    ' same guest with %s'
                                raise VmError(err_msg % (s, dev.name))

        wPath = '/local/domain/0/backend/pci/%u/0/aerState' % (self.getDomid())
        self.aerStateWatch = xswatch(wPath, self._handleAerStateWatch)
        log.debug('pci: register aer watch %s', wPath)
        return

    def _handleAerStateWatch(self, _):
        log.debug('XendDomainInfo.handleAerStateWatch')
        if self.getDomid() == 0:
            raise XendError('Domain 0 cannot be shutdown')
        readPath = '/local/domain/0/backend/pci/%u/0/aerState' % (self.getDomid())
        action = xstransact.Read(readPath)
        if action and action=='aerfail':
            log.debug('shutdown domain because of aer handle error')
            self.vm.shutdown('poweroff')
        return True