From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=48915 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q47Ci-0004Sy-Tr for qemu-devel@nongnu.org; Mon, 28 Mar 2011 03:49:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q47Ca-0003Yg-FD for qemu-devel@nongnu.org; Mon, 28 Mar 2011 03:49:32 -0400 Received: from mail-iy0-f173.google.com ([209.85.210.173]:38340) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q47Ca-0003YR-AT for qemu-devel@nongnu.org; Mon, 28 Mar 2011 03:49:28 -0400 Received: by iym10 with SMTP id 10so3385299iym.4 for ; Mon, 28 Mar 2011 00:49:27 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <4D903D80.1090100@redhat.com> Date: Mon, 28 Mar 2011 09:49:20 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <20110325062741.23726.36621.stgit@dhcp-91-7.nay.redhat.com.englab.nay.redhat.com> <4D8C8305.7030906@redhat.com> <19855.62739.96012.591499@gargle.gargle.HOWL> In-Reply-To: <19855.62739.96012.591499@gargle.gargle.HOWL> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH] floppy: save and restore DIR register List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jason Wang Cc: kwolf@redhat.com, qemu-devel@nongnu.org, quintela@redhat.com On 03/28/2011 04:40 AM, Jason Wang wrote: > > On 03/25/2011 07:27 AM, Jason Wang wrote: > > > 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. > > > > I guess you can avoid saving if the media changed flag is zero, too > > (which should be the common case after the guest has booted, right?). > > > > Paolo > > Yes, zero is the common case, but the bdrv_open() called by listening qemu in > dest mode would always set the media_changed to one, so we must save and restore > it during migration. If zero is the common case, you can do something like this to avoid saving the subsection in the common case and allow seamless migration from 0.15 to 0.14: static void fdrive_pre_save(void *opaque) { FDrive *drive = opaque; if (drive->bs != NULL) { drive->media_changed = drive->bs->media_changed; } else { drive->media_changed = 2; } } static void fdrive_pre_load(void *opaque) { FDrive *drive = opaque; /* Set the default value in case there is no subsection. */ if (drive->bs != NULL) { drive->media_changed = 0; } else { drive->media_changed = 2; } } static void fdrive_post_load(void *opaque) { /* Fail if the source machine had a disk and we don't. */ if (drive->bs == NULL && drive->media_changed != 2) { return 1; } /* Reset the field if both us and the source machine have a disk. */ if (drive->bs != NULL && drive->media_changed != 2) { /* bdrv_open() called in dest node may set the media_changed flag when trying to open floppy image. Copy it here, so that it is reset even if the subsection was not saved. */ drive->bs->media_changed = drive->media_changed; } return 0; } static bool fdrive_media_changed_needed(void *opaque) { FDrive *drive = opaque; return (drive->bs != NULL && drive->media_changed != 0); } Note that there is a small change here: if the media changed flag is 1 and you migrate 0.14 to 0.15, the destination machine will see the flag reset to 0 (while 0.14 to 0.14 will see the flag set to 1 just because that's how bdrv_open leaves it). To fix this, you can define a boolean qdev property default_migration_media_changed and use it instead of the two hard-coded "0" values. Then, register the default value of the property in hw/pc_piix.c to be 0 in pc-0.15, and 1 in pc-0.14 and older. Paolo