Compare commits
16 Commits
qdev-array
...
fixed-ram-
Author | SHA1 | Date | |
---|---|---|---|
|
a0efb212fb | ||
|
9e086f2e2a | ||
|
cc57d6c75f | ||
|
c204cfeeb7 | ||
|
d5cd94bbaf | ||
|
4c2f145632 | ||
|
fb56e2387b | ||
|
5686566113 | ||
|
4c16cca0e1 | ||
|
895c40ce0a | ||
|
cad3bc2be3 | ||
|
ea1efd3d17 | ||
|
3ce4e2e8d5 | ||
|
c1eef47d79 | ||
|
80f68f67a9 | ||
|
4ed18df9df |
@@ -43,6 +43,14 @@ struct RAMBlock {
|
||||
size_t page_size;
|
||||
/* dirty bitmap used during migration */
|
||||
unsigned long *bmap;
|
||||
/* shadow dirty bitmap used when migrating to a file */
|
||||
unsigned long *shadow_bmap;
|
||||
/*
|
||||
* offset in the file pages belonging to this ramblock are saved,
|
||||
* used only during migration to a file.
|
||||
*/
|
||||
off_t bitmap_offset;
|
||||
uint64_t pages_offset;
|
||||
/* bitmap of already received pages in postcopy */
|
||||
unsigned long *receivedmap;
|
||||
|
||||
|
@@ -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_io_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_io_pwritev_full(QIOChannel *ioc, const struct iovec *iov,
|
||||
size_t niov, off_t offset, Error **errp);
|
||||
|
||||
/**
|
||||
* qio_channel_io_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_io_pwritev(QIOChannel *ioc, char *buf, size_t buflen,
|
||||
off_t offset, Error **errp);
|
||||
|
||||
/**
|
||||
* qio_channel_io_preadv
|
||||
* @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_io_preadv_full(QIOChannel *ioc, const struct iovec *iov,
|
||||
size_t niov, off_t offset, Error **errp);
|
||||
|
||||
/**
|
||||
* qio_channel_io_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_io_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_io_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_io_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_io_pwritev_full(ioc, &iov, 1, offset, errp);
|
||||
}
|
||||
|
||||
ssize_t qio_channel_io_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_io_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_io_preadv_full(ioc, &iov, 1, offset, errp);
|
||||
}
|
||||
|
||||
int qio_channel_shutdown(QIOChannel *ioc,
|
||||
QIOChannelShutdown how,
|
||||
Error **errp)
|
||||
|
38
migration/file.c
Normal file
38
migration/file.c
Normal file
@@ -0,0 +1,38 @@
|
||||
#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.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"
|
||||
@@ -167,7 +168,8 @@ INITIALIZE_MIGRATE_CAPS_SET(check_caps_background_snapshot,
|
||||
MIGRATION_CAPABILITY_XBZRLE,
|
||||
MIGRATION_CAPABILITY_X_COLO,
|
||||
MIGRATION_CAPABILITY_VALIDATE_UUID,
|
||||
MIGRATION_CAPABILITY_ZERO_COPY_SEND);
|
||||
MIGRATION_CAPABILITY_ZERO_COPY_SEND,
|
||||
MIGRATION_CAPABILITY_FIXED_RAM);
|
||||
|
||||
/* When we add fault tolerance, we could have several
|
||||
migrations at once. For now we don't need to add
|
||||
@@ -526,6 +528,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);
|
||||
}
|
||||
@@ -1338,6 +1342,28 @@ static bool migrate_caps_check(bool *cap_list,
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cap_list[MIGRATION_CAPABILITY_FIXED_RAM]) {
|
||||
if (cap_list[MIGRATION_CAPABILITY_MULTIFD]) {
|
||||
error_setg(errp, "Directly mapped memory incompatible with multifd");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cap_list[MIGRATION_CAPABILITY_XBZRLE]) {
|
||||
error_setg(errp, "Directly mapped memory incompatible with xbzrle");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cap_list[MIGRATION_CAPABILITY_COMPRESS]) {
|
||||
error_setg(errp, "Directly mapped memory incompatible with compression");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cap_list[MIGRATION_CAPABILITY_POSTCOPY_RAM]) {
|
||||
error_setg(errp, "Directly mapped memory incompatible with postcopy ram");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (cap_list[MIGRATION_CAPABILITY_POSTCOPY_RAM]) {
|
||||
/* This check is reasonably expensive, so only when it's being
|
||||
* set the first time, also it's only the destination that needs
|
||||
@@ -2257,6 +2283,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);
|
||||
|
||||
@@ -2523,6 +2550,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);
|
||||
@@ -2730,6 +2759,11 @@ MultiFDCompression migrate_multifd_compression(void)
|
||||
return s->parameters.multifd_compression;
|
||||
}
|
||||
|
||||
int migrate_fixed_ram(void)
|
||||
{
|
||||
return migrate_get_current()->enabled_capabilities[MIGRATION_CAPABILITY_FIXED_RAM];
|
||||
}
|
||||
|
||||
int migrate_multifd_zlib_level(void)
|
||||
{
|
||||
MigrationState *s;
|
||||
@@ -3777,7 +3811,7 @@ static uint64_t migration_total_bytes(MigrationState *s)
|
||||
ram_counters.multifd_bytes;
|
||||
}
|
||||
|
||||
static void migration_calculate_complete(MigrationState *s)
|
||||
void migration_calculate_complete(MigrationState *s)
|
||||
{
|
||||
uint64_t bytes = migration_total_bytes(s);
|
||||
int64_t end_time = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
|
||||
@@ -3809,7 +3843,7 @@ static void update_iteration_initial_status(MigrationState *s)
|
||||
s->iteration_initial_pages = ram_get_total_transferred_pages();
|
||||
}
|
||||
|
||||
static void migration_update_counters(MigrationState *s,
|
||||
void migration_update_counters(MigrationState *s,
|
||||
int64_t current_time)
|
||||
{
|
||||
uint64_t transferred, transferred_pages, time_spent;
|
||||
@@ -3867,6 +3901,8 @@ static MigIterateState migration_iteration_run(MigrationState *s)
|
||||
bool in_postcopy = s->state == MIGRATION_STATUS_POSTCOPY_ACTIVE;
|
||||
|
||||
qemu_savevm_state_pending_estimate(&must_precopy, &can_postcopy);
|
||||
migration_update_counters(s, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
|
||||
|
||||
uint64_t pending_size = must_precopy + can_postcopy;
|
||||
|
||||
trace_migrate_pending_estimate(pending_size, must_precopy, can_postcopy);
|
||||
@@ -3907,6 +3943,9 @@ static void migration_iteration_finish(MigrationState *s)
|
||||
case MIGRATION_STATUS_COMPLETED:
|
||||
migration_calculate_complete(s);
|
||||
runstate_set(RUN_STATE_POSTMIGRATE);
|
||||
trace_migration_status((int)s->mbps / 8, (int)s->pages_per_second, s->total_time,
|
||||
qemu_file_total_transferred(s->to_dst_file));
|
||||
|
||||
break;
|
||||
case MIGRATION_STATUS_COLO:
|
||||
if (!migrate_colo_enabled()) {
|
||||
@@ -4318,6 +4357,19 @@ fail:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int migrate_check_fixed_ram(MigrationState *s, Error **errp)
|
||||
{
|
||||
if (!s->enabled_capabilities[MIGRATION_CAPABILITY_FIXED_RAM])
|
||||
return 0;
|
||||
|
||||
if (!qemu_file_is_seekable(s->to_dst_file)) {
|
||||
error_setg(errp, "Directly mapped memory requires a seekable transport");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void migrate_fd_connect(MigrationState *s, Error *error_in)
|
||||
{
|
||||
Error *local_err = NULL;
|
||||
@@ -4384,6 +4436,12 @@ void migrate_fd_connect(MigrationState *s, Error *error_in)
|
||||
}
|
||||
}
|
||||
|
||||
if (migrate_check_fixed_ram(s, &local_err) < 0) {
|
||||
migrate_fd_cleanup(s);
|
||||
migrate_fd_error(s, local_err);
|
||||
return;
|
||||
}
|
||||
|
||||
if (resume) {
|
||||
/* Wakeup the main migration thread to do the recovery */
|
||||
migrate_set_state(&s->state, MIGRATION_STATUS_POSTCOPY_PAUSED,
|
||||
@@ -4513,6 +4571,7 @@ static Property migration_properties[] = {
|
||||
DEFINE_PROP_STRING("tls-authz", MigrationState, parameters.tls_authz),
|
||||
|
||||
/* Migration capabilities */
|
||||
DEFINE_PROP_MIG_CAP("x-fixed-ram", MIGRATION_CAPABILITY_FIXED_RAM),
|
||||
DEFINE_PROP_MIG_CAP("x-xbzrle", MIGRATION_CAPABILITY_XBZRLE),
|
||||
DEFINE_PROP_MIG_CAP("x-rdma-pin-all", MIGRATION_CAPABILITY_RDMA_PIN_ALL),
|
||||
DEFINE_PROP_MIG_CAP("x-auto-converge", MIGRATION_CAPABILITY_AUTO_CONVERGE),
|
||||
|
@@ -96,6 +96,8 @@ struct MigrationIncomingState {
|
||||
bool have_listen_thread;
|
||||
QemuThread listen_thread;
|
||||
|
||||
bool ram_migrated;
|
||||
|
||||
/* For the kernel to send us notifications */
|
||||
int userfault_fd;
|
||||
/* To notify the fault_thread to wake, e.g., when need to quit */
|
||||
@@ -385,7 +387,9 @@ struct MigrationState {
|
||||
};
|
||||
|
||||
void migrate_set_state(int *state, int old_state, int new_state);
|
||||
|
||||
void migration_calculate_complete(MigrationState *s);
|
||||
void migration_update_counters(MigrationState *s,
|
||||
int64_t current_time);
|
||||
void migration_fd_process_incoming(QEMUFile *f, Error **errp);
|
||||
void migration_ioc_process_incoming(QIOChannel *ioc, Error **errp);
|
||||
void migration_incoming_process(void);
|
||||
@@ -416,6 +420,7 @@ bool migrate_zero_blocks(void);
|
||||
bool migrate_dirty_bitmaps(void);
|
||||
bool migrate_ignore_shared(void);
|
||||
bool migrate_validate_uuid(void);
|
||||
int migrate_fixed_ram(void);
|
||||
|
||||
bool migrate_auto_converge(void);
|
||||
bool migrate_use_multifd(void);
|
||||
|
@@ -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)
|
||||
@@ -281,6 +282,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
|
||||
@@ -559,6 +564,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_io_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_io_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);
|
||||
|
320
migration/ram.c
320
migration/ram.c
@@ -1310,9 +1310,14 @@ static int save_zero_page_to_file(PageSearchStatus *pss,
|
||||
int len = 0;
|
||||
|
||||
if (buffer_is_zero(p, TARGET_PAGE_SIZE)) {
|
||||
len += save_page_header(pss, block, offset | RAM_SAVE_FLAG_ZERO);
|
||||
qemu_put_byte(file, 0);
|
||||
len += 1;
|
||||
if (migrate_fixed_ram()) {
|
||||
/* for zero pages we don't need to do anything */
|
||||
len = 1;
|
||||
} else {
|
||||
len += save_page_header(pss, block, offset | RAM_SAVE_FLAG_ZERO);
|
||||
qemu_put_byte(file, 0);
|
||||
len += 1;
|
||||
}
|
||||
ram_release_page(block->idstr, offset);
|
||||
}
|
||||
return len;
|
||||
@@ -1394,14 +1399,20 @@ static int save_normal_page(PageSearchStatus *pss, RAMBlock *block,
|
||||
{
|
||||
QEMUFile *file = pss->pss_channel;
|
||||
|
||||
ram_transferred_add(save_page_header(pss, block,
|
||||
offset | RAM_SAVE_FLAG_PAGE));
|
||||
if (async) {
|
||||
qemu_put_buffer_async(file, buf, TARGET_PAGE_SIZE,
|
||||
migrate_release_ram() &&
|
||||
migration_in_postcopy());
|
||||
if (migrate_fixed_ram()) {
|
||||
qemu_put_buffer_at(file, buf, TARGET_PAGE_SIZE,
|
||||
block->pages_offset + offset);
|
||||
set_bit(offset >> TARGET_PAGE_BITS, block->shadow_bmap);
|
||||
} else {
|
||||
qemu_put_buffer(file, buf, TARGET_PAGE_SIZE);
|
||||
ram_transferred_add(save_page_header(pss, block,
|
||||
offset | RAM_SAVE_FLAG_PAGE));
|
||||
if (async) {
|
||||
qemu_put_buffer_async(file, buf, TARGET_PAGE_SIZE,
|
||||
migrate_release_ram() &&
|
||||
migration_in_postcopy());
|
||||
} else {
|
||||
qemu_put_buffer(file, buf, TARGET_PAGE_SIZE);
|
||||
}
|
||||
}
|
||||
ram_transferred_add(TARGET_PAGE_SIZE);
|
||||
stat64_add(&ram_atomic_counters.normal, 1);
|
||||
@@ -2731,6 +2742,8 @@ static void ram_save_cleanup(void *opaque)
|
||||
block->clear_bmap = NULL;
|
||||
g_free(block->bmap);
|
||||
block->bmap = NULL;
|
||||
g_free(block->shadow_bmap);
|
||||
block->shadow_bmap = NULL;
|
||||
}
|
||||
|
||||
xbzrle_cleanup();
|
||||
@@ -3098,6 +3111,7 @@ static void ram_list_init_bitmaps(void)
|
||||
*/
|
||||
block->bmap = bitmap_new(pages);
|
||||
bitmap_set(block->bmap, 0, pages);
|
||||
block->shadow_bmap = bitmap_new(block->used_length >> TARGET_PAGE_BITS);
|
||||
block->clear_bmap_shift = shift;
|
||||
block->clear_bmap = bitmap_new(clear_bmap_size(pages, shift));
|
||||
}
|
||||
@@ -3287,6 +3301,28 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
|
||||
if (migrate_ignore_shared()) {
|
||||
qemu_put_be64(f, block->mr->addr);
|
||||
}
|
||||
|
||||
if (migrate_fixed_ram()) {
|
||||
long num_pages = block->used_length >> TARGET_PAGE_BITS;
|
||||
long bitmap_size = BITS_TO_LONGS(num_pages) * sizeof(unsigned long);
|
||||
|
||||
|
||||
/* Needed for external programs (think analyze-migration.py) */
|
||||
qemu_put_be32(f, bitmap_size);
|
||||
|
||||
/*
|
||||
* Make pages offset aligned to TARGET_PAGE_SIZE to enable
|
||||
* DIO in the future. Also add 8 to account for the page offset
|
||||
* itself
|
||||
*/
|
||||
block->bitmap_offset = qemu_get_offset(f) + 8;
|
||||
block->pages_offset = ROUND_UP(block->bitmap_offset +
|
||||
bitmap_size, TARGET_PAGE_SIZE);
|
||||
qemu_put_be64(f, block->pages_offset);
|
||||
|
||||
/* Now prepare offset for next ramblock */
|
||||
qemu_set_offset(f, block->pages_offset + block->used_length, SEEK_SET);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3306,6 +3342,18 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ram_save_shadow_bmap(QEMUFile *f)
|
||||
{
|
||||
RAMBlock *block;
|
||||
|
||||
RAMBLOCK_FOREACH_MIGRATABLE(block) {
|
||||
long num_pages = block->used_length >> TARGET_PAGE_BITS;
|
||||
long bitmap_size = BITS_TO_LONGS(num_pages) * sizeof(unsigned long);
|
||||
qemu_put_buffer_at(f, (uint8_t *)block->shadow_bmap, bitmap_size,
|
||||
block->bitmap_offset);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* ram_save_iterate: iterative stage for migration
|
||||
*
|
||||
@@ -3413,9 +3461,15 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
|
||||
qemu_fflush(f);
|
||||
ram_transferred_add(8);
|
||||
/*
|
||||
* For fixed ram we don't want to pollute the migration stream with
|
||||
* EOS flags.
|
||||
*/
|
||||
if (!migrate_fixed_ram()) {
|
||||
qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
|
||||
qemu_fflush(f);
|
||||
ram_transferred_add(8);
|
||||
}
|
||||
|
||||
ret = qemu_file_get_error(f);
|
||||
}
|
||||
@@ -3461,6 +3515,9 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
|
||||
pages = ram_find_and_save_block(rs);
|
||||
/* no more blocks to sent */
|
||||
if (pages == 0) {
|
||||
if (migrate_fixed_ram()) {
|
||||
ram_save_shadow_bmap(f);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (pages < 0) {
|
||||
@@ -3483,8 +3540,10 @@ static int ram_save_complete(QEMUFile *f, void *opaque)
|
||||
return ret;
|
||||
}
|
||||
|
||||
qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
|
||||
qemu_fflush(f);
|
||||
if (!migrate_fixed_ram()) {
|
||||
qemu_put_be64(f, RAM_SAVE_FLAG_EOS);
|
||||
qemu_fflush(f);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -4255,6 +4314,167 @@ void colo_flush_ram_cache(void)
|
||||
trace_colo_flush_ram_cache_end();
|
||||
}
|
||||
|
||||
static int parse_ramblock(QEMUFile *f, RAMBlock *block, ram_addr_t length)
|
||||
{
|
||||
int ret = 0;
|
||||
/* ADVISE is earlier, it shows the source has the postcopy capability on */
|
||||
bool postcopy_advised = migration_incoming_postcopy_advised();
|
||||
|
||||
assert(block);
|
||||
|
||||
if (!qemu_ram_is_migratable(block)) {
|
||||
error_report("block %s should not be migrated !", block->idstr);
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
||||
if (length != block->used_length) {
|
||||
Error *local_err = NULL;
|
||||
|
||||
ret = qemu_ram_resize(block, length, &local_err);
|
||||
if (local_err) {
|
||||
error_report_err(local_err);
|
||||
}
|
||||
}
|
||||
/* For postcopy we need to check hugepage sizes match */
|
||||
if (postcopy_advised && migrate_postcopy_ram() &&
|
||||
block->page_size != qemu_host_page_size) {
|
||||
uint64_t remote_page_size = qemu_get_be64(f);
|
||||
if (remote_page_size != block->page_size) {
|
||||
error_report("Mismatched RAM page size %s "
|
||||
"(local) %zd != %" PRId64, block->idstr,
|
||||
block->page_size, remote_page_size);
|
||||
ret = -EINVAL;
|
||||
}
|
||||
}
|
||||
if (migrate_ignore_shared()) {
|
||||
hwaddr addr = qemu_get_be64(f);
|
||||
if (ramblock_is_ignored(block) &&
|
||||
block->mr->addr != addr) {
|
||||
error_report("Mismatched GPAs for block %s "
|
||||
"%" PRId64 "!= %" PRId64, block->idstr,
|
||||
(uint64_t)addr,
|
||||
(uint64_t)block->mr->addr);
|
||||
ret = -EINVAL;
|
||||
}
|
||||
}
|
||||
ram_control_load_hook(f, RAM_CONTROL_BLOCK_REG, block->idstr);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int parse_ramblocks(QEMUFile *f, ram_addr_t total_ram_bytes)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
/* Synchronize RAM block list */
|
||||
while (!ret && total_ram_bytes) {
|
||||
char id[256];
|
||||
RAMBlock *block;
|
||||
ram_addr_t length;
|
||||
int len = qemu_get_byte(f);
|
||||
|
||||
qemu_get_buffer(f, (uint8_t *)id, len);
|
||||
id[len] = 0;
|
||||
length = qemu_get_be64(f);
|
||||
|
||||
block = qemu_ram_block_by_name(id);
|
||||
if (block) {
|
||||
ret = parse_ramblock(f, block, length);
|
||||
} else {
|
||||
error_report("Unknown ramblock \"%s\", cannot accept "
|
||||
"migration", id);
|
||||
ret = -EINVAL;
|
||||
}
|
||||
total_ram_bytes -= length;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static int parse_ramblocks_fixed_ram(QEMUFile *f)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
while (!ret) {
|
||||
char id[256];
|
||||
RAMBlock *block;
|
||||
ram_addr_t length;
|
||||
unsigned long clear_bit_idx;
|
||||
long num_pages, bitmap_size;
|
||||
int len = qemu_get_byte(f);
|
||||
g_autofree unsigned long *dirty_bitmap = NULL;
|
||||
|
||||
qemu_get_buffer(f, (uint8_t *)id, len);
|
||||
id[len] = 0;
|
||||
length = qemu_get_be64(f);
|
||||
|
||||
block = qemu_ram_block_by_name(id);
|
||||
if (block) {
|
||||
ret = parse_ramblock(f, block, length);
|
||||
if (ret < 0) {
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
error_report("Unknown ramblock \"%s\", cannot accept "
|
||||
"migration", id);
|
||||
ret = -EINVAL;
|
||||
continue;
|
||||
}
|
||||
|
||||
/* 1. read the bitmap size */
|
||||
num_pages = length >> TARGET_PAGE_BITS;
|
||||
bitmap_size = qemu_get_be32(f);
|
||||
|
||||
assert(bitmap_size == BITS_TO_LONGS(num_pages)*sizeof(unsigned long));
|
||||
|
||||
block->pages_offset = qemu_get_be64(f);
|
||||
|
||||
/* 2. read the actual bitmap */
|
||||
dirty_bitmap = g_malloc0(bitmap_size);
|
||||
if (qemu_get_buffer(f, (uint8_t *)dirty_bitmap, bitmap_size) != bitmap_size) {
|
||||
error_report("Error parsing dirty bitmap");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
#define BUFSIZE (4*1024*1024)
|
||||
for (unsigned long set_bit_idx = find_first_bit(dirty_bitmap, num_pages);
|
||||
set_bit_idx < num_pages;
|
||||
set_bit_idx = find_next_bit(dirty_bitmap, num_pages, clear_bit_idx + 1)) {
|
||||
|
||||
clear_bit_idx = find_next_zero_bit(dirty_bitmap, num_pages, set_bit_idx + 1);
|
||||
unsigned long len = TARGET_PAGE_SIZE * (clear_bit_idx - set_bit_idx);
|
||||
ram_addr_t offset = set_bit_idx << TARGET_PAGE_BITS;
|
||||
|
||||
for (size_t read = 0, completed = 0; completed < len; offset += read) {
|
||||
void *host = host_from_ram_block_offset(block, offset);
|
||||
size_t read_len = MIN(len, BUFSIZE);
|
||||
|
||||
read = qemu_get_buffer_at(f, host, read_len,
|
||||
block->pages_offset + offset);
|
||||
completed += read;
|
||||
}
|
||||
}
|
||||
|
||||
/* Skip pages array */
|
||||
qemu_set_offset(f, block->pages_offset + length, SEEK_SET);
|
||||
|
||||
/* Check if this is the last ramblock */
|
||||
if (qemu_get_be64(f) == RAM_SAVE_FLAG_EOS) {
|
||||
ret = 1;
|
||||
} else {
|
||||
/*
|
||||
* If not, adjust the internal file index to account for the
|
||||
* previous 64 bit read
|
||||
*/
|
||||
qemu_file_skip(f, -8);
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* ram_load_precopy: load pages in precopy case
|
||||
*
|
||||
@@ -4269,14 +4489,13 @@ static int ram_load_precopy(QEMUFile *f)
|
||||
{
|
||||
MigrationIncomingState *mis = migration_incoming_get_current();
|
||||
int flags = 0, ret = 0, invalid_flags = 0, len = 0, i = 0;
|
||||
/* ADVISE is earlier, it shows the source has the postcopy capability on */
|
||||
bool postcopy_advised = migration_incoming_postcopy_advised();
|
||||
|
||||
if (!migrate_use_compression()) {
|
||||
invalid_flags |= RAM_SAVE_FLAG_COMPRESS_PAGE;
|
||||
}
|
||||
|
||||
while (!ret && !(flags & RAM_SAVE_FLAG_EOS)) {
|
||||
ram_addr_t addr, total_ram_bytes;
|
||||
while (!ret && !(flags & RAM_SAVE_FLAG_EOS) && !mis->ram_migrated) {
|
||||
ram_addr_t addr;
|
||||
void *host = NULL, *host_bak = NULL;
|
||||
uint8_t ch;
|
||||
|
||||
@@ -4347,64 +4566,13 @@ static int ram_load_precopy(QEMUFile *f)
|
||||
|
||||
switch (flags & ~RAM_SAVE_FLAG_CONTINUE) {
|
||||
case RAM_SAVE_FLAG_MEM_SIZE:
|
||||
/* Synchronize RAM block list */
|
||||
total_ram_bytes = addr;
|
||||
while (!ret && total_ram_bytes) {
|
||||
RAMBlock *block;
|
||||
char id[256];
|
||||
ram_addr_t length;
|
||||
|
||||
len = qemu_get_byte(f);
|
||||
qemu_get_buffer(f, (uint8_t *)id, len);
|
||||
id[len] = 0;
|
||||
length = qemu_get_be64(f);
|
||||
|
||||
block = qemu_ram_block_by_name(id);
|
||||
if (block && !qemu_ram_is_migratable(block)) {
|
||||
error_report("block %s should not be migrated !", id);
|
||||
ret = -EINVAL;
|
||||
} else if (block) {
|
||||
if (length != block->used_length) {
|
||||
Error *local_err = NULL;
|
||||
|
||||
ret = qemu_ram_resize(block, length,
|
||||
&local_err);
|
||||
if (local_err) {
|
||||
error_report_err(local_err);
|
||||
}
|
||||
}
|
||||
/* For postcopy we need to check hugepage sizes match */
|
||||
if (postcopy_advised && migrate_postcopy_ram() &&
|
||||
block->page_size != qemu_host_page_size) {
|
||||
uint64_t remote_page_size = qemu_get_be64(f);
|
||||
if (remote_page_size != block->page_size) {
|
||||
error_report("Mismatched RAM page size %s "
|
||||
"(local) %zd != %" PRId64,
|
||||
id, block->page_size,
|
||||
remote_page_size);
|
||||
ret = -EINVAL;
|
||||
}
|
||||
}
|
||||
if (migrate_ignore_shared()) {
|
||||
hwaddr addr = qemu_get_be64(f);
|
||||
if (ramblock_is_ignored(block) &&
|
||||
block->mr->addr != addr) {
|
||||
error_report("Mismatched GPAs for block %s "
|
||||
"%" PRId64 "!= %" PRId64,
|
||||
id, (uint64_t)addr,
|
||||
(uint64_t)block->mr->addr);
|
||||
ret = -EINVAL;
|
||||
}
|
||||
}
|
||||
ram_control_load_hook(f, RAM_CONTROL_BLOCK_REG,
|
||||
block->idstr);
|
||||
} else {
|
||||
error_report("Unknown ramblock \"%s\", cannot "
|
||||
"accept migration", id);
|
||||
ret = -EINVAL;
|
||||
if (migrate_fixed_ram()) {
|
||||
ret = parse_ramblocks_fixed_ram(f);
|
||||
if (ret == 1) {
|
||||
mis->ram_migrated = true;
|
||||
}
|
||||
|
||||
total_ram_bytes -= length;
|
||||
} else {
|
||||
ret = parse_ramblocks(f, addr);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@@ -241,6 +241,7 @@ static bool should_validate_capability(int capability)
|
||||
/* Validate only new capabilities to keep compatibility. */
|
||||
switch (capability) {
|
||||
case MIGRATION_CAPABILITY_X_IGNORE_SHARED:
|
||||
case MIGRATION_CAPABILITY_FIXED_RAM:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
@@ -1206,13 +1207,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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1237,8 +1250,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");
|
||||
|
||||
@@ -1627,6 +1638,7 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
|
||||
qemu_mutex_lock_iothread();
|
||||
|
||||
while (qemu_file_get_error(f) == 0) {
|
||||
migration_update_counters(ms, qemu_clock_get_ms(QEMU_CLOCK_REALTIME));
|
||||
if (qemu_savevm_state_iterate(f, false) > 0) {
|
||||
break;
|
||||
}
|
||||
@@ -1649,6 +1661,10 @@ static int qemu_savevm_state(QEMUFile *f, Error **errp)
|
||||
}
|
||||
migrate_set_state(&ms->state, MIGRATION_STATUS_SETUP, status);
|
||||
|
||||
migration_calculate_complete(ms);
|
||||
trace_migration_status((int)ms->mbps / 8, (int)ms->pages_per_second, ms->total_time,
|
||||
qemu_file_total_transferred_fast(f));
|
||||
|
||||
/* f is outer parameter, it should not stay in global migration state after
|
||||
* this function finished */
|
||||
ms->to_dst_file = NULL;
|
||||
|
@@ -165,6 +165,7 @@ migration_return_path_end_after(int rp_error) "%d"
|
||||
migration_thread_after_loop(void) ""
|
||||
migration_thread_file_err(void) ""
|
||||
migration_thread_setup_complete(void) ""
|
||||
migration_status(int mpbs, int pages_per_second, int64_t total_time, int64_t total_bytes) "%d MB/s, %d pages/s, %ld ms %ld B"
|
||||
open_return_path_on_source(void) ""
|
||||
open_return_path_on_source_continue(void) ""
|
||||
postcopy_start(void) ""
|
||||
|
@@ -485,7 +485,7 @@
|
||||
##
|
||||
{ 'enum': 'MigrationCapability',
|
||||
'data': ['xbzrle', 'rdma-pin-all', 'auto-converge', 'zero-blocks',
|
||||
'compress', 'events', 'postcopy-ram',
|
||||
'compress', 'events', 'postcopy-ram', 'fixed-ram',
|
||||
{ 'name': 'x-colo', 'features': [ 'unstable' ] },
|
||||
'release-ram',
|
||||
'block', 'return-path', 'pause-before-switchover', 'multifd',
|
||||
|
@@ -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,37 @@ 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_migrate_fixed_ram_start(QTestState *from, QTestState *to)
|
||||
{
|
||||
migrate_set_capability(from, "fixed-ram", true);
|
||||
migrate_set_capability(to, "fixed-ram", true);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void test_precopy_file_fixed_ram(void)
|
||||
{
|
||||
g_autofree char *uri = g_strdup_printf("file:%s/migfile", tmpfs);
|
||||
MigrateCommon args = {
|
||||
.connect_uri = uri,
|
||||
.listen_uri = "defer",
|
||||
.start_hook = test_migrate_fixed_ram_start,
|
||||
};
|
||||
|
||||
test_precopy_common(&args);
|
||||
}
|
||||
|
||||
static void test_precopy_tcp_plain(void)
|
||||
{
|
||||
MigrateCommon args = {
|
||||
@@ -2508,6 +2548,12 @@ 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);
|
||||
qtest_add_func("/migration/precopy/file/fixed-ram",
|
||||
test_precopy_file_fixed_ram);
|
||||
|
||||
#ifdef CONFIG_GNUTLS
|
||||
qtest_add_func("/migration/precopy/unix/tls/psk",
|
||||
test_precopy_unix_tls_psk);
|
||||
|
Reference in New Issue
Block a user