[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 099/103] qmp: add query-memory-devices command
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 099/103] qmp: add query-memory-devices command |
Date: |
Tue, 17 Jun 2014 20:42:24 +0300 |
From: Igor Mammedov <address@hidden>
... allowing to get state of present memory devices.
Currently implemented only for PCDIMMDevice.
Signed-off-by: Igor Mammedov <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Acked-by: Michael S. Tsirkin <address@hidden>
---
qapi-schema.json | 51 +++++++++++++++++++++++++++++++++++++++++
include/hw/mem/pc-dimm.h | 2 ++
hw/mem/pc-dimm.c | 39 +++++++++++++++++++++++++++++++
qmp.c | 11 +++++++++
stubs/qmp_pc_dimm_device_list.c | 7 ++++++
qmp-commands.hx | 27 ++++++++++++++++++++++
stubs/Makefile.objs | 1 +
7 files changed, 138 insertions(+)
create mode 100644 stubs/qmp_pc_dimm_device_list.c
diff --git a/qapi-schema.json b/qapi-schema.json
index 4c367d0..60e5551 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4836,3 +4836,54 @@
# Since: 2.1
##
{ 'command': 'query-memdev', 'returns': ['Memdev'] }
+# @PCDIMMDeviceInfo:
+#
+# PCDIMMDevice state information
+#
+# @id: #optional device's ID
+#
+# @addr: physical address, where device is mapped
+#
+# @size: size of memory that the device provides
+#
+# @slot: slot number at which device is plugged in
+#
+# @node: NUMA node number where device is plugged in
+#
+# @memdev: memory backend linked with device
+#
+# @hotplugged: true if device was hotplugged
+#
+# @hotpluggable: true if device if could be added/removed while machine is
running
+#
+# Since: 2.1
+##
+{ 'type': 'PCDIMMDeviceInfo',
+ 'data': { '*id': 'str',
+ 'addr': 'int',
+ 'size': 'int',
+ 'slot': 'int',
+ 'node': 'int',
+ 'memdev': 'str',
+ 'hotplugged': 'bool',
+ 'hotpluggable': 'bool'
+ }
+}
+
+##
+# @MemoryDeviceInfo:
+#
+# Union containing information about a memory device
+#
+# Since: 2.1
+##
+{ 'union': 'MemoryDeviceInfo', 'data': {'dimm': 'PCDIMMDeviceInfo'} }
+
+##
+# @query-memory-devices
+#
+# Lists available memory devices and their state
+#
+# Since: 2.1
+##
+{ 'command': 'query-memory-devices', 'returns': ['MemoryDeviceInfo'] }
diff --git a/include/hw/mem/pc-dimm.h b/include/hw/mem/pc-dimm.h
index 5f80d14..fa4cdd3 100644
--- a/include/hw/mem/pc-dimm.h
+++ b/include/hw/mem/pc-dimm.h
@@ -76,4 +76,6 @@ uint64_t pc_dimm_get_free_addr(uint64_t address_space_start,
Error **errp);
int pc_dimm_get_free_slot(const int *hint, int max_slots, Error **errp);
+
+int qmp_pc_dimm_device_list(Object *obj, void *opaque);
#endif
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 8c26568..ad176b7 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -23,6 +23,45 @@
#include "qapi/visitor.h"
#include "qemu/range.h"
+int qmp_pc_dimm_device_list(Object *obj, void *opaque)
+{
+ MemoryDeviceInfoList ***prev = opaque;
+
+ if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
+ DeviceState *dev = DEVICE(obj);
+
+ if (dev->realized) {
+ MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1);
+ MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1);
+ PCDIMMDeviceInfo *di = g_new0(PCDIMMDeviceInfo, 1);
+ DeviceClass *dc = DEVICE_GET_CLASS(obj);
+ PCDIMMDevice *dimm = PC_DIMM(obj);
+
+ if (dev->id) {
+ di->has_id = true;
+ di->id = g_strdup(dev->id);
+ }
+ di->hotplugged = dev->hotplugged;
+ di->hotpluggable = dc->hotpluggable;
+ di->addr = dimm->addr;
+ di->slot = dimm->slot;
+ di->node = dimm->node;
+ di->size = object_property_get_int(OBJECT(dimm), PC_DIMM_SIZE_PROP,
+ NULL);
+ di->memdev = object_get_canonical_path(OBJECT(dimm->hostmem));
+
+ info->dimm = di;
+ elem->value = info;
+ elem->next = NULL;
+ **prev = elem;
+ *prev = &elem->next;
+ }
+ }
+
+ object_child_foreach(obj, qmp_pc_dimm_device_list, opaque);
+ return 0;
+}
+
static int pc_dimm_slot2bitmap(Object *obj, void *opaque)
{
unsigned long *bitmap = opaque;
diff --git a/qmp.c b/qmp.c
index c3c0229..835fd78 100644
--- a/qmp.c
+++ b/qmp.c
@@ -28,6 +28,7 @@
#include "qapi/qmp-input-visitor.h"
#include "hw/boards.h"
#include "qom/object_interfaces.h"
+#include "hw/mem/pc-dimm.h"
NameInfo *qmp_query_name(Error **errp)
{
@@ -628,3 +629,13 @@ void qmp_object_del(const char *id, Error **errp)
}
object_unparent(obj);
}
+
+MemoryDeviceInfoList *qmp_query_memory_devices(Error **errp)
+{
+ MemoryDeviceInfoList *head = NULL;
+ MemoryDeviceInfoList **prev = &head;
+
+ qmp_pc_dimm_device_list(qdev_get_machine(), &prev);
+
+ return head;
+}
diff --git a/stubs/qmp_pc_dimm_device_list.c b/stubs/qmp_pc_dimm_device_list.c
new file mode 100644
index 0000000..5cb220c
--- /dev/null
+++ b/stubs/qmp_pc_dimm_device_list.c
@@ -0,0 +1,7 @@
+#include "qom/object.h"
+#include "hw/mem/pc-dimm.h"
+
+int qmp_pc_dimm_device_list(Object *obj, void *opaque)
+{
+ return 0;
+}
diff --git a/qmp-commands.hx b/qmp-commands.hx
index 2009034..177ac25 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3610,3 +3610,30 @@ Example (1):
}
EQMP
+
+ {
+ .name = "query-memory-devices",
+ .args_type = "",
+ .mhandler.cmd_new = qmp_marshal_input_query_memory_devices,
+ },
+
+SQMP
address@hidden
+--------------------
+
+Return a list of memory devices.
+
+Example:
+-> { "execute": "query-memory-devices" }
+<- { "return": [ { "data":
+ { "addr": 5368709120,
+ "hotpluggable": true,
+ "hotplugged": true,
+ "id": "d1",
+ "memdev": "/objects/memX",
+ "node": 0,
+ "size": 1073741824,
+ "slot": 0},
+ "type": "dimm"
+ } ] }
+EQMP
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 5a0b917..997d68d 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -37,3 +37,4 @@ stub-obj-y += vmstate.o
stub-obj-$(CONFIG_WIN32) += fd-register.o
stub-obj-y += cpus.o
stub-obj-y += kvm.o
+stub-obj-y += qmp_pc_dimm_device_list.o
--
MST
- [Qemu-devel] [PULL 090/103] tests: fix memory leak in test of string input visitor, (continued)
- [Qemu-devel] [PULL 090/103] tests: fix memory leak in test of string input visitor, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 091/103] qapi: make string input visitor parse int list, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 092/103] qapi: make string output visitor parse int list, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 093/103] qapi: fix build on glib < 2.28, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 094/103] qdev: reorganize error reporting in bus_set_realized, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 095/103] qdev: recursively unrealize devices when unrealizing bus, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 096/103] qmp: clean out whitespace, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 048/103] Add G_IO_HUP handler for socket chardev, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 063/103] NUMA: check if the total numa memory size is equal to ram_size, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 064/103] NUMA: Add numa_info structure to contain numa nodes info, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 099/103] qmp: add query-memory-devices command,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 100/103] acpi: introduce TYPE_ACPI_DEVICE_IF interface, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 062/103] NUMA: move numa related code to new file numa.c, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 097/103] pc: acpi: do not hardcode preprocessor, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 098/103] numa: handle mmaped memory allocation failure correctly, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 102/103] qmp: add query-acpi-ospm-status command, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 036/103] virtio: Drop superfluous conditionals around g_free(), Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 088/103] qmp: add query-memdev, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 034/103] acpi: update generated files, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 060/103] libqemustub: add stubs to be able to use qemu-char.c, Michael S. Tsirkin, 2014/06/17
- [Qemu-devel] [PULL 068/103] qmp: improve error reporting for -object and object-add, Michael S. Tsirkin, 2014/06/17