From nobody Mon Feb 9 00:56:39 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=1642772102; cv=none; d=zohomail.com; s=zohoarc; b=AM1BsGLcyTdrC6CPjzdD7o/PT0HiF1OCPgZUkQ5JjTcDrHTuHO7q8KluQ6QgbTsji4U7AG5SFmorHUhy2rmhUoEkRmV3PXjtY7VrtlC2pRJi38Fpz+aq8j5OpTrAK7SqbxzjQFTno/rf/fJlmUfunbzsHiFzHMs0elatjFqyhLY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642772102; 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=ZkLstDFF6SvvTjSnH1GQFrvpIhggXfRq9G+pzYqcPVk=; b=WsKL2E0U3DMb9WBO4HMCkB9hvjULQ8eKh72Qc7Avvr6IhBtVraSEPdmDnWUc+EaWdVJy1KT7zf5d0vo0udcIVTdR+Ha52YKExq1gsNIAc6rj6dYiRzeTufX8i3q9Yk3t/4A/BdH9d8RyBQbo1BmdWylFGneVc4rGlpKFdl9nMcU= 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 1642772102802755.8771659348184; Fri, 21 Jan 2022 05:35:02 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-422-4svoOTh9PwqAAg13wQnIIQ-1; Fri, 21 Jan 2022 08:34:17 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 6AB2146868; Fri, 21 Jan 2022 13:34:12 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2D1931091EE8; Fri, 21 Jan 2022 13:34:12 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id DBE451832DBD; Fri, 21 Jan 2022 13:34:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20LDSXtn012003 for ; Fri, 21 Jan 2022 08:28:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id 193EA1090058; Fri, 21 Jan 2022 13:28:33 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97512109004C for ; Fri, 21 Jan 2022 13:28:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642772101; 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=ZkLstDFF6SvvTjSnH1GQFrvpIhggXfRq9G+pzYqcPVk=; b=GBiPpYMBYr7brkDXaFK5HMt3O1bh725Jbo3TmoyF98zvZyuXHJ7vqhO0J+hGgZ2qEPDzqO YQkupF017RkTQtkk3vn+H6RaJSamDkiQp+djWkY9hL1Ki0Ai7Z2brxKc2cGTtdnCi+Z87l 714AiSagXJkTyeVlR06aPaGDakS1shw= X-MC-Unique: 4svoOTh9PwqAAg13wQnIIQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 10/12] conf: Convert virDomainNetDefParseXML() to virXMLProp*() Date: Fri, 21 Jan 2022 14:28:17 +0100 Message-Id: <9f89b3e6f46820d426dbf8fc9ae14e961477adef.1642771642.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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: 1642772103616100001 Content-Type: text/plain; charset="utf-8" After previous cleanups, the virDomainNetDefParseXML() function uses a mixture of virXMLProp*() and the old virXMLPropString() + virXXXTypeFromString() patterns. Rework it so that virXMLProp*() is used. Signed-off-by: Michal Privoznik --- src/conf/domain_conf.c | 112 ++++++------------ src/conf/domain_conf.h | 4 +- .../qemuxml2argvdata/vhost_queues-invalid.err | 2 +- 3 files changed, 38 insertions(+), 80 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index f4b05b1c21..a25beaee3e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -10225,7 +10225,6 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, virDomainChrSourceReconnectDef reconnect =3D {0}; int rv, val; g_autofree char *macaddr =3D NULL; - g_autofree char *macaddr_type =3D NULL; g_autofree char *network =3D NULL; g_autofree char *portgroup =3D NULL; g_autofree char *portid =3D NULL; @@ -10242,11 +10241,6 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, g_autofree char *localaddr =3D NULL; g_autofree char *localport =3D NULL; g_autofree char *model =3D NULL; - g_autofree char *backend =3D NULL; - g_autofree char *txmode =3D NULL; - g_autofree char *queues =3D NULL; - g_autofree char *rx_queue_size =3D NULL; - g_autofree char *tx_queue_size =3D NULL; g_autofree char *filter =3D NULL; g_autofree char *internal =3D NULL; g_autofree char *mode =3D NULL; @@ -10393,12 +10387,6 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, (virDomainVirtioOptionsParseXML(driver_node, &def->virtio) < 0)) goto error; =20 - backend =3D virXMLPropString(driver_node, "name"); - txmode =3D virXMLPropString(driver_node, "txmode"); - queues =3D virXMLPropString(driver_node, "queues"); - rx_queue_size =3D virXMLPropString(driver_node, "rx_queue_size"); - tx_queue_size =3D virXMLPropString(driver_node, "tx_queue_size"); - if ((filterref_node =3D virXPathNode("./filterref", ctxt))) { filter =3D virXMLPropString(filterref_node, "filter"); filterparams =3D virNWFilterParseParamAttributes(filterref_node); @@ -10446,18 +10434,11 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlop= t, def->mac_generated =3D true; } =20 - if ((macaddr_type =3D virXPathString("string(./mac/@type)", ctxt))) { - int tmp; - - if ((tmp =3D virDomainNetMacTypeTypeFromString(macaddr_type)) <=3D= 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid mac address type value: '%s'. Valid " - "values are \"generated\" and \"static\"."), - macaddr_type); - goto error; - } - def->mac_type =3D tmp; - } + if (virXMLPropEnum(mac_node, "type", + virDomainNetMacTypeTypeFromString, + VIR_XML_PROP_NONZERO, + &def->mac_type) < 0) + goto error; =20 if (virXMLPropTristateBool(mac_node, "check", VIR_XML_PROP_NONE, @@ -10732,28 +10713,18 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlop= t, =20 if (def->type !=3D VIR_DOMAIN_NET_TYPE_HOSTDEV && virDomainNetIsVirtioModel(def)) { - if (backend !=3D NULL) { - if ((val =3D virDomainNetBackendTypeFromString(backend)) < 0 || - val =3D=3D VIR_DOMAIN_NET_BACKEND_TYPE_DEFAULT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown interface " - "has been specified"), - backend); - goto error; - } - def->driver.virtio.name =3D val; - } - if (txmode !=3D NULL) { - if ((val =3D virDomainNetVirtioTxModeTypeFromString(txmode)) <= 0 || - val =3D=3D VIR_DOMAIN_NET_VIRTIO_TX_MODE_DEFAULT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown interface = " - "has been specified"), - txmode); - goto error; - } - def->driver.virtio.txmode =3D val; - } + + if (virXMLPropEnum(driver_node, "name", + virDomainNetBackendTypeFromString, + VIR_XML_PROP_NONZERO, + &def->driver.virtio.name) < 0) + goto error; + + if (virXMLPropEnum(driver_node, "txmode", + virDomainNetVirtioTxModeTypeFromString, + VIR_XML_PROP_NONZERO, + &def->driver.virtio.txmode) < 0) + goto error; =20 if (virXMLPropTristateSwitch(driver_node, "ioeventfd", VIR_XML_PROP_NONE, @@ -10765,37 +10736,24 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlop= t, &def->driver.virtio.event_idx) < 0) goto error; =20 - if (queues) { - unsigned int q; - if (virStrToLong_uip(queues, NULL, 10, &q) < 0) { - virReportError(VIR_ERR_XML_DETAIL, - _("'queues' attribute must be positive numb= er: %s"), - queues); - goto error; - } - if (q > 1) - def->driver.virtio.queues =3D q; - } - if (rx_queue_size) { - unsigned int q; - if (virStrToLong_uip(rx_queue_size, NULL, 10, &q) < 0) { - virReportError(VIR_ERR_XML_DETAIL, - _("'rx_queue_size' attribute must be positi= ve number: %s"), - rx_queue_size); - goto error; - } - def->driver.virtio.rx_queue_size =3D q; - } - if (tx_queue_size) { - unsigned int q; - if (virStrToLong_uip(tx_queue_size, NULL, 10, &q) < 0) { - virReportError(VIR_ERR_XML_DETAIL, - _("'tx_queue_size' attribute must be positi= ve number: %s"), - tx_queue_size); - goto error; - } - def->driver.virtio.tx_queue_size =3D q; - } + if (virXMLPropUInt(driver_node, "queues", 10, + VIR_XML_PROP_NONE, + &def->driver.virtio.queues) < 0) + goto error; + + /* There's always at least one TX/RX queue. */ + if (def->driver.virtio.queues =3D=3D 1) + def->driver.virtio.queues =3D 0; + + if (virXMLPropUInt(driver_node, "rx_queue_size", 10, + VIR_XML_PROP_NONE, + &def->driver.virtio.rx_queue_size) < 0) + goto error; + + if (virXMLPropUInt(driver_node, "tx_queue_size", 10, + VIR_XML_PROP_NONE, + &def->driver.virtio.tx_queue_size) < 0) + goto error; =20 if ((tmpNode =3D virXPathNode("./driver/host", ctxt))) { if (virXMLPropTristateSwitch(tmpNode, "csum", VIR_XML_PROP_NON= E, diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index bbb2f463e2..8a4d7b6f99 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -945,7 +945,7 @@ typedef enum { =20 /* the backend driver used for virtio interfaces */ typedef enum { - VIR_DOMAIN_NET_BACKEND_TYPE_DEFAULT, /* prefer kernel, fall back to us= er */ + VIR_DOMAIN_NET_BACKEND_TYPE_DEFAULT =3D 0, /* prefer kernel, fall back= to user */ VIR_DOMAIN_NET_BACKEND_TYPE_QEMU, /* userland */ VIR_DOMAIN_NET_BACKEND_TYPE_VHOST, /* kernel */ =20 @@ -954,7 +954,7 @@ typedef enum { =20 /* the TX algorithm used for virtio interfaces */ typedef enum { - VIR_DOMAIN_NET_VIRTIO_TX_MODE_DEFAULT, /* default for this version of = qemu */ + VIR_DOMAIN_NET_VIRTIO_TX_MODE_DEFAULT =3D 0, /* default for this versi= on of qemu */ VIR_DOMAIN_NET_VIRTIO_TX_MODE_IOTHREAD, VIR_DOMAIN_NET_VIRTIO_TX_MODE_TIMER, =20 diff --git a/tests/qemuxml2argvdata/vhost_queues-invalid.err b/tests/qemuxm= l2argvdata/vhost_queues-invalid.err index e89358f0a3..10c2c81339 100644 --- a/tests/qemuxml2argvdata/vhost_queues-invalid.err +++ b/tests/qemuxml2argvdata/vhost_queues-invalid.err @@ -1 +1 @@ -'queues' attribute must be positive number: -5 +XML error: Invalid value for attribute 'queues' in element 'driver': '-5'.= Expected non-negative integer value --=20 2.34.1