[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-block] [PATCH 03/10] qdev-monitor: Add blk_by_qdev_id()
From: |
Kevin Wolf |
Subject: |
[Qemu-block] [PATCH 03/10] qdev-monitor: Add blk_by_qdev_id() |
Date: |
Fri, 19 Aug 2016 18:50:28 +0200 |
This finds the BlockBackend attached to the device model identified by
its qdev ID.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
include/sysemu/block-backend.h | 1 +
qdev-monitor.c | 18 ++++++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index 410eb68..3b29317 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -112,6 +112,7 @@ void blk_attach_dev_nofail(BlockBackend *blk, void *dev);
void blk_detach_dev(BlockBackend *blk, void *dev);
void *blk_get_attached_dev(BlockBackend *blk);
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);
int blk_pread_unthrottled(BlockBackend *blk, int64_t offset, uint8_t *buf,
int count);
diff --git a/qdev-monitor.c b/qdev-monitor.c
index bc0213f..4f78ecb 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();
--
1.8.3.1
- [Qemu-block] [PATCH 00/10] block: Accept qdev IDs in device level QMP commands, Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 01/10] block: Add blk_by_dev(), Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 05/10] block: Accept device model name for x-blockdev-insert-medium, Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 02/10] qdev-monitor: Factor out find_device_state(), Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 06/10] block: Accept device model name for x-blockdev-remove-medium, Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 04/10] block: Accept device model name for blockdev-open/close-tray, Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 03/10] qdev-monitor: Add blk_by_qdev_id(),
Kevin Wolf <=
- [Qemu-block] [PATCH 07/10] block: Accept device model name for eject, Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 10/10] qemu-iotests/118: Test media change with qdev name, Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 08/10] block: Accept device model name for blockdev-change-medium, Kevin Wolf, 2016/08/19
- [Qemu-block] [PATCH 09/10] block: Accept device model name for block_set_io_throttle, Kevin Wolf, 2016/08/19