From nobody Fri Dec 19 20:13:31 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1673237484; cv=none; d=zohomail.com; s=zohoarc; b=SzHhaOyH5J5OTrISKZaevm67FRMwhBDrDTbf9LMR9fyq2BkLbqi4OWZxYilCQbopk1rwo7aT+ASLr1W9KEYGrabHAG3JOOiFzJ4n1x0Yd/9R+JfSZjr3Jmj7Trm9atF3SJshKKdv81GZa8XBodm1ZxhgGZvWcRHt21BXj7Z4U1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673237484; h=Content-Type:Content-Transfer-Encoding:Cc: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=PJoRiSfzuahMEnDd3Q+aykjkflKgpDkriR8u+v0Dqao=; b=Xw9329crlYHtnKlIBhLiikdEAq5BBX4AnMaxi0ZB/yUPvlsdB9Nik7KlYS+p4pOeYNVTn9OlR1kPbw4tmJdBqkK9M6veswkE0GJNTqH5VwdeL5KIrD1IiXUlz3RmGb7t1GLh7IeUN21xJlvrYcRSGj5fyzLTd/DL5uB9BCIMJZY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1673237484690980.478326512882; Sun, 8 Jan 2023 20:11:24 -0800 (PST) Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-590-kvZZvSGQOOeXdNKG4wPv1Q-1; Sun, 08 Jan 2023 23:11:18 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4CBCD1C05ED0; Mon, 9 Jan 2023 04:11:16 +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 3358C14152F6; Mon, 9 Jan 2023 04:11:16 +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 E734819459E5; Mon, 9 Jan 2023 04:11:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 0A97D1946586 for ; Mon, 9 Jan 2023 04:11:14 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id F25FE1121319; Mon, 9 Jan 2023 04:11:13 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.2.16.67]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF7901121314; Mon, 9 Jan 2023 04:11:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673237483; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc: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=PJoRiSfzuahMEnDd3Q+aykjkflKgpDkriR8u+v0Dqao=; b=eKT29+0PsZW9fa84z9CEea6khFJG/kp1ra4TivZF6EHaHkd1BP+lL/l7+iT556Ci7lDY08 rNojUUrivkTKJQ5kEsWmsIWggKF47qRP/kU2DA3UIz4WD1+f632Tiw4my47QxnxmGDRJwl 4eDQ+/WSDmxFICoXh8cDmhrFFCq/tiM= X-MC-Unique: kvZZvSGQOOeXdNKG4wPv1Q-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH 3/9] conf: put interface parsing/formatting separate functions Date: Sun, 8 Jan 2023 23:11:06 -0500 Message-Id: <20230109041112.368790-4-laine@redhat.com> In-Reply-To: <20230109041112.368790-1-laine@redhat.com> References: <20230109041112.368790-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 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: , Cc: sbrivio@redhat.com, passt-dev@passt.top Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 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: 1673237485288100003 Content-Type: text/plain; charset="utf-8"; x-default="true" In preparation for adding more stuff to . Signed-off-by: Laine Stump Reviewed-by: J=C3=A1n Tomko --- I wanted virDomainNetBackendParseXML to simply take a virDomainNetBackend*, but there is a test case specifically checking to be sure that backend/vhost isn't parsed if the interface isn't virtio. Silently Ignoring+stripping this during parse is arguably the wrong thing to do - either we should log an error on validation, or we should just leave it in (it's only ever used if the interface is virtio), but that's a problem for another day. (Opinions on the proper thing to do are welcome - since it's currently always stripped out on parse, I *think* I could begin checking for it during validation - there is no way that old code could leave the backend/vhost for a non-virtio interface in any domain xml written to disk. Alternately would could just allow it to be parsed and faithfully format it even when the interface isn't virtio, and not log any error.) src/conf/domain_conf.c | 57 +++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 30b0cef131..9502f2ebab 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8970,6 +8970,26 @@ virDomainNetDefParseXMLDriver(virDomainNetDef *def, } =20 =20 +static int +virDomainNetBackendParseXML(xmlNodePtr node, + virDomainNetDef *def) +{ + g_autofree char *tap =3D virXMLPropString(node, "tap"); + g_autofree char *vhost =3D virXMLPropString(node, "vhost"); + + if (tap) + def->backend.tap =3D virFileSanitizePath(tap); + + if (vhost && + def->type !=3D VIR_DOMAIN_NET_TYPE_HOSTDEV && + virDomainNetIsVirtioModel(def)) { + def->backend.vhost =3D virFileSanitizePath(vhost); + } + + return 0; +} + + static int virDomainNetDefParseXMLRequireSource(virDomainNetDef *def, xmlNodePtr source_node) @@ -9016,6 +9036,7 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, xmlNodePtr mac_node =3D NULL; xmlNodePtr target_node =3D NULL; xmlNodePtr coalesce_node =3D NULL; + xmlNodePtr backend_node =3D NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) int rv; g_autofree char *macaddr =3D NULL; @@ -9319,9 +9340,6 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, (virNetDevVlanParse(vlan_node, ctxt, &def->vlan) < 0)) return NULL; =20 - if ((tap =3D virXPathString("string(./backend/@tap)", ctxt))) - def->backend.tap =3D virFileSanitizePath(tap); - if ((mac_node =3D virXPathNode("./mac", ctxt))) { if ((macaddr =3D virXMLPropString(mac_node, "address"))) { if (virMacAddrParse((const char *)macaddr, &def->mac) < 0) { @@ -9376,12 +9394,9 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, if (virDomainNetDefParseXMLDriver(def, ctxt) < 0) return NULL; =20 - if (def->type !=3D VIR_DOMAIN_NET_TYPE_HOSTDEV && - virDomainNetIsVirtioModel(def)) { - g_autofree char *vhost =3D virXPathString("string(./backend/@vhost= )", ctxt); - - if (vhost) - def->backend.vhost =3D virFileSanitizePath(vhost); + if ((backend_node =3D virXPathNode("./backend", ctxt)) && + virDomainNetBackendParseXML(backend_node, def) < 0) { + return NULL; } =20 def->linkstate =3D VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DEFAULT; @@ -23255,6 +23270,21 @@ virDomainNetTeamingInfoFormat(virDomainNetTeamingI= nfo *teaming, } =20 =20 +static void +virDomainNetBackendFormat(virBuffer *buf, + virDomainNetBackend *backend) +{ + + if (!(backend->tap || backend->vhost)) + return; + + virBufferAddLit(buf, "tap); + virBufferEscapeString(buf, " vhost=3D'%s'", backend->vhost); + virBufferAddLit(buf, "/>\n"); +} + + int virDomainNetDefFormat(virBuffer *buf, virDomainNetDef *def, @@ -23555,12 +23585,9 @@ virDomainNetDefFormat(virBuffer *buf, virXMLFormatElement(buf, "driver", &driverAttrBuf, &driverChil= dBuf); } } - if (def->backend.tap || def->backend.vhost) { - virBufferAddLit(buf, "backend.tap); - virBufferEscapeString(buf, " vhost=3D'%s'", def->backend.vhost); - virBufferAddLit(buf, "/>\n"); - } + + virDomainNetBackendFormat(buf, &def->backend); + if (def->filter) { if (virNWFilterFormatParamAttributes(buf, def->filterparams, def->filter) < 0) --=20 2.38.1