Skip to content

Commit

Permalink
block: Fix .bdrv_open flags
Browse files Browse the repository at this point in the history
bdrv_common_open() modified bs->open_flags after inferring the set of
options to pass to the driver's .bdrv_open callback. This means that the
cache options were correctly set in bs->open_flags (and therefore
correctly displayed in 'info block'), but the image would actually be
opened with the default cache mode instead.

This patch removes the flags parameter to bdrv_common_open() (except for
BDRV_O_NO_BACKING it's the same as bs->open_flags anyway, and having two
names for the same thing is confusing), and moves the assignment of
open_flags down to immediately before calling into the block drivers. In
all other places, bs->open_flags is now used consistently.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Tested-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: Denis V. Lunev <den@openvz.org>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
  • Loading branch information
kevmw committed Jan 19, 2016
1 parent 3db34bf commit 82dc8b4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions block.c
Expand Up @@ -905,7 +905,7 @@ static QemuOptsList bdrv_runtime_opts = {
* Removes all processed options from *options.
*/
static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,
QDict *options, int flags, Error **errp)
QDict *options, Error **errp)
{
int ret, open_flags;
const char *filename;
Expand Down Expand Up @@ -943,7 +943,8 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,
goto fail_opts;
}

trace_bdrv_open_common(bs, filename ?: "", flags, drv->format_name);
trace_bdrv_open_common(bs, filename ?: "", bs->open_flags,
drv->format_name);

node_name = qemu_opt_get(opts, "node-name");
bdrv_assign_node_name(bs, node_name, &local_err);
Expand All @@ -955,8 +956,7 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,

bs->request_alignment = 512;
bs->zero_beyond_eof = true;
open_flags = bdrv_open_flags(bs, flags);
bs->read_only = !(open_flags & BDRV_O_RDWR);
bs->read_only = !(bs->open_flags & BDRV_O_RDWR);

if (use_bdrv_whitelist && !bdrv_is_whitelisted(drv, bs->read_only)) {
error_setg(errp,
Expand All @@ -969,7 +969,7 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,
}

assert(bs->copy_on_read == 0); /* bdrv_new() and bdrv_close() make it so */
if (flags & BDRV_O_COPY_ON_READ) {
if (bs->open_flags & BDRV_O_COPY_ON_READ) {
if (!bs->read_only) {
bdrv_enable_copy_on_read(bs);
} else {
Expand All @@ -994,6 +994,7 @@ static int bdrv_open_common(BlockDriverState *bs, BdrvChild *file,
bdrv_set_enable_write_cache(bs, bs->open_flags & BDRV_O_CACHE_WB);

/* Open the image, either directly or using a protocol */
open_flags = bdrv_open_flags(bs, bs->open_flags);
if (drv->bdrv_file_open) {
assert(file == NULL);
assert(!drv->bdrv_needs_filename || filename != NULL);
Expand Down Expand Up @@ -1656,7 +1657,7 @@ static int bdrv_open_inherit(BlockDriverState **pbs, const char *filename,
assert(!(flags & BDRV_O_PROTOCOL) || !file);

/* Open the image */
ret = bdrv_open_common(bs, file, options, flags, &local_err);
ret = bdrv_open_common(bs, file, options, &local_err);
if (ret < 0) {
goto fail;
}
Expand Down

0 comments on commit 82dc8b4

Please sign in to comment.