monitor: Introduce 'block_passwd' command
authorLuiz Capitulino <lcapitulino@redhat.com>
Fri, 4 Dec 2009 17:24:09 +0000 (15:24 -0200)
committerAnthony Liguori <aliguori@us.ibm.com>
Mon, 7 Dec 2009 20:04:20 +0000 (14:04 -0600)
When using encrypted disk images, QEMU will prompt the user
for passwords when started.

This makes sense for the user protocol, but doesn't for QMP.

The solution is to have Monitor command which allows the user
or a Client to set passwords in advance, so that we avoid
the prompt completely.

This is what block_passwd does, for example:

(QEMU) block_passwd ide0-hd0 foobar

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
monitor.c
qemu-monitor.hx

index ba76f3416d611e4abd71a9b44b75c23228c36e08..27c696b2d4298c8d9855de7141c46e8f47496616 100644 (file)
--- a/monitor.c
+++ b/monitor.c
@@ -772,6 +772,22 @@ static void do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data)
     eject_device(mon, bs, force);
 }
 
+static void do_block_set_passwd(Monitor *mon, const QDict *qdict,
+                                QObject **ret_data)
+{
+    BlockDriverState *bs;
+
+    bs = bdrv_find(qdict_get_str(qdict, "device"));
+    if (!bs) {
+        qemu_error_new(QERR_DEVICE_NOT_FOUND, qdict_get_str(qdict, "device"));
+        return;
+    }
+
+    if (bdrv_set_key(bs, qdict_get_str(qdict, "password")) < 0) {
+        qemu_error_new(QERR_INVALID_PASSWORD);
+    }
+}
+
 static void do_change_block(Monitor *mon, const char *device,
                             const char *filename, const char *fmt)
 {
index 62e395bffd6d087f96ca3cea4f7313069e57f8c7..c2670ee1d96c27a990f04f3cdd61f7914d56fdc3 100644 (file)
@@ -1045,6 +1045,20 @@ STEXI
 Close the file descriptor previously assigned to @var{fdname} using the
 @code{getfd} command. This is only needed if the file descriptor was never
 used by another monitor command.
+ETEXI
+
+    {
+        .name       = "block_passwd",
+        .args_type  = "device:B,password:s",
+        .params     = "block_passwd device password",
+        .help       = "set the password of encrypted block devices",
+        .user_print = monitor_user_noop,
+        .mhandler.cmd_new = do_block_set_passwd,
+    },
+
+STEXI
+@item block_passwd @var{device} @var{password}
+Set the encrypted device @var{device} password to @var{password}
 ETEXI
 
 STEXI