diff mbox series

[PULL,01/38] hw/block/nvme: introduce nvme-subsys device

Message ID 20210308122313.286938-2-its@irrelevant.dk
State New
Headers show
Series [PULL,01/38] hw/block/nvme: introduce nvme-subsys device | expand

Commit Message

Klaus Jensen March 8, 2021, 12:22 p.m. UTC
From: Minwoo Im <minwoo.im.dev@gmail.com>

To support multi-path in QEMU NVMe device model, We need to have NVMe
subsystem hierarchy to map controllers and namespaces to a NVMe
subsystem.

This patch introduced a simple nvme-subsys device model.  The subsystem
will be prepared with subsystem NQN with <subsys_id> provided in
nvme-subsys device:

  ex) -device nvme-subsys,id=subsys0: nqn.2019-08.org.qemu:subsys0

Signed-off-by: Minwoo Im <minwoo.im.dev@gmail.com>
Tested-by: Klaus Jensen <k.jensen@samsung.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/block/nvme-subsys.h | 25 ++++++++++++++++++
 hw/block/nvme-subsys.c | 60 ++++++++++++++++++++++++++++++++++++++++++
 hw/block/nvme.c        |  3 +++
 hw/block/meson.build   |  2 +-
 4 files changed, 89 insertions(+), 1 deletion(-)
 create mode 100644 hw/block/nvme-subsys.h
 create mode 100644 hw/block/nvme-subsys.c

Comments

Paolo Bonzini March 8, 2021, 6:32 p.m. UTC | #1
On 08/03/21 13:22, Klaus Jensen wrote:
> 
> This patch introduced a simple nvme-subsys device model.  The subsystem
> will be prepared with subsystem NQN with <subsys_id> provided in
> nvme-subsys device:
> 
>    ex) -device nvme-subsys,id=subsys0: nqn.2019-08.org.qemu:subsys0

Hi Klaus, sorry for not spotting this before.  In the SCSI subsystem we 
moved away from using id as guest-visible data.  Keeping it as a default 
is fine I guess, but would it be possible to add an nqn property to 
nvme-subsys and use it if it is present instead of the id?

Thanks,

Paolo
Klaus Jensen March 8, 2021, 6:46 p.m. UTC | #2
On Mar  8 19:32, Paolo Bonzini wrote:
> On 08/03/21 13:22, Klaus Jensen wrote:
> > 
> > This patch introduced a simple nvme-subsys device model.  The subsystem
> > will be prepared with subsystem NQN with <subsys_id> provided in
> > nvme-subsys device:
> > 
> >    ex) -device nvme-subsys,id=subsys0: nqn.2019-08.org.qemu:subsys0
> 
> Hi Klaus, sorry for not spotting this before.  In the SCSI subsystem we
> moved away from using id as guest-visible data.  Keeping it as a default is
> fine I guess, but would it be possible to add an nqn property to nvme-subsys
> and use it if it is present instead of the id?
> 
> Thanks,
> 
> Paolo
> 

Hi Paolo,

Thanks for pointing this out! Absolutely - we have no specific reason to
use 'id', so we can just change it completely to use 'nqn'.

Peter, you want this in a v2 or did you already start integration of
this PR?
Peter Maydell March 8, 2021, 6:53 p.m. UTC | #3
On Mon, 8 Mar 2021 at 18:46, Klaus Jensen <its@irrelevant.dk> wrote:
>
> On Mar  8 19:32, Paolo Bonzini wrote:
> > On 08/03/21 13:22, Klaus Jensen wrote:
> > >
> > > This patch introduced a simple nvme-subsys device model.  The subsystem
> > > will be prepared with subsystem NQN with <subsys_id> provided in
> > > nvme-subsys device:
> > >
> > >    ex) -device nvme-subsys,id=subsys0: nqn.2019-08.org.qemu:subsys0
> >
> > Hi Klaus, sorry for not spotting this before.  In the SCSI subsystem we
> > moved away from using id as guest-visible data.  Keeping it as a default is
> > fine I guess, but would it be possible to add an nqn property to nvme-subsys
> > and use it if it is present instead of the id?
> >
> > Thanks,
> >
> > Paolo
> >
>
> Hi Paolo,
>
> Thanks for pointing this out! Absolutely - we have no specific reason to
> use 'id', so we can just change it completely to use 'nqn'.
>
> Peter, you want this in a v2 or did you already start integration of
> this PR?

I haven't yet started working on this PR so if the change is trivial
feel free to roll a v2.

