summaryrefslogtreecommitdiff
path: root/Kernel/Storage
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2021-09-11 09:19:20 +0300
committerIdan Horowitz <idan.horowitz@gmail.com>2021-09-17 01:02:48 +0300
commitaee4786d8e80a2a4b2b2422afc4f8f342433c599 (patch)
tree1cdedafb91c7f405ff75a53f3c33cacf86d7167b /Kernel/Storage
parent9aa6dd6b786d42f6c131d03cba58e9999e0644d0 (diff)
downloadserenity-aee4786d8e80a2a4b2b2422afc4f8f342433c599.zip
Kernel: Introduce the DeviceManagement singleton
This singleton simplifies many aspects that we struggled with before: 1. There's no need to make derived classes of Device expose the constructor as public anymore. The singleton is a friend of them, so he can call the constructor. This solves the issue with try_create_device helper neatly, hopefully for good. 2. Getting a reference of the NullDevice is now being done from this singleton, which means that NullDevice no longer needs to use its own singleton, and we can apply the try_create_device helper on it too :) 3. We can now defer registration completely after the Device constructor which means the Device constructor is merely assigning the major and minor numbers of the Device, and the try_create_device helper ensures it calls the after_inserting method immediately after construction. This creates a great opportunity to make registration more OOM-safe.
Diffstat (limited to 'Kernel/Storage')
-rw-r--r--Kernel/Storage/PATADiskDevice.cpp3
-rw-r--r--Kernel/Storage/PATADiskDevice.h4
-rw-r--r--Kernel/Storage/Partition/DiskPartition.cpp3
-rw-r--r--Kernel/Storage/Partition/DiskPartition.h6
-rw-r--r--Kernel/Storage/RamdiskDevice.cpp3
-rw-r--r--Kernel/Storage/RamdiskDevice.h1
-rw-r--r--Kernel/Storage/SATADiskDevice.cpp3
-rw-r--r--Kernel/Storage/SATADiskDevice.h4
8 files changed, 16 insertions, 11 deletions
diff --git a/Kernel/Storage/PATADiskDevice.cpp b/Kernel/Storage/PATADiskDevice.cpp
index d4aab035b0..11a594f1bb 100644
--- a/Kernel/Storage/PATADiskDevice.cpp
+++ b/Kernel/Storage/PATADiskDevice.cpp
@@ -5,6 +5,7 @@
*/
#include <AK/StringView.h>
+#include <Kernel/Devices/DeviceManagement.h>
#include <Kernel/FileSystem/OpenFileDescription.h>
#include <Kernel/Sections.h>
#include <Kernel/Storage/IDEChannel.h>
@@ -15,7 +16,7 @@ namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<PATADiskDevice> PATADiskDevice::create(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 capabilities, u64 max_addressable_block)
{
- auto device_or_error = try_create_device<PATADiskDevice>(controller, channel, type, interface_type, capabilities, max_addressable_block);
+ auto device_or_error = DeviceManagement::try_create_device<PATADiskDevice>(controller, channel, type, interface_type, capabilities, max_addressable_block);
// FIXME: Find a way to propagate errors
VERIFY(!device_or_error.is_error());
return device_or_error.release_value();
diff --git a/Kernel/Storage/PATADiskDevice.h b/Kernel/Storage/PATADiskDevice.h
index 9de2561b36..77fc49b77a 100644
--- a/Kernel/Storage/PATADiskDevice.h
+++ b/Kernel/Storage/PATADiskDevice.h
@@ -20,6 +20,7 @@ class IDEController;
class IDEChannel;
class PATADiskDevice final : public StorageDevice {
friend class IDEController;
+ friend class DeviceManagement;
AK_MAKE_ETERNAL
public:
// Type of drive this IDEDiskDevice is on the ATA channel.
@@ -44,10 +45,9 @@ public:
virtual void start_request(AsyncBlockDeviceRequest&) override;
virtual String storage_name() const override;
- // FIXME: We expose this constructor to make try_create_device helper to work
+private:
PATADiskDevice(const IDEController&, IDEChannel&, DriveType, InterfaceType, u16, u64);
-private:
// ^DiskDevice
virtual StringView class_name() const override;
diff --git a/Kernel/Storage/Partition/DiskPartition.cpp b/Kernel/Storage/Partition/DiskPartition.cpp
index 5352528773..d1941a16de 100644
--- a/Kernel/Storage/Partition/DiskPartition.cpp
+++ b/Kernel/Storage/Partition/DiskPartition.cpp
@@ -5,6 +5,7 @@
*/
#include <Kernel/Debug.h>
+#include <Kernel/Devices/DeviceManagement.h>
#include <Kernel/FileSystem/OpenFileDescription.h>
#include <Kernel/Storage/Partition/DiskPartition.h>
@@ -12,7 +13,7 @@ namespace Kernel {
NonnullRefPtr<DiskPartition> DiskPartition::create(BlockDevice& device, unsigned minor_number, DiskPartitionMetadata metadata)
{
- auto partition_or_error = try_create_device<DiskPartition>(device, minor_number, metadata);
+ auto partition_or_error = DeviceManagement::try_create_device<DiskPartition>(device, minor_number, metadata);
// FIXME: Find a way to propagate errors
VERIFY(!partition_or_error.is_error());
return partition_or_error.release_value();
diff --git a/Kernel/Storage/Partition/DiskPartition.h b/Kernel/Storage/Partition/DiskPartition.h
index 1d4bae1c75..4c172785be 100644
--- a/Kernel/Storage/Partition/DiskPartition.h
+++ b/Kernel/Storage/Partition/DiskPartition.h
@@ -14,6 +14,8 @@
namespace Kernel {
class DiskPartition final : public BlockDevice {
+ friend class DeviceManagement;
+
public:
static NonnullRefPtr<DiskPartition> create(BlockDevice&, unsigned, DiskPartitionMetadata);
virtual ~DiskPartition();
@@ -28,10 +30,8 @@ public:
const DiskPartitionMetadata& metadata() const;
- // FIXME: We expose this constructor to make try_create_device helper to work
- DiskPartition(BlockDevice&, unsigned, DiskPartitionMetadata);
-
private:
+ DiskPartition(BlockDevice&, unsigned, DiskPartitionMetadata);
virtual StringView class_name() const override;
WeakPtr<BlockDevice> m_device;
diff --git a/Kernel/Storage/RamdiskDevice.cpp b/Kernel/Storage/RamdiskDevice.cpp
index 5d831edae2..e08ecdbf87 100644
--- a/Kernel/Storage/RamdiskDevice.cpp
+++ b/Kernel/Storage/RamdiskDevice.cpp
@@ -6,6 +6,7 @@
#include <AK/Memory.h>
#include <AK/StringView.h>
+#include <Kernel/Devices/DeviceManagement.h>
#include <Kernel/FileSystem/OpenFileDescription.h>
#include <Kernel/Storage/RamdiskController.h>
#include <Kernel/Storage/RamdiskDevice.h>
@@ -14,7 +15,7 @@ namespace Kernel {
NonnullRefPtr<RamdiskDevice> RamdiskDevice::create(const RamdiskController& controller, NonnullOwnPtr<Memory::Region>&& region, int major, int minor)
{
- auto device_or_error = try_create_device<RamdiskDevice>(controller, move(region), major, 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();
diff --git a/Kernel/Storage/RamdiskDevice.h b/Kernel/Storage/RamdiskDevice.h
index a55c3fd026..91cf4a22cf 100644
--- a/Kernel/Storage/RamdiskDevice.h
+++ b/Kernel/Storage/RamdiskDevice.h
@@ -15,6 +15,7 @@ class RamdiskController;
class RamdiskDevice final : public StorageDevice {
friend class RamdiskController;
+ friend class DeviceManagement;
AK_MAKE_ETERNAL
public:
static NonnullRefPtr<RamdiskDevice> create(const RamdiskController&, NonnullOwnPtr<Memory::Region>&& region, int major, int minor);
diff --git a/Kernel/Storage/SATADiskDevice.cpp b/Kernel/Storage/SATADiskDevice.cpp
index 0e7c7bd8d4..7563f0cb31 100644
--- a/Kernel/Storage/SATADiskDevice.cpp
+++ b/Kernel/Storage/SATADiskDevice.cpp
@@ -5,6 +5,7 @@
*/
#include <AK/StringView.h>
+#include <Kernel/Devices/DeviceManagement.h>
#include <Kernel/FileSystem/OpenFileDescription.h>
#include <Kernel/Storage/AHCIController.h>
#include <Kernel/Storage/IDEChannel.h>
@@ -14,7 +15,7 @@ namespace Kernel {
NonnullRefPtr<SATADiskDevice> SATADiskDevice::create(const AHCIController& controller, const AHCIPort& port, size_t sector_size, u64 max_addressable_block)
{
- auto device_or_error = try_create_device<SATADiskDevice>(controller, port, sector_size, max_addressable_block);
+ auto device_or_error = DeviceManagement::try_create_device<SATADiskDevice>(controller, port, sector_size, max_addressable_block);
// FIXME: Find a way to propagate errors
VERIFY(!device_or_error.is_error());
return device_or_error.release_value();
diff --git a/Kernel/Storage/SATADiskDevice.h b/Kernel/Storage/SATADiskDevice.h
index 97776b4500..76f6d21fb9 100644
--- a/Kernel/Storage/SATADiskDevice.h
+++ b/Kernel/Storage/SATADiskDevice.h
@@ -16,6 +16,7 @@ namespace Kernel {
class AHCIController;
class SATADiskDevice final : public StorageDevice {
friend class AHCIController;
+ friend class DeviceManagement;
public:
enum class InterfaceType : u8 {
@@ -32,10 +33,9 @@ public:
virtual void start_request(AsyncBlockDeviceRequest&) override;
virtual String storage_name() const override;
- // FIXME: We expose this constructor to make try_create_device helper to work
+private:
SATADiskDevice(const AHCIController&, const AHCIPort&, size_t sector_size, u64 max_addressable_block);
-private:
// ^DiskDevice
virtual StringView class_name() const override;
WeakPtr<AHCIPort> m_port;