From patchwork Mon Jun 24 12:12:51 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Hrdina X-Patchwork-Id: 253812 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B55502C007A for ; Mon, 24 Jun 2013 22:13:37 +1000 (EST) Received: from localhost ([::1]:49051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ur5eH-0003Ye-0V for incoming@patchwork.ozlabs.org; Mon, 24 Jun 2013 08:13:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40346) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ur5dl-0003RM-SF for qemu-devel@nongnu.org; Mon, 24 Jun 2013 08:13:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ur5dk-0004vp-14 for qemu-devel@nongnu.org; Mon, 24 Jun 2013 08:13:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37966) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ur5dj-0004vd-Mx for qemu-devel@nongnu.org; Mon, 24 Jun 2013 08:12:59 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5OCCwk9008798 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 24 Jun 2013 08:12:58 -0400 Received: from antique-laptop.brq.redhat.com (dhcp-26-113.brq.redhat.com [10.34.26.113]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r5OCCqhD006111; Mon, 24 Jun 2013 08:12:57 -0400 From: Pavel Hrdina To: qemu-devel@nongnu.org Date: Mon, 24 Jun 2013 14:12:51 +0200 Message-Id: <2748e94e71dc324d489710c949dd9fed15138989.1372072312.git.phrdina@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: kwolf@redhat.com, stefanha@gmail.com, phrdina@redhat.com, lcapitulino@redhat.com Subject: [Qemu-devel] [PATCH v4 2/3] block: move the bdrv_dev_change_media_cb() 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 This fixes a regression introduced by commit 9ca111544. The QEVENT_DEVICE_TRAY_MOVED is emitted while shutting down the guest, which is not right because it comes from bdrv_close_all() and therefore this event doesn't happen at all. The bdrv_dev_change_media_cb() should be called only for eject and change commands because these are the only commands to emit this event. We should call that function only if that command is successful. What this function does is that it calls the change_media_cb() and also emit the QEVENT_DEVICE_TRAY_MOVED event. Signed-off-by: Pavel Hrdina --- block.c | 8 -------- blockdev.c | 5 +++++ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/block.c b/block.c index 89574de..aad3091 100644 --- a/block.c +++ b/block.c @@ -1092,10 +1092,6 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options, } QDECREF(options); - if (!bdrv_key_required(bs)) { - bdrv_dev_change_media_cb(bs, true); - } - /* throttling disk I/O limits */ if (bs->io_limits_enabled) { bdrv_io_limits_enable(bs); @@ -1394,8 +1390,6 @@ void bdrv_close(BlockDriverState *bs) } } - bdrv_dev_change_media_cb(bs, false); - /*throttling disk I/O limits*/ if (bs->io_limits_enabled) { bdrv_io_limits_disable(bs); @@ -2846,8 +2840,6 @@ int bdrv_set_key(BlockDriverState *bs, const char *key) bs->valid_key = 0; } else if (!bs->valid_key) { bs->valid_key = 1; - /* call the change callback now, we skipped it on open */ - bdrv_dev_change_media_cb(bs, true); } return ret; } diff --git a/blockdev.c b/blockdev.c index 5975dde..2dbd781 100644 --- a/blockdev.c +++ b/blockdev.c @@ -1022,6 +1022,7 @@ static void eject_device(BlockDriverState *bs, int force, Error **errp) } bdrv_close(bs); + bdrv_dev_change_media_cb(bs, false); } void qmp_eject(const char *device, bool has_force, bool force, Error **errp) @@ -1074,14 +1075,18 @@ static void qmp_bdrv_open_encrypted(BlockDriverState *bs, const char *filename, if (password) { if (bdrv_set_key(bs, password) < 0) { error_set(errp, QERR_INVALID_PASSWORD); + return; } } else { error_set(errp, QERR_DEVICE_ENCRYPTED, bdrv_get_device_name(bs), bdrv_get_encrypted_filename(bs)); + return; } } else if (password) { error_set(errp, QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs)); } + + bdrv_dev_change_media_cb(bs, true); } void qmp_change_blockdev(const char *device, const char *filename,