Beispiel #1
0
 def update_XS(self, pool_id):
     """ Write (or update) data in xenstore taken from instance.
         @param pool_id: Pool id to build path to pool data in xenstore
         @type  pool_id: int
     """
     self.pool_lock.acquire()
     try:
         xs_path = XS_POOLROOT + "%s/" % pool_id
         xs_entries = {
             'uuid': self.get_uuid(),
             'name': self.name_label,
             'description': self.name_description
         }
         xstransact.Mkdir(xs_path)
         xstransact.Mkdir(xs_path, 'other_config')
         xstransact.Write(xs_path, xs_entries)
         xstransact.Write('%s%s' % (xs_path, 'other_config'),
                          self.other_config)
     finally:
         self.pool_lock.release()
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)
Beispiel #3
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()
Beispiel #4
0
#!/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})
Beispiel #5
0
    def createDeviceModel(self, restore=False):
        if self.device_model is None:
            return
        if self.pid:
            return
        # Execute device model.
        #todo: Error handling
        args = self.getDeviceModelArgs(restore)
        env = dict(os.environ)
        if self.display:
            env['DISPLAY'] = self.display
        if self.xauthority:
            env['XAUTHORITY'] = self.xauthority
        unique_id = "%i-%i" % (self.vm.getDomid(), time.time())
        sentinel_path = sentinel_path_prefix + unique_id
        sentinel_path_fifo = sentinel_path + '.fifo'
        os.mkfifo(sentinel_path_fifo, 0600)
        sentinel_write = file(sentinel_path_fifo, 'r+')
        self._openSentinel(sentinel_path_fifo)
        self.vm.storeDom("image/device-model-fifo", sentinel_path_fifo)
        xstransact.Mkdir("/local/domain/0/device-model/%i" %
                         self.vm.getDomid())
        xstransact.SetPermissions(
            "/local/domain/0/device-model/%i" % self.vm.getDomid(), {
                'dom': self.vm.getDomid(),
                'read': True,
                'write': True
            })
        log.info("spawning device models: %s %s", self.device_model, args)
        # keep track of pid and spawned options to kill it later

        self.logfile = "/var/log/xen/qemu-dm-%s.log" % str(
            self.vm.info['name_label'])

        # rotate log
        logfile_mode = os.O_WRONLY | os.O_CREAT | os.O_APPEND
        logrotate_count = XendOptions.instance().get_qemu_dm_logrotate_count()
        if logrotate_count > 0:
            logfile_mode |= os.O_TRUNC
            if os.path.exists("%s.%d" % (self.logfile, logrotate_count)):
                os.unlink("%s.%d" % (self.logfile, logrotate_count))
            for n in range(logrotate_count - 1, 0, -1):
                if os.path.exists("%s.%d" % (self.logfile, n)):
                    os.rename("%s.%d" % (self.logfile, n),
                              "%s.%d" % (self.logfile, (n + 1)))
            if os.path.exists(self.logfile):
                os.rename(self.logfile, self.logfile + ".1")

        null = os.open("/dev/null", os.O_RDONLY)
        logfd = os.open(self.logfile, logfile_mode, 0666)

        sys.stderr.flush()
        contract = osdep.prefork("%s:%d" %
                                 (self.vm.getName(), self.vm.getDomid()))
        pid = os.fork()
        if pid == 0:  #child
            try:
                osdep.postfork(contract)
                os.dup2(null, 0)
                os.dup2(logfd, 1)
                os.dup2(logfd, 2)
                oshelp.close_fds((sentinel_write.fileno(), ))
                try:
                    os.execve(self.device_model, args, env)
                except Exception, e:
                    print >> sys.stderr, (
                        'failed to set up fds or execute dm %s: %s' %
                        (self.device_model, utils.exception_string(e)))
                    os._exit(126)
            except:
                os._exit(127)
        else:
            osdep.postfork(contract, abandon=True)
            self.pid = pid
            os.close(null)
            os.close(logfd)
        sentinel_write.close()
        self.vm.storeDom("image/device-model-pid", self.pid)
        log.info("device model pid: %d", self.pid)
        # we would very much prefer not to have a thread here and instead
        #  have a callback but sadly we don't have Twisted in xend
        self.sentinel_thread = thread.start_new_thread(self._sentinel_watch,
                                                       ())
        if self.device_model.find('stubdom-dm') > -1:
            from xen.xend import XendDomain
            domains = XendDomain.instance()
            domains.domains_lock.release()

            count = 0
            while True:
                orig_state = xstransact.Read(
                    "/local/domain/0/device-model/%i/state" %
                    self.vm.getDomid())
                # This can occur right after start-up
                if orig_state != None:
                    break

                log.debug(
                    'createDeviceModel %i: orig_state is None, retrying' %
                    self.vm.getDomid())

                time.sleep(0.1)
                count += 1
                if count > 100:
                    break

            domains.domains_lock.acquire()