Skip to contentSkip to conversation

Add HMP command "info memory-devices"

PATCH Superseded Zhu Guihua 4 participants 11 messages Sep 15, 2014 – Sep 23, 2014

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Zhu Guihua

author
#0 lore raw

PATCH v4 1/1 Add HMP command "info memory-devices"

Provides HMP equivalent of QMP query-memory-devices command.

---

Changes since v3:
- optimize the time to print memory devices' information.
- change output format of di->addr and di->size.

Changes since v2:
- print address in hex.
- change the loop control from while to for.
- modify some variables' name.
- optimize the time to print memory devices' kind.

Changes since v1:
- fix bug that accessing info->dimm when MemoryDeviceInfo is not PCDIMMDevice.
- use enum to replace "dimm", and lookup typename in MemoryDeviceInfoKind_lookup[] instead of opencodding it.

 hmp-commands.hx |  2 ++
 hmp.c           | 38 ++++++++++++++++++++++++++++++++++++++
 hmp.h           |  1 +
 monitor.c       |  7 +++++++
 4 files changed, 48 insertions(+)
hmp-commands.hx +2 -0
index f859f8d..0b1a4f7 100644
@@ -1778,6 +1778,8 @@ show qdev device model list
 show roms
 @item info tpm
 show the TPM device
+@item info memory-devices
+show the memory devices
 @end table
 ETEXI
 
hmp.c +38 -0
index 40a90da..feefeb4 100644
@@ -1718,3 +1718,41 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
 
     qapi_free_MemdevList(memdev_list);
 }
+
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
+    MemoryDeviceInfoList *info;
+    MemoryDeviceInfo *value;
+    PCDIMMDeviceInfo *di;
+
+    for (info = info_list; info; info = info->next) {
+        value = info->value;
+
+        if (value) {
+            switch (value->kind) {
+            case MEMORY_DEVICE_INFO_KIND_DIMM:
+                di = value->dimm;
+
+                monitor_printf(mon, "Memory device [%s]: %s\n",
+                               MemoryDeviceInfoKind_lookup[value->kind],
+                               di->id);
+                monitor_printf(mon, "  addr: 0x%" PRIx64 "\n", di->addr);
+                monitor_printf(mon, "  slot: %" PRId64 "\n", di->slot);
+                monitor_printf(mon, "  node: %" PRId64 "\n", di->node);
+                monitor_printf(mon, "  size: %" PRIu64 "\n", di->size);
+                monitor_printf(mon, "  memdev: %s\n", di->memdev);
+                monitor_printf(mon, "  hotplugged: %s\n",
+                               di->hotplugged ? "true" : "false");
+                monitor_printf(mon, "  hotpluggable: %s\n",
+                               di->hotpluggable ? "true" : "false");
+                break;
+            default:
+                break;
+            }
+        }
+    }
+
+    qapi_free_MemoryDeviceInfoList(info_list);
+}
hmp.h +1 -0
index 4fd3c4a..4bb5dca 100644
@@ -94,6 +94,7 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict);
 void hmp_object_add(Monitor *mon, const QDict *qdict);
 void hmp_object_del(Monitor *mon, const QDict *qdict);
 void hmp_info_memdev(Monitor *mon, const QDict *qdict);
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict);
 void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
monitor.c +7 -0
index 34cee74..fe88e0d 100644
@@ -2921,6 +2921,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.cmd = hmp_info_memdev,
     },
     {
+        .name       = "memory-devices",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show memory devices",
+        .mhandler.cmd = hmp_info_memory_devices,
+    },
+    {
         .name       = NULL,
     },
 };
Signature · 1 line
1.9.3
author
#1 lore raw

Hi,

Could anyone help to review this patch?
If there was no problem, could help to merge it?

thanks!
zhu

Quoted 114 lines · Zhu Guihua

Provides HMP equivalent of QMP query-memory-devices command.

---

Changes since v3:
- optimize the time to print memory devices' information.
- change output format of di->addr and di->size.

Changes since v2:
- print address in hex.
- change the loop control from while to for.
- modify some variables' name.
- optimize the time to print memory devices' kind.

Changes since v1:
- fix bug that accessing info->dimm when MemoryDeviceInfo is not PCDIMMDevice.
- use enum to replace "dimm", and lookup typename in MemoryDeviceInfoKind_lookup[] instead of opencodding it.

 hmp-commands.hx |  2 ++
 hmp.c           | 38 ++++++++++++++++++++++++++++++++++++++
 hmp.h           |  1 +
 monitor.c       |  7 +++++++
 4 files changed, 48 insertions(+)
hmp-commands.hx +2 -0
index f859f8d..0b1a4f7 100644
@@ -1778,6 +1778,8 @@ show qdev device model list
 show roms
 @item info tpm
 show the TPM device
+@item info memory-devices
+show the memory devices
 @end table
 ETEXI
 
hmp.c +38 -0
index 40a90da..feefeb4 100644
@@ -1718,3 +1718,41 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
 
     qapi_free_MemdevList(memdev_list);
 }
