From patchwork Fri Mar 6 17:14:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin Wolf X-Patchwork-Id: 11424477 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 3D79C14BC for ; Fri, 6 Mar 2020 17:26:04 +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 133822051A for ; Fri, 6 Mar 2020 17:26:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PXkR4twq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 133822051A 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]:39956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAGjb-0004OM-7V for patchwork-qemu-devel@patchwork.kernel.org; Fri, 06 Mar 2020 12:26:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:48629) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jAGZX-00051C-4z for qemu-devel@nongnu.org; Fri, 06 Mar 2020 12:15:41 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jAGZU-00085x-Vp for qemu-devel@nongnu.org; Fri, 06 Mar 2020 12:15:38 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:51334 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 1jAGZS-0007yS-Oo for qemu-devel@nongnu.org; Fri, 06 Mar 2020 12:15:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1583514933; 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=Zk24Gz6842BbVOxvfiB5Wtlxhvz/vvXj7Ef18Q4kwtQ=; b=PXkR4twq6/OxLrWfs26a6oynAjw5Qe9+s803iPWKJZXP6yzh7AgdVDA0KcCsEVW3HLZQ1v h3+DchbxjXUTNmKLPfk8zAMwV+e1N9ouAx9xWWQ59qDOI9j4+10fk2uvbvtqaToDvRnV5V A5XC3ZvIrwoCY7E4fhTHDpEdTkImG/c= 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-4-6uQ8F1S0O5uSBqDBfTfLvQ-1; Fri, 06 Mar 2020 12:15:14 -0500 X-MC-Unique: 6uQ8F1S0O5uSBqDBfTfLvQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8A414800D6C; Fri, 6 Mar 2020 17:15:13 +0000 (UTC) Received: from linux.fritz.box.com (unknown [10.36.118.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8FE3273873; Fri, 6 Mar 2020 17:15:12 +0000 (UTC) From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 06/29] block/qcow2: Move bitmap reopen into bdrv_reopen_commit_post Date: Fri, 6 Mar 2020 18:14:35 +0100 Message-Id: <20200306171458.1848-7-kwolf@redhat.com> In-Reply-To: <20200306171458.1848-1-kwolf@redhat.com> References: <20200306171458.1848-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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] X-Received-From: 205.139.110.61 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: kwolf@redhat.com, peter.maydell@linaro.org, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" From: Peter Krempa 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 Message-Id: Signed-off-by: Kevin Wolf --- 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,