From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id AB14A5A026A for ; Mon, 9 Jan 2023 05:11:16 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673237475; h=from:from: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; bh=PJoRiSfzuahMEnDd3Q+aykjkflKgpDkriR8u+v0Dqao=; b=Tujtf0M3rkFzM2E2mt8GqIIksjKA8JZOBMiu/5GiXzqcLtuI4gwv4TQF9AJIqGV7L5CWb8 tLb1aFw3is3NkGUYbR66RzRQ1PcslqQADXcgZbzscZCZC/mUJz86tuB8D+aTnnyARLVHIp zp2t1H7/Up9hAzcU364CdvGOzoBySEg= 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-193-QKgreceyOn-CHWl_lsCFpA-1; Sun, 08 Jan 2023 23:11:14 -0500 X-MC-Unique: QKgreceyOn-CHWl_lsCFpA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EF0211823617 for ; 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) 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-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: YKXAVEYJ2YBE27CWS4YN5AAENCZ7UEH2 X-Message-ID-Hash: YKXAVEYJ2YBE27CWS4YN5AAENCZ7UEH2 X-MailFrom: laine@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: sbrivio@redhat.com, passt-dev@passt.top X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: In preparation for adding more stuff to . Signed-off-by: Laine Stump --- 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, } +static int +virDomainNetBackendParseXML(xmlNodePtr node, + virDomainNetDef *def) +{ + g_autofree char *tap = virXMLPropString(node, "tap"); + g_autofree char *vhost = virXMLPropString(node, "vhost"); + + if (tap) + def->backend.tap = virFileSanitizePath(tap); + + if (vhost && + def->type != VIR_DOMAIN_NET_TYPE_HOSTDEV && + virDomainNetIsVirtioModel(def)) { + def->backend.vhost = virFileSanitizePath(vhost); + } + + return 0; +} + + static int virDomainNetDefParseXMLRequireSource(virDomainNetDef *def, xmlNodePtr source_node) @@ -9016,6 +9036,7 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, xmlNodePtr mac_node = NULL; xmlNodePtr target_node = NULL; xmlNodePtr coalesce_node = NULL; + xmlNodePtr backend_node = NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) int rv; g_autofree char *macaddr = NULL; @@ -9319,9 +9340,6 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, (virNetDevVlanParse(vlan_node, ctxt, &def->vlan) < 0)) return NULL; - if ((tap = virXPathString("string(./backend/@tap)", ctxt))) - def->backend.tap = virFileSanitizePath(tap); - if ((mac_node = virXPathNode("./mac", ctxt))) { if ((macaddr = 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; - if (def->type != VIR_DOMAIN_NET_TYPE_HOSTDEV && - virDomainNetIsVirtioModel(def)) { - g_autofree char *vhost = virXPathString("string(./backend/@vhost)", ctxt); - - if (vhost) - def->backend.vhost = virFileSanitizePath(vhost); + if ((backend_node = virXPathNode("./backend", ctxt)) && + virDomainNetBackendParseXML(backend_node, def) < 0) { + return NULL; } def->linkstate = VIR_DOMAIN_NET_INTERFACE_LINK_STATE_DEFAULT; @@ -23255,6 +23270,21 @@ virDomainNetTeamingInfoFormat(virDomainNetTeamingInfo *teaming, } +static void +virDomainNetBackendFormat(virBuffer *buf, + virDomainNetBackend *backend) +{ + + if (!(backend->tap || backend->vhost)) + return; + + virBufferAddLit(buf, "tap); + virBufferEscapeString(buf, " vhost='%s'", backend->vhost); + virBufferAddLit(buf, "/>\n"); +} + + int virDomainNetDefFormat(virBuffer *buf, virDomainNetDef *def, @@ -23555,12 +23585,9 @@ virDomainNetDefFormat(virBuffer *buf, virXMLFormatElement(buf, "driver", &driverAttrBuf, &driverChildBuf); } } - if (def->backend.tap || def->backend.vhost) { - virBufferAddLit(buf, "backend.tap); - virBufferEscapeString(buf, " vhost='%s'", def->backend.vhost); - virBufferAddLit(buf, "/>\n"); - } + + virDomainNetBackendFormat(buf, &def->backend); + if (def->filter) { if (virNWFilterFormatParamAttributes(buf, def->filterparams, def->filter) < 0) -- 2.38.1