Serenity Operating System
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Kernel/Storage: Remove the ramdisk implementation

Nobody uses this because the x86 prekernel environment is corrupting the
ramdisk image prior to running the actual kernel. In the future we can
ensure that the prekernel doesn't corrupt the ramdisk if we want to
bring support back. In addition to that, we could just use a RAM based
filesystem to load whatever is needed like in Linux, without the need of
additional filesystem driver.

For the mentioned corruption problem, look at issue #9893.

authored by

Liav A and committed by
Andreas Kling
4e0f8543 37f527be

-227
-2
Kernel/CMakeLists.txt
··· 100 100 Storage/NVMe/NVMeInterruptQueue.cpp 101 101 Storage/NVMe/NVMePollQueue.cpp 102 102 Storage/NVMe/NVMeQueue.cpp 103 - Storage/Ramdisk/Controller.cpp 104 - Storage/Ramdisk/Device.cpp 105 103 Storage/DiskPartition.cpp 106 104 Storage/StorageController.cpp 107 105 Storage/StorageDevice.cpp
-67
Kernel/Storage/Ramdisk/Controller.cpp
··· 1 - /* 2 - * Copyright (c) 2021, the SerenityOS developers. 3 - * 4 - * SPDX-License-Identifier: BSD-2-Clause 5 - */ 6 - 7 - #include <AK/OwnPtr.h> 8 - #include <AK/Types.h> 9 - #include <Kernel/Library/LockRefPtr.h> 10 - #include <Kernel/Storage/Ramdisk/Controller.h> 11 - 12 - namespace Kernel { 13 - 14 - NonnullLockRefPtr<RamdiskController> RamdiskController::initialize() 15 - { 16 - return adopt_lock_ref(*new RamdiskController()); 17 - } 18 - 19 - bool RamdiskController::reset() 20 - { 21 - TODO(); 22 - } 23 - 24 - bool RamdiskController::shutdown() 25 - { 26 - TODO(); 27 - } 28 - 29 - size_t RamdiskController::devices_count() const 30 - { 31 - return m_devices.size(); 32 - } 33 - 34 - void RamdiskController::complete_current_request(AsyncDeviceRequest::RequestResult) 35 - { 36 - VERIFY_NOT_REACHED(); 37 - } 38 - 39 - RamdiskController::RamdiskController() 40 - : StorageController(0) 41 - { 42 - // Populate ramdisk controllers from Multiboot boot modules, if any. 43 - size_t count = 0; 44 - MM.for_each_used_memory_range([&](auto& used_memory_range) { 45 - if (used_memory_range.type == Memory::UsedMemoryRangeType::BootModule) { 46 - size_t length = Memory::page_round_up(used_memory_range.end.get()).release_value_but_fixme_should_propagate_errors() - used_memory_range.start.get(); 47 - auto region_or_error = MM.allocate_kernel_region(used_memory_range.start, length, "Ramdisk"sv, Memory::Region::Access::ReadWrite); 48 - if (region_or_error.is_error()) { 49 - dmesgln("RamdiskController: Failed to allocate kernel region of size {}", length); 50 - } else { 51 - m_devices.append(RamdiskDevice::create(*this, region_or_error.release_value(), 6, count)); 52 - } 53 - count++; 54 - } 55 - }); 56 - } 57 - 58 - RamdiskController::~RamdiskController() = default; 59 - 60 - LockRefPtr<StorageDevice> RamdiskController::device(u32 index) const 61 - { 62 - if (index >= m_devices.size()) 63 - return nullptr; 64 - return m_devices[index]; 65 - } 66 - 67 - }
-36
Kernel/Storage/Ramdisk/Controller.h
··· 1 - /* 2 - * Copyright (c) 2021, the SerenityOS developers. 3 - * 4 - * SPDX-License-Identifier: BSD-2-Clause 5 - */ 6 - 7 - #pragma once 8 - 9 - #include <AK/OwnPtr.h> 10 - #include <AK/Types.h> 11 - #include <Kernel/Library/LockRefPtr.h> 12 - #include <Kernel/Storage/Ramdisk/Device.h> 13 - #include <Kernel/Storage/StorageController.h> 14 - #include <Kernel/Storage/StorageDevice.h> 15 - 16 - namespace Kernel { 17 - 18 - class AsyncBlockDeviceRequest; 19 - 20 - class RamdiskController final : public StorageController { 21 - public: 22 - static NonnullLockRefPtr<RamdiskController> initialize(); 23 - virtual ~RamdiskController() override; 24 - 25 - virtual LockRefPtr<StorageDevice> device(u32 index) const override; 26 - virtual bool reset() override; 27 - virtual bool shutdown() override; 28 - virtual size_t devices_count() const override; 29 - virtual void complete_current_request(AsyncDeviceRequest::RequestResult) override; 30 - 31 - private: 32 - RamdiskController(); 33 - 34 - NonnullLockRefPtrVector<RamdiskDevice> m_devices; 35 - }; 36 - }
-60
Kernel/Storage/Ramdisk/Device.cpp
··· 1 - /* 2 - * Copyright (c) 2021, the SerenityOS developers. 3 - * 4 - * SPDX-License-Identifier: BSD-2-Clause 5 - */ 6 - 7 - #include <AK/Memory.h> 8 - #include <AK/StringView.h> 9 - #include <Kernel/Devices/DeviceManagement.h> 10 - #include <Kernel/FileSystem/OpenFileDescription.h> 11 - #include <Kernel/Storage/Ramdisk/Controller.h> 12 - #include <Kernel/Storage/Ramdisk/Device.h> 13 - 14 - namespace Kernel { 15 - 16 - NonnullLockRefPtr<RamdiskDevice> RamdiskDevice::create(RamdiskController const& controller, NonnullOwnPtr<Memory::Region>&& region, int major, int minor) 17 - { 18 - auto device_or_error = DeviceManagement::try_create_device<RamdiskDevice>(controller, move(region), major, minor); 19 - // FIXME: Find a way to propagate errors 20 - VERIFY(!device_or_error.is_error()); 21 - return device_or_error.release_value(); 22 - } 23 - 24 - RamdiskDevice::RamdiskDevice(RamdiskController const& controller, NonnullOwnPtr<Memory::Region>&& region, int major, int minor) 25 - : StorageDevice({}, LUNAddress { controller.controller_id(), 0, 0 }, 0, major, minor, 512, region->size() / 512) 26 - , m_region(move(region)) 27 - { 28 - dmesgln("Ramdisk: Device #{} @ {}, Capacity={}", minor, m_region->vaddr(), max_addressable_block() * 512); 29 - } 30 - 31 - RamdiskDevice::~RamdiskDevice() = default; 32 - 33 - StringView RamdiskDevice::class_name() const 34 - { 35 - return "RamdiskDevice"sv; 36 - } 37 - 38 - void RamdiskDevice::start_request(AsyncBlockDeviceRequest& request) 39 - { 40 - MutexLocker locker(m_lock); 41 - 42 - u8* base = m_region->vaddr().as_ptr(); 43 - size_t size = m_region->size(); 44 - u8* offset = base + request.block_index() * request.block_size(); 45 - size_t length = request.buffer_size(); 46 - 47 - if ((offset + length > base + size) || (offset + length < base)) { 48 - request.complete(AsyncDeviceRequest::Failure); 49 - } else { 50 - ErrorOr<void> result; 51 - if (request.request_type() == AsyncBlockDeviceRequest::Read) { 52 - result = request.buffer().write(offset, length); 53 - } else { 54 - result = request.buffer().read(offset, length); 55 - } 56 - request.complete(!result.is_error() ? AsyncDeviceRequest::Success : AsyncDeviceRequest::MemoryFault); 57 - } 58 - } 59 - 60 - }
-41
Kernel/Storage/Ramdisk/Device.h
··· 1 - /* 2 - * Copyright (c) 2021, the SerenityOS developers. 3 - * 4 - * SPDX-License-Identifier: BSD-2-Clause 5 - */ 6 - 7 - #pragma once 8 - 9 - #include <Kernel/Locking/Mutex.h> 10 - #include <Kernel/Storage/StorageDevice.h> 11 - 12 - namespace Kernel { 13 - 14 - class RamdiskController; 15 - 16 - class RamdiskDevice final : public StorageDevice { 17 - friend class RamdiskController; 18 - friend class DeviceManagement; 19 - 20 - public: 21 - static NonnullLockRefPtr<RamdiskDevice> create(RamdiskController const&, NonnullOwnPtr<Memory::Region>&& region, int major, int minor); 22 - virtual ~RamdiskDevice() override; 23 - 24 - // ^DiskDevice 25 - virtual StringView class_name() const override; 26 - 27 - private: 28 - RamdiskDevice(RamdiskController const&, NonnullOwnPtr<Memory::Region>&&, int major, int minor); 29 - 30 - // ^BlockDevice 31 - virtual void start_request(AsyncBlockDeviceRequest&) override; 32 - 33 - // ^StorageDevice 34 - virtual CommandSet command_set() const override { return CommandSet::PlainMemory; } 35 - 36 - Mutex m_lock { "RamdiskDevice"sv }; 37 - 38 - NonnullOwnPtr<Memory::Region> m_region; 39 - }; 40 - 41 - }
-2
Kernel/Storage/StorageDevice.cpp
··· 66 66 StringView StorageDevice::command_set_to_string_view() const 67 67 { 68 68 switch (command_set()) { 69 - case CommandSet::PlainMemory: 70 - return "memory"sv; 71 69 case CommandSet::SCSI: 72 70 return "scsi"sv; 73 71 case CommandSet::ATA:
-1
Kernel/Storage/StorageDevice.h
··· 34 34 // and ATAPI is the exception to no-distinction rule. If we ever put SCSI support in the kernel, 35 35 // we can create another enum class to put the distinction. 36 36 enum class CommandSet { 37 - PlainMemory, 38 37 SCSI, 39 38 ATA, 40 39 NVMe,
-17
Kernel/Storage/StorageManagement.cpp
··· 25 25 #include <Kernel/Storage/ATA/AHCI/Controller.h> 26 26 #include <Kernel/Storage/ATA/GenericIDE/Controller.h> 27 27 #include <Kernel/Storage/NVMe/NVMeController.h> 28 - #include <Kernel/Storage/Ramdisk/Controller.h> 29 28 #include <Kernel/Storage/StorageManagement.h> 30 29 #include <LibPartition/EBRPartitionTable.h> 31 30 #include <LibPartition/GUIDPartitionTable.h> ··· 48 47 49 48 static constexpr StringView ata_device_prefix = "ata"sv; 50 49 static constexpr StringView nvme_device_prefix = "nvme"sv; 51 - static constexpr StringView ramdisk_device_prefix = "ramdisk"sv; 52 50 static constexpr StringView logical_unit_number_device_prefix = "lun"sv; 53 51 54 52 UNMAP_AFTER_INIT StorageManagement::StorageManagement() ··· 289 287 }); 290 288 } 291 289 292 - UNMAP_AFTER_INIT void StorageManagement::determine_ramdisk_boot_device() 293 - { 294 - determine_hardware_relative_boot_device(ramdisk_device_prefix, [](StorageDevice const& device) -> bool { 295 - return device.command_set() == StorageDevice::CommandSet::PlainMemory; 296 - }); 297 - } 298 - 299 290 UNMAP_AFTER_INIT void StorageManagement::determine_block_boot_device() 300 291 { 301 292 VERIFY(m_boot_argument.starts_with(block_device_prefix)); ··· 352 343 353 344 if (m_boot_argument.starts_with(ata_device_prefix)) { 354 345 determine_ata_boot_device(); 355 - return; 356 - } 357 - 358 - if (m_boot_argument.starts_with(ramdisk_device_prefix)) { 359 - determine_ramdisk_boot_device(); 360 346 return; 361 347 } 362 348 ··· 442 428 } else { 443 429 enumerate_pci_controllers(force_pio, poll); 444 430 } 445 - // Note: Whether PCI bus is present on the system or not, always try to attach 446 - // a given ramdisk. 447 - m_controllers.append(RamdiskController::initialize()); 448 431 enumerate_storage_devices(); 449 432 enumerate_disk_partitions(); 450 433
-1
Kernel/Storage/StorageManagement.h
··· 55 55 void resolve_partition_from_boot_device_parameter(StorageDevice const& chosen_storage_device, StringView boot_device_prefix); 56 56 void determine_boot_device_with_logical_unit_number(); 57 57 void determine_block_boot_device(); 58 - void determine_ramdisk_boot_device(); 59 58 void determine_nvme_boot_device(); 60 59 void determine_ata_boot_device(); 61 60 void determine_hardware_relative_boot_device(StringView relative_hardware_prefix, Function<bool(StorageDevice const&)> filter_device_callback);