From nobody Thu Apr 25 07:21:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531195029126328.7632372841384; Mon, 9 Jul 2018 20:57:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2329280F6C; Tue, 10 Jul 2018 03:57:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB612308BDAC; Tue, 10 Jul 2018 03:57:05 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DCA6818037EC; Tue, 10 Jul 2018 03:57:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6A3v2Kh003322 for ; Mon, 9 Jul 2018 23:57:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id C78C17C54; Tue, 10 Jul 2018 03:57:02 +0000 (UTC) Received: from cv1.lan (ovpn-120-63.rdu2.redhat.com [10.10.120.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E76D7C4D; Tue, 10 Jul 2018 03:57:02 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 22:56:45 -0500 Message-Id: <20180710035655.24983-2-cventeic@redhat.com> In-Reply-To: <20180710035655.24983-1-cventeic@redhat.com> References: <20180710035655.24983-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , david@redhat.com Subject: [libvirt] [PATCHv2 01/11] qemu_monitor_json: Introduce qemuMonitorCPUModelInfo / JSON conversion X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 10 Jul 2018 03:57:06 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Bidirectional conversion functions between Monitor data structure and QMP Message JSON. Commit creates reusable functions usable anywhere CPUModelInfo structure is input or output from QMP Commands. JSON of form: {"model": {"name": "IvyBridge", "props": {}}} --- src/qemu/qemu_monitor_json.c | 126 ++++++++++++++++++++++++++--------- 1 file changed, 96 insertions(+), 30 deletions(-) diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index f9fe9e35ba..a18a1a1bf1 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5345,6 +5345,101 @@ qemuMonitorJSONParseCPUModelProperty(const char *ke= y, return 0; } =20 + +/* model_json: {"name": "z13-base", "props": {}} + */ +static virJSONValuePtr +qemuMonitorJSONBuildCPUModelInfoToJSON(qemuMonitorCPUModelInfoPtr model) +{ + virJSONValuePtr cpu_props =3D NULL; + virJSONValuePtr model_json =3D NULL; + size_t i; + + if (!model) + goto cleanup; + + if (!(cpu_props =3D virJSONValueNewObject())) + goto cleanup; + + for (i =3D 0; i < model->nprops; i++) { + qemuMonitorCPUPropertyPtr prop =3D &(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: + default: + virReportEnumRangeError(qemuMonitorCPUPropertyPtr, prop->type); + goto cleanup; + } + } + + ignore_value(virJSONValueObjectCreate(&model_json, "s:name", model->na= me, + "a:props", &cpu_props, NULL)); + + cleanup: + virJSONValueFree(cpu_props); + return model_json; +} + + +/* model_json: {"name": "IvyBridge", "props": {}} + */ +static qemuMonitorCPUModelInfoPtr +qemuMonitorJSONBuildCPUModelInfoFromJSON(virJSONValuePtr cpu_model) +{ + virJSONValuePtr cpu_props; + qemuMonitorCPUModelInfoPtr machine_model =3D NULL; + qemuMonitorCPUModelInfoPtr model =3D NULL; + char const *cpu_name; + + if (!(cpu_name =3D virJSONValueObjectGetString(cpu_model, "name"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Parsed JSON reply missing 'name'")); + goto cleanup; + } + + if (VIR_ALLOC(machine_model) < 0) + goto cleanup; + + if (VIR_STRDUP(machine_model->name, cpu_name) < 0) + goto cleanup; + + if ((cpu_props =3D virJSONValueObjectGetObject(cpu_model, "props"))) { + if (VIR_ALLOC_N(machine_model->props, + virJSONValueObjectKeysNumber(cpu_props)) < 0) + goto cleanup; + + if (virJSONValueObjectForeachKeyValue(cpu_props, + qemuMonitorJSONParseCPUModel= Property, + machine_model) < 0) + goto cleanup; + } + + VIR_STEAL_PTR(model, machine_model); + + cleanup: + qemuMonitorCPUModelInfoFree(machine_model); + + return model; +} + int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon, qemuMonitorCPUModelExpansionType type, @@ -5359,9 +5454,6 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mo= n, virJSONValuePtr reply =3D NULL; virJSONValuePtr data; virJSONValuePtr cpu_model; - virJSONValuePtr cpu_props; - qemuMonitorCPUModelInfoPtr machine_model =3D NULL; - char const *cpu_name; const char *typeStr =3D ""; =20 *model_info =3D NULL; @@ -5434,38 +5526,12 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr = mon, goto retry; } =20 - if (!(cpu_name =3D virJSONValueObjectGetString(cpu_model, "name"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-cpu-model-expansion reply data was missing= 'name'")); - goto cleanup; - } - - if (!(cpu_props =3D 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, - qemuMonitorJSONParseCPUModelProp= erty, - machine_model) < 0) + if (!(*model_info =3D qemuMonitorJSONBuildCPUModelInfoFromJSON(cpu_mod= el))) goto cleanup; =20 ret =3D 0; - *model_info =3D machine_model; - machine_model =3D NULL; =20 cleanup: - qemuMonitorCPUModelInfoFree(machine_model); virJSONValueFree(cmd); virJSONValueFree(reply); virJSONValueFree(model); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 07:21:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531195029051646.1728428581604; Mon, 9 Jul 2018 20:57:09 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 64C913084030; Tue, 10 Jul 2018 03:57:07 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2F8C119485; Tue, 10 Jul 2018 03:57:07 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A78EF18037F0; Tue, 10 Jul 2018 03:57:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6A3v37W003333 for ; Mon, 9 Jul 2018 23:57:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7F25F7C59; Tue, 10 Jul 2018 03:57:03 +0000 (UTC) Received: from cv1.lan (ovpn-120-63.rdu2.redhat.com [10.10.120.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id F39157C4D; Tue, 10 Jul 2018 03:57:02 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 22:56:46 -0500 Message-Id: <20180710035655.24983-3-cventeic@redhat.com> In-Reply-To: <20180710035655.24983-1-cventeic@redhat.com> References: <20180710035655.24983-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , david@redhat.com Subject: [libvirt] [PATCHv2 02/11] qemu_monitor: Introduce qemuMonitorGetCPUModelBaseline (query-cpu-model-baseline) X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Tue, 10 Jul 2018 03:57:08 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Wrap QMP query-cpu-model-baseline command transaction with QEMU. --- src/qemu/qemu_monitor.c | 13 ++++++++ src/qemu/qemu_monitor.h | 6 ++++ src/qemu/qemu_monitor_json.c | 63 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 7 ++++ 4 files changed, 89 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 6ed475ede0..a3278c018e 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3707,6 +3707,19 @@ qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUMode= lInfo *orig) return NULL; } =20 +int +qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon, + qemuMonitorCPUModelInfoPtr model_a, + qemuMonitorCPUModelInfoPtr model_b, + qemuMonitorCPUModelInfoPtr *model_baseline) +{ + VIR_DEBUG("model_a->name=3D%s, model_a->nprops=3D%lu", model_a->name, = model_a->nprops); + VIR_DEBUG("model_b->name=3D%s, model_b->nprops=3D%lu", model_b->name, = model_b->nprops); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONGetCPUModelBaseline(mon, model_a, model_b, model= _baseline); +} =20 int qemuMonitorGetCommands(qemuMonitorPtr mon, diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index b3d62324b4..18b59be985 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1025,6 +1025,12 @@ void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModel= InfoPtr model_info); qemuMonitorCPUModelInfoPtr qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig); =20 +int qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon, + qemuMonitorCPUModelInfoPtr model_a, + qemuMonitorCPUModelInfoPtr model_b, + qemuMonitorCPUModelInfoPtr *model_basel= ine) + ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4); + 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 a18a1a1bf1..90d43eee97 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5540,6 +5540,69 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr m= on, } =20 =20 +/* Note: *model_baseline =3D=3D NULL && return =3D=3D 0 if command not sup= ported by QEMU + */ +int +qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon, + qemuMonitorCPUModelInfoPtr model_a, + qemuMonitorCPUModelInfoPtr model_b, + qemuMonitorCPUModelInfoPtr *model_basel= ine) +{ + int ret =3D -1; + virJSONValuePtr cmd =3D NULL; + virJSONValuePtr reply =3D NULL; + virJSONValuePtr data =3D NULL; + virJSONValuePtr modela =3D NULL; + virJSONValuePtr modelb =3D NULL; + virJSONValuePtr cpu_model =3D NULL; + + *model_baseline =3D NULL; + + if (!(modela =3D qemuMonitorJSONBuildCPUModelInfoToJSON(model_a)) || + !(modelb =3D qemuMonitorJSONBuildCPUModelInfoToJSON(model_b))) + goto cleanup; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("query-cpu-model-baseline", + "a:modela", &modela, + "a:modelb", &modelb, + NULL))) + goto cleanup; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONHasError(reply, "GenericError")) { + /* QEMU does not support query-cpu-model-baseline or cpu model */ + ret =3D 0; + goto cleanup; + } + + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_OBJECT) < 0) + goto cleanup; + + data =3D virJSONValueObjectGetObject(reply, "return"); + + if (!(cpu_model =3D virJSONValueObjectGetObject(data, "model"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("query-cpu-model-baseline reply data was missing = 'model'")); + goto cleanup; + } + + if (!(*model_baseline =3D qemuMonitorJSONBuildCPUModelInfoFromJSON(cpu= _model))) + goto cleanup; + + ret =3D 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 6bc0dd3ad2..73e1cb6ace 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -367,6 +367,13 @@ int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr= mon, qemuMonitorCPUModelInfoPtr *model_= info) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(5); =20 +int qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon, + qemuMonitorCPUModelInfoPtr model_a, + qemuMonitorCPUModelInfoPtr model_b, + qemuMonitorCPUModelInfoPtr *model_b= aseline) + ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4); + + int qemuMonitorJSONGetCommands(qemuMonitorPtr mon, char ***commands) ATTRIBUTE_NONNULL(2); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 07:21:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531195041363335.85942258719706; Mon, 9 Jul 2018 20:57:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D009B8553F; Tue, 10 Jul 2018 03:57:19 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 99F85600CD; Tue, 10 Jul 2018 03:57:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 44F1918037F7; Tue, 10 Jul 2018 03:57:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6A3v4uG003338 for ; Mon, 9 Jul 2018 23:57:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 334177C59; Tue, 10 Jul 2018 03:57:04 +0000 (UTC) Received: from cv1.lan (ovpn-120-63.rdu2.redhat.com [10.10.120.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id A76777C4D; Tue, 10 Jul 2018 03:57:03 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 22:56:47 -0500 Message-Id: <20180710035655.24983-4-cventeic@redhat.com> In-Reply-To: <20180710035655.24983-1-cventeic@redhat.com> References: <20180710035655.24983-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , david@redhat.com Subject: [libvirt] [PATCHv2 03/11] qemu_monitor: Indicate when CPUModelInfo props report migratablity X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 10 Jul 2018 03:57:20 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Renamed variable in CPUModelInfo such that props_migratable_valid is true when properties in CPUModelInfo have been updated to accurately indicate if property is / isn't migratable. Property migratability is not returned directly in QMP messages but rather is sometimes calculated within Libvirt by other means and then stored in CPUModelInfo properties by Libvirt. props_migratable_valid is set to true when this calculation has been done by Libvirt. --- src/qemu/qemu_capabilities.c | 10 +++++----- src/qemu/qemu_monitor.c | 2 +- src/qemu/qemu_monitor.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index c7da916f9a..3d78e2e29b 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2410,7 +2410,7 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps, } } =20 - modelInfo->migratability =3D true; + modelInfo->props_migratable_valid =3D true; } =20 VIR_STEAL_PTR(cpuData->info, modelInfo); @@ -2465,7 +2465,7 @@ virQEMUCapsGetCPUFeatures(virQEMUCapsPtr qemuCaps, } =20 VIR_STEAL_PTR(*features, list); - if (migratable && !data->info->migratability) + if (migratable && !data->info->props_migratable_valid) ret =3D 1; else ret =3D 0; @@ -2864,7 +2864,7 @@ virQEMUCapsInitCPUModel(virQEMUCapsPtr qemuCaps, virQEMUCapsHostCPUDataPtr cpuData =3D virQEMUCapsGetHostCPUData(qemuCa= ps, type); int ret =3D 1; =20 - if (migratable && cpuData->info && !cpuData->info->migratability) + if (migratable && cpuData->info && !cpuData->info->props_migratable_va= lid) return 1; =20 if (ARCH_IS_S390(qemuCaps->arch)) { @@ -3047,7 +3047,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsPtr qemuCa= ps, _("invalid migratability value for host CPU model")= ); goto cleanup; } - hostCPU->migratability =3D val =3D=3D VIR_TRISTATE_BOOL_YES; + hostCPU->props_migratable_valid =3D val =3D=3D VIR_TRISTATE_BOOL_YES; VIR_FREE(str); =20 ctxt->node =3D hostCPUNode; @@ -3540,7 +3540,7 @@ virQEMUCapsFormatHostCPUModelInfo(virQEMUCapsPtr qemu= Caps, virBufferAsprintf(buf, "\n", typeStr, model->name, - model->migratability ? "yes" : "no"); + model->props_migratable_valid ? "yes" : "no"); virBufferAdjustIndent(buf, 2); =20 for (i =3D 0; i < model->nprops; i++) { diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index a3278c018e..371aaa15da 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3671,7 +3671,7 @@ qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModel= Info *orig) if (VIR_STRDUP(copy->name, orig->name) < 0) goto error; =20 - copy->migratability =3D orig->migratability; + copy->props_migratable_valid =3D orig->props_migratable_valid; copy->nprops =3D orig->nprops; =20 for (i =3D 0; i < orig->nprops; i++) { diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 18b59be985..208a7f5d21 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1005,7 +1005,7 @@ struct _qemuMonitorCPUModelInfo { char *name; size_t nprops; qemuMonitorCPUPropertyPtr props; - bool migratability; + bool props_migratable_valid; }; =20 typedef enum { --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 07:21:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531195041199748.4963452386941; Mon, 9 Jul 2018 20:57:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00C13308A964; Tue, 10 Jul 2018 03:57:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BAA3D308BDAE; Tue, 10 Jul 2018 03:57:19 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 722614A465; Tue, 10 Jul 2018 03:57:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6A3v4ZJ003349 for ; Mon, 9 Jul 2018 23:57:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id DAF417C59; Tue, 10 Jul 2018 03:57:04 +0000 (UTC) Received: from cv1.lan (ovpn-120-63.rdu2.redhat.com [10.10.120.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5B52B7C4D; Tue, 10 Jul 2018 03:57:04 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 22:56:48 -0500 Message-Id: <20180710035655.24983-5-cventeic@redhat.com> In-Reply-To: <20180710035655.24983-1-cventeic@redhat.com> References: <20180710035655.24983-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , david@redhat.com Subject: [libvirt] [PATCHv2 04/11] qemu_monitor: Introduce qemuMonitorCPUModelInfoInit and qemuMonitorCPUModelInfoFreeContents X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Tue, 10 Jul 2018 03:57:20 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" These forms modify contents of a qemuMonitorCPUModelInfo structure but do not allocate or free the actual structure. Init - Initialize model name and empty properties within existing structure FreeContents - Free model name and properties within existing structure --- src/qemu/qemu_monitor.c | 35 ++++++++++++++++++++++++++++++++++- src/qemu/qemu_monitor.h | 4 ++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 371aaa15da..2d9297c3a7 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3636,8 +3636,31 @@ qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon, } =20 =20 +int +qemuMonitorCPUModelInfoInit(const char *name, qemuMonitorCPUModelInfoPtr m= odel) +{ + int ret =3D -1; + + if (!model) + goto cleanup; + + model->name =3D NULL; + model->nprops =3D 0; + model->props =3D NULL; + model->props_migratable_valid =3D false; + + if (VIR_STRDUP(model->name, name) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + return ret; +} + + void -qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info) +qemuMonitorCPUModelInfoFreeContents(qemuMonitorCPUModelInfoPtr model_info) { size_t i; =20 @@ -3652,6 +3675,16 @@ qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoP= tr model_info) =20 VIR_FREE(model_info->props); VIR_FREE(model_info->name); + + model_info->nprops =3D 0; + model_info->props_migratable_valid =3D false; +} + + +void +qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info) +{ + qemuMonitorCPUModelInfoFreeContents(model_info); VIR_FREE(model_info); } =20 diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 208a7f5d21..0b84a91fbc 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1021,6 +1021,10 @@ int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr m= on, qemuMonitorCPUModelInfoPtr *model_info= ); =20 void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info); +void qemuMonitorCPUModelInfoFreeContents(qemuMonitorCPUModelInfoPtr model_= info); + +int qemuMonitorCPUModelInfoInit(const char *name, qemuMonitorCPUModelInfoP= tr model) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 qemuMonitorCPUModelInfoPtr qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig); --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 07:21:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531195045866117.50460235899322; Mon, 9 Jul 2018 20:57:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 40A294E4C6; Tue, 10 Jul 2018 03:57:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EEF085D761; Tue, 10 Jul 2018 03:57:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 9DFD318037F5; Tue, 10 Jul 2018 03:57:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6A3v5fs003355 for ; Mon, 9 Jul 2018 23:57:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8F1A37C59; Tue, 10 Jul 2018 03:57:05 +0000 (UTC) Received: from cv1.lan (ovpn-120-63.rdu2.redhat.com [10.10.120.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F2B57C4D; Tue, 10 Jul 2018 03:57:04 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 22:56:49 -0500 Message-Id: <20180710035655.24983-6-cventeic@redhat.com> In-Reply-To: <20180710035655.24983-1-cventeic@redhat.com> References: <20180710035655.24983-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , david@redhat.com Subject: [libvirt] [PATCHv2 05/11] qemu_monitor: CPUModelExpansion on both model name and properties X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 10 Jul 2018 03:57:24 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Send both model name and a set of features/properties to QEMU for expansion rather than just the model name. Required to expand name+props models of the form computed by baseline into fully expanded (all props/features listed) output. --- src/qemu/qemu_capabilities.c | 42 +++++++++++++++++----- src/qemu/qemu_monitor.c | 38 ++++++++++++++++---- src/qemu/qemu_monitor.h | 5 ++- src/qemu/qemu_monitor_json.c | 69 ++++++++++++++++++++++++------------ src/qemu/qemu_monitor_json.h | 7 ++-- tests/cputest.c | 7 +++- 6 files changed, 122 insertions(+), 46 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 3d78e2e29b..72ab012a78 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2343,23 +2343,32 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps, qemuMonitorCPUModelInfoPtr modelInfo =3D NULL; qemuMonitorCPUModelInfoPtr nonMigratable =3D NULL; virHashTablePtr hash =3D NULL; - const char *model; + const char *model_name; qemuMonitorCPUModelExpansionType type; virDomainVirtType virtType; virQEMUCapsHostCPUDataPtr cpuData; int ret =3D -1; + int err =3D -1; =20 if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSION)) return 0; =20 if (tcg || !virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) { virtType =3D VIR_DOMAIN_VIRT_QEMU; - model =3D "max"; + model_name =3D "max"; } else { virtType =3D VIR_DOMAIN_VIRT_KVM; - model =3D "host"; + model_name =3D "host"; } =20 + if ((VIR_ALLOC(modelInfo) < 0) || + (VIR_ALLOC(nonMigratable) < 0)) + goto cleanup; + + if ((qemuMonitorCPUModelInfoInit(model_name, modelInfo) < 0) || + (qemuMonitorCPUModelInfoInit(model_name, nonMigratable) < 0)) + goto cleanup; + cpuData =3D virQEMUCapsGetHostCPUData(qemuCaps, virtType); =20 /* Some x86_64 features defined in cpu_map.xml use spelling which diff= er @@ -2372,16 +2381,31 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps, else type =3D QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC; =20 - if (qemuMonitorGetCPUModelExpansion(mon, type, model, true, &modelInfo= ) < 0) + if ((err =3D qemuMonitorGetCPUModelExpansion(mon, type, true, modelInf= o)) < 0) goto cleanup; =20 - /* Try to check migratability of each feature. */ - if (modelInfo && - qemuMonitorGetCPUModelExpansion(mon, type, model, false, - &nonMigratable) < 0) + if (err =3D=3D 1) { + ret =3D 0; /* Qemu can't do expansion 1, exit without error */ + goto cleanup; /* We don't have info so don't update cpuData->info = */ + } + + if ((err =3D qemuMonitorGetCPUModelExpansion(mon, type, false, nonMigr= atable)) < 0) goto cleanup; =20 - if (nonMigratable) { + /* Try to check migratability of each feature */ + /* Expansion 1 sets migratable features true + * Expansion 2 sets migratable and non-migratable features true + * (non-migratable set true only in some archs like X86) + * + * If delta between Expansion 1 and 2 exists... + * - both migratable and non-migratable features set prop->value =3D t= rue + * - migratable features set prop->migatable =3D VIR_TRISTATE_BOOL_YES + * - non-migratable features set prop->migatable =3D VIR_TRISTATE_BOOL= _NO + */ + if (err =3D=3D 0) { + /* Expansion 2 succeded + * Qemu expanded both migratable and nonMigratable features */ + qemuMonitorCPUPropertyPtr prop; qemuMonitorCPUPropertyPtr nmProp; size_t i; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 2d9297c3a7..91b946c8b4 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3619,20 +3619,46 @@ qemuMonitorCPUDefInfoFree(qemuMonitorCPUDefInfoPtr = cpu) } =20 =20 +/* + * type static: + * Expand to static base model + delta property changes + * Returned model is invariant and migration safe + * + * model_info->name =3D base model name + * model_info->props =3D features to +/- to base model to achive model_n= ame + * + * type full: + * Expand model to enumerate all properties + * Returned model isn't guaranteed to be invariant or migration safe. + * + * model_info->name =3D base model name + * model_info->props =3D features to +/- to empty set to achive model_na= me + * + * type static_full: + * Expand to static base model + delta property changes (pass 0) + * Expand model to enumerate all properties (pass 1) + * Returned model is invariant and migration safe + * + * model_info->name =3D base model name + * model_info->props =3D features to +/- to empty set to achive model_na= me + * + * migratable_only: + * true: QEMU excludes non-migratable features + * false: QEMU includes non-migratable features for some archs like X86 + */ int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon, qemuMonitorCPUModelExpansionType type, - const char *model_name, - bool migratable, - qemuMonitorCPUModelInfoPtr *model_info) + bool migratable_only, + qemuMonitorCPUModelInfoPtr model_info) { VIR_DEBUG("type=3D%d model_name=3D%s migratable=3D%d", - type, model_name, migratable); + type, (model_info ? NULLSTR(model_info->name):"NULL"), + migratable_only); =20 QEMU_CHECK_MONITOR(mon); =20 - return qemuMonitorJSONGetCPUModelExpansion(mon, type, model_name, - migratable, model_info); + return qemuMonitorJSONGetCPUModelExpansion(mon, type, migratable_only,= model_info); } =20 =20 diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 0b84a91fbc..6b4b527512 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1016,9 +1016,8 @@ typedef enum { =20 int qemuMonitorGetCPUModelExpansion(qemuMonitorPtr mon, qemuMonitorCPUModelExpansionType type, - const char *model_name, - bool migratable, - qemuMonitorCPUModelInfoPtr *model_info= ); + bool migratable_only, + qemuMonitorCPUModelInfoPtr model_info); =20 void qemuMonitorCPUModelInfoFree(qemuMonitorCPUModelInfoPtr model_info); void qemuMonitorCPUModelInfoFreeContents(qemuMonitorCPUModelInfoPtr model_= info); diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 90d43eee97..9b681f4592 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -5390,8 +5390,11 @@ qemuMonitorJSONBuildCPUModelInfoToJSON(qemuMonitorCP= UModelInfoPtr model) } } =20 - ignore_value(virJSONValueObjectCreate(&model_json, "s:name", model->na= me, - "a:props", &cpu_props, NULL)); + if (model->nprops > 0) + ignore_value(virJSONValueObjectCreate(&model_json, "s:name", model= ->name, + "a:props", &cpu_props, NULL)= ); + else + ignore_value(virJSONValueObjectCreate(&model_json, "s:name", model= ->name, NULL)); =20 cleanup: virJSONValueFree(cpu_props); @@ -5440,38 +5443,52 @@ qemuMonitorJSONBuildCPUModelInfoFromJSON(virJSONVal= uePtr cpu_model) return model; } =20 + +/* return: + * -1 - Execution Failure + * 0 - Success + * 1 - Qemu unable to do expansion leaving "model" unmodified + */ int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon, qemuMonitorCPUModelExpansionType type, - const char *model_name, - bool migratable, - qemuMonitorCPUModelInfoPtr *model_info) + bool migratable_only, + qemuMonitorCPUModelInfoPtr model) { int ret =3D -1; - virJSONValuePtr model =3D NULL; - virJSONValuePtr props =3D NULL; + virJSONValuePtr json_model =3D NULL; virJSONValuePtr cmd =3D NULL; virJSONValuePtr reply =3D NULL; virJSONValuePtr data; virJSONValuePtr cpu_model; + qemuMonitorCPUModelInfoPtr expanded_model =3D NULL; + qemuMonitorCPUModelInfoPtr model_info =3D NULL; const char *typeStr =3D ""; =20 - *model_info =3D NULL; + if (!(model_info =3D qemuMonitorCPUModelInfoCopy(model))) + return -1; + + qemuMonitorCPUModelInfoFreeContents(model); =20 - if (!(model =3D virJSONValueNewObject())) - goto cleanup; + if (!migratable_only) { + /* Add property to input CPUModelInfo causing QEMU to include + * non-migratable properties for some architectures like X86 */ =20 - if (virJSONValueObjectAppendString(model, "name", model_name) < 0) - goto cleanup; + qemuMonitorCPUProperty prop; + prop.type =3D QEMU_MONITOR_CPU_PROPERTY_BOOLEAN; + prop.value.boolean =3D false; + prop.migratable =3D false; + + if (VIR_STRDUP(prop.name, "migratable") < 0) + goto cleanup; =20 - if (!migratable) { - if (!(props =3D virJSONValueNewObject()) || - virJSONValueObjectAppendBoolean(props, "migratable", false) < = 0 || - virJSONValueObjectAppend(model, "props", props) < 0) + if (VIR_APPEND_ELEMENT(model_info->props, model_info->nprops, prop= ) < 0) goto cleanup; - props =3D NULL; } =20 + if (!(json_model =3D qemuMonitorJSONBuildCPUModelInfoToJSON(model_info= ))) + goto cleanup; + retry: switch (type) { case QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC: @@ -5486,7 +5503,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mo= n, =20 if (!(cmd =3D qemuMonitorJSONMakeCommand("query-cpu-model-expansion", "s:type", typeStr, - "a:model", &model, + "a:model", &json_model, NULL))) goto cleanup; =20 @@ -5498,7 +5515,7 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mo= n, * guest architecture or it is not supported in the host environment. */ if (qemuMonitorJSONHasError(reply, "GenericError")) { - ret =3D 0; + ret =3D 1; goto cleanup; } =20 @@ -5517,7 +5534,9 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mo= n, * on the result of the initial "static" expansion. */ if (type =3D=3D QEMU_MONITOR_CPU_MODEL_EXPANSION_STATIC_FULL) { - if (!(model =3D virJSONValueCopy(cpu_model))) + virJSONValueFree(json_model); + + if (!(json_model =3D virJSONValueCopy(cpu_model))) goto cleanup; =20 virJSONValueFree(cmd); @@ -5526,16 +5545,20 @@ qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr = mon, goto retry; } =20 - if (!(*model_info =3D qemuMonitorJSONBuildCPUModelInfoFromJSON(cpu_mod= el))) + if (!(expanded_model =3D qemuMonitorJSONBuildCPUModelInfoFromJSON(cpu_= model))) goto cleanup; =20 + *model =3D *expanded_model; /* overwrite contents */ + ret =3D 0; =20 cleanup: + VIR_FREE(expanded_model); /* Free structure but not reused contents */ + qemuMonitorCPUModelInfoFreeContents(model_info); + virJSONValueFree(cmd); virJSONValueFree(reply); - virJSONValueFree(model); - virJSONValueFree(props); + virJSONValueFree(json_model); return ret; } =20 diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 73e1cb6ace..9950483c5c 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -362,10 +362,9 @@ int qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mo= n, =20 int qemuMonitorJSONGetCPUModelExpansion(qemuMonitorPtr mon, qemuMonitorCPUModelExpansionType t= ype, - const char *model_name, - bool migratable, - qemuMonitorCPUModelInfoPtr *model_= info) - ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(5); + bool migratable_only, + qemuMonitorCPUModelInfoPtr model_i= nfo) + ATTRIBUTE_NONNULL(4); =20 int qemuMonitorJSONGetCPUModelBaseline(qemuMonitorPtr mon, qemuMonitorCPUModelInfoPtr model_a, diff --git a/tests/cputest.c b/tests/cputest.c index baf2b3c648..27727aa29e 100644 --- a/tests/cputest.c +++ b/tests/cputest.c @@ -495,9 +495,14 @@ cpuTestMakeQEMUCaps(const struct data *data) if (!(testMon =3D qemuMonitorTestNewFromFile(json, driver.xmlopt, true= ))) goto error; =20 + if ((VIR_ALLOC(model) < 0) || + (qemuMonitorCPUModelInfoInit("host", model) < 0)) + goto cleanup; + + if (qemuMonitorGetCPUModelExpansion(qemuMonitorTestGetMonitor(testMon), QEMU_MONITOR_CPU_MODEL_EXPANSION_S= TATIC, - "host", true, &model) < 0) + true, model) < 0) goto error; =20 if (!(qemuCaps =3D virQEMUCapsNew())) --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 07:21:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531195045803681.4041649171039; Mon, 9 Jul 2018 20:57:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 34AE630820F4; Tue, 10 Jul 2018 03:57:24 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F0B8ABD220; Tue, 10 Jul 2018 03:57:23 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id A51AB18037FA; Tue, 10 Jul 2018 03:57:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6A3v6WI003363 for ; Mon, 9 Jul 2018 23:57:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4110C7C59; Tue, 10 Jul 2018 03:57:06 +0000 (UTC) Received: from cv1.lan (ovpn-120-63.rdu2.redhat.com [10.10.120.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id B77EA7C4D; Tue, 10 Jul 2018 03:57:05 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 22:56:50 -0500 Message-Id: <20180710035655.24983-7-cventeic@redhat.com> In-Reply-To: <20180710035655.24983-1-cventeic@redhat.com> References: <20180710035655.24983-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , david@redhat.com Subject: [libvirt] [PATCHv2 06/11] qemu_monitor: Introduce qemuMonitorCPUModelInfoRemovePropByBoolValue X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Tue, 10 Jul 2018 03:57:24 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Filter out cpu properties in qemuMonitorCPUModelInfo structure based on boolean value of true or false. Goal is to form a list of "enabled" or "disabled" properties. Required to convert between cpu model feature / property lists that indicate if property is or isn't include in model and the form of cpu model feature / property lists that only enumerate properties that are actually included in the model. --- src/qemu/qemu_monitor.c | 29 +++++++++++++++++++++++++++++ src/qemu/qemu_monitor.h | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 91b946c8b4..dd8510fbab 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3766,6 +3766,35 @@ qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUMode= lInfo *orig) return NULL; } =20 + +/* Squash CPU Model Info property list + * removing props of type boolean matching value */ +void +qemuMonitorCPUModelInfoRemovePropByBoolValue(qemuMonitorCPUModelInfoPtr mo= del, + bool value) +{ + qemuMonitorCPUPropertyPtr src, dst; + size_t i, dst_size =3D 0; + + for (i =3D 0; i < model->nprops; i++) { + src =3D &(model->props[i]); + dst =3D &(model->props[dst_size]); + + if ((src->type =3D=3D QEMU_MONITOR_CPU_PROPERTY_BOOLEAN) && + (src->value.boolean =3D=3D value)) + continue; + + *dst =3D *src; + + dst_size++; + } + + model->nprops =3D dst_size; + + ignore_value(VIR_REALLOC_N(model->props, dst_size)); /* not fatal */ +} + + int qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon, qemuMonitorCPUModelInfoPtr model_a, diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 6b4b527512..9841ab230c 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1028,6 +1028,10 @@ int qemuMonitorCPUModelInfoInit(const char *name, qe= muMonitorCPUModelInfoPtr mod qemuMonitorCPUModelInfoPtr qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig); =20 +void qemuMonitorCPUModelInfoRemovePropByBoolValue( qemuMonitorCPUModelInfo= Ptr model, + bool value) + ATTRIBUTE_NONNULL(1); + int qemuMonitorGetCPUModelBaseline(qemuMonitorPtr mon, qemuMonitorCPUModelInfoPtr model_a, qemuMonitorCPUModelInfoPtr model_b, --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 07:21:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531195044562369.66762679520014; Mon, 9 Jul 2018 20:57:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA31987624; Tue, 10 Jul 2018 03:57:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9EDE3BD211; Tue, 10 Jul 2018 03:57:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 518CE4A46D; Tue, 10 Jul 2018 03:57:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6A3v7jY003379 for ; Mon, 9 Jul 2018 23:57:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id EBD857C59; Tue, 10 Jul 2018 03:57:06 +0000 (UTC) Received: from cv1.lan (ovpn-120-63.rdu2.redhat.com [10.10.120.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6A6397C4D; Tue, 10 Jul 2018 03:57:06 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 22:56:51 -0500 Message-Id: <20180710035655.24983-8-cventeic@redhat.com> In-Reply-To: <20180710035655.24983-1-cventeic@redhat.com> References: <20180710035655.24983-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , david@redhat.com Subject: [libvirt] [PATCHv2 07/11] qemu_capabilities: Introduce virCPUDef / qemuMonitorCPUModelInfo conversions X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Tue, 10 Jul 2018 03:57:23 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Bi-directional conversion functions. Converts model / name and features / properties between the two structures. Created reusable functions to bridge the internal (virCpuDef) and QEMU/QMP specific structures for describing CPU Models. --- src/qemu/qemu_capabilities.c | 146 +++++++++++++++++++++++++++++------ src/qemu/qemu_capabilities.h | 3 + 2 files changed, 127 insertions(+), 22 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 72ab012a78..d3f2317a1d 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -2758,7 +2758,8 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps, virCPUDefPtr cpu, bool migratable) { - size_t i; + virCPUDefPtr tmp =3D NULL; + int ret =3D -1; =20 if (!modelInfo) { if (type =3D=3D VIR_DOMAIN_VIRT_KVM) { @@ -2771,32 +2772,21 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps, return 2; } =20 - if (VIR_STRDUP(cpu->model, modelInfo->name) < 0 || - VIR_ALLOC_N(cpu->features, modelInfo->nprops) < 0) - return -1; + if (!(tmp =3D virQEMUCapsCPUModelInfoToCPUDef(migratable, modelInfo))) + goto cleanup; =20 - cpu->nfeatures_max =3D modelInfo->nprops; - cpu->nfeatures =3D 0; + /* Free then copy over model, vendor, vendor_id and features */ + virCPUDefFreeModel(cpu); =20 - for (i =3D 0; i < modelInfo->nprops; i++) { - virCPUFeatureDefPtr feature =3D cpu->features + cpu->nfeatures; - qemuMonitorCPUPropertyPtr prop =3D modelInfo->props + i; - - if (prop->type !=3D QEMU_MONITOR_CPU_PROPERTY_BOOLEAN) - continue; + if (virCPUDefCopyModel(cpu, tmp, true) < 0) + goto cleanup; =20 - if (VIR_STRDUP(feature->name, prop->name) < 0) - return -1; + ret =3D 0; =20 - if (!prop->value.boolean || - (migratable && prop->migratable =3D=3D VIR_TRISTATE_BOOL_NO)) - feature->policy =3D VIR_CPU_FEATURE_DISABLE; - else - feature->policy =3D VIR_CPU_FEATURE_REQUIRE; - cpu->nfeatures++; - } + cleanup: + virCPUDefFree(tmp); =20 - return 0; + return ret; } =20 =20 @@ -3547,6 +3537,118 @@ virQEMUCapsLoadCache(virArch hostArch, return ret; } =20 +/* virCPUDef model =3D> qemuMonitorCPUModelInfo name + * virCPUDef features =3D> qemuMonitorCPUModelInfo boolean properties */ +qemuMonitorCPUModelInfoPtr +virQEMUCapsCPUModelInfoFromCPUDef(const virCPUDef *cpuDef) +{ + size_t i; + qemuMonitorCPUModelInfoPtr cpuModel =3D NULL; + qemuMonitorCPUModelInfoPtr ret =3D NULL; + + if (!cpuDef || (VIR_ALLOC(cpuModel) < 0)) + goto cleanup; + + VIR_DEBUG("cpuDef->model =3D %s", NULLSTR(cpuDef->model)); + + if (VIR_STRDUP(cpuModel->name, cpuDef->model) < 0 || + VIR_ALLOC_N(cpuModel->props, cpuDef->nfeatures) < 0) + goto cleanup; + + /* no visibility on migratability of properties / features */ + cpuModel->props_migratable_valid =3D false; + + cpuModel->nprops =3D 0; + + for (i =3D 0; i < cpuDef->nfeatures; i++) { + qemuMonitorCPUPropertyPtr prop =3D &(cpuModel->props[cpuModel->npr= ops]); + virCPUFeatureDefPtr feature =3D &(cpuDef->features[i]); + + if (!feature || !(feature->name)) + continue; + + if (VIR_STRDUP(prop->name, feature->name) < 0) + goto cleanup; + + prop->migratable =3D VIR_TRISTATE_BOOL_ABSENT; + prop->type =3D QEMU_MONITOR_CPU_PROPERTY_BOOLEAN; + + switch (feature->policy) { + case -1: /* policy undefined */ + case VIR_CPU_FEATURE_FORCE: + case VIR_CPU_FEATURE_REQUIRE: + prop->value.boolean =3D true; + break; + + case VIR_CPU_FEATURE_FORBID: + case VIR_CPU_FEATURE_DISABLE: + case VIR_CPU_FEATURE_OPTIONAL: + case VIR_CPU_FEATURE_LAST: + prop->value.boolean =3D false; + break; + } + + cpuModel->nprops +=3D 1; + } + + VIR_STEAL_PTR(ret, cpuModel); + + cleanup: + qemuMonitorCPUModelInfoFree(cpuModel); + return ret; +} + + +/* qemuMonitorCPUModelInfo name =3D> virCPUDef model + * qemuMonitorCPUModelInfo boolean properties =3D> virCPUDef features + * + * migratable_only true: mark non-migratable features as disabled + * false: allow all features as required + */ +virCPUDefPtr +virQEMUCapsCPUModelInfoToCPUDef(bool migratable_only, qemuMonitorCPUModelI= nfoPtr model) +{ + virCPUDefPtr cpu =3D NULL; + virCPUDefPtr ret =3D NULL; + size_t i; + + if (!model || (VIR_ALLOC(cpu) < 0)) + goto cleanup; + + VIR_DEBUG("model->name=3D %s", NULLSTR(model->name)); + + if (VIR_STRDUP(cpu->model, model->name) < 0 || + VIR_ALLOC_N(cpu->features, model->nprops) < 0) + goto cleanup; + + cpu->nfeatures_max =3D model->nprops; + cpu->nfeatures =3D 0; + + for (i =3D 0; i < model->nprops; i++) { + virCPUFeatureDefPtr feature =3D cpu->features + cpu->nfeatures; + qemuMonitorCPUPropertyPtr prop =3D model->props + i; + + if (prop->type !=3D QEMU_MONITOR_CPU_PROPERTY_BOOLEAN) + continue; + + if (VIR_STRDUP(feature->name, prop->name) < 0) + goto cleanup; + + if (!prop->value.boolean || + (migratable_only && prop->migratable =3D=3D VIR_TRISTATE_BOOL_= NO)) + feature->policy =3D VIR_CPU_FEATURE_DISABLE; + else + feature->policy =3D VIR_CPU_FEATURE_REQUIRE; + + cpu->nfeatures++; + } + + VIR_STEAL_PTR(ret, cpu); + + cleanup: + virCPUDefFree(cpu); + return ret; +} =20 static void virQEMUCapsFormatHostCPUModelInfo(virQEMUCapsPtr qemuCaps, diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index a048a1cf02..d5cd486295 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -564,6 +564,9 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuC= aps, void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps, const char *machineType); =20 +qemuMonitorCPUModelInfoPtr virQEMUCapsCPUModelInfoFromCPUDef(const virCPUD= ef *cpuDef); +virCPUDefPtr virQEMUCapsCPUModelInfoToCPUDef(bool migratable_only, qemuMon= itorCPUModelInfoPtr model); + virFileCachePtr virQEMUCapsCacheNew(const char *libDir, const char *cacheDir, uid_t uid, --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 07:21:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531195050294470.8311388714459; Mon, 9 Jul 2018 20:57:30 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0811C8110C; Tue, 10 Jul 2018 03:57:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B15821001947; Tue, 10 Jul 2018 03:57:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 53C414A46E; Tue, 10 Jul 2018 03:57:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6A3v7kH003387 for ; Mon, 9 Jul 2018 23:57:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9F3977C59; Tue, 10 Jul 2018 03:57:07 +0000 (UTC) Received: from cv1.lan (ovpn-120-63.rdu2.redhat.com [10.10.120.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 21C787C4D; Tue, 10 Jul 2018 03:57:07 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 22:56:52 -0500 Message-Id: <20180710035655.24983-9-cventeic@redhat.com> In-Reply-To: <20180710035655.24983-1-cventeic@redhat.com> References: <20180710035655.24983-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , david@redhat.com Subject: [libvirt] [PATCHv2 08/11] qemu_capabilities: QMPCommandPtr without maintaining shadow qmperr X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 10 Jul 2018 03:57:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Previously QMPCommandPtr (handle for issuing QMP commands) required an external char * qmperr to persist over the lifespan of QMPCommand to expose a QMP error string outside of QMPCommand. Before this change, an external char *qmperr had to be maintained between calls to virQEMUCapsInitQMPCommandNew and virQEMUCapsInitQMPCommandAbort. This change allows the qmperr pointer to be maintained within the QMPCommand structure avoiding the need to track and maintain the qmperr across a sometimes multi-function call lifespan of a QMPCommand. Q) Should we eliminate external *qmperr completely as there seems to be no current use of qmperr outside the lifespan of QMPCommand in which an internal qmperr char pointer can persist and be used by anywhere we have access to the QMPCommandPtr? --- src/qemu/qemu_capabilities.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index d3f2317a1d..f33152ec40 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4272,6 +4272,7 @@ struct _virQEMUCapsInitQMPCommand { uid_t runUid; gid_t runGid; char **qmperr; + char *qmperr_internal; char *monarg; char *monpath; char *pidfile; @@ -4349,7 +4350,11 @@ virQEMUCapsInitQMPCommandNew(char *binary, =20 cmd->runUid =3D runUid; cmd->runGid =3D runGid; - cmd->qmperr =3D qmperr; + + if (qmperr) + cmd->qmperr =3D qmperr; /* external storage */ + else + cmd->qmperr =3D &cmd->qmperr_internal; /* cmd internal storage */ =20 /* the ".sock" sufix is important to avoid a possible clash with a qemu * domain called "capabilities" --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 07:21:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531195051323778.0853406820927; Mon, 9 Jul 2018 20:57:31 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 07E0E4E33B; Tue, 10 Jul 2018 03:57:29 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBFA13001A49; Tue, 10 Jul 2018 03:57:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5A58D12D3A; Tue, 10 Jul 2018 03:57:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6A3v8DE003393 for ; Mon, 9 Jul 2018 23:57:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 505B57C59; Tue, 10 Jul 2018 03:57:08 +0000 (UTC) Received: from cv1.lan (ovpn-120-63.rdu2.redhat.com [10.10.120.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id C64BE7C4D; Tue, 10 Jul 2018 03:57:07 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 22:56:53 -0500 Message-Id: <20180710035655.24983-10-cventeic@redhat.com> In-Reply-To: <20180710035655.24983-1-cventeic@redhat.com> References: <20180710035655.24983-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , david@redhat.com Subject: [libvirt] [PATCHv2 09/11] qemu_capabilities: Persist QEMU instance over multiple QMP Cmds X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Tue, 10 Jul 2018 03:57:29 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Commit makes starting a single persistent QEMU instance possible for use over multiple independent QMP commands without starting and stopping QEMU for each QMP command or command type. Commit allows functions outside qemu_capabilities (ex. qemuConnectBaselineHypervisorCPU in qemu_driver) requiring multiple different QMP messages to be sent to QEMU to issue those requests over a single QMP Command Channel without starting and stopping QEMU for each independent QMP Command usage. Commit moves following to global scope so parent function can maintain QEMU instance over multiple QMP commands / command types: virQEMUCapsInitQMPCommand virQEMUCapsInitQMPCommandFree Commit Introduces virQEMUCapsNewQMPCommandConnection to Start and connect to QEMU so QMP commands can be performed. The new reusable function isolates code for starting QEMU and establishing Monitor connections from code for obtaining capabilities so that arbitrary QMP commands can be exchanged with QEMU. --- src/qemu/qemu_capabilities.c | 61 +++++++++++++++++++++++------------- src/qemu/qemu_capabilities.h | 26 +++++++++++++++ 2 files changed, 66 insertions(+), 21 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index f33152ec40..6f8983384a 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -4265,25 +4265,6 @@ virQEMUCapsInitQMPMonitorTCG(virQEMUCapsPtr qemuCaps= ATTRIBUTE_UNUSED, } =20 =20 -typedef struct _virQEMUCapsInitQMPCommand virQEMUCapsInitQMPCommand; -typedef virQEMUCapsInitQMPCommand *virQEMUCapsInitQMPCommandPtr; -struct _virQEMUCapsInitQMPCommand { - char *binary; - uid_t runUid; - gid_t runGid; - char **qmperr; - char *qmperr_internal; - char *monarg; - char *monpath; - char *pidfile; - virCommandPtr cmd; - qemuMonitorPtr mon; - virDomainChrSourceDef config; - pid_t pid; - virDomainObjPtr vm; -}; - - static void virQEMUCapsInitQMPCommandAbort(virQEMUCapsInitQMPCommandPtr cmd) { @@ -4318,7 +4299,7 @@ virQEMUCapsInitQMPCommandAbort(virQEMUCapsInitQMPComm= andPtr cmd) } =20 =20 -static void +void virQEMUCapsInitQMPCommandFree(virQEMUCapsInitQMPCommandPtr cmd) { if (!cmd) @@ -4334,7 +4315,7 @@ virQEMUCapsInitQMPCommandFree(virQEMUCapsInitQMPComma= ndPtr cmd) =20 =20 static virQEMUCapsInitQMPCommandPtr -virQEMUCapsInitQMPCommandNew(char *binary, +virQEMUCapsInitQMPCommandNew(const char *binary, const char *libDir, uid_t runUid, gid_t runGid, @@ -4475,6 +4456,44 @@ virQEMUCapsInitQMPCommandRun(virQEMUCapsInitQMPComma= ndPtr cmd, } =20 =20 +/* Start and connect to QEMU so QMP commands can be performed. + */ +virQEMUCapsInitQMPCommandPtr +virQEMUCapsNewQMPCommandConnection(const char *exec, + const char *libDir, uid_t runUid, gid_t runGid, + bool forceTCG) +{ + virQEMUCapsInitQMPCommandPtr cmd =3D NULL; + virQEMUCapsInitQMPCommandPtr rtn_cmd =3D NULL; + + VIR_DEBUG("exec =3D%s", NULLSTR(exec)); + + /* Allocate and initialize QMPCommand structure */ + if (!(cmd =3D virQEMUCapsInitQMPCommandNew(exec, libDir, + runUid, runGid, NULL))) + goto cleanup; + + /* Spawn QEMU and establish connection for QMP commands */ + if (virQEMUCapsInitQMPCommandRun(cmd, forceTCG) !=3D 0) + goto cleanup; + + /* Exit capabilities negotiation mode and enter QEMU command mode + * by issuing qmp_capabilities command to QEMU */ + if (qemuMonitorSetCapabilities(cmd->mon) < 0) { + VIR_DEBUG("Failed to set monitor capabilities %s", + virGetLastErrorMessage()); + goto cleanup; + } + + VIR_STEAL_PTR(rtn_cmd, cmd); + + cleanup: + virQEMUCapsInitQMPCommandFree(cmd); + + return rtn_cmd; +} + + static int virQEMUCapsInitQMP(virQEMUCapsPtr qemuCaps, const char *libDir, diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index d5cd486295..7be636d739 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -490,6 +490,32 @@ typedef enum { /* virQEMUCapsFlags grouping marker for= syntax-check */ QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; =20 +typedef struct _virQEMUCapsInitQMPCommand virQEMUCapsInitQMPCommand; +typedef virQEMUCapsInitQMPCommand *virQEMUCapsInitQMPCommandPtr; + +struct _virQEMUCapsInitQMPCommand { + char *binary; + uid_t runUid; + gid_t runGid; + char **qmperr; + char *qmperr_internal; + char *monarg; + char *monpath; + char *pidfile; + virCommandPtr cmd; + qemuMonitorPtr mon; + virDomainChrSourceDef config; + pid_t pid; + virDomainObjPtr vm; +}; + +virQEMUCapsInitQMPCommandPtr +virQEMUCapsNewQMPCommandConnection(const char *exec, + const char *libDir, uid_t runUid, gid_t= runGid, + bool forceTCG); + +void virQEMUCapsInitQMPCommandFree(virQEMUCapsInitQMPCommandPtr cmd); + typedef struct _virQEMUCaps virQEMUCaps; typedef virQEMUCaps *virQEMUCapsPtr; =20 --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 07:21:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531195054823493.859252883346; Mon, 9 Jul 2018 20:57:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 692D8307CF25; Tue, 10 Jul 2018 03:57:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1128560175; Tue, 10 Jul 2018 03:57:32 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 846E83FA54; Tue, 10 Jul 2018 03:57:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6A3v9Gj003405 for ; Mon, 9 Jul 2018 23:57:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 01EF37C59; Tue, 10 Jul 2018 03:57:09 +0000 (UTC) Received: from cv1.lan (ovpn-120-63.rdu2.redhat.com [10.10.120.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 782D37C4D; Tue, 10 Jul 2018 03:57:08 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 22:56:54 -0500 Message-Id: <20180710035655.24983-11-cventeic@redhat.com> In-Reply-To: <20180710035655.24983-1-cventeic@redhat.com> References: <20180710035655.24983-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , david@redhat.com Subject: [libvirt] [PATCHv2 10/11] qemu_capabilities: Introduce virQEMUCapsQMPBaselineCPUModel (baseline using QEMU) X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 10 Jul 2018 03:57:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Baseline cpu model using QEMU/QMP query-cpu-model-baseline query-cpu-model-baseline only compares two CPUModels so multiple exchanges are needed to evaluate more than two CPUModels. --- src/qemu/qemu_capabilities.c | 85 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_capabilities.h | 4 ++ 2 files changed, 89 insertions(+) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 6f8983384a..e0bf78fbba 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -5424,3 +5424,88 @@ virQEMUCapsStripMachineAliases(virQEMUCapsPtr qemuCa= ps) for (i =3D 0; i < qemuCaps->nmachineTypes; i++) VIR_FREE(qemuCaps->machineTypes[i].alias); } + + +/* in: + * cpus[0]->model =3D "z13-base"; + * cpus[0]->features[0].name =3D "xxx"; + * cpus[0]->features[1].name =3D "yyy"; + * *** + * cpus[n]->model =3D "s390x"; + * cpus[n]->features[0].name =3D "xxx"; + * cpus[n]->features[1].name =3D "yyy"; + * + * out: + * *baseline->model =3D "s390x"; + * *baseline->features[0].name =3D "yyy"; + * + * (ret=3D=3D0) && (*baseline=3D=3DNULL) if a QEMU rejects model name or b= aseline command + */ +int +virQEMUCapsQMPBaselineCPUModel(virQEMUCapsInitQMPCommandPtr cmd, + virCPUDefPtr *cpus, + virCPUDefPtr *baseline) +{ + qemuMonitorCPUModelInfoPtr model_baseline =3D NULL; + qemuMonitorCPUModelInfoPtr new_model_baseline =3D NULL; + qemuMonitorCPUModelInfoPtr next_model =3D NULL; + bool migratable_only =3D true; + int ret =3D -1; + size_t i; + + *baseline =3D NULL; + + if (!cpus || !cpus[0] || !cpus[1]) { + virReportError(VIR_ERR_INVALID_ARG, "%s", _("less than 2 cpus")); + goto cleanup; + } + + for (i =3D 0; !cpus[i]; i++) { /* last element in cpus =3D=3D NUL= L */ + virCPUDefPtr cpu =3D cpus[i]; + + VIR_DEBUG("cpu[%lu]->model =3D %s", i, NULLSTR(cpu->model)); + + if (!(next_model =3D virQEMUCapsCPUModelInfoFromCPUDef(cpu))) { + virReportError(VIR_ERR_INVALID_ARG, "%s", _("cpu without conte= nt")); + goto cleanup; + } + + if (i =3D=3D 0) { + model_baseline =3D next_model; + continue; + } + + if (qemuMonitorGetCPUModelBaseline(cmd->mon, model_baseline, + next_model, &new_model_baseline= ) < 0) + goto cleanup; + + if (!new_model_baseline) { + virReportError(VIR_ERR_INVALID_ARG, + _("QEMU doesn't support baseline or recognize m= odel %s or %s"), + model_baseline->name, + next_model->name); + ret =3D 0; + goto cleanup; + } + + qemuMonitorCPUModelInfoFree(model_baseline); + qemuMonitorCPUModelInfoFree(next_model); + + next_model =3D NULL; + + model_baseline =3D new_model_baseline; + } + + if (!(*baseline =3D virQEMUCapsCPUModelInfoToCPUDef(migratable_only, m= odel_baseline))) + goto cleanup; + + VIR_DEBUG("baseline->model =3D %s", NULLSTR((*baseline)->model)); + + ret =3D 0; + + cleanup: + qemuMonitorCPUModelInfoFree(model_baseline); + qemuMonitorCPUModelInfoFree(next_model); + + return ret; +} diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 7be636d739..d49c8b32ec 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -593,6 +593,10 @@ void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qem= uCaps, qemuMonitorCPUModelInfoPtr virQEMUCapsCPUModelInfoFromCPUDef(const virCPUD= ef *cpuDef); virCPUDefPtr virQEMUCapsCPUModelInfoToCPUDef(bool migratable_only, qemuMon= itorCPUModelInfoPtr model); =20 +int virQEMUCapsQMPBaselineCPUModel(virQEMUCapsInitQMPCommandPtr cmd, + virCPUDefPtr *cpus, + virCPUDefPtr *baseline); + virFileCachePtr virQEMUCapsCacheNew(const char *libDir, const char *cacheDir, uid_t uid, --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Thu Apr 25 07:21:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1531195048438976.7692275572656; Mon, 9 Jul 2018 20:57:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2720D80F7B; Tue, 10 Jul 2018 03:57:27 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DD20A60BE4; Tue, 10 Jul 2018 03:57:26 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 7A1F218037FC; Tue, 10 Jul 2018 03:57:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6A3v9WO003415 for ; Mon, 9 Jul 2018 23:57:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id A6D647C59; Tue, 10 Jul 2018 03:57:09 +0000 (UTC) Received: from cv1.lan (ovpn-120-63.rdu2.redhat.com [10.10.120.63]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29ED27C4D; Tue, 10 Jul 2018 03:57:09 +0000 (UTC) From: Chris Venteicher To: libvir-list@redhat.com Date: Mon, 9 Jul 2018 22:56:55 -0500 Message-Id: <20180710035655.24983-12-cventeic@redhat.com> In-Reply-To: <20180710035655.24983-1-cventeic@redhat.com> References: <20180710035655.24983-1-cventeic@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-loop: libvir-list@redhat.com Cc: walling@linux.ibm.com, Chris Venteicher , david@redhat.com Subject: [libvirt] [PATCHv2 11/11] qemu_driver: BaselineHypervisorCPU supports S390 using QEMU/QMP X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Tue, 10 Jul 2018 03:57:27 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Transient S390 configurations require using QEMU to compute CPU Model Baseline and to do CPU Feature Expansion. Start and use a single QEMU instance to do both the baseline and expansion transactions required by BaselineHypervisorCPU. CPU Feature Expansion uses true / false to indicate if property is/isn't included in model. Baseline only returns property list where all enumerated properties are included. --- src/qemu/qemu_driver.c | 74 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 9a35e04a85..6c6107f077 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -13400,10 +13400,13 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr co= nn, virArch arch; virDomainVirtType virttype; virDomainCapsCPUModelsPtr cpuModels; - bool migratable; + bool migratable_only; virCPUDefPtr cpu =3D NULL; char *cpustr =3D NULL; char **features =3D NULL; + virQEMUCapsInitQMPCommandPtr cmd =3D NULL; + bool forceTCG =3D false; + qemuMonitorCPUModelInfoPtr modelInfo =3D NULL; =20 virCheckFlags(VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES | VIR_CONNECT_BASELINE_CPU_MIGRATABLE, NULL); @@ -13411,8 +13414,6 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn, if (virConnectBaselineHypervisorCPUEnsureACL(conn) < 0) goto cleanup; =20 - migratable =3D !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE); - if (!(cpus =3D virCPUDefListParse(xmlCPUs, ncpus, VIR_CPU_TYPE_AUTO))) goto cleanup; =20 @@ -13425,6 +13426,19 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr con= n, if (!qemuCaps) goto cleanup; =20 + /* QEMU can enumerate non-migratable cpu model features for some archs= like x86 + * migratable_only =3D=3D true: ask for and include only migratable f= eatures + * migratable_only =3D=3D false: ask for and include all features + */ + migratable_only =3D !!(flags & VIR_CONNECT_BASELINE_CPU_MIGRATABLE); + + if (ARCH_IS_S390(arch)) { + /* QEMU for S390 arch only enumerates migratable features + * No reason to explicitly ask QEMU for or include non-migratable f= eatures + */ + migratable_only =3D true; + } + if (!(cpuModels =3D virQEMUCapsGetCPUDefinitions(qemuCaps, virttype)) = || cpuModels->nmodels =3D=3D 0) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, @@ -13437,18 +13451,31 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr co= nn, =20 if (ARCH_IS_X86(arch)) { int rc =3D virQEMUCapsGetCPUFeatures(qemuCaps, virttype, - migratable, &features); + migratable_only, &features); if (rc < 0) goto cleanup; if (features && rc =3D=3D 0) { /* We got only migratable features from QEMU if we asked for t= hem, * no further filtering in virCPUBaseline is desired. */ - migratable =3D false; + migratable_only =3D false; } =20 if (!(cpu =3D virCPUBaseline(arch, cpus, ncpus, cpuModels, - (const char **)features, migratable))) + (const char **)features, migratable_onl= y))) goto cleanup; + } else if (ARCH_IS_S390(arch)) { + + const char *binary =3D virQEMUCapsGetBinary(qemuCaps); + virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + + if (!(cmd =3D virQEMUCapsNewQMPCommandConnection(binary, cfg->libDi= r, + cfg->user, cfg->grou= p, + forceTCG))) + goto cleanup; + + if ((virQEMUCapsQMPBaselineCPUModel(cmd, cpus, &cpu) < 0) || !cpu) + goto cleanup; /* Content Error */ + } else { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, _("computing baseline hypervisor CPU is not support= ed " @@ -13458,9 +13485,36 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr con= n, =20 cpu->fallback =3D VIR_CPU_FALLBACK_FORBID; =20 - if ((flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) && - virCPUExpandFeatures(arch, cpu) < 0) - goto cleanup; + if (flags & VIR_CONNECT_BASELINE_CPU_EXPAND_FEATURES) { + if (ARCH_IS_X86(arch)) { + if (virCPUExpandFeatures(arch, cpu) < 0) + goto cleanup; + } else if (ARCH_IS_S390(arch)) { + + if (!(modelInfo =3D virQEMUCapsCPUModelInfoFromCPUDef(cpu))) + goto cleanup; + + virCPUDefFree(cpu); /* Null on failure, repopulated on success */ + + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_QUERY_CPU_MODEL_EXPANSIO= N)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Feature Expansion not supported with this Q= EMU binary")); + goto cleanup; + } + + if (qemuMonitorGetCPUModelExpansion(cmd->mon, + QEMU_MONITOR_CPU_MODEL_EXPAN= SION_FULL, + migratable_only, modelInfo) = < 0) + goto cleanup; + + /* Expansion enumerates all features + * Baseline reply enumerates only in-model (true) features */ + qemuMonitorCPUModelInfoRemovePropByBoolValue(modelInfo, false); + + if (!(cpu =3D virQEMUCapsCPUModelInfoToCPUDef(migratable_only, m= odelInfo))) + goto cleanup; + } + } =20 cpustr =3D virCPUDefFormat(cpu, NULL); =20 @@ -13469,6 +13523,8 @@ qemuConnectBaselineHypervisorCPU(virConnectPtr conn, virCPUDefFree(cpu); virObjectUnref(qemuCaps); virStringListFree(features); + virQEMUCapsInitQMPCommandFree(cmd); + qemuMonitorCPUModelInfoFree(modelInfo); =20 return cpustr; } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list