Changeset
src/qemu/qemu_monitor.c      |  16 ++++
src/qemu/qemu_monitor.h      |   5 ++
src/qemu/qemu_monitor_json.c | 179 +++++++++++++++++++++++++++++++++++++------
src/qemu/qemu_monitor_json.h |   7 ++
4 files changed, 185 insertions(+), 22 deletions(-)
Git apply log
Switched to a new branch '20180416060658.31760-1-cventeic@redhat.com'
Applying: qemu_monitor_json: Populate CPUModelInfo struct from json
Applying: qemu_monitor_json: Build Json CPU Model Info
Applying: qemu_monitor: query-cpu-model-baseline QMP command
To https://github.com/patchew-project/libvirt
 * [new tag]         patchew/20180416060658.31760-1-cventeic@redhat.com -> patchew/20180416060658.31760-1-cventeic@redhat.com
Test passed: syntax-check

loading

[libvirt] [PATCH 0/3] query-cpu-model-baseline QMP command
Posted by Chris Venteicher, 3 days ago
Implementation of libvirt functions to support the
QEMU query-cpu-model-baseline QMP command.

This is part of resolution of: https://bugzilla.redhat.com/show_bug.cgi?id=1511999

Signed-off-by: Chris Venteicher <cventeic@redhat.com>

Chris Venteicher (3):
  qemu_monitor_json: Populate CPUModelInfo struct from json
  qemu_monitor_json: Build Json CPU Model Info
  qemu_monitor: query-cpu-model-baseline QMP command

 src/qemu/qemu_monitor.c      |  16 ++++
 src/qemu/qemu_monitor.h      |   5 ++
 src/qemu/qemu_monitor_json.c | 179 +++++++++++++++++++++++++++++++++++++------
 src/qemu/qemu_monitor_json.h |   7 ++
 4 files changed, 185 insertions(+), 22 deletions(-)

-- 
2.14.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 0/3] query-cpu-model-baseline QMP command
Posted by Collin Walling, 3 days ago
On 04/16/2018 02:06 AM, Chris Venteicher wrote:
> Implementation of libvirt functions to support the
> QEMU query-cpu-model-baseline QMP command.
> 
> This is part of resolution of: https://bugzilla.redhat.com/show_bug.cgi?id=1511999
> 
> Signed-off-by: Chris Venteicher <cventeic@redhat.com>
> 
> Chris Venteicher (3):
>   qemu_monitor_json: Populate CPUModelInfo struct from json
>   qemu_monitor_json: Build Json CPU Model Info
>   qemu_monitor: query-cpu-model-baseline QMP command
> 
>  src/qemu/qemu_monitor.c      |  16 ++++
>  src/qemu/qemu_monitor.h      |   5 ++
>  src/qemu/qemu_monitor_json.c | 179 +++++++++++++++++++++++++++++++++++++------
>  src/qemu/qemu_monitor_json.h |   7 ++
>  4 files changed, 185 insertions(+), 22 deletions(-)
> 
Hi Chris,

I'm working on a neighboring item with implementing cpu-comparison. Since there
are some similarities with both comparison and baseline, I'd like for us to
work together on driving both features forward.

Thus far, I've created the qemu_monitor_json interface, tied it into the qemu 
driver, and can issue virsh cpu-compare <file.xml> successfully. (Though it's
no where near perfect yet ;) )

I've already noted some differences between our JSON interaces (namely, yours
works with qemuMonitorCPUModelInfoPtrs, and mine works with virCPUDefPtrs). 

Ultimately, I think your patches are in good shape.

Let's discuss further on my comparison patches posted here:

https://www.redhat.com/archives/libvir-list/2018-April/msg01375.html

I'm open to any suggestions / design ideas you have.

-- 
Respectfully,
- Collin Walling

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 0/3] query-cpu-model-baseline QMP command
Posted by Chris Venteicher, 9 hours ago

