From: "Dr. David Alan Gilbert" <dgilb...@redhat.com> Create QEMU_VM_COMMAND section type for sending commands from source to destination. These commands are not intended to convey guest state but to control the migration process.
For use in postcopy. Signed-off-by: Dr. David Alan Gilbert <dgilb...@redhat.com> --- include/migration/migration.h | 1 + include/sysemu/sysemu.h | 9 ++++++++ savevm.c | 48 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+) diff --git a/include/migration/migration.h b/include/migration/migration.h index 8a36255..e23947a 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -33,6 +33,7 @@ #define QEMU_VM_SECTION_END 0x03 #define QEMU_VM_SECTION_FULL 0x04 #define QEMU_VM_SUBSECTION 0x05 +#define QEMU_VM_COMMAND 0x06 struct MigrationParams { bool blk; diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 6e5953d..eed7e77 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -82,6 +82,13 @@ void do_info_snapshots(Monitor *mon, const QDict *qdict); void qemu_announce_self(void); +/* Subcommands for QEMU_VM_COMMAND */ +enum qemu_vm_cmd { + QEMU_VM_CMD_INVALID = 0, /* Must be 0 */ + + QEMU_VM_CMD_AFTERLASTVALID +}; + bool qemu_savevm_state_blocked(Error **errp); void qemu_savevm_state_begin(QEMUFile *f, const MigrationParams *params); @@ -89,6 +96,8 @@ int qemu_savevm_state_iterate(QEMUFile *f); void qemu_savevm_state_complete(QEMUFile *f); void qemu_savevm_state_cancel(void); uint64_t qemu_savevm_state_pending(QEMUFile *f, uint64_t max_size); +void qemu_savevm_command_send(QEMUFile *f, enum qemu_vm_cmd command, + uint16_t len, uint8_t *data); int qemu_loadvm_state(QEMUFile *f); /* SLIRP */ diff --git a/savevm.c b/savevm.c index a0c3b40..3cae292 100644 --- a/savevm.c +++ b/savevm.c @@ -592,6 +592,25 @@ static void vmstate_save(QEMUFile *f, SaveStateEntry *se) vmstate_save_state(f, se->vmsd, se->opaque); } + +/* Send a 'QEMU_VM_COMMAND' type element with the command + * and associated data. + */ +void qemu_savevm_command_send(QEMUFile *f, + enum qemu_vm_cmd command, + uint16_t len, + uint8_t *data) +{ + uint32_t tmp = (uint16_t)command; + qemu_put_byte(f, QEMU_VM_COMMAND); + qemu_put_be16(f, tmp); + qemu_put_be16(f, len); + if (len) { + qemu_put_buffer(f, data, len); + } + qemu_fflush(f); +} + bool qemu_savevm_state_blocked(Error **errp) { SaveStateEntry *se; @@ -881,6 +900,29 @@ static SaveStateEntry *find_se(const char *idstr, int instance_id) return NULL; } +/* + * Process an incoming 'QEMU_VM_COMMAND' + * negative return on error (will issue error message) + */ +static int loadvm_process_command(QEMUFile *f) +{ + uint16_t com; + uint16_t len; + + com = qemu_get_be16(f); + len = qemu_get_be16(f); + + /* fprintf(stderr,"loadvm_process_command: com=0x%x len=%d\n", com,len); */ + switch (com) { + + default: + error_report("VM_COMMAND 0x%x unknown (len 0x%x)", com, len); + return -1; + } + + return 0; +} + typedef struct LoadStateEntry { QLIST_ENTRY(LoadStateEntry) entry; SaveStateEntry *se; @@ -987,6 +1029,12 @@ int qemu_loadvm_state(QEMUFile *f) goto out; } break; + case QEMU_VM_COMMAND: + ret = loadvm_process_command(f); + if (ret < 0) { + goto out; + } + break; default: fprintf(stderr, "Unknown savevm section type %d\n", section_type); ret = -EINVAL; -- 1.9.3