From NVMe spec 1.4b "6.1.5. NSID and Namespace Relationships" defines valid namespace types: - Unallocated: Not exists in the NVMe subsystem - Allocated: Exists in the NVMe subsystem - Inactive: Not attached to the controller - Active: Attached to the controller This patch added support for allocated, but not attached namespace type: !nvme_ns(n, nsid) && nvme_subsys_ns(n->subsys, nsid) nvme_ns() returns attached namespace instance of the given controller and nvme_subsys_ns() returns allocated namespace instance in the subsystem. Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com> Reviewed-by: Keith Busch <kbusch@kernel.org> Reviewed-by: Klaus Jensen <k.jensen@samsung.com> Tested-by: Klaus Jensen <k.jensen@samsung.com> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
51 lines
1.2 KiB
C
51 lines
1.2 KiB
C
/*
|
|
* QEMU NVM Express Subsystem: nvme-subsys
|
|
*
|
|
* Copyright (c) 2021 Minwoo Im <minwoo.im.dev@gmail.com>
|
|
*
|
|
* This code is licensed under the GNU GPL v2. Refer COPYING.
|
|
*/
|
|
|
|
#ifndef NVME_SUBSYS_H
|
|
#define NVME_SUBSYS_H
|
|
|
|
#define TYPE_NVME_SUBSYS "nvme-subsys"
|
|
#define NVME_SUBSYS(obj) \
|
|
OBJECT_CHECK(NvmeSubsystem, (obj), TYPE_NVME_SUBSYS)
|
|
|
|
#define NVME_SUBSYS_MAX_CTRLS 32
|
|
#define NVME_SUBSYS_MAX_NAMESPACES 256
|
|
|
|
typedef struct NvmeCtrl NvmeCtrl;
|
|
typedef struct NvmeNamespace NvmeNamespace;
|
|
typedef struct NvmeSubsystem {
|
|
DeviceState parent_obj;
|
|
uint8_t subnqn[256];
|
|
|
|
NvmeCtrl *ctrls[NVME_SUBSYS_MAX_CTRLS];
|
|
/* Allocated namespaces for this subsystem */
|
|
NvmeNamespace *namespaces[NVME_SUBSYS_MAX_NAMESPACES + 1];
|
|
|
|
struct {
|
|
char *nqn;
|
|
} params;
|
|
} NvmeSubsystem;
|
|
|
|
int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp);
|
|
int nvme_subsys_register_ns(NvmeNamespace *ns, Error **errp);
|
|
|
|
/*
|
|
* Return allocated namespace of the specified nsid in the subsystem.
|
|
*/
|
|
static inline NvmeNamespace *nvme_subsys_ns(NvmeSubsystem *subsys,
|
|
uint32_t nsid)
|
|
{
|
|
if (!subsys) {
|
|
return NULL;
|
|
}
|
|
|
|
return subsys->namespaces[nsid];
|
|
}
|
|
|
|
#endif /* NVME_SUBSYS_H */
|