From bcf5d19c59a527c91bc29704f3e4956119c050cf Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Mar 2015 17:26:46 +0100 Subject: monitor: Drop dead QMP check from monitor_read_password() Function is only called in HMP context since commit 333a96e "qapi: Convert change". Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Gerd Hoffmann --- monitor.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'monitor.c') diff --git a/monitor.c b/monitor.c index 8b703f97be..1b46d0718d 100644 --- a/monitor.c +++ b/monitor.c @@ -266,10 +266,7 @@ void monitor_read_command(Monitor *mon, int show_prompt) int monitor_read_password(Monitor *mon, ReadLineFunc *readline_func, void *opaque) { - if (monitor_ctrl_mode(mon)) { - qerror_report(QERR_MISSING_PARAMETER, "password"); - return -EINVAL; - } else if (mon->rs) { + if (mon->rs) { readline_start(mon->rs, "Password: ", 1, readline_func, opaque); /* prompt is printed on return from the command handler */ return 0; -- cgit v1.2.3 From 988e0f06621fde11ec0d319a6fd0ab3ccef0602f Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Mar 2015 17:26:47 +0100 Subject: monitor: Plug memory leak in monitor_read_bdrv_key_start() Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake Signed-off-by: Gerd Hoffmann --- monitor.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'monitor.c') diff --git a/monitor.c b/monitor.c index 1b46d0718d..bc774152a1 100644 --- a/monitor.c +++ b/monitor.c @@ -5391,9 +5391,11 @@ int monitor_read_bdrv_key_start(Monitor *mon, BlockDriverState *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)); -- cgit v1.2.3 From 9b14e0efcc9a6ea41b7265538f6ec4c53e2ba270 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Thu, 12 Mar 2015 17:26:48 +0100 Subject: monitor usb: Inline monitor_read_bdrv_key_start()'s first part 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 --- monitor.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'monitor.c') diff --git a/monitor.c b/monitor.c index bc774152a1..61c00ac2fb 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 = { -- cgit v1.2.3