----- Original Message -----
> From: "Collin Walling" <walling@linux.ibm.com>
> To: "Chris Venteicher" <cventeic@redhat.com>, libvir-list@redhat.com
> Sent: Monday, April 16, 2018 6:26:07 PM
> Subject: Re: [libvirt] [PATCH 0/3] query-cpu-model-baseline QMP command
> 
> On 04/16/2018 02:06 AM, Chris Venteicher wrote:
> > Implementation of libvirt functions to support the
> > QEMU query-cpu-model-baseline QMP command.
> > 
> > This is part of resolution of:
> > https://bugzilla.redhat.com/show_bug.cgi?id=1511999
> > 
> > Signed-off-by: Chris Venteicher <cventeic@redhat.com>
> > 
> > Chris Venteicher (3):
> >   qemu_monitor_json: Populate CPUModelInfo struct from json
> >   qemu_monitor_json: Build Json CPU Model Info
> >   qemu_monitor: query-cpu-model-baseline QMP command
> > 
> >  src/qemu/qemu_monitor.c      |  16 ++++
> >  src/qemu/qemu_monitor.h      |   5 ++
> >  src/qemu/qemu_monitor_json.c | 179
> >  +++++++++++++++++++++++++++++++++++++------
> >  src/qemu/qemu_monitor_json.h |   7 ++
> >  4 files changed, 185 insertions(+), 22 deletions(-)
> > 
> Hi Chris,
> 
> I'm working on a neighboring item with implementing cpu-comparison. Since
> there
> are some similarities with both comparison and baseline, I'd like for us to
> work together on driving both features forward.
> 
> Thus far, I've created the qemu_monitor_json interface, tied it into the qemu
> driver, and can issue virsh cpu-compare <file.xml> successfully. (Though it's
> no where near perfect yet ;) )
> 
> I've already noted some differences between our JSON interaces (namely, yours
> works with qemuMonitorCPUModelInfoPtrs, and mine works with virCPUDefPtrs).
> 
> Ultimately, I think your patches are in good shape.
> 
> Let's discuss further on my comparison patches posted here:
> 
> https://www.redhat.com/archives/libvir-list/2018-April/msg01375.html
> 
> I'm open to any suggestions / design ideas you have.
> 
> --
> Respectfully,
> - Collin Walling
> 
> 

Hi Collin,

Not sure if you received my previous reply on this... It's possible it got stuck in my mail box.

Seems like we have got our wires crossed on this...
I also have an implementation going in parallel for virsh cpu-comparison I have been working under Bug 1511996 - Implement "virsh cpu-compare" for s390x.

As you mentioned the requirements for both are similar in that
1) Both functions work with cpu model info
2) Both functions require a qemu instance to be spun up during execution.

I took a look at your code for cpu-comparison.

1) Seems like it will be good to compare and contrast how both of us spin up the qemu instance for best practice
2) Looks like you translate between XML --- virCpuDef --- qemu qmp JSON
   I ended up just going straight from XML --- qemu qmp JSON

   Think there is an open question about which approach is best.

I have only pushed the qmp JSON functions to libvirt-list so far.
(In fact I just pushed v2 if you have a moment to look again.)

However I have the rest of the code for baseline, including launching the qemu instance, working and nearly ready to push.

I guess at this point I think it might be best to just finish pushing the rest of the code for baseline and see what the feedback is and to make it available for you to look at.

I am especially interested in getting feedback from community on skipping the virCpuDef step in the XML to JSON translations.

Then we could revisit and address any delta between baseline and cpu-comparison.

If straight XML to JSON is sufficient we might want to leverage more of what I have.
If the virCpuDef step is needed then leverage more of yours.

Either way try and make the QEMU spin up as clean as possible.

That seem good to you?
Chris

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 0/3] query-cpu-model-baseline QMP command
Posted by Collin Walling, 8 hours ago
[...]

>> Hi Chris,
>>
>> I'm working on a neighboring item with implementing cpu-comparison. Since
>> there
>> are some similarities with both comparison and baseline, I'd like for us to
>> work together on driving both features forward.
>>
>> Thus far, I've created the qemu_monitor_json interface, tied it into the qemu
>> driver, and can issue virsh cpu-compare <file.xml> successfully. (Though it's
>> no where near perfect yet ;) )
>>
>> I've already noted some differences between our JSON interaces (namely, yours
>> works with qemuMonitorCPUModelInfoPtrs, and mine works with virCPUDefPtrs).
>>
>> Ultimately, I think your patches are in good shape.
>>
>> Let's discuss further on my comparison patches posted here:
>>
>> https://www.redhat.com/archives/libvir-list/2018-April/msg01375.html
>>
>> I'm open to any suggestions / design ideas you have.
>>
>> --
>> Respectfully,
>> - Collin Walling
>>
>>
> 
> Hi Collin,
> 
> Not sure if you received my previous reply on this... It's possible it got stuck in my mail box.
> 
> Seems like we have got our wires crossed on this...
> I also have an implementation going in parallel for virsh cpu-comparison I have been working under Bug 1511996 - Implement "virsh cpu-compare" for s390x.
> 
> As you mentioned the requirements for both are similar in that
> 1) Both functions work with cpu model info
> 2) Both functions require a qemu instance to be spun up during execution.
> 
> I took a look at your code for cpu-comparison.
> 
> 1) Seems like it will be good to compare and contrast how both of us spin up the qemu instance for best practice

