From nobody Mon Feb 9 15:09:21 2026 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=1698036912; cv=none; d=zohomail.com; s=zohoarc; b=IgUINOW75OelkP/zVf3rRT5ZrsQGFVAB8Q9SZwxuhBEuh9iekZCrpIHsMedJKruVedcWO4uxGoVR3icvL+Dr9VZ7WZnJzVCZQFIKIEaw525SsW71s/vCMBFCQe3nFuZXganyFTYW89JM4p/4kKxZ0m1aWG3xeBr5+gjSbuPKDyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1698036912; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=JkX0ttAmLdvDofBM9RJ7ZyfbKZxw6v2l/TI5aZjphho=; b=njEimcsd2QMxkXHNRq0mqxHlt636wsyWc58eMS+Ox8IVJ8CJxVGSy14cNqU7Om3xL4c1HfFjVQ/I4DFQq+fMA0hxHmKhZ85r/U0yJ4ASWYpJmdz+ccw907h8Tg6hqG4Y1kp2ffv6JPO+s0LTNsQ+zTUEndEHnIyeFr/UYova5xk= 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 1698036912217532.9911811627943; Sun, 22 Oct 2023 21:55:12 -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-56-VQ_qGdOyOj2kiNaOksdknw-1; Mon, 23 Oct 2023 00:55:05 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AE5C288B7BA; Mon, 23 Oct 2023 04:54:59 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 85BC640C6F7E; Mon, 23 Oct 2023 04:54:59 +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 8515F19465B7; Mon, 23 Oct 2023 04:54:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 5160E1946588 for ; Mon, 23 Oct 2023 04:54:54 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 41503C15975; Mon, 23 Oct 2023 04:54:54 +0000 (UTC) Received: from vhost3.router.laine.org (unknown [10.22.8.125]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0AB49C15BB8; Mon, 23 Oct 2023 04:54:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1698036911; 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=JkX0ttAmLdvDofBM9RJ7ZyfbKZxw6v2l/TI5aZjphho=; b=ZV3ZNFQyzBRzBf4JmNxFBizhio7jqrlmcmF8QJZhkU01cQLNyqtqmrC1y9q62vNPkHURVR 0CwS5jqqMgkGTYLm+iobKUGHUY0lPJPoDXrt85mPnnByI4Np33sV6fS/Xhz9N+ofGiUeCC SF4iSUZvxCQMNRfCvaFSmfwlESfwiZc= X-MC-Unique: VQ_qGdOyOj2kiNaOksdknw-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Laine Stump To: libvir-list@redhat.com Subject: [libvirt PATCH 08/15] conf: use new common parser/formatter for hostdev driver in network XML Date: Mon, 23 Oct 2023 00:54:44 -0400 Message-ID: <20231023045451.210711-9-laine@redhat.com> In-Reply-To: <20231023045451.210711-1-laine@redhat.com> References: <20231023045451.210711-1-laine@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 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: Joao Martins , Cedric Le Goater , Jason Gunthorpe Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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: 1698036913292100001 Content-Type: text/plain; charset="utf-8"; x-default="true" Now if a new attribute is added to , we only need to update the formatting/parsing in one place. Signed-off-by: Laine Stump --- src/conf/network_conf.c | 23 ++++------------------- src/conf/virnetworkportdef.c | 20 ++++++-------------- 2 files changed, 10 insertions(+), 33 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index e3ad4c7340..43e7c78e95 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1349,13 +1349,9 @@ virNetworkForwardDefParseXML(const char *networkName, def->managed =3D true; } =20 - if ((driverNode =3D virXPathNode("./driver", ctxt))) { - if (virXMLPropEnum(driverNode, "name", - virDeviceHostdevPCIDriverTypeFromString, - VIR_XML_PROP_NONZERO, - &def->driver.type) < 0) { + if ((driverNode =3D virXPathNode("./driver", ctxt)) && + virDeviceHostdevPCIDriverInfoParseXML(driverNode, &def->driver) < = 0) { return -1; - } } =20 /* bridge and hostdev modes can use a pool of physical interfaces */ @@ -2350,19 +2346,8 @@ virNetworkDefFormatBuf(virBuffer *buf, virBufferAsprintf(buf, "%s>\n", shortforward ? "/" : ""); virBufferAdjustIndent(buf, 2); =20 - if (def->forward.driver.type) { - const char *driverName - =3D virDeviceHostdevPCIDriverTypeToString(def->forward.dri= ver.type); - if (!driverName) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected hostdev driver name type %1$d= "), - def->forward.driver.type); - return -1; - } - virBufferAsprintf(&driverAttrBuf, " name=3D'%s'", driverName); - } - - virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL); + if (virDeviceHostdevPCIDriverInfoFormat(buf, &def->forward.driver) = < 0) + return -1; =20 if (def->forward.type =3D=3D VIR_NETWORK_FORWARD_NAT) { if (virNetworkForwardNatDefFormat(buf, &def->forward) < 0) diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c index 77ef705e18..67911e498e 100644 --- a/src/conf/virnetworkportdef.c +++ b/src/conf/virnetworkportdef.c @@ -224,13 +224,10 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) &def->plug.hostdevpci.managed) < 0) return NULL; =20 - if ((driverNode =3D virXPathNode("./plug/driver", ctxt))) { - if (virXMLPropEnum(driverNode, "name", - virDeviceHostdevPCIDriverTypeFromString, - VIR_XML_PROP_NONZERO, - &def->plug.hostdevpci.driver.type) < 0) { - return NULL; - } + if ((driverNode =3D virXPathNode("./plug/driver", ctxt)) && + virDeviceHostdevPCIDriverInfoParseXML(driverNode, + &def->plug.hostdevpci.dr= iver) < 0) { + return NULL; } =20 if (!(addressNode =3D virXPathNode("./plug/address", ctxt))) { @@ -356,13 +353,8 @@ virNetworkPortDefFormatBuf(virBuffer *buf, virBufferAddLit(buf, ">\n"); virBufferAdjustIndent(buf, 2); =20 - if (def->plug.hostdevpci.driver.type) { - virBufferEscapeString(&driverAttrBuf, " name=3D'%s'", - virDeviceHostdevPCIDriverTypeToStrin= g( - def->plug.hostdevpci.driver.type= )); - } - - virXMLFormatElement(buf, "driver", &driverAttrBuf, NULL); + if (virDeviceHostdevPCIDriverInfoFormat(buf, &def->plug.hostde= vpci.driver) < 0) + return -1; =20 virPCIDeviceAddressFormat(buf, def->plug.hostdevpci.addr, fals= e); virBufferAdjustIndent(buf, -2); --=20 2.41.0