Skip to contentSkip to conversation

hw/block/nvme: support ANA

PATCH In review Minwoo Im 1 participant 4 messages Feb 14, 2021 – Feb 26, 2021

lore
Share & tools
lore

Minwoo Im

author
#0 lore raw

cover hw/block/nvme: support ANA

Hello,

This series is to support Asymmetric Namespace Access(ANA).

ana parameter to the nvme-subsys device will turn all the controllers in the subsystem to support multipath I/O with ANA. Once ana is enabled, nvme-ns device can have ana.grpid for the ANA group ID. All this information will be reported as a log information via Get Log Page command of ANA page.

But, this is just for ANA state considered, not including any transitions for ANA states between controllers and namespaces. Therefore, the second patch introduced an interface to transite the ANA state for a given ANA group via HMP command. nvme_ana_inject_state command will inject a given state to the given ANA group.

The following example breaks the path to the namespace(nsid=1) by chainging the ANA group(ana.grpid=1) state to INACCESSIBLE. Once this state is injected by HMP interface, Asynchronous Event Notifier(AEN) will be reported to the host for ANA change. Then host will read the log page again and find a path to the namespace(nsid=1) not through the nvme0 controller: nvme controller will be taken. Then all the I/O heading to namespace(nsid=1) will be routed to the nvme1 controller.

Example:

NVMe subsystem topology

    -device nvme-subsys,id=subsys0,ana=true \
    -device nvme,serial=foo,id=nvme0,subsys=subsys0 \
    -device nvme,serial=bar,id=nvme1,subsys=subsys0 \
    -device nvme-ns,id=ns1,drive=drv10,nsid=1,subsys=subsys0,ana.grpid=1 \
    -device nvme-ns,id=ns2,drive=drv11,nsid=2,subsys=subsys0,ana.grpid=2 \

ANA state transition (HMP command)

(qemu) nvme_ana_inject_state nvme0 1 inaccessible
nvme0: ANA state inaccessible(3) injected

Thanks,

Minwoo Im (2):
hw/block/nvme: support Asymmetric Namespace Access(ANA) hw/block/nvme: add 'nvme_ana_inject_state' HMP command

 hmp-commands.hx        |  13 +++
 hw/block/nvme-ns.c     |  26 +++++
 hw/block/nvme-ns.h     |   3 +
 hw/block/nvme-subsys.c |   6 ++
 hw/block/nvme-subsys.h |   6 ++
 hw/block/nvme.c        | 240 ++++++++++++++++++++++++++++++++++++++++-
 hw/block/nvme.h        |  26 +++++
 include/block/nvme.h   |  51 ++++++++-
 include/monitor/hmp.h  |   1 +
 9 files changed, 369 insertions(+), 3 deletions(-)
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/2 hw/block/nvme: support Asymmetric Namespace Access(ANA)

Recently we have been able to introduce multipath I/O with namespace sharing with a single host. One of the major feature for the multipath I/O is Asymmetric Namespace Access: so-called ANA.

Also, the multipath I/O is one of the most major path for the host system where this feature addition might be helpful to debug for.

This patch introduced ANA scheme to the nvme-subsys, nvme and nvme-ns device. ana device parameter should be given to true if want want to support ANA feature for all controllers in the subsystem:

-device nvme-subsys,id=subsys0,ana=true

This patch also introduced ANA Group which is defined in 8.20.2 ANA Groups in NVMe 1.4b spec. ANA Group can be specified by the user with ana.grpid parameter (non-zero value) to nvme-ns device:

-device nvme-ns,id=ns1,drv=drv1,subsys=subsys0,ana.grpid=1

These relationships are communicated with the host by Get Log Page command for the ANA information. The ANA log information is retrieved based on the relationship between controller and namespace with ANA group.

This patch does not contain the ANA state transition by the device itself. The following patch will support the ANA state transition from the device side.

