From: Luiz Capitulino <lcapitulino@redhat.com>
To: qemu-devel@nongnu.org
Cc: aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com
Subject: [Qemu-devel] [PATCH 09/16] qapi: Convert block_passwd
Date: Mon, 28 Nov 2011 16:11:18 -0200 [thread overview]
Message-ID: <1322503885-5913-10-git-send-email-lcapitulino@redhat.com> (raw)
In-Reply-To: <1322503885-5913-1-git-send-email-lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
---
blockdev.c | 22 ++++++++++------------
blockdev.h | 1 -
hmp-commands.hx | 3 +--
hmp.c | 10 ++++++++++
hmp.h | 1 +
qapi-schema.json | 33 +++++++++++++++++++++++++++++++++
qmp-commands.hx | 5 +----
7 files changed, 56 insertions(+), 19 deletions(-)
diff --git a/blockdev.c b/blockdev.c
index 2228186..fc9cc63 100644
--- a/blockdev.c
+++ b/blockdev.c
@@ -15,6 +15,7 @@
#include "qemu-config.h"
#include "sysemu.h"
#include "block_int.h"
+#include "qmp-commands.h"
static QTAILQ_HEAD(drivelist, DriveInfo) drives = QTAILQ_HEAD_INITIALIZER(drives);
@@ -660,28 +661,25 @@ int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data)
return eject_device(mon, bs, force);
}
-int do_block_set_passwd(Monitor *mon, const QDict *qdict,
- QObject **ret_data)
+void qmp_block_passwd(const char *device, const char *password, Error **errp)
{
BlockDriverState *bs;
int err;
- bs = bdrv_find(qdict_get_str(qdict, "device"));
+ bs = bdrv_find(device);
if (!bs) {
- qerror_report(QERR_DEVICE_NOT_FOUND, qdict_get_str(qdict, "device"));
- return -1;
+ error_set(errp, QERR_DEVICE_NOT_FOUND, device);
+ return;
}
- err = bdrv_set_key(bs, qdict_get_str(qdict, "password"));
+ err = bdrv_set_key(bs, password);
if (err == -EINVAL) {
- qerror_report(QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs));
- return -1;
+ error_set(errp, QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs));
+ return;
} else if (err < 0) {
- qerror_report(QERR_INVALID_PASSWORD);
- return -1;
+ error_set(errp, QERR_INVALID_PASSWORD);
+ return;
}
-
- return 0;
}
int do_change_block(Monitor *mon, const char *device,
diff --git a/blockdev.h b/blockdev.h
index 3587786..d1a7204 100644
--- a/blockdev.h
+++ b/blockdev.h
@@ -59,7 +59,6 @@ DriveInfo *add_init_drive(const char *opts);
void do_commit(Monitor *mon, const QDict *qdict);
int do_eject(Monitor *mon, const QDict *qdict, QObject **ret_data);
-int do_block_set_passwd(Monitor *mon, const QDict *qdict, QObject **ret_data);
int do_change_block(Monitor *mon, const char *device,
const char *filename, const char *fmt);
int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
diff --git a/hmp-commands.hx b/hmp-commands.hx
index 546b740..a054b9a 100644
--- a/hmp-commands.hx
+++ b/hmp-commands.hx
@@ -1197,8 +1197,7 @@ ETEXI
.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,
+ .mhandler.cmd = hmp_block_passwd,
},
STEXI
diff --git a/hmp.c b/hmp.c
index 9b21990..0306a97 100644
--- a/hmp.c
+++ b/hmp.c
@@ -601,3 +601,13 @@ void hmp_set_link(Monitor *mon, const QDict *qdict)
qmp_set_link(name, up, &errp);
hmp_handle_error(mon, &errp);
}
+
+void hmp_block_passwd(Monitor *mon, const QDict *qdict)
+{
+ const char *device = qdict_get_str(qdict, "device");
+ const char *password = qdict_get_str(qdict, "password");
+ Error *errp = NULL;
+
+ qmp_block_passwd(device, password, &errp);
+ hmp_handle_error(mon, &errp);
+}
diff --git a/hmp.h b/hmp.h
index 32d7f68..d6aa232 100644
--- a/hmp.h
+++ b/hmp.h
@@ -42,5 +42,6 @@ void hmp_pmemsave(Monitor *mon, const QDict *qdict);
void hmp_cont(Monitor *mon, const QDict *qdict);
void hmp_inject_nmi(Monitor *mon, const QDict *qdict);
void hmp_set_link(Monitor *mon, const QDict *qdict);
+void hmp_block_passwd(Monitor *mon, const QDict *qdict);
#endif
diff --git a/qapi-schema.json b/qapi-schema.json
index 024ddcc..08c16a6 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -985,3 +985,36 @@
# notification.
##
{ 'command': 'set_link', 'data': {'name': 'str', 'up': 'bool'} }
+
+##
+# @block_passwd:
+#
+# This command sets the password of a block device that has not been open
+# with a password and requires one.
+#
+# The two cases where this can happen are a block device is created through
+# QEMU's initial command line or a block device is changed through the legacy
+# @change interface.
+#
+# In the event that the block device is created through the initial command
+# line, the VM will start in the stopped state regardless of whether '-S' is
+# used. The intention is for a management tool to query the block devices to
+# determine which ones are encrypted, set the passwords with this command, and
+# then start the guest with the @cont command.
+#
+# @device: the name of the device to set the password on
+#
+# @password: the password to use for the device
+#
+# Returns: nothing on success
+# If @device is not a valid block device, DeviceNotFound
+# If @device is not encrypted, DeviceNotEncrypted
+# If @password is not valid for this device, InvalidPassword
+#
+# Notes: Not all block formats support encryption and some that do are not
+# able to validate that a password is correct. Disk corruption may
+# occur if an invalid password is specified.
+#
+# Since: 0.14.0
+##
+{ 'command': 'block_passwd', 'data': {'device': 'str', 'password': 'str'} }
diff --git a/qmp-commands.hx b/qmp-commands.hx
index a65da39..5e7e5dd 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -806,10 +806,7 @@ EQMP
{
.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,
+ .mhandler.cmd_new = qmp_marshal_input_block_passwd,
},
SQMP
--
1.7.8.rc3.31.g017d1.dirty
next prev parent reply other threads:[~2011-11-28 18:12 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-28 18:11 [Qemu-devel] [PATCH 1.1 v1 00/16]: QAPI conversions round 3 Luiz Capitulino
2011-11-28 18:11 ` [Qemu-devel] [PATCH 01/16] qapi: Complete system_powerdown conversion Luiz Capitulino
2011-11-28 18:11 ` [Qemu-devel] [PATCH 02/16] console: Drop unused prototypes Luiz Capitulino
2011-11-28 18:11 ` [Qemu-devel] [PATCH 03/16] QError: Introduce QERR_IO_ERROR Luiz Capitulino
2011-11-28 18:11 ` [Qemu-devel] [PATCH 04/16] qapi: Convert memsave Luiz Capitulino
2011-11-28 18:11 ` [Qemu-devel] [PATCH 05/16] qapi: Convert pmemsave Luiz Capitulino
2011-11-28 18:11 ` [Qemu-devel] [PATCH 06/16] qapi: Convert cont Luiz Capitulino
2011-11-28 18:11 ` [Qemu-devel] [PATCH 07/16] qapi: Convert inject-nmi Luiz Capitulino
2011-11-28 18:11 ` [Qemu-devel] [PATCH 08/16] qapi: Convert set_link Luiz Capitulino
2011-11-28 18:11 ` Luiz Capitulino [this message]
2011-11-28 18:11 ` [Qemu-devel] [PATCH 10/16] qapi: Convert balloon Luiz Capitulino
2011-11-28 18:11 ` [Qemu-devel] [PATCH 11/16] qapi: Convert block_resize Luiz Capitulino
2011-11-28 18:11 ` [Qemu-devel] [PATCH 12/16] qapi: Convert blockdev_snapshot_sync Luiz Capitulino
2011-11-28 18:11 ` [Qemu-devel] [PATCH 13/16] qapi: Convert human-monitor-command Luiz Capitulino
2011-11-28 18:11 ` [Qemu-devel] [PATCH 14/16] qapi: Convert migrate_cancel Luiz Capitulino
2011-11-28 18:11 ` [Qemu-devel] [PATCH 15/16] qapi: Convert migrate_set_downtime Luiz Capitulino
2011-11-28 18:11 ` [Qemu-devel] [PATCH 16/16] qapi: Convert migrate_set_speed Luiz Capitulino
-- strict thread matches above, loose matches on Subject: below --
2011-12-05 20:00 [Qemu-devel] [PATCH v2 00/16]: QAPI conversions round 3 Luiz Capitulino
2011-12-05 20:00 ` [Qemu-devel] [PATCH 09/16] qapi: Convert block_passwd Luiz Capitulino
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=1322503885-5913-10-git-send-email-lcapitulino@redhat.com \
--to=lcapitulino@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=mdroth@linux.vnet.ibm.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).