From patchwork Thu Apr 11 12:14:25 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Beno=C3=AEt_Canet?= X-Patchwork-Id: 235716 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 D7D812C00C5 for ; Thu, 11 Apr 2013 22:14:37 +1000 (EST) Received: from localhost ([::1]:37120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQGOh-0008A5-W0 for incoming@patchwork.ozlabs.org; Thu, 11 Apr 2013 08:14:36 -0400 Received: from eggs.gnu.org ([208.118.235.92]:49159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQGO1-0007w8-47 for qemu-devel@nongnu.org; Thu, 11 Apr 2013 08:13:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UQGNu-0004CU-8G for qemu-devel@nongnu.org; Thu, 11 Apr 2013 08:13:53 -0400 Received: from nodalink.pck.nerim.net ([62.212.105.220]:43053 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UQGNt-0004CB-Nh for qemu-devel@nongnu.org; Thu, 11 Apr 2013 08:13:46 -0400 Received: by paradis.irqsave.net (Postfix, from userid 1002) id 2F83A87435E; Thu, 11 Apr 2013 14:13:45 +0200 (CEST) Received: from localhost.localdomain (unknown [192.168.77.1]) by paradis.irqsave.net (Postfix) with ESMTP id D3BF887432C; Thu, 11 Apr 2013 14:13:19 +0200 (CEST) From: =?UTF-8?q?Beno=C3=AEt=20Canet?= To: qemu-devel@nongnu.org Date: Thu, 11 Apr 2013 14:14:25 +0200 Message-Id: <1365682468-12301-2-git-send-email-benoit@irqsave.net> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1365682468-12301-1-git-send-email-benoit@irqsave.net> References: <1365682468-12301-1-git-send-email-benoit@irqsave.net> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 62.212.105.220 Cc: =?UTF-8?q?Beno=C3=AEt=20Canet?= , aneesh.kumar@linux.vnet.ibm.com, quintela@redhat.com Subject: [Qemu-devel] =?utf-8?q?=5BPATCH_1/4=5D_migration=3A_Create_the_pr?= =?utf-8?q?e_migration_flush_hook_infrastructure=2E?= 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 This patch will allow the block layer and virtio-9p to cleanly register io flush hooks to be executed by cpus.c. Signed-off-by: Benoit Canet --- Makefile | 6 +-- Makefile.objs | 2 +- block.c | 8 ++++ cpus.c | 6 ++- include/migration/migration-flush-hooks.h | 30 ++++++++++++++ migration-flush-hooks.c | 62 +++++++++++++++++++++++++++++ vl.c | 6 +++ 7 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 include/migration/migration-flush-hooks.h create mode 100644 migration-flush-hooks.c diff --git a/Makefile b/Makefile index 80344d9..bb11da5 100644 --- a/Makefile +++ b/Makefile @@ -170,9 +170,9 @@ libqemuutil.a: $(util-obj-y) qemu-img.o: qemu-img-cmds.h -qemu-img$(EXESUF): qemu-img.o $(block-obj-y) libqemuutil.a libqemustub.a -qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) libqemuutil.a libqemustub.a -qemu-io$(EXESUF): qemu-io.o cmd.o $(block-obj-y) libqemuutil.a libqemustub.a +qemu-img$(EXESUF): qemu-img.o $(block-obj-y) libqemuutil.a libqemustub.a migration-flush-hooks.o +qemu-nbd$(EXESUF): qemu-nbd.o $(block-obj-y) libqemuutil.a libqemustub.a migration-flush-hooks.o +qemu-io$(EXESUF): qemu-io.o cmd.o $(block-obj-y) libqemuutil.a libqemustub.a migration-flush-hooks.o qemu-bridge-helper$(EXESUF): qemu-bridge-helper.o diff --git a/Makefile.objs b/Makefile.objs index f99841c..707faa4 100644 --- a/Makefile.objs +++ b/Makefile.objs @@ -57,7 +57,7 @@ common-obj-$(CONFIG_POSIX) += os-posix.o common-obj-$(CONFIG_LINUX) += fsdev/ -common-obj-y += migration.o migration-tcp.o +common-obj-y += migration.o migration-tcp.o migration-flush-hooks.o common-obj-y += qemu-char.o #aio.o common-obj-y += block-migration.o common-obj-y += page_cache.o xbzrle.o diff --git a/block.c b/block.c index 0ae2e93..b8d8ccc 100644 --- a/block.c +++ b/block.c @@ -34,6 +34,7 @@ #include "block/coroutine.h" #include "qmp-commands.h" #include "qemu/timer.h" +#include "migration/migration-flush-hooks.h" #ifdef CONFIG_BSD #include @@ -4131,8 +4132,15 @@ BlockDriverAIOCB *bdrv_aio_discard(BlockDriverState *bs, return &acb->common; } +static void bdrv_migration_flush_hook(void) +{ + bdrv_drain_all(); + bdrv_flush_all(); +} + void bdrv_init(void) { + register_migration_flush_hook(bdrv_migration_flush_hook); module_call_init(MODULE_INIT_BLOCK); } diff --git a/cpus.c b/cpus.c index e919dd7..9beaebc 100644 --- a/cpus.c +++ b/cpus.c @@ -38,6 +38,8 @@ #include "qemu/main-loop.h" #include "qemu/bitmap.h" +#include "migration/migration-flush-hooks.h" + #ifndef _WIN32 #include "qemu/compatfd.h" #endif @@ -444,8 +446,8 @@ static void do_vm_stop(RunState state) pause_all_vcpus(); runstate_set(state); vm_state_notify(0, state); - bdrv_drain_all(); - bdrv_flush_all(); + /* Here we will flush remaining ios */ + exec_migration_flush_hooks(); monitor_protocol_event(QEVENT_STOP, NULL); } } diff --git a/include/migration/migration-flush-hooks.h b/include/migration/migration-flush-hooks.h new file mode 100644 index 0000000..be9e597 --- /dev/null +++ b/include/migration/migration-flush-hooks.h @@ -0,0 +1,30 @@ +/* + * QEMU live pre migration flush hooks + * + * Copyright Nodalink, SARL. 2013 + * + * Authors: + * Benoît Canet + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + */ + +#ifndef QEMU_MIGRATION_FLUSH_HOOKS_H +#define QEMU_MIGRATION_FLUSH_HOOKS_H + +#include "qemu/queue.h" + +typedef struct MigrationFlushHookEntry { + void (*flush_hook)(void); + QTAILQ_ENTRY(MigrationFlushHookEntry) node; +} MigrationFlushHookEntry; + +void init_migration_flush_hooks(void); + +void register_migration_flush_hook(void (*fn)(void)); + +void exec_migration_flush_hooks(void); + +#endif diff --git a/migration-flush-hooks.c b/migration-flush-hooks.c new file mode 100644 index 0000000..b8e1bf4 --- /dev/null +++ b/migration-flush-hooks.c @@ -0,0 +1,62 @@ +/* + * QEMU live pre migration flush hooks + * + * Copyright Nodalink, SARL. 2013 + * + * Modeled after utils/modules.c + * + * Authors: + * Benoît Canet + * + * This work is licensed under the terms of the GNU GPL, version 2 or later. + * See the COPYING file in the top-level directory. + * + * The purpose of this file is to allow various part of QEMU to register hooks + * used to flush ios after vcpus are paused on live migration preparation. + * + */ +#include +#include "migration/migration-flush-hooks.h" + + +typedef QTAILQ_HEAD(, MigrationFlushHookEntry) FlushHookList; + +/* the static NULL pointer will disable the feature if not initialized */ +static FlushHookList *flush_hooks; + +void init_migration_flush_hooks(void) +{ + if (flush_hooks) { + return; + } + + flush_hooks = g_new0(FlushHookList, 1); + QTAILQ_INIT(flush_hooks); +} + +void register_migration_flush_hook(void (*fn)(void)) +{ + MigrationFlushHookEntry *e; + + if (!flush_hooks) { + return; + } + + e = g_new0(MigrationFlushHookEntry, 1); + e->flush_hook = fn; + + QTAILQ_INSERT_TAIL(flush_hooks, e, node); +} + +void exec_migration_flush_hooks(void) +{ + MigrationFlushHookEntry *e; + + if (!flush_hooks) { + return; + } + + QTAILQ_FOREACH(e, flush_hooks, node) { + e->flush_hook(); + } +} diff --git a/vl.c b/vl.c index e2c9706..b4fbcf7 100644 --- a/vl.c +++ b/vl.c @@ -139,6 +139,7 @@ int main(int argc, char **argv) #include "sysemu/blockdev.h" #include "hw/block-common.h" #include "migration/block.h" +#include "migration/migration-flush-hooks.h" #include "tpm/tpm.h" #include "sysemu/dma.h" #include "audio/audio.h" @@ -2941,6 +2942,11 @@ int main(int argc, char **argv, char **envp) nb_numa_nodes = 0; nb_nics = 0; + /* Initialize the list containing pre migration flush hooks before + * registeriring the first hook in bdrv_init(). + */ + init_migration_flush_hooks(); + bdrv_init_with_whitelist(); autostart= 1;