From patchwork Thu Jun 16 14:08:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 9181187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C465360760 for ; Thu, 16 Jun 2016 14:50:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B550927248 for ; Thu, 16 Jun 2016 14:50:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA3C028362; Thu, 16 Jun 2016 14:50:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 34BA827248 for ; Thu, 16 Jun 2016 14:50:51 +0000 (UTC) Received: from localhost ([::1]:49850 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDYd8-00071j-7i for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 Jun 2016 10:50:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46343) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDXz4-0008C4-In for qemu-devel@nongnu.org; Thu, 16 Jun 2016 10:09:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bDXyz-0000ei-An for qemu-devel@nongnu.org; Thu, 16 Jun 2016 10:09:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43675) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bDXyp-0000YZ-Jg; Thu, 16 Jun 2016 10:09:11 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 45C1AC04B308; Thu, 16 Jun 2016 14:09:11 +0000 (UTC) Received: from noname.redhat.com (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5GE8XUR003905; Thu, 16 Jun 2016 10:09:10 -0400 From: Kevin Wolf To: qemu-block@nongnu.org Date: Thu, 16 Jun 2016 16:08:20 +0200 Message-Id: <1466086108-24868-32-git-send-email-kwolf@redhat.com> In-Reply-To: <1466086108-24868-1-git-send-email-kwolf@redhat.com> References: <1466086108-24868-1-git-send-email-kwolf@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 16 Jun 2016 14:09:11 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 31/39] block: Create the commit block job before reopening any image X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Alberto Garcia If the base or overlay images need to be reopened in read-write mode but the block_job_create() call fails then no one will put those images back in read-only mode. We can solve this problem easily by calling block_job_create() first. Signed-off-by: Alberto Garcia Message-id: aa495045770a6f1a7cc5d408397a17c75097fdd8.1464346103.git.berto@igalia.com Reviewed-by: Max Reitz Signed-off-by: Max Reitz --- block/commit.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/block/commit.c b/block/commit.c index 8a00e11..444333b 100644 --- a/block/commit.c +++ b/block/commit.c @@ -236,6 +236,11 @@ void commit_start(BlockDriverState *bs, BlockDriverState *base, return; } + s = block_job_create(&commit_job_driver, bs, speed, cb, opaque, errp); + if (!s) { + return; + } + orig_base_flags = bdrv_get_flags(base); orig_overlay_flags = bdrv_get_flags(overlay_bs); @@ -252,16 +257,12 @@ void commit_start(BlockDriverState *bs, BlockDriverState *base, bdrv_reopen_multiple(reopen_queue, &local_err); if (local_err != NULL) { error_propagate(errp, local_err); + block_job_unref(&s->common); return; } } - s = block_job_create(&commit_job_driver, bs, speed, cb, opaque, errp); - if (!s) { - return; - } - s->base = blk_new(); blk_insert_bs(s->base, base);