rewamp/simplify option parsing
PATCH 1/1 rewamp/simplify option parsing
Main change is to allow get_opt_name() to accept a set of delimiters (string) instead of a single delimiter (char). This way it is easier to search for the next (sub)option in an option string, so other code using get_opt_name() can be simplified.
---
This is an old patch (from Jun 2013) which was sitting in my local git repository since that. I rebased it to current master (with 2 trivial conflicts resolved).
FWIW.
include/qemu/option.h | 3 +- util/qemu-option.c | 136 +++++++++++++++++++++++-------------------------- vl.c | 4 +- 3 files changed, 67 insertions(+), 76 deletions(-)
include/qemu/option.h +2 -1
@@ -50,7 +50,8 @@ typedef struct QEMUOptionParameter { } QEMUOptionParameter; -const char *get_opt_name (char *buf,int buf_size,const char *p,char delim); +const char *get_opt_name (char *buf,int buf_size, +const char *p,const char *delim);const char *get_opt_value (char *buf,int buf_size,const char *p);int get_next_param_value (char *buf,int buf_size,const char *tag,const char **pstr);
util/qemu-option.c +63 -73
198 lines not on this page · raw message
vl.c +2 -2
@@ -1315,7 +1315,7 @@ static void numa_add(const char *optarg)char *endptr;unsigned long long nodenr; - optarg =get_opt_name (option,128 , optarg,',' ); + optarg =get_opt_name (option,sizeof (option), optarg,"," );if (*optarg ==',' ) { optarg++; }
@@ -2757,7 +2757,7 @@ static int configure_accelerator(MachineClass *mc)if (*p ==':' ) { p++; } - p =get_opt_name (buf,sizeof (buf), p,':' ); + p =get_opt_name (buf,sizeof (buf), p,":" );for (i =0 ; i <ARRAY_SIZE (accel_list); i++) {if (strcmp (accel_list[i].opt_name, buf) ==0 ) {if (!accel_list[i].available ()) {
Signature · 1 line
1.7.10.4
On 05/12/2014 01:55 AM, Michael Tokarev wrote:
s/rewamp/revamp/ in the subject
Quoted 36 lines
Main change is to allow
get_opt_name()to accept a set of delimiters (string) instead of a single delimiter (char). This way it is easier to search for the next (sub)option in an option string, so other code usingget_opt_name()can be simplified.Signed-off-by Michael Tokarev <[email protected]>---
This is an old patch (from Jun 2013) which was sitting in my local git repository since that. I rebased it to current master (with 2 trivial conflicts resolved).FWIW.
include/qemu/option.h | 3 +- util/qemu-option.c | 136 +++++++++++++++++++++++-------------------------- vl.c | 4 +- 3 files changed, 67 insertions(+), 76 deletions(-)util/qemu-option.c +3
-8@@ -97,24 +95,27 @@ int get_next_param_value(char *buf, int buf_size, p = *pstr;for (;;) { - p =get_opt_name (option,sizeof (option), p,'=' ); -if (*p !='=' ) -break ; - p++; -if (!strcmp (tag, option)) { - *pstr =get_opt_value (buf, buf_size, p); -if (**pstr ==',' ) { - (*pstr)++; +if (*p =='\0' ) { +return 0 ; + }
util/qemu-option.c int get_next_param_value(char *buf, int buf_size, · line 109
Quoted 10 lines
util/qemu-option.c +8
-1+ p =get_opt_name (option,sizeof (option), p,"=," ); +if (strcmp (tag, option) ==0 ) { +if (*p =='=' ) { + p =get_opt_value (buf, buf_size, p +1 ); + }else { + buf[0 ] ='\0' ; } -return strlen (buf); + *pstr = *p ==',' ? p +1 : p; +return 1 ;
Does this botch handling of ',,' escaping that allows literal commas as part of an option value? I suspect there may be some corner cases you are altering. Based just on a quick read of 'qemu-kvm -help', I see:
-name string1[,process=string2][,debug-threads=on|off]
Which, if I'm interpreting correctly, means that pre-patch I can do:
qemu-kvm -name foo,,bar /dev/null
as a way to start a (pretty pointless) machine with the window title of "QEMU (foo,bar)". Reading the source code, I also found the implicit name of string1:
qemu-kvm -name guest=debug-threads= /dev/null
creates the window title "QEMU (debug-threads=)", and:
qemu-kvm -name debug-threads,, /dev/null
creates the window title "QEMU (debug-threads,)". That is, I have a way of specifying ANY name, including trailing '=' or ',', for my guest.
I did not apply your patch, but off-hand, I'm guessing that your patch breaks at least one, if not multiple, of these cases. We need unit tests in place first.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org