From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Masami Hiramatsu <mhiramat@kernel.org>,
Tom Zanussi <tom.zanussi@linux.intel.com>
Subject: [for-linus][PATCH 15/15] bootconfig: Add append value operator support
Date: Mon, 24 Feb 2020 12:20:37 -0500 [thread overview]
Message-ID: <20200224172118.216494360@goodmis.org> (raw)
In-Reply-To: 20200224172022.330525468@goodmis.org
From: Masami Hiramatsu <mhiramat@kernel.org>
Add append value operator "+=" support to bootconfig syntax.
With this operator, user can add new value to the key as
an entry of array instead of overwriting.
For example,
foo = bar
...
foo += baz
Then the key "foo" has "bar" and "baz" values as an array.
Link: http://lkml.kernel.org/r/158227283195.12842.8310503105963275584.stgit@devnote2
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
Documentation/admin-guide/bootconfig.rst | 10 +++++++++-
lib/bootconfig.c | 15 +++++++++++----
tools/bootconfig/test-bootconfig.sh | 16 ++++++++++++++--
3 files changed, 34 insertions(+), 7 deletions(-)
diff --git a/Documentation/admin-guide/bootconfig.rst b/Documentation/admin-guide/bootconfig.rst
index 57119fb69d36..cf2edcd09183 100644
--- a/Documentation/admin-guide/bootconfig.rst
+++ b/Documentation/admin-guide/bootconfig.rst
@@ -71,7 +71,15 @@ For example,::
foo = bar, baz
foo = qux # !ERROR! we can not re-define same key
-Also, a sub-key and a value can not co-exist under a parent key.
+If you want to append the value to existing key as an array member,
+you can use ``+=`` operator. For example::
+
+ foo = bar, baz
+ foo += qux
+
+In this case, the key ``foo`` has ``bar``, ``baz`` and ``qux``.
+
+However, a sub-key and a value can not co-exist under a parent key.
For example, following config is NOT allowed.::
foo = value1
diff --git a/lib/bootconfig.c b/lib/bootconfig.c
index 2ef304db31f2..ec3ce7fd299f 100644
--- a/lib/bootconfig.c
+++ b/lib/bootconfig.c
@@ -578,7 +578,7 @@ static int __init __xbc_parse_keys(char *k)
return __xbc_add_key(k);
}
-static int __init xbc_parse_kv(char **k, char *v)
+static int __init xbc_parse_kv(char **k, char *v, int op)
{
struct xbc_node *prev_parent = last_parent;
struct xbc_node *child;
@@ -593,7 +593,7 @@ static int __init xbc_parse_kv(char **k, char *v)
if (child) {
if (xbc_node_is_key(child))
return xbc_parse_error("Value is mixed with subkey", v);
- else
+ else if (op == '=')
return xbc_parse_error("Value is redefined", v);
}
@@ -774,7 +774,7 @@ int __init xbc_init(char *buf)
p = buf;
do {
- q = strpbrk(p, "{}=;\n#");
+ q = strpbrk(p, "{}=+;\n#");
if (!q) {
p = skip_spaces(p);
if (*p != '\0')
@@ -785,8 +785,15 @@ int __init xbc_init(char *buf)
c = *q;
*q++ = '\0';
switch (c) {
+ case '+':
+ if (*q++ != '=') {
+ ret = xbc_parse_error("Wrong '+' operator",
+ q - 2);
+ break;
+ }
+ /* Fall through */
case '=':
- ret = xbc_parse_kv(&p, q);
+ ret = xbc_parse_kv(&p, q, c);
break;
case '{':
ret = xbc_open_brace(&p, q);
diff --git a/tools/bootconfig/test-bootconfig.sh b/tools/bootconfig/test-bootconfig.sh
index adafb7c50940..1411f4c3454f 100755
--- a/tools/bootconfig/test-bootconfig.sh
+++ b/tools/bootconfig/test-bootconfig.sh
@@ -9,7 +9,7 @@ TEMPCONF=`mktemp temp-XXXX.bconf`
NG=0
cleanup() {
- rm -f $INITRD $TEMPCONF
+ rm -f $INITRD $TEMPCONF $OUTFILE
exit $NG
}
@@ -71,7 +71,6 @@ printf " \0\0\0 \0\0\0" >> $INITRD
$BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1
xfail grep -i "failed" $OUTFILE
xfail grep -i "error" $OUTFILE
-rm $OUTFILE
echo "Max node number check"
@@ -96,6 +95,19 @@ truncate -s 32764 $TEMPCONF
echo "\"" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0')
xpass $BOOTCONF -a $TEMPCONF $INITRD
+echo "Adding same-key values"
+cat > $TEMPCONF << EOF
+key = bar, baz
+key += qux
+EOF
+echo > $INITRD
+
+xpass $BOOTCONF -a $TEMPCONF $INITRD
+$BOOTCONF $INITRD > $OUTFILE
+xpass grep -q "bar" $OUTFILE
+xpass grep -q "baz" $OUTFILE
+xpass grep -q "qux" $OUTFILE
+
echo "=== expected failure cases ==="
for i in samples/bad-* ; do
xfail $BOOTCONF -a $i $INITRD
--
2.25.0
prev parent reply other threads:[~2020-02-24 17:21 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-24 17:20 [for-linus][PATCH 00/15] tracing: Updates coming for 5.6 rc release Steven Rostedt
2020-02-24 17:20 ` [for-linus][PATCH 01/15] tracing: Make sure synth_event_trace() example always uses u64 Steven Rostedt
2020-02-24 17:20 ` [for-linus][PATCH 02/15] tracing: Make synth_event trace functions endian-correct Steven Rostedt
2020-02-24 17:20 ` [for-linus][PATCH 03/15] tracing: Check that number of vals matches number of synth event fields Steven Rostedt
2020-02-24 17:20 ` [for-linus][PATCH 04/15] tracing: Fix number printing bug in print_synth_event() Steven Rostedt
2020-02-24 17:20 ` [for-linus][PATCH 05/15] tracing: Have synthetic event test use raw_smp_processor_id() Steven Rostedt
2020-02-24 17:20 ` [for-linus][PATCH 06/15] tracing: Disable trace_printk() on post poned tests Steven Rostedt
2020-02-24 17:20 ` [for-linus][PATCH 07/15] bootconfig: Mark boot_config_checksum() static Steven Rostedt
2020-02-24 17:20 ` [for-linus][PATCH 08/15] tracing: Clear trace_state when starting trace Steven Rostedt
2020-02-24 17:20 ` [for-linus][PATCH 09/15] bootconfig: Set CONFIG_BOOT_CONFIG=n by default Steven Rostedt
2020-02-24 17:20 ` [for-linus][PATCH 10/15] bootconfig: Add bootconfig magic word for indicating bootconfig explicitly Steven Rostedt
2020-02-24 17:20 ` [for-linus][PATCH 11/15] tools/bootconfig: Remove unneeded error message silencer Steven Rostedt
2020-02-24 17:20 ` [for-linus][PATCH 12/15] bootconfig: Reject subkey and value on same parent key Steven Rostedt
2020-02-24 17:20 ` [for-linus][PATCH 13/15] bootconfig: Print array as multiple commands for legacy command line Steven Rostedt
2020-02-24 17:20 ` [for-linus][PATCH 14/15] bootconfig: Prohibit re-defining value on same key Steven Rostedt
2020-02-24 17:20 ` Steven Rostedt [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200224172118.216494360@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mhiramat@kernel.org \
--cc=mingo@kernel.org \
--cc=tom.zanussi@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.