From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKrsi-0003po-Ak for qemu-devel@nongnu.org; Mon, 09 Feb 2015 12:12:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YKrsc-0006VZ-5v for qemu-devel@nongnu.org; Mon, 09 Feb 2015 12:12:20 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52773) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YKrsb-0006VT-Tm for qemu-devel@nongnu.org; Mon, 09 Feb 2015 12:12:14 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t19HCC6D003300 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 9 Feb 2015 12:12:13 -0500 From: Max Reitz Date: Mon, 9 Feb 2015 12:11:31 -0500 Message-Id: <1423501897-30410-32-git-send-email-mreitz@redhat.com> In-Reply-To: <1423501897-30410-1-git-send-email-mreitz@redhat.com> References: <1423501897-30410-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH v2 31/37] block: Inquire tray state before tray-moved events List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Markus Armbruster , Max Reitz , Stefan Hajnoczi , John Snow 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 00e96da..ad0af67 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -420,18 +420,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); } } } -- 2.1.0