mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-11 13:36:13 +03:00
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.
This commit is contained in:
parent
37f527be9c
commit
4e0f85432a
Notes:
sideshowbarker
2024-07-17 06:24:12 +09:00
Author: https://github.com/supercomputer7 Commit: https://github.com/SerenityOS/serenity/commit/4e0f85432a Pull-request: https://github.com/SerenityOS/serenity/pull/15435
@ -100,8 +100,6 @@ set(KERNEL_SOURCES
|
||||
Storage/NVMe/NVMeInterruptQueue.cpp
|
||||
Storage/NVMe/NVMePollQueue.cpp
|
||||
Storage/NVMe/NVMeQueue.cpp
|
||||
Storage/Ramdisk/Controller.cpp
|
||||
Storage/Ramdisk/Device.cpp
|
||||
Storage/DiskPartition.cpp
|
||||
Storage/StorageController.cpp
|
||||
Storage/StorageDevice.cpp
|
||||
|
@ -1,67 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/Types.h>
|
||||
#include <Kernel/Library/LockRefPtr.h>
|
||||
#include <Kernel/Storage/Ramdisk/Controller.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
NonnullLockRefPtr<RamdiskController> RamdiskController::initialize()
|
||||
{
|
||||
return adopt_lock_ref(*new RamdiskController());
|
||||
}
|
||||
|
||||
bool RamdiskController::reset()
|
||||
{
|
||||
TODO();
|
||||
}
|
||||
|
||||
bool RamdiskController::shutdown()
|
||||
{
|
||||
TODO();
|
||||
}
|
||||
|
||||
size_t RamdiskController::devices_count() const
|
||||
{
|
||||
return m_devices.size();
|
||||
}
|
||||
|
||||
void RamdiskController::complete_current_request(AsyncDeviceRequest::RequestResult)
|
||||
{
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
RamdiskController::RamdiskController()
|
||||
: StorageController(0)
|
||||
{
|
||||
// Populate ramdisk controllers from Multiboot boot modules, if any.
|
||||
size_t count = 0;
|
||||
MM.for_each_used_memory_range([&](auto& used_memory_range) {
|
||||
if (used_memory_range.type == Memory::UsedMemoryRangeType::BootModule) {
|
||||
size_t length = Memory::page_round_up(used_memory_range.end.get()).release_value_but_fixme_should_propagate_errors() - used_memory_range.start.get();
|
||||
auto region_or_error = MM.allocate_kernel_region(used_memory_range.start, length, "Ramdisk"sv, Memory::Region::Access::ReadWrite);
|
||||
if (region_or_error.is_error()) {
|
||||
dmesgln("RamdiskController: Failed to allocate kernel region of size {}", length);
|
||||
} else {
|
||||
m_devices.append(RamdiskDevice::create(*this, region_or_error.release_value(), 6, count));
|
||||
}
|
||||
count++;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
RamdiskController::~RamdiskController() = default;
|
||||
|
||||
LockRefPtr<StorageDevice> RamdiskController::device(u32 index) const
|
||||
{
|
||||
if (index >= m_devices.size())
|
||||
return nullptr;
|
||||
return m_devices[index];
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/Types.h>
|
||||
#include <Kernel/Library/LockRefPtr.h>
|
||||
#include <Kernel/Storage/Ramdisk/Device.h>
|
||||
#include <Kernel/Storage/StorageController.h>
|
||||
#include <Kernel/Storage/StorageDevice.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class AsyncBlockDeviceRequest;
|
||||
|
||||
class RamdiskController final : public StorageController {
|
||||
public:
|
||||
static NonnullLockRefPtr<RamdiskController> initialize();
|
||||
virtual ~RamdiskController() override;
|
||||
|
||||
virtual LockRefPtr<StorageDevice> device(u32 index) const override;
|
||||
virtual bool reset() override;
|
||||
virtual bool shutdown() override;
|
||||
virtual size_t devices_count() const override;
|
||||
virtual void complete_current_request(AsyncDeviceRequest::RequestResult) override;
|
||||
|
||||
private:
|
||||
RamdiskController();
|
||||
|
||||
NonnullLockRefPtrVector<RamdiskDevice> m_devices;
|
||||
};
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <Kernel/Devices/DeviceManagement.h>
|
||||
#include <Kernel/FileSystem/OpenFileDescription.h>
|
||||
#include <Kernel/Storage/Ramdisk/Controller.h>
|
||||
#include <Kernel/Storage/Ramdisk/Device.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
NonnullLockRefPtr<RamdiskDevice> RamdiskDevice::create(RamdiskController const& controller, NonnullOwnPtr<Memory::Region>&& region, int major, int minor)
|
||||
{
|
||||
auto device_or_error = DeviceManagement::try_create_device<RamdiskDevice>(controller, move(region), major, minor);
|
||||
// FIXME: Find a way to propagate errors
|
||||
VERIFY(!device_or_error.is_error());
|
||||
return device_or_error.release_value();
|
||||
}
|
||||
|
||||
RamdiskDevice::RamdiskDevice(RamdiskController const& controller, NonnullOwnPtr<Memory::Region>&& region, int major, int minor)
|
||||
: StorageDevice({}, LUNAddress { controller.controller_id(), 0, 0 }, 0, major, minor, 512, region->size() / 512)
|
||||
, m_region(move(region))
|
||||
{
|
||||
dmesgln("Ramdisk: Device #{} @ {}, Capacity={}", minor, m_region->vaddr(), max_addressable_block() * 512);
|
||||
}
|
||||
|
||||
RamdiskDevice::~RamdiskDevice() = default;
|
||||
|
||||
StringView RamdiskDevice::class_name() const
|
||||
{
|
||||
return "RamdiskDevice"sv;
|
||||
}
|
||||
|
||||
void RamdiskDevice::start_request(AsyncBlockDeviceRequest& request)
|
||||
{
|
||||
MutexLocker locker(m_lock);
|
||||
|
||||
u8* base = m_region->vaddr().as_ptr();
|
||||
size_t size = m_region->size();
|
||||
u8* offset = base + request.block_index() * request.block_size();
|
||||
size_t length = request.buffer_size();
|
||||
|
||||
if ((offset + length > base + size) || (offset + length < base)) {
|
||||
request.complete(AsyncDeviceRequest::Failure);
|
||||
} else {
|
||||
ErrorOr<void> result;
|
||||
if (request.request_type() == AsyncBlockDeviceRequest::Read) {
|
||||
result = request.buffer().write(offset, length);
|
||||
} else {
|
||||
result = request.buffer().read(offset, length);
|
||||
}
|
||||
request.complete(!result.is_error() ? AsyncDeviceRequest::Success : AsyncDeviceRequest::MemoryFault);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Kernel/Locking/Mutex.h>
|
||||
#include <Kernel/Storage/StorageDevice.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class RamdiskController;
|
||||
|
||||
class RamdiskDevice final : public StorageDevice {
|
||||
friend class RamdiskController;
|
||||
friend class DeviceManagement;
|
||||
|
||||
public:
|
||||
static NonnullLockRefPtr<RamdiskDevice> create(RamdiskController const&, NonnullOwnPtr<Memory::Region>&& region, int major, int minor);
|
||||
virtual ~RamdiskDevice() override;
|
||||
|
||||
// ^DiskDevice
|
||||
virtual StringView class_name() const override;
|
||||
|
||||
private:
|
||||
RamdiskDevice(RamdiskController const&, NonnullOwnPtr<Memory::Region>&&, int major, int minor);
|
||||
|
||||
// ^BlockDevice
|
||||
virtual void start_request(AsyncBlockDeviceRequest&) override;
|
||||
|
||||
// ^StorageDevice
|
||||
virtual CommandSet command_set() const override { return CommandSet::PlainMemory; }
|
||||
|
||||
Mutex m_lock { "RamdiskDevice"sv };
|
||||
|
||||
NonnullOwnPtr<Memory::Region> m_region;
|
||||
};
|
||||
|
||||
}
|
@ -66,8 +66,6 @@ StringView StorageDevice::class_name() const
|
||||
StringView StorageDevice::command_set_to_string_view() const
|
||||
{
|
||||
switch (command_set()) {
|
||||
case CommandSet::PlainMemory:
|
||||
return "memory"sv;
|
||||
case CommandSet::SCSI:
|
||||
return "scsi"sv;
|
||||
case CommandSet::ATA:
|
||||
|
@ -34,7 +34,6 @@ public:
|
||||
// and ATAPI is the exception to no-distinction rule. If we ever put SCSI support in the kernel,
|
||||
// we can create another enum class to put the distinction.
|
||||
enum class CommandSet {
|
||||
PlainMemory,
|
||||
SCSI,
|
||||
ATA,
|
||||
NVMe,
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include <Kernel/Storage/ATA/AHCI/Controller.h>
|
||||
#include <Kernel/Storage/ATA/GenericIDE/Controller.h>
|
||||
#include <Kernel/Storage/NVMe/NVMeController.h>
|
||||
#include <Kernel/Storage/Ramdisk/Controller.h>
|
||||
#include <Kernel/Storage/StorageManagement.h>
|
||||
#include <LibPartition/EBRPartitionTable.h>
|
||||
#include <LibPartition/GUIDPartitionTable.h>
|
||||
@ -48,7 +47,6 @@ static constexpr StringView block_device_prefix = "block"sv;
|
||||
|
||||
static constexpr StringView ata_device_prefix = "ata"sv;
|
||||
static constexpr StringView nvme_device_prefix = "nvme"sv;
|
||||
static constexpr StringView ramdisk_device_prefix = "ramdisk"sv;
|
||||
static constexpr StringView logical_unit_number_device_prefix = "lun"sv;
|
||||
|
||||
UNMAP_AFTER_INIT StorageManagement::StorageManagement()
|
||||
@ -289,13 +287,6 @@ UNMAP_AFTER_INIT void StorageManagement::determine_nvme_boot_device()
|
||||
});
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT void StorageManagement::determine_ramdisk_boot_device()
|
||||
{
|
||||
determine_hardware_relative_boot_device(ramdisk_device_prefix, [](StorageDevice const& device) -> bool {
|
||||
return device.command_set() == StorageDevice::CommandSet::PlainMemory;
|
||||
});
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT void StorageManagement::determine_block_boot_device()
|
||||
{
|
||||
VERIFY(m_boot_argument.starts_with(block_device_prefix));
|
||||
@ -355,11 +346,6 @@ UNMAP_AFTER_INIT void StorageManagement::determine_boot_device()
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_boot_argument.starts_with(ramdisk_device_prefix)) {
|
||||
determine_ramdisk_boot_device();
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_boot_argument.starts_with(nvme_device_prefix)) {
|
||||
determine_nvme_boot_device();
|
||||
return;
|
||||
@ -442,9 +428,6 @@ UNMAP_AFTER_INIT void StorageManagement::initialize(StringView root_device, bool
|
||||
} else {
|
||||
enumerate_pci_controllers(force_pio, poll);
|
||||
}
|
||||
// Note: Whether PCI bus is present on the system or not, always try to attach
|
||||
// a given ramdisk.
|
||||
m_controllers.append(RamdiskController::initialize());
|
||||
enumerate_storage_devices();
|
||||
enumerate_disk_partitions();
|
||||
|
||||
|
@ -55,7 +55,6 @@ private:
|
||||
void resolve_partition_from_boot_device_parameter(StorageDevice const& chosen_storage_device, StringView boot_device_prefix);
|
||||
void determine_boot_device_with_logical_unit_number();
|
||||
void determine_block_boot_device();
|
||||
void determine_ramdisk_boot_device();
|
||||
void determine_nvme_boot_device();
|
||||
void determine_ata_boot_device();
|
||||
void determine_hardware_relative_boot_device(StringView relative_hardware_prefix, Function<bool(StorageDevice const&)> filter_device_callback);
|
||||
|
Loading…
Reference in New Issue
Block a user