From patchwork Fri Sep 18 15:23:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 519414 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id B1182141106 for ; Sat, 19 Sep 2015 01:49:17 +1000 (AEST) Received: from localhost ([::1]:39893 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcxuV-00071q-LC for incoming@patchwork.ozlabs.org; Fri, 18 Sep 2015 11:49:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcxX0-0008Oi-1H for qemu-devel@nongnu.org; Fri, 18 Sep 2015 11:24:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZcxWz-0006IJ-5t for qemu-devel@nongnu.org; Fri, 18 Sep 2015 11:24:58 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42976) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZcxWt-0006Gh-Uo; Fri, 18 Sep 2015 11:24:52 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id 98A0991C16; Fri, 18 Sep 2015 15:24:51 +0000 (UTC) Received: from localhost (ovpn-116-139.ams2.redhat.com [10.36.116.139]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t8IFOnXJ024174 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 18 Sep 2015 11:24:51 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Fri, 18 Sep 2015 17:23:08 +0200 Message-Id: <1442589793-7105-34-git-send-email-mreitz@redhat.com> In-Reply-To: <1442589793-7105-1-git-send-email-mreitz@redhat.com> References: <1442589793-7105-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Alberto Garcia , Markus Armbruster , qemu-devel@nongnu.org, Max Reitz , John Snow , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH v5 33/38] block: Inquire tray state before tray-moved events 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 blk_dev_change_media_cb() is called for all potential tray movements; however, it is possible to request closing the tray but nothing actually happening (on a floppy disk drive without a medium). Thus, the actual tray status should be inquired before sending a tray-moved event (and an event should be sent whenever the status changed). Checking @load is now superfluous; it was necessary because it was possible to change a medium without having explicitly opened the tray and closed it again (or it might have been possible, at least). This is no longer possible, though. Signed-off-by: Max Reitz Reviewed-by: Eric Blake --- block/block-backend.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 66ecc07..09efb8b 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -422,18 +422,15 @@ void blk_set_dev_ops(BlockBackend *blk, const BlockDevOps *ops, void blk_dev_change_media_cb(BlockBackend *blk, bool load) { if (blk->dev_ops && blk->dev_ops->change_media_cb) { - bool tray_was_closed = !blk_dev_is_tray_open(blk); + bool tray_was_open, tray_is_open; + tray_was_open = blk_dev_is_tray_open(blk); blk->dev_ops->change_media_cb(blk->dev_opaque, load); - if (tray_was_closed) { - /* tray open */ - qapi_event_send_device_tray_moved(blk_name(blk), - true, &error_abort); - } - if (load) { - /* tray close */ - qapi_event_send_device_tray_moved(blk_name(blk), - false, &error_abort); + tray_is_open = blk_dev_is_tray_open(blk); + + if (tray_was_open != tray_is_open) { + qapi_event_send_device_tray_moved(blk_name(blk), tray_is_open, + &error_abort); } } }