[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v2 01/10] block: Add blk_by_dev()
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PATCH v2 01/10] block: Add blk_by_dev() |
Date: |
Mon, 19 Sep 2016 18:54:48 +0200 |
This finds a BlockBackend given the device model that is attached to it.
Signed-off-by: Kevin Wolf <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
---
block/block-backend.c | 19 +++++++++++++++++++
include/sysemu/block-backend.h | 1 +
2 files changed, 20 insertions(+)
diff --git a/block/block-backend.c b/block/block-backend.c
index d1349d9..0bd19ab 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -560,6 +560,25 @@ void *blk_get_attached_dev(BlockBackend *blk)
}
/*
+ * Return the BlockBackend which has the device model @dev attached if it
+ * exists, else null.
+ *
+ * @dev must not be null.
+ */
+BlockBackend *blk_by_dev(void *dev)
+{
+ BlockBackend *blk = NULL;
+
+ assert(dev != NULL);
+ while ((blk = blk_all_next(blk)) != NULL) {
+ if (blk->dev == dev) {
+ return blk;
+ }
+ }
+ return NULL;
+}
+
+/*
* Set @blk's device model callbacks to @ops.
* @opaque is the opaque argument to pass to the callbacks.
* This is for use by device models.
diff --git a/include/sysemu/block-backend.h b/include/sysemu/block-backend.h
index 4808a96..410eb68 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -111,6 +111,7 @@ int blk_attach_dev(BlockBackend *blk, void *dev);
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);
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);
--
1.8.3.1
- [Qemu-devel] [PATCH v2 00/10] block: Accept qdev IDs in device level QMP commands, Kevin Wolf, 2016/09/19
- [Qemu-devel] [PATCH v2 02/10] qdev-monitor: Factor out find_device_state(), Kevin Wolf, 2016/09/19
- [Qemu-devel] [PATCH v2 01/10] block: Add blk_by_dev(),
Kevin Wolf <=
- [Qemu-devel] [PATCH v2 04/10] block: Accept device model name for blockdev-open/close-tray, Kevin Wolf, 2016/09/19
- [Qemu-devel] [PATCH v2 03/10] qdev-monitor: Add blk_by_qdev_id(), Kevin Wolf, 2016/09/19
- [Qemu-devel] [PATCH v2 05/10] block: Accept device model name for x-blockdev-insert-medium, Kevin Wolf, 2016/09/19
- [Qemu-devel] [PATCH v2 06/10] block: Accept device model name for x-blockdev-remove-medium, Kevin Wolf, 2016/09/19
- [Qemu-devel] [PATCH v2 08/10] block: Accept device model name for blockdev-change-medium, Kevin Wolf, 2016/09/19
- [Qemu-devel] [PATCH v2 07/10] block: Accept device model name for eject, Kevin Wolf, 2016/09/19