From nobody Wed May 14 19:02:52 2025 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1519983031467269.4484519790217; Fri, 2 Mar 2018 01:30:31 -0800 (PST) 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 CB9D32D6A03; Fri, 2 Mar 2018 09:30: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 4050760C80; Fri, 2 Mar 2018 09:30:29 +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 E5EC64A471; Fri, 2 Mar 2018 09:30:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w229TMlH017635 for ; Fri, 2 Mar 2018 04:29:22 -0500 Received: by smtp.corp.redhat.com (Postfix) id ABC845D6B2; Fri, 2 Mar 2018 09:29:22 +0000 (UTC) Received: from mx1.redhat.com (ext-mx08.extmail.prod.ext.phx2.redhat.com [10.5.110.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A5C825D6A8 for ; Fri, 2 Mar 2018 09:29:22 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8C1ADC0587E8 for ; Fri, 2 Mar 2018 09:29:21 +0000 (UTC) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w229F1us069673 for ; Fri, 2 Mar 2018 04:29:21 -0500 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gf1vq4q94-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 02 Mar 2018 04:29:20 -0500 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 2 Mar 2018 09:29:19 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 2 Mar 2018 09:29:16 -0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w229TGVi28311764 for ; Fri, 2 Mar 2018 09:29:16 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3ECD542042 for ; Fri, 2 Mar 2018 09:21:44 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1E9AE42041 for ; Fri, 2 Mar 2018 09:21:44 +0000 (GMT) Received: from bradbury.ibm.com (unknown [9.152.222.40]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Fri, 2 Mar 2018 09:21:44 +0000 (GMT) From: Viktor Mihajlovski To: libvir-list@redhat.com Date: Fri, 2 Mar 2018 10:29:09 +0100 In-Reply-To: <1519982951-15767-1-git-send-email-mihajlov@linux.vnet.ibm.com> References: <1519982951-15767-1-git-send-email-mihajlov@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18030209-0012-0000-0000-000005B7D690 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18030209-0013-0000-0000-00001933DEB4 Message-Id: <1519982951-15767-5-git-send-email-mihajlov@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-02_05:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803020109 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 02 Mar 2018 09:29:21 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 02 Mar 2018 09:29:21 +0000 (UTC) for IP:'148.163.158.5' DOMAIN:'mx0b-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'mihajlov@de.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.721 (RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 148.163.158.5 mx0b-001b2d01.pphosted.com 148.163.158.5 mx0b-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.32 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/6] qemu: add architecture-specific CPU info handling 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.29]); Fri, 02 Mar 2018 09:30:30 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Extract architecture specific data from query-cpus[-fast] if available. A new function qemuMonitorJSONExtractCPUArchInfo() uses a call-back table to find and call architecture-specific extraction handlers. Initially, there's a handler for s390 cpu info to set the halted property depending on the s390 cpu state returned by QEMU. With this it's still possible to report the halted condition even when using query-cpus-fast. Signed-off-by: Viktor Mihajlovski Reviewed-by: Boris Fiuczynski --- src/qemu/qemu_monitor.c | 6 ++- src/qemu/qemu_monitor_json.c | 123 +++++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 126 insertions(+), 3 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index dad1383..5a0e8a7 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2083,12 +2083,16 @@ qemuMonitorGetCpuHalted(qemuMonitorPtr mon, size_t i; int rc; virBitmapPtr ret =3D NULL; + bool fast; =20 QEMU_CHECK_MONITOR_NULL(mon); =20 + fast =3D virQEMUCapsGet(QEMU_DOMAIN_PRIVATE(mon->vm)->qemuCaps, + QEMU_CAPS_QUERY_CPUS_FAST); + if (mon->json) rc =3D qemuMonitorJSONQueryCPUs(mon, &cpuentries, &ncpuentries, fa= lse, - false); + fast); else rc =3D qemuMonitorTextQueryCPUs(mon, &cpuentries, &ncpuentries); =20 diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 2ecdf0a..a408cfd 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1451,15 +1451,128 @@ int qemuMonitorJSONSystemReset(qemuMonitorPtr mon) } =20 =20 -/* +typedef struct { + const char *state; + bool halted; +} s390CpuStateMap; + +/** + * qemuMonitorJSONExtractCPUS390Info: + * @jsoncpu: pointer to a single JSON cpu entry + * @cpu: pointer to a single cpu entry + * + * Derive the legacy cpu info 'halted' information + * from the more accurate s390 cpu state. @cpu is + * modified only on success. + * + * Note: the 'uninitialized' s390 cpu state can't be + * mapped to halted yes/no. + * + * A s390 cpu entry could look like this + * { "arch": "s390", + * "cpu-index": 0, + * "qom-path": "/machine/unattached/device[0]", + * "thread_id": 3081, + * "cpu-state": "operating" } + * + * Returns 0 on success, and -2 if no cpu-state field was + * found or the state value is unknown. + */ +static int +qemuMonitorJSONExtractCPUS390Info(virJSONValuePtr jsoncpu, + struct qemuMonitorQueryCpusEntry *cpu) +{ + const char *cpu_state; + s390CpuStateMap states[] =3D { + { "operating", false}, + { "load", false}, + { "stopped", true}, + { "check-stop", true}, + }; + size_t i; + + if ((cpu_state =3D virJSONValueObjectGetString(jsoncpu, "cpu-state")))= { + for (i =3D 0; i < ARRAY_CARDINALITY(states); i++) { + if (STREQ(states[i].state, cpu_state)) { + cpu->halted =3D states[i].halted; + return 0; + } + } + } + + return -2; +} + +typedef struct { + const char *arch; + int (*extract)(virJSONValuePtr jsoncpu, + struct qemuMonitorQueryCpusEntry *cpu); +} qemuCpuArchInfoHandler; + + +/** + * qemuMonitorJSONExtractCPUArchInfo: + * @arch: virtual CPU's architecture + * @jsoncpu: pointer to a single JSON cpu entry + * @cpu: pointer to a single cpu entry + * + * Extracts architecure specific virtual CPU data for a single + * CPU from the QAPI response using an architecture specific + * callback. * + * To add a support for a new architecture, extend the array + * 'handlers' with a line like + * ... + * { "newarch", qemuMonitorJSONExtractCPUNewarch }, + * ... + * and implement the extraction callback. + * Check the QEMU QAPI schema for valid architecture names. + * + * Returns the called handler's return value or 0, if no handler + * was called. + */ +static int +qemuMonitorJSONExtractCPUArchInfo(const char *arch, virJSONValuePtr jsoncp= u, + struct qemuMonitorQueryCpusEntry *cpu) +{ + qemuCpuArchInfoHandler handlers[] =3D { + { "s390", qemuMonitorJSONExtractCPUS390Info }, + }; + size_t i; + + for (i =3D 0; i < ARRAY_CARDINALITY(handlers); i++) { + if (STREQ(handlers[i].arch, arch)) + return handlers[i].extract(jsoncpu, cpu); + } + + return 0; +} + +/** + * qemuMonitorJSONExtractCPUArchInfo: + * @data: JSON response data + * @entries: filled with detected cpu entries on success + * @nentries: number of entries returned + * @fast: true if this is a response from query-cpus-fast + * + * The JSON response @data will have the following format + * in case @fast =3D=3D false * [{ "arch": "x86", * "current": true, * "CPU": 0, * "qom_path": "/machine/unattached/device[0]", * "pc": -2130415978, * "halted": true, - * "thread_id": 2631237}, + * "thread_id": 2631237, + * ...}, + * {...} + * ] + * and for @fast =3D=3D true + * [{ "arch": "x86", + * "cpu-index": 0, + * "qom-path": "/machine/unattached/device[0]", + * "thread_id": 2631237, + * ...}, * {...} * ] */ @@ -1486,6 +1599,7 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data, int thread =3D 0; bool halted =3D false; const char *qom_path; + const char *arch; if (!entry) { ret =3D -2; goto cleanup; @@ -1505,6 +1619,11 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data, cpus[i].halted =3D halted; if (VIR_STRDUP(cpus[i].qom_path, qom_path) < 0) goto cleanup; + + /* process optional architecture-specific data */ + if ((arch =3D virJSONValueObjectGetString(entry, "arch"))) + ignore_value(qemuMonitorJSONExtractCPUArchInfo(arch, entry, + cpus + i)); } =20 VIR_STEAL_PTR(*entries, cpus); --=20 1.9.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list