Compare commits
9 Commits
qdev-array
...
file
Author | SHA1 | Date | |
---|---|---|---|
|
c02a48d633 | ||
|
e7291a96e5 | ||
|
5b2ad21985 | ||
|
b6f87ecdfe | ||
|
ec13463af4 | ||
|
97de3d3d10 | ||
|
e4fc1b2e2c | ||
|
7608096206 | ||
|
f0887a597e |
@@ -39,6 +39,8 @@ over any transport.
|
||||
- exec migration: do the migration using the stdin/stdout through a process.
|
||||
- fd migration: do the migration using a file descriptor that is
|
||||
passed to QEMU. QEMU doesn't care how this file descriptor is opened.
|
||||
- file migration: do the migration using a file that is passed by name
|
||||
to QEMU.
|
||||
|
||||
In addition, support is included for migration using RDMA, which
|
||||
transports the page data using ``RDMA``, where the hardware takes care of
|
||||
|
@@ -44,6 +44,7 @@ enum QIOChannelFeature {
|
||||
QIO_CHANNEL_FEATURE_LISTEN,
|
||||
QIO_CHANNEL_FEATURE_WRITE_ZERO_COPY,
|
||||
QIO_CHANNEL_FEATURE_READ_MSG_PEEK,
|
||||
QIO_CHANNEL_FEATURE_SEEKABLE,
|
||||
};
|
||||
|
||||
|
||||
@@ -128,6 +129,16 @@ struct QIOChannelClass {
|
||||
Error **errp);
|
||||
|
||||
/* Optional callbacks */
|
||||
ssize_t (*io_pwritev)(QIOChannel *ioc,
|
||||
const struct iovec *iov,
|
||||
size_t niov,
|
||||
off_t offset,
|
||||
Error **errp);
|
||||
ssize_t (*io_preadv)(QIOChannel *ioc,
|
||||
const struct iovec *iov,
|
||||
size_t niov,
|
||||
off_t offset,
|
||||
Error **errp);
|
||||
int (*io_shutdown)(QIOChannel *ioc,
|
||||
QIOChannelShutdown how,
|
||||
Error **errp);
|
||||
@@ -510,6 +521,78 @@ int qio_channel_set_blocking(QIOChannel *ioc,
|
||||
int qio_channel_close(QIOChannel *ioc,
|
||||
Error **errp);
|
||||
|
||||
/**
|
||||
* qio_channel_pwritev_full
|
||||
* @ioc: the channel object
|
||||
* @iov: the array of memory regions to write data from
|
||||
* @niov: the length of the @iov array
|
||||
* @offset: offset in the channel where writes should begin
|
||||
* @errp: pointer to a NULL-initialized error object
|
||||
*
|
||||
* Not all implementations will support this facility, so may report
|
||||
* an error. To avoid errors, the caller may check for the feature
|
||||
* flag QIO_CHANNEL_FEATURE_SEEKABLE prior to calling this method.
|
||||
*
|
||||
* Behaves as qio_channel_writev_full, apart from not supporting
|
||||
* sending of file handles as well as beginning the write at the
|
||||
* passed @offset
|
||||
*
|
||||
*/
|
||||
ssize_t qio_channel_pwritev_full(QIOChannel *ioc, const struct iovec *iov,
|
||||
size_t niov, off_t offset, Error **errp);
|
||||
|
||||
/**
|
||||
* qio_channel_pwritev
|
||||
* @ioc: the channel object
|
||||
* @buf: the memory region to write data into
|
||||
* @buflen: the number of bytes to @buf
|
||||
* @offset: offset in the channel where writes should begin
|
||||
* @errp: pointer to a NULL-initialized error object
|
||||
*
|
||||
* Not all implementations will support this facility, so may report
|
||||
* an error. To avoid errors, the caller may check for the feature
|
||||
* flag QIO_CHANNEL_FEATURE_SEEKABLE prior to calling this method.
|
||||
*
|
||||
*/
|
||||
ssize_t qio_channel_pwritev(QIOChannel *ioc, char *buf, size_t buflen,
|
||||
off_t offset, Error **errp);
|
||||
|
||||
/**
|
||||
* qio_channel_preadv_full
|
||||
* @ioc: the channel object
|
||||
* @iov: the array of memory regions to read data into
|
||||
* @niov: the length of the @iov array
|
||||
* @offset: offset in the channel where writes should begin
|
||||
* @errp: pointer to a NULL-initialized error object
|
||||
*
|
||||
* Not all implementations will support this facility, so may report
|
||||
* an error. To avoid errors, the caller may check for the feature
|
||||
* flag QIO_CHANNEL_FEATURE_SEEKABLE prior to calling this method.
|
||||
*
|
||||
* Behaves as qio_channel_readv_full, apart from not supporting
|
||||
* receiving of file handles as well as beginning the read at the
|
||||
* passed @offset
|
||||
*
|
||||
*/
|
||||
ssize_t qio_channel_preadv_full(QIOChannel *ioc, const struct iovec *iov,
|
||||
size_t niov, off_t offset, Error **errp);
|
||||
|
||||
/**
|
||||
* qio_channel_preadv
|
||||
* @ioc: the channel object
|
||||
* @buf: the memory region to write data into
|
||||
* @buflen: the number of bytes to @buf
|
||||
* @offset: offset in the channel where writes should begin
|
||||
* @errp: pointer to a NULL-initialized error object
|
||||
*
|
||||
* Not all implementations will support this facility, so may report
|
||||
* an error. To avoid errors, the caller may check for the feature
|
||||
* flag QIO_CHANNEL_FEATURE_SEEKABLE prior to calling this method.
|
||||
*
|
||||
*/
|
||||
ssize_t qio_channel_preadv(QIOChannel *ioc, char *buf, size_t buflen,
|
||||
off_t offset, Error **errp);
|
||||
|
||||
/**
|
||||
* qio_channel_shutdown:
|
||||
* @ioc: the channel object
|
||||
|
@@ -50,6 +50,8 @@ unsigned int qemu_get_be16(QEMUFile *f);
|
||||
unsigned int qemu_get_be32(QEMUFile *f);
|
||||
uint64_t qemu_get_be64(QEMUFile *f);
|
||||
|
||||
bool qemu_file_is_seekable(QEMUFile *f);
|
||||
|
||||
static inline void qemu_put_be64s(QEMUFile *f, const uint64_t *pv)
|
||||
{
|
||||
qemu_put_be64(f, *pv);
|
||||
|
@@ -35,6 +35,10 @@ qio_channel_file_new_fd(int fd)
|
||||
|
||||
ioc->fd = fd;
|
||||
|
||||
if (lseek(fd, 0, SEEK_CUR) != (off_t)-1) {
|
||||
qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_SEEKABLE);
|
||||
}
|
||||
|
||||
trace_qio_channel_file_new_fd(ioc, fd);
|
||||
|
||||
return ioc;
|
||||
@@ -59,6 +63,10 @@ qio_channel_file_new_path(const char *path,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (lseek(ioc->fd, 0, SEEK_CUR) != (off_t)-1) {
|
||||
qio_channel_set_feature(QIO_CHANNEL(ioc), QIO_CHANNEL_FEATURE_SEEKABLE);
|
||||
}
|
||||
|
||||
trace_qio_channel_file_new_path(ioc, path, flags, mode, ioc->fd);
|
||||
|
||||
return ioc;
|
||||
@@ -137,6 +145,56 @@ static ssize_t qio_channel_file_writev(QIOChannel *ioc,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t qio_channel_file_preadv(QIOChannel *ioc,
|
||||
const struct iovec *iov,
|
||||
size_t niov,
|
||||
off_t offset,
|
||||
Error **errp)
|
||||
{
|
||||
QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
|
||||
ssize_t ret;
|
||||
|
||||
retry:
|
||||
ret = preadv(fioc->fd, iov, niov, offset);
|
||||
if (ret < 0) {
|
||||
if (errno == EAGAIN) {
|
||||
return QIO_CHANNEL_ERR_BLOCK;
|
||||
}
|
||||
if (errno == EINTR) {
|
||||
goto retry;
|
||||
}
|
||||
|
||||
error_setg_errno(errp, errno, "Unable to read from file");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ssize_t qio_channel_file_pwritev(QIOChannel *ioc,
|
||||
const struct iovec *iov,
|
||||
size_t niov,
|
||||
off_t offset,
|
||||
Error **errp)
|
||||
{
|
||||
QIOChannelFile *fioc = QIO_CHANNEL_FILE(ioc);
|
||||
ssize_t ret;
|
||||
|
||||
retry:
|
||||
ret = pwritev(fioc->fd, iov, niov, offset);
|
||||
if (ret <= 0) {
|
||||
if (errno == EAGAIN) {
|
||||
return QIO_CHANNEL_ERR_BLOCK;
|
||||
}
|
||||
if (errno == EINTR) {
|
||||
goto retry;
|
||||
}
|
||||
error_setg_errno(errp, errno, "Unable to write to file");
|
||||
return -1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int qio_channel_file_set_blocking(QIOChannel *ioc,
|
||||
bool enabled,
|
||||
Error **errp)
|
||||
@@ -219,6 +277,8 @@ static void qio_channel_file_class_init(ObjectClass *klass,
|
||||
ioc_klass->io_writev = qio_channel_file_writev;
|
||||
ioc_klass->io_readv = qio_channel_file_readv;
|
||||
ioc_klass->io_set_blocking = qio_channel_file_set_blocking;
|
||||
ioc_klass->io_pwritev = qio_channel_file_pwritev;
|
||||
ioc_klass->io_preadv = qio_channel_file_preadv;
|
||||
ioc_klass->io_seek = qio_channel_file_seek;
|
||||
ioc_klass->io_close = qio_channel_file_close;
|
||||
ioc_klass->io_create_watch = qio_channel_file_create_watch;
|
||||
|
58
io/channel.c
58
io/channel.c
@@ -445,6 +445,64 @@ GSource *qio_channel_add_watch_source(QIOChannel *ioc,
|
||||
}
|
||||
|
||||
|
||||
ssize_t qio_channel_pwritev_full(QIOChannel *ioc, const struct iovec *iov,
|
||||
size_t niov, off_t offset, Error **errp)
|
||||
{
|
||||
QIOChannelClass *klass = QIO_CHANNEL_GET_CLASS(ioc);
|
||||
|
||||
if (!klass->io_pwritev) {
|
||||
error_setg(errp, "Channel does not support pwritev");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_SEEKABLE)) {
|
||||
error_setg_errno(errp, EINVAL, "Requested channel is not seekable");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return klass->io_pwritev(ioc, iov, niov, offset, errp);
|
||||
}
|
||||
|
||||
ssize_t qio_channel_pwritev(QIOChannel *ioc, char *buf, size_t buflen,
|
||||
off_t offset, Error **errp)
|
||||
{
|
||||
struct iovec iov = {
|
||||
.iov_base = buf,
|
||||
.iov_len = buflen
|
||||
};
|
||||
|
||||
return qio_channel_pwritev_full(ioc, &iov, 1, offset, errp);
|
||||
}
|
||||
|
||||
ssize_t qio_channel_preadv_full(QIOChannel *ioc, const struct iovec *iov,
|
||||
size_t niov, off_t offset, Error **errp)
|
||||
{
|
||||
QIOChannelClass *klass = QIO_CHANNEL_GET_CLASS(ioc);
|
||||
|
||||
if (!klass->io_preadv) {
|
||||
error_setg(errp, "Channel does not support preadv");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!qio_channel_has_feature(ioc, QIO_CHANNEL_FEATURE_SEEKABLE)) {
|
||||
error_setg_errno(errp, EINVAL, "Requested channel is not seekable");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return klass->io_preadv(ioc, iov, niov, offset, errp);
|
||||
}
|
||||
|
||||
ssize_t qio_channel_preadv(QIOChannel *ioc, char *buf, size_t buflen,
|
||||
off_t offset, Error **errp)
|
||||
{
|
||||
struct iovec iov = {
|
||||
.iov_base = buf,
|
||||
.iov_len = buflen
|
||||
};
|
||||
|
||||
return qio_channel_preadv_full(ioc, &iov, 1, offset, errp);
|
||||
}
|
||||
|
||||
int qio_channel_shutdown(QIOChannel *ioc,
|
||||
QIOChannelShutdown how,
|
||||
Error **errp)
|
||||
|
36
migration/file.c
Normal file
36
migration/file.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "qemu/osdep.h"
|
||||
#include "channel.h"
|
||||
#include "io/channel-file.h"
|
||||
#include "file.h"
|
||||
#include "qemu/error-report.h"
|
||||
|
||||
|
||||
void file_start_outgoing_migration(MigrationState *s, const char *fname, Error **errp)
|
||||
{
|
||||
QIOChannelFile *ioc;
|
||||
|
||||
ioc = qio_channel_file_new_path(fname, O_CREAT | O_TRUNC | O_WRONLY, 0660, errp);
|
||||
if (!ioc) {
|
||||
error_report("Error creating a channel");
|
||||
return;
|
||||
}
|
||||
|
||||
qio_channel_set_name(QIO_CHANNEL(ioc), "migration-file-outgoing");
|
||||
migration_channel_connect(s, QIO_CHANNEL(ioc), NULL, NULL);
|
||||
object_unref(OBJECT(ioc));
|
||||
}
|
||||
|
||||
void file_start_incoming_migration(const char *fname, Error **errp)
|
||||
{
|
||||
QIOChannelFile *ioc;
|
||||
|
||||
ioc = qio_channel_file_new_path(fname, O_RDONLY, 0, errp);
|
||||
if (!ioc) {
|
||||
error_report("Error creating a channel");
|
||||
return;
|
||||
}
|
||||
|
||||
qio_channel_set_name(QIO_CHANNEL(ioc), "migration-file-incoming");
|
||||
migration_channel_process_incoming(QIO_CHANNEL(ioc));
|
||||
object_unref(OBJECT(ioc));
|
||||
}
|
10
migration/file.h
Normal file
10
migration/file.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef QEMU_MIGRATION_FILE_H
|
||||
#define QEMU_MIGRATION_FILE_H
|
||||
|
||||
void file_start_outgoing_migration(MigrationState *s,
|
||||
const char *filename,
|
||||
Error **errp);
|
||||
|
||||
void file_start_incoming_migration(const char *fname, Error **errp);
|
||||
#endif
|
||||
|
@@ -17,6 +17,7 @@ softmmu_ss.add(files(
|
||||
'colo.c',
|
||||
'exec.c',
|
||||
'fd.c',
|
||||
'file.c',
|
||||
'global_state.c',
|
||||
'migration-hmp-cmds.c',
|
||||
'migration-stats.c',
|
||||
|
@@ -20,6 +20,7 @@
|
||||
#include "migration/blocker.h"
|
||||
#include "exec.h"
|
||||
#include "fd.h"
|
||||
#include "file.h"
|
||||
#include "socket.h"
|
||||
#include "sysemu/runstate.h"
|
||||
#include "sysemu/sysemu.h"
|
||||
@@ -428,6 +429,8 @@ static void qemu_start_incoming_migration(const char *uri, Error **errp)
|
||||
exec_start_incoming_migration(p, errp);
|
||||
} else if (strstart(uri, "fd:", &p)) {
|
||||
fd_start_incoming_migration(p, errp);
|
||||
} else if (strstart(uri, "file:", &p)) {
|
||||
file_start_incoming_migration(p, errp);
|
||||
} else {
|
||||
error_setg(errp, "unknown migration protocol: %s", uri);
|
||||
}
|
||||
@@ -1394,6 +1397,7 @@ void migrate_init(MigrationState *s)
|
||||
error_free(s->error);
|
||||
s->error = NULL;
|
||||
s->hostname = NULL;
|
||||
s->vmdesc = NULL;
|
||||
|
||||
migrate_set_state(&s->state, MIGRATION_STATUS_NONE, MIGRATION_STATUS_SETUP);
|
||||
|
||||
@@ -1659,6 +1663,8 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
|
||||
exec_start_outgoing_migration(s, p, &local_err);
|
||||
} else if (strstart(uri, "fd:", &p)) {
|
||||
fd_start_outgoing_migration(s, p, &local_err);
|
||||
} else if (strstart(uri, "file:", &p)) {
|
||||
file_start_outgoing_migration(s, p, &local_err);
|
||||
} else {
|
||||
if (!(has_resume && resume)) {
|
||||
yank_unregister_instance(MIGRATION_YANK_INSTANCE);
|
||||
|
@@ -30,6 +30,7 @@
|
||||
#include "qemu-file.h"
|
||||
#include "trace.h"
|
||||
#include "qapi/error.h"
|
||||
#include "io/channel-file.h"
|
||||
|
||||
#define IO_BUF_SIZE 32768
|
||||
#define MAX_IOV_SIZE MIN_CONST(IOV_MAX, 64)
|
||||
@@ -277,6 +278,10 @@ static void qemu_iovec_release_ram(QEMUFile *f)
|
||||
memset(f->may_free, 0, sizeof(f->may_free));
|
||||
}
|
||||
|
||||
bool qemu_file_is_seekable(QEMUFile *f)
|
||||
{
|
||||
return qio_channel_has_feature(f->ioc, QIO_CHANNEL_FEATURE_SEEKABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Flushes QEMUFile buffer
|
||||
@@ -545,6 +550,81 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, size_t size)
|
||||
}
|
||||
}
|
||||
|
||||
void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, off_t pos)
|
||||
{
|
||||
Error *err = NULL;
|
||||
|
||||
if (f->last_error) {
|
||||
return;
|
||||
}
|
||||
|
||||
qemu_fflush(f);
|
||||
qio_channel_pwritev(f->ioc, (char *)buf, buflen, pos, &err);
|
||||
|
||||
if (err) {
|
||||
qemu_file_set_error_obj(f, -EIO, err);
|
||||
} else {
|
||||
f->total_transferred += buflen;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, off_t pos)
|
||||
{
|
||||
Error *err = NULL;
|
||||
ssize_t ret;
|
||||
|
||||
if (f->last_error) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = qio_channel_preadv(f->ioc, (char *)buf, buflen, pos, &err);
|
||||
if (ret == -1 || err) {
|
||||
goto error;
|
||||
}
|
||||
|
||||
return (size_t)ret;
|
||||
|
||||
error:
|
||||
qemu_file_set_error_obj(f, -EIO, err);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void qemu_set_offset(QEMUFile *f, off_t off, int whence)
|
||||
{
|
||||
Error *err = NULL;
|
||||
off_t ret;
|
||||
|
||||
qemu_fflush(f);
|
||||
|
||||
if (!qemu_file_is_writable(f)) {
|
||||
f->buf_index = 0;
|
||||
f->buf_size = 0;
|
||||
}
|
||||
|
||||
ret = qio_channel_io_seek(f->ioc, off, whence, &err);
|
||||
if (ret == (off_t)-1) {
|
||||
qemu_file_set_error_obj(f, -EIO, err);
|
||||
}
|
||||
}
|
||||
|
||||
off_t qemu_get_offset(QEMUFile *f)
|
||||
{
|
||||
Error *err = NULL;
|
||||
off_t ret;
|
||||
|
||||
qemu_fflush(f);
|
||||
|
||||
ret = qio_channel_io_seek(f->ioc, 0, SEEK_CUR, &err);
|
||||
if (ret == (off_t)-1) {
|
||||
qemu_file_set_error_obj(f, -EIO, err);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
void qemu_put_byte(QEMUFile *f, int v)
|
||||
{
|
||||
if (f->last_error) {
|
||||
|
@@ -149,6 +149,10 @@ QEMUFile *qemu_file_get_return_path(QEMUFile *f);
|
||||
void qemu_fflush(QEMUFile *f);
|
||||
void qemu_file_set_blocking(QEMUFile *f, bool block);
|
||||
int qemu_file_get_to_fd(QEMUFile *f, int fd, size_t size);
|
||||
void qemu_set_offset(QEMUFile *f, off_t off, int whence);
|
||||
off_t qemu_get_offset(QEMUFile *f);
|
||||
void qemu_put_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, off_t pos);
|
||||
size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, size_t buflen, off_t pos);
|
||||
|
||||
void ram_control_before_iterate(QEMUFile *f, uint64_t flags);
|
||||
void ram_control_after_iterate(QEMUFile *f, uint64_t flags);
|
||||
|
@@ -1209,13 +1209,25 @@ void qemu_savevm_non_migratable_list(strList **reasons)
|
||||
|
||||
void qemu_savevm_state_header(QEMUFile *f)
|
||||
{
|
||||
MigrationState *s = migrate_get_current();
|
||||
|
||||
s->vmdesc = json_writer_new(false);
|
||||
|
||||
trace_savevm_state_header();
|
||||
qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
|
||||
qemu_put_be32(f, QEMU_VM_FILE_VERSION);
|
||||
|
||||
if (migrate_get_current()->send_configuration) {
|
||||
if (s->send_configuration) {
|
||||
qemu_put_byte(f, QEMU_VM_CONFIGURATION);
|
||||
vmstate_save_state(f, &vmstate_configuration, &savevm_state, 0);
|
||||
/*
|
||||
* This starts the main json object and is paired with the
|
||||
* json_writer_end_object in
|
||||
* qemu_savevm_state_complete_precopy_non_iterable
|
||||
*/
|
||||
json_writer_start_object(s->vmdesc, NULL);
|
||||
json_writer_start_object(s->vmdesc, "configuration");
|
||||
vmstate_save_state(f, &vmstate_configuration, &savevm_state, s->vmdesc);
|
||||
json_writer_end_object(s->vmdesc);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1240,8 +1252,6 @@ void qemu_savevm_state_setup(QEMUFile *f)
|
||||
Error *local_err = NULL;
|
||||
int ret;
|
||||
|
||||
ms->vmdesc = json_writer_new(false);
|
||||
json_writer_start_object(ms->vmdesc, NULL);
|
||||
json_writer_int64(ms->vmdesc, "page_size", qemu_target_page_size());
|
||||
json_writer_start_array(ms->vmdesc, "devices");
|
||||
|
||||
|
@@ -23,7 +23,7 @@ import argparse
|
||||
import collections
|
||||
import struct
|
||||
import sys
|
||||
|
||||
import math
|
||||
|
||||
def mkdir_p(path):
|
||||
try:
|
||||
@@ -119,11 +119,16 @@ class RamSection(object):
|
||||
self.file = file
|
||||
self.section_key = section_key
|
||||
self.TARGET_PAGE_SIZE = ramargs['page_size']
|
||||
self.TARGET_PAGE_BITS = math.log2(self.TARGET_PAGE_SIZE)
|
||||
self.dump_memory = ramargs['dump_memory']
|
||||
self.write_memory = ramargs['write_memory']
|
||||
self.fixed_ram = ramargs['fixed-ram']
|
||||
self.sizeinfo = collections.OrderedDict()
|
||||
self.bitmap_offset = collections.OrderedDict()
|
||||
self.pages_offset = collections.OrderedDict()
|
||||
self.data = collections.OrderedDict()
|
||||
self.data['section sizes'] = self.sizeinfo
|
||||
self.ram_read = False
|
||||
self.name = ''
|
||||
if self.write_memory:
|
||||
self.files = { }
|
||||
@@ -140,7 +145,13 @@ class RamSection(object):
|
||||
def getDict(self):
|
||||
return self.data
|
||||
|
||||
def write_or_dump_fixed_ram(self):
|
||||
pass
|
||||
|
||||
def read(self):
|
||||
if self.fixed_ram and self.ram_read:
|
||||
return
|
||||
|
||||
# Read all RAM sections
|
||||
while True:
|
||||
addr = self.file.read64()
|
||||
@@ -167,7 +178,26 @@ class RamSection(object):
|
||||
f.truncate(0)
|
||||
f.truncate(len)
|
||||
self.files[self.name] = f
|
||||
|
||||
if self.fixed_ram:
|
||||
bitmap_len = self.file.read32()
|
||||
# skip the pages_offset which we don't need
|
||||
offset = self.file.tell() + 8
|
||||
self.bitmap_offset[self.name] = offset
|
||||
offset = ((offset + bitmap_len + self.TARGET_PAGE_SIZE - 1) //
|
||||
self.TARGET_PAGE_SIZE) * self.TARGET_PAGE_SIZE
|
||||
self.pages_offset[self.name] = offset
|
||||
self.file.file.seek(offset + len)
|
||||
|
||||
flags &= ~self.RAM_SAVE_FLAG_MEM_SIZE
|
||||
if self.fixed_ram:
|
||||
self.ram_read = True
|
||||
# now we should rewind to the ram page offset of the first
|
||||
# ram section
|
||||
if self.fixed_ram:
|
||||
if self.write_memory or self.dump_memory:
|
||||
self.write_or_dump_fixed_ram()
|
||||
return
|
||||
|
||||
if flags & self.RAM_SAVE_FLAG_COMPRESS:
|
||||
if flags & self.RAM_SAVE_FLAG_CONTINUE:
|
||||
@@ -208,7 +238,7 @@ class RamSection(object):
|
||||
|
||||
# End of RAM section
|
||||
if flags & self.RAM_SAVE_FLAG_EOS:
|
||||
break
|
||||
return
|
||||
|
||||
if flags != 0:
|
||||
raise Exception("Unknown RAM flags: %x" % flags)
|
||||
@@ -521,6 +551,7 @@ class MigrationDump(object):
|
||||
ramargs['page_size'] = self.vmsd_desc['page_size']
|
||||
ramargs['dump_memory'] = dump_memory
|
||||
ramargs['write_memory'] = write_memory
|
||||
ramargs['fixed-ram'] = False
|
||||
self.section_classes[('ram',0)][1] = ramargs
|
||||
|
||||
while True:
|
||||
@@ -528,8 +559,20 @@ class MigrationDump(object):
|
||||
if section_type == self.QEMU_VM_EOF:
|
||||
break
|
||||
elif section_type == self.QEMU_VM_CONFIGURATION:
|
||||
section = ConfigurationSection(file)
|
||||
section.read()
|
||||
config_desc = self.vmsd_desc.get('configuration')
|
||||
if config_desc is not None:
|
||||
config = VMSDSection(file, 1, config_desc, 'configuration')
|
||||
config.read()
|
||||
caps = config.data.get("configuration/capabilities")
|
||||
if caps is not None:
|
||||
caps = caps.data["capabilities"]
|
||||
if type(caps) != list:
|
||||
caps = [caps]
|
||||
for i in caps:
|
||||
# chomp out string length
|
||||
cap = i.data[1:].decode("utf8")
|
||||
if cap == "fixed-ram":
|
||||
ramargs['fixed-ram'] = True
|
||||
elif section_type == self.QEMU_VM_SECTION_START or section_type == self.QEMU_VM_SECTION_FULL:
|
||||
section_id = file.read32()
|
||||
name = file.readstr()
|
||||
|
@@ -130,6 +130,25 @@ void migrate_qmp(QTestState *who, const char *uri, const char *fmt, ...)
|
||||
qobject_unref(rsp);
|
||||
}
|
||||
|
||||
|
||||
void migrate_incoming_qmp(QTestState *who, const char *uri, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
QDict *args, *rsp;
|
||||
|
||||
va_start(ap, fmt);
|
||||
args = qdict_from_vjsonf_nofail(fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
g_assert(!qdict_haskey(args, "uri"));
|
||||
qdict_put_str(args, "uri", uri);
|
||||
|
||||
rsp = qtest_qmp(who, "{ 'execute': 'migrate-incoming', 'arguments': %p}", args);
|
||||
|
||||
g_assert(qdict_haskey(rsp, "return"));
|
||||
qobject_unref(rsp);
|
||||
}
|
||||
|
||||
/*
|
||||
* Note: caller is responsible to free the returned object via
|
||||
* qobject_unref() after use
|
||||
|
@@ -31,6 +31,10 @@ QDict *qmp_command(QTestState *who, const char *command, ...);
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void migrate_qmp(QTestState *who, const char *uri, const char *fmt, ...);
|
||||
|
||||
G_GNUC_PRINTF(3, 4)
|
||||
void migrate_incoming_qmp(QTestState *who, const char *uri,
|
||||
const char *fmt, ...);
|
||||
|
||||
QDict *migrate_query(QTestState *who);
|
||||
QDict *migrate_query_not_failed(QTestState *who);
|
||||
|
||||
|
@@ -748,6 +748,7 @@ static void test_migrate_end(QTestState *from, QTestState *to, bool test_dest)
|
||||
cleanup("migsocket");
|
||||
cleanup("src_serial");
|
||||
cleanup("dest_serial");
|
||||
cleanup("migfile");
|
||||
}
|
||||
|
||||
#ifdef CONFIG_GNUTLS
|
||||
@@ -1371,6 +1372,14 @@ static void test_precopy_common(MigrateCommon *args)
|
||||
* hanging forever if migration didn't converge */
|
||||
wait_for_migration_complete(from);
|
||||
|
||||
/*
|
||||
* For file based migration the target must begin its migration after
|
||||
* the source has finished
|
||||
*/
|
||||
if (args->connect_uri && strstr(args->connect_uri, "file:")) {
|
||||
migrate_incoming_qmp(to, args->connect_uri, "{}");
|
||||
}
|
||||
|
||||
if (!got_stop) {
|
||||
qtest_qmp_eventwait(from, "STOP");
|
||||
}
|
||||
@@ -1524,6 +1533,17 @@ static void test_precopy_unix_xbzrle(void)
|
||||
test_precopy_common(&args);
|
||||
}
|
||||
|
||||
static void test_precopy_file_stream_ram(void)
|
||||
{
|
||||
g_autofree char *uri = g_strdup_printf("file:%s/migfile", tmpfs);
|
||||
MigrateCommon args = {
|
||||
.connect_uri = uri,
|
||||
.listen_uri = "defer",
|
||||
};
|
||||
|
||||
test_precopy_common(&args);
|
||||
}
|
||||
|
||||
static void test_precopy_tcp_plain(void)
|
||||
{
|
||||
MigrateCommon args = {
|
||||
@@ -2537,6 +2557,10 @@ int main(int argc, char **argv)
|
||||
qtest_add_func("/migration/bad_dest", test_baddest);
|
||||
qtest_add_func("/migration/precopy/unix/plain", test_precopy_unix_plain);
|
||||
qtest_add_func("/migration/precopy/unix/xbzrle", test_precopy_unix_xbzrle);
|
||||
|
||||
qtest_add_func("/migration/precopy/file/stream-ram",
|
||||
test_precopy_file_stream_ram);
|
||||
|
||||
#ifdef CONFIG_GNUTLS
|
||||
qtest_add_func("/migration/precopy/unix/tls/psk",
|
||||
test_precopy_unix_tls_psk);
|
||||
|
Reference in New Issue
Block a user