From nobody Thu May 16 06:22:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606757514; cv=none; d=zohomail.com; s=zohoarc; b=RyfZ1xraoWUGG+v1y2C9px0aRBG2+ua0893jxqh1P1MGErL7fxXDDRfC+5TnNV0ueeN10MN/VpqIfMVHSKQah+nMLSJ+MyiF49S7Qar2cd2TX92jU0rY2a8hcRNj3GbXoPim4kKpixJPfmcOIGIlZaeRhJzcKOcdWlFc6XLubuA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606757514; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FwyRmMiBEgtSQgNfQFM+23pWqY0exgzMPJSFNurBxjo=; b=gBDPjrItG5fkdsxwk3cuITBxvqojW9HcJCkzlqoqgzqf03eGQTQ2YGbDSiog/HqzXis+1bzj0QQJ706N6MKTIYmxym771apfWEl+bUcoVCGFZC9J3W26elJRfRxb59DpKXRnZF4Cv/vkJFQk3wJsoVFpCN2DXnuos2SjY2uRu0M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606757514400474.8845146800097; Mon, 30 Nov 2020 09:31:54 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-386-KUuqfd8aN7aItStuTNsQPw-1; Mon, 30 Nov 2020 12:26:51 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E2CCF100A651; Mon, 30 Nov 2020 17:26:21 +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 C085560875; Mon, 30 Nov 2020 17:26:21 +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 8DEDE4E58F; Mon, 30 Nov 2020 17:26:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AUHQ63I003706 for ; Mon, 30 Nov 2020 12:26:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8398D189A4; Mon, 30 Nov 2020 17:26:06 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id E34149CA0 for ; Mon, 30 Nov 2020 17:26:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606757213; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FwyRmMiBEgtSQgNfQFM+23pWqY0exgzMPJSFNurBxjo=; b=NjwZobMDxsfQpSdjy7op2wN8V1IWrrmIFvkWOBjv887nFCaV3Rzqj0mXQe0prxweAtKTn4 i/Zad0UB7wcaJrvvfV//O20D7nBOygV2oDLqbmXJaYotWYiJMxmrL5zBNiYFOwvpqsAZO6 CiWSXzcvuJwaHhHEE0tB4vu8BVxZfbw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606757513; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FwyRmMiBEgtSQgNfQFM+23pWqY0exgzMPJSFNurBxjo=; b=B58+5bw0DpftHvhf2FXSb5J+ZyxpqIky0Z8ZsWa9xWYDeHsbNVnlEBEwoNIOrcf57YC8We KgXQeP0Z1Bvkjg8Mt2tOwLzveIBMz1R6sgxCEHVEMwu/pcbpZAZIEXkCXS6LcPdZvoIChF 9bgtSMLQ8AVdCEM5mKCmSrX7fZa2YFI= X-MC-Unique: KUuqfd8aN7aItStuTNsQPw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/3] qemu: monitor: Implement new handlers for 'query-command-line-options' Date: Mon, 30 Nov 2020 18:25:57 +0100 Message-Id: <827cb27ddfbd21d9ddb12548da591cf49173fe70.1606757081.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Add a new set hander for getting the data for 'query-command-line-options' which returns everything at once and lets the caller extract the data. This way we don't need to cache the output of the monitor command for repeated calls. Note that we will have enough testing of this code path via qemucapabilitiestest. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_monitor.c | 9 +++++++ src/qemu/qemu_monitor.h | 1 + src/qemu/qemu_monitor_json.c | 48 ++++++++++++++++++++++++++++++++++++ src/qemu/qemu_monitor_json.h | 1 + 4 files changed, 59 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index f2ed165b22..a60d04f78a 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3873,6 +3873,15 @@ qemuMonitorGetCommandLineOptionParameters(qemuMonito= rPtr mon, } +GHashTable * +qemuMonitorGetCommandLineOptions(qemuMonitorPtr mon) +{ + QEMU_CHECK_MONITOR_NULL(mon); + + return qemuMonitorJSONGetCommandLineOptions(mon); +} + + int qemuMonitorGetKVMState(qemuMonitorPtr mon, bool *enabled, diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index d301568e40..6b2e435f70 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1288,6 +1288,7 @@ int qemuMonitorGetCommandLineOptionParameters(qemuMon= itorPtr mon, const char *option, char ***params, bool *found); +GHashTable *qemuMonitorGetCommandLineOptions(qemuMonitorPtr mon); int qemuMonitorGetKVMState(qemuMonitorPtr mon, bool *enabled, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 723bdb4426..44d0152812 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6402,6 +6402,54 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon, } +static int +qemuMonitorJSONGetCommandLineOptionsWorker(size_t pos G_GNUC_UNUSED, + virJSONValuePtr item, + void *opaque) +{ + const char *name =3D virJSONValueObjectGetString(item, "option"); + g_autoptr(virJSONValue) parameters =3D NULL; + GHashTable *options =3D opaque; + + if (!name || + virJSONValueObjectRemoveKey(item, "parameters", ¶meters) <=3D = 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("reply data was missing 'option' name or paramete= rs")); + return -1; + } + + g_hash_table_insert(options, g_strdup(name), parameters); + parameters =3D NULL; + + return 0; +} + + +GHashTable * +qemuMonitorJSONGetCommandLineOptions(qemuMonitorPtr mon) +{ + g_autoptr(GHashTable) ret =3D virHashNew(virJSONValueHashFree); + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("query-command-line-options",= NULL))) + return NULL; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + return NULL; + + if (qemuMonitorJSONCheckReply(cmd, reply, VIR_JSON_TYPE_ARRAY) < 0) + return NULL; + + if (virJSONValueArrayForeachSteal(virJSONValueObjectGetArray(reply, "r= eturn"), + qemuMonitorJSONGetCommandLineOptions= Worker, + ret) < 0) + return NULL; + + return g_steal_pointer(&ret); +} + + int qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon, const char *option, diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index b588722d90..53445b97bb 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -430,6 +430,7 @@ int qemuMonitorJSONGetCommandLineOptionParameters(qemuM= onitorPtr mon, char ***params, bool *found) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); +GHashTable *qemuMonitorJSONGetCommandLineOptions(qemuMonitorPtr mon); int qemuMonitorJSONGetKVMState(qemuMonitorPtr mon, bool *enabled, --=20 2.28.0 From nobody Thu May 16 06:22:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606757456; cv=none; d=zohomail.com; s=zohoarc; b=c3gt5t1PrcnPwp/1i636/ipGMUO2Lm3epm5eXOUvGH4DJCKdquWi3o77ltUT7Q2Bu+Ce19kRiDwBCj78KEXnCyy6V0a+zwvRefiFnv7Nc4wzhkSjZ+zicJsAGFRK/9wPdLF9jdsKK77ygeZ5b+NRbyBZSaN2Cunrl+jzA2tbCUU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606757456; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=FbfzlnchAou74vI1UhW7f4iZKyGh9FcO9G75nS7HjbQ=; b=Sg87GuCdouyimqRGKHG8DtqobESqhZmz9uqpvhSiLYFMhT9elbh8MwCEskEAJwIKUM+tRUIB5QwM4VSx/TZUjikT9I3RXhbfCHWWmW7ozMHxhpdPS+T1kVXuMuVBuFVA2rl+2QohZcJOLVRuvszMbKhW7p1sj4xEjruJfsYqZDc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1606757456054500.0437509761682; Mon, 30 Nov 2020 09:30:56 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-236-Ub7IRAX1MmWGeab4jB1AhA-1; Mon, 30 Nov 2020 12:26:41 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 956CE1005D52; Mon, 30 Nov 2020 17:26: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 6F3CE5D705; Mon, 30 Nov 2020 17:26:24 +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 360901809CA1; Mon, 30 Nov 2020 17:26:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AUHQ7J3003714 for ; Mon, 30 Nov 2020 12:26:07 -0500 Received: by smtp.corp.redhat.com (Postfix) id B7183189A4; Mon, 30 Nov 2020 17:26:07 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id EA9AB9CA0 for ; Mon, 30 Nov 2020 17:26:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606757205; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=FbfzlnchAou74vI1UhW7f4iZKyGh9FcO9G75nS7HjbQ=; b=WrOwatYn5J2xxVQp1KzENXxnHTBkWn3ijv3djsioLSUOYNnXlKotByPEt6A1G1Pklu6VY+ qzMzmv8D+9vSnXhbYAc4qziNYYgdH2heF+4cvT6tFomoLcWZiJYJk1Rs87jcexJ5AslLFW WD0z2kWVogpMLaln1QQ3QESuMhngazc= X-MC-Unique: Ub7IRAX1MmWGeab4jB1AhA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/3] virQEMUCapsProbeQMPCommandLine: Rewrite using qemuMonitorGetCommandLineOptions Date: Mon, 30 Nov 2020 18:25:58 +0100 Message-Id: <59259331e7d1b406a0ce3df76d04dda2424f064b.1606757081.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Use the new handler to fetch the required data and do the extraction locally without conversion to string list. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_capabilities.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 538551e772..584bd21be3 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3226,28 +3226,32 @@ static int virQEMUCapsProbeQMPCommandLine(virQEMUCapsPtr qemuCaps, qemuMonitorPtr mon) { - bool found =3D false; - int nvalues; - char **values; - size_t i, j; + g_autoptr(GHashTable) options =3D NULL; + size_t i; + + if (!(options =3D qemuMonitorGetCommandLineOptions(mon))) + return -1; for (i =3D 0; i < G_N_ELEMENTS(virQEMUCapsCommandLine); i++) { - if ((nvalues =3D qemuMonitorGetCommandLineOptionParameters(mon, - virQEMUCa= psCommandLine[i].option, - &values, - &found)) = < 0) - return -1; + virJSONValuePtr option =3D g_hash_table_lookup(options, virQEMUCap= sCommandLine[i].option); + size_t j; - if (found && !virQEMUCapsCommandLine[i].param) + if (!option) + continue; + + /* not looking for a specific argument */ + if (!virQEMUCapsCommandLine[i].param) { virQEMUCapsSet(qemuCaps, virQEMUCapsCommandLine[i].flag); + continue; + } - for (j =3D 0; j < nvalues; j++) { - if (STREQ_NULLABLE(virQEMUCapsCommandLine[i].param, values[j])= ) { + for (j =3D 0; j < virJSONValueArraySize(option); j++) { + virJSONValuePtr param =3D virJSONValueArrayGet(option, j); + const char *paramname =3D virJSONValueObjectGetString(param, "= name"); + + if (STREQ_NULLABLE(virQEMUCapsCommandLine[i].param, paramname)) virQEMUCapsSet(qemuCaps, virQEMUCapsCommandLine[i].flag); - break; - } } - g_strfreev(values); } return 0; --=20 2.28.0 From nobody Thu May 16 06:22:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1606757503; cv=none; d=zohomail.com; s=zohoarc; b=RV9cAa0+RPhhw0ayCSHX7Bt62hCqc9+bCXab28yvqlAdVquszbJrB8jn8wMZ6tQ4ANXzgkA/1IsIfkfjMFjTdkGKs/sfWgbeJcjEMwRzYKErX1aNfK0aTx22JUjZk9z6kkTFVO1cd/xX/xmQvgLpgMQKHp73xMXpLdAmfn+stGM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1606757503; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=q2eiXr7Z2tfcUrNUUHmeBorvIYpAKaiMEfYuMDy6WOs=; b=ECY7S4+hug9rr9Ag+HLS8wI05W/NsWaJk/vWlqP+cny0TAYlhYcFC8NbkCQzPL2ISu4HxbsupDHGs+vpvz/z70YmJlAwpq/R/AQm+Asf48BQtEK0T7B1gdRPuIlOQXpl+6Sk0aXyYf+tFTjB22VkXiZxxpx+VECMhpJldorvFQI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1606757503063474.0003911256274; Mon, 30 Nov 2020 09:31:43 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-381-aPqKyPeaNgS5zUZkK17q0A-1; Mon, 30 Nov 2020 12:26:41 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id 81C03104FB6A; Mon, 30 Nov 2020 17:26:11 +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 7E27A5D6A8; Mon, 30 Nov 2020 17:26:10 +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 CB196180954D; Mon, 30 Nov 2020 17:26:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0AUHQ9sa003721 for ; Mon, 30 Nov 2020 12:26:09 -0500 Received: by smtp.corp.redhat.com (Postfix) id 0A079189BB; Mon, 30 Nov 2020 17:26:09 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 26A2C9CA0 for ; Mon, 30 Nov 2020 17:26:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1606757204; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=q2eiXr7Z2tfcUrNUUHmeBorvIYpAKaiMEfYuMDy6WOs=; b=hJl98LWTQVDGX0E/L014giAe+wa76dGIGxaBLXOqdbzk4+u+XMKvBcfL/xHik8xt1TrV/N MA8gCtdzdR4JVwaKFtC31Bknb0u3xAgREXjEFpY28j7bMk09fRn5GM+ndSVWeQYyUnbulb GLlZsIunj8eN/XskvshkE/ZesFsbzls= X-MC-Unique: aPqKyPeaNgS5zUZkK17q0A-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 3/3] qemuMonitorGetCommandLineOptionParameters: remove the unused function and helpers Date: Mon, 30 Nov 2020 18:25:59 +0100 Message-Id: <63f869e6f74b4467ce649067dd2dae2e722c0c8b.1606757081.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Remove the function along with helpers for caching the reply and tests. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/qemu/qemu_monitor.c | 35 ---------- src/qemu/qemu_monitor.h | 8 --- src/qemu/qemu_monitor_json.c | 120 ----------------------------------- src/qemu/qemu_monitor_json.h | 5 -- tests/qemumonitorjsontest.c | 117 ---------------------------------- 5 files changed, 285 deletions(-) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index a60d04f78a..c333fc1364 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -101,9 +101,6 @@ struct _qemuMonitor { bool waitGreeting; - /* cache of query-command-line-options results */ - virJSONValuePtr options; - /* If found, path to the virtio memballoon driver */ char *balloonpath; bool ballooninit; @@ -240,7 +237,6 @@ qemuMonitorDispose(void *obj) virResetError(&mon->lastError); virCondDestroy(&mon->notify); VIR_FREE(mon->buffer); - virJSONValueFree(mon->options); VIR_FREE(mon->balloonpath); } @@ -992,20 +988,6 @@ qemuMonitorLastError(qemuMonitorPtr mon) } -virJSONValuePtr -qemuMonitorGetOptions(qemuMonitorPtr mon) -{ - return mon->options; -} - - -void -qemuMonitorSetOptions(qemuMonitorPtr mon, virJSONValuePtr options) -{ - mon->options =3D options; -} - - /** * Search the qom objects for the balloon driver object by its known names * of "virtio-balloon-pci" or "virtio-balloon-ccw". The entry for the driv= er @@ -3856,23 +3838,6 @@ qemuMonitorGetEvents(qemuMonitorPtr mon, } -/* Collect the parameters associated with a given command line option. - * Return count of known parameters or -1 on error. */ -int -qemuMonitorGetCommandLineOptionParameters(qemuMonitorPtr mon, - const char *option, - char ***params, - bool *found) -{ - VIR_DEBUG("option=3D%s params=3D%p", option, params); - - QEMU_CHECK_MONITOR(mon); - - return qemuMonitorJSONGetCommandLineOptionParameters(mon, option, - params, found); -} - - GHashTable * qemuMonitorGetCommandLineOptions(qemuMonitorPtr mon) { diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 6b2e435f70..3dcceffef8 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -444,10 +444,6 @@ int qemuMonitorSetLink(qemuMonitorPtr mon, char *qemuMonitorNextCommandID(qemuMonitorPtr mon); int qemuMonitorSend(qemuMonitorPtr mon, qemuMonitorMessagePtr msg) G_GNUC_NO_INLINE; -virJSONValuePtr qemuMonitorGetOptions(qemuMonitorPtr mon) - ATTRIBUTE_NONNULL(1); -void qemuMonitorSetOptions(qemuMonitorPtr mon, virJSONValuePtr options) - ATTRIBUTE_NONNULL(1); int qemuMonitorUpdateVideoMemorySize(qemuMonitorPtr mon, virDomainVideoDefPtr video, const char *videoName) @@ -1284,10 +1280,6 @@ int qemuMonitorGetCommands(qemuMonitorPtr mon, char ***commands); int qemuMonitorGetEvents(qemuMonitorPtr mon, char ***events); -int qemuMonitorGetCommandLineOptionParameters(qemuMonitorPtr mon, - const char *option, - char ***params, - bool *found); GHashTable *qemuMonitorGetCommandLineOptions(qemuMonitorPtr mon); int qemuMonitorGetKVMState(qemuMonitorPtr mon, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 44d0152812..5990163519 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6450,126 +6450,6 @@ qemuMonitorJSONGetCommandLineOptions(qemuMonitorPtr= mon) } -int -qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon, - const char *option, - char ***params, - bool *found) -{ - int ret =3D -1; - virJSONValuePtr cmd =3D NULL; - virJSONValuePtr reply =3D NULL; - virJSONValuePtr data =3D NULL; - virJSONValuePtr array =3D NULL; - char **paramlist =3D NULL; - size_t n =3D 0; - size_t i; - - *params =3D NULL; - if (found) - *found =3D false; - - /* query-command-line-options has fixed output for a given qemu - * binary; but since callers want to query parameters for one - * option at a time, we cache the option list from qemu. */ - if (!(array =3D qemuMonitorGetOptions(mon))) { - if (!(cmd =3D qemuMonitorJSONMakeCommand("query-command-line-optio= ns", - NULL))) - return -1; - - if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) - goto cleanup; - - if (qemuMonitorJSONHasError(reply, "CommandNotFound")) { - ret =3D 0; - goto cleanup; - } - - if (qemuMonitorJSONCheckError(cmd, reply) < 0) - goto cleanup; - - if (virJSONValueObjectRemoveKey(reply, "return", &array) <=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-command-line-options reply was missing= " - "return data")); - goto cleanup; - } - - if (!virJSONValueIsArray(array)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Malformed query-command-line-options array")= ); - goto cleanup; - } - - qemuMonitorSetOptions(mon, array); - } - - for (i =3D 0; i < virJSONValueArraySize(array); i++) { - virJSONValuePtr child =3D virJSONValueArrayGet(array, i); - const char *tmp; - - if (!(tmp =3D virJSONValueObjectGetString(child, "option"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-command-line-options reply data was " - "missing 'option'")); - goto cleanup; - } - if (STREQ(tmp, option)) { - data =3D virJSONValueObjectGet(child, "parameters"); - break; - } - } - - if (!data) { - /* Option not found; return 0 parameters rather than an error. */ - ret =3D 0; - goto cleanup; - } - - if (found) - *found =3D true; - - if (!virJSONValueIsArray(data)) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("Malformed query-command-line-options parameters = array")); - goto cleanup; - } - n =3D virJSONValueArraySize(data); - - /* null-terminated list */ - paramlist =3D g_new0(char *, n + 1); - - for (i =3D 0; i < n; i++) { - virJSONValuePtr child =3D virJSONValueArrayGet(data, i); - const char *tmp; - - if (!(tmp =3D virJSONValueObjectGetString(child, "name"))) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("query-command-line-options parameter data wa= s " - "missing 'name'")); - goto cleanup; - } - - paramlist[i] =3D g_strdup(tmp); - } - - ret =3D n; - *params =3D paramlist; - paramlist =3D NULL; - - cleanup: - /* If we failed before getting the JSON array of options, we (try) - * to cache an empty array to speed up the next failure. */ - if (!qemuMonitorGetOptions(mon)) - qemuMonitorSetOptions(mon, virJSONValueNewArray()); - - g_strfreev(paramlist); - virJSONValueFree(cmd); - virJSONValueFree(reply); - return ret; -} - - int qemuMonitorJSONGetKVMState(qemuMonitorPtr mon, bool *enabled, bool *present) diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index 53445b97bb..da988f0d41 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -425,11 +425,6 @@ int qemuMonitorJSONGetCommands(qemuMonitorPtr mon, int qemuMonitorJSONGetEvents(qemuMonitorPtr mon, char ***events) ATTRIBUTE_NONNULL(2); -int qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon, - const char *option, - char ***params, - bool *found) - ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); GHashTable *qemuMonitorJSONGetCommandLineOptions(qemuMonitorPtr mon); int qemuMonitorJSONGetKVMState(qemuMonitorPtr mon, diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index 25ebf06eb0..d22a92d3e1 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -616,122 +616,6 @@ testQemuMonitorJSONGetTPMModels(const void *opaque) } -static int -testQemuMonitorJSONGetCommandLineOptionParameters(const void *opaque) -{ - const testGenericData *data =3D opaque; - virDomainXMLOptionPtr xmlopt =3D data->xmlopt; - int ret =3D -1; - char **params =3D NULL; - int nparams =3D 0; - bool found =3D false; - g_autoptr(qemuMonitorTest) test =3D NULL; - - if (!(test =3D qemuMonitorTestNewSchema(xmlopt, data->schema))) - return -1; - - if (qemuMonitorTestAddItem(test, "query-command-line-options", - "{ " - " \"return\": [ " - " {\"parameters\": [], \"option\": \"acpi\= " }," - " {\"parameters\": [" - " {\"name\": \"romfile\", " - " \"type\": \"string\"}, " - " {\"name\": \"bootindex\", " - " \"type\": \"number\"}], " - " \"option\": \"option-rom\"}" - " ]" - "}") < 0) - goto cleanup; - - /* present with params */ - if ((nparams =3D qemuMonitorGetCommandLineOptionParameters(qemuMonitor= TestGetMonitor(test), - "option-rom", - ¶ms, - NULL)) < 0) - goto cleanup; - - if (nparams !=3D 2) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "nparams was %d, expected 2", nparams); - goto cleanup; - } - -#define CHECK(i, wantname) \ - do { \ - if (STRNEQ(params[i], (wantname))) { \ - virReportError(VIR_ERR_INTERNAL_ERROR, \ - "name was %s, expected %s", \ - params[i], (wantname)); \ - goto cleanup; \ - } \ - } while (0) - - CHECK(0, "romfile"); - CHECK(1, "bootindex"); - -#undef CHECK - - g_strfreev(params); - params =3D NULL; - - /* present but empty */ - if ((nparams =3D qemuMonitorGetCommandLineOptionParameters(qemuMonitor= TestGetMonitor(test), - "acpi", - ¶ms, - &found)) < 0) - goto cleanup; - - if (nparams !=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "nparams was %d, expected 0", nparams); - goto cleanup; - } - if (!found) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - "found was false, expected true"); - goto cleanup; - } - if (params && params[0]) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - "unexpected array contents"); - goto cleanup; - } - - g_strfreev(params); - params =3D NULL; - - /* no such option */ - if ((nparams =3D qemuMonitorGetCommandLineOptionParameters(qemuMonitor= TestGetMonitor(test), - "foobar", - ¶ms, - &found)) < 0) - goto cleanup; - - if (nparams !=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "nparams was %d, expected 0", nparams); - goto cleanup; - } - if (found) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - "found was true, expected false"); - goto cleanup; - } - if (params && params[0]) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - "unexpected array contents"); - goto cleanup; - } - - ret =3D 0; - - cleanup: - g_strfreev(params); - return ret; -} - - struct qemuMonitorJSONTestAttachChardevData { qemuMonitorTestPtr test; virDomainChrSourceDefPtr chr; @@ -3256,7 +3140,6 @@ mymain(void) DO_TEST(GetCPUDefinitions); DO_TEST(GetCommands); DO_TEST(GetTPMModels); - DO_TEST(GetCommandLineOptionParameters); if (qemuMonitorJSONTestAttachChardev(driver.xmlopt, qapiData.schema) <= 0) ret =3D -1; DO_TEST(DetachChardev); --=20 2.28.0