Skip to content

Commit

Permalink
Wrong error message in block_passwd command
Browse files Browse the repository at this point in the history
Signed-off-by: Shahar Havivi <shaharh@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
  • Loading branch information
shaharha authored and Anthony Liguori committed Mar 17, 2010
1 parent 25b28f0 commit fd04a2a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 5 additions & 2 deletions block.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1057,14 +1057,19 @@ 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) {
qerror_report(QERR_DEVICE_NOT_FOUND, qdict_get_str(qdict, "device"));
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) {
qerror_report(QERR_DEVICE_NOT_ENCRYPTED, bdrv_get_device_name(bs));
return -1;
} else if (err < 0) {
qerror_report(QERR_INVALID_PASSWORD);
return -1;
}
Expand Down

0 comments on commit fd04a2a

Please sign in to comment.