Received: from eggs.gnu.org ([2001:4830:134:3::10]:47301) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZc8R-0001FU-8m for qemu-devel@nongnu.org; Thu, 02 Oct 2014 04:53:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XZc8I-0005dH-T0 for qemu-devel@nongnu.org; Thu, 02 Oct 2014 04:53:15 -0400 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:46869) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XZc8I-0005cE-6m for qemu-devel@nongnu.org; Thu, 02 Oct 2014 04:53:06 -0400 Received: from /spool/local by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 2 Oct 2014 18:53:02 +1000 Received: from d23relay05.au.ibm.com (d23relay05.au.ibm.com [9.190.235.152]) by d23dlp01.au.ibm.com (Postfix) with ESMTP id 16F5E2CE8047 for ; Thu, 2 Oct 2014 18:53:00 +1000 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay05.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id s928Sf0J58720414 for ; Thu, 2 Oct 2014 18:28:42 +1000 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s928qwCV019284 for ; Thu, 2 Oct 2014 18:52:58 +1000 From: Alexey Kardashevskiy Date: Thu, 2 Oct 2014 18:52:52 +1000 Message-Id: <1412239972-23493-1-git-send-email-aik@ozlabs.ru> Subject: [Qemu-devel] [RFC PATCH] block/migration: Disable cache invalidate for incoming migration List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Alexey Kardashevskiy , Kevin Wolf , Stefan Hajnoczi , Paolo Bonzini When migrated using libvirt with "--copy-storage-all", at the end of migration there is race between NBD mirroring task trying to do flush and migration completion, both end up invalidating cache. Since qcow2 driver does not handle this situation very well, random crashes happen. This disables the BDRV_O_INCOMING flag for the block device being migrated and restores it when NBD task is done. Signed-off-by: Alexey Kardashevskiy --- The commit log is not full and most likely incorrect as well as the patch :) Please, help. Thanks! The patch seems to fix the initial problem though. btw is there any easy way to migrate one QEMU to another using NBD (i.e. not using "migrate -b") and not using libvirt? What would the command line be? Debugging with libvirt is real pain :( --- block.c | 17 ++++------------- migration.c | 1 - nbd.c | 11 +++++++++++ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/block.c b/block.c index c5a251c..ed72e0a 100644 --- a/block.c +++ b/block.c @@ -5073,6 +5073,10 @@ void bdrv_invalidate_cache_all(Error **errp) QTAILQ_FOREACH(bs, &bdrv_states, device_list) { AioContext *aio_context = bdrv_get_aio_context(bs); + if (!(bs->open_flags & BDRV_O_INCOMING)) { + continue; + } + aio_context_acquire(aio_context); bdrv_invalidate_cache(bs, &local_err); aio_context_release(aio_context); @@ -5083,19 +5087,6 @@ void bdrv_invalidate_cache_all(Error **errp) } } -void bdrv_clear_incoming_migration_all(void) -{ - BlockDriverState *bs; - - QTAILQ_FOREACH(bs, &bdrv_states, device_list) { - AioContext *aio_context = bdrv_get_aio_context(bs); - - aio_context_acquire(aio_context); - bs->open_flags = bs->open_flags & ~(BDRV_O_INCOMING); - aio_context_release(aio_context); - } -} - int bdrv_flush(BlockDriverState *bs) { Coroutine *co; diff --git a/migration.c b/migration.c index 8d675b3..c49a05a 100644 --- a/migration.c +++ b/migration.c @@ -103,7 +103,6 @@ static void process_incoming_migration_co(void *opaque) } qemu_announce_self(); - bdrv_clear_incoming_migration_all(); /* Make sure all file formats flush their mutable metadata */ bdrv_invalidate_cache_all(&local_err); if (local_err) { diff --git a/nbd.c b/nbd.c index e9b539b..7b479c0 100644 --- a/nbd.c +++ b/nbd.c @@ -106,6 +106,7 @@ struct NBDExport { off_t dev_offset; off_t size; uint32_t nbdflags; + bool restore_incoming; QTAILQ_HEAD(, NBDClient) clients; QTAILQ_ENTRY(NBDExport) next; @@ -972,6 +973,13 @@ NBDExport *nbd_export_new(BlockDriverState *bs, off_t dev_offset, exp->ctx = bdrv_get_aio_context(bs); bdrv_ref(bs); bdrv_add_aio_context_notifier(bs, bs_aio_attached, bs_aio_detach, exp); + + if (bs->open_flags & BDRV_O_INCOMING) { + bdrv_invalidate_cache(bs, NULL); + exp->restore_incoming = !!(bs->open_flags & BDRV_O_INCOMING); + bs->open_flags &= ~(BDRV_O_INCOMING); + } + return exp; } @@ -1021,6 +1029,9 @@ void nbd_export_close(NBDExport *exp) if (exp->bs) { bdrv_remove_aio_context_notifier(exp->bs, bs_aio_attached, bs_aio_detach, exp); + if (exp->restore_incoming) { + exp->bs->open_flags |= BDRV_O_INCOMING; + } bdrv_unref(exp->bs); exp->bs = NULL; } -- 2.0.0