Skip to contentSkip to conversation

parse_bool fixes

PATCH In review Don Slutz 4 participants 14 messages Jul 29, 2014 – Aug 4, 2014

lore
Share & tools
lore

Don Slutz

author
#0 lore raw

v2 cover parse_bool fixes

Changes v1 to v2:

Jan Beulich, Keir Fraser, Andrew Cooper:
v1 #1 "cmdline_parse: Also pass bool_assert to OPT_CUSTOM..."
NAK (several ways of saying this) so drop this pacth.

As suggested by Jan Beulich:
v2 #1 "cmdline_parse: Convert no- prefix into =no for OPT_CUSTOM"

V2 #2 "xen/console: Better handing of console_timestamps as a boolean_param"
Drop stacked inversions part of patch.

---

console_timestamps use to be a boolean_param. Now it is more. This patch series is to make old xen command lines with console_timestamps in them continue to work the way they did at 4.4.

Don Slutz (2):
cmdline_parse: Convert no- prefix into =no for OPT_CUSTOM xen/console: Better handing of console_timestamps as a boolean_param

 xen/common/kernel.c        | 15 ++++++++++++++-
 xen/drivers/char/console.c | 26 ++++++++++++++++++--------
 2 files changed, 32 insertions(+), 9 deletions(-)
Signature · 1 line
1.8.4
author
#1 lore raw

PATCH v2 1/2 cmdline_parse: Convert no- prefix into =no for OPT_CUSTOM

This allows converting OPT_BOOL into OPT_CUSTOM and still do what is expected.

Note: if both no- and = provided, pass provided = if not a zero length string. Also log a warning about this.

---
 xen/common/kernel.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
xen/common/kernel.c +14 -1
index 7e83353..9857159 100644
@@ -135,7 +135,20 @@ void __init cmdline_parse(const char *cmdline)
                     parse_size_and_unit(optval, NULL));
                 break;
             case OPT_CUSTOM:
-                ((void (*)(const char *))param->var)(optval);
+                if ( !bool_assert )
+                {
+                    if ( *optval )
+                    {
+                        printk(XENLOG_WARNING
+                               "Warning: ignored no- prefix for %s=%s\n",
+                               param->name, optval);
+                        ((void (*)(const char *))param->var)(optval);
+                    }
+                    else
+                        ((void (*)(const char *))param->var)("no");
+                }
+                else
+                    ((void (*)(const char *))param->var)(optval);
                 break;
             default:
                 BUG();
Signature · 1 line
1.8.4
#2 lore raw

Re: [PATCH v2 1/2] cmdline_parse: Convert no- prefix into =no for OPT_CUSTOM

Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 29.07.14 at 21:57, <[email protected]> wrote:

This allows converting OPT_BOOL into OPT_CUSTOM and still do what is expected.

Note: if both no- and = provided, pass provided = if not a zero length string. Also log a warning about this.

---
 xen/common/kernel.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)
xen/common/kernel.c +0 -0
index 7e83353..9857159 100644
@@ -135,7 +135,20 @@ void __init cmdline_parse(const char *cmdline)
                     parse_size_and_unit(optval, NULL));

xen/common/kernel.c void __init cmdline_parse(const char *cmdline) · line 144

Quoted 10 lines
xen/common/kernel.c +7 -1
                 break;
             case OPT_CUSTOM:
-                ((void (*)(const char *))param->var)(optval);
+                if ( !bool_assert )
+                {
+                    if ( *optval )
+                    {
+                        printk(XENLOG_WARNING
+                               "Warning: ignored no- prefix for %s=%s\n",
+                               param->name, optval);

Log messages printed before the consoles get initialized are of limited value (they would only show up in "xl dmesg" or equivalent output). Therefore I'm not really certain this is worthwhile.

xen/common/kernel.c void __init cmdline_parse(const char *cmdline) · line 151

Quoted 7 lines
xen/common/kernel.c +7 -0
+                        ((void (*)(const char *))param->var)(optval);
+                    }
+                    else
+                        ((void (*)(const char *))param->var)("no");
+                }
+                else
+                    ((void (*)(const char *))param->var)(optval);