I look forward to seeing your approach on this.

> 2) Looks like you translate between XML --- virCpuDef --- qemu qmp JSON
>    I ended up just going straight from XML --- qemu qmp JSON
> 
>    Think there is an open question about which approach is best.

I did XML -> CpuDef -> JSON because my approach utilized the CpuDef found in virCaps 
(which I stole from qemuCaps, but it looks like this is not the way we should being
do this). It looked cleaner to pass two cpudefs to the monitor function.

I think it'll be more clear to both of us which approach is better once we see how 
the host / hypervisor CPU will be stored.

> 
> I have only pushed the qmp JSON functions to libvirt-list so far.
> (In fact I just pushed v2 if you have a moment to look again.)

I'll take a look at them.

> 
> However I have the rest of the code for baseline, including launching the qemu instance, working and nearly ready to push.
> 
> I guess at this point I think it might be best to just finish pushing the rest of the code for baseline and see what the feedback is and to make it available for you to look at.
> 
> I am especially interested in getting feedback from community on skipping the virCpuDef step in the XML to JSON translations.
> 
> Then we could revisit and address any delta between baseline and cpu-comparison.
> 
> If straight XML to JSON is sufficient we might want to leverage more of what I have.
> If the virCpuDef step is needed then leverage more of yours.
> 
> Either way try and make the QEMU spin up as clean as possible.

Agreed.

> 
> That seem good to you?

Perfectly fine with me :)

At this point, it seems like my role in this is better suited as a reviewer -- which 
is fine. I'll be keeping a close eye on the forthcoming patches and provide my 2cents.

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


-- 
Respectfully,
- Collin Walling

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 1/3] qemu_monitor_json: Populate CPUModelInfo struct from json
Posted by Chris Venteicher, 3 days ago
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": {}}}
+static int
+qemuMonitorJSONBuildCPUModelInfo(virJSONValuePtr model_json,
+                                 qemuMonitorCPUModelInfoPtr *model)
+{
+    virJSONValuePtr cpu_model;
+    virJSONValuePtr cpu_props;
+    qemuMonitorCPUModelInfoPtr machine_model = NULL;
+    int ret = -1;
+    char const *cpu_name;
+
+    *model = NULL;
+
+    if (!(cpu_model = virJSONValueObjectGetObject(model_json, "model"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("query-cpu-model-expansion reply data was missing 'model'"));
+        goto cleanup;
+    }
+
+    if (!(cpu_name = virJSONValueObjectGetString(cpu_model, "name"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("query-cpu-model-expansion reply data was missing 'name'"));
+        goto cleanup;
+    }
+
+    if (!(cpu_props = virJSONValueObjectGetObject(cpu_model, "props"))) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("query-cpu-model-expansion reply data was missing 'props'"));
+        goto cleanup;
+    }
+
+    if (VIR_ALLOC(machine_model) < 0)
+        goto cleanup;
+
+    if (VIR_STRDUP(machine_model->name, cpu_name) < 0)
+        goto cleanup;
+
+    if (VIR_ALLOC_N(machine_model->props, virJSONValueObjectKeysNumber(cpu_props)) < 0)
+        goto cleanup;
+
+    if (virJSONValueObjectForeachKeyValue(cpu_props,
+                                          qemuMonitorJSONParseCPUModelProperty,
+                                          machine_model) < 0)
+        goto cleanup;
+
+    ret = 0;
+    *model = machine_model;
+    machine_model = NULL;
+
+ cleanup:
+    qemuMonitorCPUModelInfoFree(machine_model);
+
+    return ret;
+}
+
 int
 qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
                                     qemuMonitorCPUModelExpansionType type,
@@ -5351,9 +5406,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
     virJSONValuePtr reply = NULL;
     virJSONValuePtr data;
     virJSONValuePtr cpu_model;
-    virJSONValuePtr cpu_props;
     qemuMonitorCPUModelInfoPtr machine_model = NULL;