+
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
+    MemoryDeviceInfoList *info;
+    MemoryDeviceInfo *value;
+    PCDIMMDeviceInfo *di;
+
+    for (info = info_list; info; info = info->next) {
+        value = info->value;
+
+        if (value) {
+            switch (value->kind) {
+            case MEMORY_DEVICE_INFO_KIND_DIMM:
+                di = value->dimm;
+
+                monitor_printf(mon, "Memory device [%s]: %s\n",
+                               MemoryDeviceInfoKind_lookup[value->kind],
+                               di->id);
+                monitor_printf(mon, "  addr: 0x%" PRIx64 "\n", di->addr);
+                monitor_printf(mon, "  slot: %" PRId64 "\n", di->slot);
+                monitor_printf(mon, "  node: %" PRId64 "\n", di->node);
+                monitor_printf(mon, "  size: %" PRIu64 "\n", di->size);
+                monitor_printf(mon, "  memdev: %s\n", di->memdev);
+                monitor_printf(mon, "  hotplugged: %s\n",
+                               di->hotplugged ? "true" : "false");
+                monitor_printf(mon, "  hotpluggable: %s\n",
+                               di->hotpluggable ? "true" : "false");
+                break;
+            default:
+                break;
+            }
+        }
+    }
+
+    qapi_free_MemoryDeviceInfoList(info_list);
+}
hmp.h +1 -0
index 4fd3c4a..4bb5dca 100644
@@ -94,6 +94,7 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict);
 void hmp_object_add(Monitor *mon, const QDict *qdict);
 void hmp_object_del(Monitor *mon, const QDict *qdict);
 void hmp_info_memdev(Monitor *mon, const QDict *qdict);
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict);
 void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
monitor.c +7 -0
index 34cee74..fe88e0d 100644
@@ -2921,6 +2921,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.cmd = hmp_info_memdev,
     },
     {
+        .name       = "memory-devices",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show memory devices",
+        .mhandler.cmd = hmp_info_memory_devices,
+    },
+    {
         .name       = NULL,
     },
 };
Reviewed-by
#2 lore raw
Quoted 67 lines · On Thu, 18 Sep 2014 16:09:32 +0800 zhugh <[email protected]> wrote:

Hi,

Could anyone help to review this patch?
If there was no problem, could help to merge it?

thanks!
zhu

Quoted 58 lines · Zhu Guihua

Provides HMP equivalent of QMP query-memory-devices command.

---

Changes since v3:
- optimize the time to print memory devices' information.
- change output format of di->addr and di->size.

Changes since v2:
- print address in hex.
- change the loop control from while to for.
- modify some variables' name.
- optimize the time to print memory devices' kind.

Changes since v1:
- fix bug that accessing info->dimm when MemoryDeviceInfo is not PCDIMMDevice.
- use enum to replace "dimm", and lookup typename in MemoryDeviceInfoKind_lookup[] instead of opencodding it.

 hmp-commands.hx |  2 ++
 hmp.c           | 38 ++++++++++++++++++++++++++++++++++++++
 hmp.h           |  1 +
 monitor.c       |  7 +++++++
 4 files changed, 48 insertions(+)
hmp-commands.hx +2 -0
index f859f8d..0b1a4f7 100644
@@ -1778,6 +1778,8 @@ show qdev device model list
 show roms
 @item info tpm
 show the TPM device
+@item info memory-devices
+show the memory devices
 @end table
 ETEXI
 
hmp.c +12 -0
index 40a90da..feefeb4 100644
@@ -1718,3 +1718,41 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
 
     qapi_free_MemdevList(memdev_list);
 }
+
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
+    MemoryDeviceInfoList *info;
+    MemoryDeviceInfo *value;
+    PCDIMMDeviceInfo *di;
+
+    for (info = info_list; info; info = info->next) {
+        value = info->value;
+
Quoted 8 lines

hmp.c void hmp_info_memdev(Monitor *mon, const QDict *qdict) · line 1740

Quoted 8 lines
hmp.c +8 -0
+        if (value) {
+            switch (value->kind) {
+            case MEMORY_DEVICE_INFO_KIND_DIMM:
+                di = value->dimm;
+
+                monitor_printf(mon, "Memory device [%s]: %s\n",
+                               MemoryDeviceInfoKind_lookup[value->kind],
+                               di->id);

'id' might be null, here is what user will see:

Memory device [dimm]: (null)

I'd suggest to replace (null) with "" as it is done elsewhere.

With that fixed

Quoted 50 lines
Quoted 48 lines
hmp.c +18 -0
+                monitor_printf(mon, "  addr: 0x%" PRIx64 "\n", di->addr);
+                monitor_printf(mon, "  slot: %" PRId64 "\n", di->slot);
+                monitor_printf(mon, "  node: %" PRId64 "\n", di->node);
+                monitor_printf(mon, "  size: %" PRIu64 "\n", di->size);
+                monitor_printf(mon, "  memdev: %s\n", di->memdev);
+                monitor_printf(mon, "  hotplugged: %s\n",
+                               di->hotplugged ? "true" : "false");
+                monitor_printf(mon, "  hotpluggable: %s\n",
+                               di->hotpluggable ? "true" : "false");
+                break;
+            default:
+                break;
+            }
+        }
+    }
+
+    qapi_free_MemoryDeviceInfoList(info_list);
+}
hmp.h +1 -0
index 4fd3c4a..4bb5dca 100644
@@ -94,6 +94,7 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict);
 void hmp_object_add(Monitor *mon, const QDict *qdict);
 void hmp_object_del(Monitor *mon, const QDict *qdict);
 void hmp_info_memdev(Monitor *mon, const QDict *qdict);
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict);
 void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
