From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=51404 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q30UM-0000pn-Mx for qemu-devel@nongnu.org; Fri, 25 Mar 2011 02:27:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q30UL-0003Aw-Nd for qemu-devel@nongnu.org; Fri, 25 Mar 2011 02:27:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21990) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q30UL-0003As-Cq for qemu-devel@nongnu.org; Fri, 25 Mar 2011 02:27:13 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2P6RCA6009448 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 25 Mar 2011 02:27:12 -0400 From: Jason Wang Date: Fri, 25 Mar 2011 14:27:42 +0800 Message-ID: <20110325062741.23726.36621.stgit@dhcp-91-7.nay.redhat.com.englab.nay.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] floppy: save and restore DIR register List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: kwolf@redhat.com, qemu-devel@nongnu.org, quintela@redhat.com We need to keep DIR register unchanged across migration, but currently it depends on the media_changed flags from block layer and we do not save/restore it which could let the guest driver 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 --- hw/fdc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 46 insertions(+), 0 deletions(-) diff --git a/hw/fdc.c b/hw/fdc.c index 9fdbc75..8257d51 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,6 +535,42 @@ 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; + + 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, @@ -543,6 +581,14 @@ static const VMStateDescription vmstate_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 */ + } } };