From patchwork Wed Aug 24 18:43:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 111414 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 648B3B6F18 for ; Thu, 25 Aug 2011 05:13:25 +1000 (EST) Received: from localhost ([::1]:56455 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwIR6-0002Yx-Iz for incoming@patchwork.ozlabs.org; Wed, 24 Aug 2011 14:44:24 -0400 Received: from eggs.gnu.org ([140.186.70.92]:46517) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwIQP-0000Ia-An for qemu-devel@nongnu.org; Wed, 24 Aug 2011 14:43:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QwIQJ-0006Mo-E7 for qemu-devel@nongnu.org; Wed, 24 Aug 2011 14:43:41 -0400 Received: from e3.ny.us.ibm.com ([32.97.182.143]:56383) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QwIQJ-0006MP-AV for qemu-devel@nongnu.org; Wed, 24 Aug 2011 14:43:35 -0400 Received: from d01relay05.pok.ibm.com (d01relay05.pok.ibm.com [9.56.227.237]) by e3.ny.us.ibm.com (8.14.4/8.13.1) with ESMTP id p7OIJ88V014415 for ; Wed, 24 Aug 2011 14:19:08 -0400 Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay05.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p7OIhXqD217720 for ; Wed, 24 Aug 2011 14:43:33 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p7OIhXgb011381 for ; Wed, 24 Aug 2011 15:43:33 -0300 Received: from titi.austin.rr.com (sig-9-48-61-239.mts.ibm.com [9.48.61.239]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p7OIhHub009550; Wed, 24 Aug 2011 15:43:29 -0300 From: Anthony Liguori To: qemu-devel@nongnu.org Date: Wed, 24 Aug 2011 13:43:04 -0500 Message-Id: <1314211389-28915-10-git-send-email-aliguori@us.ibm.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1314211389-28915-1-git-send-email-aliguori@us.ibm.com> References: <1314211389-28915-1-git-send-email-aliguori@us.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 32.97.182.143 Cc: Kevin Wolf , Anthony Liguori , Michael Roth , Luiz Capitulino Subject: [Qemu-devel] [PATCH 09/14] qapi: convert block_passwd and add set-blockdev-password 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 block_passwd is unfortunately named so while converting block_passwd to QAPI, introduce a more properly named alias. Signed-off-by: Anthony Liguori --- blockdev.c | 29 +++++++++++++++-------------- hmp-commands.hx | 2 +- hmp.c | 12 ++++++++++++ hmp.h | 1 + qapi-schema.json | 47 +++++++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 11 +++++++++-- 6 files changed, 85 insertions(+), 17 deletions(-) diff --git a/blockdev.c b/blockdev.c index 6b7fc41..37b2f29 100644 --- a/blockdev.c +++ b/blockdev.c @@ -672,28 +672,29 @@ void qmp_eject(const char *device, bool has_force, bool force, Error **errp) eject_device(bs, force, errp); } -int do_block_set_passwd(Monitor *mon, const QDict *qdict, - QObject **ret_data) +void qmp_set_blockdev_password(const char *device, const char *password, + Error **err) { BlockDriverState *bs; - int err; + int ret; - 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(err, QERR_DEVICE_NOT_FOUND, device); + return; } - err = bdrv_set_key(bs, qdict_get_str(qdict, "password")); - if (err == -EINVAL) { - qerror_report(QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs)); - return -1; - } else if (err < 0) { - qerror_report(QERR_INVALID_PASSWORD); - return -1; + ret = bdrv_set_key(bs, password); + if (ret == -EINVAL) { + error_set(err, QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs)); + } else if (ret < 0) { + error_set(err, QERR_INVALID_PASSWORD); } +} - return 0; +void qmp_block_passwd(const char *device, const char *password, Error **err) +{ + qmp_set_blockdev_password(device, password, err); } int do_change_block(Monitor *mon, const char *device, diff --git a/hmp-commands.hx b/hmp-commands.hx index bcb789b..2f0ffa3 100644 --- a/hmp-commands.hx +++ b/hmp-commands.hx @@ -1205,7 +1205,7 @@ ETEXI .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 36eb5b9..a8ae36b 100644 --- a/hmp.c +++ b/hmp.c @@ -38,3 +38,15 @@ void hmp_eject(Monitor *mon, const QDict *qdict) } } +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 *err = NULL; + + qmp_set_blockdev_password(device, password, &err); + if (err) { + monitor_printf(mon, "block_passwd: %s\n", error_get_pretty(err)); + error_free(err); + } +} diff --git a/hmp.h b/hmp.h index 6a552c1..8f72ef2 100644 --- a/hmp.h +++ b/hmp.h @@ -19,5 +19,6 @@ void hmp_info_name(Monitor *mon); void hmp_eject(Monitor *mon, const QDict *args); +void hmp_block_passwd(Monitor *mon, const QDict *qdict); #endif diff --git a/qapi-schema.json b/qapi-schema.json index 934ea81..f159d81 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -49,3 +49,50 @@ ## { 'command': 'eject', 'data': {'device': 'str', '*force': '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'} } + +## +# @set-blockdev-password: +# +# Alias for @block_passwd. +# +# @device: see @block_passwd +# @password: see @block_passwd +# +# Since: 1.0 +## +{ 'command': 'set-blockdev-password', + 'data': {'device': 'str', 'password': 'str'} } + diff --git a/qmp-commands.hx b/qmp-commands.hx index 81d1800..909c778 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -837,8 +837,15 @@ EQMP .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, + }, + + { + .name = "set-blockdev-password", + .args_type = "device:B,password:s", + .params = "block_passwd device password", + .help = "set the password of encrypted block devices", + .mhandler.cmd_new = qmp_marshal_input_set_blockdev_password, }, SQMP