e548935634
Prior to this patch, if a private nvme-ns device (that is, a namespace that is not linked to a subsystem) is wired up to an nvme-subsys linked nvme controller device, the device fails to verify that the namespace id is unique within the subsystem. NVM Express v1.4b, Section 6.1.6 ("NSID and Namespace Usage") states that because the device supports Namespace Management, "NSIDs *shall* be unique within the NVM subsystem". Additionally, prior to this patch, private namespaces are not known to the subsystem and the namespace is considered exclusive to the controller with which it is initially wired up to. However, this is not the definition of a private namespace; per Section 1.6.33 ("private namespace"), a private namespace is just a namespace that does not support multipath I/O or namespace sharing, which means "that it is only able to be attached to one controller at a time". Fix this by always allocating namespaces in the subsystem (if one is linked to the controller), regardless of the shared/private status of the namespace. Whether or not the namespace is shareable is controlled by a new `shared` nvme-ns parameter. Finally, this fix allows the nvme-ns `subsys` parameter to be removed, since the `shared` parameter now serves the purpose of attaching the namespace to all controllers in the subsystem upon device realization. It is invalid to have an nvme-ns namespace device with a linked subsystem without the parent nvme controller device also being linked to one and since the nvme-ns devices will unconditionally be "attached" (in QEMU terms that is) to an nvme controller device through an NvmeBus, the nvme-ns namespace device can always get a reference to the subsystem of the controller it is explicitly (using 'bus=' parameter) or implicitly attaching to. Fixes: e570768566b3 ("hw/block/nvme: support for shared namespace in subsystem") Cc: Minwoo Im <minwoo.im.dev@gmail.com> Signed-off-by: Klaus Jensen <k.jensen@samsung.com> Reviewed-by: Gollu Appalanaidu <anaidu.gollu@samsung.com> Reviewed-by: Keith Busch <kbusch@kernel.org> Reviewed-by: Minwoo Im <minwoo.im.dev@gmail.com>
92 lines
2.1 KiB
C
92 lines
2.1 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.
|
|
*/
|
|
|
|
#include "qemu/units.h"
|
|
#include "qemu/osdep.h"
|
|
#include "qemu/uuid.h"
|
|
#include "qemu/iov.h"
|
|
#include "qemu/cutils.h"
|
|
#include "qapi/error.h"
|
|
#include "hw/qdev-properties.h"
|
|
#include "hw/qdev-core.h"
|
|
#include "hw/block/block.h"
|
|
#include "block/aio.h"
|
|
#include "block/accounting.h"
|
|
#include "sysemu/sysemu.h"
|
|
#include "hw/pci/pci.h"
|
|
#include "nvme.h"
|
|
#include "nvme-subsys.h"
|
|
|
|
int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp)
|
|
{
|
|
NvmeSubsystem *subsys = n->subsys;
|
|
int cntlid;
|
|
|
|
for (cntlid = 0; cntlid < ARRAY_SIZE(subsys->ctrls); cntlid++) {
|
|
if (!subsys->ctrls[cntlid]) {
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (cntlid == ARRAY_SIZE(subsys->ctrls)) {
|
|
error_setg(errp, "no more free controller id");
|
|
return -1;
|
|
}
|
|
|
|
subsys->ctrls[cntlid] = n;
|
|
|
|
return cntlid;
|
|
}
|
|
|
|
static void nvme_subsys_setup(NvmeSubsystem *subsys)
|
|
{
|
|
const char *nqn = subsys->params.nqn ?
|
|
subsys->params.nqn : subsys->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)
|
|
{
|
|
NvmeSubsystem *subsys = NVME_SUBSYS(dev);
|
|
|
|
nvme_subsys_setup(subsys);
|
|
}
|
|
|
|
static Property nvme_subsystem_props[] = {
|
|
DEFINE_PROP_STRING("nqn", NvmeSubsystem, params.nqn),
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
};
|
|
|
|
static void nvme_subsys_class_init(ObjectClass *oc, void *data)
|
|
{
|
|
DeviceClass *dc = DEVICE_CLASS(oc);
|
|
|
|
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
|
|
|
|
dc->realize = nvme_subsys_realize;
|
|
dc->desc = "Virtual NVMe subsystem";
|
|
|
|
device_class_set_props(dc, nvme_subsystem_props);
|
|
}
|
|
|
|
static const TypeInfo nvme_subsys_info = {
|
|
.name = TYPE_NVME_SUBSYS,
|
|
.parent = TYPE_DEVICE,
|
|
.class_init = nvme_subsys_class_init,
|
|
.instance_size = sizeof(NvmeSubsystem),
|
|
};
|
|
|
|
static void nvme_subsys_register_types(void)
|
|
{
|
|
type_register_static(&nvme_subsys_info);
|
|
}
|
|
|
|
type_init(nvme_subsys_register_types)
|