Commit 5f811c57 authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Steven Rostedt (VMware)

bootconfig: Add append value operator support

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@devnote2Signed-off-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
Signed-off-by: default avatarSteven Rostedt (VMware) <rostedt@goodmis.org>
parent 4e4694d8
...@@ -71,7 +71,15 @@ For example,:: ...@@ -71,7 +71,15 @@ For example,::
foo = bar, baz foo = bar, baz
foo = qux # !ERROR! we can not re-define same key 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.:: For example, following config is NOT allowed.::
foo = value1 foo = value1
......
...@@ -578,7 +578,7 @@ static int __init __xbc_parse_keys(char *k) ...@@ -578,7 +578,7 @@ static int __init __xbc_parse_keys(char *k)
return __xbc_add_key(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 *prev_parent = last_parent;
struct xbc_node *child; struct xbc_node *child;
...@@ -593,7 +593,7 @@ static int __init xbc_parse_kv(char **k, char *v) ...@@ -593,7 +593,7 @@ static int __init xbc_parse_kv(char **k, char *v)
if (child) { if (child) {
if (xbc_node_is_key(child)) if (xbc_node_is_key(child))
return xbc_parse_error("Value is mixed with subkey", v); return xbc_parse_error("Value is mixed with subkey", v);
else else if (op == '=')
return xbc_parse_error("Value is redefined", v); return xbc_parse_error("Value is redefined", v);
} }
...@@ -774,7 +774,7 @@ int __init xbc_init(char *buf) ...@@ -774,7 +774,7 @@ int __init xbc_init(char *buf)
p = buf; p = buf;
do { do {
q = strpbrk(p, "{}=;\n#"); q = strpbrk(p, "{}=+;\n#");
if (!q) { if (!q) {
p = skip_spaces(p); p = skip_spaces(p);
if (*p != '\0') if (*p != '\0')
...@@ -785,8 +785,15 @@ int __init xbc_init(char *buf) ...@@ -785,8 +785,15 @@ int __init xbc_init(char *buf)
c = *q; c = *q;
*q++ = '\0'; *q++ = '\0';
switch (c) { switch (c) {
case '+':
if (*q++ != '=') {
ret = xbc_parse_error("Wrong '+' operator",
q - 2);
break;
}
/* Fall through */
case '=': case '=':
ret = xbc_parse_kv(&p, q); ret = xbc_parse_kv(&p, q, c);
break; break;
case '{': case '{':
ret = xbc_open_brace(&p, q); ret = xbc_open_brace(&p, q);
......
...@@ -9,7 +9,7 @@ TEMPCONF=`mktemp temp-XXXX.bconf` ...@@ -9,7 +9,7 @@ TEMPCONF=`mktemp temp-XXXX.bconf`
NG=0 NG=0
cleanup() { cleanup() {
rm -f $INITRD $TEMPCONF rm -f $INITRD $TEMPCONF $OUTFILE
exit $NG exit $NG
} }
...@@ -71,7 +71,6 @@ printf " \0\0\0 \0\0\0" >> $INITRD ...@@ -71,7 +71,6 @@ printf " \0\0\0 \0\0\0" >> $INITRD
$BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1 $BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1
xfail grep -i "failed" $OUTFILE xfail grep -i "failed" $OUTFILE
xfail grep -i "error" $OUTFILE xfail grep -i "error" $OUTFILE
rm $OUTFILE
echo "Max node number check" echo "Max node number check"
...@@ -96,6 +95,19 @@ truncate -s 32764 $TEMPCONF ...@@ -96,6 +95,19 @@ truncate -s 32764 $TEMPCONF
echo "\"" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0') echo "\"" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0')
xpass $BOOTCONF -a $TEMPCONF $INITRD 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 ===" echo "=== expected failure cases ==="
for i in samples/bad-* ; do for i in samples/bad-* ; do
xfail $BOOTCONF -a $i $INITRD xfail $BOOTCONF -a $i $INITRD
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment