mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 23:03:54 -06:00
hw: Convert from BlockDriverState to BlockBackend, mostly
Device models should access their block backends only through the block-backend.h API. Convert them, and drop direct includes of inappropriate headers. Just four uses of BlockDriverState are left: * The Xen paravirtual block device backend (xen_disk.c) opens images itself when set up via xenbus, bypassing blockdev.c. I figure it should go through qmp_blockdev_add() instead. * Device model "usb-storage" prompts for keys. No other device model does, and this one probably shouldn't do it, either. * ide_issue_trim_cb() uses bdrv_aio_discard() instead of blk_aio_discard() because it fishes its backend out of a BlockAIOCB, which has only the BlockDriverState. * PC87312State has an unused BlockDriverState[] member. The next two commits take care of the latter two. Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
2a30307f70
commit
4be746345f
110 changed files with 1127 additions and 798 deletions
|
@ -13,6 +13,7 @@
|
|||
#include "net/net.h"
|
||||
#include "hw/qdev.h"
|
||||
#include "qapi/qmp/qerror.h"
|
||||
#include "sysemu/block-backend.h"
|
||||
#include "sysemu/blockdev.h"
|
||||
#include "hw/block/block.h"
|
||||
#include "net/hub.h"
|
||||
|
@ -68,16 +69,16 @@ static void set_pointer(Object *obj, Visitor *v, Property *prop,
|
|||
|
||||
static int parse_drive(DeviceState *dev, const char *str, void **ptr)
|
||||
{
|
||||
BlockDriverState *bs;
|
||||
BlockBackend *blk;
|
||||
|
||||
bs = bdrv_find(str);
|
||||
if (bs == NULL) {
|
||||
blk = blk_by_name(str);
|
||||
if (!blk) {
|
||||
return -ENOENT;
|
||||
}
|
||||
if (bdrv_attach_dev(bs, dev) < 0) {
|
||||
if (blk_attach_dev(blk, dev) < 0) {
|
||||
return -EEXIST;
|
||||
}
|
||||
*ptr = bs;
|
||||
*ptr = blk;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -85,17 +86,17 @@ static void release_drive(Object *obj, const char *name, void *opaque)
|
|||
{
|
||||
DeviceState *dev = DEVICE(obj);
|
||||
Property *prop = opaque;
|
||||
BlockDriverState **ptr = qdev_get_prop_ptr(dev, prop);
|
||||
BlockBackend **ptr = qdev_get_prop_ptr(dev, prop);
|
||||
|
||||
if (*ptr) {
|
||||
bdrv_detach_dev(*ptr, dev);
|
||||
blk_detach_dev(*ptr, dev);
|
||||
blockdev_auto_del(*ptr);
|
||||
}
|
||||
}
|
||||
|
||||
static char *print_drive(void *ptr)
|
||||
{
|
||||
return g_strdup(bdrv_get_device_name(ptr));
|
||||
return g_strdup(blk_name(ptr));
|
||||
}
|
||||
|
||||
static void get_drive(Object *obj, Visitor *v, void *opaque,
|
||||
|
@ -335,12 +336,11 @@ PropertyInfo qdev_prop_vlan = {
|
|||
};
|
||||
|
||||
int qdev_prop_set_drive(DeviceState *dev, const char *name,
|
||||
BlockDriverState *value)
|
||||
BlockBackend *value)
|
||||
{
|
||||
Error *err = NULL;
|
||||
const char *bdrv_name = value ? bdrv_get_device_name(value) : "";
|
||||
object_property_set_str(OBJECT(dev), bdrv_name,
|
||||
name, &err);
|
||||
object_property_set_str(OBJECT(dev),
|
||||
value ? blk_name(value) : "", name, &err);
|
||||
if (err) {
|
||||
qerror_report_err(err);
|
||||
error_free(err);
|
||||
|
@ -350,7 +350,7 @@ int qdev_prop_set_drive(DeviceState *dev, const char *name,
|
|||
}
|
||||
|
||||
void qdev_prop_set_drive_nofail(DeviceState *dev, const char *name,
|
||||
BlockDriverState *value)
|
||||
BlockBackend *value)
|
||||
{
|
||||
if (qdev_prop_set_drive(dev, name, value) < 0) {
|
||||
exit(1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue