Context:
https://github.com/openshift/os/pull/1350#issuecomment-1708486101
1. Test manually with `-cdrom`, which is ide controller by default
- run `eject`, device `/dev/sr0` can not be removed
- run `device_del`, delete `/dev/sr0` failed as `Bus 'ide.1' does not support hotplugging`
```
# first boot
IGNITION_CONFIG="/home/fedora/ign/ssh.ign"
IGNITION_DEVICE_ARG="-fw_cfg name=opt/com.coreos/config,file=${IGNITION_CONFIG}"
qemu-kvm -m 4096 -cpu host -nographic \
-drive if=virtio,file=qmp.qcow2 ${IGNITION_DEVICE_ARG}\
-cdrom test.iso \
-qmp-pretty tcp::8888,server,nowait
qemu-kvm -m 4096 -cpu host -nographic \
-drive if=virtio,file=qmp.qcow2 \
-cdrom test.iso \
-qmp-pretty tcp::8888,server,nowait
$ telnet localhost 8888
# Issue the qmp_capabilities command, so that QMP enters command mode
{"execute":"qmp_capabilities"}
# Get a list of BlockInfo for all virtual block devices.
{ "execute": "query-block" }
{"execute":"eject","arguments":{"device":"ide1-cd0","force":true}}
# Remove a device from a guest
{ "execute": "device_del", "arguments": { "id": "/machine/unattached/device[24]" } }
{
"error": {
"class": "GenericError",
"desc": "Bus 'ide.1' does not support hotplugging"
}
}
```
2. Test manually with scsi cdrom,
- run `device_del`, delete `/dev/sr0` successfully
(maybe this is what we want?)
```
qemu-kvm -m 4096 -cpu host -nographic \
-drive if=virtio,file=/home/fedora/data/qmp.qcow2 \
-drive id=cdrom0,if=none,readonly=on,file=/home/fedora/data/test.iso \
-device virtio-scsi-pci,id=scsi0 \
-device scsi-cd,bus=scsi0.0,drive=cdrom0 \
-qmp-pretty tcp::8888,server,nowait
telnet localhost 8888
{"execute":"qmp_capabilities"}
# This command will list any properties of a object given a path in the object model.
{ "execute": "qom-list", "arguments": { "path": "/machine/peripheral-anon" } }
{
"return": [
{
"name": "type",
"type": "string"
},
{
"name": "device[0]",
"type": "child<scsi-cd>"
},
{
"name": "device[1]",
"type": "child<virtio-blk-pci>"
}
]
}
[core@localhost ~]$ ls /dev/sr0
/dev/sr0
```
```
{ "execute": "device_del", "arguments": { "id": "/machine/peripheral-anon/device[0]" } }
{
"return": {
}
}
{
"timestamp": {
"seconds": 1694173073,
"microseconds": 162006
},
"event": "DEVICE_DELETED",
"data": {
"path": "/machine/peripheral-anon/device[0]"
}
}
[core@localhost ~]$ ls /dev/sr0
ls: cannot access '/dev/sr0': No such file or directory
```
3. Make a little change, build and testing, will remove device `/dev/sr0`.
See https://github.com/coreos/coreos-assembler/commit/a1a00472b3070c87b68026828a259a789f0f6546
```
podman build -t localhost/coreos-assembler .
export COREOS_ASSEMBLER_CONTAINER=localhost/coreos-assembler
$ cosa shell
[coreos-assembler]$ env COSA_TEST_CDROM_UNPLUG=8s cosa run qemu.qcow2 --debug -- \
-drive id=cdrom0,if=none,readonly=on,file=/srv/test.iso \
-device virtio-scsi-pci,id=scsi0 \
-device scsi-cd,bus=scsi0.0,drive=cdrom0
...
2023-09-12T10:54:08Z platform: get cdrom id /machine/peripheral-anon/device[2]
[STARTUP] '2023-09-12T10:54:13Z platform: delete cdrom
...
[core@cosa-devsh ~]$ ls /dev/sr0
ls: cannot access '/dev/sr0': No such file or directory
```
Reference:
https://wiki.qemu.org/Documentation/QMP
https://qemu-project.gitlab.io/qemu/interop/qemu-qmp-ref.html