machine: Fix replacement of '_' by '-' in machine property names
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
@@ -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
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.
Signed-off-by Markus Armbruster <[email protected]>--- 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
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.
Signed-off-by Markus Armbruster <[email protected]>
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@@ -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
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.
Signed-off-by Markus Armbruster <[email protected]>
Quoted 7 lines
Reviewed-by Eduardo Habkost <[email protected]>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?
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.
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eduardo Habkost <[email protected]>
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
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.
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eduardo Habkost <[email protected]>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_MACHINEsubclasses 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?
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.
Signed-off-by Markus Armbruster <[email protected]>Reviewed-by Eduardo Habkost <[email protected]>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_MACHINEsubclasses 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
Eduardo Habkost
AppliedQuoted 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.
Signed-off-by Markus Armbruster <[email protected]>
Applied to machine-next. Thanks.
Signature · 1 line
Eduardo