diff mbox

[V2] floppy: save and restore DIR register

Message ID 20110328024726.4753.77783.stgit@dhcp-91-7.nay.redhat.com.englab.nay.redhat.com
State New
Headers show

Commit Message

Jason Wang March 28, 2011, 2:47 a.m. UTC
We need to keep DIR register unchanged across migration, but currently it
depends on the media_changed flags from block layer. Since we do not
save/restore it and the bdrv_open() called in dest node may set the
media_changed flag when trying to open floppy image, guest driver may think the
floppy have changed after migration. To fix this, a new filed media_changed in
FDrive strcutre was introduced in order to save and restore the it from block
layer through pre_save/post_load callbacks.

Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/fdc.c |   52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 51 insertions(+), 1 deletions(-)

Comments

Jes Sorensen March 28, 2011, 8:16 a.m. UTC | #1
On 03/28/11 04:47, Jason Wang wrote:
> We need to keep DIR register unchanged across migration, but currently it
> depends on the media_changed flags from block layer. Since we do not
> save/restore it and the bdrv_open() called in dest node may set the
> media_changed flag when trying to open floppy image, guest driver may think the
> floppy have changed after migration. To fix this, a new filed media_changed in
> FDrive strcutre was introduced in order to save and restore the it from block
> layer through pre_save/post_load callbacks.
> 
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>  hw/fdc.c |   52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 51 insertions(+), 1 deletions(-)

Looks good to me.

Reviewed-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Juan Quintela March 28, 2011, 11:18 a.m. UTC | #2
Jason Wang <jasowang@redhat.com> wrote:
> We need to keep DIR register unchanged across migration, but currently it
> depends on the media_changed flags from block layer. Since we do not
> save/restore it and the bdrv_open() called in dest node may set the
> media_changed flag when trying to open floppy image, guest driver may think the
> floppy have changed after migration. To fix this, a new filed media_changed in
> FDrive strcutre was introduced in order to save and restore the it from block
> layer through pre_save/post_load callbacks.
>
> Signed-off-by: Jason Wang <jasowang@redhat.com>

Reviewed-by: Juan Quintela <quintela@redhat.com>
diff mbox

Patch

diff --git a/hw/fdc.c b/hw/fdc.c
index 9fdbc75..865ff0e 100644
--- a/hw/fdc.c
+++ b/hw/fdc.c
@@ -36,6 +36,7 @@ 
 #include "qdev-addr.h"
 #include "blockdev.h"
 #include "sysemu.h"
+#include "block_int.h"
 
 /********************************************************/
 /* debug Floppy devices */
@@ -82,6 +83,7 @@  typedef struct FDrive {
     uint8_t max_track;        /* Nb of tracks           */
     uint16_t bps;             /* Bytes per sector       */
     uint8_t ro;               /* Is read-only           */
+    uint8_t media_changed;    /* Is media changed       */
 } FDrive;
 
 static void fd_init(FDrive *drv)
@@ -533,16 +535,64 @@  static CPUWriteMemoryFunc * const fdctrl_mem_write_strict[3] = {
     NULL,
 };
 
+static void fdrive_media_changed_pre_save(void *opaque)
+{
+    FDrive *drive = opaque;
+
+    drive->media_changed = drive->bs->media_changed;
+}
+
+static int fdrive_media_changed_post_load(void *opaque, int version_id)
+{
+    FDrive *drive = opaque;
+
+    if (drive->bs == NULL) {
+        return 1;
+    }
+
+    drive->bs->media_changed = drive->media_changed;
+
+    return 0;
+}
+
+static bool fdrive_has_driver(void *opaque)
+{
+    FDrive *drive = opaque;
+
+    return drive->bs != NULL;
+}
+
+static const VMStateDescription vmstate_fdrive_media_changed = {
+    .name = "fdrive/media_changed",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .pre_save = fdrive_media_changed_pre_save,
+    .post_load = fdrive_media_changed_post_load,
+    .fields      = (VMStateField[]) {
+        VMSTATE_UINT8(media_changed, FDrive),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
 static const VMStateDescription vmstate_fdrive = {
     .name = "fdrive",
     .version_id = 1,
     .minimum_version_id = 1,
     .minimum_version_id_old = 1,
-    .fields      = (VMStateField []) {
+    .fields      = (VMStateField[]) {
         VMSTATE_UINT8(head, FDrive),
         VMSTATE_UINT8(track, FDrive),
         VMSTATE_UINT8(sect, FDrive),
         VMSTATE_END_OF_LIST()
+    },
+    .subsections = (VMStateSubsection[]) {
+        {
+            .vmsd = &vmstate_fdrive_media_changed,
+            .needed = &fdrive_has_driver,
+        } , {
+            /* empty */
+        }
     }
 };