-    char const *cpu_name;
     const char *typeStr = "";
 
     *model_info = NULL;
@@ -5426,30 +5479,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
         goto retry;
     }
 
-    if (!(cpu_name = virJSONValueObjectGetString(cpu_model, "name"))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("query-cpu-model-expansion reply data was missing 'name'"));
-        goto cleanup;
-    }
-
-    if (!(cpu_props = virJSONValueObjectGetObject(cpu_model, "props"))) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("query-cpu-model-expansion reply data was missing 'props'"));
-        goto cleanup;
-    }
-
-    if (VIR_ALLOC(machine_model) < 0)
-        goto cleanup;
-
-    if (VIR_STRDUP(machine_model->name, cpu_name) < 0)
-        goto cleanup;
-
-    if (VIR_ALLOC_N(machine_model->props, virJSONValueObjectKeysNumber(cpu_props)) < 0)
-        goto cleanup;
-
-    if (virJSONValueObjectForeachKeyValue(cpu_props,
-                                          qemuMonitorJSONParseCPUModelProperty,
-                                          machine_model) < 0)
+    if (qemuMonitorJSONBuildCPUModelInfo(data, &machine_model) < 0)
         goto cleanup;
 
     ret = 0;
-- 
2.14.1

--
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
Posted by Ján Tomko, 3 days ago
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
--
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
Posted by Erik Skultety, 3 days ago
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
[libvirt] [PATCH 2/3] qemu_monitor_json: Build Json CPU Model Info
Posted by Chris Venteicher, 3 days ago
Function qemuMonitorJSONBuildCPUModelInfoJSON builds Json of form
{"model": {"name": "IvyBridge", "props": {}}}
from pointer to qemuMonitorCPUModelInfo.
---
 src/qemu/qemu_monitor_json.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index cf31c16a0..320d4601e 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5337,6 +5337,55 @@ qemuMonitorJSONParseCPUModelProperty(const char *key,
     return 0;
 }
 
+// model_json: {"model": {"name": "IvyBridge", "props": {}}}
+static int
+qemuMonitorJSONBuildCPUModelInfoJSON(qemuMonitorCPUModelInfoPtr model,
+                                     virJSONValuePtr *model_json)
+{
+    virJSONValuePtr cpu_props = NULL;
+    size_t i;
+    int ret = -1;
+
+    *model_json = NULL;
+
+    if (!(cpu_props = virJSONValueNewObject()))
+        goto cleanup;
+
+    for (i = 0; i < model->nprops; i++) {
+        qemuMonitorCPUPropertyPtr prop = model->props + i;
+
+        switch (prop->type) {
+        case QEMU_MONITOR_CPU_PROPERTY_BOOLEAN:
+            if (virJSONValueObjectAppendBoolean(cpu_props, prop->name, prop->value.boolean) < 0)
+                goto cleanup;
+            break;
+
+        case QEMU_MONITOR_CPU_PROPERTY_STRING:
+            if (virJSONValueObjectAppendString(cpu_props, prop->name, prop->value.string) < 0)
+                goto cleanup;
+            break;
+
+        case QEMU_MONITOR_CPU_PROPERTY_NUMBER:
+            if (virJSONValueObjectAppendNumberLong(cpu_props, prop->name, prop->value.number) < 0)
+                goto cleanup;
+            break;
+
+        case QEMU_MONITOR_CPU_PROPERTY_LAST:
+            break;
+        }
+    }
+
+    if (virJSONValueObjectCreate(model_json, "s:name", model->name,
+                                             "a:props", &cpu_props, NULL) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+
+    return ret;
+}
+
 // model_json: {"model": {"name": "IvyBridge", "props": {}}}
 static int
 qemuMonitorJSONBuildCPUModelInfo(virJSONValuePtr model_json,
-- 
2.14.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 2/3] qemu_monitor_json: Build Json CPU Model Info
Posted by Erik Skultety, 3 days ago
On Mon, Apr 16, 2018 at 01:06:57AM -0500, Chris Venteicher wrote:
> Function qemuMonitorJSONBuildCPUModelInfoJSON builds Json of form
> {"model": {"name": "IvyBridge", "props": {}}}
> from pointer to qemuMonitorCPUModelInfo.
> ---
>  src/qemu/qemu_monitor_json.c | 49 ++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 49 insertions(+)

...

> +
> +        switch (prop->type) {
> +        case QEMU_MONITOR_CPU_PROPERTY_BOOLEAN:
> +            if (virJSONValueObjectAppendBoolean(cpu_props, prop->name, prop->value.boolean) < 0)
> +                goto cleanup;
> +            break;
> +
> +        case QEMU_MONITOR_CPU_PROPERTY_STRING:
> +            if (virJSONValueObjectAppendString(cpu_props, prop->name, prop->value.string) < 0)
> +                goto cleanup;
> +            break;
> +
> +        case QEMU_MONITOR_CPU_PROPERTY_NUMBER:
> +            if (virJSONValueObjectAppendNumberLong(cpu_props, prop->name, prop->value.number) < 0)
> +                goto cleanup;
> +            break;
> +
> +        case QEMU_MONITOR_CPU_PROPERTY_LAST:
> +            break;

The most recent "correct" way to write switches in libvirt is to do the
following:
    case QEMU_MONITOR_CPU_PROPERTY_LAST:
    default:
        virReportEnumRangeError(qemuMonitorCPUPropertyPtr, prop->type);
        goto cleanup;

Erik

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
[libvirt] [PATCH 3/3] qemu_monitor: query-cpu-model-baseline QMP command
Posted by Chris Venteicher, 3 days ago
 Function qemuMonitorGetCPUModelBaseline exposed to carry out a QMP
 query-cpu-model-baseline transaction with QEMU.

 QEMU determines a baseline CPU Model from two input CPU Models to
 complete the query-cpu-model-baseline transaction.
---
 src/qemu/qemu_monitor.c      | 16 +++++++++++++
 src/qemu/qemu_monitor.h      |  5 ++++
 src/qemu/qemu_monitor_json.c | 56 ++++++++++++++++++++++++++++++++++++++++++++
 src/qemu/qemu_monitor_json.h |  7 ++++++
 4 files changed, 84 insertions(+)

diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 7b647525b..9db9d4b81 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -3874,6 +3874,22 @@ qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig)
     return NULL;
 }
 
