init: respond to binary-name changes

This patch covers the resolution of the ROM route for child binaries
via the generic label-rewriting mechanics. Now, the <binary> node has
become merely sytactic sugar for a route like the following:

<start name="test"/>
  <route>
    <service name="ROM" unscoped_label="test">
      <parent label="test-binary-name"/> </service>
      ...
  </route>
  ...
</start>

A change of the binary name has an effect on the child's ROM route to
the binary and thereby implicitly triggers a child restart due to the
existing re-validation of the routing.
This commit is contained in:
Norman Feske 2017-03-02 13:19:14 +01:00 committed by Christian Helmuth
parent 48174ab974
commit fcf25c22d1
2 changed files with 99 additions and 2 deletions

View File

@ -478,7 +478,8 @@ class Init::Child : Child_policy, Child_service::Wakeup
return start_node.sub_node("binary").attribute_value("name", Name());
}
Binary_name const _binary_name;
/* updated on configuration update */
Binary_name _binary_name;
struct Read_quota
{
@ -840,6 +841,13 @@ class Init::Child : Child_policy, Child_service::Wakeup
config_update = CONFIG_CHANGED;
}
/*
* Import new binary name. A change may affect the route for
* the binary's ROM session, triggering the restart of the
* child.
*/
_binary_name = _binary_name_from_xml(start_node, _unique_name);
/* import new start node */
_start_node.construct(_alloc, start_node);
}
@ -924,7 +932,7 @@ class Init::Child : Child_policy, Child_service::Wakeup
Child_policy::Name name() const override { return _unique_name; }
Binary_name binary_name() const override { return _binary_name; }
Binary_name binary_name() const override { return _unique_name; }
Ram_session &ref_ram() override { return _env.ram(); }
Ram_session_capability ref_ram_cap() const override { return _env.ram_session_cap(); }
@ -1002,6 +1010,19 @@ class Init::Child : Child_policy, Child_service::Wakeup
*/
}
/*
* Check for the binary's ROM request
*
* The binary is requested as a ROM with the child's unique
* name ('Child_policy::binary_name' equals 'Child_policy::name').
* If the binary name differs from the child's unique name,
* we resolve the session request with the binary name as label.
* Otherwise the regular routing is applied.
*/
if (service_name == Rom_session::service_name() &&
label == _unique_name && _unique_name != _binary_name)
return resolve_session_request(service_name, _binary_name);
/* check for "session_requests" ROM request */
if (service_name == Rom_session::service_name()
&& label.last_element() == Session_requester::rom_name())

View File

@ -235,7 +235,78 @@ append config {
<sleep ms="100"/>
<message string="test label rewritiong and binary-name update"/>
<init_config>
<parent-provides>
<service name="ROM"/> <service name="RAM"/>
<service name="CPU"/> <service name="PD"/>
<service name="LOG"/>
</parent-provides>
<start name="test">
<binary name="dummy"/>
<resource name="RAM" quantum="1M"/>
<config version="binary-name test"/>
<route>
<any-service> <parent/> </any-service>
</route>
</start>
</init_config>
<expect_log string="[init -> test] config 1: binary-name test"/>
<!-- We change the binary name, but also use the label-rewriting
feature of init to produce the same route as the original
binary. Consequently, init does not need to restart the
child. Instead the original child merely prints a new
config version (count 2). -->
<init_config>
<parent-provides>
<service name="ROM"/> <service name="RAM"/>
<service name="CPU"/> <service name="PD"/>
<service name="LOG"/>
</parent-provides>
<start name="test">
<binary name="renamed_dummy"/>
<resource name="RAM" quantum="1M"/>
<config version="binary re-routed to same route"/>
<route>
<service name="ROM" unscoped_label="renamed_dummy">
<parent label="dummy"/> </service>
<any-service> <parent/> </any-service>
</route>
</start>
</init_config>
<expect_log string="[init -> test] config 2: binary re-routed to same route"/>
<!-- We change the binary name in a way that results in a
different route for the binary ROM request, which requires
restart of the child. The config version printed by the
new child will have a count of 1. -->
<init_config>
<parent-provides>
<service name="ROM"/> <service name="RAM"/>
<service name="CPU"/> <service name="PD"/>
<service name="LOG"/>
</parent-provides>
<start name="test">
<binary name="another_dummy"/>
<resource name="RAM" quantum="1M"/>
<config version="binary re-routed to other route"/>
<route>
<service name="ROM" unscoped_label="renamed_dummy">
<parent label="dummy"/> </service>
<any-service> <parent/> </any-service>
</route>
</start>
</init_config>
<expect_log string="[init -> test] config 1: binary re-routed to other route"/>
<sleep ms="100"/>
<message string="test RAM preservation"/>
<init_config>
<report init_ram="yes"/>
<resource name="RAM" preserve="2M"/>
@ -286,6 +357,11 @@ append config {
<service name="Report"> <child name="report_rom"/> </service>
<service name="LOG"> <child name="test-init"/> </service>
<service name="Timer"> <child name="timer"/> </service>
<!-- alias for the binary as requested by the binary-name update test -->
<service name="ROM" label="another_dummy">
<parent label="dummy"/> </service>
<any-service> <parent/> </any-service>
</route>
</start>