From nobody Mon Feb 9 06:09:18 2026 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=1633623060; cv=none; d=zohomail.com; s=zohoarc; b=Lj1pVoXj5ikxyXZw+AV49w+wN+olbiKLw/0P2hpocP0NJ1bz8ES5g+oj8UU1H9fXOK9bau9m+8ho0OhV1o08zyyRTzbAUpbcyNfv2ZmCxpuU36SqMBplmmZtqq1F5NLoBpnnre+XqWasQivBUCr+Zkd6hXCFwNiQfABJcyf4fyA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633623060; 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=OCzsvjbQjRTcG+xbEQu9JAR242N275u7i/bQAAgYmMM=; b=d3rGHshFbEB1lUcd5EFE1e3koMT0/c2Ct3UzqzbcW4p5aJpHwtwx2ZbvLazUpO0ZURqBU2ZrBkyuaue9PQMz8Zsp6PQbZb4jLbnco74g/e5ua4spu1ADaDDJoqbmlW7VDb6uqFYL/kSmBMqhixNoFWnnw7fasvGtmK/Ep7RODts= 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) 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 1633623059943958.4404552626968; Thu, 7 Oct 2021 09:10:59 -0700 (PDT) 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-135-y3uHmXmcNu6sCJv83-Dtxw-1; Thu, 07 Oct 2021 12:10:55 -0400 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id D060AF9291A; Thu, 7 Oct 2021 15:53:41 +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 8CB1D81DD6; Thu, 7 Oct 2021 15:53:41 +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 309A01803B30; Thu, 7 Oct 2021 15:53:41 +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 197FKaAm024193 for ; Thu, 7 Oct 2021 11:20:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id CB9BF5F503; Thu, 7 Oct 2021 15:20:36 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30BB95F4F4 for ; Thu, 7 Oct 2021 15:20:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633623059; 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=OCzsvjbQjRTcG+xbEQu9JAR242N275u7i/bQAAgYmMM=; b=SliormL8gZw06FaEgc5Er3tUx4ybdBvEh97/RwVUNoJfUR158Od0+/VsdzesNYolPmUe5L blmn0G8I6EsXurTzpSDF36Mje1mehRLySXW9UEUFL9gf+jMXHpyITqOWBiHRj3aLqS4o05 AflBFxm3aCijmmL0g++ZmEX76xKTpfI= X-MC-Unique: y3uHmXmcNu6sCJv83-Dtxw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 062/103] qemuBuildRNGCommandLine: Generate via JSON Date: Thu, 7 Oct 2021 17:17:50 +0200 Message-Id: <610770df594fb428a4c9378e838a07a164e13ab3.1633619630.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.12 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) X-ZM-MESSAGEID: 1633623061440100001 Content-Type: text/plain; charset="utf-8" The 'virtio-rng' has the following property types according to QEMU: rng=3D> max-bytes=3D - (default: 9223372036854775807) period=3D - (default: 65536) Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 46 +++++++++++++++++++++++------------------ src/qemu/qemu_command.h | 7 ++++--- src/qemu/qemu_hotplug.c | 6 +++--- 3 files changed, 33 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 95070e4a06..b321c964ab 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5800,32 +5800,36 @@ qemuBuildRNGBackendProps(virDomainRNGDef *rng, } -char * -qemuBuildRNGDevStr(const virDomainDef *def, - virDomainRNGDef *dev, - virQEMUCaps *qemuCaps) +virJSONValue * +qemuBuildRNGDevProps(const virDomainDef *def, + virDomainRNGDef *dev, + virQEMUCaps *qemuCaps) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + g_autoptr(virJSONValue) props =3D NULL; + unsigned int period =3D 0; - if (qemuBuildVirtioDevStr(&buf, qemuCaps, VIR_DOMAIN_DEVICE_RNG, dev) = < 0) { + if (!(props =3D qemuBuildVirtioDevProps(VIR_DOMAIN_DEVICE_RNG, dev, qe= muCaps))) return NULL; - } - - virBufferAsprintf(&buf, ",rng=3Dobj%s,id=3D%s", - dev->info.alias, dev->info.alias); if (dev->rate > 0) { - virBufferAsprintf(&buf, ",max-bytes=3D%u", dev->rate); - if (dev->period) - virBufferAsprintf(&buf, ",period=3D%u", dev->period); - else - virBufferAddLit(&buf, ",period=3D1000"); + period =3D dev->period; + + if (period =3D=3D 0) + period =3D 1000; } - if (qemuBuildDeviceAddressStr(&buf, def, &dev->info) < 0) + if (virJSONValueObjectAdd(props, + "f:rng", g_strdup_printf("obj%s", dev->info.= alias), + "s:id", dev->info.alias, + "p:max-bytes", dev->rate, + "p:period", period, + NULL) < 0) return NULL; - return virBufferContentAndReset(&buf); + if (qemuBuildDeviceAddressProps(props, def, &dev->info) < 0) + return NULL; + + return g_steal_pointer(&props); } @@ -5844,7 +5848,7 @@ qemuBuildRNGCommandLine(virLogManager *logManager, g_autoptr(virJSONValue) props =3D NULL; virDomainRNGDef *rng =3D def->rngs[i]; g_autofree char *chardev =3D NULL; - g_autofree char *devstr =3D NULL; + g_autoptr(virJSONValue) devprops =3D NULL; if (!rng->info.alias) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -5871,9 +5875,11 @@ qemuBuildRNGCommandLine(virLogManager *logManager, if (qemuCommandAddExtDevice(cmd, &rng->info) < 0) return -1; - if (!(devstr =3D qemuBuildRNGDevStr(def, rng, qemuCaps))) + if (!(devprops =3D qemuBuildRNGDevProps(def, rng, qemuCaps))) + return -1; + + if (qemuBuildDeviceCommandlineFromJSON(cmd, devprops, qemuCaps) < = 0) return -1; - virCommandAddArgList(cmd, "-device", devstr, NULL); } return 0; diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 3cf1671c79..709b75c252 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -169,9 +169,10 @@ char *qemuBuildPCIHostdevDevStr(const virDomainDef *de= f, virDomainHostdevDef *dev, virQEMUCaps *qemuCaps); -char *qemuBuildRNGDevStr(const virDomainDef *def, - virDomainRNGDef *dev, - virQEMUCaps *qemuCaps); +virJSONValue * +qemuBuildRNGDevProps(const virDomainDef *def, + virDomainRNGDef *dev, + virQEMUCaps *qemuCaps); int qemuBuildRNGBackendProps(virDomainRNGDef *rng, virJSONValue **props); diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 3ee0ccd088..4230f6f70e 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2309,7 +2309,7 @@ qemuDomainAttachRNGDevice(virQEMUDriver *driver, qemuDomainObjPrivate *priv =3D vm->privateData; virDomainDeviceDef dev =3D { VIR_DOMAIN_DEVICE_RNG, { .rng =3D rng } }; virErrorPtr orig_err; - g_autofree char *devstr =3D NULL; + g_autoptr(virJSONValue) devprops =3D NULL; g_autofree char *charAlias =3D NULL; g_autofree char *objAlias =3D NULL; g_autofree char *tlsAlias =3D NULL; @@ -2338,7 +2338,7 @@ qemuDomainAttachRNGDevice(virQEMUDriver *driver, teardowncgroup =3D true; /* build required metadata */ - if (!(devstr =3D qemuBuildRNGDevStr(vm->def, rng, priv->qemuCaps))) + if (!(devprops =3D qemuBuildRNGDevProps(vm->def, rng, priv->qemuCaps))) goto cleanup; if (qemuBuildRNGBackendProps(rng, &props) < 0) @@ -2369,7 +2369,7 @@ qemuDomainAttachRNGDevice(virQEMUDriver *driver, if (qemuDomainAttachExtensionDevice(priv->mon, &rng->info) < 0) goto exit_monitor; - if (qemuMonitorAddDevice(priv->mon, devstr) < 0) { + if (qemuMonitorAddDeviceProps(priv->mon, &devprops) < 0) { ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &rng->info= )); goto exit_monitor; } --=20 2.31.1