From patchwork Tue Sep 29 08:37:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Dr. David Alan Gilbert" X-Patchwork-Id: 523845 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D71881400A0 for ; Wed, 30 Sep 2015 00:05:35 +1000 (AEST) Received: from localhost ([::1]:52344 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZgvXB-00016M-Vj for incoming@patchwork.ozlabs.org; Tue, 29 Sep 2015 10:05:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54282) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZgqRB-000651-6I for qemu-devel@nongnu.org; Tue, 29 Sep 2015 04:39:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZgqR9-00023j-Vq for qemu-devel@nongnu.org; Tue, 29 Sep 2015 04:39:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45957) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZgqR9-00022k-Og for qemu-devel@nongnu.org; Tue, 29 Sep 2015 04:38:59 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 6EF178C1A3; Tue, 29 Sep 2015 08:38:59 +0000 (UTC) Received: from dgilbert-t530.redhat.com (ovpn-116-104.ams2.redhat.com [10.36.116.104]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8T8cJYx015509; Tue, 29 Sep 2015 04:38:57 -0400 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org, quintela@redhat.com, amit.shah@redhat.com Date: Tue, 29 Sep 2015 09:37:42 +0100 Message-Id: <1443515898-3594-19-git-send-email-dgilbert@redhat.com> In-Reply-To: <1443515898-3594-1-git-send-email-dgilbert@redhat.com> References: <1443515898-3594-1-git-send-email-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: aarcange@redhat.com, pbonzini@redhat.com, liang.z.li@intel.com, luis@cs.umu.se, bharata@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH v8 18/54] Migration commands X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: "Dr. David Alan Gilbert" 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 Reviewed-by: Amit Shah Reviewed-by: Juan Quintela --- include/migration/migration.h | 1 + include/sysemu/sysemu.h | 8 +++++ migration/savevm.c | 70 +++++++++++++++++++++++++++++++++++++++++++ trace-events | 2 ++ 4 files changed, 81 insertions(+) diff --git a/include/migration/migration.h b/include/migration/migration.h index 82cc3a6..0bb4383 100644 --- a/include/migration/migration.h +++ b/include/migration/migration.h @@ -35,6 +35,7 @@ #define QEMU_VM_SUBSECTION 0x05 #define QEMU_VM_VMDESCRIPTION 0x06 #define QEMU_VM_CONFIGURATION 0x07 +#define QEMU_VM_COMMAND 0x08 #define QEMU_VM_SECTION_FOOTER 0x7e struct MigrationParams { diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 7fd6c73..07e9502 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -84,6 +84,12 @@ void hmp_info_snapshots(Monitor *mon, const QDict *qdict); void qemu_announce_self(void); +/* Subcommands for QEMU_VM_COMMAND */ +enum qemu_vm_cmd { + MIG_CMD_INVALID = 0, /* Must be 0 */ + MIG_CMD_MAX +}; + bool qemu_savevm_state_blocked(Error **errp); void qemu_savevm_state_begin(QEMUFile *f, const MigrationParams *params); @@ -92,6 +98,8 @@ int qemu_savevm_state_iterate(QEMUFile *f); void qemu_savevm_state_complete_precopy(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); typedef enum DisplayType diff --git a/migration/savevm.c b/migration/savevm.c index e621afd..eb495e6 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -59,6 +59,14 @@ static bool skip_section_footers; +static struct mig_cmd_args { + ssize_t len; /* -1 = variable */ + const char *name; +} mig_cmd_args[] = { + [MIG_CMD_INVALID] = { .len = -1, .name = "INVALID" }, + [MIG_CMD_MAX] = { .len = -1, .name = "MAX" }, +}; + static int announce_self_create(uint8_t *buf, uint8_t *mac_addr) { @@ -693,6 +701,28 @@ static void save_section_footer(QEMUFile *f, SaveStateEntry *se) } } +/** + * qemu_savevm_command_send: Send a 'QEMU_VM_COMMAND' type element with the + * command and associated data. + * + * @f: File to send command on + * @command: Command type to send + * @len: Length of associated data + * @data: Data associated with command. + */ +void qemu_savevm_command_send(QEMUFile *f, + enum qemu_vm_cmd command, + uint16_t len, + uint8_t *data) +{ + trace_savevm_command_send(command, len); + qemu_put_byte(f, QEMU_VM_COMMAND); + qemu_put_be16(f, (uint16_t)command); + qemu_put_be16(f, len); + qemu_put_buffer(f, data, len); + qemu_fflush(f); +} + bool qemu_savevm_state_blocked(Error **errp) { SaveStateEntry *se; @@ -1003,6 +1033,40 @@ static SaveStateEntry *find_se(const char *idstr, int instance_id) return NULL; } +/** + * loadvm_process_command: Process an incoming 'QEMU_VM_COMMAND' + * + * Returns: 0 on success, negative on error (in which case it will issue an + * error message). + * @f: The stream to read the command data from. + */ +static int loadvm_process_command(QEMUFile *f) +{ + uint16_t cmd; + uint16_t len; + + cmd = qemu_get_be16(f); + len = qemu_get_be16(f); + + trace_loadvm_process_command(cmd, len); + if (cmd >= MIG_CMD_MAX || cmd == MIG_CMD_INVALID) { + error_report("MIG_CMD 0x%x unknown (len 0x%x)", cmd, len); + return -EINVAL; + } + + if (mig_cmd_args[cmd].len != -1 && mig_cmd_args[cmd].len != len) { + error_report("%s received with bad length - expecting %zd, got %d", + mig_cmd_args[cmd].name, mig_cmd_args[cmd].len, len); + return -ERANGE; + } + + switch (cmd) { + /* Filling added in next patch */ + } + + return 0; +} + struct LoadStateEntry { QLIST_ENTRY(LoadStateEntry) entry; SaveStateEntry *se; @@ -1182,6 +1246,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: error_report("Unknown savevm section type %d", section_type); ret = -EINVAL; diff --git a/trace-events b/trace-events index cec51f6..b6cdf11 100644 --- a/trace-events +++ b/trace-events @@ -1197,6 +1197,8 @@ virtio_gpu_fence_resp(uint64_t fence) "fence 0x%" PRIx64 qemu_loadvm_state_section(unsigned int section_type) "%d" qemu_loadvm_state_section_partend(uint32_t section_id) "%u" qemu_loadvm_state_section_startfull(uint32_t section_id, const char *idstr, uint32_t instance_id, uint32_t version_id) "%u(%s) %u %u" +loadvm_process_command(uint16_t com, uint16_t len) "com=0x%x len=%d" +savevm_command_send(uint16_t command, uint16_t len) "com=0x%x len=%d" savevm_section_start(const char *id, unsigned int section_id) "%s, section_id %u" savevm_section_end(const char *id, unsigned int section_id, int ret) "%s, section_id %u -> %d" savevm_section_skip(const char *id, unsigned int section_id) "%s, section_id %u"