Wrong error message in block_passwd command
PATCH 1/1 Wrong error message in block_passwd command
Monitor command 'block_passwd' reports a wrong error message when drive is not encrypted
--- block.c | 9 ++++++--- monitor.c | 7 ++++++- qerror.c | 4 ++++ qerror.h | 3 +++ 4 files changed, 19 insertions(+), 4 deletions(-)
block.c +6 -3
@@ -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 ; + } +if (!bs->encrypted) { +return -EINVAL ; + }else if (!bs->drv || !bs->drv->bdrv_set_key) { +return -ENOMEDIUM ; } -if (!bs->encrypted || !bs->drv || !bs->drv->bdrv_set_key) -return -1 ; ret = bs->drv->bdrv_set_key (bs, key);if (ret <0 ) { bs->valid_key =0 ;
monitor.c +6 -1
@@ -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 ; }
qerror.c +4 -0
@@ -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", },
qerror.h +3 -0
@@ -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 } }"
Signature · 1 line
1.6.3.3
Am 05.03.2010 16:12, schrieb Shahar Havivi:
Quoted 16 lines
Monitor command '
block_passwd' reports a wrong error message when drive is not encryptedSigned-off-by Shahar Havivi <[email protected]>--- block.c | 9 ++++++--- monitor.c | 7 ++++++- qerror.c | 4 ++++ qerror.h | 3 +++ 4 files changed, 19 insertions(+), 4 deletions(-)block.c +0
-0
block.c int bdrv_set_key(BlockDriverState *bs, const char *key) · line 1136
Quoted 6 lines
block.c +2
-1@@ -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
Quoted 34 lines · Kevin Wolf
Date: Fri, 05 Mar 2010 16:22:55 +0100
From: Kevin Wolf <[email protected]>
To: Shahar Havivi <[email protected]>
CC: [email protected], Dor Laor <[email protected]>,
Luiz Capitulino <[email protected]>
Subject: Re: [PATCH] Wrong error message inblock_passwdcommandAm 05.03.2010 16:12, schrieb Shahar Havivi:
Quoted 16 lines
Monitor command '
block_passwd' reports a wrong error message when drive is not encryptedSigned-off-by Shahar Havivi <[email protected]>--- block.c | 9 ++++++--- monitor.c | 7 ++++++- qerror.c | 4 ++++ qerror.h | 3 +++ 4 files changed, 19 insertions(+), 4 deletions(-)block.c +0
-0block.c int bdrv_set_key(BlockDriverState *bs, const char *key) · line 1136
Quoted 6 lines
block.c +2
-1@@ -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.
Quoted 7 lines
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.
--- block.c | 7 +++++-- monitor.c | 7 ++++++- qerror.c | 4 ++++ qerror.h | 3 +++ 4 files changed, 18 insertions(+), 3 deletions(-)
block.c +5 -2
@@ -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 ;
monitor.c +6 -1
@@ -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 ; }
qerror.c +4 -0
@@ -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", },
qerror.h +3 -0
@@ -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 } }"
Signature · 1 line
1.6.3.3
Quoted 39 lines · On Fri, 5 Mar 2010 17:47:33 +0200 Shahar Havivi <[email protected]> wrote:
Quoted 38 lines · Kevin Wolf
Date: Fri, 05 Mar 2010 16:22:55 +0100
From: Kevin Wolf <[email protected]>
To: Shahar Havivi <[email protected]>
CC: [email protected], Dor Laor <[email protected]>,
Luiz Capitulino <[email protected]>
Subject: Re: [PATCH] Wrong error message inblock_passwdcommandAm 05.03.2010 16:12, schrieb Shahar Havivi:
Quoted 16 lines
Monitor command '
block_passwd' reports a wrong error message when drive is not encryptedSigned-off-by Shahar Havivi <[email protected]>--- block.c | 9 ++++++--- monitor.c | 7 ++++++- qerror.c | 4 ++++ qerror.h | 3 +++ 4 files changed, 19 insertions(+), 4 deletions(-)block.c +0
-0block.c int bdrv_set_key(BlockDriverState *bs, const char *key) · line 1136
Quoted 6 lines
block.c +2
-1@@ -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.
Quoted 5 lines
Quoted 3 lines
The other parts look good to me.
Kevin
You right Kevin,
Revert returning error when backing file inbdrv_set_key.
Looks good to me too, but it's better to send it as new message, as
maintainers can miss patches submitted in the middle of thread.
Quoted 20 lines · Shahar Havivi
qerror.c +4
-0@@ -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", },qerror.h +0
-0
qerror.h QError *qobject_to_qerror(const QObject *obj); · line 53
Quoted 8 lines
qerror.h +3
-0@@ -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 } }"
Would you humor me and keep the error definitions sorted? Thanks.
PS: Luiz has always put each new error in its own commit, and I followed that practice. Not sure we really care.
Quoted 25 lines · On Fri, 05 Mar 2010 17:47:49 +0100 Markus Armbruster <[email protected]> wrote:
Quoted 23 lines · Shahar Havivi
qerror.c +4
-0@@ -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", },qerror.h +0
-0@@ -46,6 +46,9 @@ QError *qobject_to_qerror(const QObject *obj);#define QERR_DEVICE_ENCRYPTED \ "{ 'class': 'DeviceEncrypted', 'data': { 'device': %s } }"
Quoted 7 lines
qerror.h QError *qobject_to_qerror(const QObject *obj); · line 53
Quoted 5 lines
qerror.h +3
-0+#define QERR_DEVICE_NOT_ENCRYPTED \ + "{ 'class': 'DeviceNotEncrypted', 'data': { 'device': %s } }" +#define QERR_DEVICE_LOCKED \ "{ 'class': 'DeviceLocked', 'data': { 'device': %s } }"Would you humor me and keep the error definitions sorted? Thanks.
A comment in the file will help.
Quoted 2 lines
PS: Luiz has always put each new error in its own commit, and I followed that practice. Not sure we really care.
Well, turns out you were the only one to revert some of them :) So, I'm
ok with either way.