-- PMM
Klaus Jensen March 8, 2021, 6:55 p.m. UTC | #4
On Mar  8 18:53, Peter Maydell wrote:
> On Mon, 8 Mar 2021 at 18:46, Klaus Jensen <its@irrelevant.dk> wrote:
> >
> > On Mar  8 19:32, Paolo Bonzini wrote:
> > > On 08/03/21 13:22, Klaus Jensen wrote:
> > > >
> > > > This patch introduced a simple nvme-subsys device model.  The subsystem
> > > > will be prepared with subsystem NQN with <subsys_id> provided in
> > > > nvme-subsys device:
> > > >
> > > >    ex) -device nvme-subsys,id=subsys0: nqn.2019-08.org.qemu:subsys0
> > >
> > > Hi Klaus, sorry for not spotting this before.  In the SCSI subsystem we
> > > moved away from using id as guest-visible data.  Keeping it as a default is
> > > fine I guess, but would it be possible to add an nqn property to nvme-subsys
> > > and use it if it is present instead of the id?
> > >
> > > Thanks,
> > >
> > > Paolo
> > >
> >
> > Hi Paolo,
> >
> > Thanks for pointing this out! Absolutely - we have no specific reason to
> > use 'id', so we can just change it completely to use 'nqn'.
> >
> > Peter, you want this in a v2 or did you already start integration of
> > this PR?
> 
> I haven't yet started working on this PR so if the change is trivial
> feel free to roll a v2.
> 

Thanks, I'll do that!
diff mbox series

Patch

diff --git a/hw/block/nvme-subsys.h b/hw/block/nvme-subsys.h
new file mode 100644
index 000000000000..40f06a4c7db0
--- /dev/null
+++ b/hw/block/nvme-subsys.h
@@ -0,0 +1,25 @@ 
+/*
+ * 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
+
+typedef struct NvmeCtrl NvmeCtrl;
+typedef struct NvmeNamespace NvmeNamespace;
+typedef struct NvmeSubsystem {
+    DeviceState parent_obj;
+    uint8_t     subnqn[256];
+} NvmeSubsystem;
+
+#endif /* NVME_SUBSYS_H */
diff --git a/hw/block/nvme-subsys.c b/hw/block/nvme-subsys.c
new file mode 100644
index 000000000000..aa82911b951c
--- /dev/null
+++ b/hw/block/nvme-subsys.c
@@ -0,0 +1,60 @@ 
+/*
+ * 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"
+
+static void nvme_subsys_setup(NvmeSubsystem *subsys)
+{
+    snprintf((char *)subsys->subnqn, sizeof(subsys->subnqn),
+             "nqn.2019-08.org.qemu:%s", subsys->parent_obj.id);
+}
+
+static void nvme_subsys_realize(DeviceState *dev, Error **errp)
+{
+    NvmeSubsystem *subsys = NVME_SUBSYS(dev);
+
+    nvme_subsys_setup(subsys);
+}
+
+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";
+}
+
+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)
diff --git a/hw/block/nvme.c b/hw/block/nvme.c
index fb83636abdc1..1950b34684cd 100644
--- a/hw/block/nvme.c
+++ b/hw/block/nvme.c
@@ -25,6 +25,7 @@ 
  *              mdts=<N[optional]>,zoned.append_size_limit=<N[optional]> \
  *      -device nvme-ns,drive=<drive_id>,bus=<bus_name>,nsid=<nsid>,\
  *              zoned=<true|false[optional]>
+ *      -device nvme-subsys,id=<subsys_id>
  *
  * Note cmb_size_mb denotes size of CMB in MB. CMB is assumed to be at
  * offset 0 in BAR2 and supports only WDS, RDS and SQS for now. By default, the
@@ -38,6 +39,8 @@ 
  *
  * The PMR will use BAR 4/5 exclusively.
  *
+ * To place controller(s) and namespace(s) to a subsystem, then provide
+ * nvme-subsys device as above.
  *
  * nvme device parameters
  * ~~~~~~~~~~~~~~~~~~~~~~
diff --git a/hw/block/meson.build b/hw/block/meson.build
index 602ca6c8541d..83ea2d37978d 100644
--- a/hw/block/meson.build
+++ b/hw/block/meson.build
@@ -13,7 +13,7 @@  softmmu_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80.c'))
 softmmu_ss.add(when: 'CONFIG_SWIM', if_true: files('swim.c'))
 softmmu_ss.add(when: 'CONFIG_XEN', if_true: files('xen-block.c'))
 softmmu_ss.add(when: 'CONFIG_SH4', if_true: files('tc58128.c'))
-softmmu_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('nvme.c', 'nvme-ns.c'))
+softmmu_ss.add(when: 'CONFIG_NVME_PCI', if_true: files('nvme.c', 'nvme-ns.c', 'nvme-subsys.c'))
 
 specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c'))
 specific_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk.c'))