Skip to contentSkip to conversation

machine: Fix replacement of '_' by '-' in machine property names

PATCH Applied Markus Armbruster 3 participants 8 messages Oct 13, 2016 – Oct 17, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 machine: Fix replacement of '_' by '-' in machine property names

machine_set_property() replaces '_' by '-' in the property name. Except it fails to replace an initial '_'. Screwed up in commit b0ddb8b. Reproducer: "-M pc,__foo_bar=true" produces "Property '._-foo-bar' not found".

Error messages using a mangled name rather than the name the user actually wrote is user-hostile, but that's a different topic.

---
 vl.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
vl.c +4 -5
index c657acd..1c0b0ba 100644
@@ -2804,17 +2804,16 @@ static int machine_set_property(void *opaque,
 {
     Object *obj = OBJECT(opaque);
     Error *local_err = NULL;
-    char *c, *qom_name;
+    char *p, *qom_name;
 
     if (strcmp(name, "type") == 0) {
         return 0;
     }
 
     qom_name = g_strdup(name);
-    c = qom_name;
-    while (*c++) {
-        if (*c == '_') {
-            *c = '-';
+    for (p = qom_name; *p; p++) {
+        if (*p == '_') {
+            *p = '-';
         }
     }
 
Signature · 1 line
2.5.5
Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · Markus Armbruster

machine_set_property() replaces '_' by '-' in the property name. Except it fails to replace an initial '_'. Screwed up in commit b0ddb8b. Reproducer: "-M pc,__foo_bar=true" produces "Property '._-foo-bar' not found".

Quoted 7 lines

Error messages using a mangled name rather than the name the user actually wrote is user-hostile, but that's a different topic.

---
 vl.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Reviewed-by on v1 1/1
#2 lore raw
In reply to Markus Armbruster
Quoted 9 lines · Markus Armbruster

machine_set_property() replaces '_' by '-' in the property name. Except it fails to replace an initial '_'. Screwed up in commit b0ddb8b. Reproducer: "-M pc,__foo_bar=true" produces "Property '._-foo-bar' not found".

Error messages using a mangled name rather than the name the user actually wrote is user-hostile, but that's a different topic.

I suggest we follow the same approach we used in the x86 CPU
code: instead of requiring a special parser that magically translate strings, just add property aliases for the old names that contained "_". It would fix the user-hostile error messages as well.

Quoted 33 lines
---
 vl.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
vl.c +4 -5
index c657acd..1c0b0ba 100644
@@ -2804,17 +2804,16 @@ static int machine_set_property(void *opaque,
 {
     Object *obj = OBJECT(opaque);
     Error *local_err = NULL;
-    char *c, *qom_name;
+    char *p, *qom_name;
 
     if (strcmp(name, "type") == 0) {
         return 0;
     }
 
     qom_name = g_strdup(name);
-    c = qom_name;
-    while (*c++) {
-        if (*c == '_') {
-            *c = '-';
+    for (p = qom_name; *p; p++) {
+        if (*p == '_') {
+            *p = '-';
         }
     }
 
Signature · 1 line
2.5.5
Signature · 1 line
Eduardo
#3 lore raw
Quoted 11 lines · Eduardo Habkost
Quoted 9 lines · Markus Armbruster

machine_set_property() replaces '_' by '-' in the property name. Except it fails to replace an initial '_'. Screwed up in commit b0ddb8b. Reproducer: "-M pc,__foo_bar=true" produces "Property '._-foo-bar' not found".

Error messages using a mangled name rather than the name the user actually wrote is user-hostile, but that's a different topic.

Quoted 7 lines

I suggest we follow the same approach we used in the x86 CPU
code: instead of requiring a special parser that magically translate strings, just add property aliases for the old names that contained "_". It would fix the user-hostile error messages as well.

Adding the aliases is slightly annoying, but it's probably the easiest way to get decent error messages. How can we ensure no new alias-requiring names get added?

#4 lore raw
Quoted 15 lines · Markus Armbruster
Quoted 13 lines · Eduardo Habkost
Quoted 9 lines · Markus Armbruster

machine_set_property() replaces '_' by '-' in the property name. Except it fails to replace an initial '_'. Screwed up in commit b0ddb8b. Reproducer: "-M pc,__foo_bar=true" produces "Property '._-foo-bar' not found".

Error messages using a mangled name rather than the name the user actually wrote is user-hostile, but that's a different topic.

Quoted 8 lines
Quoted 5 lines

I suggest we follow the same approach we used in the x86 CPU
code: instead of requiring a special parser that magically translate strings, just add property aliases for the old names that contained "_". It would fix the user-hostile error messages as well.

Adding the aliases is slightly annoying, but it's probably the easiest way to get decent error messages.

I started working on it, but then I noticed I had do check for "_" in all TYPE_MACHINE subclasses and it would take more time than I expected. Then I put it at the end of my queue and went work on something else.

Quoted 1 line

How can we ensure no new alias-requiring names get added?

Being a style issue, maybe checkpatch.pl could detect some cases. It's not different from the other QOM classes.

Signature · 1 line
Eduardo
#5 lore raw
Quoted 30 lines · Eduardo Habkost
Quoted 15 lines · Markus Armbruster
Quoted 13 lines · Eduardo Habkost
Quoted 9 lines · Markus Armbruster

machine_set_property() replaces '_' by '-' in the property name. Except it fails to replace an initial '_'. Screwed up in commit b0ddb8b. Reproducer: "-M pc,__foo_bar=true" produces "Property '._-foo-bar' not found".

Error messages using a mangled name rather than the name the user actually wrote is user-hostile, but that's a different topic.

Quoted 8 lines
Quoted 5 lines

I suggest we follow the same approach we used in the x86 CPU
code: instead of requiring a special parser that magically translate strings, just add property aliases for the old names that contained "_". It would fix the user-hostile error messages as well.

Adding the aliases is slightly annoying, but it's probably the easiest way to get decent error messages.

I started working on it, but then I noticed I had do check for "_" in all TYPE_MACHINE subclasses and it would take more time than I expected. Then I put it at the end of my queue and went work on something else.

Quoted 4 lines
Quoted 1 line

How can we ensure no new alias-requiring names get added?

Being a style issue, maybe checkpatch.pl could detect some cases. It's not different from the other QOM classes.

Can we adopt the rule for all of QOM, and enforce it right when properties get added? Or at some other suitable time?

#6 lore raw
Quoted 32 lines · Markus Armbruster
Quoted 30 lines · Eduardo Habkost
Quoted 15 lines · Markus Armbruster
Quoted 13 lines · Eduardo Habkost
Quoted 9 lines · Markus Armbruster

machine_set_property() replaces '_' by '-' in the property name. Except it fails to replace an initial '_'. Screwed up in commit b0ddb8b. Reproducer: "-M pc,__foo_bar=true" produces "Property '._-foo-bar' not found".

Error messages using a mangled name rather than the name the user actually wrote is user-hostile, but that's a different topic.

Quoted 8 lines
Quoted 5 lines

I suggest we follow the same approach we used in the x86 CPU
code: instead of requiring a special parser that magically translate strings, just add property aliases for the old names that contained "_". It would fix the user-hostile error messages as well.

Adding the aliases is slightly annoying, but it's probably the easiest way to get decent error messages.

I started working on it, but then I noticed I had do check for "_" in all TYPE_MACHINE subclasses and it would take more time than I expected. Then I put it at the end of my queue and went work on something else.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

How can we ensure no new alias-requiring names get added?

Being a style issue, maybe checkpatch.pl could detect some cases. It's not different from the other QOM classes.

Can we adopt the rule for all of QOM, and enforce it right when properties get added? Or at some other suitable time?

You mean, at runtime? We could, but if there are existing properties that would fail the test we need to fix them first.

Signature · 1 line
Eduardo
#7 lore raw
In reply to Markus Armbruster
Quoted 9 lines · Markus Armbruster

machine_set_property() replaces '_' by '-' in the property name. Except it fails to replace an initial '_'. Screwed up in commit b0ddb8b. Reproducer: "-M pc,__foo_bar=true" produces "Property '._-foo-bar' not found".

Error messages using a mangled name rather than the name the user actually wrote is user-hostile, but that's a different topic.

Applied to machine-next. Thanks.

Signature · 1 line
Eduardo