From patchwork Fri Mar 5 15:47:33 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shahar Havivi X-Patchwork-Id: 47011 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id D87C8B7CE7 for ; Sat, 6 Mar 2010 02:52:39 +1100 (EST) Received: from localhost ([127.0.0.1]:55234 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NnZlo-0007pi-VK for incoming@patchwork.ozlabs.org; Fri, 05 Mar 2010 10:48:56 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NnZkZ-0007pd-Ub for qemu-devel@nongnu.org; Fri, 05 Mar 2010 10:47:39 -0500 Received: from [199.232.76.173] (port=39961 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NnZkZ-0007pU-Dm for qemu-devel@nongnu.org; Fri, 05 Mar 2010 10:47:39 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NnZkX-0002DY-JE for qemu-devel@nongnu.org; Fri, 05 Mar 2010 10:47:39 -0500 Received: from mx1.redhat.com ([209.132.183.28]:14975) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NnZkX-0002DK-56 for qemu-devel@nongnu.org; Fri, 05 Mar 2010 10:47:37 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o25Fla6v032400 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 5 Mar 2010 10:47:36 -0500 Received: from localhost (dhcp-1-229.tlv.redhat.com [10.35.1.229]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o25FlYN1018008; Fri, 5 Mar 2010 10:47:35 -0500 Date: Fri, 5 Mar 2010 17:47:33 +0200 From: Shahar Havivi To: Kevin Wolf Message-ID: <20100305154732.GA21444@redhat.com> References: <20100305151222.GA21283@redhat.com> <4B9121CF.6020703@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <4B9121CF.6020703@redhat.com> User-Agent: Mutt/1.5.20 (2009-08-17) X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Luiz Capitulino , Dor Laor , qemu-devel@nongnu.org Subject: [Qemu-devel] Re: [PATCH] Wrong error message in block_passwd command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Fri, Mar 05, 2010 at 04:22:55PM +0100, Kevin Wolf wrote: > Date: Fri, 05 Mar 2010 16:22:55 +0100 > From: Kevin Wolf > To: Shahar Havivi > CC: qemu-devel@nongnu.org, Dor Laor , > Luiz Capitulino > Subject: Re: [PATCH] Wrong error message in block_passwd command > > Am 05.03.2010 16:12, schrieb Shahar Havivi: > > Monitor command 'block_passwd' reports a wrong error message when > > drive is not encrypted > > > > Signed-off-by: Shahar Havivi > > --- > > block.c | 9 ++++++--- > > monitor.c | 7 ++++++- > > qerror.c | 4 ++++ > > qerror.h | 3 +++ > > 4 files changed, 19 insertions(+), 4 deletions(-) > > > > diff --git a/block.c b/block.c > > index 31d1ba4..dd484fa 100644 > > --- a/block.c > > +++ b/block.c > > @@ -1132,10 +1132,13 @@ int bdrv_set_key(BlockDriverState *bs, const char *key) > > if (ret < 0) > > return ret; > > if (!bs->encrypted) > > - return 0; > > + return -EINVAL; > > + } > > I think this part is wrong actually. Sorry for not catching it when you > sent me the patch first. > > The logic here is that it's not an error to set the password for a file > which isn't encrypted itself, but its backing file is. In this case the > key is only set for the backing file and we return success. > > The other parts look good to me. > > Kevin You right Kevin, Revert returning error when backing file in bdrv_set_key. Signed-off-by: Shahar Havivi --- block.c | 7 +++++-- monitor.c | 7 ++++++- qerror.c | 4 ++++ qerror.h | 3 +++ 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/block.c b/block.c index 31d1ba4..e891544 100644 --- a/block.c +++ b/block.c @@ -1134,8 +1134,11 @@ int bdrv_set_key(BlockDriverState *bs, const char *key) if (!bs->encrypted) return 0; } - if (!bs->encrypted || !bs->drv || !bs->drv->bdrv_set_key) - return -1; + if (!bs->encrypted) { + return -EINVAL; + } else if (!bs->drv || !bs->drv->bdrv_set_key) { + return -ENOMEDIUM; + } ret = bs->drv->bdrv_set_key(bs, key); if (ret < 0) { bs->valid_key = 0; diff --git a/monitor.c b/monitor.c index 19470d1..30dcbbe 100644 --- a/monitor.c +++ b/monitor.c @@ -1042,6 +1042,7 @@ static int do_block_set_passwd(Monitor *mon, const QDict *qdict, QObject **ret_data) { BlockDriverState *bs; + int err; bs = bdrv_find(qdict_get_str(qdict, "device")); if (!bs) { @@ -1049,7 +1050,11 @@ static int do_block_set_passwd(Monitor *mon, const QDict *qdict, return -1; } - if (bdrv_set_key(bs, qdict_get_str(qdict, "password")) < 0) { + err = bdrv_set_key(bs, qdict_get_str(qdict, "password")); + if (err == -EINVAL) { + qemu_error_new(QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs)); + return -1; + } else if (err < 0) { qemu_error_new(QERR_INVALID_PASSWORD); return -1; } diff --git a/qerror.c b/qerror.c index 2f657f4..4e63a54 100644 --- a/qerror.c +++ b/qerror.c @@ -49,6 +49,10 @@ static const QErrorStringTable qerror_table[] = { .desc = "The %(device) is encrypted", }, { + .error_fmt = QERR_DEVICE_NOT_ENCRYPTED, + .desc = "Device '%(device)' is not encrypted", + }, + { .error_fmt = QERR_DEVICE_LOCKED, .desc = "Device %(device) is locked", }, diff --git a/qerror.h b/qerror.h index ee59615..b93fff6 100644 --- a/qerror.h +++ b/qerror.h @@ -46,6 +46,9 @@ QError *qobject_to_qerror(const QObject *obj); #define QERR_DEVICE_ENCRYPTED \ "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s } }" +#define QERR_DEVICE_NOT_ENCRYPTED \ + "{ 'class': 'DeviceNotEncrypted', 'data': { 'device': %s } }" + #define QERR_DEVICE_LOCKED \ "{ 'class': 'DeviceLocked', 'data': { 'device': %s } }"