From patchwork Fri Feb 28 12:44:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Krempa X-Patchwork-Id: 11412181 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 221A51395 for ; Fri, 28 Feb 2020 12:48:14 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id ECBE5246AF for ; Fri, 28 Feb 2020 12:48:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="APr+t7WP" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ECBE5246AF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:46420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7f3t-0002Ku-1A for patchwork-qemu-devel@patchwork.kernel.org; Fri, 28 Feb 2020 07:48:13 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:49112) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7f11-0007f8-Gs for qemu-devel@nongnu.org; Fri, 28 Feb 2020 07:45:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1j7f10-000083-Ey for qemu-devel@nongnu.org; Fri, 28 Feb 2020 07:45:15 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:38376 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1j7f10-00007x-Bt for qemu-devel@nongnu.org; Fri, 28 Feb 2020 07:45:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1582893914; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CwLQqse83511sZxyxLXj0O3RrUg6kH/4VcWWgUAjDqg=; b=APr+t7WPquW22Z155PNs5s6QNPTZ2k1rILvpzQx4DCC3dYm4apaC17ybGfQ+I3hNm22m0j tjnDGRB9v0ouAfU+az2/SaCR1kWl0dtqMhIfhJQ2hA8hMZq0gJ3arvxx75hHtWHKD/AtpX aT61BVboBb7i8YeaWeJcH+eM/loCWdY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-173-LmA-iKE2PsGbMR_Cj-Fb-A-1; Fri, 28 Feb 2020 07:45:10 -0500 X-MC-Unique: LmA-iKE2PsGbMR_Cj-Fb-A-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 46171800D55; Fri, 28 Feb 2020 12:45:09 +0000 (UTC) Received: from angien.redhat.com (unknown [10.43.2.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id E248819C7F; Fri, 28 Feb 2020 12:45:07 +0000 (UTC) From: Peter Krempa To: qemu-devel@nongnu.org Subject: [PATCH 2/2] block/qcow2: Move bitmap reopen into bdrv_reopen_commit_post Date: Fri, 28 Feb 2020 13:44:47 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 207.211.31.120 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Peter Krempa , John Snow , qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" The bitmap code requires writing the 'file' child when the qcow2 driver is reopened in read-write mode. If the 'file' child is being reopened due to a permissions change, the modification is commited yet when qcow2_reopen_commit is called. This means that any attempt to write the 'file' child will end with EBADFD as the original fd was already closed. Moving bitmap reopening to the new callback which is called after permission modifications are commited fixes this as the file descriptor will be replaced with the correct one. The above problem manifests itself when reopening 'qcow2' format layer which uses a 'file-posix' file child which was opened with the 'auto-read-only' property set. Signed-off-by: Peter Krempa --- block/qcow2.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 3c754f616b..3640e8c07d 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -1884,6 +1884,11 @@ fail: static void qcow2_reopen_commit(BDRVReopenState *state) { qcow2_update_options_commit(state->bs, state->opaque); + g_free(state->opaque); +} + +static void qcow2_reopen_commit_post(BDRVReopenState *state) +{ if (state->flags & BDRV_O_RDWR) { Error *local_err = NULL; @@ -1898,7 +1903,6 @@ static void qcow2_reopen_commit(BDRVReopenState *state) bdrv_get_node_name(state->bs)); } } - g_free(state->opaque); } static void qcow2_reopen_abort(BDRVReopenState *state) @@ -5534,6 +5538,7 @@ BlockDriver bdrv_qcow2 = { .bdrv_close = qcow2_close, .bdrv_reopen_prepare = qcow2_reopen_prepare, .bdrv_reopen_commit = qcow2_reopen_commit, + .bdrv_reopen_commit_post = qcow2_reopen_commit_post, .bdrv_reopen_abort = qcow2_reopen_abort, .bdrv_join_options = qcow2_join_options, .bdrv_child_perm = bdrv_format_default_perms,