From patchwork Wed Oct 28 15:01:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev" X-Patchwork-Id: 537404 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 2E531141321 for ; Thu, 29 Oct 2015 02:05:22 +1100 (AEDT) Received: from localhost ([::1]:38649 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrSHw-0001mL-Ag for incoming@patchwork.ozlabs.org; Wed, 28 Oct 2015 11:05:20 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37423) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrSEI-0004Kh-9i for qemu-devel@nongnu.org; Wed, 28 Oct 2015 11:01:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZrSEC-0003Dj-E0 for qemu-devel@nongnu.org; Wed, 28 Oct 2015 11:01:34 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:48620 helo=relay.sw.ru) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrSEB-0003C3-VY for qemu-devel@nongnu.org; Wed, 28 Oct 2015 11:01:28 -0400 Received: from hades.sw.ru ([10.30.8.132]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id t9SF15Vn000526; Wed, 28 Oct 2015 18:01:13 +0300 (MSK) From: "Denis V. Lunev" To: Date: Wed, 28 Oct 2015 18:01:05 +0300 Message-Id: <1446044465-19312-5-git-send-email-den@openvz.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1446044465-19312-1-git-send-email-den@openvz.org> References: <1446044465-19312-1-git-send-email-den@openvz.org> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x X-Received-From: 195.214.232.25 Cc: Juan Quintela , qemu-devel@nongnu.org, qemu-stable@nongnu.org, Stefan Hajnoczi , Paolo Bonzini , Amit Shah , "Denis V. Lunev" Subject: [Qemu-devel] [PATCH 4/4] migration: add missed aio_context_acquire into HMP snapshot code 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 aio_context should be locked in the similar way as was done in QMP snapshot creation in the other case there are a lot of possible troubles if native AIO mode is enabled for disk. - the command can hang (HMP thread) with missed wakeup (the operation is actually complete) io_submit ioq_submit laio_submit raw_aio_submit raw_aio_readv bdrv_co_io_em bdrv_co_readv_em bdrv_aligned_preadv bdrv_co_do_preadv bdrv_co_do_readv bdrv_co_readv qcow2_co_readv bdrv_aligned_preadv bdrv_co_do_pwritev bdrv_rw_co_entry - QEMU can assert in coroutine re-enter __GI_abort qemu_coroutine_enter bdrv_co_io_em_complete qemu_laio_process_completion qemu_laio_completion_bh aio_bh_poll aio_dispatch aio_poll iothread_run qemu_fopen_bdrv and bdrv_fclose are used in real snapshot operations only along with block drivers. This change should influence only HMP snapshot operations. AioContext lock is reqursive. Thus nested locking should not be a problem. Signed-off-by: Denis V. Lunev CC: Stefan Hajnoczi CC: Paolo Bonzini CC: Juan Quintela CC: Amit Shah Reviewed-by: Juan Quintela --- block/snapshot.c | 5 +++++ migration/savevm.c | 18 +++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/block/snapshot.c b/block/snapshot.c index 89500f2..f6fa17a 100644 --- a/block/snapshot.c +++ b/block/snapshot.c @@ -259,6 +259,9 @@ void bdrv_snapshot_delete_by_id_or_name(BlockDriverState *bs, { int ret; Error *local_err = NULL; + AioContext *aio_context = bdrv_get_aio_context(bs); + + aio_context_acquire(aio_context); ret = bdrv_snapshot_delete(bs, id_or_name, NULL, &local_err); if (ret == -ENOENT || ret == -EINVAL) { @@ -267,6 +270,8 @@ void bdrv_snapshot_delete_by_id_or_name(BlockDriverState *bs, ret = bdrv_snapshot_delete(bs, NULL, id_or_name, &local_err); } + aio_context_release(aio_context); + if (ret < 0) { error_propagate(errp, local_err); } diff --git a/migration/savevm.c b/migration/savevm.c index dbcc39a..1653f56 100644 --- a/migration/savevm.c +++ b/migration/savevm.c @@ -153,7 +153,11 @@ static ssize_t block_get_buffer(void *opaque, uint8_t *buf, int64_t pos, static int bdrv_fclose(void *opaque) { - return bdrv_flush(opaque); + BlockDriverState *bs = (BlockDriverState *)opaque; + int ret = bdrv_flush(bs); + + aio_context_release(bdrv_get_aio_context(bs)); + return ret; } static const QEMUFileOps bdrv_read_ops = { @@ -169,10 +173,18 @@ static const QEMUFileOps bdrv_write_ops = { static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable) { + QEMUFile *file; + if (is_writable) { - return qemu_fopen_ops(bs, &bdrv_write_ops); + file = qemu_fopen_ops(bs, &bdrv_write_ops); + } else { + file = qemu_fopen_ops(bs, &bdrv_read_ops); + } + + if (file != NULL) { + aio_context_acquire(bdrv_get_aio_context(bs)); } - return qemu_fopen_ops(bs, &bdrv_read_ops); + return file; }