Considering this repeated cast I'd prefer coding this quite differently, not the least because you also can't pass a literal "no" to the parsing functions (as they're permitted to alter the string), and at once also ignoring bogus "no-<name>=<value>" options instead of trying to assign a (perhaps unexpected) meaning:

convert "no-" command line option prefix into "=no" for OPT_CUSTOM

... to allow restoring/retaining previous behavior for options getting converted from boolean to custom.

xen/common/kernel.c +7 -0
@@ -135,6 +135,13 @@ void __init cmdline_parse(const char *cm
                     parse_size_and_unit(optval, NULL));
                 break;
             case OPT_CUSTOM:
+                if ( !bool_assert )
+                {
+                    if ( *optval )
+                        break;
+                    safe_strcpy(opt, "no");
+                    optval = opt;
+                }
                 ((void (*)(const char *))param->var)(optval);
                 break;
             default:

convert "no-" command line option prefix into "=no" for OPT_CUSTOM

... to allow restoring/retaining previous behavior for options getting converted from boolean to custom.

xen/common/kernel.c +7 -0
@@ -135,6 +135,13 @@ void __init cmdline_parse(const char *cm
                     parse_size_and_unit(optval, NULL));
                 break;
             case OPT_CUSTOM:
+                if ( !bool_assert )
+                {
+                    if ( *optval )
+                        break;
+                    safe_strcpy(opt, "no");
+                    optval = opt;
+                }
                 ((void (*)(const char *))param->var)(optval);
                 break;
             default:

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#3 lore raw

Re: [PATCH v2 1/2] cmdline_parse: Convert no- prefix into =no for OPT_CUSTOM

Quoted 23 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 29.07.14 at 21:57, <[email protected]> wrote:

This allows converting OPT_BOOL into OPT_CUSTOM and still do what is expected.

Note: if both no- and = provided, pass provided = if not a zero length string. Also log a warning about this.

---
  xen/common/kernel.c | 15 ++++++++++++++-
  1 file changed, 14 insertions(+), 1 deletion(-)
xen/common/kernel.c +2 -1
index 7e83353..9857159 100644
@@ -135,7 +135,20 @@ void __init cmdline_parse(const char *cmdline)
                      parse_size_and_unit(optval, NULL));
                  break;
              case OPT_CUSTOM:
-                ((void (*)(const char *))param->var)(optval);
+                if ( !bool_assert )
+                {
Quoted 8 lines

xen/common/kernel.c void __init cmdline_parse(const char *cmdline) · line 144

Quoted 5 lines
xen/common/kernel.c +5 -0
+                    if ( *optval )
+                    {
+                        printk(XENLOG_WARNING
+                               "Warning: ignored no- prefix for %s=%s\n",
+                               param->name, optval);

Log messages printed before the consoles get initialized are of limited value (they would only show up in "xl dmesg" or equivalent output). Therefore I'm not really certain this is worthwhile.

I am happy to go either way.

Quoted 30 lines

xen/common/kernel.c void __init cmdline_parse(const char *cmdline) · line 151

Quoted 7 lines
xen/common/kernel.c +7 -0
+                        ((void (*)(const char *))param->var)(optval);
+                    }
+                    else
+                        ((void (*)(const char *))param->var)("no");
+                }
+                else
+                    ((void (*)(const char *))param->var)(optval);

