mirror of https://gitee.com/openkylin/qemu.git
fdc: Make media change detection more robust
fdctrl_change_cb() gets called on a virtual media change via monitor. It would be nice if host device block drivers called it on physical media change, but they don't. bdrv_media_changed() lets you poll for media change, but it returns "don't know" except with block driver "host_floppy". FDrive member media_changed gets set on device initialization and by fdctrl_change_cb(), and cleared by fdctrl_media_changed(). Thus, it's set on first entry to fdctrl_media_changed() since device initialization or virtual media change. fdctrl_media_changed() ignores media_changed unless bdrv_media_changed() returns "don't know". If we change media via monitor (setting media_changed), and the new media's block driver returns 0, we lose. Fortunately, "host_floppy" always returns 1 on first call. Brittle. Clean it up not to rely on it. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
8e49ca4624
commit
18d9005529
12
hw/fdc.c
12
hw/fdc.c
|
@ -898,11 +898,15 @@ static int fdctrl_media_changed(FDrive *drv)
|
|||
|
||||
if (!drv->bs)
|
||||
return 0;
|
||||
ret = bdrv_media_changed(drv->bs);
|
||||
if (ret < 0) {
|
||||
ret = drv->media_changed;
|
||||
if (drv->media_changed) {
|
||||
drv->media_changed = 0;
|
||||
ret = 1;
|
||||
} else {
|
||||
ret = bdrv_media_changed(drv->bs);
|
||||
if (ret < 0) {
|
||||
ret = 0; /* we don't know, assume no */
|
||||
}
|
||||
}
|
||||
drv->media_changed = 0;
|
||||
if (ret) {
|
||||
fd_revalidate(drv);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue