Message ID | 1401289056-28171-2-git-send-email-imammedo@redhat.com |
---|---|
State | New |
Headers | show |
The Wednesday 28 May 2014 à 09:30:11 (-0600), Eric Blake wrote : > On 05/28/2014 08:57 AM, Igor Mammedov wrote: > > ... allowing to get state of present memory devices. > > Currently implemented only for DimmDevice. > > > > Signed-off-by: Igor Mammedov <imammedo@redhat.com> > > --- > > hw/mem/dimm.c | 36 ++++++++++++++++++++++++++++ > > include/hw/mem/dimm.h | 2 + > > qapi-schema.json | 53 ++++++++++++++++++++++++++++++++++++++++++ > > qmp-commands.hx | 27 +++++++++++++++++++++ > > qmp.c | 11 ++++++++ > > stubs/Makefile.objs | 1 + > > stubs/qmp_dimm_device_list.c | 7 +++++ > > 7 files changed, 137 insertions(+), 0 deletions(-) > > create mode 100644 stubs/qmp_dimm_device_list.c > > Focusing on just the interface for now... > > > > +++ b/qapi-schema.json > > @@ -4722,3 +4722,56 @@ > > 'btn' : 'InputBtnEvent', > > 'rel' : 'InputMoveEvent', > > 'abs' : 'InputMoveEvent' } } > > + > > +## > > +# @DIMMDeviceInfo: > > +# > > +# DimmDevice state information > > +# > > +# @id: the devices's ID > > s/devices's/device's/ > > > +# > > +# @addr: physical address, where DimmDevice is mammped > > s/mammped/mapped/ (or maybe mmapped, but the fact that you used 'mmap' > feels like an implementation detail, so the English word is sufficient) > > > +# > > +# @size: size of memory DimmDevice provides > > +# > > +# @slot: slot number at which DimmDevice is plugged in > > +# > > +# @node: NUMA node number where DIMM is plugged in > > +# > > +# @memdev: memory backend linked with DimmDevice > > +# > > +# @hotplugged: true if device was hotplugged > > +# > > +# @hoptluggable: true if device if could be added/removed while machine is running > > s/hoptluggable/hotpluggable/ > > > +# > > +# Since: 2.1 > > +## > > +{ 'type': 'DIMMDeviceInfo', > > + 'data': { 'id': 'str', > > + 'addr': 'int', > > + 'size': 'int', > > + 'slot': 'int', > > + 'node': 'int', > > + 'memdev': 'str', > > + 'hotplugged': 'bool', > > + 'hoptluggable': 'bool' > > s/hoptluggable/hotpluggable/ > > > + } > > +} > > + > > +## > > +# @MemoryDeviceInfo: > > +# > > +# Union containing information about a memory devices > > s/devices/device/ > > > +# > > +# Since: 2.1 > > +## > > +{ 'union': 'MemoryDeviceInfo', 'data': {'dimm': 'DIMMDeviceInfo'} } > > + > > +## > > +# @query-memory-devices > > +# > > +# Lists available memory devices and their state > > +# > > +# Since: 2.1 > > +## > > Seems reasonable. > > > +{ 'command': 'query-memory-devices', 'returns': ['MemoryDeviceInfo'] } > > diff --git a/qmp-commands.hx b/qmp-commands.hx > > index d8aa4ed..45cb980 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': > > s/'/"/ throughout your example. Our schema files allow ' as an > ease-of-typing shortcut, but JSON itself (and therefore the on-the-wire > QMP example) requires use of ". > > > + { 'addr': 5368709120, > > + 'hoptluggable': True, > > + 'hotplugged': True, > > s/True/true/ twice (True is not valid JSON) Well this file is more QSON than JSON ;) Perhaps we should change the extension. Best regards Benoît > > -- > Eric Blake eblake redhat com +1-919-301-3266 > Libvirt virtualization library http://libvirt.org >
On Fri, 30 May 2014 13:43:52 +0200 Benoît Canet <benoit.canet@irqsave.net> wrote: > The Wednesday 28 May 2014 à 09:30:11 (-0600), Eric Blake wrote : > > On 05/28/2014 08:57 AM, Igor Mammedov wrote: > > > ... allowing to get state of present memory devices. > > > Currently implemented only for DimmDevice. > > > > > > Signed-off-by: Igor Mammedov <imammedo@redhat.com> > > > --- > > > hw/mem/dimm.c | 36 ++++++++++++++++++++++++++++ > > > include/hw/mem/dimm.h | 2 + > > > qapi-schema.json | 53 ++++++++++++++++++++++++++++++++++++++++++ > > > qmp-commands.hx | 27 +++++++++++++++++++++ > > > qmp.c | 11 ++++++++ > > > stubs/Makefile.objs | 1 + > > > stubs/qmp_dimm_device_list.c | 7 +++++ > > > 7 files changed, 137 insertions(+), 0 deletions(-) > > > create mode 100644 stubs/qmp_dimm_device_list.c > > > > Focusing on just the interface for now... > > > > > > > +++ b/qapi-schema.json > > > @@ -4722,3 +4722,56 @@ > > > 'btn' : 'InputBtnEvent', > > > 'rel' : 'InputMoveEvent', > > > 'abs' : 'InputMoveEvent' } } > > > + > > > +## > > > +# @DIMMDeviceInfo: > > > +# > > > +# DimmDevice state information > > > +# > > > +# @id: the devices's ID > > > > s/devices's/device's/ > > > > > +# > > > +# @addr: physical address, where DimmDevice is mammped > > > > s/mammped/mapped/ (or maybe mmapped, but the fact that you used 'mmap' > > feels like an implementation detail, so the English word is sufficient) > > > > > +# > > > +# @size: size of memory DimmDevice provides > > > +# > > > +# @slot: slot number at which DimmDevice is plugged in > > > +# > > > +# @node: NUMA node number where DIMM is plugged in > > > +# > > > +# @memdev: memory backend linked with DimmDevice > > > +# > > > +# @hotplugged: true if device was hotplugged > > > +# > > > +# @hoptluggable: true if device if could be added/removed while machine is running > > > > s/hoptluggable/hotpluggable/ > > > > > +# > > > +# Since: 2.1 > > > +## > > > +{ 'type': 'DIMMDeviceInfo', > > > + 'data': { 'id': 'str', > > > + 'addr': 'int', > > > + 'size': 'int', > > > + 'slot': 'int', > > > + 'node': 'int', > > > + 'memdev': 'str', > > > + 'hotplugged': 'bool', > > > + 'hoptluggable': 'bool' > > > > s/hoptluggable/hotpluggable/ > > > > > + } > > > +} > > > + > > > +## > > > +# @MemoryDeviceInfo: > > > +# > > > +# Union containing information about a memory devices > > > > s/devices/device/ > > > > > +# > > > +# Since: 2.1 > > > +## > > > +{ 'union': 'MemoryDeviceInfo', 'data': {'dimm': 'DIMMDeviceInfo'} } > > > + > > > +## > > > +# @query-memory-devices > > > +# > > > +# Lists available memory devices and their state > > > +# > > > +# Since: 2.1 > > > +## > > > > Seems reasonable. > > > > > +{ 'command': 'query-memory-devices', 'returns': ['MemoryDeviceInfo'] } > > > diff --git a/qmp-commands.hx b/qmp-commands.hx > > > index d8aa4ed..45cb980 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': > > > > s/'/"/ throughout your example. Our schema files allow ' as an > > ease-of-typing shortcut, but JSON itself (and therefore the on-the-wire > > QMP example) requires use of ". > > > > > + { 'addr': 5368709120, > > > + 'hoptluggable': True, > > > + 'hotplugged': True, > > > > s/True/true/ twice (True is not valid JSON) That was output from qmp-shell, parhaps we should fix it there as well. > > Well this file is more QSON than JSON ;) Perhaps we should change the extension. > > Best regards > > Benoît > > > > > -- > > Eric Blake eblake redhat com +1-919-301-3266 > > Libvirt virtualization library http://libvirt.org > > > >
The Friday 30 May 2014 à 13:47:21 (+0200), Igor Mammedov wrote : > On Fri, 30 May 2014 13:43:52 +0200 > Benoît Canet <benoit.canet@irqsave.net> wrote: > > > The Wednesday 28 May 2014 à 09:30:11 (-0600), Eric Blake wrote : > > > On 05/28/2014 08:57 AM, Igor Mammedov wrote: > > > > ... allowing to get state of present memory devices. > > > > Currently implemented only for DimmDevice. > > > > > > > > Signed-off-by: Igor Mammedov <imammedo@redhat.com> > > > > --- > > > > hw/mem/dimm.c | 36 ++++++++++++++++++++++++++++ > > > > include/hw/mem/dimm.h | 2 + > > > > qapi-schema.json | 53 ++++++++++++++++++++++++++++++++++++++++++ > > > > qmp-commands.hx | 27 +++++++++++++++++++++ > > > > qmp.c | 11 ++++++++ > > > > stubs/Makefile.objs | 1 + > > > > stubs/qmp_dimm_device_list.c | 7 +++++ > > > > 7 files changed, 137 insertions(+), 0 deletions(-) > > > > create mode 100644 stubs/qmp_dimm_device_list.c > > > > > > Focusing on just the interface for now... > > > > > > > > > > +++ b/qapi-schema.json > > > > @@ -4722,3 +4722,56 @@ > > > > 'btn' : 'InputBtnEvent', > > > > 'rel' : 'InputMoveEvent', > > > > 'abs' : 'InputMoveEvent' } } > > > > + > > > > +## > > > > +# @DIMMDeviceInfo: > > > > +# > > > > +# DimmDevice state information > > > > +# > > > > +# @id: the devices's ID > > > > > > s/devices's/device's/ > > > > > > > +# > > > > +# @addr: physical address, where DimmDevice is mammped > > > > > > s/mammped/mapped/ (or maybe mmapped, but the fact that you used 'mmap' > > > feels like an implementation detail, so the English word is sufficient) > > > > > > > +# > > > > +# @size: size of memory DimmDevice provides > > > > +# > > > > +# @slot: slot number at which DimmDevice is plugged in > > > > +# > > > > +# @node: NUMA node number where DIMM is plugged in > > > > +# > > > > +# @memdev: memory backend linked with DimmDevice > > > > +# > > > > +# @hotplugged: true if device was hotplugged > > > > +# > > > > +# @hoptluggable: true if device if could be added/removed while machine is running > > > > > > s/hoptluggable/hotpluggable/ > > > > > > > +# > > > > +# Since: 2.1 > > > > +## > > > > +{ 'type': 'DIMMDeviceInfo', > > > > + 'data': { 'id': 'str', > > > > + 'addr': 'int', > > > > + 'size': 'int', > > > > + 'slot': 'int', > > > > + 'node': 'int', > > > > + 'memdev': 'str', > > > > + 'hotplugged': 'bool', > > > > + 'hoptluggable': 'bool' > > > > > > s/hoptluggable/hotpluggable/ > > > > > > > + } > > > > +} > > > > + > > > > +## > > > > +# @MemoryDeviceInfo: > > > > +# > > > > +# Union containing information about a memory devices > > > > > > s/devices/device/ > > > > > > > +# > > > > +# Since: 2.1 > > > > +## > > > > +{ 'union': 'MemoryDeviceInfo', 'data': {'dimm': 'DIMMDeviceInfo'} } > > > > + > > > > +## > > > > +# @query-memory-devices > > > > +# > > > > +# Lists available memory devices and their state > > > > +# > > > > +# Since: 2.1 > > > > +## > > > > > > Seems reasonable. > > > > > > > +{ 'command': 'query-memory-devices', 'returns': ['MemoryDeviceInfo'] } > > > > diff --git a/qmp-commands.hx b/qmp-commands.hx > > > > index d8aa4ed..45cb980 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': > > > > > > s/'/"/ throughout your example. Our schema files allow ' as an > > > ease-of-typing shortcut, but JSON itself (and therefore the on-the-wire > > > QMP example) requires use of ". > > > > > > > + { 'addr': 5368709120, > > > > + 'hoptluggable': True, > > > > + 'hotplugged': True, > > > > > > s/True/true/ twice (True is not valid JSON) > That was output from qmp-shell, parhaps we should fix it there as well. True with a capitalized T is python type for true. But python can also serialize this data to JSON with the json module. Best regards Benoît > > > > > Well this file is more QSON than JSON ;) Perhaps we should change the extension. > > > > Best regards > > > > Benoît > > > > > > > > -- > > > Eric Blake eblake redhat com +1-919-301-3266 > > > Libvirt virtualization library http://libvirt.org > > > > > > > > > > -- > Regards, > Igor >
diff --git a/hw/mem/dimm.c b/hw/mem/dimm.c index a189b59..42c94dc 100644 --- a/hw/mem/dimm.c +++ b/hw/mem/dimm.c @@ -23,6 +23,42 @@ #include "qapi/visitor.h" #include "qemu/range.h" +int qmp_dimm_device_list(Object *obj, void *opaque) +{ + MemoryDeviceInfoList ***prev = opaque; + + if (object_dynamic_cast(obj, TYPE_DIMM)) { + DeviceState *dev = DEVICE(obj); + + if (dev->realized) { + MemoryDeviceInfoList *elem = g_new0(MemoryDeviceInfoList, 1); + MemoryDeviceInfo *info = g_new0(MemoryDeviceInfo, 1); + DIMMDeviceInfo *di = g_new0(DIMMDeviceInfo, 1); + DeviceClass *dc = DEVICE_GET_CLASS(obj); + DimmDevice *dimm = DIMM(obj); + + di->id = g_strdup(dev->id); + di->hotplugged = dev->hotplugged; + di->hoptluggable = dc->hotpluggable; + di->addr = dimm->addr; + di->slot = dimm->slot; + di->node = dimm->node; + di->size = object_property_get_int(OBJECT(dimm), 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_dimm_device_list, opaque); + return 0; +} + static int dimm_slot2bitmap(Object *obj, void *opaque) { unsigned long *bitmap = opaque; diff --git a/include/hw/mem/dimm.h b/include/hw/mem/dimm.h index 1be8fb2..304bd5f 100644 --- a/include/hw/mem/dimm.h +++ b/include/hw/mem/dimm.h @@ -77,4 +77,6 @@ uint64_t dimm_get_free_addr(uint64_t address_space_start, Error **errp); int dimm_get_free_slot(const int *hint, int max_slots, Error **errp); + +int qmp_dimm_device_list(Object *obj, void *opaque); #endif diff --git a/qapi-schema.json b/qapi-schema.json index 7bc33ea..0cc3eb3 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4722,3 +4722,56 @@ 'btn' : 'InputBtnEvent', 'rel' : 'InputMoveEvent', 'abs' : 'InputMoveEvent' } } + +## +# @DIMMDeviceInfo: +# +# DimmDevice state information +# +# @id: the devices's ID +# +# @addr: physical address, where DimmDevice is mammped +# +# @size: size of memory DimmDevice provides +# +# @slot: slot number at which DimmDevice is plugged in +# +# @node: NUMA node number where DIMM is plugged in +# +# @memdev: memory backend linked with DimmDevice +# +# @hotplugged: true if device was hotplugged +# +# @hoptluggable: true if device if could be added/removed while machine is running +# +# Since: 2.1 +## +{ 'type': 'DIMMDeviceInfo', + 'data': { 'id': 'str', + 'addr': 'int', + 'size': 'int', + 'slot': 'int', + 'node': 'int', + 'memdev': 'str', + 'hotplugged': 'bool', + 'hoptluggable': 'bool' + } +} + +## +# @MemoryDeviceInfo: +# +# Union containing information about a memory devices +# +# Since: 2.1 +## +{ 'union': 'MemoryDeviceInfo', 'data': {'dimm': 'DIMMDeviceInfo'} } + +## +# @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..45cb980 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, + 'hoptluggable': 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..045d477 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/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_dimm_device_list(qdev_get_machine(), &prev); + + return head; +} diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs index d99e2b9..b2017d8 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_dimm_device_list.o diff --git a/stubs/qmp_dimm_device_list.c b/stubs/qmp_dimm_device_list.c new file mode 100644 index 0000000..7bb31c7 --- /dev/null +++ b/stubs/qmp_dimm_device_list.c @@ -0,0 +1,7 @@ +#include "qom/object.h" +#include "hw/mem/dimm.h" + +int qmp_dimm_device_list(Object *obj, void *opaque) +{ + return 0; +}
... allowing to get state of present memory devices. Currently implemented only for DimmDevice. Signed-off-by: Igor Mammedov <imammedo@redhat.com> --- hw/mem/dimm.c | 36 ++++++++++++++++++++++++++++ include/hw/mem/dimm.h | 2 + qapi-schema.json | 53 ++++++++++++++++++++++++++++++++++++++++++ qmp-commands.hx | 27 +++++++++++++++++++++ qmp.c | 11 ++++++++ stubs/Makefile.objs | 1 + stubs/qmp_dimm_device_list.c | 7 +++++ 7 files changed, 137 insertions(+), 0 deletions(-) create mode 100644 stubs/qmp_dimm_device_list.c