From: Amit Shah <amit.shah@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Juan Quintela <quintela@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Daniel P. Berrange" <berrange@redhat.com>,
qemu list <qemu-devel@nongnu.org>,
Amit Shah <amit.shah@redhat.com>
Subject: [Qemu-devel] [PULL 11/28] migration: convert post-copy to use QIOChannelBuffer
Date: Thu, 26 May 2016 11:42:02 +0530 [thread overview]
Message-ID: <61b67d473d2471d5b470cd4653947ddaaa2c1c44.1464242913.git.amit.shah@redhat.com> (raw)
In-Reply-To: <cover.1464242913.git.amit.shah@redhat.com>
In-Reply-To: <cover.1464242913.git.amit.shah@redhat.com>
From: "Daniel P. Berrange" <berrange@redhat.com>
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>
---
docs/migration.txt | 4 ++--
include/sysemu/sysemu.h | 2 +-
migration/migration.c | 15 +++++++--------
migration/savevm.c | 47 ++++++++++++++++-------------------------------
4 files changed, 26 insertions(+), 42 deletions(-)
diff --git a/docs/migration.txt b/docs/migration.txt
index 90209ab..6503c17 100644
--- a/docs/migration.txt
+++ b/docs/migration.txt
@@ -403,8 +403,8 @@ listen thread: --- page -- page -- page -- page -- page --
On receipt of CMD_PACKAGED (1)
All the data associated with the package - the ( ... ) section in the
-diagram - is read into memory (into a QEMUSizedBuffer), and the main thread
-recurses into qemu_loadvm_state_main to process the contents of the package (2)
+diagram - is read into memory, and the main thread recurses into
+qemu_loadvm_state_main to process the contents of the package (2)
which contains commands (3,6) and devices (4...)
On receipt of 'postcopy listen' - 3 -(i.e. the 1st command in the package)
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 618169c..9428141 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -119,7 +119,7 @@ void qemu_savevm_command_send(QEMUFile *f, enum qemu_vm_cmd command,
uint16_t len, uint8_t *data);
void qemu_savevm_send_ping(QEMUFile *f, uint32_t value);
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_listen(QEMUFile *f);
void qemu_savevm_send_postcopy_run(QEMUFile *f);
diff --git a/migration/migration.c b/migration/migration.c
index 1420ccc..1ab9535 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -34,6 +34,7 @@
#include "qom/cpu.h"
#include "exec/memory.h"
#include "exec/address-spaces.h"
+#include "io/channel-buffer.h"
#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)
{
int ret;
- const QEMUSizedBuffer *qsb;
+ QIOChannelBuffer *bioc;
+ QEMUFile *fb;
int64_t time_at_stop = qemu_clock_get_ms(QEMU_CLOCK_REALTIME);
migrate_set_state(&ms->state, MIGRATION_STATUS_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;
* to do this we use a qemu_buf to hold the whole of the device state.
*/
- QEMUFile *fb = qemu_bufopen("w", NULL);
- if (!fb) {
- error_report("Failed to create buffered file");
- goto fail;
- }
+ bioc = qio_channel_buffer_new(4096);
+ fb = qemu_fopen_channel_output(QIO_CHANNEL(bioc));
+ object_unref(OBJECT(bioc));
/*
* 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);
/* <><> end of stuff going into the package */
- qsb = qemu_buf_get(fb);
/* 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;
}
qemu_fclose(fb);
diff --git a/migration/savevm.c b/migration/savevm.c
index 65ce0c6..43031a0 100644
--- a/migration/savevm.c
+++ b/migration/savevm.c
@@ -51,6 +51,7 @@
#include "block/snapshot.h"
#include "block/qapi.h"
#include "qemu/cutils.h"
+#include "io/channel-buffer.h"
#ifndef ETH_P_RARP
#define ETH_P_RARP 0x8035
@@ -760,10 +761,8 @@ void qemu_savevm_send_open_return_path(QEMUFile *f)
* 0 on success
* -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;
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();
qemu_savevm_command_send(f, MIG_CMD_PACKAGED, 4, (uint8_t *)&tmp);
- /* all the data follows (concatinating the iov's) */
- 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);
- }
+ qemu_put_buffer(f, buf, len);
return 0;
}
@@ -1578,39 +1566,36 @@ static int loadvm_postcopy_handle_run(MigrationIncomingState *mis)
static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis)
{
int ret;
- uint8_t *buffer;
- uint32_t length;
- QEMUSizedBuffer *qsb;
+ size_t length;
+ QIOChannelBuffer *bioc;
length = qemu_get_be32(mis->from_src_file);
trace_loadvm_handle_cmd_packaged(length);
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;
}
- 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) {
- g_free(buffer);
- error_report("CMD_PACKAGED: Buffer receive fail ret=%d length=%d",
+ object_unref(OBJECT(bioc));
+ error_report("CMD_PACKAGED: Buffer receive fail ret=%d length=%zu",
ret, length);
return (ret < 0) ? ret : -EAGAIN;
}
+ bioc->usage += length;
trace_loadvm_handle_cmd_packaged_received(ret);
- /* Setup a dummy QEMUFile that actually reads from the buffer */
- 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);
+ QEMUFile *packf = qemu_fopen_channel_input(QIO_CHANNEL(bioc));
ret = qemu_loadvm_state_main(packf, mis);
trace_loadvm_handle_cmd_packaged_main(ret);
qemu_fclose(packf);
- qsb_free(qsb);
+ object_unref(OBJECT(bioc));
return ret;
}
--
2.5.5
next prev parent reply other threads:[~2016-05-26 6:13 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-26 6:11 [Qemu-devel] [PULL 00/28] migration: support for TLS Amit Shah
2016-05-26 6:11 ` [Qemu-devel] [PULL 01/28] s390: use FILE instead of QEMUFile for creating text file Amit Shah
2016-05-26 6:11 ` [Qemu-devel] [PULL 02/28] io: avoid double-free when closing QIOChannelBuffer Amit Shah
2016-05-26 6:11 ` [Qemu-devel] [PULL 03/28] migration: remove use of qemu_bufopen from vmstate tests Amit Shah
2016-05-26 6:11 ` [Qemu-devel] [PULL 04/28] migration: ensure qemu_fflush() always writes full data amount Amit Shah
2016-05-26 6:11 ` [Qemu-devel] [PULL 05/28] migration: split migration hooks out of QEMUFileOps Amit Shah
2016-05-26 6:11 ` [Qemu-devel] [PULL 06/28] migration: introduce set_blocking function in QEMUFileOps Amit Shah
2016-05-26 6:11 ` [Qemu-devel] [PULL 07/28] migration: force QEMUFile to blocking mode for outgoing migration Amit Shah
2016-05-26 6:11 ` [Qemu-devel] [PULL 08/28] migration: introduce a new QEMUFile impl based on QIOChannel Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 09/28] migration: add helpers for creating QEMUFile from a QIOChannel Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 10/28] migration: add reporting of errors for outgoing migration Amit Shah
2016-05-26 15:00 ` Eric Blake
2016-05-31 15:16 ` Daniel P. Berrange
2016-06-06 8:38 ` Paolo Bonzini
2016-05-26 6:12 ` Amit Shah [this message]
2016-05-26 6:12 ` [Qemu-devel] [PULL 12/28] migration: convert unix socket protocol to use QIOChannel Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 13/28] migration: rename unix.c to socket.c Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 14/28] migration: convert tcp socket protocol to use QIOChannel Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 15/28] migration: convert fd " Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 16/28] migration: convert exec " Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 17/28] migration: convert RDMA to use QIOChannel interface Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 18/28] migration: convert savevm to use QIOChannel for writing to files Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 19/28] migration: delete QEMUFile buffer implementation Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 20/28] migration: delete QEMUSizedBuffer struct Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 21/28] migration: delete QEMUFile sockets implementation Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 22/28] migration: delete QEMUFile stdio implementation Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 23/28] migration: move definition of struct QEMUFile back into qemu-file.c Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 24/28] migration: don't use an array for storing migrate parameters Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 25/28] migration: define 'tls-creds' and 'tls-hostname' migration parameters Amit Shah
2016-05-26 15:05 ` Eric Blake
2016-05-27 10:02 ` Amit Shah
2016-05-31 9:22 ` Daniel P. Berrange
2016-05-26 6:12 ` [Qemu-devel] [PULL 26/28] migration: add support for encrypting data with TLS Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 27/28] migration: remove support for non-iovec based write handlers Amit Shah
2016-05-26 6:12 ` [Qemu-devel] [PULL 28/28] migration: remove qemu_get_fd method from QEMUFile Amit Shah
2016-05-26 16:29 ` [Qemu-devel] [PULL 00/28] migration: support for TLS Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=61b67d473d2471d5b470cd4653947ddaaa2c1c44.1464242913.git.amit.shah@redhat.com \
--to=amit.shah@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).