From patchwork Mon Dec 5 20:00:19 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 129422 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 87AFA1007D4 for ; Tue, 6 Dec 2011 07:41:44 +1100 (EST) Received: from localhost ([::1]:39640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXej6-0004IG-Qx for incoming@patchwork.ozlabs.org; Mon, 05 Dec 2011 15:01:24 -0500 Received: from eggs.gnu.org ([140.186.70.92]:41750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXeia-0002mB-Cg for qemu-devel@nongnu.org; Mon, 05 Dec 2011 15:00:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RXeiY-00060m-QX for qemu-devel@nongnu.org; Mon, 05 Dec 2011 15:00:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51271) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RXeiY-00060V-CC for qemu-devel@nongnu.org; Mon, 05 Dec 2011 15:00:50 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pB5K0mSX006851 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 5 Dec 2011 15:00:48 -0500 Received: from localhost (ovpn-113-50.phx2.redhat.com [10.3.113.50]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pB5K0koc012302; Mon, 5 Dec 2011 15:00:47 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Mon, 5 Dec 2011 18:00:19 -0200 Message-Id: <1323115226-16817-10-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1323115226-16817-1-git-send-email-lcapitulino@redhat.com> References: <1323115226-16817-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 209.132.183.28 Cc: aliguori@us.ibm.com, mdroth@linux.vnet.ibm.com Subject: [Qemu-devel] [PATCH 09/16] qapi: Convert block_passwd X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Anthony Liguori Signed-off-by: Luiz Capitulino --- 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 dbf0251..aba7aaf 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); @@ -710,28 +711,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 1b48a75..93311a9 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 93d4a7e..0bf8896 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1198,8 +1198,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 5d1687d..3893d59 100644 --- a/hmp.c +++ b/hmp.c @@ -611,3 +611,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 1d6fb4d..569aa74 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -999,3 +999,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 5054da3..bbf9bfc 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