From: Shahar Havivi <shaharh@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
Luiz Capitulino <lcapitul@redhat.com>,
Dor Laor <dlaor@redhat.com>
Subject: [Qemu-devel] [PATCH] Wrong error message in block_passwd command
Date: Fri, 5 Mar 2010 17:12:27 +0200 [thread overview]
Message-ID: <20100305151222.GA21283@redhat.com> (raw)
Monitor command 'block_passwd' reports a wrong error message when
drive is not encrypted
Signed-off-by: Shahar Havivi <shaharh@redhat.com>
---
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;
+ }
+ 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;
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 } }"
--
1.6.3.3
next reply other threads:[~2010-03-05 15:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-05 15:12 Shahar Havivi [this message]
2010-03-05 15:22 ` [Qemu-devel] Re: [PATCH] Wrong error message in block_passwd command Kevin Wolf
2010-03-05 15:47 ` Shahar Havivi
2010-03-05 15:56 ` Luiz Capitulino
2010-03-05 16:47 ` Markus Armbruster
2010-03-05 20:41 ` Luiz Capitulino
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100305151222.GA21283@redhat.com \
--to=shaharh@redhat.com \
--cc=dlaor@redhat.com \
--cc=kwolf@redhat.com \
--cc=lcapitul@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).