summary refs log tree commit diff stats
path: root/hw/usb/dev-storage.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2015-03-12 17:26:48 +0100
committerGerd Hoffmann <kraxel@redhat.com>2015-03-17 14:23:52 +0100
commit9b14e0efcc9a6ea41b7265538f6ec4c53e2ba270 (patch)
treed763480ad414d55dd59a53fb274bd2165cb6571a /hw/usb/dev-storage.c
parent988e0f06621fde11ec0d319a6fd0ab3ccef0602f (diff)
downloadfocaccia-qemu-9b14e0efcc9a6ea41b7265538f6ec4c53e2ba270.tar.gz
focaccia-qemu-9b14e0efcc9a6ea41b7265538f6ec4c53e2ba270.zip
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 <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'hw/usb/dev-storage.c')
-rw-r--r--hw/usb/dev-storage.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
index dacefd71a5..f47c8561ef 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;