From ab5770c492c3c9691bc923502a9bde73cd291025 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Wed, 4 Mar 2020 13:54:20 +0100 Subject: [PATCH] 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. --- .../src/app/sculpt_manager/model/usb_storage_device.h | 11 ++++++++++- repos/gems/src/app/sculpt_manager/storage.cc | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/repos/gems/src/app/sculpt_manager/model/usb_storage_device.h b/repos/gems/src/app/sculpt_manager/model/usb_storage_device.h index faf5428cd0..a17ba269f0 100644 --- a/repos/gems/src/app/sculpt_manager/model/usb_storage_device.h +++ b/repos/gems/src/app/sculpt_manager/model/usb_storage_device.h @@ -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())); diff --git a/repos/gems/src/app/sculpt_manager/storage.cc b/repos/gems/src/app/sculpt_manager/storage.cc index b5f42ff589..2563cb3f17 100644 --- a/repos/gems/src/app/sculpt_manager/storage.cc +++ b/repos/gems/src/app/sculpt_manager/storage.cc @@ -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