Skip to content

Commit

Permalink
block: drop BlockDriverState::read_only
Browse files Browse the repository at this point in the history
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 <vsementsov@virtuozzo.com>
Message-Id: <20210527154056.70294-3-vsementsov@virtuozzo.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
Vladimir Sementsov-Ogievskiy authored and kevmw committed Jun 2, 2021
1 parent 307261b commit 975da07
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 13 deletions.
7 changes: 1 addition & 6 deletions block.c
Expand Up @@ -265,7 +265,7 @@ void bdrv_parse_filename_strip_prefix(const char *filename, const char *prefix,
* image is inactivated. */
bool bdrv_is_read_only(BlockDriverState *bs)
{
return bs->read_only;
return !(bs->open_flags & BDRV_O_RDWR);
}

int bdrv_can_set_read_only(BlockDriverState *bs, bool read_only,
Expand Down Expand Up @@ -317,7 +317,6 @@ int bdrv_apply_auto_read_only(BlockDriverState *bs, const char *errmsg,
goto fail;
}

bs->read_only = true;
bs->open_flags &= ~BDRV_O_RDWR;

return 0;
Expand Down Expand Up @@ -1549,7 +1548,6 @@ static int bdrv_open_driver(BlockDriverState *bs, BlockDriver *drv,
}

bs->drv = drv;
bs->read_only = !(bs->open_flags & BDRV_O_RDWR);
bs->opaque = g_malloc0(drv->instance_size);

if (drv->bdrv_file_open) {
Expand Down Expand Up @@ -1771,8 +1769,6 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
trace_bdrv_open_common(bs, filename ?: "", bs->open_flags,
drv->format_name);

bs->read_only = !(bs->open_flags & BDRV_O_RDWR);

ro = bdrv_is_read_only(bs);

if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, ro)) {
Expand Down Expand Up @@ -4548,7 +4544,6 @@ static void bdrv_reopen_commit(BDRVReopenState *reopen_state)
bs->explicit_options = reopen_state->explicit_options;
bs->options = reopen_state->options;
bs->open_flags = reopen_state->flags;
bs->read_only = !(reopen_state->flags & BDRV_O_RDWR);
bs->detect_zeroes = reopen_state->detect_zeroes;

if (reopen_state->replace_backing_bs) {
Expand Down
1 change: 0 additions & 1 deletion include/block/block_int.h
Expand Up @@ -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 */
Expand Down
6 changes: 0 additions & 6 deletions tests/unit/test-block-iothread.c
Expand Up @@ -194,13 +194,11 @@ static void test_sync_op_truncate(BdrvChild *c)
g_assert_cmpint(ret, ==, -EINVAL);

/* Error: Read-only image */
c->bs->read_only = true;
c->bs->open_flags &= ~BDRV_O_RDWR;

ret = bdrv_truncate(c, 65536, false, PREALLOC_MODE_OFF, 0, NULL);
g_assert_cmpint(ret, ==, -EACCES);

c->bs->read_only = false;
c->bs->open_flags |= BDRV_O_RDWR;
}

Expand Down Expand Up @@ -236,13 +234,11 @@ static void test_sync_op_flush(BdrvChild *c)
g_assert_cmpint(ret, ==, 0);

/* Early success: Read-only image */
c->bs->read_only = true;
c->bs->open_flags &= ~BDRV_O_RDWR;

ret = bdrv_flush(c->bs);
g_assert_cmpint(ret, ==, 0);

c->bs->read_only = false;
c->bs->open_flags |= BDRV_O_RDWR;
}

Expand All @@ -256,13 +252,11 @@ static void test_sync_op_blk_flush(BlockBackend *blk)
g_assert_cmpint(ret, ==, 0);

/* Early success: Read-only image */
bs->read_only = true;
bs->open_flags &= ~BDRV_O_RDWR;

ret = blk_flush(blk);
g_assert_cmpint(ret, ==, 0);

bs->read_only = false;
bs->open_flags |= BDRV_O_RDWR;
}

Expand Down

0 comments on commit 975da07

Please sign in to comment.