migration: convert post-copy to use QIOChannelBuffer
The post-copy code does some I/O to/from an intermediate in-memory buffer rather than direct to the underlying I/O channel. Switch this code to use QIOChannelBuffer instead of QEMUSizedBuffer. Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> Signed-off-by: Daniel P. Berrange <berrange@redhat.com> Message-Id: <1461751518-12128-12-git-send-email-berrange@redhat.com> Signed-off-by: Amit Shah <amit.shah@redhat.com>
This commit is contained in:
parent
d59ce6f344
commit
61b67d473d
@ -403,8 +403,8 @@ listen thread: --- page -- page -- page -- page -- page --
|
|||||||
|
|
||||||
On receipt of CMD_PACKAGED (1)
|
On receipt of CMD_PACKAGED (1)
|
||||||
All the data associated with the package - the ( ... ) section in the
|
All the data associated with the package - the ( ... ) section in the
|
||||||
diagram - is read into memory (into a QEMUSizedBuffer), and the main thread
|
diagram - is read into memory, and the main thread recurses into
|
||||||
recurses into qemu_loadvm_state_main to process the contents of the package (2)
|
qemu_loadvm_state_main to process the contents of the package (2)
|
||||||
which contains commands (3,6) and devices (4...)
|
which contains commands (3,6) and devices (4...)
|
||||||
|
|
||||||
On receipt of 'postcopy listen' - 3 -(i.e. the 1st command in the package)
|
On receipt of 'postcopy listen' - 3 -(i.e. the 1st command in the package)
|
||||||
|
@ -119,7 +119,7 @@ void qemu_savevm_command_send(QEMUFile *f, enum qemu_vm_cmd command,
|
|||||||
uint16_t len, uint8_t *data);
|
uint16_t len, uint8_t *data);
|
||||||
void qemu_savevm_send_ping(QEMUFile *f, uint32_t value);
|
void qemu_savevm_send_ping(QEMUFile *f, uint32_t value);
|
||||||
void qemu_savevm_send_open_return_path(QEMUFile *f);
|
void qemu_savevm_send_open_return_path(QEMUFile *f);
|
||||||
int qemu_savevm_send_packaged(QEMUFile *f, const QEMUSizedBuffer *qsb);
|
int qemu_savevm_send_packaged(QEMUFile *f, const uint8_t *buf, size_t len);
|
||||||
void qemu_savevm_send_postcopy_advise(QEMUFile *f);
|
void qemu_savevm_send_postcopy_advise(QEMUFile *f);
|
||||||
void qemu_savevm_send_postcopy_listen(QEMUFile *f);
|
void qemu_savevm_send_postcopy_listen(QEMUFile *f);
|
||||||
void qemu_savevm_send_postcopy_run(QEMUFile *f);
|
void qemu_savevm_send_postcopy_run(QEMUFile *f);
|
||||||
|
@ -34,6 +34,7 @@
|
|||||||
#include "qom/cpu.h"
|
#include "qom/cpu.h"
|
||||||
#include "exec/memory.h"
|
#include "exec/memory.h"
|
||||||
#include "exec/address-spaces.h"
|
#include "exec/address-spaces.h"
|
||||||
|
#include "io/channel-buffer.h"
|
||||||
|
|
||||||
#define MAX_THROTTLE (32 << 20) /* Migration transfer speed throttling */
|
#define MAX_THROTTLE (32 << 20) /* Migration transfer speed throttling */
|
||||||
|
|
||||||
@ -1457,7 +1458,8 @@ static int await_return_path_close_on_source(MigrationState *ms)
|
|||||||
static int postcopy_start(MigrationState *ms, bool *old_vm_running)
|
static int postcopy_start(MigrationState *ms, bool *old_vm_running)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
const QEMUSizedBuffer *qsb;
|
QIOChannelBuffer *bioc;
|
||||||
|
QEMUFile *fb;
|
||||||
int64_t time_at_stop = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
|
int64_t time_at_stop = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
|
||||||
migrate_set_state(&ms->state, MIGRATION_STATUS_ACTIVE,
|
migrate_set_state(&ms->state, MIGRATION_STATUS_ACTIVE,
|
||||||
MIGRATION_STATUS_POSTCOPY_ACTIVE);
|
MIGRATION_STATUS_POSTCOPY_ACTIVE);
|
||||||
@ -1516,11 +1518,9 @@ static int postcopy_start(MigrationState *ms, bool *old_vm_running)
|
|||||||
* So we wrap the device state up in a package with a length at the start;
|
* So we wrap the device state up in a package with a length at the start;
|
||||||
* to do this we use a qemu_buf to hold the whole of the device state.
|
* to do this we use a qemu_buf to hold the whole of the device state.
|
||||||
*/
|
*/
|
||||||
QEMUFile *fb = qemu_bufopen("w", NULL);
|
bioc = qio_channel_buffer_new(4096);
|
||||||
if (!fb) {
|
fb = qemu_fopen_channel_output(QIO_CHANNEL(bioc));
|
||||||
error_report("Failed to create buffered file");
|
object_unref(OBJECT(bioc));
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Make sure the receiver can get incoming pages before we send the rest
|
* Make sure the receiver can get incoming pages before we send the rest
|
||||||
@ -1534,10 +1534,9 @@ static int postcopy_start(MigrationState *ms, bool *old_vm_running)
|
|||||||
qemu_savevm_send_postcopy_run(fb);
|
qemu_savevm_send_postcopy_run(fb);
|
||||||
|
|
||||||
/* <><> end of stuff going into the package */
|
/* <><> end of stuff going into the package */
|
||||||
qsb = qemu_buf_get(fb);
|
|
||||||
|
|
||||||
/* Now send that blob */
|
/* Now send that blob */
|
||||||
if (qemu_savevm_send_packaged(ms->to_dst_file, qsb)) {
|
if (qemu_savevm_send_packaged(ms->to_dst_file, bioc->data, bioc->usage)) {
|
||||||
goto fail_closefb;
|
goto fail_closefb;
|
||||||
}
|
}
|
||||||
qemu_fclose(fb);
|
qemu_fclose(fb);
|
||||||
|
@ -51,6 +51,7 @@
|
|||||||
#include "block/snapshot.h"
|
#include "block/snapshot.h"
|
||||||
#include "block/qapi.h"
|
#include "block/qapi.h"
|
||||||
#include "qemu/cutils.h"
|
#include "qemu/cutils.h"
|
||||||
|
#include "io/channel-buffer.h"
|
||||||
|
|
||||||
#ifndef ETH_P_RARP
|
#ifndef ETH_P_RARP
|
||||||
#define ETH_P_RARP 0x8035
|
#define ETH_P_RARP 0x8035
|
||||||
@ -760,10 +761,8 @@ void qemu_savevm_send_open_return_path(QEMUFile *f)
|
|||||||
* 0 on success
|
* 0 on success
|
||||||
* -ve on error
|
* -ve on error
|
||||||
*/
|
*/
|
||||||
int qemu_savevm_send_packaged(QEMUFile *f, const QEMUSizedBuffer *qsb)
|
int qemu_savevm_send_packaged(QEMUFile *f, const uint8_t *buf, size_t len)
|
||||||
{
|
{
|
||||||
size_t cur_iov;
|
|
||||||
size_t len = qsb_get_length(qsb);
|
|
||||||
uint32_t tmp;
|
uint32_t tmp;
|
||||||
|
|
||||||
if (len > MAX_VM_CMD_PACKAGED_SIZE) {
|
if (len > MAX_VM_CMD_PACKAGED_SIZE) {
|
||||||
@ -777,18 +776,7 @@ int qemu_savevm_send_packaged(QEMUFile *f, const QEMUSizedBuffer *qsb)
|
|||||||
trace_qemu_savevm_send_packaged();
|
trace_qemu_savevm_send_packaged();
|
||||||
qemu_savevm_command_send(f, MIG_CMD_PACKAGED, 4, (uint8_t *)&tmp);
|
qemu_savevm_command_send(f, MIG_CMD_PACKAGED, 4, (uint8_t *)&tmp);
|
||||||
|
|
||||||
/* all the data follows (concatinating the iov's) */
|
qemu_put_buffer(f, buf, len);
|
||||||
for (cur_iov = 0; cur_iov < qsb->n_iov; cur_iov++) {
|
|
||||||
/* The iov entries are partially filled */
|
|
||||||
size_t towrite = MIN(qsb->iov[cur_iov].iov_len, len);
|
|
||||||
len -= towrite;
|
|
||||||
|
|
||||||
if (!towrite) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
qemu_put_buffer(f, qsb->iov[cur_iov].iov_base, towrite);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1578,39 +1566,36 @@ static int loadvm_postcopy_handle_run(MigrationIncomingState *mis)
|
|||||||
static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis)
|
static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
uint8_t *buffer;
|
size_t length;
|
||||||
uint32_t length;
|
QIOChannelBuffer *bioc;
|
||||||
QEMUSizedBuffer *qsb;
|
|
||||||
|
|
||||||
length = qemu_get_be32(mis->from_src_file);
|
length = qemu_get_be32(mis->from_src_file);
|
||||||
trace_loadvm_handle_cmd_packaged(length);
|
trace_loadvm_handle_cmd_packaged(length);
|
||||||
|
|
||||||
if (length > MAX_VM_CMD_PACKAGED_SIZE) {
|
if (length > MAX_VM_CMD_PACKAGED_SIZE) {
|
||||||
error_report("Unreasonably large packaged state: %u", length);
|
error_report("Unreasonably large packaged state: %zu", length);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
buffer = g_malloc0(length);
|
|
||||||
ret = qemu_get_buffer(mis->from_src_file, buffer, (int)length);
|
bioc = qio_channel_buffer_new(length);
|
||||||
|
ret = qemu_get_buffer(mis->from_src_file,
|
||||||
|
bioc->data,
|
||||||
|
length);
|
||||||
if (ret != length) {
|
if (ret != length) {
|
||||||
g_free(buffer);
|
object_unref(OBJECT(bioc));
|
||||||
error_report("CMD_PACKAGED: Buffer receive fail ret=%d length=%d",
|
error_report("CMD_PACKAGED: Buffer receive fail ret=%d length=%zu",
|
||||||
ret, length);
|
ret, length);
|
||||||
return (ret < 0) ? ret : -EAGAIN;
|
return (ret < 0) ? ret : -EAGAIN;
|
||||||
}
|
}
|
||||||
|
bioc->usage += length;
|
||||||
trace_loadvm_handle_cmd_packaged_received(ret);
|
trace_loadvm_handle_cmd_packaged_received(ret);
|
||||||
|
|
||||||
/* Setup a dummy QEMUFile that actually reads from the buffer */
|
QEMUFile *packf = qemu_fopen_channel_input(QIO_CHANNEL(bioc));
|
||||||
qsb = qsb_create(buffer, length);
|
|
||||||
g_free(buffer); /* Because qsb_create copies */
|
|
||||||
if (!qsb) {
|
|
||||||
error_report("Unable to create qsb");
|
|
||||||
}
|
|
||||||
QEMUFile *packf = qemu_bufopen("r", qsb);
|
|
||||||
|
|
||||||
ret = qemu_loadvm_state_main(packf, mis);
|
ret = qemu_loadvm_state_main(packf, mis);
|
||||||
trace_loadvm_handle_cmd_packaged_main(ret);
|
trace_loadvm_handle_cmd_packaged_main(ret);
|
||||||
qemu_fclose(packf);
|
qemu_fclose(packf);
|
||||||
qsb_free(qsb);
|
object_unref(OBJECT(bioc));
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user