From nobody Sun Feb 8 21:33:27 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1685705344; cv=none; d=zohomail.com; s=zohoarc; b=HeMp2sEGF8kfRHbgk8Iy0/uLUHB7qYvpk6x0liilrRurkOkAvuCjvsCJ7uz6p+0tqTb85bHWb/leyQGQSAIVxZK28gLCYG/vuE5r6aak3Fd3xTpUYY7ziSeDHRhyLLl1uQ8zB5Qr9l11fvESdFuU7wGgnKaYuYADSXEp1Vhxjtc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685705344; 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=4FZVDkgRQRnVwrMy5VimAA7HpXiNCF86T9U880Y7qwY=; b=WtrVhLflp4nWl67ydFiSiM+Abmm+l+b2paknSFO5p/Rcx+V4BDG17Tr+mb4uR33oYTRsh71b5JXmXuSgIjB5/KFSbEBUxv3aNzPI3ufhtSCorqqpV7+VHHPJSkuqku+Sq4EN69q58PSTD0IXZ4bqA7TfbE9U9hefYtELKDh0I44= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.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.129.124]) by mx.zohomail.com with SMTPS id 168570534403220.54366859875006; Fri, 2 Jun 2023 04:29:04 -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-119-xRDaVRNmMsKaKMTlmo6tlQ-1; Fri, 02 Jun 2023 07:28:35 -0400 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 227DC1019C87; Fri, 2 Jun 2023 11:28:32 +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 11090492B00; Fri, 2 Jun 2023 11:28:32 +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 83BB01946F09; Fri, 2 Jun 2023 11:28:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 6AE5A1946A46 for ; Fri, 2 Jun 2023 11:28:29 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3F08C8162; Fri, 2 Jun 2023 11:28:29 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id BD89D9E78 for ; Fri, 2 Jun 2023 11:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685705343; 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=4FZVDkgRQRnVwrMy5VimAA7HpXiNCF86T9U880Y7qwY=; b=idG+eo/WOjDxcfh1n6F4SsRqlzdhC76r7x2cCtLL6jY2AXQz4+rxm4l3UHuWFQa4mJxsI/ WynPEuOPsByWrRI2snWhimRlDkLcTLGKTEzexGTQEkvvVyv3jc/XCGubyUMCmIeRoj1g8l nUgUIZ0oMulIvSP5AUAJXOZW2Fhyp+0= X-MC-Unique: xRDaVRNmMsKaKMTlmo6tlQ-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 03/15] virNetDevBandwidthParseRate: Refactor parsing Date: Fri, 2 Jun 2023 13:28:13 +0200 Message-Id: <62d90bc0c1207d450df9bc2db5c695c840aefcec.1685705273.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 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: 1685705344745100003 Content-Type: text/plain; charset="utf-8" Remove the unnecessary check for valid arguments and use virXMLPropULongLong instead of hand-written property parsers. Signed-off-by: Peter Krempa --- src/conf/netdev_bandwidth_conf.c | 89 +++++++++++--------------------- 1 file changed, 29 insertions(+), 60 deletions(-) diff --git a/src/conf/netdev_bandwidth_conf.c b/src/conf/netdev_bandwidth_c= onf.c index 2ac1983dce..f34d7499ae 100644 --- a/src/conf/netdev_bandwidth_conf.c +++ b/src/conf/netdev_bandwidth_conf.c @@ -25,61 +25,46 @@ #define VIR_FROM_THIS VIR_FROM_NONE static int -virNetDevBandwidthParseRate(xmlNodePtr node, virNetDevBandwidthRate *rate) +virNetDevBandwidthParseRate(xmlNodePtr node, + virNetDevBandwidthRate *rate, + bool allowFloor) { - g_autofree char *average =3D NULL; - g_autofree char *peak =3D NULL; - g_autofree char *burst =3D NULL; - g_autofree char *floor =3D NULL; - - if (!node || !rate) { - virReportError(VIR_ERR_INVALID_ARG, "%s", - _("invalid argument supplied")); + int rc_average; + int rc_peak; + int rc_burst; + int rc_floor; + + if ((rc_average =3D virXMLPropULongLong(node, "average", 10, VIR_XML_P= ROP_NONE, + &rate->average)) < 0) return -1; - } - average =3D virXMLPropString(node, "average"); - peak =3D virXMLPropString(node, "peak"); - burst =3D virXMLPropString(node, "burst"); - floor =3D virXMLPropString(node, "floor"); + if ((rc_peak =3D virXMLPropULongLong(node, "peak", 10, VIR_XML_PROP_NO= NE, + &rate->peak)) < 0) + return -1; - if (average) { - if (virStrToLong_ullp(average, NULL, 10, &rate->average) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("could not convert bandwidth average value '%= 1$s'"), - average); - return -1; - } - } else if (!floor) { - virReportError(VIR_ERR_XML_DETAIL, "%s", - _("Missing mandatory average or floor attributes")); + if ((rc_burst =3D virXMLPropULongLong(node, "burst", 10, VIR_XML_PROP_= NONE, + &rate->burst)) < 0) return -1; - } - if ((peak || burst) && !average) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("'peak' and 'burst' require 'average' attribute")= ); + if ((rc_floor =3D virXMLPropULongLong(node, "floor", 10, VIR_XML_PROP_= NONE, + &rate->floor)) < 0) return -1; - } - if (peak && virStrToLong_ullp(peak, NULL, 10, &rate->peak) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("could not convert bandwidth peak value '%1$s'"), - peak); + if (!rc_average && !rc_floor) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("Missing mandatory average or floor attributes")); return -1; } - if (burst && virStrToLong_ullp(burst, NULL, 10, &rate->burst) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("could not convert bandwidth burst value '%1$s'"), - burst); + if ((rc_peak || rc_burst) && !rc_average) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("'peak' and 'burst' require 'average' attribute")= ); return -1; } - if (floor && virStrToLong_ullp(floor, NULL, 10, &rate->floor) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("could not convert bandwidth floor value '%1$s'"), - floor); + if (rc_floor && !allowFloor) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("floor attribute is not supported for this config= ")); return -1; } @@ -157,32 +142,16 @@ virNetDevBandwidthParse(virNetDevBandwidth **bandwidt= h, if (in) { def->in =3D g_new0(virNetDevBandwidthRate, 1); - if (virNetDevBandwidthParseRate(in, def->in) < 0) { - /* helper reported error for us */ - return -1; - } - - if (def->in->floor && !allowFloor) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("floor attribute is not supported for this co= nfig")); + if (virNetDevBandwidthParseRate(in, def->in, allowFloor) < 0) return -1; - } } if (out) { def->out =3D g_new0(virNetDevBandwidthRate, 1); - if (virNetDevBandwidthParseRate(out, def->out) < 0) { - /* helper reported error for us */ - return -1; - } - - if (def->out->floor) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("'floor' attribute allowed " - "only in element")); + /* floor is not allowed for */ + if (virNetDevBandwidthParseRate(out, def->out, false) < 0) return -1; - } } if (def->in || def->out) --=20 2.40.1