[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v4 22/47] QEMU_VM_CMD_PACKAGED: Send a packaged chun
From: |
Dr. David Alan Gilbert (git) |
Subject: |
[Qemu-devel] [PATCH v4 22/47] QEMU_VM_CMD_PACKAGED: Send a packaged chunk of migration stream |
Date: |
Fri, 3 Oct 2014 18:47:28 +0100 |
From: "Dr. David Alan Gilbert" <address@hidden>
QEMU_VM_CMD_PACKAGED is a migration command that allows a chunk
of migration stream to be sent in one go, and be received by
a separate instance of the loadvm loop while not interacting
with the migration stream.
This is used by postcopy to load device state (from the package)
while loading memory pages from the main stream.
Signed-off-by: Dr. David Alan Gilbert <address@hidden>
---
include/sysemu/sysemu.h | 4 +++
savevm.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 86 insertions(+)
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
index 102dd93..ef98fa9 100644
--- a/include/sysemu/sysemu.h
+++ b/include/sysemu/sysemu.h
@@ -87,6 +87,7 @@ enum qemu_vm_cmd {
QEMU_VM_CMD_INVALID = 0, /* Must be 0 */
QEMU_VM_CMD_OPENRP, /* Tell the dest to open the Return path */
QEMU_VM_CMD_REQACK, /* Request an ACK on the RP */
+ QEMU_VM_CMD_PACKAGED, /* Send a wrapped stream within this stream */
QEMU_VM_CMD_POSTCOPY_RAM_ADVISE = 20, /* Prior to any page transfers, just
warn we might want to do PC */
@@ -101,6 +102,8 @@ enum qemu_vm_cmd {
QEMU_VM_CMD_AFTERLASTVALID
};
+#define MAX_VM_CMD_PACKAGED_SIZE (1ul << 24)
+
bool qemu_savevm_state_blocked(Error **errp);
void qemu_savevm_state_begin(QEMUFile *f,
const MigrationParams *params);
@@ -112,6 +115,7 @@ void qemu_savevm_command_send(QEMUFile *f, enum qemu_vm_cmd
command,
uint16_t len, uint8_t *data);
void qemu_savevm_send_reqack(QEMUFile *f, uint32_t value);
void qemu_savevm_send_openrp(QEMUFile *f);
+void qemu_savevm_send_packaged(QEMUFile *f, const QEMUSizedBuffer *qsb);
void qemu_savevm_send_postcopy_ram_advise(QEMUFile *f);
void qemu_savevm_send_postcopy_ram_discard(QEMUFile *f, const char *name,
uint16_t len, uint8_t offset,
diff --git a/savevm.c b/savevm.c
index b942e8c..bffe890 100644
--- a/savevm.c
+++ b/savevm.c
@@ -626,6 +626,38 @@ void qemu_savevm_send_openrp(QEMUFile *f)
qemu_savevm_command_send(f, QEMU_VM_CMD_OPENRP, 0, NULL);
}
+/* We have a buffer of data to send; we don't want that all to be loaded
+ * by the command itself, so the command contains just the length of the
+ * extra buffer that we then send straight after it.
+ * TODO: Must be a better way to organise that
+ */
+void qemu_savevm_send_packaged(QEMUFile *f, const QEMUSizedBuffer *qsb)
+{
+ size_t cur_iov;
+ size_t len = qsb_get_length(qsb);
+ uint32_t tmp;
+
+ tmp = cpu_to_be32(len);
+
+ DPRINTF("send_packaged");
+ qemu_savevm_command_send(f, QEMU_VM_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 = (qsb->iov[cur_iov].iov_len > len) ?
+ len :
+ qsb->iov[cur_iov].iov_len;
+ len -= towrite;
+
+ if (!towrite) {
+ break;
+ }
+
+ qemu_put_buffer(f, qsb->iov[cur_iov].iov_base, towrite);
+ }
+}
+
/* Send prior to any RAM transfer */
void qemu_savevm_send_postcopy_ram_advise(QEMUFile *f)
{
@@ -1249,6 +1281,48 @@ static int loadvm_process_command_simple_lencheck(const
char *name,
return 0;
}
+/* Immediately following this command is a blob of data containing an embedded
+ * chunk of migration stream; read it and load it.
+ */
+static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis,
+ uint32_t length,
+ LoadStateEntry_Head *loadvm_handlers)
+{
+ int ret;
+ uint8_t *buffer;
+ QEMUSizedBuffer *qsb;
+
+ DPRINTF("loadvm_handle_cmd_packaged: length=%u", length);
+
+ if (length > MAX_VM_CMD_PACKAGED_SIZE) {
+ error_report("Unreasonably large packaged state: %u", length);
+ return -1;
+ }
+ buffer = g_malloc0(length);
+ ret = qemu_get_buffer(mis->file, buffer, (int)length);
+ if (ret != length) {
+ g_free(buffer);
+ error_report("CMD_PACKAGED: Buffer receive fail ret=%d length=%d\n",
+ ret, length);
+ return (ret < 0) ? ret : -EAGAIN;
+ }
+ DPRINTF("%s: Received %d package, going to load", __func__, 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);
+
+ ret = qemu_loadvm_state_main(packf, loadvm_handlers);
+ DPRINTF("%s: qemu_loadvm_state_main returned %d", __func__, ret);
+ qemu_fclose(packf); /* also frees the qsb */
+
+ return ret;
+}
+
/*
* Process an incoming 'QEMU_VM_COMMAND'
* negative return on error (will issue error message)
@@ -1299,6 +1373,14 @@ static int loadvm_process_command(QEMUFile *f,
migrate_send_rp_ack(mis, tmp32);
break;
+ case QEMU_VM_CMD_PACKAGED:
+ if (loadvm_process_command_simple_lencheck("CMD_POSTCOPY_RAM_PACKAGED",
+ len, 4)) {
+ return -1;
+ }
+ tmp32 = qemu_get_be32(f);
+ return loadvm_handle_cmd_packaged(mis, tmp32, loadvm_handlers);
+
case QEMU_VM_CMD_POSTCOPY_RAM_ADVISE:
if (loadvm_process_command_simple_lencheck("CMD_POSTCOPY_RAM_ADVISE",
len, 16)) {
--
1.9.3
- [Qemu-devel] [PATCH v4 18/47] ram_debug_dump_bitmap: Dump a migration bitmap as text, (continued)
[Qemu-devel] [PATCH v4 20/47] Add migration-capability boolean for postcopy-ram., Dr. David Alan Gilbert (git), 2014/10/03
[Qemu-devel] [PATCH v4 21/47] Add wrappers and handlers for sending/receiving the postcopy-ram migration messages., Dr. David Alan Gilbert (git), 2014/10/03
[Qemu-devel] [PATCH v4 22/47] QEMU_VM_CMD_PACKAGED: Send a packaged chunk of migration stream,
Dr. David Alan Gilbert (git) <=
[Qemu-devel] [PATCH v4 23/47] migrate_init: Call from savevm, Dr. David Alan Gilbert (git), 2014/10/03
[Qemu-devel] [PATCH v4 24/47] Allow savevm handlers to state whether they could go into postcopy, Dr. David Alan Gilbert (git), 2014/10/03
[Qemu-devel] [PATCH v4 25/47] postcopy: OS support test, Dr. David Alan Gilbert (git), 2014/10/03
[Qemu-devel] [PATCH v4 26/47] migrate_start_postcopy: Command to trigger transition to postcopy, Dr. David Alan Gilbert (git), 2014/10/03
[Qemu-devel] [PATCH v4 27/47] MIG_STATE_POSTCOPY_ACTIVE: Add new migration state, Dr. David Alan Gilbert (git), 2014/10/03
[Qemu-devel] [PATCH v4 28/47] qemu_savevm_state_complete: Postcopy changes, Dr. David Alan Gilbert (git), 2014/10/03
[Qemu-devel] [PATCH v4 29/47] Postcopy page-map-incoming (PMI) structure, Dr. David Alan Gilbert (git), 2014/10/03
[Qemu-devel] [PATCH v4 30/47] Postcopy: Maintain sentmap and calculate discard, Dr. David Alan Gilbert (git), 2014/10/03
[Qemu-devel] [PATCH v4 31/47] postcopy: Incoming initialisation, Dr. David Alan Gilbert (git), 2014/10/03