runtime-rs: Avoid share-rw on readonly virtio-scsi/blk devices

Hotplugging a readonly block device could fail with:

  Block node is read-only

The backend block node was created readonly, but the virtio-scsi/blk
frontend path still forced share-rw=true. This is unnecessary and can
cause QEMU to reject the attach because the frontend configuration
does not match the readonly backend.

Fix the virtio-scsi/blk hotplug path by:
- setting read-only for readonly devices where supported
- skipping share-rw for readonly devices

Readonly handling remains in the backend block node configuration,
while the frontend keeps normal disk semantics for block devices.

Signed-off-by: Alex Lyn <alex.lyn@antgroup.com>
This commit is contained in:
Alex Lyn
2026-04-11 17:02:41 +08:00
committed by Fabiano Fidêncio
parent 02f975f88b
commit be47c2e932

View File

@@ -775,7 +775,9 @@ impl Qmp {
// add SCSI frontend device
blkdev_add_args.insert("scsi-id".to_string(), scsi_id.into());
blkdev_add_args.insert("lun".to_string(), lun.into());
blkdev_add_args.insert("share-rw".to_string(), true.into());
if !is_readonly {
blkdev_add_args.insert("share-rw".to_string(), true.into());
}
info!(
sl!(),
@@ -813,7 +815,9 @@ impl Qmp {
let ccw_addr = subchannel.address_format_ccw_for_virt_server(slot);
blkdev_add_args.insert("devno".to_owned(), devno.clone().into());
blkdev_add_args.insert("share-rw".to_string(), true.into());
if !is_readonly {
blkdev_add_args.insert("share-rw".to_string(), true.into());
}
info!(
sl!(),
@@ -844,7 +848,9 @@ impl Qmp {
} else {
let (bus, slot) = self.find_free_slot()?;
blkdev_add_args.insert("addr".to_owned(), format!("{slot:02}").into());
blkdev_add_args.insert("share-rw".to_string(), true.into());
if !is_readonly {
blkdev_add_args.insert("share-rw".to_string(), true.into());
}
info!(
sl!(),