monitor.c +7 -0
index 34cee74..fe88e0d 100644
@@ -2921,6 +2921,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.cmd = hmp_info_memdev,
     },
     {
+        .name       = "memory-devices",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show memory devices",
+        .mhandler.cmd = hmp_info_memory_devices,
+    },
+    {
         .name       = NULL,
     },
 };
#3 lore raw
Quoted 80 lines · On Fri, 19 Sep 2014 15:30:19 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 67 lines · On Thu, 18 Sep 2014 16:09:32 +0800 zhugh <[email protected]> wrote:

Hi,

Could anyone help to review this patch?
If there was no problem, could help to merge it?

thanks!
zhu

Quoted 58 lines · Zhu Guihua

Provides HMP equivalent of QMP query-memory-devices command.

---

Changes since v3:
- optimize the time to print memory devices' information.
- change output format of di->addr and di->size.

Changes since v2:
- print address in hex.
- change the loop control from while to for.
- modify some variables' name.
- optimize the time to print memory devices' kind.

Changes since v1:
- fix bug that accessing info->dimm when MemoryDeviceInfo is not PCDIMMDevice.
- use enum to replace "dimm", and lookup typename in MemoryDeviceInfoKind_lookup[] instead of opencodding it.

 hmp-commands.hx |  2 ++
 hmp.c           | 38 ++++++++++++++++++++++++++++++++++++++
 hmp.h           |  1 +
 monitor.c       |  7 +++++++
 4 files changed, 48 insertions(+)
hmp-commands.hx +2 -0
index f859f8d..0b1a4f7 100644
@@ -1778,6 +1778,8 @@ show qdev device model list
 show roms
 @item info tpm
 show the TPM device
+@item info memory-devices
+show the memory devices
 @end table
 ETEXI
 
hmp.c +12 -0
index 40a90da..feefeb4 100644
@@ -1718,3 +1718,41 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
 
     qapi_free_MemdevList(memdev_list);
 }
+
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
+    MemoryDeviceInfoList *info;
+    MemoryDeviceInfo *value;
+    PCDIMMDeviceInfo *di;
+
+    for (info = info_list; info; info = info->next) {
+        value = info->value;
+
Quoted 8 lines

hmp.c void hmp_info_memdev(Monitor *mon, const QDict *qdict) · line 1740

Quoted 8 lines
hmp.c +8 -0
+        if (value) {
+            switch (value->kind) {
+            case MEMORY_DEVICE_INFO_KIND_DIMM:
+                di = value->dimm;
+
+                monitor_printf(mon, "Memory device [%s]: %s\n",
+                               MemoryDeviceInfoKind_lookup[value->kind],
+                               di->id);

'id' might be null, here is what user will see:

Quoted 3 lines

Memory device [dimm]: (null)

I'd suggest to replace (null) with "" as it is done elsewhere.

Is the fix below what you're looking for? If it is I can apply it myself:

hmp.c +1 -1
index feefeb4..14cb9f8 100644
@@ -1737,7 +1737,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
 
                 monitor_printf(mon, "Memory device [%s]: %s\n",
                                MemoryDeviceInfoKind_lookup[value->kind],
-                               di->id);
+                               di->id ? di->id : "");
                 monitor_printf(mon, "  addr: 0x%" PRIx64 "\n", di->addr);
                 monitor_printf(mon, "  slot: %" PRId64 "\n", di->slot);
                 monitor_printf(mon, "  node: %" PRId64 "\n", di->node);
Quoted 55 lines

With that fixed

Quoted 50 lines
Quoted 48 lines
hmp.c +18 -0
+                monitor_printf(mon, "  addr: 0x%" PRIx64 "\n", di->addr);
+                monitor_printf(mon, "  slot: %" PRId64 "\n", di->slot);
+                monitor_printf(mon, "  node: %" PRId64 "\n", di->node);
+                monitor_printf(mon, "  size: %" PRIu64 "\n", di->size);
+                monitor_printf(mon, "  memdev: %s\n", di->memdev);
+                monitor_printf(mon, "  hotplugged: %s\n",
+                               di->hotplugged ? "true" : "false");
+                monitor_printf(mon, "  hotpluggable: %s\n",
+                               di->hotpluggable ? "true" : "false");
+                break;
+            default:
+                break;
+            }
+        }
+    }
+
+    qapi_free_MemoryDeviceInfoList(info_list);
+}
hmp.h +1 -0
index 4fd3c4a..4bb5dca 100644
@@ -94,6 +94,7 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict);
 void hmp_object_add(Monitor *mon, const QDict *qdict);
 void hmp_object_del(Monitor *mon, const QDict *qdict);
 void hmp_info_memdev(Monitor *mon, const QDict *qdict);
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict);
 void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