+int
+qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
+                               qemuMonitorCPUModelInfoPtr model_a,
+                               qemuMonitorCPUModelInfoPtr model_b,
+                               qemuMonitorCPUModelInfoPtr *model_baseline)
+{
+    if (model_a)
+        VIR_DEBUG("model_a->name=%s", model_a->name);
+
+    if (model_b)
+        VIR_DEBUG("model_b->name=%s", model_b->name);
+
+    QEMU_CHECK_MONITOR_JSON(mon);
+
+    return qemuMonitorJSONGetCPUModelBaseline(mon, model_a, model_b, model_baseline);
+}
 
 int
 qemuMonitorGetCommands(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index d04148e56..c7a80ca63 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -1079,6 +1079,11 @@ void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info);
 qemuMonitorCPUModelInfoPtr
 qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig);
 
+int qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
+                                   qemuMonitorCPUModelInfoPtr model_a,
+                                   qemuMonitorCPUModelInfoPtr model_b,
+                                   qemuMonitorCPUModelInfoPtr *model_baseline);
+
 int qemuMonitorGetCommands(qemuMonitorPtr mon,
                            char ***commands);
 int qemuMonitorGetEvents(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 320d4601e..e03f6091c 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -5544,6 +5544,62 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
     return ret;
 }
 
+int
+qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon,
+                                   qemuMonitorCPUModelInfoPtr model_a,
+                                   qemuMonitorCPUModelInfoPtr model_b,
+                                   qemuMonitorCPUModelInfoPtr *model_baseline)
+{
+    int ret = -1;
+    virJSONValuePtr cmd   = NULL;
+    virJSONValuePtr reply = NULL;
+    virJSONValuePtr data  = NULL;
+    virJSONValuePtr modela = NULL;
+    virJSONValuePtr modelb = NULL;
+
+    *model_baseline = NULL;
+
+    if (qemuMonitorJSONBuildCPUModelInfoJSON(model_a, &modela) < 0)
+        goto cleanup;
+
+    if (qemuMonitorJSONBuildCPUModelInfoJSON(model_b, &modelb) < 0)
+        goto cleanup;
+
+    if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-baseline",
+                                           "a:modela", &modela,
+                                           "a:modelb", &modelb,
+                                           NULL)))
+        goto cleanup;
+
+
+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
+        goto cleanup;
+
+    /* Urgh, some QEMU architectures have query-cpu-model-baseline
+     * command but return 'GenericError' with string "Not supported",
+     * instead of simply omitting the command entirely
+     */
+    if (qemuMonitorJSONHasError(reply, "GenericError"))
+        goto cleanup;
+
+    if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0)
+        goto cleanup;
+
+    data = virJSONValueObjectGetObject(reply, "return");
+
+    if (qemuMonitorJSONBuildCPUModelInfo(data, model_baseline) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    virJSONValueFree(cmd);
+    virJSONValueFree(reply);
+    virJSONValueFree(modela);
+    virJSONValueFree(modelb);
+
+    return ret;
+}
 
 int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
                                char ***commands)
diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
index 045df4919..6c33049c6 100644
--- a/src/qemu/qemu_monitor_json.h
+++ b/src/qemu/qemu_monitor_json.h
@@ -361,6 +361,13 @@ int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
                                         qemuMonitorCPUModelInfoPtr *model_info)
     ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(5);
 
+int qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon,
+                                       qemuMonitorCPUModelInfoPtr model_a,
+                                       qemuMonitorCPUModelInfoPtr model_b,
+                                       qemuMonitorCPUModelInfoPtr *model_baseline)
+    ATTRIBUTE_NONNULL(4);
+
+
 int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
                                char ***commands)
     ATTRIBUTE_NONNULL(2);
-- 
2.14.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/3] qemu_monitor: query-cpu-model-baseline QMP command
Posted by Ján Tomko, 3 days ago
On Mon, Apr 16, 2018 at 01:06:58AM -0500, Chris Venteicher wrote:
> Function qemuMonitorGetCPUModelBaseline exposed to carry out a QMP
> query-cpu-model-baseline transaction with QEMU.
>
> QEMU determines a baseline CPU Model from two input CPU Models to
> complete the query-cpu-model-baseline transaction.
>---
> src/qemu/qemu_monitor.c      | 16 +++++++++++++
> src/qemu/qemu_monitor.h      |  5 ++++
> src/qemu/qemu_monitor_json.c | 56 ++++++++++++++++++++++++++++++++++++++++++++
> src/qemu/qemu_monitor_json.h |  7 ++++++
> 4 files changed, 84 insertions(+)
>
>diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
>index 7b647525b..9db9d4b81 100644
>--- a/src/qemu/qemu_monitor.c
>+++ b/src/qemu/qemu_monitor.c
>@@ -3874,6 +3874,22 @@ qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig)
>     return NULL;
> }
>
>+int
>+qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
>+                               qemuMonitorCPUModelInfoPtr model_a,
>+                               qemuMonitorCPUModelInfoPtr model_b,
>+                               qemuMonitorCPUModelInfoPtr *model_baseline)
>+{
>+    if (model_a)
>+        VIR_DEBUG("model_a->name=%s", model_a->name);
>+
>+    if (model_b)
>+        VIR_DEBUG("model_b->name=%s", model_b->name);
>+
>+    QEMU_CHECK_MONITOR_JSON(mon);
>+
>+    return qemuMonitorJSONGetCPUModelBaseline(mon, model_a, model_b, model_baseline);
>+}
>
> int
> qemuMonitorGetCommands(qemuMonitorPtr mon,
>diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
>index d04148e56..c7a80ca63 100644
>--- a/src/qemu/qemu_monitor.h
>+++ b/src/qemu/qemu_monitor.h
>@@ -1079,6 +1079,11 @@ void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info);
> qemuMonitorCPUModelInfoPtr
> qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig);
>
>+int qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
>+                                   qemuMonitorCPUModelInfoPtr model_a,
>+                                   qemuMonitorCPUModelInfoPtr model_b,
>+                                   qemuMonitorCPUModelInfoPtr *model_baseline);
>+
> int qemuMonitorGetCommands(qemuMonitorPtr mon,
>                            char ***commands);
> int qemuMonitorGetEvents(qemuMonitorPtr mon,
>diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
>index 320d4601e..e03f6091c 100644
>--- a/src/qemu/qemu_monitor_json.c
>+++ b/src/qemu/qemu_monitor_json.c
>@@ -5544,6 +5544,62 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
>     return ret;
> }
>
>+int
>+qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon,
>+                                   qemuMonitorCPUModelInfoPtr model_a,
>+                                   qemuMonitorCPUModelInfoPtr model_b,
>+                                   qemuMonitorCPUModelInfoPtr *model_baseline)
>+{
>+    int ret = -1;
>+    virJSONValuePtr cmd   = NULL;
>+    virJSONValuePtr reply = NULL;
>+    virJSONValuePtr data  = NULL;
>+    virJSONValuePtr modela = NULL;
>+    virJSONValuePtr modelb = NULL;

Please do not try to align the =.

>+
>+    *model_baseline = NULL;
>+
>+    if (qemuMonitorJSONBuildCPUModelInfoJSON(model_a, &modela) < 0)
>+        goto cleanup;
>+
>+    if (qemuMonitorJSONBuildCPUModelInfoJSON(model_b, &modelb) < 0)
>+        goto cleanup;
>+
>+    if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-baseline",
>+                                           "a:modela", &modela,
>+                                           "a:modelb", &modelb,
>+                                           NULL)))
>+        goto cleanup;
>+
>+
>+    if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
>+        goto cleanup;
>+
>+    /* Urgh, some QEMU architectures have query-cpu-model-baseline
>+     * command but return 'GenericError' with string "Not supported",
>+     * instead of simply omitting the command entirely
>+     */
>+    if (qemuMonitorJSONHasError(reply, "GenericError"))
>+        goto cleanup;

