From patchwork Wed Apr 6 10:34:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 90004 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D2ECEB6F0B for ; Wed, 6 Apr 2011 20:35:23 +1000 (EST) Received: from localhost ([127.0.0.1]:43587 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q7Q52-00049E-FC for incoming@patchwork.ozlabs.org; Wed, 06 Apr 2011 06:35:20 -0400 Received: from [140.186.70.92] (port=40572 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q7Q3m-00046K-3V for qemu-devel@nongnu.org; Wed, 06 Apr 2011 06:34:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q7Q3l-0005SS-3n for qemu-devel@nongnu.org; Wed, 06 Apr 2011 06:34:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35605) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q7Q3k-0005SA-Rd for qemu-devel@nongnu.org; Wed, 06 Apr 2011 06:34:01 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p36AXwF0014136 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 6 Apr 2011 06:33:58 -0400 Received: from dhcp-91-7.nay.redhat.com (dhcp-8-146.nay.redhat.com [10.66.8.146]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p36AXr7w027868; Wed, 6 Apr 2011 06:33:55 -0400 From: Jason Wang To: anthony@codemonkey.ws, qemu-devel@nongnu.org, pbonzini@redhat.com, quintela@redhat.com, Jes.Sorensen@redhat.com, kwolf@redhat.com Date: Wed, 6 Apr 2011 18:34:31 +0800 Message-Id: <1302086071-15742-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: Jason Wang Subject: [Qemu-devel] [PATCH v4] floppy: save and restore DIR register X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Juan Quintela Acked-by: Paolo Bonzini --- 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 */ + } } };