diff options
author | Eric Blake <eblake@redhat.com> | 2020-04-28 14:26:46 -0500 |
---|---|---|
committer | Max Reitz <mreitz@redhat.com> | 2020-05-05 13:17:36 +0200 |
commit | a3aeeab557f08285c4fcf537fca575b069eb67ef (patch) | |
tree | c7baa354e4f6b9bd1d62f570c2da8cb84e6397c5 /block/qcow2.c | |
parent | 52ea799e9631ff00c230f1fed50986246149d8f2 (diff) | |
download | qemu-a3aeeab557f08285c4fcf537fca575b069eb67ef.zip qemu-a3aeeab557f08285c4fcf537fca575b069eb67ef.tar.gz qemu-a3aeeab557f08285c4fcf537fca575b069eb67ef.tar.bz2 |
block: Add blk_new_with_bs() helper
There are several callers that need to create a new block backend from
an existing BDS; make the task slightly easier with a common helper
routine.
Suggested-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20200424190903.522087-2-eblake@redhat.com>
[mreitz: Set @ret only in error paths, see
https://lists.nongnu.org/archive/html/qemu-block/2020-04/msg01216.html]
Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-Id: <20200428192648.749066-2-eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
Diffstat (limited to 'block/qcow2.c')
-rw-r--r-- | block/qcow2.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/block/qcow2.c b/block/qcow2.c index 2ba0b17..0edc7f4 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3405,10 +3405,10 @@ qcow2_co_create(BlockdevCreateOptions *create_options, Error **errp) } /* Create BlockBackend to write to the image */ - blk = blk_new(bdrv_get_aio_context(bs), - BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_ALL); - ret = blk_insert_bs(blk, bs, errp); - if (ret < 0) { + blk = blk_new_with_bs(bs, BLK_PERM_WRITE | BLK_PERM_RESIZE, BLK_PERM_ALL, + errp); + if (!blk) { + ret = -EPERM; goto out; } blk_set_allow_write_beyond_eof(blk, true); @@ -5412,12 +5412,10 @@ static int qcow2_amend_options(BlockDriverState *bs, QemuOpts *opts, } if (new_size) { - BlockBackend *blk = blk_new(bdrv_get_aio_context(bs), - BLK_PERM_RESIZE, BLK_PERM_ALL); - ret = blk_insert_bs(blk, bs, errp); - if (ret < 0) { - blk_unref(blk); - return ret; + BlockBackend *blk = blk_new_with_bs(bs, BLK_PERM_RESIZE, BLK_PERM_ALL, + errp); + if (!blk) { + return -EPERM; } /* |