init: add version attribute to start nodes

The optional 'version' attribute allows for the forced restart of a
child with an otherwise unmodified start node. The specified value is
also reflected in the state report.
This commit is contained in:
Norman Feske 2017-03-02 14:34:27 +01:00 committed by Christian Helmuth
parent fcf25c22d1
commit 8d4fb288d9
2 changed files with 44 additions and 3 deletions

View File

@ -424,6 +424,12 @@ class Init::Child : Child_policy, Child_service::Wakeup
Reconstructible<Buffered_xml> _start_node;
/*
* Version attribute of the start node, used to force child restarts.
*/
typedef String<80> Version;
Version _version { _start_node->xml().attribute_value("version", Version()) };
Default_route_accessor &_default_route_accessor;
Ram_limit_accessor &_ram_limit_accessor;
@ -816,6 +822,15 @@ class Init::Child : Child_policy, Child_service::Wakeup
Genode::memcmp(start_node.addr(), _start_node->xml().addr(),
start_node.size()) != 0)
{
/*
* Check for a change of the version attribute, force restart
* if the version changed.
*/
if (_version != start_node.attribute_value("version", Version())) {
abandon();
return MAY_HAVE_SIDE_EFFECTS;
}
/*
* Start node changed
*
@ -887,6 +902,9 @@ class Init::Child : Child_policy, Child_service::Wakeup
xml.attribute("name", _unique_name);
xml.attribute("binary", _binary_name);
if (_version.valid())
xml.attribute("version", _version);
if (detail.ids())
xml.attribute("id", _id.value);

View File

@ -203,7 +203,6 @@ append config {
<message string="update child config"/>
<init_config>
<report ids="yes"/>
<parent-provides>
<service name="ROM"/> <service name="RAM"/>
<service name="CPU"/> <service name="PD"/>
@ -218,7 +217,6 @@ append config {
</init_config>
<expect_log string="[init -> application] config 1: Version A"/>
<init_config>
<report ids="yes"/>
<parent-provides>
<service name="ROM"/> <service name="RAM"/>
<service name="CPU"/> <service name="PD"/>
@ -232,6 +230,31 @@ append config {
</start>
</init_config>
<expect_log string="[init -> application] config 2: Version B"/>
<!-- Add 'version' attribute to start node, which should trigger
the restart of the child, printing a version count of 1.
We also validate that the version is reflected in the state
report. -->
<init_config>
<report/>
<parent-provides>
<service name="ROM"/> <service name="RAM"/>
<service name="CPU"/> <service name="PD"/>
<service name="LOG"/>
</parent-provides>
<start name="application" version="X">
<binary name="dummy"/>
<resource name="RAM" quantum="1M"/>
<config version="Version B"/>
<route> <any-service> <parent/> </any-service> </route>
</start>
</init_config>
<expect_log string="[init -> application] config 1: Version B"/>
<sleep ms="150"/>
<expect_init_state>
<node name="child"> <attribute name="version" value="X"/> </node>
</expect_init_state>
<sleep ms="100"/>
@ -261,6 +284,7 @@ append config {
config version (count 2). -->
<init_config>
<report/>
<parent-provides>
<service name="ROM"/> <service name="RAM"/>
<service name="CPU"/> <service name="PD"/>
@ -302,7 +326,6 @@ append config {
</start>
</init_config>
<expect_log string="[init -> test] config 1: binary re-routed to other route"/>
<sleep ms="100"/>
<message string="test RAM preservation"/>