Skip to contentSkip to conversation

Replace QERR_PERMISSION_DENIED by better error messages

PATCH In review Markus Armbruster 4 participants 11 messages Oct 12, 2022 – Oct 27, 2022

lore
Share & tools
lore
#0 lore raw

cover Replace QERR_PERMISSION_DENIED by better error messages

Markus Armbruster (4):
qom: Improve error messages when property has no getter or setter
backends: Improve error messages when property can no longer be set
qtest: Improve error messages when property can not be set right now
qerror: QERR_PERMISSION_DENIED is no longer used, drop

 include/qapi/qmp/qerror.h       | 3 ---
 backends/cryptodev-vhost-user.c | 2 +-
 backends/rng-egd.c              | 2 +-
 backends/rng-random.c           | 2 +-
 backends/vhost-user.c           | 2 +-
 qom/object.c                    | 6 ++++--
 softmmu/qtest.c                 | 4 ++--
 7 files changed, 10 insertions(+), 11 deletions(-)
Signature · 1 line
2.37.2
#1 lore raw

PATCH 1/4 qom: Improve error messages when property has no getter or setter

When you try to set a property that has no setter, the error message blames "insufficient permission":

    $ qemu-system-x86_64 -S -display none -nodefaults -monitor stdio
    QEMU 7.1.50 monitor - type 'help' for more information
    (qemu) qom-set /machine type q35
    Error: Insufficient permission to perform this operation

This implies it could work with "sufficient permission". It can't. Change the error message to:

Error: Property 'pc-i440fx-7.2-machine.type' is not writable

Do the same for getting a property that has no getter.

---
 qom/object.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
qom/object.c +4 -2
index d34608558e..e5cef30f6d 100644
@@ -1383,7 +1383,8 @@ bool object_property_get(Object *obj, const char *name, Visitor *v,
     }
 
     if (!prop->get) {
-        error_setg(errp, QERR_PERMISSION_DENIED);
+        error_setg(errp, "Property '%s.%s' is not readable",
+                   object_get_typename(obj), name);
         return false;
     }
     prop->get(obj, v, name, prop->opaque, &err);
@@ -1402,7 +1403,8 @@ bool object_property_set(Object *obj, const char *name, Visitor *v,
     }
 
     if (!prop->set) {
-        error_setg(errp, QERR_PERMISSION_DENIED);
+        error_setg(errp, "Property '%s.%s' is not writable",
+                   object_get_typename(obj), name);
         return false;
     }
     prop->set(obj, v, name, prop->opaque, errp);
Signature · 1 line
2.37.2
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] qom: Improve error messages when property has no getter or setter

Quoted 35 lines · Markus Armbruster

When you try to set a property that has no setter, the error message blames "insufficient permission":

     $ qemu-system-x86_64 -S -display none -nodefaults -monitor stdio
     QEMU 7.1.50 monitor - type 'help' for more information
     (qemu) qom-set /machine type q35
     Error: Insufficient permission to perform this operation

This implies it could work with "sufficient permission". It can't. Change the error message to:

Error: Property 'pc-i440fx-7.2-machine.type' is not writable

Do the same for getting a property that has no getter.

---
  qom/object.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
qom/object.c +2 -1
index d34608558e..e5cef30f6d 100644
@@ -1383,7 +1383,8 @@ bool object_property_get(Object *obj, const char *name, Visitor *v,
      }
 
      if (!prop->get) {
-        error_setg(errp, QERR_PERMISSION_DENIED);
+        error_setg(errp, "Property '%s.%s' is not readable",
+                   object_get_typename(obj), name);
          return false;
      }
      prop->get(obj, v, name, prop->opaque, &err);

qom/object.c bool object_property_set(Object *obj, const char *name, Visitor *v, · line 1410

Quoted 9 lines
qom/object.c +2 -1
@@ -1402,7 +1403,8 @@ bool object_property_set(Object *obj, const char *name, Visitor *v,
      }
 
      if (!prop->set) {
-        error_setg(errp, QERR_PERMISSION_DENIED);
+        error_setg(errp, "Property '%s.%s' is not writable",
+                   object_get_typename(obj), name);
          return false;
      }
      prop->set(obj, v, name, prop->opaque, errp);

Much better!

Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw

PATCH 2/4 backends: Improve error messages when property can no longer be set

In reply to Markus Armbruster

When you try to set virtio-rng property "filename" after the backend has been completed with user_creatable_complete(), the error message blames "insufficient permission":

    $ qemu-system-x86_64 -S -display none -nodefaults -monitor stdio -object rng-random,id=rng0 -device virtio-rng,id=vrng0,rng=rng0
    QEMU 7.1.50 monitor - type 'help' for more information
    (qemu) qom-set /objects/rng0 filename /dev/random
    Error: Insufficient permission to perform this operation

This implies it could work with "sufficient permission". It can't. Change the error message to:

Error: Property 'filename' can no longer be set

Same for cryptodev-vhost-user property "chardev", rng-egd property "chardev", and vhost-user-backend property "chardev".

# This is the commit message #2:

# fixup! backends: Improve error messages when property can no longer be set

---
 backends/cryptodev-vhost-user.c | 2 +-
 backends/rng-egd.c              | 2 +-
 backends/rng-random.c           | 2 +-
 backends/vhost-user.c           | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)
