From patchwork Mon Oct 19 15:53:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Reitz X-Patchwork-Id: 532441 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 B3D6F1402B0 for ; Tue, 20 Oct 2015 03:14:29 +1100 (AEDT) Received: from localhost ([::1]:40659 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoD4t-0003uO-G9 for incoming@patchwork.ozlabs.org; Mon, 19 Oct 2015 12:14:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoCmd-0002HR-Dj for qemu-devel@nongnu.org; Mon, 19 Oct 2015 11:55:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZoCmb-0007KR-JB for qemu-devel@nongnu.org; Mon, 19 Oct 2015 11:55:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50811) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoCmW-0007I8-5d; Mon, 19 Oct 2015 11:55:28 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id C51AF19F201; Mon, 19 Oct 2015 15:55:27 +0000 (UTC) Received: from localhost (ovpn-116-133.ams2.redhat.com [10.36.116.133]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9JFtPCl002032 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 19 Oct 2015 11:55:27 -0400 From: Max Reitz To: qemu-block@nongnu.org Date: Mon, 19 Oct 2015 17:53:40 +0200 Message-Id: <1445270025-22999-35-git-send-email-mreitz@redhat.com> In-Reply-To: <1445270025-22999-1-git-send-email-mreitz@redhat.com> References: <1445270025-22999-1-git-send-email-mreitz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 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 v7 34/39] 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 Reviewed-by: Kevin Wolf --- 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 eb7409c..10e4d71 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -429,18 +429,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); } } }