From nobody Sun Feb 8 22:07:56 2026 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 1530776696988569.0703378166434; Thu, 5 Jul 2018 00:44:56 -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 9FB47C04AC49; Thu, 5 Jul 2018 07:44:55 +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 6762560177; Thu, 5 Jul 2018 07:44:55 +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 16AA918037F1; Thu, 5 Jul 2018 07:44:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w657ilE3007093 for ; Thu, 5 Jul 2018 03:44:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7C77D111DD03; Thu, 5 Jul 2018 07:44:47 +0000 (UTC) Received: from localhost.localdomain (ovpn-204-55.brq.redhat.com [10.40.204.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8A328111DD02 for ; Thu, 5 Jul 2018 07:44:46 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Thu, 5 Jul 2018 09:44:37 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 5/6] qemu_monitor: Introduce qemuMonitorJSONGetPRManagerInfo 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.31]); Thu, 05 Jul 2018 07:44:56 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This function fetches status of all pr-managers. So far, qemu reports only a single attribute "connected" but that fits our needs. Signed-off-by: Michal Privoznik --- src/qemu/qemu_monitor.c | 25 +++++++++++++ src/qemu/qemu_monitor.h | 9 +++++ src/qemu/qemu_monitor_json.c | 83 ++++++++++++++++++++++++++++++++++++++++= ++++ src/qemu/qemu_monitor_json.h | 4 +++ 4 files changed, 121 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index ca95f6f94a..3514e9f8a1 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -4335,3 +4335,28 @@ qemuMonitorGetSEVMeasurement(qemuMonitorPtr mon) =20 return qemuMonitorJSONGetSEVMeasurement(mon); } + + +int +qemuMonitorGetPRManagerInfo(qemuMonitorPtr mon, + virHashTablePtr *retinfo) +{ + int ret =3D -1; + virHashTablePtr info =3D NULL; + + *retinfo =3D NULL; + + QEMU_CHECK_MONITOR(mon); + + if (!(info =3D virHashCreate(10, virHashValueFree))) + goto cleanup; + + if (qemuMonitorJSONGetPRManagerInfo(mon, info) < 0) + goto cleanup; + + VIR_STEAL_PTR(*retinfo, info); + ret =3D 0; + cleanup: + virHashFree(info); + return ret; +} diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index f1ea0bc541..e588d73678 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1156,4 +1156,13 @@ int qemuMonitorBlockdevDel(qemuMonitorPtr mon, char * qemuMonitorGetSEVMeasurement(qemuMonitorPtr mon); =20 +typedef struct _qemuMonitorPRManagerInfo qemuMonitorPRManagerInfo; +typedef qemuMonitorPRManagerInfo *qemuMonitorPRManagerInfoPtr; +struct _qemuMonitorPRManagerInfo { + bool connected; +}; + +int qemuMonitorGetPRManagerInfo(qemuMonitorPtr mon, + virHashTablePtr *retinfo); + #endif /* QEMU_MONITOR_H */ diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 03c94cd88b..291a505d5d 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -8065,3 +8065,86 @@ qemuMonitorJSONGetSEVMeasurement(qemuMonitorPtr mon) virJSONValueFree(reply); return measurement; } + + +/* + * Example return data + * + * "return": [ + * { "connected": true, "id": "pr-helper0" } + * ]} + * + */ +static int +qemuMonitorJSONExtractPRManagerInfo(virJSONValuePtr reply, + virHashTablePtr info) +{ + qemuMonitorPRManagerInfoPtr entry =3D NULL; + virJSONValuePtr data; + int ret =3D -1; + size_t i; + + data =3D virJSONValueObjectGetArray(reply, "return"); + + for (i =3D 0; i < virJSONValueArraySize(data); i++) { + virJSONValuePtr prManager =3D virJSONValueArrayGet(data, i); + const char *alias; + + if (!prManager) + goto malformed; + + if (!(alias =3D virJSONValueObjectGetString(prManager, "id"))) + goto malformed; + + if (VIR_ALLOC(entry) < 0) + goto cleanup; + + if (virJSONValueObjectGetBoolean(prManager, + "connected", + &entry->connected) < 0) { + goto malformed; + } + + if (virHashAddEntry(info, alias, entry) < 0) + goto cleanup; + + entry =3D NULL; + } + + ret =3D 0; + cleanup: + VIR_FREE(entry); + return ret; + + malformed: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("malformed prManager reply")); + goto cleanup; +} + + +int +qemuMonitorJSONGetPRManagerInfo(qemuMonitorPtr mon, + virHashTablePtr info) +{ + int ret =3D -1; + virJSONValuePtr cmd; + virJSONValuePtr reply =3D NULL; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("query-pr-managers", + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) + goto cleanup; + + ret =3D qemuMonitorJSONExtractPRManagerInfo(reply, info); + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; + +} diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 6bc0dd3ad2..66536ceb97 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -550,4 +550,8 @@ int qemuMonitorJSONBlockdevDel(qemuMonitorPtr mon, const char *nodename) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); =20 +int qemuMonitorJSONGetPRManagerInfo(qemuMonitorPtr mon, + virHashTablePtr info) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); + #endif /* QEMU_MONITOR_JSON_H */ --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list