From nobody Thu Nov 13 21:53:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1582894105; cv=none; d=zohomail.com; s=zohoarc; b=hNeJSvMLI7I1mHSWq/sSErlrAOxBiIAckmEw7Rv4oP+7F4KVCl89AXRRRBVfOVlDPMRpm6dg4nxEnxhnhdcM4NAEeRACJfJ0Ekotrk3sIhXG1sq6kp0x7G5Gu/CHHB2DNneqaYxtX/mW1186bXFf4t4jNOwfElnCe6Y/FEzuqQA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1582894105; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=CwLQqse83511sZxyxLXj0O3RrUg6kH/4VcWWgUAjDqg=; b=Igq8PJZ7fkZOnDygvP6LQF4fY3iBVbZHd7spmOPE/2plcv7sjbmZWFUFfL+QW0nZLxJPZGDGFFhYh4sBN6IP7xpPZ0bcxZvHVNy88e4mir8SXYTlEKLNRp7P9ccaGxx5EhPbCuT2fr+ckNFHcqMGHNCMGQGn2nEekut1/G7+FJ0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1582894105102445.47725163203916; Fri, 28 Feb 2020 04:48:25 -0800 (PST) Received: from localhost ([::1]:46420 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1j7f43-0002Ku-Vw for importer@patchew.org; Fri, 28 Feb 2020 07:48:24 -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 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 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) 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= X-MC-Unique: LmA-iKE2PsGbMR_Cj-Fb-A-1 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 Content-Transfer-Encoding: quoted-printable 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" 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 =3D NULL; @@ -1898,7 +1903,6 @@ static void qcow2_reopen_commit(BDRVReopenState *stat= e) bdrv_get_node_name(state->bs)); } } - g_free(state->opaque); } static void qcow2_reopen_abort(BDRVReopenState *state) @@ -5534,6 +5538,7 @@ BlockDriver bdrv_qcow2 =3D { .bdrv_close =3D qcow2_close, .bdrv_reopen_prepare =3D qcow2_reopen_prepare, .bdrv_reopen_commit =3D qcow2_reopen_commit, + .bdrv_reopen_commit_post =3D qcow2_reopen_commit_post, .bdrv_reopen_abort =3D qcow2_reopen_abort, .bdrv_join_options =3D qcow2_join_options, .bdrv_child_perm =3D bdrv_format_default_perms, --=20 2.24.1