aboutsummaryrefslogtreecommitdiff
path: root/qdev-monitor.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2016-09-20 13:38:42 +0200
committerKevin Wolf <kwolf@redhat.com>2016-09-23 13:36:10 +0200
commit9680caee0fa530726809bc72d44e127ae676e251 (patch)
treef503fcf35a705b9dbb2a7ee39bed4990e38ebad1 /qdev-monitor.c
parent6c1db528b0e1a68c342d49d032af1c707e9de87c (diff)
qdev-monitor: Add blk_by_qdev_id()
This finds the BlockBackend attached to the device model identified by its qdev ID. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'qdev-monitor.c')
-rw-r--r--qdev-monitor.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/qdev-monitor.c b/qdev-monitor.c
index bc0213f5e3..4f78ecb091 100644
--- a/qdev-monitor.c
+++ b/qdev-monitor.c
@@ -28,6 +28,7 @@
#include "qemu/config-file.h"
#include "qemu/error-report.h"
#include "qemu/help_option.h"
+#include "sysemu/block-backend.h"
/*
* Aliases were a bad idea from the start. Let's keep them
@@ -838,6 +839,23 @@ void qmp_device_del(const char *id, Error **errp)
}
}
+BlockBackend *blk_by_qdev_id(const char *id, Error **errp)
+{
+ DeviceState *dev;
+ BlockBackend *blk;
+
+ dev = find_device_state(id, errp);
+ if (dev == NULL) {
+ return NULL;
+ }
+
+ blk = blk_by_dev(dev);
+ if (!blk) {
+ error_setg(errp, "Device does not have a block device backend");
+ }
+ return blk;
+}
+
void qdev_machine_init(void)
{
qdev_get_peripheral_anon();