From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54887) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYDhk-0006Z7-F6 for qemu-devel@nongnu.org; Wed, 18 Mar 2015 09:08:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YYDhb-0005xQ-5T for qemu-devel@nongnu.org; Wed, 18 Mar 2015 09:08:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34083) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YYDha-0005wT-Uo for qemu-devel@nongnu.org; Wed, 18 Mar 2015 09:08:03 -0400 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 t2ID82TY010914 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 18 Mar 2015 09:08:02 -0400 From: Gerd Hoffmann Date: Wed, 18 Mar 2015 14:07:49 +0100 Message-Id: <1426684075-27224-8-git-send-email-kraxel@redhat.com> In-Reply-To: <1426684075-27224-1-git-send-email-kraxel@redhat.com> References: <1426684075-27224-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PULL 07/13] monitor usb: Inline monitor_read_bdrv_key_start()'s first part List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Luiz Capitulino , Markus Armbruster , Gerd Hoffmann From: Markus Armbruster monitor_read_bdrv_key_start() does several things: 1. If no key is needed, call completion_cb() and succeed 2. If we're in QMP context, call qerror_report_err() and fail 3. Start reading the key in the monitor. This is two things too many. Inline 1. and 2. into its callers monitor_read_block_device_key() and usb_msd_realize_storage(). Since monitor_read_block_device_key() only ever runs in HMP context, drop 2. there. The next commit will clean up the result in usb_msd_realize_storage(). Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Gerd Hoffmann --- hw/usb/dev-storage.c | 13 +++++++++++-- monitor.c | 29 +++++++++++------------------ 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c index dacefd7..f47c856 100644 --- a/hw/usb/dev-storage.c +++ b/hw/usb/dev-storage.c @@ -641,8 +641,17 @@ static void usb_msd_realize_storage(USBDevice *dev, Error **errp) if (bdrv_key_required(blk_bs(blk))) { if (cur_mon) { - monitor_read_bdrv_key_start(cur_mon, blk_bs(blk), - usb_msd_password_cb, s); + bdrv_add_key(blk_bs(blk), NULL, &err); + if (!err) { + usb_msd_password_cb(s, 0); + } else if (monitor_cur_is_qmp()) { + qerror_report_err(err); + error_free(err); + } else { + error_free(err); + monitor_read_bdrv_key_start(cur_mon, blk_bs(blk), + usb_msd_password_cb, s); + } s->dev.auto_attach = 0; } else { autostart = 0; diff --git a/monitor.c b/monitor.c index bc77415..61c00ac 100644 --- a/monitor.c +++ b/monitor.c @@ -5377,25 +5377,8 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *bs, BlockCompletionFunc *completion_cb, void *opaque) { - Error *local_err = NULL; int err; - bdrv_add_key(bs, NULL, &local_err); - if (!local_err) { - if (completion_cb) - completion_cb(opaque, 0); - return 0; - } - - /* Need a key for @bs */ - - if (monitor_ctrl_mode(mon)) { - qerror_report_err(local_err); - error_free(local_err); - return -1; - } - - error_free(local_err); monitor_printf(mon, "%s (%s) is encrypted.\n", bdrv_get_device_name(bs), bdrv_get_encrypted_filename(bs)); @@ -5414,6 +5397,7 @@ int monitor_read_block_device_key(Monitor *mon, const char *device, BlockCompletionFunc *completion_cb, void *opaque) { + Error *err = NULL; BlockBackend *blk; blk = blk_by_name(device); @@ -5422,7 +5406,16 @@ int monitor_read_block_device_key(Monitor *mon, const char *device, return -1; } - return monitor_read_bdrv_key_start(mon, blk_bs(blk), completion_cb, opaque); + bdrv_add_key(blk_bs(blk), NULL, &err); + if (err) { + error_free(err); + return monitor_read_bdrv_key_start(mon, blk_bs(blk), completion_cb, opaque); + } + + if (completion_cb) { + completion_cb(opaque, 0); + } + return 0; } QemuOptsList qemu_mon_opts = { -- 1.8.3.1