Skip to contentSkip to conversation

Fix block_passwd monitor command error

PATCH Applied Shahar Havivi 4 participants 6 messages Mar 5, 2010 – Mar 17, 2010

lore
Share & tools
lore
#0 lore raw

cover Fix block_passwd monitor command error

The next two patches fix the wrong error message in block_passwd monitor command: when trying to decrypt un-encrypted drive, user get error wrong password.

"1" add error message to qerror.h and qerror.c
"2" patch the monitor command error handling

Shahar Havivi (2):
QError: New QERR_DEVICE_NOT_ENCRYPTED
Wrong error message in block_passwd command

 block.c   |    7 +++++--
 monitor.c |    7 ++++++-
 qerror.c  |    4 ++++
 qerror.h  |    3 +++
 4 files changed, 18 insertions(+), 3 deletions(-)
#1 lore raw

PATCH 1/2 QError: New QERR_DEVICE_NOT_ENCRYPTED

---
 qerror.c |    4 ++++
 qerror.h |    3 +++
 2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
index 2f657f4..4e63a54 100644
@@ -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
index ee59615..b93fff6 100644
@@ -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
#3 lore raw

PATCH 2/2 Wrong error message in block_passwd command

In reply to Shahar Havivi
---
 block.c   |    7 +++++--
 monitor.c |    7 ++++++-
 2 files changed, 11 insertions(+), 3 deletions(-)
block.c +5 -2
index 31d1ba4..e891544 100644
@@ -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
index 19470d1..30dcbbe 100644
@@ -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;
     }
Signature · 1 line
1.6.3.3
Acked-by on the v1 series
#4 lore raw
In reply to Shahar Havivi

Am 05.03.2010 23:24, schrieb Shahar Havivi:

Quoted 11 lines

The next two patches fix the wrong error message in block_passwd monitor command: when trying to decrypt un-encrypted drive, user get error wrong password.

"1" add error message to qerror.h and qerror.c
"2" patch the monitor command error handling

Shahar Havivi (2):
QError: New QERR_DEVICE_NOT_ENCRYPTED
Wrong error message in block_passwd command

Quoted 5 lines
 block.c   |    7 +++++--
 monitor.c |    7 ++++++-
 qerror.c  |    4 ++++
 qerror.h  |    3 +++
 4 files changed, 18 insertions(+), 3 deletions(-)
#5 lore raw
In reply to Shahar Havivi
Quoted 6 lines · On Sat, 6 Mar 2010 00:24:53 +0200 Shahar Havivi <[email protected]> wrote:

The next two patches fix the wrong error message in block_passwd monitor command: when trying to decrypt un-encrypted drive, user get error wrong password.

"1" add error message to qerror.h and qerror.c
"2" patch the monitor command error handling

Looks good to me.

Quoted 13 lines

Shahar Havivi (2):
QError: New QERR_DEVICE_NOT_ENCRYPTED
Wrong error message in block_passwd command

 block.c   |    7 +++++--
 monitor.c |    7 ++++++-
 qerror.c  |    4 ++++
 qerror.h  |    3 +++
 4 files changed, 18 insertions(+), 3 deletions(-)
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] QError: New QERR_DEVICE_NOT_ENCRYPTED

In reply to Shahar Havivi
Quoted 2 lines · Shahar Havivi

Applied. Thanks.

Regards,

Anthony Liguori

Quoted 35 lines
---
  qerror.c |    4 ++++
  qerror.h |    3 +++
  2 files changed, 7 insertions(+), 0 deletions(-)
qerror.c +4 -0
index 2f657f4..4e63a54 100644
@@ -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
index ee59615..b93fff6 100644
@@ -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 } }"