提交 9680caee 编写于 作者: K Kevin Wolf

qdev-monitor: Add blk_by_qdev_id()

This finds the BlockBackend attached to the device model identified by
its qdev ID.
Signed-off-by: NKevin Wolf <kwolf@redhat.com>
Reviewed-by: NEric Blake <eblake@redhat.com>
上级 6c1db528
...@@ -112,6 +112,7 @@ void blk_attach_dev_nofail(BlockBackend *blk, void *dev); ...@@ -112,6 +112,7 @@ void blk_attach_dev_nofail(BlockBackend *blk, void *dev);
void blk_detach_dev(BlockBackend *blk, void *dev); void blk_detach_dev(BlockBackend *blk, void *dev);
void *blk_get_attached_dev(BlockBackend *blk); void *blk_get_attached_dev(BlockBackend *blk);
BlockBackend *blk_by_dev(void *dev); BlockBackend *blk_by_dev(void *dev);
BlockBackend *blk_by_qdev_id(const char *id, Error **errp);
void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque); void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque);
int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf, int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf,
int count); int count);
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include "qemu/config-file.h" #include "qemu/config-file.h"
#include "qemu/error-report.h" #include "qemu/error-report.h"
#include "qemu/help_option.h" #include "qemu/help_option.h"
#include "sysemu/block-backend.h"
/* /*
* Aliases were a bad idea from the start. Let's keep them * 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) ...@@ -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) void qdev_machine_init(void)
{ {
qdev_get_peripheral_anon(); qdev_get_peripheral_anon();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册