[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 01/16] introduce a new API to enable/disable attach
From: |
Wen Congyang |
Subject: |
[Qemu-devel] [PATCH 01/16] introduce a new API to enable/disable attach device model |
Date: |
Wed, 2 Sep 2015 16:51:05 +0800 |
Signed-off-by: Wen Congyang <address@hidden>
---
block/block-backend.c | 24 ++++++++++++++++++++++++
include/sysemu/block-backend.h | 2 ++
2 files changed, 26 insertions(+)
diff --git a/block/block-backend.c b/block/block-backend.c
index aee8a12..72d8b2c 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -344,6 +344,30 @@ void *blk_get_attached_dev(BlockBackend *blk)
}
/*
+ * Disable to attach a device mode to @blk.
+ * Return 0 on success, -EBUSY when a device model is attached already.
+ */
+int blk_disable_attach_dev(BlockBackend *blk)
+{
+ if (blk->dev) {
+ return blk->dev == (void *)-1 ? 0 : -EBUSY;
+ }
+
+ blk->dev = (void *)-1;
+ return 0;
+}
+
+/*
+ * Enable to attach a device mode to @blk.
+ */
+void blk_enable_attach_dev(BlockBackend *blk)
+{
+ if (blk->dev == (void *)-1) {
+ blk->dev = 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 8fc960f..7619a9f 100644
--- a/include/sysemu/block-backend.h
+++ b/include/sysemu/block-backend.h
@@ -80,6 +80,8 @@ 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);
+int blk_disable_attach_dev(BlockBackend *blk);
+void blk_enable_attach_dev(BlockBackend *blk);
void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void *opaque);
int blk_read(BlockBackend *blk, int64_t sector_num, uint8_t *buf,
int nb_sectors);
--
2.4.3