From nobody Mon Feb 9 04:46:36 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=1633622693; cv=none; d=zohomail.com; s=zohoarc; b=Yosqr0+DVqBFQydR6SiW2O1FmuvVNpyNEUnkR8P/AZW9M9iQXv96XFx8rM6S6FTcT673rLdyIOmWGQxaIiZKWYUpzvcVSxFzdLfAqpAxr8/cpFkHtk4Zu9uxRVHe4raG5ITt7+/9UZTRX/NwUK89/yVhP1tawZyFC2VRnVbhe9w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633622693; 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=CvWm6i5b3nK5TZ7CXWQX6Yroa2m6mJ0sOkIyAG1huMI=; b=mSY6XUtT3n88MUTBbyR7hOqND79s2IEnZIqVQ6PrOOBHNgmloS5mqqTJLyBOyOZzRiLAavNZGsSIxjYjbD8EY2iepGVbVSsun8bdx825PR2ymvdkXOR71UPEd0uPUUW64bVdXU0b1BYCSj4/4agmJ++1CV1/+m1cwLtsg7sh8Bw= 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 1633622693261218.30070670162706; Thu, 7 Oct 2021 09:04:53 -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-521-v5TOimeZMvyAveoZW82N8w-1; Thu, 07 Oct 2021 12:04:50 -0400 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 D34189B244F; Thu, 7 Oct 2021 15:46:02 +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 66B23E0001; Thu, 7 Oct 2021 15:46:02 +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 26EF51806D02; Thu, 7 Oct 2021 15:46:02 +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 197FIdud023541 for ; Thu, 7 Oct 2021 11:18:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id C1A875D6D5; Thu, 7 Oct 2021 15:18:39 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.5]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2EBE55D6BA for ; Thu, 7 Oct 2021 15:18:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633622692; 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=CvWm6i5b3nK5TZ7CXWQX6Yroa2m6mJ0sOkIyAG1huMI=; b=EawqiUhzZcst5iJeMjhpE896YRzwRxBA/+6X0CaJ5crmtxF0YbzzP8jrp4uPxbFoVqGhXw 0DuRq3Ik2nCZueyP1rdY7xk8XUe/nsa2aBVStfj6gEp05+7C7YQpZ6wYPPdH2XK77J7+WX FU/nrYuE3Aij8oEZQ5/CVxhO5gECtUE= X-MC-Unique: v5TOimeZMvyAveoZW82N8w-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 006/103] qemuBuildObjectCommandlineFromJSON: Format directly into the virCommand Date: Thu, 7 Oct 2021 17:16:54 +0200 Message-Id: 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.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) X-ZM-MESSAGEID: 1633622694692100001 Content-Type: text/plain; charset="utf-8" All callers basically end up dumping the buffer into a string and then adding '-object' 'props' arguments to virCommand. Simplify all callers by doing this in the function itself. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 119 +++++++++++----------------------------- 1 file changed, 32 insertions(+), 87 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index a4d439a0ec..ae8234f88f 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -156,10 +156,11 @@ VIR_ENUM_IMPL(qemuAudioDriver, static int -qemuBuildObjectCommandlineFromJSON(virBuffer *buf, +qemuBuildObjectCommandlineFromJSON(virCommand *cmd, virJSONValue *props, virQEMUCaps *qemuCaps) { + g_autofree char *arg =3D NULL; const char *type =3D virJSONValueObjectGetString(props, "qom-type"); const char *alias =3D virJSONValueObjectGetString(props, "id"); @@ -171,13 +172,22 @@ qemuBuildObjectCommandlineFromJSON(virBuffer *buf, } if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_QAPIFIED)) { - return virJSONValueToBuffer(props, buf, false); + if (!(arg =3D virJSONValueToString(props, false))) + return -1; } else { - virBufferAsprintf(buf, "%s,", type); + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - return virQEMUBuildCommandLineJSON(props, buf, "qom-type", - virQEMUBuildCommandLineJSONArra= yBitmap); + virBufferAsprintf(&buf, "%s,", type); + + if (virQEMUBuildCommandLineJSON(props, &buf, "qom-type", + virQEMUBuildCommandLineJSONArrayBi= tmap) < 0) + return -1; + + arg =3D virBufferContentAndReset(&buf); } + + virCommandAddArgList(cmd, "-object", arg, NULL); + return 0; } @@ -197,7 +207,6 @@ qemuBuildMasterKeyCommandLine(virCommand *cmd, { g_autofree char *alias =3D NULL; g_autofree char *path =3D NULL; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autoptr(virJSONValue) props =3D NULL; if (!(alias =3D qemuDomainGetMasterKeyAlias())) @@ -217,12 +226,9 @@ qemuBuildMasterKeyCommandLine(virCommand *cmd, NULL) < 0) return -1; - if (qemuBuildObjectCommandlineFromJSON(&buf, props, priv->qemuCaps) < = 0) + if (qemuBuildObjectCommandlineFromJSON(cmd, props, priv->qemuCaps) < 0) return -1; - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &buf); - return 0; } @@ -732,18 +738,14 @@ qemuBuildObjectSecretCommandLine(virCommand *cmd, qemuDomainSecretInfo *secinfo, virQEMUCaps *qemuCaps) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autoptr(virJSONValue) props =3D NULL; if (qemuBuildSecretInfoProps(secinfo, &props) < 0) return -1; - if (qemuBuildObjectCommandlineFromJSON(&buf, props, qemuCaps) < 0) + if (qemuBuildObjectCommandlineFromJSON(cmd, props, qemuCaps) < 0) return -1; - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &buf); - return 0; } @@ -803,19 +805,15 @@ qemuBuildTLSx509CommandLine(virCommand *cmd, const char *alias, virQEMUCaps *qemuCaps) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autoptr(virJSONValue) props =3D NULL; if (qemuBuildTLSx509BackendProps(tlspath, isListen, verifypeer, alias, certEncSecretAlias, &props) < 0) return -1; - if (qemuBuildObjectCommandlineFromJSON(&buf, props, qemuCaps) < 0) + if (qemuBuildObjectCommandlineFromJSON(cmd, props, qemuCaps) < 0) return -1; - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &buf); - return 0; } @@ -1852,17 +1850,12 @@ qemuBuildObjectCommandline(virCommand *cmd, virJSONValue *objProps, virQEMUCaps *qemuCaps) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; - if (!objProps) return 0; - if (qemuBuildObjectCommandlineFromJSON(&buf, objProps, qemuCaps) < 0) + if (qemuBuildObjectCommandlineFromJSON(cmd, objProps, qemuCaps) < 0) return -1; - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &buf); - return 0; } @@ -3210,7 +3203,7 @@ qemuBuildMemoryCellBackendProps(virDomainDef *def, static int -qemuBuildMemoryDimmBackendStr(virBuffer *buf, +qemuBuildMemoryDimmBackendStr(virCommand *cmd, virDomainMemoryDef *mem, virDomainDef *def, virQEMUDriverConfig *cfg, @@ -3231,7 +3224,7 @@ qemuBuildMemoryDimmBackendStr(virBuffer *buf, priv, def, mem, true, false) < 0) return -1; - if (qemuBuildObjectCommandlineFromJSON(buf, props, priv->qemuCaps) < 0) + if (qemuBuildObjectCommandlineFromJSON(cmd, props, priv->qemuCaps) < 0) return -1; return 0; @@ -3946,16 +3939,12 @@ qemuBuildInputCommandLine(virCommand *cmd, if (input->type =3D=3D VIR_DOMAIN_INPUT_TYPE_EVDEV) { g_autoptr(virJSONValue) props =3D NULL; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; if (!(props =3D qemuBuildInputEvdevProps(input))) return -1; - if (qemuBuildObjectCommandlineFromJSON(&buf, props, qemuCaps) = < 0) + if (qemuBuildObjectCommandlineFromJSON(cmd, props, qemuCaps) <= 0) return -1; - - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &buf); } else { g_autofree char *devstr =3D NULL; @@ -5523,11 +5512,9 @@ qemuBuildRNGCommandLine(virLogManager *logManager, for (i =3D 0; i < def->nrngs; i++) { g_autoptr(virJSONValue) props =3D NULL; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; virDomainRNGDef *rng =3D def->rngs[i]; g_autofree char *chardev =3D NULL; g_autofree char *devstr =3D NULL; - int rc; if (!rng->info.alias) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -5547,14 +5534,9 @@ qemuBuildRNGCommandLine(virLogManager *logManager, if (qemuBuildRNGBackendProps(rng, &props) < 0) return -1; - rc =3D qemuBuildObjectCommandlineFromJSON(&buf, props, qemuCaps); - - if (rc < 0) + if (qemuBuildObjectCommandlineFromJSON(cmd, props, qemuCaps) < 0) return -1; - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &buf); - /* add the device */ if (qemuCommandAddExtDevice(cmd, &rng->info) < 0) return -1; @@ -7109,7 +7091,6 @@ qemuBuildMemCommandLineMemoryDefaultBackend(virComman= d *cmd, { g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv->dr= iver); g_autoptr(virJSONValue) props =3D NULL; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; virDomainMemoryDef mem =3D { 0 }; mem.size =3D virDomainDefGetMemoryInitial(def); @@ -7120,11 +7101,9 @@ qemuBuildMemCommandLineMemoryDefaultBackend(virComma= nd *cmd, priv, def, &mem, false, true) < 0) return -1; - if (qemuBuildObjectCommandlineFromJSON(&buf, props, priv->qemuCaps) < = 0) + if (qemuBuildObjectCommandlineFromJSON(cmd, props, priv->qemuCaps) < 0) return -1; - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &buf); return 0; } @@ -7203,17 +7182,13 @@ qemuBuildIOThreadCommandLine(virCommand *cmd, for (i =3D 0; i < def->niothreadids; i++) { g_autoptr(virJSONValue) props =3D NULL; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autofree char *alias =3D g_strdup_printf("iothread%u", def->ioth= readids[i]->iothread_id); if (qemuMonitorCreateObjectProps(&props, "iothread", alias, NULL) = < 0) return -1; - if (qemuBuildObjectCommandlineFromJSON(&buf, props, qemuCaps) < 0) + if (qemuBuildObjectCommandlineFromJSON(cmd, props, qemuCaps) < 0) return -1; - - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &buf); } return 0; @@ -7442,14 +7417,9 @@ qemuBuildNumaCommandLine(virQEMUDriverConfig *cfg, ssize_t initiator =3D virDomainNumaGetNodeInitiator(def->numa, i); if (needBackend) { - g_auto(virBuffer) objbuf =3D VIR_BUFFER_INITIALIZER; - - if (qemuBuildObjectCommandlineFromJSON(&objbuf, nodeBackends[i= ], + if (qemuBuildObjectCommandlineFromJSON(cmd, nodeBackends[i], priv->qemuCaps) < 0) goto cleanup; - - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &objbuf); } virCommandAddArg(cmd, "-numa"); @@ -7527,15 +7497,11 @@ qemuBuildMemoryDeviceCommandLine(virCommand *cmd, /* memory hotplug requires NUMA to be enabled - we already checked * that memory devices are present only when NUMA is */ for (i =3D 0; i < def->nmems; i++) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; char *dimmStr; - if (qemuBuildMemoryDimmBackendStr(&buf, def->mems[i], def, cfg, pr= iv) < 0) + if (qemuBuildMemoryDimmBackendStr(cmd, def->mems[i], def, cfg, pri= v) < 0) return -1; - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &buf); - if (!(dimmStr =3D qemuBuildMemoryDeviceStr(def, def->mems[i], priv= ->qemuCaps))) return -1; @@ -9044,10 +9010,8 @@ qemuBuildShmemCommandLine(virLogManager *logManager, bool chardevStdioLogd) { g_autoptr(virJSONValue) memProps =3D NULL; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autofree char *devstr =3D NULL; g_autofree char *chardev =3D NULL; - int rc; unsigned int cdevflags =3D QEMU_BUILD_CHARDEV_TCP_NOWAIT | QEMU_BUILD_CHARDEV_UNIX_FD_PASS; if (chardevStdioLogd) @@ -9088,14 +9052,9 @@ qemuBuildShmemCommandLine(virLogManager *logManager, if (!(memProps =3D qemuBuildShmemBackendMemProps(shmem))) return -1; - rc =3D qemuBuildObjectCommandlineFromJSON(&buf, memProps, qemuCaps= ); - - if (rc < 0) + if (qemuBuildObjectCommandlineFromJSON(cmd, memProps, qemuCaps) < = 0) return -1; - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &buf); - G_GNUC_FALLTHROUGH; case VIR_DOMAIN_SHMEM_MODEL_IVSHMEM_DOORBELL: devstr =3D qemuBuildShmemDevStr(def, shmem, qemuCaps); @@ -9816,7 +9775,6 @@ qemuBuildSEVCommandLine(virDomainObj *vm, virCommand = *cmd, virDomainSEVDef *sev) { g_autoptr(virJSONValue) props =3D NULL; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; qemuDomainObjPrivate *priv =3D vm->privateData; g_autofree char *dhpath =3D NULL; g_autofree char *sessionpath =3D NULL; @@ -9839,11 +9797,9 @@ qemuBuildSEVCommandLine(virDomainObj *vm, virCommand= *cmd, NULL) < 0) return -1; - if (qemuBuildObjectCommandlineFromJSON(&buf, props, priv->qemuCaps) < = 0) + if (qemuBuildObjectCommandlineFromJSON(cmd, props, priv->qemuCaps) < 0) return -1; - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &buf); return 0; } @@ -9852,18 +9808,15 @@ static int qemuBuildPVCommandLine(virDomainObj *vm, virCommand *cmd) { g_autoptr(virJSONValue) props =3D NULL; - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; qemuDomainObjPrivate *priv =3D vm->privateData; if (qemuMonitorCreateObjectProps(&props, "s390-pv-guest", "lsec0", NULL) < 0) return -1; - if (qemuBuildObjectCommandlineFromJSON(&buf, props, priv->qemuCaps) < = 0) + if (qemuBuildObjectCommandlineFromJSON(cmd, props, priv->qemuCaps) < 0) return -1; - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &buf); return 0; } @@ -9993,7 +9946,6 @@ qemuBuildManagedPRCommandLine(virCommand *cmd, const virDomainDef *def, qemuDomainObjPrivate *priv) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autoptr(virJSONValue) props =3D NULL; if (!virDomainDefHasManagedPR(def)) @@ -10002,12 +9954,9 @@ qemuBuildManagedPRCommandLine(virCommand *cmd, if (!(props =3D qemuBuildPRManagedManagerInfoProps(priv))) return -1; - if (qemuBuildObjectCommandlineFromJSON(&buf, props, priv->qemuCaps) < = 0) + if (qemuBuildObjectCommandlineFromJSON(cmd, props, priv->qemuCaps) < 0) return -1; - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &buf); - return 0; } @@ -10076,7 +10025,6 @@ qemuBuildDBusVMStateCommandLine(virCommand *cmd, virQEMUDriver *driver, virDomainObj *vm) { - g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; g_autoptr(virJSONValue) props =3D NULL; qemuDomainObjPrivate *priv =3D QEMU_DOMAIN_PRIVATE(vm); @@ -10091,12 +10039,9 @@ qemuBuildDBusVMStateCommandLine(virCommand *cmd, if (!(props =3D qemuBuildDBusVMStateInfoProps(driver, vm))) return -1; - if (qemuBuildObjectCommandlineFromJSON(&buf, props, priv->qemuCaps) < = 0) + if (qemuBuildObjectCommandlineFromJSON(cmd, props, priv->qemuCaps) < 0) return -1; - virCommandAddArg(cmd, "-object"); - virCommandAddArgBuffer(cmd, &buf); - priv->dbusVMState =3D true; return 0; --=20 2.31.1