Skip to content

Commit 5f811c5

Browse files
mhiramatrostedt
authored andcommitted
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@devnote2 Signed-off-by: Masami Hiramatsu <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 4e4694d commit 5f811c5

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

Documentation/admin-guide/bootconfig.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,15 @@ For example,::
7171
foo = bar, baz
7272
foo = qux # !ERROR! we can not re-define same key
7373

74-
Also, a sub-key and a value can not co-exist under a parent key.
74+
If you want to append the value to existing key as an array member,
75+
you can use ``+=`` operator. For example::
76+
77+
foo = bar, baz
78+
foo += qux
79+
80+
In this case, the key ``foo`` has ``bar``, ``baz`` and ``qux``.
81+
82+
However, a sub-key and a value can not co-exist under a parent key.
7583
For example, following config is NOT allowed.::
7684

7785
foo = value1

lib/bootconfig.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ static int __init __xbc_parse_keys(char *k)
578578
return __xbc_add_key(k);
579579
}
580580

581-
static int __init xbc_parse_kv(char **k, char *v)
581+
static int __init xbc_parse_kv(char **k, char *v, int op)
582582
{
583583
struct xbc_node *prev_parent = last_parent;
584584
struct xbc_node *child;
@@ -593,7 +593,7 @@ static int __init xbc_parse_kv(char **k, char *v)
593593
if (child) {
594594
if (xbc_node_is_key(child))
595595
return xbc_parse_error("Value is mixed with subkey", v);
596-
else
596+
else if (op == '=')
597597
return xbc_parse_error("Value is redefined", v);
598598
}
599599

@@ -774,7 +774,7 @@ int __init xbc_init(char *buf)
774774

775775
p = buf;
776776
do {
777-
q = strpbrk(p, "{}=;\n#");
777+
q = strpbrk(p, "{}=+;\n#");
778778
if (!q) {
779779
p = skip_spaces(p);
780780
if (*p != '\0')
@@ -785,8 +785,15 @@ int __init xbc_init(char *buf)
785785
c = *q;
786786
*q++ = '\0';
787787
switch (c) {
788+
case '+':
789+
if (*q++ != '=') {
790+
ret = xbc_parse_error("Wrong '+' operator",
791+
q - 2);
792+
break;
793+
}
794+
/* Fall through */
788795
case '=':
789-
ret = xbc_parse_kv(&p, q);
796+
ret = xbc_parse_kv(&p, q, c);
790797
break;
791798
case '{':
792799
ret = xbc_open_brace(&p, q);

tools/bootconfig/test-bootconfig.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ TEMPCONF=`mktemp temp-XXXX.bconf`
99
NG=0
1010

1111
cleanup() {
12-
rm -f $INITRD $TEMPCONF
12+
rm -f $INITRD $TEMPCONF $OUTFILE
1313
exit $NG
1414
}
1515

@@ -71,7 +71,6 @@ printf " \0\0\0 \0\0\0" >> $INITRD
7171
$BOOTCONF -a $TEMPCONF $INITRD > $OUTFILE 2>&1
7272
xfail grep -i "failed" $OUTFILE
7373
xfail grep -i "error" $OUTFILE
74-
rm $OUTFILE
7574

7675
echo "Max node number check"
7776

@@ -96,6 +95,19 @@ truncate -s 32764 $TEMPCONF
9695
echo "\"" >> $TEMPCONF # add 2 bytes + terminal ('\"\n\0')
9796
xpass $BOOTCONF -a $TEMPCONF $INITRD
9897

98+
echo "Adding same-key values"
99+
cat > $TEMPCONF << EOF
100+
key = bar, baz
101+
key += qux
102+
EOF
103+
echo > $INITRD
104+
105+
xpass $BOOTCONF -a $TEMPCONF $INITRD
106+
$BOOTCONF $INITRD > $OUTFILE
107+
xpass grep -q "bar" $OUTFILE
108+
xpass grep -q "baz" $OUTFILE
109+
xpass grep -q "qux" $OUTFILE
110+
99111
echo "=== expected failure cases ==="
100112
for i in samples/bad-* ; do
101113
xfail $BOOTCONF -a $i $INITRD

0 commit comments

Comments
 (0)