aboutsummaryrefslogtreecommitdiff
path: root/blockdev.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2014-10-07 13:59:05 +0200
committerKevin Wolf <kwolf@redhat.com>2014-10-20 13:41:26 +0200
commit7e7d56d9e05b340290669442cfa05f5869204572 (patch)
tree5ac3934eadc67544a188e1f368357bfe16c6b81c /blockdev.c
parent26f54e9a3cfe62fca61baf83a06b269935d6b9a4 (diff)
downloadqemu-7e7d56d9e05b340290669442cfa05f5869204572.zip
qemu-7e7d56d9e05b340290669442cfa05f5869204572.tar.gz
qemu-7e7d56d9e05b340290669442cfa05f5869204572.tar.bz2
block: Connect BlockBackend to BlockDriverState
Convenience function blk_new_with_bs() creates a BlockBackend with its BlockDriverState. Callers have to unref both. The commit after next will relieve them of the need to unref the BlockDriverState. Complication: due to the silly way drive_del works, we need a way to hide a BlockBackend, just like bdrv_make_anon(). To emphasize its "special" status, give the function a suitably off-putting name: blk_hide_on_behalf_of_do_drive_del(). Unfortunately, hiding turns the BlockBackend's name into the empty string. Can't avoid that without breaking the blk->bs->device_name equals blk->name invariant. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'blockdev.c')
-rw-r--r--blockdev.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/blockdev.c b/blockdev.c
index 508188e..12fabcc 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -279,7 +279,7 @@ static void bdrv_format_print(void *opaque, const char *name)
void drive_del(DriveInfo *dinfo)
{
- BlockBackend *blk = blk_by_name(dinfo->id);
+ BlockBackend *blk = dinfo->bdrv->blk;
bdrv_unref(dinfo->bdrv);
blk_unref(blk);
@@ -528,14 +528,11 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
}
/* init */
- blk = blk_new(qemu_opts_id(opts), errp);
+ blk = blk_new_with_bs(qemu_opts_id(opts), errp);
if (!blk) {
goto early_err;
}
- bs = bdrv_new_root(qemu_opts_id(opts), errp);
- if (!bs) {
- goto bdrv_new_err;
- }
+ bs = blk_bs(blk);
bs->open_flags = snapshot ? BDRV_O_SNAPSHOT : 0;
bs->read_only = ro;
bs->detect_zeroes = detect_zeroes;
@@ -600,7 +597,6 @@ static DriveInfo *blockdev_init(const char *file, QDict *bs_opts,
err:
bdrv_unref(bs);
-bdrv_new_err:
blk_unref(blk);
early_err:
qemu_opts_del(opts);
@@ -1840,16 +1836,18 @@ void qmp_block_set_io_throttle(const char *device, int64_t bps, int64_t bps_rd,
int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
{
const char *id = qdict_get_str(qdict, "id");
+ BlockBackend *blk;
BlockDriverState *bs;
DriveInfo *dinfo;
AioContext *aio_context;
Error *local_err = NULL;
- bs = bdrv_find(id);
- if (!bs) {
+ blk = blk_by_name(id);
+ if (!blk) {
error_report("Device '%s' not found", id);
return -1;
}
+ bs = blk_bs(blk);
dinfo = drive_get_by_blockdev(bs);
if (dinfo && !dinfo->enable_auto_del) {
@@ -1879,8 +1877,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
* then we can just get rid of the block driver state right here.
*/
if (bdrv_get_attached_dev(bs)) {
- bdrv_make_anon(bs);
-
+ blk_hide_on_behalf_of_do_drive_del(blk);
/* Further I/O must not pause the guest */
bdrv_set_on_error(bs, BLOCKDEV_ON_ERROR_REPORT,
BLOCKDEV_ON_ERROR_REPORT);