From patchwork Wed Jul 20 16:24:15 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 105789 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BB391B6F6F for ; Thu, 21 Jul 2011 04:53:33 +1000 (EST) Received: from localhost ([::1]:50871 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qjbtg-0003zz-Sg for incoming@patchwork.ozlabs.org; Wed, 20 Jul 2011 14:53:29 -0400 Received: from eggs.gnu.org ([140.186.70.92]:39990) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjZhJ-00060Z-5X for qemu-devel@nongnu.org; Wed, 20 Jul 2011 12:32:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QjZhA-0001Kh-W4 for qemu-devel@nongnu.org; Wed, 20 Jul 2011 12:32:32 -0400 Received: from oxygen.pond.sub.org ([78.46.104.156]:39188) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QjZhA-0001K3-AJ for qemu-devel@nongnu.org; Wed, 20 Jul 2011 12:32:24 -0400 Received: from oxygen-old.pond.sub.org (unknown [IPv6:2a01:4f8:130:9021::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "oxygen.pond.sub.org", Issuer "CAcert Class 3 Root" (verified OK)) by oxygen.pond.sub.org (Postfix) with ESMTPS id E02EBA247F; Wed, 20 Jul 2011 18:32:22 +0200 (CEST) Received: from blackfin.pond.sub.org (p5B32D5F4.dip.t-dialin.net [91.50.213.244]) by oxygen-old.pond.sub.org (Postfix) with ESMTPA id B1BC82771CE; Wed, 20 Jul 2011 18:32:22 +0200 (CEST) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id F154E379; Wed, 20 Jul 2011 18:24:32 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Wed, 20 Jul 2011 18:24:15 +0200 Message-Id: <1311179069-27882-42-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1311179069-27882-1-git-send-email-armbru@redhat.com> References: <1311179069-27882-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 78.46.104.156 Cc: kwolf@redhat.com, quintela@redhat.com, dbaryshkov@gmail.com, stefano.stabellini@eu.citrix.com, lcapitulino@redhat.com, amit.shah@redhat.com Subject: [Qemu-devel] [PATCH 41/55] fdc: Make media change detection more robust X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- hw/fdc.c | 12 ++++++++---- 1 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hw/fdc.c b/hw/fdc.c index a2d8aae..6854e15 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); }