Missing virReportError.

Ideally, on error all libvirt functions would either call virReportError
or be quiet in all possible exit paths.

Jano
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/3] qemu_monitor: query-cpu-model-baseline QMP command
Posted by Chris Venteicher, 1 day ago

On 04/16/2018 03:02 AM, J�n Tomko wrote:
> On Mon, Apr 16, 2018 at 01:06:58AM -0500, Chris Venteicher wrote:
>> Function qemuMonitorGetCPUModelBaseline exposed to carry out a QMP
>> query-cpu-model-baseline transaction with QEMU.
>>
>> QEMU determines a baseline CPU Model from two input CPU Models to
>> complete the query-cpu-model-baseline transaction.
>> ---
>> src/qemu/qemu_monitor.c����� | 16 +++++++++++++
>> src/qemu/qemu_monitor.h����� |� 5 ++++
>> src/qemu/qemu_monitor_json.c | 56 
>> ++++++++++++++++++++++++++++++++++++++++++++
>> src/qemu/qemu_monitor_json.h |� 7 ++++++
>> 4 files changed, 84 insertions(+)
>>
>> diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
>> index 7b647525b..9db9d4b81 100644
>> --- a/src/qemu/qemu_monitor.c
>> +++ b/src/qemu/qemu_monitor.c
>> @@ -3874,6 +3874,22 @@ qemuMonitorCPUModelInfoCopy(const 
>> qemuMonitorCPUModelInfo *orig)
>> ��� return NULL;
>> }
>>
>> +int
>> +qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
>> +������������������������������ qemuMonitorCPUModelInfoPtr model_a,
>> +������������������������������ qemuMonitorCPUModelInfoPtr model_b,
>> +������������������������������ qemuMonitorCPUModelInfoPtr 
>> *model_baseline)
>> +{
>> +��� if (model_a)
>> +������� VIR_DEBUG("model_a->name=%s", model_a->name);
>> +
>> +��� if (model_b)
>> +������� VIR_DEBUG("model_b->name=%s", model_b->name);
>> +
>> +��� QEMU_CHECK_MONITOR_JSON(mon);
>> +
>> +��� return qemuMonitorJSONGetCPUModelBaseline(mon, model_a, model_b, 
>> model_baseline);
>> +}
>>
>> int
>> qemuMonitorGetCommands(qemuMonitorPtr mon,
>> diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
>> index d04148e56..c7a80ca63 100644
>> --- a/src/qemu/qemu_monitor.h
>> +++ b/src/qemu/qemu_monitor.h
>> @@ -1079,6 +1079,11 @@ void 
>> qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info);
>> qemuMonitorCPUModelInfoPtr
>> qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig);
>>
>> +int qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon,
>> +���������������������������������� qemuMonitorCPUModelInfoPtr model_a,
>> +���������������������������������� qemuMonitorCPUModelInfoPtr model_b,
>> +���������������������������������� qemuMonitorCPUModelInfoPtr 
>> *model_baseline);
>> +
>> int qemuMonitorGetCommands(qemuMonitorPtr mon,
>> �������������������������� char ***commands);
>> int qemuMonitorGetEvents(qemuMonitorPtr mon,
>> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
>> index 320d4601e..e03f6091c 100644
>> --- a/src/qemu/qemu_monitor_json.c
>> +++ b/src/qemu/qemu_monitor_json.c
>> @@ -5544,6 +5544,62 @@ 
>> qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
>> ��� return ret;
>> }
>>
>> +int
>> +qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon,
>> +���������������������������������� qemuMonitorCPUModelInfoPtr model_a,
>> +���������������������������������� qemuMonitorCPUModelInfoPtr model_b,
>> +���������������������������������� qemuMonitorCPUModelInfoPtr 
>> *model_baseline)
>> +{
>> +��� int ret = -1;
>> +��� virJSONValuePtr cmd�� = NULL;
>> +��� virJSONValuePtr reply = NULL;
>> +��� virJSONValuePtr data� = NULL;
>> +��� virJSONValuePtr modela = NULL;
>> +��� virJSONValuePtr modelb = NULL;
>
> Please do not try to align the =.
>
>> +
>> +��� *model_baseline = NULL;
>> +
>> +��� if (qemuMonitorJSONBuildCPUModelInfoJSON(model_a, &modela) < 0)
>> +������� goto cleanup;
>> +
>> +��� if (qemuMonitorJSONBuildCPUModelInfoJSON(model_b, &modelb) < 0)
>> +������� goto cleanup;
>> +
>> +��� if (!(cmd = qemuMonitorJSONMakeCommand("query-cpu-model-baseline",
>> +������������������������������������������ "a:modela", &modela,
>> +������������������������������������������ "a:modelb", &modelb,
>> +������������������������������������������ NULL)))
>> +������� goto cleanup;
>> +
>> +
>> +��� if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0)
>> +������� goto cleanup;
>> +
>> +��� /* Urgh, some QEMU architectures have query-cpu-model-baseline
>> +���� * command but return 'GenericError' with string "Not supported",
>> +���� * instead of simply omitting the command entirely
>> +���� */
>> +��� if (qemuMonitorJSONHasError(reply, "GenericError"))
>> +������� goto cleanup;
>
> Missing virReportError.
>
> Ideally, on error all libvirt functions would either call virReportError
> or be quiet in all possible exit paths.
Please see next version of patch set...
Returning 0 instead of -1 in response to reply "GenericError" to be 
consistent with other commands.