monitor.c +7 -0
index 34cee74..fe88e0d 100644
@@ -2921,6 +2921,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.cmd = hmp_info_memdev,
     },
     {
+        .name       = "memory-devices",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show memory devices",
+        .mhandler.cmd = hmp_info_memory_devices,
+    },
+    {
         .name       = NULL,
     },
 };
author
#4 lore raw
Quoted 83 lines · Luiz Capitulino
Quoted 80 lines · On Fri, 19 Sep 2014 15:30:19 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 67 lines · On Thu, 18 Sep 2014 16:09:32 +0800 zhugh <[email protected]> wrote:

Hi,

Could anyone help to review this patch?
If there was no problem, could help to merge it?

thanks!
zhu

Quoted 58 lines · Zhu Guihua

Provides HMP equivalent of QMP query-memory-devices command.

---

Changes since v3:
- optimize the time to print memory devices' information.
- change output format of di->addr and di->size.

Changes since v2:
- print address in hex.
- change the loop control from while to for.
- modify some variables' name.
- optimize the time to print memory devices' kind.

Changes since v1:
- fix bug that accessing info->dimm when MemoryDeviceInfo is not PCDIMMDevice.
- use enum to replace "dimm", and lookup typename in MemoryDeviceInfoKind_lookup[] instead of opencodding it.

 hmp-commands.hx |  2 ++
 hmp.c           | 38 ++++++++++++++++++++++++++++++++++++++
 hmp.h           |  1 +
 monitor.c       |  7 +++++++
 4 files changed, 48 insertions(+)
hmp-commands.hx +2 -0
index f859f8d..0b1a4f7 100644
@@ -1778,6 +1778,8 @@ show qdev device model list
 show roms
 @item info tpm
 show the TPM device
+@item info memory-devices
+show the memory devices
 @end table
 ETEXI
 
hmp.c +12 -0
index 40a90da..feefeb4 100644
@@ -1718,3 +1718,41 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
 
     qapi_free_MemdevList(memdev_list);
 }
+
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
+    MemoryDeviceInfoList *info;
+    MemoryDeviceInfo *value;
+    PCDIMMDeviceInfo *di;
+
+    for (info = info_list; info; info = info->next) {
+        value = info->value;
+
Quoted 8 lines

hmp.c void hmp_info_memdev(Monitor *mon, const QDict *qdict) · line 1740

Quoted 8 lines
hmp.c +8 -0
+        if (value) {
+            switch (value->kind) {
+            case MEMORY_DEVICE_INFO_KIND_DIMM:
+                di = value->dimm;
+
+                monitor_printf(mon, "Memory device [%s]: %s\n",
+                               MemoryDeviceInfoKind_lookup[value->kind],
+                               di->id);

'id' might be null, here is what user will see:

Quoted 5 lines
Quoted 3 lines

Memory device [dimm]: (null)

I'd suggest to replace (null) with "" as it is done elsewhere.

Is the fix below what you're looking for? If it is I can apply it myself:

Yes, I think the fix is what Igor expects. So could you apply the fix? If not, I can send patch v5 to fix the problem.

Quoted 70 lines
hmp.c +1 -1
index feefeb4..14cb9f8 100644
@@ -1737,7 +1737,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
 
                 monitor_printf(mon, "Memory device [%s]: %s\n",
                                MemoryDeviceInfoKind_lookup[value->kind],
-                               di->id);
+                               di->id ? di->id : "");
                 monitor_printf(mon, "  addr: 0x%" PRIx64 "\n", di->addr);
                 monitor_printf(mon, "  slot: %" PRId64 "\n", di->slot);
                 monitor_printf(mon, "  node: %" PRId64 "\n", di->node);
Quoted 55 lines

With that fixed

Quoted 50 lines
Quoted 48 lines
hmp.c +18 -0
+                monitor_printf(mon, "  addr: 0x%" PRIx64 "\n", di->addr);
+                monitor_printf(mon, "  slot: %" PRId64 "\n", di->slot);
+                monitor_printf(mon, "  node: %" PRId64 "\n", di->node);
+                monitor_printf(mon, "  size: %" PRIu64 "\n", di->size);
+                monitor_printf(mon, "  memdev: %s\n", di->memdev);
+                monitor_printf(mon, "  hotplugged: %s\n",
+                               di->hotplugged ? "true" : "false");
+                monitor_printf(mon, "  hotpluggable: %s\n",
+                               di->hotpluggable ? "true" : "false");
+                break;
+            default:
+                break;
+            }
+        }
+    }
+
+    qapi_free_MemoryDeviceInfoList(info_list);
+}
hmp.h +1 -0
index 4fd3c4a..4bb5dca 100644
@@ -94,6 +94,7 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict);
 void hmp_object_add(Monitor *mon, const QDict *qdict);
 void hmp_object_del(Monitor *mon, const QDict *qdict);
 void hmp_info_memdev(Monitor *mon, const QDict *qdict);
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict);
 void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
