From patchwork Fri Jul 4 17:41:20 2014 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: 367181 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 DF07F14007D for ; Sat, 5 Jul 2014 04:23:48 +1000 (EST) Received: from localhost ([::1]:37397 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X37aB-0004jA-FE for incoming@patchwork.ozlabs.org; Fri, 04 Jul 2014 13:47:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60659) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X37VB-0007VW-3T for qemu-devel@nongnu.org; Fri, 04 Jul 2014 13:42:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X37V4-0008Gr-DI for qemu-devel@nongnu.org; Fri, 04 Jul 2014 13:42:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31499) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X37V4-0008Gk-4j for qemu-devel@nongnu.org; Fri, 04 Jul 2014 13:42:18 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s64HgFIf001688 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 4 Jul 2014 13:42:15 -0400 Received: from dgilbert-t530.home.treblig.org (vpn1-7-141.ams2.redhat.com [10.36.7.141]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s64HfvTc030576; Fri, 4 Jul 2014 13:42:14 -0400 From: "Dr. David Alan Gilbert (git)" To: qemu-devel@nongnu.org Date: Fri, 4 Jul 2014 18:41:20 +0100 Message-Id: <1404495717-4239-10-git-send-email-dgilbert@redhat.com> In-Reply-To: <1404495717-4239-1-git-send-email-dgilbert@redhat.com> References: <1404495717-4239-1-git-send-email-dgilbert@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: aarcange@redhat.com, yamahata@private.email.ne.jp, lilei@linux.vnet.ibm.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH 09/46] 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 --- include/migration/migration.h | 1 + include/sysemu/sysemu.h | 7 +++++ savevm.c | 61 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) diff --git a/include/migration/migration.h b/include/migration/migration.h index 4103460..728b93e 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 d8539fd..66821eb 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -81,6 +81,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); diff --git a/savevm.c b/savevm.c index 46cb9b0..0c7d537 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,42 @@ static SaveStateEntry *find_se(const char *idstr, int instance_id) return NULL; } +static int loadvm_process_command_simple_lencheck(const char *name, + unsigned int actual, + unsigned int expected) +{ + if (actual != expected) { + error_report("%s received with bad length - expecting %d, got %d", + name, expected, actual); + return -1; + } + + return 0; +} + +/* Process an incoming 'QEMU_VM_COMMAND' + * -ve return on error (will issue error message) + */ +static int loadvm_process_command(QEMUFile *f) +{ + uint16_t com; + uint16_t len; + uint32_t tmp32; + + 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 +1042,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;