@@ -6539,7 +6539,7 @@ static int nvme_init_subsys(NvmeCtrl *n, Error **errp)
return 0;
}
- cntlid = nvme_subsys_register_ctrl(n, errp);
+ cntlid = nvme_subsys_register_ctrl(n->subsys, n, errp);
if (cntlid < 0) {
return -1;
}
@@ -6567,6 +6567,10 @@ static void nvme_realize(PCIDevice *pci_dev, Error **errp)
NvmeCtrl *n = NVME(pci_dev);
Error *local_err = NULL;
+ if (n->subsys_dev) {
+ n->subsys = &n->subsys_dev->subsys;
+ }
+
nvme_check_constraints(n, &local_err);
if (local_err) {
error_propagate(errp, local_err);
@@ -6637,8 +6641,8 @@ static Property nvme_props[] = {
DEFINE_BLOCK_PROPERTIES(NvmeCtrl, namespace.blkconf),
DEFINE_PROP_LINK("pmrdev", NvmeCtrl, pmr.dev, TYPE_MEMORY_BACKEND,
HostMemoryBackend *),
- DEFINE_PROP_LINK("subsys", NvmeCtrl, subsys, TYPE_NVME_SUBSYS,
- NvmeSubsystem *),
+ DEFINE_PROP_LINK("subsys", NvmeCtrl, subsys_dev, TYPE_NVME_SUBSYSTEM_DEVICE,
+ NvmeSubsystemDevice *),
DEFINE_PROP_STRING("serial", NvmeCtrl, params.serial),
DEFINE_PROP_UINT32("cmb_size_mb", NvmeCtrl, params.cmb_size_mb, 0),
DEFINE_PROP_UINT32("num_queues", NvmeCtrl, params.num_queues, 0),
@@ -509,7 +509,7 @@ static void nvme_nsdev_realize(DeviceState *dev, Error **errp)
* If this namespace belongs to a subsystem (through a link on the
* controller device), reparent the device.
*/
- if (!qdev_set_parent_bus(dev, &subsys->bus.parent_bus, errp)) {
+ if (!qdev_set_parent_bus(dev, &n->subsys_dev->bus.parent_bus, errp)) {
return;
}
}
@@ -40,24 +40,29 @@ typedef struct NvmeBus {
BusState parent_bus;
} NvmeBus;
-#define TYPE_NVME_SUBSYS "nvme-subsys"
-#define NVME_SUBSYS(obj) \
- OBJECT_CHECK(NvmeSubsystem, (obj), TYPE_NVME_SUBSYS)
-
typedef struct NvmeSubsystem {
- DeviceState parent_obj;
- NvmeBus bus;
uint8_t subnqn[256];
NvmeCtrl *ctrls[NVME_MAX_CONTROLLERS];
NvmeNamespace *namespaces[NVME_MAX_NAMESPACES + 1];
+} NvmeSubsystem;
+
+#define TYPE_NVME_SUBSYSTEM_DEVICE "nvme-subsys"
+OBJECT_DECLARE_SIMPLE_TYPE(NvmeSubsystemDevice, NVME_SUBSYSTEM_DEVICE)
+
+typedef struct NvmeSubsystemDevice {
+ DeviceState parent_obj;
+ NvmeBus bus;
+
+ NvmeSubsystem subsys;
struct {
char *nqn;
} params;
-} NvmeSubsystem;
+} NvmeSubsystemDevice;
-int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp);
+int nvme_subsys_register_ctrl(NvmeSubsystem *subsys, NvmeCtrl *n,
+ Error **errp);
void nvme_subsys_unregister_ctrl(NvmeSubsystem *subsys, NvmeCtrl *n);
static inline NvmeCtrl *nvme_subsys_ctrl(NvmeSubsystem *subsys,
@@ -436,7 +441,8 @@ typedef struct NvmeCtrl {
#define NVME_CHANGED_NSID_SIZE (NVME_MAX_NAMESPACES + 1)
DECLARE_BITMAP(changed_nsids, NVME_CHANGED_NSID_SIZE);
- NvmeSubsystem *subsys;
+ NvmeSubsystem *subsys;
+ NvmeSubsystemDevice *subsys_dev;
NvmeNamespaceDevice namespace;
NvmeNamespace *namespaces[NVME_MAX_NAMESPACES + 1];
@@ -11,9 +11,8 @@
#include "nvme.h"
-int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp)
+int nvme_subsys_register_ctrl(NvmeSubsystem *subsys, NvmeCtrl *n, Error **errp)
{
- NvmeSubsystem *subsys = n->subsys;
int cntlid, nsid;
for (cntlid = 0; cntlid < ARRAY_SIZE(subsys->ctrls); cntlid++) {
@@ -45,53 +44,54 @@ void nvme_subsys_unregister_ctrl(NvmeSubsystem *subsys, NvmeCtrl *n)
n->cntlid = -1;
}
-static void nvme_subsys_setup(NvmeSubsystem *subsys)
+static void nvme_subsys_device_setup(NvmeSubsystemDevice *dev)
{
- const char *nqn = subsys->params.nqn ?
- subsys->params.nqn : subsys->parent_obj.id;
+ NvmeSubsystem *subsys = &dev->subsys;
+ const char *nqn = dev->params.nqn ?
+ dev->params.nqn : dev->parent_obj.id;
snprintf((char *)subsys->subnqn, sizeof(subsys->subnqn),
"nqn.2019-08.org.qemu:%s", nqn);
}
-static void nvme_subsys_realize(DeviceState *dev, Error **errp)
+static void nvme_subsys_device_realize(DeviceState *dev, Error **errp)
{
- NvmeSubsystem *subsys = NVME_SUBSYS(dev);
+ NvmeSubsystemDevice *subsys = NVME_SUBSYSTEM_DEVICE(dev);
qbus_create_inplace(&subsys->bus, sizeof(NvmeBus), TYPE_NVME_BUS, dev,
dev->id);
- nvme_subsys_setup(subsys);
+ nvme_subsys_device_setup(subsys);
}
-static Property nvme_subsystem_props[] = {
- DEFINE_PROP_STRING("nqn", NvmeSubsystem, params.nqn),
+static Property nvme_subsystem_device_props[] = {
+ DEFINE_PROP_STRING("nqn", NvmeSubsystemDevice, params.nqn),
DEFINE_PROP_END_OF_LIST(),
};
-static void nvme_subsys_class_init(ObjectClass *oc, void *data)
+static void nvme_subsys_device_class_init(ObjectClass *oc, void *data)
{
DeviceClass *dc = DEVICE_CLASS(oc);
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
- dc->realize = nvme_subsys_realize;
+ dc->realize = nvme_subsys_device_realize;
dc->desc = "Virtual NVMe subsystem";
dc->hotpluggable = false;
- device_class_set_props(dc, nvme_subsystem_props);
+ device_class_set_props(dc, nvme_subsystem_device_props);
}
-static const TypeInfo nvme_subsys_info = {
- .name = TYPE_NVME_SUBSYS,
+static const TypeInfo nvme_subsys_device_info = {
+ .name = TYPE_NVME_SUBSYSTEM_DEVICE,
.parent = TYPE_DEVICE,
- .class_init = nvme_subsys_class_init,
- .instance_size = sizeof(NvmeSubsystem),
+ .class_init = nvme_subsys_device_class_init,
+ .instance_size = sizeof(NvmeSubsystemDevice),
};
static void nvme_subsys_register_types(void)
{
- type_register_static(&nvme_subsys_info);
+ type_register_static(&nvme_subsys_device_info);
}
type_init(nvme_subsys_register_types)