Considering this repeated cast I'd prefer coding this quite differently, not the least because you also can't pass a literal "no" to the parsing functions (as they're permitted to alter the string), and at once also ignoring bogus "no-<name>=<value>" options instead of trying to assign a (perhaps unexpected) meaning:

convert "no-" command line option prefix into "=no" for OPT_CUSTOM

... to allow restoring/retaining previous behavior for options getting converted from boolean to custom.

xen/common/kernel.c +0 -0
@@ -135,6 +135,13 @@ void __init cmdline_parse(const char *cm
                      parse_size_and_unit(optval, NULL));
                  break;
              case OPT_CUSTOM:

xen/common/kernel.c void __init cmdline_parse(const char *cm · line 147

Quoted 10 lines
xen/common/kernel.c +7 -0
+                if ( !bool_assert )
+                {
+                    if ( *optval )
+                        break;
+                    safe_strcpy(opt, "no");
+                    optval = opt;
+                }
                  ((void (*)(const char *))param->var)(optval);
                  break;
              default:

Without the log message, I think it might help to include the part about ignoring bogus "no-<name>=<value>"... aka stacked inversions in the commit message. This is because boolean options do still support stacked inversions, which is valid under the statement "Explicitly specifying any value other than those listed above is undefined, as is stacking a no- prefix with an explicit value."

I am happy with the actual code change.

-Don Slutz

#4 lore raw

Re: [PATCH v2 1/2] cmdline_parse: Convert no- prefix into =no for OPT_CUSTOM

Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 31.07.14 at 02:59, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich
xen/common/kernel.c +7 -0
@@ -135,6 +135,13 @@ void __init cmdline_parse(const char *cm
                      parse_size_and_unit(optval, NULL));
                  break;
              case OPT_CUSTOM:
+                if ( !bool_assert )
+                {
+                    if ( *optval )
+                        break;
+                    safe_strcpy(opt, "no");
+                    optval = opt;
+                }
                  ((void (*)(const char *))param->var)(optval);
                  break;
              default:
Quoted 8 lines
Quoted 1 line

Without the log message, I think it might help to include the part about ignoring bogus "no-<name>=<value>"... aka stacked inversions in the commit message. This is because boolean options do still support stacked inversions, which is valid under the statement "Explicitly specifying any value other than those listed above is undefined, as is stacking a no- prefix with an explicit value."

I added:

Obviously that'll work only when no
other argument was specified for the option. Command line settings of the form "no-<name>=<value>" will now be ignored as ambiguous (rather than being interpreted as "<name>=<value>", i.e. ignoring the "no-" prefix).

Jan

author
#5 lore raw

Re: [PATCH v2 1/2] cmdline_parse: Convert no- prefix into =no for OPT_CUSTOM

Quoted 28 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 31.07.14 at 02:59, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
xen/common/kernel.c +7 -0
@@ -135,6 +135,13 @@ void __init cmdline_parse(const char *cm
                       parse_size_and_unit(optval, NULL));
                   break;
               case OPT_CUSTOM:
+                if ( !bool_assert )
+                {
+                    if ( *optval )
+                        break;
+                    safe_strcpy(opt, "no");
+                    optval = opt;
+                }
                   ((void (*)(const char *))param->var)(optval);
                   break;
               default:
Quoted 8 lines
Quoted 2 lines

Without the log message, I think it might help to include the part about ignoring bogus "no-<name>=<value>"... aka stacked inversions in the commit message. This is because boolean options do still support stacked inversions, which is valid under the statement "Explicitly specifying any value other than those listed above is undefined, as is stacking a no- prefix with an explicit value."

I added:

Quoted 8 lines

Obviously that'll work only when no
other argument was specified for the option. Command line settings of the form "no-<name>=<value>" will now be ignored as ambiguous (rather than being interpreted as "<name>=<value>", i.e. ignoring the "no-" prefix).

Jan

Looks good to me.
-Don Slutz

Acked-by
#6 lore raw

Re: [PATCH v2 1/2] cmdline_parse: Convert no- prefix into =no for OPT_CUSTOM

In reply to Jan Beulich
Quoted 11 lines · Jan Beulich

convert "no-" command line option prefix into "=no" for OPT_CUSTOM

... to allow restoring/retaining previous behavior for options getting converted from boolean to custom.

xen/common/kernel.c void __init cmdline_parse(const char *cm · line 141

Quoted 7 lines
xen/common/kernel.c +4 -0
@@ -135,6 +135,13 @@ void __init cmdline_parse(const char *cm
                     parse_size_and_unit(optval, NULL));
                 break;
             case OPT_CUSTOM:
+                if ( !bool_assert )
+                {
+                    if ( *optval )
+                        break;

I think this results in silently ignoring mad combinations, rather than reporting them as an error. If that was what you intended then:

#7 lore raw

Re: [PATCH v2 1/2] cmdline_parse: Convert no- prefix into =no for OPT_CUSTOM

Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 04.08.14 at 12:58, <[email protected]> wrote:
Quoted 8 lines · Jan Beulich

convert "no-" command line option prefix into "=no" for OPT_CUSTOM

... to allow restoring/retaining previous behavior for options getting converted from boolean to custom.

Quoted 13 lines

xen/common/kernel.c void __init cmdline_parse(const char *cm · line 141

Quoted 10 lines
xen/common/kernel.c +4 -0
@@ -135,6 +135,13 @@ void __init cmdline_parse(const char *cm
                     parse_size_and_unit(optval, NULL));
                 break;
             case OPT_CUSTOM:
+                if ( !bool_assert )
+                {
+                    if ( *optval )
+                        break;

I think this results in silently ignoring mad combinations, rather than reporting them as an error. If that was what you intended then:

Yes, it was (mentioned in the thread that led here): The resulting message is only of limited use, as it wouldn't possibly make it to the (serial) console.

Quoted 1 line

Thanks, Jan

author
#8 lore raw

PATCH v2 2/2 xen/console: Better handing of console_timestamps as a boolean_param

In reply to Don Slutz

In order to handle all the old ways, change to use parse_bool().

---
v2:
Drop stacked inversions part of patch.

 xen/drivers/char/console.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)
xen/drivers/char/console.c +18 -8
index 2f6c090..4f473e3 100644
@@ -559,15 +559,25 @@ static int printk_prefix_check(char *p, char **pp)
 
 static void __init parse_console_timestamps(char *s)
 {
-    if ( *s == '\0' || /* Compat for old booleanparam() */
-         !strcmp(s, "date") )
-        opt_con_timestamp_mode = TSM_DATE;
-    else if ( !strcmp(s, "datems") )
-        opt_con_timestamp_mode = TSM_DATE_MS;
-    else if ( !strcmp(s, "boot") )
-        opt_con_timestamp_mode = TSM_BOOT;
-    else if ( !strcmp(s, "none") )
+    switch ( parse_bool(s) )
+    {
+    case 0:
         opt_con_timestamp_mode = TSM_NONE;
+        break;
+    case 1:
+        opt_con_timestamp_mode = TSM_DATE;
+        break;
+    default:
+        if ( *s == '\0' || /* Compat for old booleanparam() */
+             !strcmp(s, "date") )
+            opt_con_timestamp_mode = TSM_DATE;
+        else if ( !strcmp(s, "datems") )
+            opt_con_timestamp_mode = TSM_DATE_MS;
+        else if ( !strcmp(s, "boot") )
+            opt_con_timestamp_mode = TSM_BOOT;
+        else if ( !strcmp(s, "none") )
+            opt_con_timestamp_mode = TSM_NONE;
+    }
 }
 
 static void printk_start_of_line(const char *prefix)
Signature · 1 line
1.8.4
#9 lore raw

Re: [PATCH v2 2/2] xen/console: Better handing of console_timestamps as a boolean_param

Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 29.07.14 at 21:57, <[email protected]> wrote:
xen/drivers/char/console.c +0 -6
@@ -559,15 +559,25 @@ static int printk_prefix_check(char *p, char **pp)
 
 static void __init parse_console_timestamps(char *s)
 {
-    if ( *s == '\0' || /* Compat for old booleanparam() */
-         !strcmp(s, "date") )
-        opt_con_timestamp_mode = TSM_DATE;
-    else if ( !strcmp(s, "datems") )
-        opt_con_timestamp_mode = TSM_DATE_MS;
-    else if ( !strcmp(s, "boot") )

xen/drivers/char/console.c static int printk_prefix_check(char *p, char **pp) · line 569

Quoted 10 lines
xen/drivers/char/console.c +7 -2
-        opt_con_timestamp_mode = TSM_BOOT;
-    else if ( !strcmp(s, "none") )
+    switch ( parse_bool(s) )
+    {
+    case 0:
         opt_con_timestamp_mode = TSM_NONE;
+        break;
+    case 1:
+        opt_con_timestamp_mode = TSM_DATE;
+        break;

The patch could have been quite a bit smaller if you used "return" instead of "break" in the two above cases.

Jan

Quoted 16 lines
xen/drivers/char/console.c +11 -0
+    default:
+        if ( *s == '\0' || /* Compat for old booleanparam() */
+             !strcmp(s, "date") )
+            opt_con_timestamp_mode = TSM_DATE;
+        else if ( !strcmp(s, "datems") )
+            opt_con_timestamp_mode = TSM_DATE_MS;
+        else if ( !strcmp(s, "boot") )
+            opt_con_timestamp_mode = TSM_BOOT;
+        else if ( !strcmp(s, "none") )
+            opt_con_timestamp_mode = TSM_NONE;
+    }
 }
 
 static void printk_start_of_line(const char *prefix)
Signature · 1 line
1.8.4
Reviewed-by Andrew Cooper Reviewed-by Andrew Cooper
#10 lore raw

Re: [PATCH v2 2/2] xen/console: Better handing of console_timestamps as a boolean_param

Quoted 19 lines
Quoted 19 lines
Quoted 2 lines · On 30.07.14 at 10:01, <[email protected]> wrote:
Quoted 1 line · On 29.07.14 at 21:57, <[email protected]> wrote:
xen/drivers/char/console.c +3 -8
@@ -559,15 +559,25 @@ static int printk_prefix_check(char *p, char **pp)
 
 static void __init parse_console_timestamps(char *s)
 {
-    if ( *s == '\0' || /* Compat for old booleanparam() */
-         !strcmp(s, "date") )
-        opt_con_timestamp_mode = TSM_DATE;
-    else if ( !strcmp(s, "datems") )
-        opt_con_timestamp_mode = TSM_DATE_MS;
-    else if ( !strcmp(s, "boot") )
-        opt_con_timestamp_mode = TSM_BOOT;
-    else if ( !strcmp(s, "none") )
+    switch ( parse_bool(s) )
+    {
+    case 0:
Quoted 8 lines

xen/drivers/char/console.c static int printk_prefix_check(char *p, char **pp) · line 569

Quoted 5 lines
xen/drivers/char/console.c +4 -0
         opt_con_timestamp_mode = TSM_NONE;
+        break;
+    case 1:
+        opt_con_timestamp_mode = TSM_DATE;
+        break;

The patch could have been quite a bit smaller if you used "return" instead of "break" in the two above cases.

I.e.

console: better handing of console_timestamps as a boolean_param

In order to handle all the old ways, change to use parse_bool().

Restructure code to limit churn.

xen/drivers/char/console.c +9 -0
@@ -559,6 +559,15 @@ static int printk_prefix_check(char *p, 
 
 static void __init parse_console_timestamps(char *s)
 {
+    switch ( parse_bool(s) )
+    {
+    case 0:
+        opt_con_timestamp_mode = TSM_NONE;
+        return;
+    case 1:
+        opt_con_timestamp_mode = TSM_DATE;
+        return;
+    }
     if ( *s == '\0' || /* Compat for old booleanparam() */
          !strcmp(s, "date") )
         opt_con_timestamp_mode = TSM_DATE;

console: better handing of console_timestamps as a boolean_param

In order to handle all the old ways, change to use parse_bool().

Restructure code to limit churn.

xen/drivers/char/console.c +9 -0
@@ -559,6 +559,15 @@ static int printk_prefix_check(char *p, 
 
 static void __init parse_console_timestamps(char *s)
 {
+    switch ( parse_bool(s) )
+    {
+    case 0:
+        opt_con_timestamp_mode = TSM_NONE;
+        return;
+    case 1:
+        opt_con_timestamp_mode = TSM_DATE;
+        return;
+    }
     if ( *s == '\0' || /* Compat for old booleanparam() */
          !strcmp(s, "date") )
         opt_con_timestamp_mode = TSM_DATE;

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author
#11 lore raw

Re: [PATCH v2 2/2] xen/console: Better handing of console_timestamps as a boolean_param

Quoted 11 lines · Jan Beulich
Quoted 7 lines

xen/drivers/char/console.c

Quoted 4 lines
Quoted 2 lines · On 30.07.14 at 10:01, <[email protected]> wrote:
Quoted 1 line · On 29.07.14 at 21:57, <[email protected]> wrote:
xen/drivers/char/console.c +0 -0

The patch could have been quite a bit smaller if you used "return" instead of "break" in the two above cases.

I.e.

console: better handing of console_timestamps as a boolean_param

Quoted 8 lines

In order to handle all the old ways, change to use parse_bool().

Restructure code to limit churn.

This is fine with me.
-Don Slutz

Quoted 21 lines
xen/drivers/char/console.c +9 -0
@@ -559,6 +559,15 @@ static int printk_prefix_check(char *p,
 
  static void __init parse_console_timestamps(char *s)
  {
+    switch ( parse_bool(s) )
+    {
+    case 0:
+        opt_con_timestamp_mode = TSM_NONE;
+        return;
+    case 1:
+        opt_con_timestamp_mode = TSM_DATE;
+        return;
+    }
      if ( *s == '\0' || /* Compat for old booleanparam() */
           !strcmp(s, "date") )
          opt_con_timestamp_mode = TSM_DATE;
Acked-by
#12 lore raw

Re: [PATCH v2 2/2] xen/console: Better handing of console_timestamps as a boolean_param

In reply to Jan Beulich
Quoted 10 lines · Jan Beulich

console: better handing of console_timestamps as a boolean_param

In order to handle all the old ways, change to use parse_bool().

Restructure code to limit churn.

Ian

#13 lore raw
In reply to Don Slutz
Quoted 1 line · Don Slutz

Changes v1 to v2:

Much better!

Both Reviewed-by: Andrew Cooper <[email protected]>

Quoted 27 lines

Jan Beulich, Keir Fraser, Andrew Cooper:
v1 #1 "cmdline_parse: Also pass bool_assert to OPT_CUSTOM..."
NAK (several ways of saying this) so drop this pacth.

As suggested by Jan Beulich:
v2 #1 "cmdline_parse: Convert no- prefix into =no for OPT_CUSTOM"

V2 #2 "xen/console: Better handing of console_timestamps as a boolean_param"
Drop stacked inversions part of patch.

---

console_timestamps use to be a boolean_param. Now it is more. This patch series is to make old xen command lines with console_timestamps in them continue to work the way they did at 4.4.

Don Slutz (2):
cmdline_parse: Convert no- prefix into =no for OPT_CUSTOM xen/console: Better handing of console_timestamps as a boolean_param

 xen/common/kernel.c        | 15 ++++++++++++++-
 xen/drivers/char/console.c | 26 ++++++++++++++++++--------
 2 files changed, 32 insertions(+), 9 deletions(-)