From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: kraxel@redhat.com, lcapitulino@redhat.com
Subject: [Qemu-devel] [PATCH 3/5] monitor usb: Inline monitor_read_bdrv_key_start()'s first part
Date: Thu, 12 Mar 2015 17:26:48 +0100 [thread overview]
Message-ID: <1426177610-4848-4-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1426177610-4848-1-git-send-email-armbru@redhat.com>
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 <armbru@redhat.com>
---
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 12d80a1..85223cf 100644
--- a/monitor.c
+++ b/monitor.c
@@ -5376,25 +5376,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));
@@ -5413,6 +5396,7 @@ int monitor_read_block_device_key(Monitor *mon, const char *device,
BlockCompletionFunc *completion_cb,
void *opaque)
{
+ Error *err = NULL;
BlockDriverState *bs;
bs = bdrv_find(device);
@@ -5421,7 +5405,16 @@ int monitor_read_block_device_key(Monitor *mon, const char *device,
return -1;
}
- return monitor_read_bdrv_key_start(mon, bs, completion_cb, opaque);
+ bdrv_add_key(bs, NULL, &err);
+ if (err) {
+ error_free(err);
+ return monitor_read_bdrv_key_start(mon, bs, completion_cb, opaque);
+ }
+
+ if (completion_cb) {
+ completion_cb(opaque, 0);
+ }
+ return 0;
}
QemuOptsList qemu_mon_opts = {
--
1.9.3
next prev parent reply other threads:[~2015-03-12 16:27 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-12 16:26 [Qemu-devel] [PATCH 0/5] monitor usb: Fixes for encrypted images Markus Armbruster
2015-03-12 16:26 ` [Qemu-devel] [PATCH 1/5] monitor: Drop dead QMP check from monitor_read_password() Markus Armbruster
2015-03-12 16:26 ` [Qemu-devel] [PATCH 2/5] monitor: Plug memory leak in monitor_read_bdrv_key_start() Markus Armbruster
2015-03-12 16:26 ` Markus Armbruster [this message]
2015-03-12 16:26 ` [Qemu-devel] [PATCH 4/5] usb/dev-storage: Fix QMP device_add missing encryption key failure Markus Armbruster
2015-03-12 16:26 ` [Qemu-devel] [PATCH 5/5] usb/dev-storage: Avoid qerror_report_err() outside QMP handlers Markus Armbruster
2015-03-12 18:06 ` [Qemu-devel] [PATCH 0/5] monitor usb: Fixes for encrypted images Eric Blake
2015-03-17 12:09 ` Gerd Hoffmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1426177610-4848-4-git-send-email-armbru@redhat.com \
--to=armbru@redhat.com \
--cc=kraxel@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).