qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v4] floppy: save and restore DIR register
@ 2011-04-06 10:34 Jason Wang
  2011-04-06 12:13 ` [Qemu-devel] " Juan Quintela
  2011-04-06 15:22 ` Kevin Wolf
  0 siblings, 2 replies; 4+ messages in thread
From: Jason Wang @ 2011-04-06 10:34 UTC (permalink / raw)
  To: anthony, qemu-devel, pbonzini, quintela, Jes.Sorensen, kwolf; +Cc: Jason Wang

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>
---

Changed from V3:
According to Juan's suggestions, back to v2 and just add the checking for
media_changed "changed" in .needed.
Do not fail the migration when src have a drive but dest does not, we can treat
it as user ejected the floppy.

Changed from V2:
According to Paolo's suggestions, a default_migration_media_changed property was
added to avoid saving subsections as much as possible. Its was set media_changed
in pre_load callback and then we can avoid the saving when it was equal to the
media_changed when migrating the FDrive. Behaviors of elder machine types are
also kept through compat_props.

Changed from V1:
Check the drive->bs during post_load.

 hw/fdc.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 50 insertions(+), 1 deletions(-)

diff --git a/hw/fdc.c b/hw/fdc.c
index 9fdbc75..edf0360 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,63 @@ 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) {
+        drive->bs->media_changed = drive->media_changed;
+    }
+
+    /* User ejected the floppy when drive->bs == NULL */
+    return 0;
+}
+
+static bool fdrive_media_changed_needed(void *opaque)
+{
+    FDrive *drive = opaque;
+
+    return (drive->bs != NULL && drive->bs->media_changed != 1);
+}
+
+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_media_changed_needed,
+        } , {
+            /* empty */
+        }
     }
 };
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [PATCH v4] floppy: save and restore DIR register
  2011-04-06 10:34 [Qemu-devel] [PATCH v4] floppy: save and restore DIR register Jason Wang
@ 2011-04-06 12:13 ` Juan Quintela
  2011-04-06 12:33   ` Paolo Bonzini
  2011-04-06 15:22 ` Kevin Wolf
  1 sibling, 1 reply; 4+ messages in thread
From: Juan Quintela @ 2011-04-06 12:13 UTC (permalink / raw)
  To: Jason Wang; +Cc: kwolf, pbonzini, qemu-devel, Jes.Sorensen

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>
> ---
>
> Changed from V3:
> According to Juan's suggestions, back to v2 and just add the checking for
> media_changed "changed" in .needed.
> Do not fail the migration when src have a drive but dest does not, we can treat
> it as user ejected the floppy.
>
> Changed from V2:
> According to Paolo's suggestions, a default_migration_media_changed property was
> added to avoid saving subsections as much as possible. Its was set media_changed
> in pre_load callback and then we can avoid the saving when it was equal to the
> media_changed when migrating the FDrive. Behaviors of elder machine types are
> also kept through compat_props.
>
> Changed from V1:
> Check the drive->bs during post_load.
>
>  hw/fdc.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 50 insertions(+), 1 deletions(-)
>

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

This solution is way less invasive that v3, and achieves exactly the
same compatibility.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [PATCH v4] floppy: save and restore DIR register
  2011-04-06 12:13 ` [Qemu-devel] " Juan Quintela
@ 2011-04-06 12:33   ` Paolo Bonzini
  0 siblings, 0 replies; 4+ messages in thread
From: Paolo Bonzini @ 2011-04-06 12:33 UTC (permalink / raw)
  To: quintela; +Cc: kwolf, Jes.Sorensen, Jason Wang, qemu-devel

On 04/06/2011 02:13 PM, Juan Quintela wrote:
> 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>
>> ---
>>
>> Changed from V3:
>> According to Juan's suggestions, back to v2 and just add the checking for
>> media_changed "changed" in .needed.
>> Do not fail the migration when src have a drive but dest does not, we can treat
>> it as user ejected the floppy.
>>
>> Changed from V2:
>> According to Paolo's suggestions, a default_migration_media_changed property was
>> added to avoid saving subsections as much as possible. Its was set media_changed
>> in pre_load callback and then we can avoid the saving when it was equal to the
>> media_changed when migrating the FDrive. Behaviors of elder machine types are
>> also kept through compat_props.
>>
>> Changed from V1:
>> Check the drive->bs during post_load.
>>
>>   hw/fdc.c |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
>>   1 files changed, 50 insertions(+), 1 deletions(-)
>>
>
> Reviewed-by: Juan Quintela<quintela@redhat.com>
>
> This solution is way less invasive that v3, and achieves exactly the
> same compatibility.

True, thanks for putting up with the reviews! :)

Acked-by: Paolo Bonzini <pbonzini@redhat.com>

Paolo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] Re: [PATCH v4] floppy: save and restore DIR register
  2011-04-06 10:34 [Qemu-devel] [PATCH v4] floppy: save and restore DIR register Jason Wang
  2011-04-06 12:13 ` [Qemu-devel] " Juan Quintela
@ 2011-04-06 15:22 ` Kevin Wolf
  1 sibling, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2011-04-06 15:22 UTC (permalink / raw)
  To: Jason Wang; +Cc: pbonzini, Jes.Sorensen, qemu-devel, quintela

Am 06.04.2011 12:34, schrieb Jason Wang:
> 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>

Thanks, applied to the block branch.

Kevin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-04-06 15:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-06 10:34 [Qemu-devel] [PATCH v4] floppy: save and restore DIR register Jason Wang
2011-04-06 12:13 ` [Qemu-devel] " Juan Quintela
2011-04-06 12:33   ` Paolo Bonzini
2011-04-06 15:22 ` Kevin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).