From patchwork Fri Jul 13 07:23:24 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 170823 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 386CA2C02F6 for ; Fri, 13 Jul 2012 18:41:07 +1000 (EST) Received: from localhost ([::1]:54343 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SpaFD-00012p-4h for incoming@patchwork.ozlabs.org; Fri, 13 Jul 2012 03:24:55 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SpaEH-0007Yt-P3 for qemu-devel@nongnu.org; Fri, 13 Jul 2012 03:24:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SpaEA-0004N1-3A for qemu-devel@nongnu.org; Fri, 13 Jul 2012 03:23:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52095) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SpaE9-0004Mq-S7 for qemu-devel@nongnu.org; Fri, 13 Jul 2012 03:23:50 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q6D7NnbJ013604 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 13 Jul 2012 03:23:49 -0400 Received: from trasno.mitica (ovpn-116-28.ams2.redhat.com [10.36.116.28]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q6D7NjQq014276; Fri, 13 Jul 2012 03:23:48 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 13 Jul 2012 09:23:24 +0200 Message-Id: <1342164224-32709-3-git-send-email-quintela@redhat.com> In-Reply-To: <1342164224-32709-1-git-send-email-quintela@redhat.com> References: <1342164224-32709-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 02/22] savevm: Live migration handlers register the struct directly 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 Notice that the live migration users never unregister, so no problem about freeing the ops structure. Signed-off-by: Juan Quintela --- arch_init.c | 9 +++++++-- block-migration.c | 10 ++++++++-- migration.h | 4 ++-- savevm.c | 18 +++++++----------- vl.c | 3 +-- vmstate.h | 5 +---- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/arch_init.c b/arch_init.c index 5b0f562..606b848 100644 --- a/arch_init.c +++ b/arch_init.c @@ -298,7 +298,7 @@ static void migration_end(void) #define MAX_WAIT 50 /* ms, half buffered_file limit */ -int ram_save_live(QEMUFile *f, int stage, void *opaque) +static int ram_save_live(QEMUFile *f, int stage, void *opaque) { ram_addr_t addr; uint64_t bytes_transferred_last; @@ -437,7 +437,7 @@ static inline void *host_from_stream_offset(QEMUFile *f, return NULL; } -int ram_load(QEMUFile *f, void *opaque, int version_id) +static int ram_load(QEMUFile *f, void *opaque, int version_id) { ram_addr_t addr; int flags, ret = 0; @@ -534,6 +534,11 @@ done: return ret; } +SaveVMHandlers savevm_ram_handlers = { + .save_live_state = ram_save_live, + .load_state = ram_load, +}; + #ifdef HAS_AUDIO struct soundhw { const char *name; diff --git a/block-migration.c b/block-migration.c index b95b4e1..00151a0 100644 --- a/block-migration.c +++ b/block-migration.c @@ -709,11 +709,17 @@ static void block_set_params(const MigrationParams *params, void *opaque) block_mig_state.blk_enable |= params->shared; } +SaveVMHandlers savevm_block_handlers = { + .set_params = block_set_params, + .save_live_state = block_save_live, + .load_state = block_load, +}; + void blk_mig_init(void) { QSIMPLEQ_INIT(&block_mig_state.bmds_list); QSIMPLEQ_INIT(&block_mig_state.blk_list); - register_savevm_live(NULL, "block", 0, 1, block_set_params, - block_save_live, NULL, block_load, &block_mig_state); + register_savevm_live(NULL, "block", 0, 1, &savevm_block_handlers, + &block_mig_state); } diff --git a/migration.h b/migration.h index de13004..57572a6 100644 --- a/migration.h +++ b/migration.h @@ -18,6 +18,7 @@ #include "qemu-common.h" #include "notify.h" #include "error.h" +#include "vmstate.h" struct MigrationParams { bool blk; @@ -81,8 +82,7 @@ uint64_t ram_bytes_remaining(void); uint64_t ram_bytes_transferred(void); uint64_t ram_bytes_total(void); -int ram_save_live(QEMUFile *f, int stage, void *opaque); -int ram_load(QEMUFile *f, void *opaque, int version_id); +extern SaveVMHandlers savevm_ram_handlers; /** * @migrate_add_blocker - prevent migration from proceeding diff --git a/savevm.c b/savevm.c index 73626d4..a451be2 100644 --- a/savevm.c +++ b/savevm.c @@ -1223,10 +1223,7 @@ int register_savevm_live(DeviceState *dev, const char *idstr, int instance_id, int version_id, - SaveSetParamsHandler *set_params, - SaveLiveStateHandler *save_live_state, - SaveStateHandler *save_state, - LoadStateHandler *load_state, + SaveVMHandlers *ops, void *opaque) { SaveStateEntry *se; @@ -1234,16 +1231,12 @@ int register_savevm_live(DeviceState *dev, se = g_malloc0(sizeof(SaveStateEntry)); se->version_id = version_id; se->section_id = global_section_id++; - se->ops = g_malloc0(sizeof(SaveVMHandlers)); - se->ops->set_params = set_params; - se->ops->save_live_state = save_live_state; - se->ops->save_state = save_state; - se->ops->load_state = load_state; + se->ops = ops; se->opaque = opaque; se->vmsd = NULL; se->no_migrate = 0; /* if this is a live_savem then set is_ram */ - if (save_live_state != NULL) { + if (ops->save_live_state != NULL) { se->is_ram = 1; } @@ -1282,8 +1275,11 @@ int register_savevm(DeviceState *dev, LoadStateHandler *load_state, void *opaque) { + SaveVMHandlers *ops = g_malloc0(sizeof(SaveVMHandlers)); + ops->save_state = save_state; + ops->load_state = load_state; return register_savevm_live(dev, idstr, instance_id, version_id, - NULL, NULL, save_state, load_state, opaque); + ops, opaque); } void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque) diff --git a/vl.c b/vl.c index 2e140f5..61fe7df 100644 --- a/vl.c +++ b/vl.c @@ -3437,8 +3437,7 @@ int main(int argc, char **argv, char **envp) default_drive(default_sdcard, snapshot, machine->use_scsi, IF_SD, 0, SD_OPTS); - register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL, - ram_load, NULL); + register_savevm_live(NULL, "ram", 0, 4, &savevm_ram_handlers, NULL); if (nb_numa_nodes > 0) { int i; diff --git a/vmstate.h b/vmstate.h index 909af69..4bce53b 100644 --- a/vmstate.h +++ b/vmstate.h @@ -50,10 +50,7 @@ int register_savevm_live(DeviceState *dev, const char *idstr, int instance_id, int version_id, - SaveSetParamsHandler *set_params, - SaveLiveStateHandler *save_live_state, - SaveStateHandler *save_state, - LoadStateHandler *load_state, + SaveVMHandlers *ops, void *opaque); void unregister_savevm(DeviceState *dev, const char *idstr, void *opaque);