sculpt: improve USB hotplug handling

- Don't reset sculpt partition on USB changes whenever ram fs is
  selected for use.

- Reconfigure runtime immediately when plugging USB devices.
  This prevents the usb-block driver and part_block from
  dangling in the graph. They disappear immediately now.
This commit is contained in:
Norman Feske 2020-03-04 13:54:20 +01:00 committed by Christian Helmuth
parent a90eab8b9a
commit ab5770c492
2 changed files with 18 additions and 1 deletions

View File

@ -147,6 +147,8 @@ struct Sculpt::Usb_storage_device_update_policy
Env &_env;
Allocator &_alloc;
bool device_added_or_vanished = false;
Signal_context_capability _sigh;
Usb_storage_device_update_policy(Env &env, Allocator &alloc,
@ -157,10 +159,17 @@ struct Sculpt::Usb_storage_device_update_policy
typedef Usb_storage_device::Label Label;
void destroy_element(Usb_storage_device &elem) { destroy(_alloc, &elem); }
void destroy_element(Usb_storage_device &elem)
{
device_added_or_vanished = true;
destroy(_alloc, &elem);
}
Usb_storage_device &create_element(Xml_node node)
{
device_added_or_vanished = true;
return *new (_alloc)
Usb_storage_device(_env, _alloc, _sigh,
node.attribute_value("label_suffix", Label()));

View File

@ -41,6 +41,9 @@ void Sculpt::Storage::handle_storage_devices_update()
_storage_devices.update_usb_storage_devices_from_xml(policy, raw);
if (policy.device_added_or_vanished)
reconfigure_runtime = true;
_storage_devices.usb_storage_devices.for_each([&] (Usb_storage_device &dev) {
dev.process_driver_report();
@ -66,7 +69,12 @@ void Sculpt::Storage::handle_storage_devices_update()
* target to use.
*/
if (_sculpt_partition.valid()) {
bool sculpt_partition_exists = false;
if (_sculpt_partition.ram_fs())
sculpt_partition_exists = true;
_storage_devices.for_each([&] (Storage_device const &device) {
device.for_each_partition([&] (Partition const &partition) {
if (device.label == _sculpt_partition.device