From nobody Tue Apr 15 06:44:29 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1622641915; cv=none; d=zohomail.com; s=zohoarc; b=eK1pA8nNLvbKscKuyrhahgzFKSsCC5mxAwrUzz6xMRWVA0LhAXKv7N5KLBhFQ/iyjI6bK4R0wg4KPkjDOcwC1zVxqhZ+JU+2Uc4M21LW/hGooc5Q5m5A05hIQXX9Q77wQAJuYsP28lTxNUtkTGOTrPwR34cY/PHfCnDSgloAZf0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1622641915; 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=uSczhTETjrLOl+SvUO6QOHAEcDO1fonXuQdHChJmCdE=; b=FK8pyEui1bAOmpsEfeHtrtArB6C6Ss/ykZ7Ru8BK/Ij+RWVsUzYLw3HsQXPbL32jUkv9ZvFexaOhweaSKYDcU0Yy5Vsm4k4akAgR38Im7QOwz3D1F8DrF6KyYXyMK7MnBiFR4uoYwKGKZ5pae5WzS9TfERGbpOOAYiOdiNt9nvo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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=pass 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 1622641915296488.9776897872125; Wed, 2 Jun 2021 06:51:55 -0700 (PDT) Received: from localhost ([::1]:60826 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1loRHm-0006Ru-J5 for importer@patchew.org; Wed, 02 Jun 2021 09:51:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1loRC6-0000LF-Na for qemu-devel@nongnu.org; Wed, 02 Jun 2021 09:46:02 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43222) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1loRC4-00076a-TT for qemu-devel@nongnu.org; Wed, 02 Jun 2021 09:46:02 -0400 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-507-iDwnJmA9M8i6xzWcp8aPvg-1; Wed, 02 Jun 2021 09:45:58 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 622638B95A4; Wed, 2 Jun 2021 13:45:42 +0000 (UTC) Received: from merkur.redhat.com (ovpn-114-240.ams2.redhat.com [10.36.114.240]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E25160BD9; Wed, 2 Jun 2021 13:45:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1622641560; 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=uSczhTETjrLOl+SvUO6QOHAEcDO1fonXuQdHChJmCdE=; b=FxIFNm6iLudWJUKLyExXHi3tq//FwKjReXj7kwlFdHpt7nIsRPHinPl4IPME8ck606TQ8w tIcYwlyeiAS2KX8QmIefY81Rg86b3U+Tk5fhDctj6PM++QkgPNnUb8i0e0Tmb9YYhQv1VU d+p+3Nl50wEd5zEj0lUUWnPosQAAlHU= X-MC-Unique: iDwnJmA9M8i6xzWcp8aPvg-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PULL 06/20] block: drop BlockDriverState::read_only Date: Wed, 2 Jun 2021 15:45:15 +0200 Message-Id: <20210602134529.231756-7-kwolf@redhat.com> In-Reply-To: <20210602134529.231756-1-kwolf@redhat.com> References: <20210602134529.231756-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=kwolf@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=216.205.24.124; envelope-from=kwolf@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -31 X-Spam_score: -3.2 X-Spam_bar: --- X-Spam_report: (-3.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.371, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy This variable is just a cache for !(bs->open_flags & BDRV_O_RDWR), which we have to synchronize everywhere. Let's just drop it and consistently use bdrv_is_read_only(). Signed-off-by: Vladimir Sementsov-Ogievskiy Message-Id: <20210527154056.70294-3-vsementsov@virtuozzo.com> Signed-off-by: Kevin Wolf --- include/block/block_int.h | 1 - block.c | 7 +------ tests/unit/test-block-iothread.c | 6 ------ 3 files changed, 1 insertion(+), 13 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index b2c8b09d0f..09661a134b 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -843,7 +843,6 @@ struct BlockDriverState { * locking needed during I/O... */ int open_flags; /* flags used to open the file, re-used for re-open */ - bool read_only; /* if true, the media is read only */ bool encrypted; /* if true, the media is encrypted */ bool sg; /* if true, the device is a /dev/sg* */ bool probed; /* if true, format was probed rather than specified */ diff --git a/block.c b/block.c index 33e99d0c9e..84cb7212f7 100644 --- a/block.c +++ b/block.c @@ -265,7 +265,7 @@ void bdrv_parse_filename_strip_prefix(const char *filen= ame, const char *prefix, * image is inactivated. */ bool bdrv_is_read_only(BlockDriverState *bs) { - return bs->read_only; + return !(bs->open_flags & BDRV_O_RDWR); } =20 int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only, @@ -317,7 +317,6 @@ int bdrv_apply_auto_read_only(BlockDriverState *bs, con= st char *errmsg, goto fail; } =20 - bs->read_only =3D true; bs->open_flags &=3D ~BDRV_O_RDWR; =20 return 0; @@ -1549,7 +1548,6 @@ static int bdrv_open_driver(BlockDriverState *bs, Blo= ckDriver *drv, } =20 bs->drv =3D drv; - bs->read_only =3D !(bs->open_flags & BDRV_O_RDWR); bs->opaque =3D g_malloc0(drv->instance_size); =20 if (drv->bdrv_file_open) { @@ -1771,8 +1769,6 @@ static int bdrv_open_common(BlockDriverState *bs, Blo= ckBackend *file, trace_bdrv_open_common(bs, filename ?: "", bs->open_flags, drv->format_name); =20 - bs->read_only =3D !(bs->open_flags & BDRV_O_RDWR); - ro =3D bdrv_is_read_only(bs); =20 if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, ro)) { @@ -4548,7 +4544,6 @@ static void bdrv_reopen_commit(BDRVReopenState *reope= n_state) bs->explicit_options =3D reopen_state->explicit_options; bs->options =3D reopen_state->options; bs->open_flags =3D reopen_state->flags; - bs->read_only =3D !(reopen_state->flags & BDRV_O_RDWR); bs->detect_zeroes =3D reopen_state->detect_zeroes; =20 if (reopen_state->replace_backing_bs) { diff --git a/tests/unit/test-block-iothread.c b/tests/unit/test-block-iothr= ead.c index 8cf172cb7a..c39e70b2f5 100644 --- a/tests/unit/test-block-iothread.c +++ b/tests/unit/test-block-iothread.c @@ -194,13 +194,11 @@ static void test_sync_op_truncate(BdrvChild *c) g_assert_cmpint(ret, =3D=3D, -EINVAL); =20 /* Error: Read-only image */ - c->bs->read_only =3D true; c->bs->open_flags &=3D ~BDRV_O_RDWR; =20 ret =3D bdrv_truncate(c, 65536, false, PREALLOC_MODE_OFF, 0, NULL); g_assert_cmpint(ret, =3D=3D, -EACCES); =20 - c->bs->read_only =3D false; c->bs->open_flags |=3D BDRV_O_RDWR; } =20 @@ -236,13 +234,11 @@ static void test_sync_op_flush(BdrvChild *c) g_assert_cmpint(ret, =3D=3D, 0); =20 /* Early success: Read-only image */ - c->bs->read_only =3D true; c->bs->open_flags &=3D ~BDRV_O_RDWR; =20 ret =3D bdrv_flush(c->bs); g_assert_cmpint(ret, =3D=3D, 0); =20 - c->bs->read_only =3D false; c->bs->open_flags |=3D BDRV_O_RDWR; } =20 @@ -256,13 +252,11 @@ static void test_sync_op_blk_flush(BlockBackend *blk) g_assert_cmpint(ret, =3D=3D, 0); =20 /* Early success: Read-only image */ - bs->read_only =3D true; bs->open_flags &=3D ~BDRV_O_RDWR; =20 ret =3D blk_flush(blk); g_assert_cmpint(ret, =3D=3D, 0); =20 - bs->read_only =3D false; bs->open_flags |=3D BDRV_O_RDWR; } =20 --=20 2.30.2