---
 hw/block/nvme-ns.c     |  26 ++++++++
 hw/block/nvme-ns.h     |   3 +
 hw/block/nvme-subsys.c |   6 ++
 hw/block/nvme-subsys.h |   6 ++
 hw/block/nvme.c        | 147 ++++++++++++++++++++++++++++++++++++++++-
 hw/block/nvme.h        |  25 +++++++
 include/block/nvme.h   |  50 +++++++++++++-
 7 files changed, 260 insertions(+), 3 deletions(-)
hw/block/nvme-ns.c +26 -0
index 0e8760020483..1bfc50eb1035 100644
@@ -75,6 +75,31 @@ static int nvme_ns_init(NvmeNamespace *ns, Error **errp)
     return 0;
 }
 
+int nvme_ns_post_init(NvmeCtrl *n, NvmeNamespace *ns, Error **errp)
+{
+    NvmeIdNs *id_ns = &ns->id_ns;
+
+    if (n->subsys && !n->subsys->params.ana && ns->params.anagrpid) {
+        error_setg(errp, "anagrpid needs 'ana=true' in nvme subsystem");
+        return -1;
+    }
+
+    if (ns->params.anagrpid && !nvme_ns_shared(ns)) {
+        error_setg(errp, "anagrpid needs nvme-ns device shared");
+        return -1;
+    }
+
+    if (ns->params.anagrpid > n->id_ctrl.anagrpmax) {
+        error_setg(errp,
+                   "anagrpid should be less than %u", n->id_ctrl.anagrpmax);
+        return -1;
+    }
+
+    id_ns->anagrpid = ns->params.anagrpid;
+
+    return 0;
+}
+
 static int nvme_ns_init_blk(NvmeNamespace *ns, Error **errp)
 {
     bool read_only;
@@ -417,6 +442,7 @@ static Property nvme_ns_props[] = {
                        params.max_open_zones, 0),
     DEFINE_PROP_UINT32("zoned.descr_ext_size", NvmeNamespace,
                        params.zd_extension_size, 0),
+    DEFINE_PROP_UINT32("ana.grpid", NvmeNamespace, params.anagrpid, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
 
hw/block/nvme-ns.h +3 -0
index 7af6884862b5..b3ca6176f4ce 100644
@@ -40,8 +40,10 @@ typedef struct NvmeNamespaceParams {
     uint32_t max_active_zones;
     uint32_t max_open_zones;
     uint32_t zd_extension_size;
+    uint32_t anagrpid;
 } NvmeNamespaceParams;
 
+typedef struct NvmeAna NvmeAna;
 typedef struct NvmeNamespace {
     DeviceState  parent_obj;
     BlockConf    blkconf;
@@ -185,6 +187,7 @@ static inline void nvme_aor_dec_active(NvmeNamespace *ns)
     assert(ns->nr_active_zones >= 0);
 }
 
+int nvme_ns_post_init(NvmeCtrl *n, NvmeNamespace *ns, Error **errp);
 int nvme_ns_setup(NvmeNamespace *ns, Error **errp);
 void nvme_ns_drain(NvmeNamespace *ns);
 void nvme_ns_shutdown(NvmeNamespace *ns);
hw/block/nvme-subsys.c +6 -0
index 641de33e99fc..72fcf4cc6966 100644
@@ -81,6 +81,11 @@ static void nvme_subsys_realize(DeviceState *dev, Error **errp)
     nvme_subsys_setup(subsys);
 }
 
+static Property nvme_subsys_props[] = {
+    DEFINE_PROP_BOOL("ana", NvmeSubsystem, params.ana, false),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static void nvme_subsys_class_init(ObjectClass *oc, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(oc);
@@ -89,6 +94,7 @@ static void nvme_subsys_class_init(ObjectClass *oc, void *data)
 
     dc->realize = nvme_subsys_realize;
     dc->desc = "Virtual NVMe subsystem";
+    device_class_set_props(dc, nvme_subsys_props);
 }
 
 static const TypeInfo nvme_subsys_info = {
hw/block/nvme-subsys.h +6 -0
index ccf6a71398d3..7d177312e554 100644
@@ -16,6 +16,10 @@
 #define NVME_SUBSYS_MAX_CTRLS   32
 #define NVME_SUBSYS_MAX_NAMESPACES  32
 
+typedef struct NvmeSubsystemParams {
+    bool     ana;
+} NvmeSubsystemParams;
+
 typedef struct NvmeCtrl NvmeCtrl;
 typedef struct NvmeNamespace NvmeNamespace;
 typedef struct NvmeSubsystem {
@@ -24,6 +28,8 @@ typedef struct NvmeSubsystem {
 
     NvmeCtrl    *ctrls[NVME_SUBSYS_MAX_CTRLS];
     NvmeNamespace *namespaces[NVME_SUBSYS_MAX_NAMESPACES];
+
+    NvmeSubsystemParams params;
 } NvmeSubsystem;
 
 int nvme_subsys_register_ctrl(NvmeCtrl *n, Error **errp);
hw/block/nvme.c +146 -1

222 lines not on this page · raw message

hw/block/nvme.h +25 -0
index cb2b5175f1a1..842245d0a845 100644
@@ -126,6 +126,24 @@ typedef struct NvmeFeatureVal {
     uint32_t    async_config;
 } NvmeFeatureVal;
 
+typedef struct NvmeAna {
+    uint32_t        grpid;
+    uint8_t         state;
+#define NVME_MAX_ANA_GROUP          (NVME_MAX_NAMESPACES)
+#define NVME_ANA_NSID_BITMAP_SIZE   (NVME_MAX_ANA_GROUP + 1)
+    DECLARE_BITMAP(nsids, NVME_ANA_NSID_BITMAP_SIZE);
+} NvmeAna;
+
+static inline void nvme_ana_register_ns(NvmeAna *ana, uint32_t nsid)
+{
+    set_bit(nsid, ana->nsids);
+}
+
+static inline bool nvme_ana_has_ns(NvmeAna *ana, uint32_t nsid)
+{
+    return test_bit(nsid, ana->nsids);
+}
+
 typedef struct NvmeCtrl {
     PCIDevice    parent_obj;
     MemoryRegion bar0;
@@ -174,6 +192,8 @@ typedef struct NvmeCtrl {
     uint8_t     zasl;
 
     NvmeSubsystem   *subsys;
+    NvmeAna         ana[NVME_MAX_NAMESPACES + 1];
+    uint64_t        ana_change_count;
 
     NvmeNamespace   namespace;
     NvmeNamespace   *namespaces[NVME_MAX_NAMESPACES];
@@ -208,6 +228,11 @@ static inline NvmeCtrl *nvme_ctrl(NvmeRequest *req)
     return sq->ctrl;
 }
 
+static inline long nvme_ana_nr_ns(NvmeAna *ana)
+{
+    return bitmap_count_one(ana->nsids, NVME_ANA_NSID_BITMAP_SIZE);
+}
+
 int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp);
 
 #endif /* HW_NVME_H */
include/block/nvme.h +48 -2

98 lines not on this page · raw message

Signature · 1 line
2.17.1
author
#2 lore raw

PATCH 2/2 hw/block/nvme: add 'nvme_ana_inject_state' HMP command

In reply to Minwoo Im

Human Monitor Interface(HMP) is there for easy human debugging. This patch added a HMP command 'nvme_ana_inject_state'. This can be executed from the QEMU monitor. This command will have the following syntax:

	# nvme_ana_inject_state <nvme-id> <anagrpid> <state>
	(qemu) nvme_ana_inject_state nvme0 1 inaccessible

The example above will make ANA group #1 transitioned to ANA_INACCESSIBLE state for nvme0 controller device. Additionally, device will notify to the host that ANA has been changed via Asynchronous Event Notifier(AEN). Then the host will figure out another path to I/O for the namespace by reading the log page for ANA information again, and this is what we call the multipath I/O.

This feature is good to debug the host multipath I/O by controlling the device ANA group state transition. The path-related errors can be tested and debugged by this feature. Also, the HMP command interafce will make us not to build QEMU itself again to control things in device.

This interface supports Persistent Loss state transition, but it's not going to be persistent: volatile of qemu perspective.

Cc Dr . David Alan Gilbert <[email protected]>
---
 hmp-commands.hx       | 13 ++++++
 hw/block/nvme.c       | 93 +++++++++++++++++++++++++++++++++++++++++++
 hw/block/nvme.h       |  1 +
 include/block/nvme.h  |  1 +
 include/monitor/hmp.h |  1 +
 5 files changed, 109 insertions(+)
hmp-commands.hx +13 -0
index d4001f9c5dc6..5a099191429d 100644
@@ -1307,6 +1307,19 @@ SRST
   Inject PCIe AER error
 ERST
 
+    {
+        .name       = "nvme_ana_inject_state",
+        .args_type  = "id:s,grpid:i,state:s",
+        .params     = "id grpid [optimized|non-optimized|inaccessible|change]",
+        .help       = "inject ANA state",
+        .cmd        = hmp_nvme_ana_inject_state,
+    },
+
+SRST
+``nvme_ana_inject_state``
+  Inject ANA state to NVMe subsystem
+ERST
+
     {
         .name       = "netdev_add",
         .args_type  = "netdev:O",
hw/block/nvme.c +93 -0

117 lines not on this page · raw message

hw/block/nvme.h +1 -0
index 842245d0a845..1a1a022dad0a 100644
@@ -234,5 +234,6 @@ static inline long nvme_ana_nr_ns(NvmeAna *ana)
 }
 
 int nvme_register_namespace(NvmeCtrl *n, NvmeNamespace *ns, Error **errp);
+void hmp_nvme_ana_inject_state(Monitor *mon, const QDict *qdict);
 
 #endif /* HW_NVME_H */
include/block/nvme.h +1 -0
index c51fbf845f5a..b27dd8eab7e9 100644
@@ -771,6 +771,7 @@ enum NvmeAsyncEventRequest {
     NVME_AER_INFO_SMART_RELIABILITY         = 0,
     NVME_AER_INFO_SMART_TEMP_THRESH         = 1,
     NVME_AER_INFO_SMART_SPARE_THRESH        = 2,
+    NVME_AER_INFO_ANA_CHANGE                = 3,
 };
 
 typedef struct QEMU_PACKED NvmeAerResult {
include/monitor/hmp.h +1 -0
index ed2913fd18e8..cbeaf7935900 100644
@@ -133,5 +133,6 @@ void hmp_info_replay(Monitor *mon, const QDict *qdict);
 void hmp_replay_break(Monitor *mon, const QDict *qdict);
 void hmp_replay_delete_break(Monitor *mon, const QDict *qdict);
 void hmp_replay_seek(Monitor *mon, const QDict *qdict);
+void hmp_nvme_ana_inject_state(Monitor *mon, const QDict *qdict);
 
 #endif
Signature · 1 line
2.17.1
author
#3 lore raw

Re: [PATCH 2/2] hw/block/nvme: add 'nvme_ana_inject_state' HMP command

Quoted 19 lines · Minwoo Im

Human Monitor Interface(HMP) is there for easy human debugging. This patch added a HMP command 'nvme_ana_inject_state'. This can be executed from the QEMU monitor. This command will have the following syntax:

	# nvme_ana_inject_state <nvme-id> <anagrpid> <state>
	(qemu) nvme_ana_inject_state nvme0 1 inaccessible

The example above will make ANA group #1 transitioned to ANA_INACCESSIBLE state for nvme0 controller device. Additionally, device will notify to the host that ANA has been changed via Asynchronous Event Notifier(AEN). Then the host will figure out another path to I/O for the namespace by reading the log page for ANA information again, and this is what we call the multipath I/O.

This feature is good to debug the host multipath I/O by controlling the device ANA group state transition. The path-related errors can be tested and debugged by this feature. Also, the HMP command interafce will make us not to build QEMU itself again to control things in device.

Quoted 5 lines

This interface supports Persistent Loss state transition, but it's not going to be persistent: volatile of qemu perspective.

Cc Dr . David Alan Gilbert <[email protected]>

Hello Keith,

Do you have any comments about this injection method? As discussed ealier, I've tried to introduce a natural way to control some of device status like ANA state which device can behave properly.

It would be great if I can have your feedback on this :)

Thanks!