@@ -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.
@@ -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);
Signed-off-by: Wen Congyang <wency@cn.fujitsu.com> --- block/block-backend.c | 24 ++++++++++++++++++++++++ include/sysemu/block-backend.h | 2 ++ 2 files changed, 26 insertions(+)