From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:33555) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uhj51-0004GX-1r for qemu-devel@nongnu.org; Wed, 29 May 2013 12:18:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Uhj4z-00036t-T1 for qemu-devel@nongnu.org; Wed, 29 May 2013 12:18:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21282) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Uhj4z-00036h-JD for qemu-devel@nongnu.org; Wed, 29 May 2013 12:18:25 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r4TGIPaC028351 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 29 May 2013 12:18:25 -0400 From: Pavel Hrdina Date: Wed, 29 May 2013 18:18:19 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: Subject: [Qemu-devel] [PATCH v2 2/2] block: move the bdrv_dev_change_media_cb() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, phrdina@redhat.com, armbru@redhat.com, lcapitulino@redhat.com The bdrv_dev_change_media_cb() should be called only for eject and change commands. 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 99bc357..a64a9ec 100644 --- a/block.c +++ b/block.c @@ -1084,10 +1084,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); @@ -1389,8 +1385,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); @@ -2845,8 +2839,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 d1ec99a..a9273de 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) @@ -1071,14 +1072,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, -- 1.8.1.4