monitor.c +7 -0
index 34cee74..fe88e0d 100644
@@ -2921,6 +2921,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.cmd = hmp_info_memdev,
     },
     {
+        .name       = "memory-devices",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show memory devices",
+        .mhandler.cmd = hmp_info_memory_devices,
+    },
+    {
         .name       = NULL,
     },
 };
author
#5 lore raw
In reply to Luiz Capitulino
Quoted 83 lines · Luiz Capitulino
Quoted 80 lines · On Fri, 19 Sep 2014 15:30:19 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 67 lines · On Thu, 18 Sep 2014 16:09:32 +0800 zhugh <[email protected]> wrote:

Hi,

Could anyone help to review this patch?
If there was no problem, could help to merge it?

thanks!
zhu

Quoted 58 lines · Zhu Guihua

Provides HMP equivalent of QMP query-memory-devices command.

---

Changes since v3:
- optimize the time to print memory devices' information.
- change output format of di->addr and di->size.

Changes since v2:
- print address in hex.
- change the loop control from while to for.
- modify some variables' name.
- optimize the time to print memory devices' kind.

Changes since v1:
- fix bug that accessing info->dimm when MemoryDeviceInfo is not PCDIMMDevice.
- use enum to replace "dimm", and lookup typename in MemoryDeviceInfoKind_lookup[] instead of opencodding it.

 hmp-commands.hx |  2 ++
 hmp.c           | 38 ++++++++++++++++++++++++++++++++++++++
 hmp.h           |  1 +
 monitor.c       |  7 +++++++
 4 files changed, 48 insertions(+)
hmp-commands.hx +2 -0
index f859f8d..0b1a4f7 100644
@@ -1778,6 +1778,8 @@ show qdev device model list
 show roms
 @item info tpm
 show the TPM device
+@item info memory-devices
+show the memory devices
 @end table
 ETEXI
 
hmp.c +12 -0
index 40a90da..feefeb4 100644
@@ -1718,3 +1718,41 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
 
     qapi_free_MemdevList(memdev_list);
 }
+
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
+    MemoryDeviceInfoList *info;
+    MemoryDeviceInfo *value;
+    PCDIMMDeviceInfo *di;
+
+    for (info = info_list; info; info = info->next) {
+        value = info->value;
+
Quoted 8 lines

hmp.c void hmp_info_memdev(Monitor *mon, const QDict *qdict) · line 1740

Quoted 8 lines
hmp.c +8 -0
+        if (value) {
+            switch (value->kind) {
+            case MEMORY_DEVICE_INFO_KIND_DIMM:
+                di = value->dimm;
+
+                monitor_printf(mon, "Memory device [%s]: %s\n",
+                               MemoryDeviceInfoKind_lookup[value->kind],
+                               di->id);

'id' might be null, here is what user will see:

Quoted 5 lines
Quoted 3 lines

Memory device [dimm]: (null)

I'd suggest to replace (null) with "" as it is done elsewhere.

Is the fix below what you're looking for? If it is I can apply it myself:

I am sorry, I did not test this fix in my code last time. But your fix would print nothing when the id was null.
So I think the fix would like the below, could you apply it? Thanks!

hmp.c +0 -0
index feefeb4..39a6490 100644
@@ -1737,7 +1737,7 @@ void hmp_info_memory_devices(Monitor *mon, const

QDict *qdict)

                monitor_printf(mon, "Memory device [%s]: %s\n",
                               MemoryDeviceInfoKind_lookup[value->kind],
-                              di->id);
+                              di->id ? di->id : "\"\"");
                monitor_printf(mon, "  addr: 0x%" PRIx64 "\n",di->addr);
                monitor_printf(mon, "  slot: %" PRId64 "\n", di->slot);
                monitor_printf(mon, "  node: %" PRId64 "\n", di->node);
Quoted 70 lines
hmp.c +1 -1
index feefeb4..14cb9f8 100644
@@ -1737,7 +1737,7 @@ void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
 
                 monitor_printf(mon, "Memory device [%s]: %s\n",
                                MemoryDeviceInfoKind_lookup[value->kind],
-                               di->id);
+                               di->id ? di->id : "");
                 monitor_printf(mon, "  addr: 0x%" PRIx64 "\n", di->addr);
                 monitor_printf(mon, "  slot: %" PRId64 "\n", di->slot);
                 monitor_printf(mon, "  node: %" PRId64 "\n", di->node);
Quoted 55 lines

With that fixed

Quoted 50 lines
Quoted 48 lines
hmp.c +18 -0
+                monitor_printf(mon, "  addr: 0x%" PRIx64 "\n", di->addr);
+                monitor_printf(mon, "  slot: %" PRId64 "\n", di->slot);
+                monitor_printf(mon, "  node: %" PRId64 "\n", di->node);
+                monitor_printf(mon, "  size: %" PRIu64 "\n", di->size);
+                monitor_printf(mon, "  memdev: %s\n", di->memdev);
+                monitor_printf(mon, "  hotplugged: %s\n",
+                               di->hotplugged ? "true" : "false");
+                monitor_printf(mon, "  hotpluggable: %s\n",
+                               di->hotpluggable ? "true" : "false");
+                break;
+            default:
+                break;
+            }
+        }
+    }
+
+    qapi_free_MemoryDeviceInfoList(info_list);
+}
hmp.h +1 -0
index 4fd3c4a..4bb5dca 100644
@@ -94,6 +94,7 @@ void hmp_cpu_add(Monitor *mon, const QDict *qdict);
 void hmp_object_add(Monitor *mon, const QDict *qdict);
 void hmp_object_del(Monitor *mon, const QDict *qdict);
 void hmp_info_memdev(Monitor *mon, const QDict *qdict);
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict);
 void object_add_completion(ReadLineState *rs, int nb_args, const char *str);
 void object_del_completion(ReadLineState *rs, int nb_args, const char *str);
 void device_add_completion(ReadLineState *rs, int nb_args, const char *str);
