From nobody Mon Feb 9 12:29:15 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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 170.10.129.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=1652196078; cv=none; d=zohomail.com; s=zohoarc; b=myWT6sCOlWk57aS0QmXn6J2cZIudGj+bIIx/XefJJp3KgCPM2MN5K9RLW56QzSos2Z4e2CA7EdFcasOS/JtRTWqLHHsjOYt51HtqB3+2Z7jLTDPQXqGKajc+mS2tJIc6L53Pwrdqxz6Dpr7dCGOYjL4BasgFBLKJ8tHZTwaVHG8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1652196078; 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=AEGmG42HS1+n2WAIgQh/aB1cNfjrl8U3er4CRruMCI0=; b=BzTnyH33QY4mxYhQgW3mg43elbm5iP8wnU9V+CJXQDDqFtg1GxgJ9q2udb0+tXMryVVrxQzGYzzGCNpvfxmRQi73zDAVi0JyP92ybAqRlvSnaZfESfGGDrOpJc/4BXuuDwQqfU6vPXRmKwoBpFnN95O1PW/OFnZpN0JlD82J374= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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 [170.10.129.124]) by mx.zohomail.com with SMTPS id 1652196078686101.74267078972002; Tue, 10 May 2022 08:21:18 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-73-ip1ZskPaMgaD96seY7Qzng-1; Tue, 10 May 2022 11:21:12 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AC46D85A5BC; Tue, 10 May 2022 15:21:09 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9861640CFD06; Tue, 10 May 2022 15:21:09 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 633091947055; Tue, 10 May 2022 15:21:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id F23F2194704D for ; Tue, 10 May 2022 15:21:07 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id C635A200B427; Tue, 10 May 2022 15:21:07 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 569B72024CCA for ; Tue, 10 May 2022 15:20:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652196077; 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=AEGmG42HS1+n2WAIgQh/aB1cNfjrl8U3er4CRruMCI0=; b=Que02MTWaICO+mQ9jt6U+PMDOa+04/xseKeHjJERnMAwsNSHMYKqzzmbBbGhtPdwsakS2y KBlJa820Evj8X1i12NjvEAWI57vJwwP0GCim/GO3ewvKhMT05Guk6ADegynMdORzeUtOuc NJGwuh0ONM3QqB/tBcGg5dD93IlYuFA= X-MC-Unique: ip1ZskPaMgaD96seY7Qzng-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 16/37] qemuBuildHostNetProps: Refactor construction of tapfd/vhostfd arguments Date: Tue, 10 May 2022 17:19:52 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 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: 1652196080287100001 Content-Type: text/plain; charset="utf-8" Pre-construct the array the same way for the case when there's only one FD and when there are multiple. We just change the argument name depending on the count. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 66 +++++++++++++++++++---------------------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 19afad22a1..c412bc50e0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4215,54 +4215,50 @@ qemuBuildHostNetProps(virDomainNetDef *net, case VIR_DOMAIN_NET_TYPE_BRIDGE: case VIR_DOMAIN_NET_TYPE_NETWORK: case VIR_DOMAIN_NET_TYPE_DIRECT: - case VIR_DOMAIN_NET_TYPE_ETHERNET: - if (virJSONValueObjectAdd(&netprops, "s:type", "tap", NULL) < 0) - return NULL; + case VIR_DOMAIN_NET_TYPE_ETHERNET: { + g_auto(virBuffer) buf =3D VIR_BUFFER_INITIALIZER; + /* for one tapfd/vhostfd 'fd=3D' shall be used, for more than use = 'fds=3D' */ + const char *tapfd_field =3D "s:fd"; + g_autofree char *tapfd_arg =3D NULL; + const char *vhostfd_field =3D "S:vhostfd"; + g_autofree char *vhostfd_arg =3D NULL; + bool vhost =3D false; - /* for one tapfd 'fd=3D' shall be used, - * for more than one 'fds=3D' is the right choice */ - if (tapfdSize =3D=3D 1) { - if (virJSONValueObjectAdd(&netprops, "s:fd", tapfd[0], NULL) <= 0) - return NULL; - } else { - g_auto(virBuffer) fdsbuf =3D VIR_BUFFER_INITIALIZER; + for (i =3D 0; i < tapfdSize; i++) + virBufferAsprintf(&buf, "%s:", tapfd[i]); - for (i =3D 0; i < tapfdSize; i++) - virBufferAsprintf(&fdsbuf, "%s:", tapfd[i]); + if (tapfdSize > 1) + tapfd_field =3D "s:fds"; - virBufferTrim(&fdsbuf, ":"); + virBufferTrim(&buf, ":"); + tapfd_arg =3D virBufferContentAndReset(&buf); - if (virJSONValueObjectAdd(&netprops, - "s:fds", virBufferCurrentContent(&fd= sbuf), - NULL) < 0) - return NULL; - } + if (vhostfdSize > 0) { + vhost =3D true; - if (vhostfdSize) { - if (virJSONValueObjectAppendBoolean(netprops, "vhost", true) <= 0) - return NULL; + for (i =3D 0; i < vhostfdSize; i++) + virBufferAsprintf(&buf, "%s:", vhostfd[i]); - if (vhostfdSize =3D=3D 1) { - if (virJSONValueObjectAdd(&netprops, "s:vhostfd", vhostfd[= 0], NULL) < 0) - return NULL; - } else { - g_auto(virBuffer) fdsbuf =3D VIR_BUFFER_INITIALIZER; + if (vhostfdSize > 1) + vhostfd_field =3D "s:vhostfds"; + } - for (i =3D 0; i < vhostfdSize; i++) - virBufferAsprintf(&fdsbuf, "%s:", vhostfd[i]); + virBufferTrim(&buf, ":"); + vhostfd_arg =3D virBufferContentAndReset(&buf); - virBufferTrim(&fdsbuf, ":"); + if (virJSONValueObjectAdd(&netprops, + "s:type", "tap", + tapfd_field, tapfd_arg, + "B:vhost", vhost, + vhostfd_field, vhostfd_arg, + NULL) < 0) + return NULL; - if (virJSONValueObjectAdd(&netprops, - "s:vhostfds", virBufferCurrentCo= ntent(&fdsbuf), - NULL) < 0) - return NULL; - } - } if (net->tune.sndbuf_specified && virJSONValueObjectAppendNumberUlong(netprops, "sndbuf", net->t= une.sndbuf) < 0) return NULL; + } break; case VIR_DOMAIN_NET_TYPE_CLIENT: --=20 2.35.1