backends/cryptodev-vhost-user.c +1 -1
index 5443a59153..f9c5867e38 100644
@@ -339,7 +339,7 @@ static void cryptodev_vhost_user_set_chardev(Object *obj,
                       CRYPTODEV_BACKEND_VHOST_USER(obj);
 
     if (s->opened) {
-        error_setg(errp, QERR_PERMISSION_DENIED);
+        error_setg(errp, "Property 'chardev' can no longer be set");
     } else {
         g_free(s->chr_name);
         s->chr_name = g_strdup(value);
backends/rng-egd.c +1 -1
index 4de142b9dc..684c3cf3d6 100644
@@ -116,7 +116,7 @@ static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)
     RngEgd *s = RNG_EGD(b);
 
     if (b->opened) {
-        error_setg(errp, QERR_PERMISSION_DENIED);
+        error_setg(errp, "Property 'chardev' can no longer be set");
     } else {
         g_free(s->chr_name);
         s->chr_name = g_strdup(value);
backends/rng-random.c +1 -1
index 7add272edd..80eb5be138 100644
@@ -96,7 +96,7 @@ static void rng_random_set_filename(Object *obj, const char *filename,
     RngRandom *s = RNG_RANDOM(obj);
 
     if (b->opened) {
-        error_setg(errp, QERR_PERMISSION_DENIED);
+        error_setg(errp, "Property 'filename' can no longer be set");
         return;
     }
 
backends/vhost-user.c +1 -1
index 10b39992d2..5dedb2d987 100644
@@ -141,7 +141,7 @@ static void set_chardev(Object *obj, const char *value, Error **errp)
     Chardev *chr;
 
     if (b->completed) {
-        error_setg(errp, QERR_PERMISSION_DENIED);
+        error_setg(errp, "Property 'chardev' can no longer be set");
         return;
     }
 
Signature · 1 line
2.37.2
#4 lore raw

PATCH 3/4 qtest: Improve error messages when property can not be set right now

In reply to Markus Armbruster

When you try to set qtest property "log" while the qtest object is active, the error message blames "insufficient permission":

    $ qemu-system-x86_64 -S -display none -nodefaults -monitor stdio -chardev socket,id=chrqt0,path=qtest.socket,server=on,wait=off -object qtest,id=qt0,chardev=chrqt0,log=/dev/null
    QEMU 7.1.50 monitor - type 'help' for more information
    (qemu) qom-set /objects/qt0 log qtest.log
    Error: Insufficient permission to perform this operation

This implies it could work with "sufficient permission". It can't. Change the error message to:

Error: Property 'log' can not be set now

Same for property "chardev".

---
 softmmu/qtest.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
softmmu/qtest.c +2 -2
index f8acef2628..afea7693d0 100644
@@ -977,7 +977,7 @@ static void qtest_set_log(Object *obj, const char *value, Error **errp)
     QTest *q = QTEST(obj);
 
     if (qtest == q) {
-        error_setg(errp, QERR_PERMISSION_DENIED);
+        error_setg(errp, "Property 'log' can not be set now");
     } else {
         g_free(q->log);
         q->log = g_strdup(value);
@@ -997,7 +997,7 @@ static void qtest_set_chardev(Object *obj, const char *value, Error **errp)
     Chardev *chr;
 
     if (qtest == q) {
-        error_setg(errp, QERR_PERMISSION_DENIED);
+        error_setg(errp, "Property 'chardev' can not be set now");
         return;
     }
 
Signature · 1 line
2.37.2
#5 lore raw

Re: [PATCH 3/4] qtest: Improve error messages when property can not be set right now

Quoted 8 lines · Markus Armbruster

When you try to set qtest property "log" while the qtest object is active, the error message blames "insufficient permission":

     $ qemu-system-x86_64 -S -display none -nodefaults -monitor stdio -chardev socket,id=chrqt0,path=qtest.socket,server=on,wait=off -object qtest,id=qt0,chardev=chrqt0,log=/dev/null
     QEMU 7.1.50 monitor - type 'help' for more information
     (qemu) qom-set /objects/qt0 log qtest.log
     Error: Insufficient permission to perform this operation
Quoted 4 lines

This implies it could work with "sufficient permission". It can't. Change the error message to:

Error: Property 'log' can not be set now

Can it be set later? ... if not, that error message is almost as confusing as the original one. Maybe it's better to tell the users *when* they can set the property?

Thomas

#6 lore raw

Re: [PATCH 3/4] qtest: Improve error messages when property can not be set right now

Quoted 9 lines · Thomas Huth
Quoted 8 lines · Markus Armbruster

When you try to set qtest property "log" while the qtest object is active, the error message blames "insufficient permission":

      $ qemu-system-x86_64 -S -display none -nodefaults -monitor stdio -chardev socket,id=chrqt0,path=qtest.socket,server=on,wait=off -object qtest,id=qt0,chardev=chrqt0,log=/dev/null
      QEMU 7.1.50 monitor - type 'help' for more information
      (qemu) qom-set /objects/qt0 log qtest.log
      Error: Insufficient permission to perform this operation
Quoted 8 lines
Quoted 4 lines

This implies it could work with "sufficient permission". It can't. Change the error message to:

Error: Property 'log' can not be set now

Can it be set later? ... if not, that error message is almost as confusing as the original one. Maybe it's better to tell the users *when* they can set the property?

I assume it's mostly about "This property cannot be set." and "This property can no longer be set." ?

Signature · 3 lines
Thanks,

David / dhildenb
#7 lore raw

Re: [PATCH 3/4] qtest: Improve error messages when property can not be set right now

In reply to Thomas Huth
Quoted 9 lines · Thomas Huth
Quoted 8 lines · Markus Armbruster

When you try to set qtest property "log" while the qtest object is active, the error message blames "insufficient permission":

     $ qemu-system-x86_64 -S -display none -nodefaults -monitor stdio -chardev socket,id=chrqt0,path=qtest.socket,server=on,wait=off -object qtest,id=qt0,chardev=chrqt0,log=/dev/null
     QEMU 7.1.50 monitor - type 'help' for more information
     (qemu) qom-set /objects/qt0 log qtest.log
     Error: Insufficient permission to perform this operation
Quoted 8 lines
Quoted 4 lines

This implies it could work with "sufficient permission". It can't. Change the error message to:

Error: Property 'log' can not be set now

Can it be set later? ... if not, that error message is almost as confusing as the original one. Maybe it's better to tell the users *when* they can set the property?

The property cannot be set while the object is "active", i.e. global @qtest points to it.

Right now, @qtest points to the object from completion with user_creatable_complete() to unparent.

Completion fails when @qtest already points to another object, i.e. only one object can be complete at any time.

Since Paolo took the trouble to code an unparent method, I assume unparent can happen. I can't tell offhand when.

Help!

#8 lore raw

Re: [PATCH 3/4] qtest: Improve error messages when property can not be set right now

Quoted 26 lines · Markus Armbruster
Quoted 9 lines · Thomas Huth
Quoted 8 lines · Markus Armbruster

When you try to set qtest property "log" while the qtest object is active, the error message blames "insufficient permission":

     $ qemu-system-x86_64 -S -display none -nodefaults -monitor stdio -chardev socket,id=chrqt0,path=qtest.socket,server=on,wait=off -object qtest,id=qt0,chardev=chrqt0,log=/dev/null
     QEMU 7.1.50 monitor - type 'help' for more information
     (qemu) qom-set /objects/qt0 log qtest.log
     Error: Insufficient permission to perform this operation
Quoted 8 lines
Quoted 4 lines

This implies it could work with "sufficient permission". It can't. Change the error message to:

Error: Property 'log' can not be set now

Can it be set later? ... if not, that error message is almost as confusing as the original one. Maybe it's better to tell the users *when* they can set the property?

The property cannot be set while the object is "active", i.e. global @qtest points to it.

Right now, @qtest points to the object from completion with user_creatable_complete() to unparent.

Quoted 7 lines

Completion fails when @qtest already points to another object, i.e. only one object can be complete at any time.

Since Paolo took the trouble to code an unparent method, I assume unparent can happen. I can't tell offhand when.

Help!

Since users are unlikely to hit this error, the new message feels good enough to me. Happy to take rewordings, or to redo the patch so that it preserves the old message while getting rid of QERR_PERMISSION_DENIED.

#9 lore raw

PATCH 4/4 qerror: QERR_PERMISSION_DENIED is no longer used, drop

In reply to Markus Armbruster
---
 include/qapi/qmp/qerror.h | 3 ---
 1 file changed, 3 deletions(-)
include/qapi/qmp/qerror.h +0 -3
index 596fce0c54..87ca83b155 100644
@@ -50,9 +50,6 @@
 #define QERR_MISSING_PARAMETER \
     "Parameter '%s' is missing"
 
-#define QERR_PERMISSION_DENIED \
-    "Insufficient permission to perform this operation"
-
 #define QERR_PROPERTY_VALUE_BAD \
     "Property '%s.%s' doesn't take value '%s'"
 
Signature · 1 line
2.37.2
Acked-by on the v1 series
#10 lore raw
In reply to Markus Armbruster
Quoted 5 lines · Markus Armbruster

Markus Armbruster (4):
qom: Improve error messages when property has no getter or setter
backends: Improve error messages when property can no longer be set
qtest: Improve error messages when property can not be set right now
qerror: QERR_PERMISSION_DENIED is no longer used, drop

vhost user things

Quoted 11 lines
 include/qapi/qmp/qerror.h       | 3 ---
 backends/cryptodev-vhost-user.c | 2 +-
 backends/rng-egd.c              | 2 +-
 backends/rng-random.c           | 2 +-
 backends/vhost-user.c           | 2 +-
 qom/object.c                    | 6 ++++--
 softmmu/qtest.c                 | 4 ++--
 7 files changed, 10 insertions(+), 11 deletions(-)
Signature · 1 line
2.37.2