Otherwise, I think I am mirroring other functions in the file in terms 
of when virReportError is called.
Possible exception is error while parsing "return" json within 
qemuMonitorJSONBuildCPUModelInfoFromJSON... But virReportErrors are 
generated within that function if there found.

Please advise with specifics places I where I should be adding 
virReportErrors if you still see the problem in version 2 of the patch set.

Chris

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

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 3/3] qemu_monitor: query-cpu-model-baseline QMP command
Posted by Collin Walling, 3 days ago
On 04/16/2018 02:06 AM, Chris Venteicher wrote:
>  Function qemuMonitorGetCPUModelBaseline exposed to carry out a QMP
>  query-cpu-model-baseline transaction with QEMU.
> 
>  QEMU determines a baseline CPU Model from two input CPU Models to
>  complete the query-cpu-model-baseline transaction.
> ---
>  src/qemu/qemu_monitor.c      | 16 +++++++++++++
>  src/qemu/qemu_monitor.h      |  5 ++++
>  src/qemu/qemu_monitor_json.c | 56 ++++++++++++++++++++++++++++++++++++++++++++
>  src/qemu/qemu_monitor_json.h |  7 ++++++
>  4 files changed, 84 insertions(+)
> 
[...]
>  
>  int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
>                                 char ***commands)
> diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h
> index 045df4919..6c33049c6 100644
> --- a/src/qemu/qemu_monitor_json.h
> +++ b/src/qemu/qemu_monitor_json.h
> @@ -361,6 +361,13 @@ int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon,
>                                          qemuMonitorCPUModelInfoPtr *model_info)
>      ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(5);
>  
> +int qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon,
> +                                       qemuMonitorCPUModelInfoPtr model_a,
> +                                       qemuMonitorCPUModelInfoPtr model_b,
> +                                       qemuMonitorCPUModelInfoPtr *model_baseline)
> +    ATTRIBUTE_NONNULL(4);
> +
> +

I believe you want NONNULL(2) and (3) here as well.

>  int qemuMonitorJSONGetCommands(qemuMonitorPtr mon,
>                                 char ***commands)
>      ATTRIBUTE_NONNULL(2);
> 


-- 
Respectfully,
- Collin Walling

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