From patchwork Tue Jul 27 00:11:00 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cam Macdonell X-Patchwork-Id: 59961 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CE9B3B70A4 for ; Tue, 27 Jul 2010 10:13:02 +1000 (EST) Received: from localhost ([127.0.0.1]:45636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OdXn1-0003RB-3Z for incoming@patchwork.ozlabs.org; Mon, 26 Jul 2010 20:12:59 -0400 Received: from [140.186.70.92] (port=42961 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OdXlV-0003PR-58 for qemu-devel@nongnu.org; Mon, 26 Jul 2010 20:11:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OdXlS-0006ml-Kl for qemu-devel@nongnu.org; Mon, 26 Jul 2010 20:11:25 -0400 Received: from fleet.cs.ualberta.ca ([129.128.22.22]:33346) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OdXlS-0006kx-7D for qemu-devel@nongnu.org; Mon, 26 Jul 2010 20:11:22 -0400 Received: from localhost.localdomain (st-brides.cs.ualberta.ca [129.128.23.21]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp-auth.cs.ualberta.ca (Postfix) with ESMTP id 296632801E; Mon, 26 Jul 2010 18:11:09 -0600 (MDT) From: Cam Macdonell To: qemu-devel@nongnu.org Date: Mon, 26 Jul 2010 18:11:00 -0600 Message-Id: <1280189461-1929-5-git-send-email-cam@cs.ualberta.ca> X-Mailer: git-send-email 1.6.3.2.198.g6096d In-Reply-To: <1280189461-1929-4-git-send-email-cam@cs.ualberta.ca> References: <1280189461-1929-1-git-send-email-cam@cs.ualberta.ca> <1280189461-1929-2-git-send-email-cam@cs.ualberta.ca> <1280189461-1929-3-git-send-email-cam@cs.ualberta.ca> <1280189461-1929-4-git-send-email-cam@cs.ualberta.ca> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Cc: Cam Macdonell , kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH v8 4/5] Support marking a device as non-migratable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org A non-migratable device should be removed before migration and re-added after. Signed-off-by: Cam Macdonell --- hw/hw.h | 2 ++ savevm.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/hw/hw.h b/hw/hw.h index c2de6fe..28b4204 100644 --- a/hw/hw.h +++ b/hw/hw.h @@ -264,6 +264,8 @@ int register_savevm_live(DeviceState *dev, void *opaque); void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque); +void register_device_unmigratable(DeviceState *dev, const char *idstr, + void *opaque); typedef void QEMUResetHandler(void *opaque); diff --git a/savevm.c b/savevm.c index ee27989..6d55d28 100644 --- a/savevm.c +++ b/savevm.c @@ -1005,6 +1005,7 @@ typedef struct SaveStateEntry { const VMStateDescription *vmsd; void *opaque; CompatEntry *compat; + int no_migrate; } SaveStateEntry; @@ -1068,6 +1069,7 @@ int register_savevm_live(DeviceState *dev, se->load_state = load_state; se->opaque = opaque; se->vmsd = NULL; + se->no_migrate = 0; if (dev && dev->parent_bus && dev->parent_bus->info->get_dev_path) { char *id = dev->parent_bus->info->get_dev_path(dev); @@ -1131,6 +1133,31 @@ void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque) } } +/* mark a device as not to be migrated, that is the device should be + unplugged before migration */ +void register_device_unmigratable(DeviceState *dev, const char *idstr, + void *opaque) +{ + SaveStateEntry *se; + char id[256] = ""; + + if (dev && dev->parent_bus && dev->parent_bus->info->get_dev_path) { + char *path = dev->parent_bus->info->get_dev_path(dev); + if (path) { + pstrcpy(id, sizeof(id), path); + pstrcat(id, sizeof(id), "/"); + qemu_free(path); + } + } + pstrcat(id, sizeof(id), idstr); + + QTAILQ_FOREACH(se, &savevm_handlers, entry) { + if (strcmp(se->idstr, id) == 0 && se->opaque == opaque) { + se->no_migrate = 1; + } + } +} + int vmstate_register_with_alias_id(DeviceState *dev, int instance_id, const VMStateDescription *vmsd, void *opaque, int alias_id, @@ -1323,13 +1350,19 @@ static int vmstate_load(QEMUFile *f, SaveStateEntry *se, int version_id) return vmstate_load_state(f, se->vmsd, se->opaque, version_id); } -static void vmstate_save(QEMUFile *f, SaveStateEntry *se) +static int vmstate_save(QEMUFile *f, SaveStateEntry *se) { + if (se->no_migrate) { + return -1; + } + if (!se->vmsd) { /* Old style */ se->save_state(f, se->opaque); - return; + return 0; } vmstate_save_state(f,se->vmsd, se->opaque); + + return 0; } #define QEMU_VM_FILE_MAGIC 0x5145564d @@ -1423,6 +1456,7 @@ int qemu_savevm_state_iterate(Monitor *mon, QEMUFile *f) int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f) { SaveStateEntry *se; + int r; cpu_synchronize_all_states(); @@ -1455,7 +1489,11 @@ int qemu_savevm_state_complete(Monitor *mon, QEMUFile *f) qemu_put_be32(f, se->instance_id); qemu_put_be32(f, se->version_id); - vmstate_save(f, se); + r = vmstate_save(f, se); + if (r < 0) { + monitor_printf(mon, "cannot migrate with device '%s'\n", se->idstr); + return r; + } } qemu_put_byte(f, QEMU_VM_EOF);