[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] blockdev: add 'media=cdrom' argument to support usb cdrom emulat
From: |
luzhipeng |
Subject: |
[PATCH] blockdev: add 'media=cdrom' argument to support usb cdrom emulated as cdrom |
Date: |
Thu, 1 Dec 2022 21:42:27 +0800 |
From: zhipeng Lu <luzhipeng@cestc.cn>
The drive interface supports media=cdrom so that the usb cdrom
can be emulated as cdrom in qemu, but libvirt deprived the drive
interface, so media=cdrom is added to the blockdev interface to
support usb cdrom emulated as cdrom
Signed-off-by: zhipeng Lu <luzhipeng@cestc.cn>
---
block.c | 11 ++++++++++-
block/block-backend.c | 18 ++++++++++++++++++
hw/core/qdev-properties-system.c | 3 +++
hw/scsi/scsi-bus.c | 4 +++-
include/block/block_int-common.h | 1 +
include/sysemu/block-backend-global-state.h | 2 ++
6 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/block.c b/block.c
index a18f052374..d194e3039e 100644
--- a/block.c
+++ b/block.c
@@ -3787,6 +3787,7 @@ static BlockDriverState *bdrv_open_inherit(const char
*filename,
Error *local_err = NULL;
QDict *snapshot_options = NULL;
int snapshot_flags = 0;
+ int media = 0;
assert(!child_class || !flags);
assert(!child_class == !parent);
@@ -3906,6 +3907,12 @@ static BlockDriverState *bdrv_open_inherit(const char
*filename,
qdict_del(bs->options, "backing");
qdict_del(options, "backing");
}
+ if (!g_strcmp0(qdict_get_try_str(options, "media"), "cdrom")) {
+ media = 1;
+ qdict_del(bs->explicit_options, "media");
+ qdict_del(bs->options, "media");
+ qdict_del(options, "media");
+ }
/* Open image file without format layer. This BlockBackend is only used for
* probing, the block drivers will do their own bdrv_open_child() for the
@@ -4033,7 +4040,9 @@ static BlockDriverState *bdrv_open_inherit(const char
*filename,
bdrv_unref(bs);
bs = snapshot_bs;
}
-
+ if (bs && media) {
+ bs->media_cd = true;
+ }
return bs;
fail:
diff --git a/block/block-backend.c b/block/block-backend.c
index d98a96ff37..1760079a67 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -72,6 +72,7 @@ struct BlockBackend {
uint64_t perm;
uint64_t shared_perm;
bool disable_perm;
+ bool media_cd;
bool allow_aio_context_change;
bool allow_write_beyond_eof;
@@ -2634,3 +2635,20 @@ int blk_make_empty(BlockBackend *blk, Error **errp)
return bdrv_make_empty(blk->root, errp);
}
+
+bool blk_is_cdrom(BlockBackend *blk)
+{
+ if (!blk) {
+ return false;
+ }
+ return blk->media_cd;
+
+}
+
+void blk_set_cdrom(BlockBackend *blk)
+{
+ if (!blk) {
+ return ;
+ }
+ blk->media_cd = true;
+}
diff --git a/hw/core/qdev-properties-system.c b/hw/core/qdev-properties-system.c
index a91f60567a..99df29ccb8 100644
--- a/hw/core/qdev-properties-system.c
+++ b/hw/core/qdev-properties-system.c
@@ -149,6 +149,9 @@ static void set_drive_helper(Object *obj, Visitor *v, const
char *name,
if (ret < 0) {
goto fail;
}
+ if (bs->media_cd) {
+ blk_set_cdrom(blk);
+ }
}
}
if (!blk) {
diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index ceceafb2cd..bc2bbdc823 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -321,7 +321,9 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus,
BlockBackend *blk,
driver = "scsi-generic";
} else {
dinfo = blk_legacy_dinfo(blk);
- if (dinfo && dinfo->media_cd) {
+ if ((dinfo && dinfo->media_cd)) {
+ driver = "scsi-cd";
+ } else if (blk_is_cdrom(blk)) {
driver = "scsi-cd";
} else {
driver = "scsi-hd";
diff --git a/include/block/block_int-common.h b/include/block/block_int-common.h
index 31ae91e56e..04a814ab1b 100644
--- a/include/block/block_int-common.h
+++ b/include/block/block_int-common.h
@@ -1023,6 +1023,7 @@ struct BlockDriverState {
bool probed; /* if true, format was probed rather than specified */
bool force_share; /* if true, always allow all shared permissions */
bool implicit; /* if true, this filter node was automatically inserted */
+ bool media_cd;
BlockDriver *drv; /* NULL means no media */
void *opaque;
diff --git a/include/sysemu/block-backend-global-state.h
b/include/sysemu/block-backend-global-state.h
index 6858e39cb6..108dfad283 100644
--- a/include/sysemu/block-backend-global-state.h
+++ b/include/sysemu/block-backend-global-state.h
@@ -71,6 +71,8 @@ void blk_set_on_error(BlockBackend *blk, BlockdevOnError
on_read_error,
BlockdevOnError on_write_error);
bool blk_supports_write_perm(BlockBackend *blk);
bool blk_is_sg(BlockBackend *blk);
+bool blk_is_cdrom(BlockBackend *blk);
+void blk_set_cdrom(BlockBackend *blk);
void blk_set_enable_write_cache(BlockBackend *blk, bool wce);
int blk_get_flags(BlockBackend *blk);
bool blk_op_is_blocked(BlockBackend *blk, BlockOpType op, Error **errp);
--
2.31.1
- [PATCH] blockdev: add 'media=cdrom' argument to support usb cdrom emulated as cdrom,
luzhipeng <=
- Re: [PATCH] blockdev: add 'media=cdrom' argument to support usb cdrom emulated as cdrom, Markus Armbruster, 2022/12/01
- Re: [PATCH] blockdev: add 'media=cdrom' argument to support usb cdrom emulated as cdrom, Zhipeng Lu, 2022/12/01
- Re: [PATCH] blockdev: add 'media=cdrom' argument to support usb cdrom emulated as cdrom, Paolo Bonzini, 2022/12/02
- Re: [PATCH] blockdev: add 'media=cdrom' argument to support usb cdrom emulated as cdrom, Zhipeng Lu, 2022/12/03
- Re: [PATCH] blockdev: add 'media=cdrom' argument to support usb cdrom emulated as cdrom, Paolo Bonzini, 2022/12/07
- Re: [PATCH] blockdev: add 'media=cdrom' argument to support usb cdrom emulated as cdrom, Zhipeng Lu, 2022/12/08
- Re: [PATCH] blockdev: add 'media=cdrom' argument to support usb cdrom emulated as cdrom, Paolo Bonzini, 2022/12/09