Kernel: Fix NVMe controller namespace numbering
namespace numbers were incrementing globally instead of per controller. This led to two single namespace controllers creating nvme0n1 and nvme1n2
This commit is contained in:
parent
ff62c262fe
commit
c7b134ba4b
|
@ -11,7 +11,7 @@ namespace Kernel
|
|||
class NVMeNamespace : public StorageDevice
|
||||
{
|
||||
public:
|
||||
static BAN::ErrorOr<BAN::RefPtr<NVMeNamespace>> create(NVMeController&, uint32_t nsid, uint64_t block_count, uint32_t block_size);
|
||||
static BAN::ErrorOr<BAN::RefPtr<NVMeNamespace>> create(NVMeController&, uint32_t ns_index, uint32_t nsid, uint64_t block_count, uint32_t block_size);
|
||||
|
||||
virtual uint32_t sector_size() const override { return m_block_size; }
|
||||
virtual uint64_t total_size() const override { return m_block_size * m_block_count; }
|
||||
|
@ -20,7 +20,7 @@ namespace Kernel
|
|||
virtual BAN::StringView name() const { return m_name; }
|
||||
|
||||
private:
|
||||
NVMeNamespace(NVMeController&, uint32_t nsid, uint64_t block_count, uint32_t block_size);
|
||||
NVMeNamespace(NVMeController&, uint32_t ns_index, uint32_t nsid, uint64_t block_count, uint32_t block_size);
|
||||
BAN::ErrorOr<void> initialize();
|
||||
|
||||
virtual BAN::ErrorOr<void> read_sectors_impl(uint64_t lba, uint64_t sector_count, BAN::ByteSpan) override;
|
||||
|
|
|
@ -213,7 +213,7 @@ namespace Kernel
|
|||
dprintln(" block size {} B", block_size);
|
||||
dprintln(" total {} MiB", block_count * block_size / (1 << 20));
|
||||
|
||||
auto ns = TRY(NVMeNamespace::create(*this, nsid, block_count, block_size));
|
||||
auto ns = TRY(NVMeNamespace::create(*this, m_namespaces.size(), nsid, block_count, block_size));
|
||||
TRY(m_namespaces.push_back(BAN::move(ns)));
|
||||
}
|
||||
|
||||
|
|
|
@ -14,9 +14,9 @@ namespace Kernel
|
|||
return minor++;
|
||||
}
|
||||
|
||||
BAN::ErrorOr<BAN::RefPtr<NVMeNamespace>> NVMeNamespace::create(NVMeController& controller, uint32_t nsid, uint64_t block_count, uint32_t block_size)
|
||||
BAN::ErrorOr<BAN::RefPtr<NVMeNamespace>> NVMeNamespace::create(NVMeController& controller, uint32_t ns_index, uint32_t nsid, uint64_t block_count, uint32_t block_size)
|
||||
{
|
||||
auto* namespace_ptr = new NVMeNamespace(controller, nsid, block_count, block_size);
|
||||
auto* namespace_ptr = new NVMeNamespace(controller, ns_index, nsid, block_count, block_size);
|
||||
if (namespace_ptr == nullptr)
|
||||
return BAN::Error::from_errno(ENOMEM);
|
||||
auto ns = BAN::RefPtr<NVMeNamespace>::adopt(namespace_ptr);
|
||||
|
@ -24,7 +24,7 @@ namespace Kernel
|
|||
return ns;
|
||||
}
|
||||
|
||||
NVMeNamespace::NVMeNamespace(NVMeController& controller, uint32_t nsid, uint64_t block_count, uint32_t block_size)
|
||||
NVMeNamespace::NVMeNamespace(NVMeController& controller, uint32_t ns_index, uint32_t nsid, uint64_t block_count, uint32_t block_size)
|
||||
: m_controller(controller)
|
||||
, m_nsid(nsid)
|
||||
, m_block_size(block_size)
|
||||
|
@ -35,7 +35,7 @@ namespace Kernel
|
|||
ASSERT(m_controller.name().size() + 2 < sizeof(m_name));
|
||||
memcpy(m_name, m_controller.name().data(), m_controller.name().size());
|
||||
m_name[m_controller.name().size() + 0] = 'n';
|
||||
m_name[m_controller.name().size() + 1] = '1' + minor(m_rdev);
|
||||
m_name[m_controller.name().size() + 1] = '1' + ns_index;
|
||||
m_name[m_controller.name().size() + 2] = '\0';
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue