diff mbox series

[RFC,13/13] hw/nvme: add attached-namespaces prop

Message ID 20210914203737.182571-14-its@irrelevant.dk
State New
Headers show
Series hw/nvme: experimental user-creatable objects | expand

Commit Message

Klaus Jensen Sept. 14, 2021, 8:37 p.m. UTC
From: Klaus Jensen <k.jensen@samsung.com>

Add a runtime property to get a list of attached namespaces per
controller.

Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
---
 hw/nvme/ctrl.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
diff mbox series

Patch

diff --git a/hw/nvme/ctrl.c b/hw/nvme/ctrl.c
index 04e564ad6be6..ed867384e40a 100644
--- a/hw/nvme/ctrl.c
+++ b/hw/nvme/ctrl.c
@@ -6746,6 +6746,27 @@  static void nvme_set_smart_warning(Object *obj, Visitor *v, const char *name,
     }
 }
 
+static void get_attached_namespaces(Object *obj, Visitor *v, const char *name,
+                                    void *opaque, Error **errp)
+{
+    NvmeState *n = NVME_STATE(obj);
+    strList *paths = NULL;
+    strList **tail = &paths;
+    int nsid;
+
+    for (nsid = 1; nsid <= NVME_MAX_NAMESPACES; nsid++) {
+        NvmeNamespace *ns = nvme_ns(n, nsid);
+        if (!ns) {
+            continue;
+        }
+
+        QAPI_LIST_APPEND(tail, object_get_canonical_path(OBJECT(ns)));
+    }
+
+    visit_type_strList(v, name, &paths, errp);
+    qapi_free_strList(paths);
+}
+
 static const VMStateDescription nvme_vmstate = {
     .name = "nvme",
     .unmigratable = 1,
@@ -6771,6 +6792,9 @@  static void nvme_state_instance_init(Object *obj)
     object_property_add(obj, "smart_critical_warning", "uint8",
                         nvme_get_smart_warning,
                         nvme_set_smart_warning, NULL, NULL);
+
+    object_property_add(obj, "attached-namespaces", "str",
+                        get_attached_namespaces, NULL, NULL, NULL);
 }
 
 static const TypeInfo nvme_state_info = {