monitor.c +7 -0
index 34cee74..fe88e0d 100644
@@ -2921,6 +2921,13 @@ static mon_cmd_t info_cmds[] = {
         .mhandler.cmd = hmp_info_memdev,
     },
     {
+        .name       = "memory-devices",
+        .args_type  = "",
+        .params     = "",
+        .help       = "show memory devices",
+        .mhandler.cmd = hmp_info_memory_devices,
+    },
+    {
         .name       = NULL,
     },
 };
#6 lore raw
Quoted 19 lines · zhugh
Quoted 18 lines · Luiz Capitulino
Quoted 15 lines · On Fri, 19 Sep 2014 15:30:19 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 12 lines · On Thu, 18 Sep 2014 16:09:32 +0800 zhugh <[email protected]> wrote:

Hi,

Could anyone help to review this patch?
If there was no problem, could help to merge it?

thanks!
zhu

Quoted 3 lines · Zhu Guihua

Provides HMP equivalent of QMP query-memory-devices command.

[...]

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 20 lines
Quoted 20 lines
hmp.c +12 -0
index 40a90da..feefeb4 100644
@@ -1718,3 +1718,41 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
 
     qapi_free_MemdevList(memdev_list);
 }
+
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
+    MemoryDeviceInfoList *info;
+    MemoryDeviceInfo *value;
+    PCDIMMDeviceInfo *di;
+
+    for (info = info_list; info; info = info->next) {
+        value = info->value;
+
Quoted 8 lines

hmp.c void hmp_info_memdev(Monitor *mon, const QDict *qdict) · line 1740

Quoted 8 lines
hmp.c +8 -0
+        if (value) {
+            switch (value->kind) {
+            case MEMORY_DEVICE_INFO_KIND_DIMM:
+                di = value->dimm;
+
+                monitor_printf(mon, "Memory device [%s]: %s\n",
+                               MemoryDeviceInfoKind_lookup[value->kind],
+                               di->id);

'id' might be null, here is what user will see:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Memory device [dimm]: (null)

I'd suggest to replace (null) with "" as it is done elsewhere.

Is the fix below what you're looking for? If it is I can apply it myself:

I am sorry, I did not test this fix in my code last time. But your fix would print nothing when the id was null.

Printing nothing when there's no ID has a certain logic to it :)

Quoted 16 lines

So I think the fix would like the below, could you apply it? Thanks!

hmp.c +1 -1
index feefeb4..39a6490 100644
@@ -1737,7 +1737,7 @@ void hmp_info_memory_devices(Monitor *mon, const
 QDict *qdict)
 
                monitor_printf(mon, "Memory device [%s]: %s\n",
                               MemoryDeviceInfoKind_lookup[value->kind],
-                              di->id);
+                              di->id ? di->id : "\"\"");
                monitor_printf(mon, "  addr: 0x%" PRIx64 "\n",di->addr);
                monitor_printf(mon, "  slot: %" PRId64 "\n", di->slot);
Quoted 1 line
                monitor_printf(mon, "  node: %" PRId64 "\n", di->node);

I'd stick to printing nothing.

#7 lore raw
Quoted 54 lines · On Mon, 22 Sep 2014 09:59:06 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 19 lines · zhugh
Quoted 18 lines · Luiz Capitulino
Quoted 15 lines · On Fri, 19 Sep 2014 15:30:19 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 12 lines · On Thu, 18 Sep 2014 16:09:32 +0800 zhugh <[email protected]> wrote:

Hi,

Could anyone help to review this patch?
If there was no problem, could help to merge it?

thanks!
zhu

Quoted 3 lines · Zhu Guihua

Provides HMP equivalent of QMP query-memory-devices command.

[...]

Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 20 lines
Quoted 20 lines
hmp.c +12 -0
index 40a90da..feefeb4 100644
@@ -1718,3 +1718,41 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
 
     qapi_free_MemdevList(memdev_list);
 }
+
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
+    MemoryDeviceInfoList *info;
+    MemoryDeviceInfo *value;
+    PCDIMMDeviceInfo *di;
+
+    for (info = info_list; info; info = info->next) {
+        value = info->value;
+
Quoted 8 lines

hmp.c void hmp_info_memdev(Monitor *mon, const QDict *qdict) · line 1740

Quoted 8 lines
hmp.c +8 -0
+        if (value) {
+            switch (value->kind) {
+            case MEMORY_DEVICE_INFO_KIND_DIMM:
+                di = value->dimm;
+
+                monitor_printf(mon, "Memory device [%s]: %s\n",
+                               MemoryDeviceInfoKind_lookup[value->kind],
+                               di->id);

'id' might be null, here is what user will see:

Memory device [dimm]: (null)

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

I'd suggest to replace (null) with "" as it is done elsewhere.

Is the fix below what you're looking for? If it is I can apply it myself:

I am sorry, I did not test this fix in my code last time. But your fix would print nothing when the id was null.

Printing nothing when there's no ID has a certain logic to it :)

When I do 'info qtree' it displays empty IDs with as empty "" I think we should be consistent and apply above correction.

Quoted 20 lines
Quoted 17 lines

So I think the fix would like the below, could you apply it? Thanks!

hmp.c +1 -1
index feefeb4..39a6490 100644
@@ -1737,7 +1737,7 @@ void hmp_info_memory_devices(Monitor *mon, const
 QDict *qdict)
 
                monitor_printf(mon, "Memory device [%s]: %s\n",
                               MemoryDeviceInfoKind_lookup[value->kind],
-                              di->id);
+                              di->id ? di->id : "\"\"");
                monitor_printf(mon, "  addr: 0x%" PRIx64 "\n",di->addr);
                monitor_printf(mon, "  slot: %" PRId64 "\n", di->slot);
Quoted 1 line
                monitor_printf(mon, "  node: %" PRId64 "\n", di->node);

I'd stick to printing nothing.

#8 lore raw
Quoted 61 lines · Igor Mammedov
Quoted 58 lines · On Mon, 22 Sep 2014 09:59:06 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 19 lines · zhugh
Quoted 18 lines · Luiz Capitulino
Quoted 15 lines · On Fri, 19 Sep 2014 15:30:19 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 12 lines · On Thu, 18 Sep 2014 16:09:32 +0800 zhugh <[email protected]> wrote:

Hi,

Could anyone help to review this patch?
If there was no problem, could help to merge it?

thanks!
zhu

Quoted 3 lines · Zhu Guihua

Provides HMP equivalent of QMP query-memory-devices command.

[...]

Quoted 36 lines
Quoted 35 lines
Quoted 30 lines
Quoted 20 lines
Quoted 20 lines
hmp.c +12 -0
index 40a90da..feefeb4 100644
@@ -1718,3 +1718,41 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
 
     qapi_free_MemdevList(memdev_list);
 }
+
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
+    MemoryDeviceInfoList *info;
+    MemoryDeviceInfo *value;
+    PCDIMMDeviceInfo *di;
+
+    for (info = info_list; info; info = info->next) {
+        value = info->value;
+
Quoted 8 lines

hmp.c void hmp_info_memdev(Monitor *mon, const QDict *qdict) · line 1740

Quoted 8 lines
hmp.c +8 -0
+        if (value) {
+            switch (value->kind) {
+            case MEMORY_DEVICE_INFO_KIND_DIMM:
+                di = value->dimm;
+
+                monitor_printf(mon, "Memory device [%s]: %s\n",
+                               MemoryDeviceInfoKind_lookup[value->kind],
+                               di->id);

'id' might be null, here is what user will see:

Quoted 3 lines

Memory device [dimm]: (null)

I'd suggest to replace (null) with "" as it is done elsewhere.

Is the fix below what you're looking for? If it is I can apply it myself:

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I am sorry, I did not test this fix in my code last time. But your fix would print nothing when the id was null.

Printing nothing when there's no ID has a certain logic to it :)

When I do 'info qtree' it displays empty IDs with as empty "" I think we should be consistent and apply above correction.

If you want consistency with "info qtree", you should enclose non-null ID in double quotes.

[...]

#9 lore raw
Quoted 66 lines · On Mon, 22 Sep 2014 11:29:00 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 64 lines · Igor Mammedov
Quoted 61 lines · On Mon, 22 Sep 2014 09:59:06 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 19 lines · zhugh
Quoted 18 lines · Luiz Capitulino
Quoted 15 lines · On Fri, 19 Sep 2014 15:30:19 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 12 lines · On Thu, 18 Sep 2014 16:09:32 +0800 zhugh <[email protected]> wrote:

Hi,

Could anyone help to review this patch?
If there was no problem, could help to merge it?

thanks!
zhu

Quoted 3 lines · Zhu Guihua

Provides HMP equivalent of QMP query-memory-devices command.

[...]

Quoted 38 lines
Quoted 30 lines
Quoted 30 lines
Quoted 20 lines
Quoted 20 lines
hmp.c +12 -0
index 40a90da..feefeb4 100644
@@ -1718,3 +1718,41 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
 
     qapi_free_MemdevList(memdev_list);
 }
+
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
+    MemoryDeviceInfoList *info;
+    MemoryDeviceInfo *value;
+    PCDIMMDeviceInfo *di;
+
+    for (info = info_list; info; info = info->next) {
+        value = info->value;
+
Quoted 8 lines

hmp.c void hmp_info_memdev(Monitor *mon, const QDict *qdict) · line 1740

Quoted 8 lines
hmp.c +8 -0
+        if (value) {
+            switch (value->kind) {
+            case MEMORY_DEVICE_INFO_KIND_DIMM:
+                di = value->dimm;
+
+                monitor_printf(mon, "Memory device [%s]: %s\n",
+                               MemoryDeviceInfoKind_lookup[value->kind],
+                               di->id);

'id' might be null, here is what user will see:

Quoted 5 lines
Quoted 3 lines

Memory device [dimm]: (null)

I'd suggest to replace (null) with "" as it is done elsewhere.

Is the fix below what you're looking for? If it is I can apply it myself:

I am sorry, I did not test this fix in my code last time. But your fix would print nothing when the id was null.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Printing nothing when there's no ID has a certain logic to it :)

When I do 'info qtree' it displays empty IDs with as empty "" I think we should be consistent and apply above correction.

If you want consistency with "info qtree", you should enclose non-null ID in double quotes.

zhugh, at this point is better to respin the patch.

author
#10 lore raw
Quoted 71 lines · Luiz Capitulino
Quoted 68 lines · On Mon, 22 Sep 2014 11:29:00 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 66 lines · Igor Mammedov
Quoted 62 lines · On Mon, 22 Sep 2014 09:59:06 +0200 Markus Armbruster <[email protected]> wrote:
Quoted 19 lines · zhugh
Quoted 18 lines · Luiz Capitulino
Quoted 15 lines · On Fri, 19 Sep 2014 15:30:19 +0200 Igor Mammedov <[email protected]> wrote:
Quoted 12 lines · On Thu, 18 Sep 2014 16:09:32 +0800 zhugh <[email protected]> wrote:

Hi,

Could anyone help to review this patch?
If there was no problem, could help to merge it?

thanks!
zhu

Quoted 3 lines · Zhu Guihua

Provides HMP equivalent of QMP query-memory-devices command.

[...]

Quoted 30 lines
Quoted 30 lines
Quoted 30 lines
Quoted 20 lines
Quoted 20 lines
hmp.c +12 -0
index 40a90da..feefeb4 100644
@@ -1718,3 +1718,41 @@ void hmp_info_memdev(Monitor *mon, const QDict *qdict)
 
     qapi_free_MemdevList(memdev_list);
 }
+
+void hmp_info_memory_devices(Monitor *mon, const QDict *qdict)
+{
+    Error *err = NULL;
+    MemoryDeviceInfoList *info_list = qmp_query_memory_devices(&err);
+    MemoryDeviceInfoList *info;
+    MemoryDeviceInfo *value;
+    PCDIMMDeviceInfo *di;
+
+    for (info = info_list; info; info = info->next) {
+        value = info->value;
+
Quoted 8 lines

hmp.c void hmp_info_memdev(Monitor *mon, const QDict *qdict) · line 1740

Quoted 8 lines
hmp.c +8 -0
+        if (value) {
+            switch (value->kind) {
+            case MEMORY_DEVICE_INFO_KIND_DIMM:
+                di = value->dimm;
+
+                monitor_printf(mon, "Memory device [%s]: %s\n",
+                               MemoryDeviceInfoKind_lookup[value->kind],
+                               di->id);

'id' might be null, here is what user will see:

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Memory device [dimm]: (null)

I'd suggest to replace (null) with "" as it is done elsewhere.

Is the fix below what you're looking for? If it is I can apply it myself:

I am sorry, I did not test this fix in my code last time. But your fix would print nothing when the id was null.

Printing nothing when there's no ID has a certain logic to it :)

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

When I do 'info qtree' it displays empty IDs with as empty "" I think we should be consistent and apply above correction.

If you want consistency with "info qtree", you should enclose non-null ID in double quotes.

zhugh, at this point is better to respin the patch.

Ok, I will send v5 to fix this.
Thanks!

Zhu