From nobody Sun Dec 14 02:18:19 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=smartx.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1751642457939883.0586951705152; Fri, 4 Jul 2025 08:20:57 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id ED61A157A; Fri, 4 Jul 2025 11:20:56 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 038F41488; Fri, 4 Jul 2025 11:20:31 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 38D4F145F; Fri, 4 Jul 2025 11:20:27 -0400 (EDT) Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 07FFE1445 for ; Fri, 4 Jul 2025 11:20:24 -0400 (EDT) Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-235ea292956so10502375ad.1 for ; Fri, 04 Jul 2025 08:20:23 -0700 (PDT) Received: from Hyman-Dev-Euler.zelin.local ([45.8.186.102]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23c84350221sm23628205ad.83.2025.07.04.08.20.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 08:20:22 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1751642423; x=1752247223; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NAmTsAEG/RKtYkVKAZOjiOXxkHky3cRTDXvfjk3jnuw=; b=EP9lWSNFwYAW54fHvcuqeAX95WcuTqykQrV9+X3X/CiSYp92fcBGf7yxTUsp+xooh9 bzBqvS5AVmm1DrPhXfOYhYLhddMAK4tqoO/ruv7j0FsqqkQIumD96BOo38tXo88IWESp RHVibZ4zJ2QCA3x5UlMfCNBPC+b5lCKIHGTO7xcYL67/2OH2tQe0t0ZajKVb4p5w+ioG gsk3eVfT/EQrLy3PZFjSMeePcMAPwJ+fq5hfLnqjqMsaLqt6zRp9O2WAPis55fojZgsJ ua22xbpDC2y5XDxA4j+Y82MaTGKiKcWh+cD7Yt8r2vh0y9V1JwpYlxLU1urt/GN+gcoP 99xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751642423; x=1752247223; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NAmTsAEG/RKtYkVKAZOjiOXxkHky3cRTDXvfjk3jnuw=; b=KwcBUuqjFM97bYb6n/2tbYAHaJ3rZkT7IrUFjNFNnzoHScP/P6eYDZOq7YaAv7SppK 6vyxo+/+Azlnn0fdlzV9DKgGiQlbhTFi/9Lp18NGO1aYkOJw/7O5V42EEAwVIBsPuT5J JMKsMcKUfXbdI3o0NXDVg6Y0GORfmMPT03xZm2xnW4hpL2IPw07yv+ccJ2/dgBBTUpza sjrgO5lH7Y0vKbePH1pscip1dSDrcMN77qIrZ2AymmNyOFUypYaVPMFHIzDq9dJUpuvb wypS6Z1sfhnT1wMHEzJ/AmamZOtjVAXZA+bI3EBgCPkdvwy4k8nvujcAcjlij2tbyoa3 JDvQ== X-Gm-Message-State: AOJu0YzGqOSoo+1wa9T/FYfACuvCpNj03M0sZT/Moc/Nu6YtzOYQiDgT mtRZ0jjIyNVfAKcEFrUQKpmNj4tZAmT/PEoq36DP1y7XFfeBhoBLY3Rpj+3bu6A/JJjph/VD3lt EdKI7UhwFZw== X-Gm-Gg: ASbGncusZArvlSnQ0AUkT536cY8wT9Vr3bckN1xbkTBAM6sTuz6o0fsWieRuLarcVzt yvf1NP3FEBEKxNEi+FPzTA9Wmiii59XwiiuojkvJN8HEkO6NWdMEnqVs1e67zuzcLyFXd96h3N8 yBYAZQ7Ad0fOfXqXpPwa7RzApc3Pw+yQCyJ7H8F/IKZ9JJhGf/llBj49GArkdI4NBq8V9QDfMgy LV0Sh1eXGvroxJRt2Iu+6HIYVpCNbPwTlQkn0xuixneQ/KPKtGVU/IyydUbgKvIFP5st3L4ZdAr P+aJa9YBBcQ8xBbVIIzFCv/ZXtxVjxQyCGDA/ogoxC89UzqQzMtaY2UcYqunCUZhO8b5IlHf5am bDyU4rzXj X-Google-Smtp-Source: AGHT+IEvsArKoWLNHhQXZcEOpDwmgMHXRypEnMU1lWEQni4L3uvY/ls+lbPebP3mlM57NgkuhU7wiw== X-Received: by 2002:a17:902:e752:b0:234:d10d:9f9f with SMTP id d9443c01a7336-23c8759606dmr38429105ad.40.1751642422802; Fri, 04 Jul 2025 08:20:22 -0700 (PDT) From: yong.huang@smartx.com To: devel@lists.libvirt.org Subject: [RFC 1/4] qemu_passt: Make logFile backend-specific Date: Fri, 4 Jul 2025 22:57:56 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 3PHJR3MVAA632TTB3Y6V322XDJRBSION X-Message-ID-Hash: 3PHJR3MVAA632TTB3Y6V322XDJRBSION X-MailFrom: yong.huang@smartx.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: yong.huang@smartx.com X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1751642460784116600 Content-Type: text/plain; charset="utf-8" From: Hyman Huang The 'logFile' field within the virDomainNetBackend struct is backend-specific. Refactor the code by introducing a union struct to encapsulate backend-specific fields, rather than using a plain field. This refactoring is also a prerequisite for implementing the 'openvswitch' backend of vhostuser interface in upcoming commits. --- src/conf/domain_conf.c | 18 +++++++++++++----- src/conf/domain_conf.h | 7 +++++-- src/qemu/qemu_passt.c | 4 ++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1e24e41a48..9862a76023 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -2917,7 +2917,8 @@ virDomainNetDefFree(virDomainNetDef *def) =20 g_free(def->backend.tap); g_free(def->backend.vhost); - g_free(def->backend.logFile); + if (def->backend.type =3D=3D VIR_DOMAIN_NET_BACKEND_PASST) + g_free(def->backend.data.passt.logFile); virDomainNetTeamingInfoFree(def->teaming); g_free(def->virtPortProfile); g_free(def->script); @@ -9797,7 +9798,8 @@ virDomainNetBackendParseXML(xmlNodePtr node, return -1; } =20 - def->backend.logFile =3D virXMLPropString(node, "logFile"); + if (def->backend.type =3D=3D VIR_DOMAIN_NET_BACKEND_PASST) + def->backend.data.passt.logFile =3D virXMLPropString(node, "logFil= e"); =20 if (tap) def->backend.tap =3D virFileSanitizePath(tap); @@ -20798,10 +20800,14 @@ virDomainNetBackendIsEqual(virDomainNetBackend *s= rc, { if (src->type !=3D dst->type || STRNEQ_NULLABLE(src->tap, dst->tap) || - STRNEQ_NULLABLE(src->vhost, dst->vhost) || - STRNEQ_NULLABLE(src->logFile, dst->logFile)) { + STRNEQ_NULLABLE(src->vhost, dst->vhost)) { return false; } + + if (src->type =3D=3D VIR_DOMAIN_NET_BACKEND_PASST) { + return !(STRNEQ_NULLABLE(src->data.passt.logFile, dst->data.passt.= logFile)); + } + return true; } =20 @@ -24933,7 +24939,9 @@ virDomainNetBackendFormat(virBuffer *buf, } virBufferEscapeString(&attrBuf, " tap=3D'%s'", backend->tap); virBufferEscapeString(&attrBuf, " vhost=3D'%s'", backend->vhost); - virBufferEscapeString(&attrBuf, " logFile=3D'%s'", backend->logFile); + if (backend->type =3D=3D VIR_DOMAIN_NET_BACKEND_PASST) { + virBufferEscapeString(&attrBuf, " logFile=3D'%s'", backend->data.p= asst.logFile); + } virXMLFormatElement(buf, "backend", &attrBuf, NULL); } =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 6997cf7c09..6d43654f0a 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1074,8 +1074,11 @@ struct _virDomainNetBackend { virDomainNetBackendType type; char *tap; char *vhost; - /* The following are currently only valid/used when backend type=3D'pa= sst' */ - char *logFile; /* path to logfile used by passt process */ + union { + struct { + char *logFile; /* path to logfile used by passt process */ + } passt; + } data; }; =20 struct _virDomainNetPortForwardRange { diff --git a/src/qemu/qemu_passt.c b/src/qemu/qemu_passt.c index fcc34de384..d74fc2ee47 100644 --- a/src/qemu/qemu_passt.c +++ b/src/qemu/qemu_passt.c @@ -226,8 +226,8 @@ qemuPasstStart(virDomainObj *vm, if (net->sourceDev) virCommandAddArgList(cmd, "--interface", net->sourceDev, NULL); =20 - if (net->backend.logFile) - virCommandAddArgList(cmd, "--log-file", net->backend.logFile, NULL= ); + if (net->backend.data.passt.logFile) + virCommandAddArgList(cmd, "--log-file", net->backend.data.passt.lo= gFile, NULL); =20 /* Add IP address info */ for (i =3D 0; i < net->guestIP.nips; i++) { --=20 2.27.0 From nobody Sun Dec 14 02:18:19 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=smartx.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1751642529361971.1330255611193; Fri, 4 Jul 2025 08:22:09 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 6E7EE14FE; Fri, 4 Jul 2025 11:22:08 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2254115B7; Fri, 4 Jul 2025 11:20:34 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 3C80C1445; Fri, 4 Jul 2025 11:20:28 -0400 (EDT) Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 41DAE145E for ; Fri, 4 Jul 2025 11:20:26 -0400 (EDT) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-235d6de331fso14133495ad.3 for ; Fri, 04 Jul 2025 08:20:26 -0700 (PDT) Received: from Hyman-Dev-Euler.zelin.local ([45.8.186.102]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23c84350221sm23628205ad.83.2025.07.04.08.20.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 08:20:24 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1751642425; x=1752247225; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=y1TLyi+SVZr7mnLuuXipiC8II3zUAkGKVFHc9cwRfhA=; b=AY4Ac6HKC6Whl3Dua8DJAgGe/jRld3r3L8tNxn/DAM+8kATA3Tat0KKF+zCCUlGJ0r tYoc7Slz5pPRZWXAGm6JPQ5eGkldmg2fiZwUN0cg7gg3e0/dqis6vgPSoWgkA9RUTDhZ +DMpLSfLk0HaPFi98Ozcc5O8J1VvDiqMX08KVc6SnbVaMnbyRipyrHgu2y+lTyDYtYS8 58Qo3o0KNnNFvxVtVipYbhDA35ofNi0/PEhouZaBVnZlt2IOZBV9xC57JE0FgOrJvqBa skxUQvFCf9kbUO9Rdgh9SZLrF1kBdC6JrPNjAaLMA4Bc317YPK6MVlTTC6n1318wAPIx RLvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751642425; x=1752247225; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y1TLyi+SVZr7mnLuuXipiC8II3zUAkGKVFHc9cwRfhA=; b=vIlhFqucg4QIEQMQ3iJyBoGnCZXNI5WqLbaeDsSlJgfGNX0l/QP9DWNYzcf4tns88l MKcc6Pq7XVLhijPdE1baHyAxAcvmsu6VLvS3X+UiqhuD/pozuoe8zD9XuQdh+K9zL+Fc wEYtR8tK9Pl8OnT46HvGAZ78ucvR1J5p5IAJEFdQfbXyyrGMDnWH/5juh75e06VoAvqQ tIbIypEnqdw0/P6ieH0oo5kgHhoetoympccY+CjIavl6/Ceagv+j2p6WbpR5PFXMZpvT FerCAYwqLZictEcAX3cFptv3Ddmnl9n8borZNynPlPS7ijZvUMQHKk5wNIX10G4gtfg5 PIZA== X-Gm-Message-State: AOJu0YxpFQBvSeld60aZi4f+7OHKBxlc0+2IuYBpIxlzNg+zwVvpaN9N 38P/pQtgRRFAK/235vmQCkcDswksGWkwtYxJfsoSbvEuwkzzJZPWOyC72sLESaUD97RZ+uy8hgq wMI8RIGmgpQ== X-Gm-Gg: ASbGncuSVb2mgHsAqVLeqZ9dI/2ZChcC+3MlaI13VXukCgVnCwUHzhaYwiiORPImBxi C9gytYuspio823iHjCV6AHQp3lkqoPeKXvFL6ou0zftCpdCUsJZdmde5UnArzBiR33WdBAHhDaK EgR0BKck0GAG2dAePVyHd0KecDXUkFYhNCwPAzU4+CFt2GpnZ0M8kIkVFXvdHTCY1pfbaPH+17t jlE3kOAs0Mh4IHBXdxgBVEbfyDHUw7K2yLBJdlx01yRJxpeNx63+LsZ7mS3+r2M9oe6iSM/Gdst gkf2BOvbLt4qp/s7RzwRL3X/Z5WA9Uvwhxo0V504VjIGHPjUQYm5xNkathmuVHY8ABlhVS019UG rZVszrtRA X-Google-Smtp-Source: AGHT+IF7ErNWBw4Y3g+YcTz6tu1YD2s6mUoMXnx6r/QpwXPJRpxHilcO8Edm14fBpUet43+lM5fEtw== X-Received: by 2002:a17:902:d592:b0:235:799:eca5 with SMTP id d9443c01a7336-23c85eb051dmr53673945ad.44.1751642424795; Fri, 04 Jul 2025 08:20:24 -0700 (PDT) From: yong.huang@smartx.com To: devel@lists.libvirt.org Subject: [RFC 2/4] conf: Introduce autoiface attribute for vhostuser interface Date: Fri, 4 Jul 2025 22:57:57 +0800 Message-Id: <9a6b705367e32dc18f7bcd0ced1fcffd5a1b4187.1751640926.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: YUAE6PG7OGOVGO63QGCSY5WLXUCVOGXQ X-Message-ID-Hash: YUAE6PG7OGOVGO63QGCSY5WLXUCVOGXQ X-MailFrom: yong.huang@smartx.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: yong.huang@smartx.com X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1751642530923116600 Content-Type: text/plain; charset="utf-8" From: Hyman Huang This implements XML support for automatically attaching a vhostuser port to an Open vSwitch bridge. Here is an example of the config for a vhostuser interface that attached to bridge automatically: This setup offers an automated method to configure a vhostuser interface in server mode, simplifying integration with DPDK-enabled Open vSwitch bridges. --- docs/formatdomain.rst | 37 +++++++++++- src/conf/domain_conf.c | 59 ++++++++++++++++++- src/conf/domain_conf.h | 6 ++ src/conf/domain_postparse.c | 46 +++++++++++++++ src/conf/domain_validate.c | 24 ++++++++ src/conf/schemas/domaincommon.rng | 20 +++++++ .../net-vhostuser.x86_64-latest.xml | 10 ++++ tests/qemuxmlconfdata/net-vhostuser.xml | 10 ++++ 8 files changed, 209 insertions(+), 3 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 9a2f065590..d7051618a7 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -6533,6 +6533,12 @@ plane is based on shared memory. + + + + + + @@ -6557,11 +6563,40 @@ two attributes ``enabled`` (which accepts ``yes`` a= nd ``no``) and ``timeout`` which specifies the amount of seconds after which hypervisor tries to reconnect. =20 +The ```` element specifies the backend implementation of +the ``vhostuser`` interface type. The ``type`` attribute is required +and currently supports ``openvswitch`` and ``passt``. + +If ``type=3D'openvswitch'``: + + * The ``autoiface`` attribute may be specified (``yes`` or ``no``). + * If ``autoiface=3D'yes'``, the ```` element ``bridge`` + attribute is mandatory. Libvirt will derive the interface name + by extracting the substring after the ``/`` character in the + vhostuser server path, and attach it to the bridge specified by + the ``bridge`` attribute. + +If ``type=3D'passt'``: + + * See the `here + `__ + section for detailed information. + +The optional ```` element applies only to the +``openvswitch`` backend (which is both the default and only supported +type currently). See the `here +`__ section for detailed information +about ````. + Note that when ``mode=3D'server'`` is used, the hypervisor will wait for t= he incoming connection to be established prior to actually running the VM. Th= is is not possible when hotplugging an interface with such config so the VM will continue to run even when no connection is made. It's advised to use -``mode=3D'client'`` instead. +``mode=3D'client'`` instead. :since:`Since 11.6.0`, Libvirt can automatica= lly +attach the vhostuser port to the Open vSwitch bridge (i.e., the ``backend`` +element has ``type=3D'openvswitch'`` and ``autoiface=3D'yes'``). This setup +offers an automated method to configure a vhostuser interface in server +mode, simplifying integration with DPDK-enabled Open vSwitch bridges. =20 vhost-user connection with passt backend ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9862a76023..2b0b840819 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -650,6 +650,7 @@ VIR_ENUM_IMPL(virDomainNetBackend, VIR_DOMAIN_NET_BACKEND_LAST, "default", "passt", + "openvswitch", ); =20 VIR_ENUM_IMPL(virDomainNetProto, @@ -9773,6 +9774,8 @@ virDomainNetBackendParseXML(xmlNodePtr node, { g_autofree char *tap =3D virXMLPropString(node, "tap"); g_autofree char *vhost =3D virXMLPropString(node, "vhost"); + virTristateBool autoiface; + xmlNodePtr parameters =3D NULL; =20 /* In the case of NET_TYPE_USER, backend type can be unspecified * (i.e. VIR_DOMAIN_NET_BACKEND_DEFAULT) and that means 'use @@ -9798,8 +9801,33 @@ virDomainNetBackendParseXML(xmlNodePtr node, return -1; } =20 - if (def->backend.type =3D=3D VIR_DOMAIN_NET_BACKEND_PASST) + switch (def->backend.type) { + case VIR_DOMAIN_NET_BACKEND_DEFAULT: + break; + + case VIR_DOMAIN_NET_BACKEND_PASST: def->backend.data.passt.logFile =3D virXMLPropString(node, "logFil= e"); + break; + + case VIR_DOMAIN_NET_BACKEND_OPENVSWITCH: + if (virXMLPropTristateBool(node, "autoiface", VIR_XML_PROP_NONE, + &autoiface) < 0) + return -1; + virTristateBoolToBool(autoiface, &def->backend.data.openvswitch.au= toiface); + + if (def->backend.data.openvswitch.autoiface) { + if ((parameters =3D virXMLNodeGetSubelement(node, "parameters"= ))) { + def->backend.data.openvswitch.iface =3D virXMLPropString(p= arameters, "iface"); + def->backend.data.openvswitch.bridge =3D virXMLPropString(= parameters, "bridge"); + } + } + break; + + case VIR_DOMAIN_NET_BACKEND_LAST: + default: + virReportEnumRangeError(virDomainNetBackendType, def->backend.type= ); + break; + } =20 if (tap) def->backend.tap =3D virFileSanitizePath(tap); @@ -10142,6 +10170,10 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, source_node, ctxt) = < 0) return NULL; } + + virtualport_flags =3D VIR_VPORT_XML_GENERATE_MISSING_DEFAULTS | + VIR_VPORT_XML_REQUIRE_ALL_ATTRIBUTES | + VIR_VPORT_XML_REQUIRE_TYPE; } break; =20 @@ -24927,11 +24959,26 @@ virDomainNetTeamingInfoFormat(virDomainNetTeaming= Info *teaming, } =20 =20 +static void +virDomainNetBackendOpenvswitchIfaceFormat(virDomainNetBackend *backend, + virBuffer *buf) +{ + if (backend->data.openvswitch.autoiface) { + virBufferEscapeString(buf, "data.openvswitch.iface); + virBufferEscapeString(buf, " bridge=3D'%s'", + backend->data.openvswitch.bridge); + virBufferAddLit(buf, "/>\n"); + } +} + + static void virDomainNetBackendFormat(virBuffer *buf, virDomainNetBackend *backend) { g_auto(virBuffer) attrBuf =3D VIR_BUFFER_INITIALIZER; + g_auto(virBuffer) childBuf =3D VIR_BUFFER_INIT_CHILD(buf); =20 if (backend->type) { virBufferAsprintf(&attrBuf, " type=3D'%s'", @@ -24941,8 +24988,12 @@ virDomainNetBackendFormat(virBuffer *buf, virBufferEscapeString(&attrBuf, " vhost=3D'%s'", backend->vhost); if (backend->type =3D=3D VIR_DOMAIN_NET_BACKEND_PASST) { virBufferEscapeString(&attrBuf, " logFile=3D'%s'", backend->data.p= asst.logFile); + } else if (backend->type =3D=3D VIR_DOMAIN_NET_BACKEND_OPENVSWITCH) { + virBufferAsprintf(&attrBuf, " autoiface=3D'%s'", + backend->data.openvswitch.autoiface ? "yes" : "n= o"); + virDomainNetBackendOpenvswitchIfaceFormat(backend, &childBuf); } - virXMLFormatElement(buf, "backend", &attrBuf, NULL); + virXMLFormatElement(buf, "backend", &attrBuf, &childBuf); } =20 =20 @@ -30141,6 +30192,10 @@ virDomainNetGetActualBridgeName(const virDomainNet= Def *iface) (iface->data.network.actual->type =3D=3D VIR_DOMAIN_NET_TYPE_BRIDG= E || iface->data.network.actual->type =3D=3D VIR_DOMAIN_NET_TYPE_NETWO= RK)) return iface->data.network.actual->data.bridge.brname; + if (iface->type =3D=3D VIR_DOMAIN_NET_TYPE_VHOSTUSER && + iface->backend.type =3D=3D VIR_DOMAIN_NET_BACKEND_OPENVSWITCH && + iface->backend.data.openvswitch.autoiface) + return iface->backend.data.openvswitch.bridge; return NULL; } =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 6d43654f0a..c19a56e375 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -1030,6 +1030,7 @@ typedef enum { typedef enum { VIR_DOMAIN_NET_BACKEND_DEFAULT =3D 0, VIR_DOMAIN_NET_BACKEND_PASST, + VIR_DOMAIN_NET_BACKEND_OPENVSWITCH, =20 VIR_DOMAIN_NET_BACKEND_LAST } virDomainNetBackendType; @@ -1078,6 +1079,11 @@ struct _virDomainNetBackend { struct { char *logFile; /* path to logfile used by passt process */ } passt; + struct { + bool autoiface; /* create openvswitch interface automatically = */ + char *iface; /* interface name */ + char *bridge; /* bridge name that interface attached to */ + } openvswitch; } data; }; =20 diff --git a/src/conf/domain_postparse.c b/src/conf/domain_postparse.c index a07ec8d94e..f618ea3165 100644 --- a/src/conf/domain_postparse.c +++ b/src/conf/domain_postparse.c @@ -1235,6 +1235,49 @@ virDomainDefRejectDuplicatePanics(virDomainDef *def) } =20 =20 +static int +virDomainPostParseInterfaceAutoGenerate(virDomainNetDef *net) +{ + if (net->type =3D=3D VIR_DOMAIN_NET_TYPE_VHOSTUSER && + net->backend.type =3D=3D VIR_DOMAIN_NET_BACKEND_OPENVSWITCH && + net->backend.data.openvswitch.autoiface) { + if (!net->virtPortProfile) { + virNetDevVPortProfile *virtPort =3D g_new0(virNetDevVPortProfi= le, 1); + virtPort->virtPortType =3D VIR_NETDEV_VPORT_PROFILE_OPENVSWITC= H; + if (virUUIDGenerate(virtPort->instanceID) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("cannot generate a random uuid for instan= ceid")); + return -1; + } + virtPort->instanceID_specified =3D true; + net->virtPortProfile =3D virtPort; + } + + if (!net->backend.data.openvswitch.iface) { + virDomainChrSourceDef *src =3D net->data.vhostuser; + char *ifname =3D strrchr(src->data.nix.path, '/'); + if (++ifname) { + net->backend.data.openvswitch.iface =3D g_strdup(ifname); + } + } + } + + return 0; +} + + +static int +virDomainDefPostParseInterface(virDomainDef *def) +{ + size_t i; + for (i =3D 0; i < def->nnets; i++) { + if (virDomainPostParseInterfaceAutoGenerate(def->nets[i]) < 0) + return -1; + } + return 0; +} + + static int virDomainDefPostParseCommon(virDomainDef *def, struct virDomainDefPostParseDeviceIteratorData= *data, @@ -1315,6 +1358,9 @@ virDomainDefPostParseCommon(virDomainDef *def, if (virDomainDefPostParseCPU(def) < 0) return -1; =20 + if (virDomainDefPostParseInterface(def) < 0) + return -1; + return 0; } =20 diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index b28af7fa56..03ebce93a1 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -2262,6 +2262,30 @@ virDomainNetDefValidate(const virDomainNetDef *net) } } =20 + if (net->backend.type =3D=3D VIR_DOMAIN_NET_BACKEND_OPENVSWITCH) { + if (net->type !=3D VIR_DOMAIN_NET_TYPE_VHOSTUSER) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("The 'openvswitch' backend can only be used w= ith interface type=3D'vhostuser'")); + return -1; + } + + if (net->backend.data.openvswitch.autoiface) { + if (!net->backend.data.openvswitch.iface || + !net->backend.data.openvswitch.bridge) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("No interface or bridge name provided")); + return -1; + } + + if ((!net->virtPortProfile) || + (net->virtPortProfile->virtPortType !=3D VIR_NETDEV_VPORT_= PROFILE_OPENVSWITCH)) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Invalid virtualport element encountered"= )); + return -1; + } + } + } + if (net->sourceDev && net->backend.type !=3D VIR_DOMAIN_NET_BACKEND_PA= SST) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("The 'dev' attribute of the element can = only be used with type=3D'user' or type=3D'vhostuser' if the type=3D'passt'")); diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index 183dd5db5e..50a37fce43 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -3534,6 +3534,9 @@ + + + @@ -3913,6 +3916,7 @@ default passt + openvswitch @@ -3931,6 +3935,22 @@ + + + + + + + + + + + [a-zA-Z0-9\-_]+ + + + + + diff --git a/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.xml b/tests/= qemuxmlconfdata/net-vhostuser.x86_64-latest.xml index 44bebef2c8..05b85a6df0 100644 --- a/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.xml +++ b/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.xml @@ -30,12 +30,22 @@ + + + +
+ + + + + +
diff --git a/tests/qemuxmlconfdata/net-vhostuser.xml b/tests/qemuxmlconfdat= a/net-vhostuser.xml index 91d1abc027..dc4d69ba2b 100644 --- a/tests/qemuxmlconfdata/net-vhostuser.xml +++ b/tests/qemuxmlconfdata/net-vhostuser.xml @@ -23,11 +23,21 @@ + + + + + + + + + + --=20 2.27.0 From nobody Sun Dec 14 02:18:19 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=smartx.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1751642555412305.53095790906764; Fri, 4 Jul 2025 08:22:35 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 67EEDA09; Fri, 4 Jul 2025 11:22:34 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5493814D3; Fri, 4 Jul 2025 11:20:37 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 4F5621443; Fri, 4 Jul 2025 11:20:28 -0400 (EDT) Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 7C598140D for ; Fri, 4 Jul 2025 11:20:27 -0400 (EDT) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-23633a6ac50so14842075ad.2 for ; Fri, 04 Jul 2025 08:20:27 -0700 (PDT) Received: from Hyman-Dev-Euler.zelin.local ([45.8.186.102]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23c84350221sm23628205ad.83.2025.07.04.08.20.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 08:20:25 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1751642426; x=1752247226; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FsDvgzqkcIq18FtyWDBq3CEjYBEb624x1GIhn5DOqqk=; b=S8vufDJ91apZXnWJt3VfBtoHWAaEa3dSaff4ygJQEYLCQNTZ1Hn5X1slBz6BErft4H 9Qi+9VUXg1iNkFzDFKoAJeflwqGEAGwR/GYIkmq70hkOamPIgKta/PBUrm7E3xOkXWIC oew3WU2or+YgljbXlCHrBbv7E7408fg0y5Y49EaQGelymOETcDuMUJ7XuoeGrfWMQmam ssB9ucaqag4P/W1oHOnTBC8pbD4ERMHFHwBwYoeJuKkBUNtA5bM5+sjgNZDBFVAlAsOy GUZ6nuOhXihEELXLuVjLLe8StaP+xeQHddIb17RUmMh7rf1zLuuzMNc7gZSdphRnXl+f tsUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751642426; x=1752247226; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FsDvgzqkcIq18FtyWDBq3CEjYBEb624x1GIhn5DOqqk=; b=At82M8LUyAQVfC+yINSLIwQlWnUJhypkUgT6ned6/RI17/aydvcsyL1KNLdRoNGwfI j5BxnMJae95DwP1ktGCFVFk15cP5fCtl4Usio7X3ltJYmVH2LioqIWcBcmTyNA8Ebm71 N28oDhJThI6XIO1o7PZ1Sd2i4euREK9dmDJduEKLuqfy+SSJC0q3l+bEO1nARaFmMRp2 oRgZ4aI/xKG0CTU+0LNJh6wnYs9gWVCVQpApAsRWxbQWKEP6csceSyAlLUaqm8ANTrmS 3jqIA0AefBbF4Sotlz3r1BjAiQeBvgzO4nJn477nJGkzt92O6Jtx1UFeVIhFY5xjmkt8 gs1g== X-Gm-Message-State: AOJu0Yx641xbB1waoHY6fuQZsxftdC8vgt+hy+rOqvHdeddiPimPOXvD /D30um5N+umYy+ceLvIGkJfbeULF7eJb4iLyfxmZyaltE9ehlaLoGEDHHnrxpO7yRL1s/gHEDCL 8Qwu0PEO82w== X-Gm-Gg: ASbGncuY6mS44+wdaNppsdTAhmejgGi+mvVcQjhxt1dU5Ql6F/qGp1j7ZnvtoT8zq1M NvUh0I+CtpWJYALZemUsOszT7KmwRHNrFHINGMyI1hYH1MTPvLUrG61W6YspuvUzopaFuD+MfAr jKynuSJhtH6mm5wSuYSy7cm59DmW4DYHMtdyHLEWGvypPhBHIDn5J45VBUULTKWkgKTRBp/N6FX n/R62Lfb3LAC7WWy+dfzyhYxPrNkLMAzEdHZcJCpusz3NYLaabcmbDlLis7hCcmWuZ8C2WkU5f3 4rGdD0IItLBp64puYcsLFkK2IJo9hOYEETMdA9o9c5Qrm8nprszwsYNZPpL3oGTo2bj5GfkI77C VT3lMUXqT X-Google-Smtp-Source: AGHT+IGT20eT7H77IZcuv9z27FFHt2BPvg2a735S5ESYfmGGtVTeKk/XDDiudSuJnJd7kvl5RzEYZA== X-Received: by 2002:a17:902:f542:b0:237:f76f:ce34 with SMTP id d9443c01a7336-23c86066fffmr43603625ad.15.1751642426240; Fri, 04 Jul 2025 08:20:26 -0700 (PDT) From: yong.huang@smartx.com To: devel@lists.libvirt.org Subject: [RFC 3/4] util: Add iface argument to virNetDevOpenvswitchAddPort Date: Fri, 4 Jul 2025 22:57:58 +0800 Message-Id: <874213089a231f26c3e0aa2b0310fd1609561c22.1751640926.git.yong.huang@smartx.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: RIRZZXXKMAEE5ADLYWYBDYFPRHW77NHK X-Message-ID-Hash: RIRZZXXKMAEE5ADLYWYBDYFPRHW77NHK X-MailFrom: yong.huang@smartx.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: yong.huang@smartx.com X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1751642556929116600 Content-Type: text/plain; charset="utf-8" From: Hyman Huang Introduce the virNetDevVhostUserIface struct to encapsulate the necessary configuration for attaching a vhostuser port to a bridge. Update the virNetDevOpenvswitchAddPort signature to accept an additional iface argument. Extend the implementation of virNetDevOpenvswitchAddPort to fully support automatic attachment of the vhostuser port. --- src/lxc/lxc_process.c | 3 ++- src/util/virnetdevopenvswitch.c | 36 ++++++++++++++++++++++++++++++++- src/util/virnetdevopenvswitch.h | 10 ++++++++- src/util/virnetdevtap.c | 3 ++- 4 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c index 1bca9e8dae..ad1554fa56 100644 --- a/src/lxc/lxc_process.c +++ b/src/lxc/lxc_process.c @@ -286,7 +286,8 @@ virLXCProcessSetupInterfaceTap(virDomainDef *vm, if (brname) { if (vport && vport->virtPortType =3D=3D VIR_NETDEV_VPORT_PROFILE_O= PENVSWITCH) { if (virNetDevOpenvswitchAddPort(brname, parentVeth, &net->mac,= vm->uuid, - vport, virDomainNetGetActualVl= an(net)) < 0) + vport, virDomainNetGetActualVl= an(net), + NULL) < 0) return NULL; } else { if (virNetDevBridgeAddPort(brname, parentVeth, virDomainNetGet= ActualVlan(net)) < 0) diff --git a/src/util/virnetdevopenvswitch.c b/src/util/virnetdevopenvswitc= h.c index 868d6d26ba..6f6b995fe2 100644 --- a/src/util/virnetdevopenvswitch.c +++ b/src/util/virnetdevopenvswitch.c @@ -119,6 +119,36 @@ virNetDevOpenvswitchConstructVlans(virCommand *cmd, co= nst virNetDevVlan *virtVla } } =20 +/** + * virNetDevOpenvswitchConstructIface: + * @cmd: command to construct + * @ifname: the ovs interface name + * @iface: the configuration of ovs vhost user interface + * + * Construct the ovs vhost user interface configuration + * parameters to be passed to ovs-vsctl command. + * + */ +static void +virNetDevOpenvswitchConstructIface(virCommand *cmd, const char *ifname, + const virNetDevVhostUserIface *iface) +{ + g_autofree char *type_info =3D NULL; + g_autofree char *server_path =3D NULL; + + if (!ifname || !iface) + return; + + type_info =3D g_strdup_printf("type=3D\"%s\"", + iface->client ? "dpdkvhostuserclient" : "dpdkvhostuser"); + server_path =3D g_strdup_printf("options:vhost-server-path=3D\"%s\"", = iface->path); + + virCommandAddArgList(cmd, + "--", "set", "Interface", ifname, type_info, + "--", "set", "Interface", ifname, server_path, + NULL); +} + /** * virNetDevOpenvswitchAddPort: * @brname: the bridge name @@ -126,6 +156,7 @@ virNetDevOpenvswitchConstructVlans(virCommand *cmd, con= st virNetDevVlan *virtVla * @macaddr: the mac address of the virtual interface * @vmuuid: the Domain UUID that has this interface * @ovsport: the ovs specific fields + * @ovsiface: the configuration of ovs vhost user interface * * Add an interface to the OVS bridge * @@ -135,7 +166,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, con= st char *ifname, const virMacAddr *macaddr, const unsigned char *vmuuid, const virNetDevVPortProfile *ovsport, - const virNetDevVlan *virtVlan) + const virNetDevVlan *virtVlan, + const virNetDevVhostUserIface *ovsiface) { char macaddrstr[VIR_MAC_STRING_BUFLEN]; char ifuuidstr[VIR_UUID_STRING_BUFLEN]; @@ -170,6 +202,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, con= st char *ifname, =20 virNetDevOpenvswitchConstructVlans(cmd, virtVlan); =20 + virNetDevOpenvswitchConstructIface(cmd, ifname, ovsiface); + if (ovsport->profileID[0] =3D=3D '\0') { virCommandAddArgList(cmd, "--", "set", "Interface", ifname, attachedmac= _ex_id, diff --git a/src/util/virnetdevopenvswitch.h b/src/util/virnetdevopenvswitc= h.h index 3b4a1e509b..4d5300f7d8 100644 --- a/src/util/virnetdevopenvswitch.h +++ b/src/util/virnetdevopenvswitch.h @@ -27,6 +27,13 @@ =20 #define VIR_NETDEV_OVS_DEFAULT_TIMEOUT 5 =20 +typedef struct _virNetDevVhostUserIface virNetDevVhostUserIface; +typedef virNetDevVhostUserIface *virNetDevVhostUserIfacePtr; +struct _virNetDevVhostUserIface { + bool client; + char *path; /* vhost user path listened by server */ +}; + void virNetDevOpenvswitchSetTimeout(unsigned int timeout); =20 int virNetDevOpenvswitchAddPort(const char *brname, @@ -34,7 +41,8 @@ int virNetDevOpenvswitchAddPort(const char *brname, const virMacAddr *macaddr, const unsigned char *vmuuid, const virNetDevVPortProfile *ovsport, - const virNetDevVlan *virtVlan) + const virNetDevVlan *virtVlan, + const virNetDevVhostUserIface *ovsiface) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) G_GNUC_WARN_UNUSED_RESULT; =20 diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c index b709d76cc7..f0e0c3c16b 100644 --- a/src/util/virnetdevtap.c +++ b/src/util/virnetdevtap.c @@ -479,7 +479,8 @@ virNetDevTapAttachBridge(const char *tapname, return -1; } else if (virtPortProfile->virtPortType =3D=3D VIR_NETDEV_VPORT_P= ROFILE_OPENVSWITCH) { if (virNetDevOpenvswitchAddPort(brname, tapname, macaddr, vmuu= id, - virtPortProfile, virtVlan) < 0) + virtPortProfile, virtVlan, + NULL) < 0) return -1; } } else { --=20 2.27.0 From nobody Sun Dec 14 02:18:19 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=smartx.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1751642588812643.4701623271252; Fri, 4 Jul 2025 08:23:08 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id C50791476; Fri, 4 Jul 2025 11:23:07 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id A7069154D; Fri, 4 Jul 2025 11:20:40 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 58B701443; Fri, 4 Jul 2025 11:20:29 -0400 (EDT) Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id BCB45140D for ; Fri, 4 Jul 2025 11:20:28 -0400 (EDT) Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-23526264386so10458985ad.2 for ; Fri, 04 Jul 2025 08:20:28 -0700 (PDT) Received: from Hyman-Dev-Euler.zelin.local ([45.8.186.102]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23c84350221sm23628205ad.83.2025.07.04.08.20.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Jul 2025 08:20:27 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=smartx-com.20230601.gappssmtp.com; s=20230601; t=1751642428; x=1752247228; darn=lists.libvirt.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=92Pt2wovbBql184ns0bfSnntEXnUQMoEZs0RbaqnT9g=; b=oO36GbHusvTpuIeqIqQyA7tVFwfWAi7bUa/vk5gjKuGlti/Dl8LmMENxw0OZkyN1+g bVDiZAOzNOez0hdllH9PEeQAo69rOWmro1gZAfcJqyYJkOKdOHLmvJ4ZabFXxc+lZk/m tViQSmV0ccr+ZcLFUGoIKyYsPTNofiUINjNLyG+P8kVDIG1fRcURijfjA24PNda2fv+I QX5dEkl0Dh1ehsMoFaM5ONsthjWQzPQpp74PBbCj27m5I/0qKMajixylm1oZl86FadLG Dx8f+3+St4FqhX2J2ovUBuEYt3oYudbc2YJwqZr3D9c6MtzAuXzlaaFW7rslJvWWcNfs Wfjw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751642428; x=1752247228; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=92Pt2wovbBql184ns0bfSnntEXnUQMoEZs0RbaqnT9g=; b=Mq3vaJUDo3wDOJN5KCrVN9RcIIbSUs7nTzmQhHnVy7HELhRLuhxuQ0NHIyv3fat07e pKN13uFDS/RetFzXxi8s556KGyiH+R8Mg3qKj4TYCv806kxhg3Fu2mnePSYKBR69cvmV O4iRwdTRKzjQFpIrwKwd29jVTgzuG2X1z7uDkGnH5n1N6igpCwD7zJPX5zSqipsVfzpt vTc7e2VqhmAPx/GtHvBKJ9GSQ1M+3l6PnevWqrjiEo3NoyA1/ve6gFOM1Az2rWrhtIso UfwnIw1tpC294kDDmf1lQo6xiaPbiXs9xbuumTRZcJow5J02bhfn3pLdx3wI/TY4qHH/ cZQA== X-Gm-Message-State: AOJu0YwhJ4RfxUQVE/uvMRDEN96Raygl4RQlbtyq15EVdbGVX2BWJhT7 2O9f2+hTmYP2Bx98HNkF9h7zeWyogRQYWi5tyS5iP4OzkFyYPtnsiAniaX269/ErtCEgurwwzk6 Votag56735g== X-Gm-Gg: ASbGncve/QKT1Ky4M4PConZBJXX6bnwBdvnk9cCSt6FapNSD/p/WKTRxLtY39v/4Oyc fYx4PVTSouRfFQk+D2dAmLrlTx+nLM8Fq8qQ8RVoN/0oVjdBFyjcaadSqW+5gcgp9Jc0V+lsgDM XrwnsgrC7wjhr10rrDJCOxwo2Ynoy3HEht9X6drH6SauCT8pJNiiQm3o7dxT4LrD3WJAiu0859N FNOvvD95pGlCDmq7kwUq9qwdWWVDkbLL2opsgdG+ScGyd94eJm5gis3SV9E9d7F2roJp1294UuK tE4Mpf2WmdboJLTT/AaH/mMEnvA3igHZl9lpURStwAKZTPPetj68n/V2Dc8hdTG5vCuQLM07j5w DsqWyLXsb X-Google-Smtp-Source: AGHT+IFzgE0NWatQXQgM6vz8RG7lfkxeUFlThQDE7d7Vet0LfkB8msZiZe1Z6Oq6bybDD/lCPXnIaA== X-Received: by 2002:a17:903:1b4d:b0:23a:bc47:381f with SMTP id d9443c01a7336-23c8759dbb3mr42791105ad.36.1751642427705; Fri, 04 Jul 2025 08:20:27 -0700 (PDT) From: yong.huang@smartx.com To: devel@lists.libvirt.org Subject: [RFC 4/4] qemu: Implement automatic attachment of the vhostuser port Date: Fri, 4 Jul 2025 22:57:59 +0800 Message-Id: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-ID-Hash: H2IAONXNRQVPJ7OVJAJPB73ZNNAIQRSJ X-Message-ID-Hash: H2IAONXNRQVPJ7OVJAJPB73ZNNAIQRSJ X-MailFrom: yong.huang@smartx.com X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0 CC: yong.huang@smartx.com X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1751642589024116600 Content-Type: text/plain; charset="utf-8" From: Hyman Huang Add logic for automatic attachment and detachment of the vhostuser port within the vhostuser interface lifecycle. --- src/qemu/qemu_command.c | 3 +++ src/qemu/qemu_hotplug.c | 4 ++++ src/qemu/qemu_interface.c | 46 +++++++++++++++++++++++++++++++++++++++ src/qemu/qemu_interface.h | 3 +++ src/qemu/qemu_process.c | 4 ++++ 5 files changed, 60 insertions(+) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 202f2dfaca..0370749fc7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -8883,6 +8883,9 @@ qemuBuildInterfaceCommandLine(virQEMUDriver *driver, if (qemuInterfaceVhostuserConnect(cmd, net, qemuCaps) < 0) goto cleanup; =20 + if (qemuInterfaceVhostUserAddPort(def, net) < 0) + goto cleanup; + if (net->backend.type !=3D VIR_DOMAIN_NET_BACKEND_PASST && virNetDevOpenvswitchGetVhostuserIfname(net->data.vhostuser->da= ta.nix.path, net->data.vhostuser->da= ta.nix.listen, diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 67a2464ce4..b6a028700c 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1305,6 +1305,10 @@ qemuDomainAttachNetDevice(virQEMUDriver *driver, if (qemuSecuritySetNetdevLabel(driver, vm, net) < 0) goto cleanup; teardownlabel =3D true; + + if (qemuInterfaceVhostUserAddPort(vm->def, net) < 0) + goto cleanup; + break; =20 case VIR_DOMAIN_NET_TYPE_USER: diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index 23a23d201a..8518ddd8bd 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -215,3 +215,49 @@ qemuInterfaceOpenVhostNet(virDomainObj *vm, virDomainAuditNetDevice(vm->def, net, vhostnet_path, vhostfdSize); return 0; } + +/** + * qemuInterfaceVhostUserAddPort: + * @def: domain definition + * @net: network definition + * + * Called *only* called if actualType is VIR_DOMAIN_NET_TYPE_VHOSTUSER + * + * Returns 0 in case of success or -1 on failure + */ +int +qemuInterfaceVhostUserAddPort(virDomainDefPtr def, + virDomainNetDefPtr net) +{ + virDomainChrSourceDefPtr src =3D net->data.vhostuser; + virNetDevVhostUserIface iface =3D { + .client =3D src->data.nix.listen ? true : false, + .path =3D src->data.nix.path, + }; + + if (net->backend.type !=3D VIR_DOMAIN_NET_BACKEND_OPENVSWITCH || + !net->backend.data.openvswitch.autoiface) + return 0; + + if (!net->backend.data.openvswitch.bridge || + !net->backend.data.openvswitch.iface) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("No interface or bridge name found")); + return -1; + } + + if (virNetDevOpenvswitchAddPort(net->backend.data.openvswitch.bridge, + net->backend.data.openvswitch.iface, + &net->mac, def->uuid, + virDomainNetGetActualVirtPortProfile(n= et), + virDomainNetGetActualVlan(net), + &iface) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to attach vhost user port '%1$s' to bridg= e '%2$s'"), + net->backend.data.openvswitch.iface, + net->backend.data.openvswitch.bridge); + return -1; + } + + return 0; +} diff --git a/src/qemu/qemu_interface.h b/src/qemu/qemu_interface.h index d9deca0094..2f8e93b56e 100644 --- a/src/qemu/qemu_interface.h +++ b/src/qemu/qemu_interface.h @@ -37,3 +37,6 @@ int qemuInterfaceOpenVhostNet(virDomainObj *def, =20 int qemuInterfacePrepareSlirp(virQEMUDriver *driver, virDomainNetDef *net); + +int qemuInterfaceVhostUserAddPort(virDomainDefPtr def, + virDomainNetDefPtr net); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 82cab3f76e..c17108fafc 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5885,6 +5885,10 @@ qemuProcessPrepareDomainNetwork(virDomainObj *vm) /* some extra setup of internal data for passt vhostuser m= ode */ qemuPasstPrepareVhostUser(vm, net); } + + if (qemuInterfaceVhostUserAddPort(def, net) < 0) + return -1; + break; =20 case VIR_DOMAIN_NET_TYPE_DIRECT: --=20 2.27.0