From nobody Fri May 17 10:34:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1618988599; cv=none; d=zohomail.com; s=zohoarc; b=IrXBq06lU7QMza3esN/LpcfIppQQQHS/p0UeF9RK8iwSMAGQKJOj3pFzGgGhhHL4kyy39O/OtOp1Lb2Lq9jwx9FGKYO4g53fWxmU5NVFWJfJgkFUlWnl0iOhQd5z3jAZUYJ1rf7QSKGsGETimVs2QmUAl2Ckh2ozrsVd9sY0bV0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618988599; 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=3v6Z428diWHhubjUDbFf3iJ4ru3zqeuUm7u5kbpAlK8=; b=cOvAgPMZ4jVRVhwGSdT3uPQ9i2AFI/ftHXlGKu4o7gl/n0vQTEpw0dbbWeX5nfm9WdMjMGO4KcbM03e76CkBdoEXU4kOWxJNJWSnlQ4WT5+xoT+to+F1du2WqsRKlpUMcVGpGOVLVQGgZPz5ZvFLfddG0B0HqtMW4SszZaBdELw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618988599338110.1820531505; Wed, 21 Apr 2021 00:03:19 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-525-jh7RMZzNMsmH38rNC7M6IQ-1; Wed, 21 Apr 2021 03:03:15 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 143446D257; Wed, 21 Apr 2021 07:03:09 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 205A55D6A1; Wed, 21 Apr 2021 07:03:07 +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 6AB6544A5B; Wed, 21 Apr 2021 07:03:02 +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 13L6xi7W009253 for ; Wed, 21 Apr 2021 02:59:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4FF3210016FD; Wed, 21 Apr 2021 06:59:44 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC82D10016F4 for ; Wed, 21 Apr 2021 06:59:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618988598; 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=3v6Z428diWHhubjUDbFf3iJ4ru3zqeuUm7u5kbpAlK8=; b=G9qcn2fFdv65EmMrcrx9fJNxmX/OeMNB5D0sYBVGSTtefPF+MkYLXBM2VVWUwx02xO58aT wYHQvDr5UcXSNqwhhZle2sm1Tov+q6saDTO61GZkNUam2DEL3gqmk+RHD6W+zjtMVR/HXK wwTZBb17y/w+NTrGypklG7u5oo0DpY8= X-MC-Unique: jh7RMZzNMsmH38rNC7M6IQ-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 1/2] util: xml: Remove VIR_XML_PROP_WRAPNEGATIVE Date: Wed, 21 Apr 2021 08:59:37 +0200 Message-Id: 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.79 on 10.5.11.15 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) Content-Type: text/plain; charset="utf-8" As I've pointed out in my review, the negative number wrapping for unsigned variables is an anti-feature which should not be promoted in any way. Remove VIR_XML_PROP_WRAPNEGATIVE which would make it more accessible. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/util/virxml.c | 6 +----- src/util/virxml.h | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index d0d9494009..bfb4005e62 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -734,11 +734,7 @@ virXMLPropUInt(xmlNodePtr node, return -1; } - if (flags & VIR_XML_PROP_WRAPNEGATIVE) { - ret =3D virStrToLong_ui(tmp, NULL, base, &val); - } else { - ret =3D virStrToLong_uip(tmp, NULL, base, &val); - } + ret =3D virStrToLong_uip(tmp, NULL, base, &val); if (ret < 0) { virReportError(VIR_ERR_XML_ERROR, diff --git a/src/util/virxml.h b/src/util/virxml.h index 2b40398eee..a8f088fb43 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -38,7 +38,6 @@ typedef enum { VIR_XML_PROP_OPTIONAL =3D 0, /* Attribute may be absent */ VIR_XML_PROP_REQUIRED =3D 1 << 0, /* Attribute may not be absent */ VIR_XML_PROP_NONZERO =3D 1 << 1, /* Attribute may not be zero */ - VIR_XML_PROP_WRAPNEGATIVE =3D 1 << 2, /* Wrap around negative values */ } virXMLPropFlags; --=20 2.30.2 From nobody Fri May 17 10:34:37 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1618988599; cv=none; d=zohomail.com; s=zohoarc; b=FdQSibpcwOiSQ6c2DAZ+WOyee2Et/5lSiKKzYWhO8HDv/Y6H1Rb6SrnJQU8ayXioRQ54I9dU+kV5fOss+u151jM4zDu2Hn//uGf/uJt9HZyWitQeKVz+KgYvSrkwwN46Qi7fVyLqrIb2/wpVIL7ecsYQBLVx7CsloYDXzUcxmyE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618988599; 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=RGEbDkpkQM0QGSVxv375d6H0zVBzWQlgbDHrY9kCrvo=; b=FRAZ4Zh95Ruj5mm6GRfy6853kr/rLDWz7JMUqpUlap6aAtOHrRV3r+pHsknBrrN8LFnL3PGdeuEHt+fcs1XVJVoNnWjvZC/+aUMcQeUgbaKzVXvUkl9CX5hKUQnDFV/yipEdQtvWbm9N5ESjLmB1IEAMUJv4lzoTU5aLoW6gEro= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618988599519543.5059222256539; Wed, 21 Apr 2021 00:03:19 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-567-C66QL9QBPBm1PpxUV_Pxkw-1; Wed, 21 Apr 2021 03:03:16 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 25EEC107B457; Wed, 21 Apr 2021 07:03:09 +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 20A0B19702; Wed, 21 Apr 2021 07:03:07 +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 6A9D31806D16; Wed, 21 Apr 2021 07:03:02 +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 13L6xjVP009262 for ; Wed, 21 Apr 2021 02:59:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 57B0710016FD; Wed, 21 Apr 2021 06:59:45 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id BB8E210016F4 for ; Wed, 21 Apr 2021 06:59:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618988598; 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=RGEbDkpkQM0QGSVxv375d6H0zVBzWQlgbDHrY9kCrvo=; b=Adei3A+xvUKTN2uDxsPL1QqMojSDbDOACaRYhYIw64FIHgN954Dg8BqOlZf3pVhy9Ls259 EUiPE82YGWwovWqoijx3mndWfHxYsuKmdG6IfMeZwiakDRIp9c/qnn8I/cogNUlR9OOHzw J3uzgzAUjqcqeMlagh4NfG7d+5dd1es= X-MC-Unique: C66QL9QBPBm1PpxUV_Pxkw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 2/2] util: xml: Fix confusing semantics of VIR_XML_PROP_OPTIONAL flag Date: Wed, 21 Apr 2021 08:59:38 +0200 Message-Id: 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.23 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) Content-Type: text/plain; charset="utf-8" The new enum helpers use a set of flags to modify their behaviour, but the declared set of flags is semantically confusing: typedef enum { VIR_XML_PROP_OPTIONAL =3D 0, /* Attribute may be absent */ VIR_XML_PROP_REQUIRED =3D 1 << 0, /* Attribute may not be absent */ Since VIR_XML_PROP_OPTIONAL is declared as 0 any other flag shadows it and makes it impossible to detect. The functions are not able to detect a semantic nonsense of VIR_XML_PROP_OPTIONAL | VIR_XML_PROP_REQUIRED and it's a perfectly valid statement for the compilers. In general having two flags to do the same boolean don't make sense and the implementation doesn't fix any shortcomings either. To prevent mistakes, rename VIR_XML_PROP_OPTIONAL to VIR_XML_PROP_NONE, so that there's always an enum value used with the calls but it doesn't imply that the flag makes the property optional when the actual value is 0. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- src/conf/cpu_conf.c | 2 +- src/conf/domain_conf.c | 24 ++++++++++++------------ src/conf/network_conf.c | 2 +- src/util/virxml.h | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index c7bea8ae00..4bd22b8b72 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -435,7 +435,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, } if (virXMLPropEnum(ctxt->node, "check", virCPUCheckTypeFromString, - VIR_XML_PROP_OPTIONAL, &def->check) < 0) + VIR_XML_PROP_NONE, &def->check) < 0) return -1; } diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ac0386a2d1..9a0d1f9285 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9337,28 +9337,28 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, def->device =3D VIR_DOMAIN_DISK_DEVICE_DISK; if (virXMLPropEnum(node, "device", virDomainDiskDeviceTypeFromString, - VIR_XML_PROP_OPTIONAL, &def->device) < 0) + VIR_XML_PROP_NONE, &def->device) < 0) return NULL; if (virXMLPropEnum(node, "model", virDomainDiskModelTypeFromString, - VIR_XML_PROP_OPTIONAL, &def->model) < 0) + VIR_XML_PROP_NONE, &def->model) < 0) return NULL; if (virXMLPropEnum(node, "snapshot", virDomainSnapshotLocationTypeFrom= String, - VIR_XML_PROP_OPTIONAL | VIR_XML_PROP_NONZERO, &def-= >snapshot) < 0) + VIR_XML_PROP_NONZERO, &def->snapshot) < 0) return NULL; - if (virXMLPropTristateBool(node, "rawio", VIR_XML_PROP_OPTIONAL, &def-= >rawio) < 0) + if (virXMLPropTristateBool(node, "rawio", VIR_XML_PROP_NONE, &def->raw= io) < 0) return NULL; if (virXMLPropEnum(node, "sgio", virDomainDeviceSGIOTypeFromString, - VIR_XML_PROP_OPTIONAL | VIR_XML_PROP_NONZERO, &def-= >sgio) < 0) + VIR_XML_PROP_NONZERO, &def->sgio) < 0) return NULL; if ((sourceNode =3D virXPathNode("./source", ctxt))) { if (virXMLPropEnum(sourceNode, "startupPolicy", virDomainStartupPolicyTypeFromString, - VIR_XML_PROP_OPTIONAL | VIR_XML_PROP_NONZERO, + VIR_XML_PROP_NONZERO, &def->startupPolicy) < 0) return NULL; } @@ -9368,19 +9368,19 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, if (virXMLPropEnum(targetNode, "bus", virDomainDiskBusTypeFromString, - VIR_XML_PROP_OPTIONAL | VIR_XML_PROP_NONZERO, + VIR_XML_PROP_NONZERO, &def->bus) < 0) return NULL; if (virXMLPropEnum(targetNode, "tray", virDomainDiskTrayTypeFromSt= ring, - VIR_XML_PROP_OPTIONAL, &def->tray_status) < 0) + VIR_XML_PROP_NONE, &def->tray_status) < 0) return NULL; - if (virXMLPropTristateSwitch(targetNode, "removable", VIR_XML_PROP= _OPTIONAL, + if (virXMLPropTristateSwitch(targetNode, "removable", VIR_XML_PROP= _NONE, &def->removable) < 0) return NULL; - if (virXMLPropUInt(targetNode, "rotation_rate", 10, VIR_XML_PROP_O= PTIONAL, + if (virXMLPropUInt(targetNode, "rotation_rate", 10, VIR_XML_PROP_N= ONE, &def->rotation_rate) < 0) return NULL; } @@ -9391,11 +9391,11 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, } if ((blockioNode =3D virXPathNode("./blockio", ctxt))) { - if (virXMLPropUInt(blockioNode, "logical_block_size", 10, VIR_XML_= PROP_OPTIONAL, + if (virXMLPropUInt(blockioNode, "logical_block_size", 10, VIR_XML_= PROP_NONE, &def->blockio.logical_block_size) < 0) return NULL; - if (virXMLPropUInt(blockioNode, "physical_block_size", 10, VIR_XML= _PROP_OPTIONAL, + if (virXMLPropUInt(blockioNode, "physical_block_size", 10, VIR_XML= _PROP_NONE, &def->blockio.physical_block_size) < 0) return NULL; } diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 17835ac8d3..d6eafa3f57 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -1332,7 +1332,7 @@ virNetworkForwardNatDefParseXML(const char *networkNa= me, return -1; } - if (virXMLPropTristateBool(node, "ipv6", VIR_XML_PROP_OPTIONAL, + if (virXMLPropTristateBool(node, "ipv6", VIR_XML_PROP_NONE, &def->natIPv6) < 0) return -1; diff --git a/src/util/virxml.h b/src/util/virxml.h index a8f088fb43..afb1e085ea 100644 --- a/src/util/virxml.h +++ b/src/util/virxml.h @@ -35,7 +35,7 @@ xmlXPathContextPtr virXMLXPathContextNew(xmlDocPtr xml) typedef enum { - VIR_XML_PROP_OPTIONAL =3D 0, /* Attribute may be absent */ + VIR_XML_PROP_NONE =3D 0, VIR_XML_PROP_REQUIRED =3D 1 << 0, /* Attribute may not be absent */ VIR_XML_PROP_NONZERO =3D 1 << 1, /* Attribute may not be zero */ } virXMLPropFlags; --=20 2.30.2