diff options
author | Max Reitz <mreitz@redhat.com> | 2014-02-18 18:33:10 +0100 |
---|---|---|
committer | Kevin Wolf <kwolf@redhat.com> | 2014-02-21 21:02:22 +0100 |
commit | 5469a2a688b47bc6d8d224c3f1b02cd96b0e4b65 (patch) | |
tree | a09f3efedccc0e0deb067da4ea4e2df858d1bf6f /block.c | |
parent | d4446eae630a363403ec73182cf371deeed4e172 (diff) | |
download | qemu-5469a2a688b47bc6d8d224c3f1b02cd96b0e4b65.tar.gz qemu-5469a2a688b47bc6d8d224c3f1b02cd96b0e4b65.tar.bz2 qemu-5469a2a688b47bc6d8d224c3f1b02cd96b0e4b65.zip |
block: Handle bs->options in bdrv_open() only
The fail paths of bdrv_file_open() and bdrv_open() naturally exhibit
similarities, thus it is possible to reuse the one from bdrv_open() and
shorten the one in bdrv_file_open() accordingly.
Also, setting bs->options in bdrv_file_open() is not necessary if it is
already done in bdrv_open().
Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Benoit Canet <benoit@irqsave.net>
Reviewed-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block.c')
-rw-r--r-- | block.c | 38 |
1 files changed, 15 insertions, 23 deletions
@@ -969,14 +969,6 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename, Error *local_err = NULL; int ret; - /* NULL means an empty set of options */ - if (options == NULL) { - options = qdict_new(); - } - - bs->options = options; - options = qdict_clone_shallow(options); - /* Fetch the file name from the options QDict if necessary */ if (!filename) { filename = qdict_get_try_str(options, "filename"); @@ -1051,9 +1043,6 @@ static int bdrv_file_open(BlockDriverState *bs, const char *filename, fail: QDECREF(options); - if (!bs->drv) { - QDECREF(bs->options); - } return ret; } @@ -1254,18 +1243,6 @@ int bdrv_open(BlockDriverState **pbs, const char *filename, bs = bdrv_new(""); } - if (flags & BDRV_O_PROTOCOL) { - assert(!drv); - ret = bdrv_file_open(bs, filename, options, flags & ~BDRV_O_PROTOCOL, - errp); - if (ret && !*pbs) { - bdrv_unref(bs); - } else if (!ret) { - *pbs = bs; - } - return ret; - } - /* NULL means an empty set of options */ if (options == NULL) { options = qdict_new(); @@ -1274,6 +1251,21 @@ int bdrv_open(BlockDriverState **pbs, const char *filename, bs->options = options; options = qdict_clone_shallow(options); + if (flags & BDRV_O_PROTOCOL) { + assert(!drv); + ret = bdrv_file_open(bs, filename, options, flags & ~BDRV_O_PROTOCOL, + &local_err); + options = NULL; + if (!ret) { + *pbs = bs; + return 0; + } else if (bs->drv) { + goto close_and_fail; + } else { + goto fail; + } + } + /* For snapshot=on, create a temporary qcow2 overlay */ if (flags & BDRV_O_SNAPSHOT) { BlockDriverState *bs1; |