All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: qemu-devel@nongnu.org
Cc: pkrempa@redhat.com, mst@redhat.com, armbru@redhat.com,
	lcapitulino@redhat.com, vasilis.liaskovitis@profitbricks.com
Subject: [Qemu-devel] [PATCH 1/5] qmp: add query-memory-devices command
Date: Thu,  5 Jun 2014 16:36:04 +0200	[thread overview]
Message-ID: <1401978968-7733-2-git-send-email-imammedo@redhat.com> (raw)
In-Reply-To: <1401978968-7733-1-git-send-email-imammedo@redhat.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 6456 bytes --]

... allowing to get state of present memory devices.
Currently implemented only for PCDIMMDevice.

Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v2:
 * fix typos an json syntax in QMP example
 * make 'id' optional to allow command work with
   anonymous memory devices
---
 hw/mem/pc-dimm.c                |   39 ++++++++++++++++++++++++++++
 include/hw/mem/pc-dimm.h        |    2 +
 qapi-schema.json                |   53 +++++++++++++++++++++++++++++++++++++++
 qmp-commands.hx                 |   27 ++++++++++++++++++++
 qmp.c                           |   11 ++++++++
 stubs/Makefile.objs             |    1 +
 stubs/qmp_pc_dimm_device_list.c |    7 +++++
 7 files changed, 140 insertions(+), 0 deletions(-)
 create mode 100644 stubs/qmp_pc_dimm_device_list.c

diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 9f091c6..361071f 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/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/qapi-schema.json b/qapi-schema.json
index 7bc33ea..beb2de8 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4722,3 +4722,56 @@
               'btn'     : 'InputBtnEvent',
               'rel'     : 'InputMoveEvent',
               'abs'     : 'InputMoveEvent' } }
+
+##
+# @PCDIMMDeviceInfo:
+#
+# PCDIMMDevice state information
+#
+# @id: the device's ID
+#
+# @addr: physical address, where device is mapped
+#
+# @size: size of memory 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/qmp-commands.hx b/qmp-commands.hx
index d8aa4ed..c0e0d9e 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -3572,3 +3572,30 @@ Example:
                    } } ] }
 
 EQMP
+
+    {
+        .name       = "query-memory-devices",
+        .args_type  = "",
+        .mhandler.cmd_new = qmp_marshal_input_query_memory_devices,
+    },
+
+SQMP
+@query-memory-devices
+--------------------
+
+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/qmp.c b/qmp.c
index b722dbe..66d2d67 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/Makefile.objs b/stubs/Makefile.objs
index d99e2b9..6a95122 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -29,3 +29,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
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;
+}
-- 
1.7.1

  reply	other threads:[~2014-06-05 14:36 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05 14:36 [Qemu-devel] [PATCH 0/5] ACPI memory hotplug: QMP interfaces Igor Mammedov
2014-06-05 14:36 ` Igor Mammedov [this message]
2014-06-16 15:21   ` [Qemu-devel] [PATCH 1/5] qmp: add query-memory-devices command Eric Blake
2014-06-05 14:36 ` [Qemu-devel] [PATCH 2/5] acpi: introduce TYPE_ACPI_DEVICE_IF interface Igor Mammedov
2014-06-16 15:32   ` Eric Blake
2014-06-05 14:36 ` [Qemu-devel] [PATCH 3/5] acpi: implement ospm_status() method for PIIX4/ICH9_LPC devices Igor Mammedov
2014-06-16 16:14   ` Eric Blake
2014-06-16 16:42     ` Igor Mammedov
2014-06-05 14:36 ` [Qemu-devel] [PATCH 4/5] qmp: add query-acpi-ospm-status command Igor Mammedov
2014-06-16 16:19   ` Eric Blake
2014-06-05 14:36 ` [Qemu-devel] [PATCH 5/5] qmp: add ACPI_DEVICE_OST event handling Igor Mammedov
2014-06-16 16:25   ` Eric Blake
2014-06-16 15:03 ` [Qemu-devel] [PATCH 0/5] ACPI memory hotplug: QMP interfaces Igor Mammedov
2014-06-16 15:30 ` Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1401978968-7733-2-git-send-email-imammedo@redhat.com \
    --to=imammedo@redhat.com \
    --cc=armbru@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=mst@redhat.com \
    --cc=pkrempa@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=vasilis.liaskovitis@profitbricks.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.