示例#1
0
def found_new_qdisk(domid, devid, uuid):
    q = qmp.QEMUMonitorProtocol(
        '{}/qemu-dp/qmp_sock.{}'.format(var_run_prefix(), uuid))

    path = '{}/{}'.format(var_run_prefix(), uuid)
    with open(path, 'w') as f:
        f.write("/local/domain/{}/device/vbd/{}/state".format(domid, devid))

    params = {}
    params['domid'] = domid
    params['devid'] = devid
    params['type'] = 'qdisk'
    params['blocknode'] = 'qemu_node'
    params['devicename'] = uuid

    connected = False
    count = 0
    while not connected:
        try:
            q.connect()
            connected = True
        except:
            if count > 5:
                print "ERROR: not delivering xen-watch-device %s" % params
                return
            print ("got exception {};"
                   " sleeping before attempting reconnect...".format(
                       sys.exc_info()))
            time.sleep(1)
            count += 1

    print "calling: xen-watch-device %s" % params
    res = q.command('xen-watch-device', **params)
    print "result: %s" % res
示例#2
0
    def close(self, dbg, key, f):
        # FIXME: this would not work for raw support
        # assert isinstance(f, image.Cow)
        log.debug("%s: closing image %s in qemu with sock %s" %
                  (dbg, f, self.qmp_sock))

        try:
            self._qmp_connect(dbg)
            path = "{}/{}".format(var_run_prefix(), key)
            try:
                with open(path, 'r') as f:
                    line = f.readline().strip()
                os.unlink(path)
                args = {
                    'type': 'qdisk',
                    'domid': int(re.search(r'domain/(\d+)/', line).group(1)),
                    'devid': int(re.search(r'vbd/(\d+)/', line).group(1))
                }
                self._qmp_command(dbg, "xen-unwatch-device", **args)
            except:
                log.debug('No VBD found')

            # Stop the NBD server
            self._qmp_command(dbg, "nbd-server-stop")

            # Remove the block device
            args = {"node-name": LEAF_NODE_NAME}
            self._qmp_command(dbg, "blockdev-del", **args)
            self._qmp_disconnect(dbg)
        except Exception as e:
            log.debug('{}: failed to close qemu: {}'.format(dbg, e))
            self._kill_qemu()
示例#3
0
def create(dbg, key):
    socket_dir = os.path.join(var_run_prefix(), 'qemu-dp')
    mkdir_p(socket_dir, 0o0700)
    qmp_sock = os.path.join(socket_dir, 'qmp_sock.{}'.format(key))
    log.debug("spawning qemu process with qmp socket at %s" % (qmp_sock))
    cmd = [QEMU_DP, qmp_sock]
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    log.debug("new qemu process has pid %d" % (p.pid))
    return Qemudisk(p.pid, qmp_sock, key, None)
示例#4
0
 def stop():
     with VolumeContext(callbacks, uri, 'w') as opq:
         path = os.path.join(util.var_run_prefix(), 'sr',
                             callbacks.getUniqueIdentifier(opq),
                             name + '_task.pickle')
         with open(path) as f:
             process = pickle.load(f)
         process.kill()
         process.wait()
         os.unlink(path)
示例#5
0
def start_task(dbg_msg, uri, callbacks, name, args):
    with VolumeContext(callbacks, uri, 'w') as opq:
        task = subprocess.Popen(args)
        log.debug(dbg_msg)
        path = os.path.join(util.var_run_prefix(), 'sr',
                            callbacks.getUniqueIdentifier(opq))
        try:
            os.makedirs(path)
        except OSError:
            pass
        path = os.path.join(path, name + '_task.pickle')
        with open(path, 'w+') as f:
            pickle.dump(task, f)
示例#6
0
def _metadata_dir(path):
    return os.path.join(var_run_prefix(), "nonpersistent", "dp-tapdisk",
                        os.path.realpath(path).lstrip('/'))