Re: [libvirt] [PATCH 1/3] qemu_monitor_json: Populate CPUModelInfo struct from json

2018-04-16 Thread Erik Skultety
On Mon, Apr 16, 2018 at 01:06:56AM -0500, Chris Venteicher wrote:
> New function qemuMonitorJSONBuildCPUModelInfo created by extracting code
> from existing function qemuMonitorJSONGetCPUModelExpansion to create a
> reusable function for extracting cpu model info from json.
> ---
>  src/qemu/qemu_monitor_json.c | 82 
> ++--
>  1 file changed, 56 insertions(+), 26 deletions(-)
>
...

> +if (virJSONValueObjectForeachKeyValue(cpu_props,
> +  
> qemuMonitorJSONParseCPUModelProperty,
> +  machine_model) < 0)
> +goto cleanup;
> +
> +ret = 0;
> +*model = machine_model;
> +machine_model = NULL;

we also tend to use VIR_STEAL_PTR(dst, src) in ^this case.

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH 1/3] qemu_monitor_json: Populate CPUModelInfo struct from json

2018-04-16 Thread Ján Tomko

On Mon, Apr 16, 2018 at 01:06:56AM -0500, Chris Venteicher wrote:

New function qemuMonitorJSONBuildCPUModelInfo created by extracting code
from existing function qemuMonitorJSONGetCPUModelExpansion to create a
reusable function for extracting cpu model info from json.
---
src/qemu/qemu_monitor_json.c | 82 ++--
1 file changed, 56 insertions(+), 26 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 57c2c4de0..cf31c16a0 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5337,6 +5337,61 @@ qemuMonitorJSONParseCPUModelProperty(const char *key,
return 0;
}

+// model_json: {"model": {"name": "IvyBridge", "props": {}}}


/* comment */

and

/*
* comment
*/

are the preferred comment styles in libvirt.
https://libvirt.org/hacking.html#formatting


+static int


This function either returns -1 when model is NULL or 0 when it's not.
You can return qemuMonitorCPUModelInfoPtr directly.


+qemuMonitorJSONBuildCPUModelInfo(virJSONValuePtr model_json,


Put 'FromJSON' at the end of the function name, e.g.:
qemuMonitorJSONGetCPUModelInfoFromJSON


+ qemuMonitorCPUModelInfoPtr *model)
+{
+virJSONValuePtr cpu_model;
+virJSONValuePtr cpu_props;
+qemuMonitorCPUModelInfoPtr machine_model = NULL;
+int ret = -1;
+char const *cpu_name;
+
+*model = NULL;
+


Jano


signature.asc
Description: Digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list