mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-27 21:40:49 +00:00
hw/nvme: fix controller hot unplugging
Prior to this patch the nvme-ns devices are always children of the NvmeBus owned by the NvmeCtrl. This causes the namespaces to be unrealized when the parent device is removed. However, when subsystems are involved, this is not what we want since the namespaces may be attached to other controllers as well. This patch adds an additional NvmeBus on the subsystem device. When nvme-ns devices are realized, if the parent controller device is linked to a subsystem, the parent bus is set to the subsystem one instead. This makes sure that namespaces are kept alive and not unrealized. Reviewed-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
This commit is contained in:
parent
51e90178f7
commit
5ffbaeed16
@ -6527,16 +6527,14 @@ static void nvme_exit(PCIDevice *pci_dev)
|
||||
|
||||
nvme_ctrl_reset(n);
|
||||
|
||||
for (i = 1; i <= NVME_MAX_NAMESPACES; i++) {
|
||||
ns = nvme_ns(n, i);
|
||||
if (!ns) {
|
||||
continue;
|
||||
if (n->subsys) {
|
||||
for (i = 1; i <= NVME_MAX_NAMESPACES; i++) {
|
||||
ns = nvme_ns(n, i);
|
||||
if (ns) {
|
||||
ns->attached--;
|
||||
}
|
||||
}
|
||||
|
||||
nvme_ns_cleanup(ns);
|
||||
}
|
||||
|
||||
if (n->subsys) {
|
||||
nvme_subsys_unregister_ctrl(n->subsys, n);
|
||||
}
|
||||
|
||||
|
18
hw/nvme/ns.c
18
hw/nvme/ns.c
@ -441,6 +441,15 @@ void nvme_ns_cleanup(NvmeNamespace *ns)
|
||||
}
|
||||
}
|
||||
|
||||
static void nvme_ns_unrealize(DeviceState *dev)
|
||||
{
|
||||
NvmeNamespace *ns = NVME_NS(dev);
|
||||
|
||||
nvme_ns_drain(ns);
|
||||
nvme_ns_shutdown(ns);
|
||||
nvme_ns_cleanup(ns);
|
||||
}
|
||||
|
||||
static void nvme_ns_realize(DeviceState *dev, Error **errp)
|
||||
{
|
||||
NvmeNamespace *ns = NVME_NS(dev);
|
||||
@ -462,6 +471,14 @@ static void nvme_ns_realize(DeviceState *dev, Error **errp)
|
||||
"linked to an nvme-subsys device");
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* 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)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (nvme_ns_setup(ns, errp)) {
|
||||
@ -552,6 +569,7 @@ static void nvme_ns_class_init(ObjectClass *oc, void *data)
|
||||
|
||||
dc->bus_type = TYPE_NVME_BUS;
|
||||
dc->realize = nvme_ns_realize;
|
||||
dc->unrealize = nvme_ns_unrealize;
|
||||
device_class_set_props(dc, nvme_ns_props);
|
||||
dc->desc = "Virtual NVMe namespace";
|
||||
}
|
||||
|
@ -33,12 +33,20 @@ QEMU_BUILD_BUG_ON(NVME_MAX_NAMESPACES > NVME_NSID_BROADCAST - 1);
|
||||
typedef struct NvmeCtrl NvmeCtrl;
|
||||
typedef struct NvmeNamespace NvmeNamespace;
|
||||
|
||||
#define TYPE_NVME_BUS "nvme-bus"
|
||||
OBJECT_DECLARE_SIMPLE_TYPE(NvmeBus, NVME_BUS)
|
||||
|
||||
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];
|
||||
@ -365,13 +373,6 @@ typedef struct NvmeCQueue {
|
||||
QTAILQ_HEAD(, NvmeRequest) req_list;
|
||||
} NvmeCQueue;
|
||||
|
||||
#define TYPE_NVME_BUS "nvme-bus"
|
||||
#define NVME_BUS(obj) OBJECT_CHECK(NvmeBus, (obj), TYPE_NVME_BUS)
|
||||
|
||||
typedef struct NvmeBus {
|
||||
BusState parent_bus;
|
||||
} NvmeBus;
|
||||
|
||||
#define TYPE_NVME "nvme"
|
||||
#define NVME(obj) \
|
||||
OBJECT_CHECK(NvmeCtrl, (obj), TYPE_NVME)
|
||||
|
@ -50,6 +50,9 @@ static void nvme_subsys_realize(DeviceState *dev, Error **errp)
|
||||
{
|
||||
NvmeSubsystem *subsys = NVME_SUBSYS(dev);
|
||||
|
||||
qbus_create_inplace(&subsys->bus, sizeof(NvmeBus), TYPE_NVME_BUS, dev,
|
||||
dev->id);
|
||||
|
||||
nvme_subsys_setup(subsys);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user