From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:55052) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0xi7-0001pA-Uq for qemu-devel@nongnu.org; Tue, 06 Sep 2011 11:37:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R0xhz-0003lN-5r for qemu-devel@nongnu.org; Tue, 06 Sep 2011 11:37:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50605) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R0xhy-0003lI-Uz for qemu-devel@nongnu.org; Tue, 06 Sep 2011 11:37:07 -0400 From: Kevin Wolf Date: Tue, 6 Sep 2011 17:39:28 +0200 Message-Id: <1315323586-23840-14-git-send-email-kwolf@redhat.com> In-Reply-To: <1315323586-23840-1-git-send-email-kwolf@redhat.com> References: <1315323586-23840-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 13/31] fdc: Make media change detection more robust List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Markus Armbruster fdctrl_change_cb() gets called on a virtual media change via monitor. It would be nice if host device block drivers called it on physical media change, but they don't. bdrv_media_changed() lets you poll for media change, but it returns "don't know" except with block driver "host_floppy". FDrive member media_changed gets set on device initialization and by fdctrl_change_cb(), and cleared by fdctrl_media_changed(). Thus, it's set on first entry to fdctrl_media_changed() since device initialization or virtual media change. fdctrl_media_changed() ignores media_changed unless bdrv_media_changed() returns "don't know". If we change media via monitor (setting media_changed), and the new media's block driver returns 0, we lose. Fortunately, "host_floppy" always returns 1 on first call. Brittle. Clean it up not to rely on it. Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/fdc.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/fdc.c b/hw/fdc.c index 4f4c621..1d44bbd 100644 --- a/hw/fdc.c +++ b/hw/fdc.c @@ -898,11 +898,15 @@ static int fdctrl_media_changed(FDrive *drv) if (!drv->bs) return 0; - ret = bdrv_media_changed(drv->bs); - if (ret < 0) { - ret = drv->media_changed; + if (drv->media_changed) { + drv->media_changed = 0; + ret = 1; + } else { + ret = bdrv_media_changed(drv->bs); + if (ret < 0) { + ret = 0; /* we don't know, assume no */ + } } - drv->media_changed = 0; if (ret) { fd_revalidate(drv); } -- 1.7.6