From nobody Sun May 5 14:10:28 2024 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=1642772050; cv=none; d=zohomail.com; s=zohoarc; b=AfKM+UqflL+sVfDCEIRbzdg5sv+I+mtVg6oMisNg+LjSJfklbv75Rm14NiXbQt5MS80RLXvnG9Dl12jCusz3OIraQLFaO2hRrnDELS4n750PdsDX8mzt+4lUDHE3amMkIfJjP7Q1b5w4Ub+MGSu2BW1ant91ijepXxTLTfIL0s4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642772050; 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=/qj7ZS5omz8JG4tzABl5pAPTeswEKKnHNSaQJl9x8Y4=; b=b/kWIhILV14F2diJIZJ275lIsVz/uPWTNbvS4tfQTd37NcneOJ6iBf0lGLEQrTwq9Ez2EYK6inPLSzOu0v62CQT7tsT+AoAV+lVOfzyTxNvfAY4nYTtK/tZzk1Z/nshwgzMGox40Qg85Lzl1j3RbhtD8FHL9Q3owIUp9ELgcOQM= 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 1642772050443521.6131303814477; Fri, 21 Jan 2022 05:34:10 -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-351-0g9zEOlnMCakMOaC031fSQ-1; Fri, 21 Jan 2022 08:34:06 -0500 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 EFC1D1091DA1; Fri, 21 Jan 2022 13:34:00 +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 CB40727BD1; Fri, 21 Jan 2022 13:34:00 +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 8A4844A700; Fri, 21 Jan 2022 13:34:00 +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 20LDSPtd011932 for ; Fri, 21 Jan 2022 08:28:25 -0500 Received: by smtp.corp.redhat.com (Postfix) id AF8BA1090022; Fri, 21 Jan 2022 13:28:25 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3A71D108F850 for ; Fri, 21 Jan 2022 13:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642772049; 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=/qj7ZS5omz8JG4tzABl5pAPTeswEKKnHNSaQJl9x8Y4=; b=WjmHOmUfQxKmQUDwoUKdXRqLiHdOiOqQix3vFpkPTnRTjQB8z2SRERcV0wKawgAJKjPzCT T59pSRGw6bXL7WN62LCIcKhqybB8vGvdZU/c9b1LcuImC2n1GN6+Lbw17+3WCkVITtFVGl P4qGYrEGz4RhHMkpowiN+R2Yzik/4Ao= X-MC-Unique: 0g9zEOlnMCakMOaC031fSQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 01/12] virxml: Extend virXMLPropU{Int, LongLong}() error message Date: Fri, 21 Jan 2022 14:28:08 +0100 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) X-ZM-MESSAGEID: 1642772051682100001 Content-Type: text/plain; charset="utf-8" In case virXMLPropUInt() or virXMLPropULongLong() meets an attribute with a negative integer the following error message is printed: Invalid value ...: Expected integer value This message is not as good as it could be. Let users know it's a non-negative integer we are expecting. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/util/virxml.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 4b09374107..bb1ae3e305 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -679,7 +679,7 @@ virXMLPropUInt(xmlNodePtr node, =20 if (ret < 0) { virReportError(VIR_ERR_XML_ERROR, - _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected integer value"), + _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected non-negative integer value"), name, node->name, tmp); return -1; } @@ -738,7 +738,7 @@ virXMLPropULongLong(xmlNodePtr node, =20 if (ret < 0) { virReportError(VIR_ERR_XML_ERROR, - _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected integer value"), + _("Invalid value for attribute '%s' in element '%s'= : '%s'. Expected non-negative integer value"), name, node->name, tmp); return -1; } --=20 2.34.1 From nobody Sun May 5 14:10:28 2024 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=1642771958; cv=none; d=zohomail.com; s=zohoarc; b=P6S1P/ytKEfMkUjjth2YKF0EkjN/KT2tDYDM4oifnI6CeRs0YlJzv+EW4kFfEV8Wb/TENA6WhsNh7OZ8vVJtstlsLzjxC/s6vBP2Fp3FGfOc4J3YYESMrXmrlRuWkzUBqVZC3HetrklmJKZODyKzaUV18AwJjIzVmcGMNjk9eD4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642771958; 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=Trhy9ZEmrBMkSNQWA2Kp89LpsHRhzOgD1ej+5ROw6YM=; b=D5r+CjEFLbrLHvJQRW+/gsdrXm6OgcB/0rF43d9+nnzmn/2suauOwJ1ZI9T279XV1IchBSvQj4o7szt2MTMMptYp7aAMGW5JV9NFrk0MGDiDquaj46TbaEucmFikHQsozj012sSJ+hyNN8Um5zSjJd7slEVyQ+/60/7xm4wRHK8= 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 1642771958212225.59998685022515; Fri, 21 Jan 2022 05:32:38 -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-350-Eyk9_TvXOuWA9VWeudo0uw-1; Fri, 21 Jan 2022 08:32:33 -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 30E1A8144E2; Fri, 21 Jan 2022 13:32:28 +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 7C937108F850; Fri, 21 Jan 2022 13:32:25 +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 3B4174BB7C; Fri, 21 Jan 2022 13:32:21 +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 20LDSQtI011940 for ; Fri, 21 Jan 2022 08:28:26 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7FCD11090022; Fri, 21 Jan 2022 13:28:26 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0A538108F850 for ; Fri, 21 Jan 2022 13:28:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642771957; 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=Trhy9ZEmrBMkSNQWA2Kp89LpsHRhzOgD1ej+5ROw6YM=; b=JMXBpDtv1paSaiNxYK9fMnR9PXj579DnDEyTgfxcV4giOL+NblEYIkfooNf1/Vlixm9x4j zpeQX36ESounubmDUzJFh+/ugw6Sp03KtBaCF9j/3EZDJyBSZJ7QDwIAoPr40NLKAb8p2D gheaqQvEU/Xf8HElj6tyCwZkwZ7uio0= X-MC-Unique: Eyk9_TvXOuWA9VWeudo0uw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 02/12] virNetworkPortDefParseXML: Fix a typo in an error message Date: Fri, 21 Jan 2022 14:28:09 +0100 Message-Id: <987cd79609330985ae5bddccdda8b592d0e5b53e.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: 1642771959897100001 Content-Type: text/plain; charset="utf-8" There's a typo in error message that's printed when parsing of fails: "prt" is reported instead of "port". Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/conf/virnetworkportdef.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c index 1ca1eddb5a..c4f5f96392 100644 --- a/src/conf/virnetworkportdef.c +++ b/src/conf/virnetworkportdef.c @@ -186,7 +186,7 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) if (plugtype && (def->plugtype =3D virNetworkPortPlugTypeFromString(plugtype)) < 0= ) { virReportError(VIR_ERR_XML_ERROR, - _("Invalid network prt plug type '%s'"), plugtype); + _("Invalid network port plug type '%s'"), plugtype); } =20 switch (def->plugtype) { --=20 2.34.1 From nobody Sun May 5 14:10:28 2024 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=1642772431; cv=none; d=zohomail.com; s=zohoarc; b=erU3icQ15dpoMV784u6F3qoeYS5xeGYj5Aj71cqVf3yZJiYt15J93kLXuOsM26RLM7qxbVVVQp1We25SwlgzglaxZbuPUykVGMS8x1s2qyfROJWVbNoL7EZKcZCLq1USjyT7desKxtnIUskVdEaB21ZOudJt1lUMHpFVKr8ztPE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642772431; 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=zvLGzup4XBrBpYX38NriuxxM5lWH7Z9YRmu3ogiUnTE=; b=ARwCzbXIq3nx0SJJlVFHMYouY9AXXSLCeKAi3p6WkVcXTo9sEMMDQ6b0mp7TgT0F79AblMwSWiyISlYy8224G/lbhBTEO6Fipj/HjL4etywGrBciWdd6EZoWlreSK+qN8i4pdpyBBeK5hyKQO2is1YzGOqRWeYK9NbXcC+KN3Fs= 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 1642772431075522.970190705359; Fri, 21 Jan 2022 05:40:31 -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-125-ep5iy8QVNYCxy7Z0_E6dIg-1; Fri, 21 Jan 2022 08:40:26 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7F65351084; Fri, 21 Jan 2022 13:40:21 +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 58ABD7E227; Fri, 21 Jan 2022 13:40:21 +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 EC75D4CA9B; Fri, 21 Jan 2022 13:40:20 +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 20LDSRu8011950 for ; Fri, 21 Jan 2022 08:28:27 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4EF451090022; Fri, 21 Jan 2022 13:28:27 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id CD0FF108F850 for ; Fri, 21 Jan 2022 13:28:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642772430; 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=zvLGzup4XBrBpYX38NriuxxM5lWH7Z9YRmu3ogiUnTE=; b=Iz9mDXdRAS0EKHJh76Q5YB5naVwOWaK33jMjzcceq1aQTjnOSeEY1gHIakE8RMlNvjCNx/ ZvgYEDIcDDHy3mZg1VLpvPuG0mcBUOuJuxslwDfSj+lmF92kzqb6OOBTajJPmIYuqWStsG z9iUC10Qs+w0o8Wax/O6TWsKKQAAVyk= X-MC-Unique: ep5iy8QVNYCxy7Z0_E6dIg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 03/12] qemuValidateDomainDeviceDefFS: Use correct enum for fs->multidevs comparison Date: Fri, 21 Jan 2022 14:28:10 +0100 Message-Id: <8b1743d483179d39ec6a426a268bd399f12f9206.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.79 on 10.5.11.11 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: 1642772432825100001 Content-Type: text/plain; charset="utf-8" During validation of a virDomainFSDef QEMU capabilities are check for multidevs support if the FS definition has it enabled. However, the fs->multidevs is really type of virDomainFSMultidevs but is compared against virDomainFSModel enum. Fortunately, both values are the same so no user visible harm done here. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_validate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index ae0ee4e744..24e0866f8c 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -4234,7 +4234,7 @@ qemuValidateDomainDeviceDefFS(virDomainFSDef *fs, _("only supports mount filesystem type")); return -1; } - if (fs->multidevs !=3D VIR_DOMAIN_FS_MODEL_DEFAULT && + if (fs->multidevs !=3D VIR_DOMAIN_FS_MULTIDEVS_DEFAULT && !virQEMUCapsGet(qemuCaps, QEMU_CAPS_FSDEV_MULTIDEVS)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("multidevs is not supported with this QEMU binary= ")); --=20 2.34.1 From nobody Sun May 5 14:10:28 2024 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=1642771975; cv=none; d=zohomail.com; s=zohoarc; b=aYPOWaPqXGZ3FBJ/LOn5xDUZNtjdzTJL8i1HEfuhOJvxO8bbH3JEpoCyfwsOZ0piHe3nEJMToMTA1v/vsn4rkeXF1r7qYpraS9w20m4rlLjWUXYencnn1e8wWp3az18TqiaV5AZilpgT4Q8aURY8UQ6Im7VMUPeQewwvHPSJ1gw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642771975; 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=XKFiLVEnc/qFVMszEFq9mQvCGn4U0BCBdJPCOE1eEm0=; b=QUR1rZxhvTuCqKO5AKEwegWJiAT4hRKC4l1xzE5LzrxhxEFffimg1GtF309vYsr9V+CySI875Iggc5kGHFNgQSWFWZHKlVNMxWiIJjl0sNvtalKB2Q5uHcZEBjfCVLPa2RdDJp/0hUIzxqosa69Up01ky1qdjP4z3gxmUMr4Zs4= 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 1642771975277689.891533391982; Fri, 21 Jan 2022 05:32:55 -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-359-peHyopmLOP-nWy9_7feyrw-1; Fri, 21 Jan 2022 08:32:51 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DE9D1101F006; Fri, 21 Jan 2022 13:32:45 +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 9F3C0798A3; Fri, 21 Jan 2022 13:32:45 +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 5DC651832DBE; Fri, 21 Jan 2022 13:32:45 +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 20LDSSsO011957 for ; Fri, 21 Jan 2022 08:28:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1DD161090033; Fri, 21 Jan 2022 13:28:28 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C83E108F850 for ; Fri, 21 Jan 2022 13:28:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642771974; 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=XKFiLVEnc/qFVMszEFq9mQvCGn4U0BCBdJPCOE1eEm0=; b=XH/aigPthO2rmYGtZEe8FH1dZlTPUpKz80hKzweyuy+PJ276Ai/zEwzDdTIKVxYKtiFxHu Y8fHkgBLFMjaFv9+Ua24AC8TIfGNIra/+QH1D+9LRP6nbi5p8YbCZ1ZBLs6nql/ioNqUkm tCDgN9OZGAs0nkNwfbTD12I2TzuVepY= X-MC-Unique: peHyopmLOP-nWy9_7feyrw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 04/12] qemu: Use virTristateBool instead of virTristateSwitch in a few places Date: Fri, 21 Jan 2022 14:28:11 +0100 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.14 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: 1642771976032100001 Content-Type: text/plain; charset="utf-8" Both @accel2d and @accel3d are parsed as virTristateBool, but in a few places (qemuDeviceVideoGetModel() and qemuValidateDomainDeviceDefVideo()) they are compared to virTristateSwitch enum either directly or via a variable of that type. Clear this confusion by using the correct enum. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_command.c | 8 ++++---- src/qemu/qemu_validate.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 60b4f96e06..99ac44d7f1 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -695,7 +695,7 @@ qemuDeviceVideoGetModel(virQEMUCaps *qemuCaps, { const char *model =3D NULL; bool primaryVga =3D false; - virTristateSwitch accel3d =3D VIR_TRISTATE_SWITCH_ABSENT; + virTristateBool accel3d =3D VIR_TRISTATE_BOOL_ABSENT; =20 *virtio =3D false; *virtioBusSuffix =3D false; @@ -735,7 +735,7 @@ qemuDeviceVideoGetModel(virQEMUCaps *qemuCaps, break; case VIR_DOMAIN_VIDEO_TYPE_VIRTIO: if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_VGA_GL) && - accel3d =3D=3D VIR_TRISTATE_SWITCH_ON) + accel3d =3D=3D VIR_TRISTATE_BOOL_YES) model =3D "virtio-vga-gl"; else model =3D "virtio-vga"; @@ -765,7 +765,7 @@ qemuDeviceVideoGetModel(virQEMUCaps *qemuCaps, break; case VIR_DOMAIN_VIDEO_TYPE_VIRTIO: if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_GL_PCI) = && - accel3d =3D=3D VIR_TRISTATE_SWITCH_ON) + accel3d =3D=3D VIR_TRISTATE_BOOL_YES) model =3D "virtio-gpu-gl"; else model =3D "virtio-gpu"; @@ -4816,7 +4816,7 @@ qemuBuildDeviceVideoCmd(virCommand *cmd, virQEMUCaps *qemuCaps) { const char *model =3D NULL; - virTristateSwitch virgl =3D VIR_TRISTATE_SWITCH_ABSENT; + virTristateBool virgl =3D VIR_TRISTATE_BOOL_ABSENT; bool virtio =3D false; bool virtioBusSuffix =3D false; g_autoptr(virJSONValue) props =3D NULL; diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 24e0866f8c..7eaad3614e 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2489,7 +2489,7 @@ qemuValidateDomainDeviceDefVideo(const virDomainVideo= Def *video, } } =20 - if (video->accel && video->accel->accel2d =3D=3D VIR_TRISTATE_SWITCH_O= N) { + if (video->accel && video->accel->accel2d =3D=3D VIR_TRISTATE_BOOL_YES= ) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("qemu does not support the accel2d setting")); return -1; @@ -2553,7 +2553,7 @@ qemuValidateDomainDeviceDefVideo(const virDomainVideo= Def *video, return -1; } } else if (video->accel) { - if (video->accel->accel3d =3D=3D VIR_TRISTATE_SWITCH_ON && + if (video->accel->accel3d =3D=3D VIR_TRISTATE_BOOL_YES && (video->type !=3D VIR_DOMAIN_VIDEO_TYPE_VIRTIO || !(virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_VIRGL) || virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_GL_PCI) || --=20 2.34.1 From nobody Sun May 5 14:10:28 2024 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=1642772436; cv=none; d=zohomail.com; s=zohoarc; b=kjRSH0qamQXXS3jZTjNz95dcGe05pwn6TtcI0vRgrN6cN27iloyi+pfhV6a/mJrfvyaC6bPEcFG+YDaPas9lrh42yDXdjLdJ1PMZuAjljFz7+LmrHV+X4mvwjl0GBUs699VgpkHpWM2I2C7JOPaMAa0LeetFvEYiCoNim+AEH4E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642772436; 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=heo9J8YsXccglGDHHLRxJE6mwT9AEolJK8HP1QjYdsw=; b=ixHMr8SQNKJYfTIhE2iSB33ZTmtK7ptWYX5iTL363XEHjLgVpuLmqf4i4/O00vVKk51Lc4K5uXlZJtXvXMQf36Vgx2rcV2vs/2VxUyXA1TMOcdOtcGCEyopwre3ZLTSbVfJNwYjkzpXUSoM+YH3FGsxWIm/z06LgUdDg3J6BktQ= 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 16427724360237.627562975067804; Fri, 21 Jan 2022 05:40:36 -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-444-cX-A5cHjPQ62xpR4DlFdGw-1; Fri, 21 Jan 2022 08:40:30 -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 9AD58190B2DB; Fri, 21 Jan 2022 13:40:24 +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 784D91090081; Fri, 21 Jan 2022 13:40:24 +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 468474A7C9; Fri, 21 Jan 2022 13:40:24 +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 20LDSSTv011965 for ; Fri, 21 Jan 2022 08:28:28 -0500 Received: by smtp.corp.redhat.com (Postfix) id E21491090022; Fri, 21 Jan 2022 13:28:28 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C4EB108F850 for ; Fri, 21 Jan 2022 13:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642772435; 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=heo9J8YsXccglGDHHLRxJE6mwT9AEolJK8HP1QjYdsw=; b=W5xfcA37N6XC9Rtam7/dzZfYU/1nH39uffzK9Snz03uqo0P42bwQELbpAvIt5Mq2yUmMhz 6aVglo3RuCM9JRRIIOuKQcuZDaP6XLBiWiOsOm81gOIxmVWm5jcM9v/04xPZE82DAu1Y9x clygBAHOCRHvevuzPhSnlP5AjxJYR+g= X-MC-Unique: cX-A5cHjPQ62xpR4DlFdGw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 05/12] lib: Eliminate use of virTristateSwitchTypeFromString() Date: Fri, 21 Jan 2022 14:28:12 +0100 Message-Id: <4669f86bceb8ec7cd10efb79975d576fae7903a1.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: 1642772437817100001 Content-Type: text/plain; charset="utf-8" There are couple of places (all of them in XML parsing) where virTristateSwitchTypeFromString() is called. Well, the same result can be achieved by virXMLPropTristateSwitch() and on fewer lines. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/conf/cpu_conf.c | 32 +++++------- src/conf/domain_conf.c | 111 ++++++++++++++--------------------------- src/conf/domain_conf.h | 6 +-- src/cpu/cpu_x86.c | 35 ++++++------- 4 files changed, 66 insertions(+), 118 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index fbceac1657..4d61bfd01b 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -323,12 +323,12 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, xmlNodePtr topology =3D NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) int n; + int rv; size_t i; g_autofree char *cpuMode =3D NULL; g_autofree char *fallback =3D NULL; g_autofree char *vendor_id =3D NULL; g_autofree char *tscScaling =3D NULL; - g_autofree char *migratable =3D NULL; g_autofree virHostCPUTscInfo *tsc =3D NULL; =20 *cpu =3D NULL; @@ -394,25 +394,17 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, def->mode =3D VIR_CPU_MODE_CUSTOM; } =20 - if ((migratable =3D virXMLPropString(ctxt->node, "migratable"))) { - int val; - - if (def->mode !=3D VIR_CPU_MODE_HOST_PASSTHROUGH && - def->mode !=3D VIR_CPU_MODE_MAXIMUM) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Attribute migratable is only allowed for " - "'host-passthrough' / 'maximum' CPU mode")); - return -1; - } - - if ((val =3D virTristateSwitchTypeFromString(migratable)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Invalid value in migratable attribute: '%s'"= ), - migratable); - return -1; - } - - def->migratable =3D val; + if ((rv =3D virXMLPropTristateSwitch(ctxt->node, "migratable", + VIR_XML_PROP_NONE, + &def->migratable)) < 0) { + return -1; + } else if (rv > 0 && + def->mode !=3D VIR_CPU_MODE_HOST_PASSTHROUGH && + def->mode !=3D VIR_CPU_MODE_MAXIMUM) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("Attribute migratable is only allowed for " + "'host-passthrough' / 'maximum' CPU mode")); + return -1; } =20 if (def->type =3D=3D VIR_CPU_TYPE_GUEST) { diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 393f9d9478..83212f9c10 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7310,8 +7310,6 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, g_autofree char *rawio =3D NULL; g_autofree char *backendStr =3D NULL; g_autofree char *model =3D NULL; - g_autofree char *display =3D NULL; - g_autofree char *ramfb =3D NULL; =20 /* @managed can be read from the xml document - it is always an * attribute of the toplevel element, no matter what type of @@ -7324,8 +7322,6 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, sgio =3D virXMLPropString(node, "sgio"); rawio =3D virXMLPropString(node, "rawio"); model =3D virXMLPropString(node, "model"); - display =3D virXMLPropString(node, "display"); - ramfb =3D virXMLPropString(node, "ramfb"); =20 /* @type is passed in from the caller rather than read from the * xml document, because it is specified in different places for @@ -7426,23 +7422,15 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, return -1; } =20 - if (display && - (mdevsrc->display =3D virTristateSwitchTypeFromString(display)= ) <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown value '%s' for attribute " - "'display'"), - display); + if (virXMLPropTristateSwitch(node, "display", + VIR_XML_PROP_NONE, + &mdevsrc->display) < 0) return -1; - } =20 - if (ramfb && - (mdevsrc->ramfb =3D virTristateSwitchTypeFromString(ramfb)) <= =3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown value '%s' for attribute " - "'ramfb'"), - ramfb); + if (virXMLPropTristateSwitch(node, "ramfb", + VIR_XML_PROP_NONE, + &mdevsrc->ramfb) < 0) return -1; - } } =20 switch (def->source.subsys.type) { @@ -9924,11 +9912,10 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, if (def->fsdriver =3D=3D VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) { g_autofree char *queue_size =3D virXPathString("string(./driver/@q= ueue)", ctxt); g_autofree char *binary =3D virXPathString("string(./binary/@path)= ", ctxt); - g_autofree char *xattr =3D virXPathString("string(./binary/@xattr)= ", ctxt); g_autofree char *cache =3D virXPathString("string(./binary/cache/@= mode)", ctxt); g_autofree char *sandbox =3D virXPathString("string(./binary/sandb= ox/@mode)", ctxt); - g_autofree char *posix_lock =3D virXPathString("string(./binary/lo= ck/@posix)", ctxt); - g_autofree char *flock =3D virXPathString("string(./binary/lock/@f= lock)", ctxt); + xmlNodePtr binary_node =3D virXPathNode("./binary", ctxt); + xmlNodePtr binary_lock_node =3D virXPathNode("./binary/lock", ctxt= ); int val; =20 if (queue_size && virStrToLong_ull(queue_size, NULL, 10, &def->que= ue_size) < 0) { @@ -9941,14 +9928,20 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, if (binary) def->binary =3D virFileSanitizePath(binary); =20 - if (xattr) { - if ((val =3D virTristateSwitchTypeFromString(xattr)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown xattr value '%s'"), xattr); - goto error; - } - def->xattr =3D val; - } + if (virXMLPropTristateSwitch(binary_node, "xattr", + VIR_XML_PROP_NONE, + &def->xattr) < 0) + goto error; + + if (virXMLPropTristateSwitch(binary_lock_node, "posix", + VIR_XML_PROP_NONE, + &def->posix_lock) < 0) + goto error; + + if (virXMLPropTristateSwitch(binary_lock_node, "flock", + VIR_XML_PROP_NONE, + &def->flock) < 0) + goto error; =20 if (cache) { if ((val =3D virDomainFSCacheModeTypeFromString(cache)) <=3D 0= ) { @@ -9970,23 +9963,6 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, def->sandbox =3D val; } =20 - if (posix_lock) { - if ((val =3D virTristateSwitchTypeFromString(posix_lock)) <=3D= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown posix lock value '%s'"), posix_l= ock); - goto error; - } - def->posix_lock =3D val; - } - - if (flock) { - if ((val =3D virTristateSwitchTypeFromString(flock)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown flock value '%s'"), flock); - goto error; - } - def->flock =3D val; - } } =20 if (source =3D=3D NULL && def->type !=3D VIR_DOMAIN_FS_TYPE_RAM @@ -10309,8 +10285,6 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, g_autofree char *model =3D NULL; g_autofree char *backend =3D NULL; g_autofree char *txmode =3D NULL; - g_autofree char *ioeventfd =3D NULL; - g_autofree char *event_idx =3D NULL; g_autofree char *queues =3D NULL; g_autofree char *rx_queue_size =3D NULL; g_autofree char *tx_queue_size =3D NULL; @@ -10462,8 +10436,6 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, =20 backend =3D virXMLPropString(driver_node, "name"); txmode =3D virXMLPropString(driver_node, "txmode"); - ioeventfd =3D virXMLPropString(driver_node, "ioeventfd"); - event_idx =3D virXMLPropString(driver_node, "event_idx"); 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"); @@ -10828,24 +10800,17 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlop= t, } def->driver.virtio.txmode =3D val; } - if (ioeventfd) { - if ((val =3D virTristateSwitchTypeFromString(ioeventfd)) <=3D = 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown interface ioeventfd mode '%s'"), - ioeventfd); - goto error; - } - def->driver.virtio.ioeventfd =3D val; - } - if (event_idx) { - if ((val =3D virTristateSwitchTypeFromString(event_idx)) <=3D = 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown interface event_idx mode '%s'"), - event_idx); - goto error; - } - def->driver.virtio.event_idx =3D val; - } + + if (virXMLPropTristateSwitch(driver_node, "ioeventfd", + VIR_XML_PROP_NONE, + &def->driver.virtio.ioeventfd) < 0) + goto error; + + if (virXMLPropTristateSwitch(driver_node, "event_idx", + VIR_XML_PROP_NONE, + &def->driver.virtio.event_idx) < 0) + goto error; + if (queues) { unsigned int q; if (virStrToLong_uip(queues, NULL, 10, &q) < 0) { @@ -19112,13 +19077,11 @@ virDomainDefParseMemory(virDomainDef *def, } =20 /* and info about it */ - if ((tmp =3D virXPathString("string(./memory[1]/@dumpCore)", ctxt)) && - (def->mem.dump_core =3D virTristateSwitchTypeFromString(tmp)) <=3D= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Invalid memory core dump attribute value '%s'"),= tmp); + if ((node =3D virXPathNode("./memory[1]", ctxt)) && + virXMLPropTristateSwitch(node, "dumpCore", + VIR_XML_PROP_NONE, + &def->mem.dump_core) < 0) return -1; - } - VIR_FREE(tmp); =20 tmp =3D virXPathString("string(./memoryBacking/source/@type)", ctxt); if (tmp) { diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index e2f35fe20b..dcc8eec5a7 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -272,9 +272,9 @@ struct _virDomainHostdevSubsysSCSI { =20 struct _virDomainHostdevSubsysMediatedDev { int model; /* enum virMediatedDeviceModelType= */ - int display; /* virTristateSwitch */ + virTristateSwitch display; char uuidstr[VIR_UUID_STRING_BUFLEN]; /* mediated device's uuid stri= ng */ - int ramfb; /* virTristateSwitch */ + virTristateSwitch ramfb; }; =20 typedef enum { @@ -2674,7 +2674,7 @@ struct _virDomainMemtune { =20 bool nosharepages; bool locked; - int dump_core; /* enum virTristateSwitch */ + virTristateSwitch dump_core; unsigned long long hard_limit; /* in kibibytes, limit at off_t bytes */ unsigned long long soft_limit; /* in kibibytes, limit at off_t bytes */ unsigned long long min_guarantee; /* in kibibytes, limit at off_t byte= s */ diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index 5cb9caef8a..f9a076dddf 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1444,36 +1444,29 @@ static int x86ModelParseDecode(virCPUx86Model *model, xmlXPathContextPtr ctxt) { - g_autofree char *host =3D NULL; - g_autofree char *guest =3D NULL; - int val; + xmlNodePtr decode_node =3D NULL; + virTristateSwitch decodeHost; + virTristateSwitch decodeGuest; =20 - if ((host =3D virXPathString("string(./decode/@host)", ctxt))) - val =3D virTristateSwitchTypeFromString(host); - else - val =3D VIR_TRISTATE_SWITCH_ABSENT; - - if (val <=3D 0) { + if (!(decode_node =3D virXPathNode("./decode", ctxt))) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid or missing decode/host attribute in CPU = model %s"), + _("missing decode element in CPU model %s"), model->name); return -1; } - model->decodeHost =3D val =3D=3D VIR_TRISTATE_SWITCH_ON; =20 - if ((guest =3D virXPathString("string(./decode/@guest)", ctxt))) - val =3D virTristateSwitchTypeFromString(guest); - else - val =3D VIR_TRISTATE_SWITCH_ABSENT; + if (virXMLPropTristateSwitch(decode_node, "host", + VIR_XML_PROP_REQUIRED, + &decodeHost) < 0) + return -1; =20 - if (val <=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid or missing decode/guest attribute in CPU= model %s"), - model->name); + if (virXMLPropTristateSwitch(decode_node, "guest", + VIR_XML_PROP_REQUIRED, + &decodeGuest) < 0) return -1; - } - model->decodeGuest =3D val =3D=3D VIR_TRISTATE_SWITCH_ON; =20 + virTristateSwitchToBool(decodeHost, &model->decodeHost); + virTristateSwitchToBool(decodeGuest, &model->decodeGuest); return 0; } =20 --=20 2.34.1 From nobody Sun May 5 14:10:28 2024 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=1642771980; cv=none; d=zohomail.com; s=zohoarc; b=CAUjrtpvHvQ2umrFxnG2zWP6zqsE6KT44otYAh2pC6JgUVtcQKtsHaVfxVEUNTRYgr29xry86YzGit8tuyJW4E7xVZIhAYoqsAtuWznukgUdbw5bCxPXB7nebPc5HaZNJMMACrckEwtiHVlvg1k3kqg25NdHh/yadxgEfPpzopA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642771980; 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=PKQn3uuMSRIAT1icy6HXy3CIcYaYz8Auk+hJYh5hTUU=; b=mWdvolRbKkjpYsRM6r/ZWV61unRHhAC7TNpfbTXroM1b3RXeAf8slVSNppbdTiie+lRYVS1VAi1E7wsshgN/PfR+xxv4P4vjj4MCD+IOFDHKcOaKx7U1PhEmt0tMvq8Io4qT5o+7AFrjlfrm9Epg8wXc1koFrO/x7XiFBHbomVM= 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 1642771980538249.92129690803336; Fri, 21 Jan 2022 05:33:00 -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-551-TWo2hcndPbut1pDDUOnCxQ-1; Fri, 21 Jan 2022 08:32:57 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8A530363A9; Fri, 21 Jan 2022 13:32:52 +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 654457DE56; Fri, 21 Jan 2022 13:32:52 +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 25BE71832DC1; Fri, 21 Jan 2022 13:32:52 +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 20LDSTgw011977 for ; Fri, 21 Jan 2022 08:28:29 -0500 Received: by smtp.corp.redhat.com (Postfix) id D9E381090033; Fri, 21 Jan 2022 13:28:29 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3DEDE108F850 for ; Fri, 21 Jan 2022 13:28:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642771979; 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=PKQn3uuMSRIAT1icy6HXy3CIcYaYz8Auk+hJYh5hTUU=; b=fFcPoBRafmGv2yy8rnyupDEnwwLkSuGpEz5LwcE1rW7RziddTFRdG/eDscg31EAXJuwrs2 v6GooACxb2yuA2Yoycq8mbO4O5dxAvyaRGsYCkut5pxSBT247KIScBs8n7GgwjKsnQsDPC nGPGtImApVH7mLcVY/tWn20YSk6ugNo= X-MC-Unique: TWo2hcndPbut1pDDUOnCxQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 06/12] lib: Almost eliminate use of virTristateBoolTypeFromString() Date: Fri, 21 Jan 2022 14:28:13 +0100 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.11 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: 1642771981260100001 Content-Type: text/plain; charset="utf-8" There are couple of places where virTristateBoolTypeFromString() is called. Well, the same result can be achieved by virXMLPropTristateBool() and on fewer lines. Note there are couple of places left untouched because those don't care about error reporting and thus are shorter they way they are now. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/conf/cpu_conf.c | 20 ++-- src/conf/domain_conf.c | 170 ++++++++++++--------------------- src/conf/domain_conf.h | 13 ++- src/conf/network_conf.c | 116 ++++++---------------- src/conf/network_conf.h | 12 +-- src/conf/storage_conf.c | 17 ++-- src/conf/storage_source_conf.c | 14 +-- src/conf/storage_source_conf.h | 2 +- src/conf/virnetworkportdef.c | 31 +++--- src/conf/virnetworkportdef.h | 4 +- src/cpu/cpu_x86.c | 23 ++--- src/qemu/qemu_capabilities.c | 28 ++---- src/qemu/qemu_domain.c | 16 +--- 13 files changed, 157 insertions(+), 309 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 4d61bfd01b..8e61a16919 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -328,7 +328,6 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, g_autofree char *cpuMode =3D NULL; g_autofree char *fallback =3D NULL; g_autofree char *vendor_id =3D NULL; - g_autofree char *tscScaling =3D NULL; g_autofree virHostCPUTscInfo *tsc =3D NULL; =20 *cpu =3D NULL; @@ -427,6 +426,8 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, =20 if (def->type =3D=3D VIR_CPU_TYPE_HOST) { g_autofree char *arch =3D virXPathString("string(./arch[1])", ctxt= ); + xmlNodePtr counter_node =3D NULL; + if (!arch) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing CPU architecture")); @@ -446,7 +447,7 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, return -1; } =20 - if (virXPathBoolean("boolean(./counter[@name=3D'tsc'])", ctxt) > 0= ) { + if ((counter_node =3D virXPathNode("./counter[@name=3D'tsc'])", ct= xt))) { tsc =3D g_new0(virHostCPUTscInfo, 1); =20 if (virXPathULongLong("string(./counter[@name=3D'tsc']/@freque= ncy)", @@ -456,17 +457,10 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, return -1; } =20 - tscScaling =3D virXPathString("string(./counter[@name=3D'tsc']= /@scaling)", - ctxt); - if (tscScaling) { - int scaling =3D virTristateBoolTypeFromString(tscScaling); - if (scaling < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Invalid TSC scaling attribute")); - return -1; - } - tsc->scaling =3D scaling; - } + if (virXMLPropTristateBool(counter_node, "scaling", + VIR_XML_PROP_NONE, + &tsc->scaling) < 0) + return -1; =20 def->tsc =3D g_steal_pointer(&tsc); } diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 83212f9c10..281879b915 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6912,23 +6912,16 @@ virDomainHostdevSubsysPCIDefParseXML(xmlNodePtr nod= e, virDomainHostdevDef *def, unsigned int flags) { - g_autofree char *filtering =3D NULL; xmlNodePtr address =3D NULL; xmlNodePtr origstates =3D NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) =20 ctxt->node =3D node; =20 - if ((filtering =3D virXMLPropString(node, "writeFiltering"))) { - int val; - if ((val =3D virTristateBoolTypeFromString(filtering)) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown pci writeFiltering setting '%s'"), - filtering); - return -1; - } - def->writeFiltering =3D val; - } + if (virXMLPropTristateBool(node, "writeFiltering", + VIR_XML_PROP_NONE, + &def->writeFiltering) < 0) + return -1; =20 if ((address =3D virXPathNode("./address", ctxt)) && virPCIDeviceAddressParseXML(address, &def->source.subsys.u.pci.add= r) < 0) @@ -7305,22 +7298,22 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, virDomainHostdevSubsysSCSI *scsisrc =3D &def->source.subsys.u.scsi; virDomainHostdevSubsysSCSIVHost *scsihostsrc =3D &def->source.subsys.u= .scsi_host; virDomainHostdevSubsysMediatedDev *mdevsrc =3D &def->source.subsys.u.m= dev; - g_autofree char *managed =3D NULL; + virTristateBool managed; g_autofree char *sgio =3D NULL; - g_autofree char *rawio =3D NULL; g_autofree char *backendStr =3D NULL; g_autofree char *model =3D NULL; + int rv; =20 /* @managed can be read from the xml document - it is always an * attribute of the toplevel element, no matter what type of * element that might be (pure hostdev, or higher level device * (e.g. ) with type=3D'hostdev') */ - if ((managed =3D virXMLPropString(node, "managed")) !=3D NULL) - ignore_value(virStringParseYesNo(managed, &def->managed)); + ignore_value(virXMLPropTristateBool(node, "managed", + VIR_XML_PROP_NONE, &managed)); + virTristateBoolToBool(managed, &def->managed); =20 sgio =3D virXMLPropString(node, "sgio"); - rawio =3D virXMLPropString(node, "rawio"); model =3D virXMLPropString(node, "model"); =20 /* @type is passed in from the caller rather than read from the @@ -7373,19 +7366,15 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, } } =20 - if (rawio) { - if (def->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SC= SI) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("rawio is only supported for scsi host device= ")); - return -1; - } - - if ((scsisrc->rawio =3D virTristateBoolTypeFromString(rawio)) <=3D= 0) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown hostdev rawio setting '%s'"), - rawio); - return -1; - } + if ((rv =3D virXMLPropTristateBool(node, "rawio", + VIR_XML_PROP_NONE, + &scsisrc->rawio)) < 0) { + return -1; + } else if (rv > 0 && + def->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE= _SCSI) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("rawio is only supported for scsi host device")); + return -1; } =20 if (def->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV && @@ -10259,6 +10248,7 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, xmlNodePtr vlan_node =3D NULL; xmlNodePtr bandwidth_node =3D NULL; xmlNodePtr tmpNode; + xmlNodePtr mac_node =3D NULL; g_autoptr(GHashTable) filterparams =3D NULL; virDomainActualNetDef *actual =3D NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) @@ -10266,7 +10256,6 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, int rv, val; g_autofree char *macaddr =3D NULL; g_autofree char *macaddr_type =3D NULL; - g_autofree char *macaddr_check =3D NULL; g_autofree char *network =3D NULL; g_autofree char *portgroup =3D NULL; g_autofree char *portid =3D NULL; @@ -10467,7 +10456,9 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlopt, if ((vhost =3D virXPathString("string(./backend/@vhost)", ctxt))) vhost_path =3D virFileSanitizePath(vhost); =20 - if ((macaddr =3D virXPathString("string(./mac/@address)", ctxt))) { + mac_node =3D virXPathNode("./mac", ctxt); + + if ((macaddr =3D virXMLPropString(mac_node, "address"))) { if (virMacAddrParse((const char *)macaddr, &def->mac) < 0) { virReportError(VIR_ERR_XML_ERROR, _("unable to parse mac address '%s'"), @@ -10498,17 +10489,10 @@ virDomainNetDefParseXML(virDomainXMLOption *xmlop= t, def->mac_type =3D tmp; } =20 - if ((macaddr_check =3D virXPathString("string(./mac/@check)", ctxt))) { - int tmpCheck; - - if ((tmpCheck =3D virTristateBoolTypeFromString(macaddr_check)) < = 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid mac address check value: '%s'"), - macaddr_check); - goto error; - } - def->mac_check =3D tmpCheck; - } + if (virXMLPropTristateBool(mac_node, "check", + VIR_XML_PROP_NONE, + &def->mac_check) < 0) + goto error; =20 if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &def->info, flags | VIR_DOMAIN_DEF_PARSE_ALLOW_BOOT @@ -14165,40 +14149,21 @@ static virDomainVideoAccelDef * virDomainVideoAccelDefParseXML(xmlNodePtr node) { g_autofree virDomainVideoAccelDef *def =3D NULL; - int val; - g_autofree char *accel2d =3D NULL; - g_autofree char *accel3d =3D NULL; g_autofree char *rendernode =3D NULL; =20 - accel3d =3D virXMLPropString(node, "accel3d"); - accel2d =3D virXMLPropString(node, "accel2d"); rendernode =3D virXMLPropString(node, "rendernode"); =20 - if (!accel3d && !accel2d && !rendernode) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("missing values for acceleration")); - return NULL; - } - def =3D g_new0(virDomainVideoAccelDef, 1); =20 - if (accel3d) { - if ((val =3D virTristateBoolTypeFromString(accel3d)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown accel3d value '%s'"), accel3d); - return NULL; - } - def->accel3d =3D val; - } + if (virXMLPropTristateBool(node, "accel3d", + VIR_XML_PROP_NONE, + &def->accel3d) < 0) + return NULL; =20 - if (accel2d) { - if ((val =3D virTristateBoolTypeFromString(accel2d)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown accel2d value '%s'"), accel2d); - return NULL; - } - def->accel2d =3D val; - } + if (virXMLPropTristateBool(node, "accel2d", + VIR_XML_PROP_NONE, + &def->accel2d) < 0) + return NULL; =20 if (rendernode) def->rendernode =3D virFileSanitizePath(rendernode); @@ -14633,20 +14598,13 @@ virDomainEventActionParseXML(xmlXPathContextPtr c= txt, static int virDomainPMStateParseXML(xmlXPathContextPtr ctxt, const char *xpath, - int *val) + virTristateBool *val) { - g_autofree char *tmp =3D virXPathString(xpath, ctxt); + xmlNodePtr node =3D virXPathNode(xpath, ctxt); =20 - if (tmp) { - *val =3D virTristateBoolTypeFromString(tmp); - if (*val < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown PM state value %s"), tmp); - return -1; - } - } - - return 0; + return virXMLPropTristateBool(node, "enabled", + VIR_XML_PROP_NONE, + val); } =20 =20 @@ -16972,18 +16930,14 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, } =20 if ((node =3D virXPathNode("./os/bootmenu[1]", ctxt))) { - tmp =3D virXMLPropString(node, "enable"); - if (tmp) { - def->os.bootmenu =3D virTristateBoolTypeFromString(tmp); - if (def->os.bootmenu <=3D 0) { - /* In order not to break misconfigured machines, this - * should not emit an error, but rather set the bootmenu - * to disabled */ - VIR_WARN("disabling bootmenu due to unknown option '%s'", - tmp); - def->os.bootmenu =3D VIR_TRISTATE_BOOL_NO; - } - VIR_FREE(tmp); + if (virXMLPropTristateBool(node, "enable", + VIR_XML_PROP_NONE, + &def->os.bootmenu) < 0) { + /* In order not to break misconfigured machines, this + * should not emit an error, but rather set the bootmenu + * to disabled */ + VIR_WARN("disabling bootmenu due to unknown option"); + def->os.bootmenu =3D VIR_TRISTATE_BOOL_NO; } =20 tmp =3D virXMLPropString(node, "timeout"); @@ -18388,26 +18342,21 @@ virDomainDefParseBootFirmwareOptions(virDomainDef= *def, features =3D g_new0(int, VIR_DOMAIN_OS_DEF_FIRMWARE_FEATURE_LAST); =20 for (i =3D 0; i < n; i++) { - g_autofree char *name =3D virXMLPropString(nodes[i], "name"); - g_autofree char *enabled =3D virXMLPropString(nodes[i], "enabled"); - int feature =3D virDomainOsDefFirmwareFeatureTypeFromString(name); - int val =3D virTristateBoolTypeFromString(enabled); + unsigned int feature; + virTristateBool enabled; =20 - if (feature < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid firmware feature name '%s'"), - name); + if (virXMLPropEnum(nodes[i], "name", + virDomainOsDefFirmwareFeatureTypeFromString, + VIR_XML_PROP_REQUIRED, + &feature) < 0) return -1; - } =20 - if (val < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid firmware feature enabled value '%s'"= ), - enabled); + if (virXMLPropTristateBool(nodes[i], "enabled", + VIR_XML_PROP_REQUIRED, + &enabled) < 0) return -1; - } =20 - features[feature] =3D val; + features[feature] =3D enabled; } =20 def->os.firmwareFeatures =3D g_steal_pointer(&features); @@ -19523,12 +19472,12 @@ virDomainDefLifecycleParse(virDomainDef *def, return -1; =20 if (virDomainPMStateParseXML(ctxt, - "string(./pm/suspend-to-mem/@enabled)", + "./pm/suspend-to-mem", &def->pm.s3) < 0) return -1; =20 if (virDomainPMStateParseXML(ctxt, - "string(./pm/suspend-to-disk/@enabled)", + "./pm/suspend-to-disk", &def->pm.s4) < 0) return -1; =20 @@ -30565,6 +30514,7 @@ virDomainNetDefActualFromNetworkPort(virDomainNetDe= f *iface, break; case VIR_TRISTATE_BOOL_ABSENT: case VIR_TRISTATE_BOOL_NO: + case VIR_TRISTATE_BOOL_LAST: actual->data.hostdev.def.managed =3D false; break; } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index dcc8eec5a7..c2c263dfab 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -263,7 +263,7 @@ struct _virDomainHostdevSubsysSCSIiSCSI { struct _virDomainHostdevSubsysSCSI { int protocol; /* enum virDomainHostdevSCSIProtocolType */ int sgio; /* enum virDomainDeviceSGIO */ - int rawio; /* enum virTristateBool */ + virTristateBool rawio; union { virDomainHostdevSubsysSCSIHost host; virDomainHostdevSubsysSCSIiSCSI iscsi; @@ -1706,8 +1706,8 @@ typedef enum { VIR_ENUM_DECL(virDomainVideoVGAConf); =20 struct _virDomainVideoAccelDef { - int accel2d; /* enum virTristateBool */ - int accel3d; /* enum virTristateBool */ + virTristateBool accel2d; + virTristateBool accel3d; char *rendernode; }; =20 @@ -2325,7 +2325,7 @@ struct _virDomainOSDef { char *machine; size_t nBootDevs; int bootDevs[VIR_DOMAIN_BOOT_LAST]; - int bootmenu; /* enum virTristateBool */ + virTristateBool bootmenu; unsigned int bm_timeout; bool bm_timeout_set; char *init; @@ -2688,9 +2688,8 @@ struct _virDomainMemtune { }; =20 struct _virDomainPowerManagement { - /* These options are of type enum virTristateBool */ - int s3; - int s4; + virTristateBool s3; + virTristateBool s4; }; =20 struct _virDomainPerfDef { diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index 681273a547..10d3330fdf 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -928,37 +928,21 @@ virNetworkDNSDefParseXML(const char *networkName, g_autofree xmlNodePtr *srvNodes =3D NULL; g_autofree xmlNodePtr *txtNodes =3D NULL; g_autofree xmlNodePtr *fwdNodes =3D NULL; - g_autofree char *forwardPlainNames =3D NULL; - g_autofree char *enable =3D NULL; int nhosts, nsrvs, ntxts, nfwds; size_t i; VIR_XPATH_NODE_AUTORESTORE(ctxt) =20 ctxt->node =3D node; =20 - enable =3D virXPathString("string(./@enable)", ctxt); - if (enable) { - def->enable =3D virTristateBoolTypeFromString(enable); - if (def->enable <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid dns enable setting '%s' " - "in network '%s'"), - enable, networkName); - return -1; - } - } + if (virXMLPropTristateBool(node, "enable", + VIR_XML_PROP_NONE, + &def->enable) < 0) + return -1; =20 - forwardPlainNames =3D virXPathString("string(./@forwardPlainNames)", c= txt); - if (forwardPlainNames) { - def->forwardPlainNames =3D virTristateBoolTypeFromString(forwardPl= ainNames); - if (def->forwardPlainNames <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid dns forwardPlainNames setting '%s' " - "in network '%s'"), - forwardPlainNames, networkName); - return -1; - } - } + if (virXMLPropTristateBool(node, "forwardPlainNames", + VIR_XML_PROP_NONE, + &def->forwardPlainNames) < 0) + return -1; =20 nfwds =3D virXPathNodeSet("./forwarder", ctxt, &fwdNodes); if (nfwds < 0) { @@ -1076,7 +1060,6 @@ virNetworkIPDefParseXML(const char *networkName, xmlNodePtr dhcp; g_autofree char *address =3D NULL; g_autofree char *netmask =3D NULL; - g_autofree char *localPtr =3D NULL; unsigned long prefix =3D 0; int prefixRc; int ret =3D -1; @@ -1121,16 +1104,10 @@ virNetworkIPDefParseXML(const char *networkName, else def->prefix =3D prefix; =20 - localPtr =3D virXPathString("string(./@localPtr)", ctxt); - if (localPtr) { - def->localPTR =3D virTristateBoolTypeFromString(localPtr); - if (def->localPTR <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid localPtr value '%s' in network '%s'"= ), - localPtr, networkName); - goto cleanup; - } - } + if (virXMLPropTristateBool(node, "localPtr", + VIR_XML_PROP_NONE, + &def->localPTR) < 0) + goto cleanup; =20 /* validate address, etc. for each family */ if ((def->family =3D=3D NULL) || (STREQ(def->family, "ipv4"))) { @@ -1217,19 +1194,11 @@ int virNetworkPortOptionsParseXML(xmlXPathContextPtr ctxt, virTristateBool *isolatedPort) { - g_autofree char *str =3D NULL; - int tmp =3D VIR_TRISTATE_BOOL_ABSENT; + xmlNodePtr port_node =3D virXPathNode("./port", ctxt); =20 - if ((str =3D virXPathString("string(./port/@isolated)", ctxt))) { - if ((tmp =3D virTristateBoolTypeFromString(str)) <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown port isolated value '%s'"), str); - return -1; - } - } - - *isolatedPort =3D tmp; - return 0; + return virXMLPropTristateBool(port_node, "isolated", + VIR_XML_PROP_NONE, + isolatedPort); } =20 =20 @@ -1248,7 +1217,6 @@ virNetworkPortGroupParseXML(virPortGroupDef *def, xmlNodePtr vlanNode; xmlNodePtr bandwidth_node; g_autofree char *isDefault =3D NULL; - g_autofree char *trustGuestRxFilters =3D NULL; =20 int ret =3D -1; =20 @@ -1265,17 +1233,10 @@ virNetworkPortGroupParseXML(virPortGroupDef *def, isDefault =3D virXPathString("string(./@default)", ctxt); def->isDefault =3D isDefault && STRCASEEQ(isDefault, "yes"); =20 - trustGuestRxFilters - =3D virXPathString("string(./@trustGuestRxFilters)", ctxt); - if (trustGuestRxFilters) { - if ((def->trustGuestRxFilters - =3D virTristateBoolTypeFromString(trustGuestRxFilters)) <=3D = 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid trustGuestRxFilters setting '%s' " - "in portgroup"), trustGuestRxFilters); - goto cleanup; - } - } + if (virXMLPropTristateBool(node, "trustGuestRxFilters", + VIR_XML_PROP_NONE, + &def->trustGuestRxFilters) < 0) + goto cleanup; =20 virtPortNode =3D virXPathNode("./virtualport", ctxt); if (virtPortNode && @@ -1662,7 +1623,6 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt, { g_autoptr(virNetworkDef) def =3D NULL; g_autofree char *uuid =3D NULL; - g_autofree char *localOnly =3D NULL; g_autofree char *stp =3D NULL; g_autofree char *stpDelay =3D NULL; g_autofree char *macTableManager =3D NULL; @@ -1676,11 +1636,11 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt, xmlNodePtr virtPortNode =3D NULL; xmlNodePtr forwardNode =3D NULL; g_autofree char *ipv6nogwStr =3D NULL; - g_autofree char *trustGuestRxFilters =3D NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) xmlNodePtr bandwidthNode =3D NULL; xmlNodePtr vlanNode; xmlNodePtr metadataNode =3D NULL; + xmlNodePtr domain_node =3D NULL; =20 def =3D g_new0(virNetworkDef, 1); =20 @@ -1724,32 +1684,18 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt, } } =20 - trustGuestRxFilters - =3D virXPathString("string(./@trustGuestRxFilters)", ctxt); - if (trustGuestRxFilters) { - if ((def->trustGuestRxFilters - =3D virTristateBoolTypeFromString(trustGuestRxFilters)) <=3D = 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid trustGuestRxFilters setting '%s' " - "in network '%s'"), - trustGuestRxFilters, def->name); - return NULL; - } - } + if (virXMLPropTristateBool(ctxt->node, "trustGuestRxFilters", + VIR_XML_PROP_NONE, + &def->trustGuestRxFilters) < 0) + return NULL; =20 /* Parse network domain information */ - def->domain =3D virXPathString("string(./domain[1]/@name)", ctxt); - localOnly =3D virXPathString("string(./domain[1]/@localOnly)", ctxt); - if (localOnly) { - def->domainLocalOnly =3D virTristateBoolTypeFromString(localOnly); - if (def->domainLocalOnly <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid domain localOnly setting '%s' " - "in network '%s'"), - localOnly, def->name); - return NULL; - } - } + domain_node =3D virXPathNode("./domain[1]", ctxt); + def->domain =3D virXMLPropString(domain_node, "name"); + if (virXMLPropTristateBool(domain_node, "localOnly", + VIR_XML_PROP_NONE, + &def->domainLocalOnly) < 0) + return NULL; =20 if ((bandwidthNode =3D virXPathNode("./bandwidth", ctxt)) && virNetDevBandwidthParse(&def->bandwidth, NULL, bandwidthNode, fals= e) < 0) diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h index cf24c8e268..b374bbba48 100644 --- a/src/conf/network_conf.h +++ b/src/conf/network_conf.h @@ -158,8 +158,8 @@ struct _virNetworkDNSForwarder { =20 typedef struct _virNetworkDNSDef virNetworkDNSDef; struct _virNetworkDNSDef { - int enable; /* enum virTristateBool */ - int forwardPlainNames; /* enum virTristateBool */ + virTristateBool enable; + virTristateBool forwardPlainNames; size_t ntxts; virNetworkDNSTxtDef *txts; size_t nhosts; @@ -184,7 +184,7 @@ struct _virNetworkIPDef { unsigned int prefix; /* ipv6 - only prefix allowed */ virSocketAddr netmask; /* ipv4 - either netmask or prefix specifi= ed */ =20 - int localPTR; /* virTristateBool */ + virTristateBool localPTR; =20 size_t nranges; /* Zero or more dhcp ranges */ virNetworkDHCPRangeDef *ranges; @@ -243,7 +243,7 @@ struct _virPortGroupDef { virNetDevVPortProfile *virtPortProfile; virNetDevBandwidth *bandwidth; virNetDevVlan vlan; - int trustGuestRxFilters; /* enum virTristateBool */ + virTristateBool trustGuestRxFilters; }; =20 typedef struct _virNetworkDef virNetworkDef; @@ -257,7 +257,7 @@ struct _virNetworkDef { char *bridgeZone; /* name of firewalld zone for bridge */ int macTableManager; /* enum virNetworkBridgeMACTableManager */ char *domain; - int domainLocalOnly; /* enum virTristateBool: yes disables dns forward= ing */ + virTristateBool domainLocalOnly; /* yes disables dns forwarding */ unsigned long delay; /* Bridge forward delay (ms) */ bool stp; /* Spanning tree protocol */ unsigned int mtu; /* MTU for bridge, 0 means "default" i.e. unset in c= onfig */ @@ -284,7 +284,7 @@ struct _virNetworkDef { virPortGroupDef *portGroups; virNetDevBandwidth *bandwidth; virNetDevVlan vlan; - int trustGuestRxFilters; /* enum virTristateBool */ + virTristateBool trustGuestRxFilters; virTristateBool isolatedPort; =20 /* Application-specific custom metadata */ diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c index 6690d26ffd..85260431e7 100644 --- a/src/conf/storage_conf.c +++ b/src/conf/storage_conf.c @@ -804,22 +804,21 @@ static int virStoragePoolDefParseFeatures(virStoragePoolDef *def, xmlXPathContextPtr ctxt) { - g_autofree char *cow =3D virXPathString("string(./features/cow/@state)= ", ctxt); + xmlNodePtr node =3D virXPathNode("./features/cow", ctxt); + virTristateBool val; + int rv; =20 - if (cow) { - int val; + if ((rv =3D virXMLPropTristateBool(node, "state", + VIR_XML_PROP_NONE, + &val)) < 0) { + return -1; + } else if (rv > 0) { if (def->type !=3D VIR_STORAGE_POOL_FS && def->type !=3D VIR_STORAGE_POOL_DIR) { virReportError(VIR_ERR_NO_SUPPORT, "%s", _("cow feature may only be used for 'fs' and 'd= ir' pools")); return -1; } - if ((val =3D virTristateBoolTypeFromString(cow)) <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid storage pool cow feature state '%s'"= ), - cow); - return -1; - } def->features.cow =3D val; } =20 diff --git a/src/conf/storage_source_conf.c b/src/conf/storage_source_conf.c index d42f715f26..851a2da877 100644 --- a/src/conf/storage_source_conf.c +++ b/src/conf/storage_source_conf.c @@ -322,24 +322,16 @@ virStoragePRDefParseXML(xmlXPathContextPtr ctxt) { virStoragePRDef *prd; virStoragePRDef *ret =3D NULL; - g_autofree char *managed =3D NULL; g_autofree char *type =3D NULL; g_autofree char *path =3D NULL; g_autofree char *mode =3D NULL; =20 prd =3D g_new0(virStoragePRDef, 1); =20 - if (!(managed =3D virXPathString("string(./@managed)", ctxt))) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing @managed attribute for ")= ); + if (virXMLPropTristateBool(ctxt->node, "managed", + VIR_XML_PROP_REQUIRED, + &prd->managed) < 0) goto cleanup; - } - - if ((prd->managed =3D virTristateBoolTypeFromString(managed)) <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid value for 'managed': %s"), managed); - goto cleanup; - } =20 type =3D virXPathString("string(./source[1]/@type)", ctxt); path =3D virXPathString("string(./source[1]/@path)", ctxt); diff --git a/src/conf/storage_source_conf.h b/src/conf/storage_source_conf.h index c4a026881c..c720d093be 100644 --- a/src/conf/storage_source_conf.h +++ b/src/conf/storage_source_conf.h @@ -226,7 +226,7 @@ struct _virStorageAuthDef { =20 typedef struct _virStoragePRDef virStoragePRDef; struct _virStoragePRDef { - int managed; /* enum virTristateBool */ + virTristateBool managed; char *path; =20 /* manager object alias */ diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c index c4f5f96392..1d75436085 100644 --- a/src/conf/virnetworkportdef.c +++ b/src/conf/virnetworkportdef.c @@ -87,12 +87,12 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) xmlNodePtr vlanNode; xmlNodePtr bandwidthNode; xmlNodePtr addressNode; - g_autofree char *trustGuestRxFilters =3D NULL; + xmlNodePtr rxfiltersNode =3D NULL; + xmlNodePtr plugNode =3D NULL; g_autofree char *mac =3D NULL; g_autofree char *macmgr =3D NULL; g_autofree char *mode =3D NULL; g_autofree char *plugtype =3D NULL; - g_autofree char *managed =3D NULL; g_autofree char *driver =3D NULL; =20 def =3D g_new0(virNetworkPortDef, 1); @@ -169,18 +169,13 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) if (virNetworkPortOptionsParseXML(ctxt, &def->isolatedPort) < 0) return NULL; =20 - trustGuestRxFilters - =3D virXPathString("string(./rxfilters/@trustGuest)", ctxt); - if (trustGuestRxFilters) { - if ((def->trustGuestRxFilters - =3D virTristateBoolTypeFromString(trustGuestRxFilters)) <=3D = 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid guest rx filters trust setting '%s' = "), - trustGuestRxFilters); - return NULL; - } - } + rxfiltersNode =3D virXPathNode("./rxfilters", ctxt); + if (virXMLPropTristateBool(rxfiltersNode, "trustGuest", + VIR_XML_PROP_NONE, + &def->trustGuestRxFilters) < 0) + return NULL; =20 + plugNode =3D virXPathNode("./plug", ctxt); plugtype =3D virXPathString("string(./plug/@type)", ctxt); =20 if (plugtype && @@ -228,14 +223,10 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) break; =20 case VIR_NETWORK_PORT_PLUG_TYPE_HOSTDEV_PCI: - managed =3D virXPathString("string(./plug/@managed)", ctxt); - if (managed && - (def->plug.hostdevpci.managed =3D - virTristateBoolTypeFromString(managed)) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid managed setting '%s' in network port= "), mode); + if (virXMLPropTristateBool(plugNode, "managed", + VIR_XML_PROP_NONE, + &def->plug.hostdevpci.managed) < 0) return NULL; - } driver =3D virXPathString("string(./plug/driver/@name)", ctxt); if (driver && (def->plug.hostdevpci.driver =3D diff --git a/src/conf/virnetworkportdef.h b/src/conf/virnetworkportdef.h index 5c7cd2953e..c6474c4ad8 100644 --- a/src/conf/virnetworkportdef.h +++ b/src/conf/virnetworkportdef.h @@ -55,7 +55,7 @@ struct _virNetworkPortDef { virNetDevBandwidth *bandwidth; unsigned int class_id; /* class ID for bandwidth 'floor' */ virNetDevVlan vlan; - int trustGuestRxFilters; /* enum virTristateBool */ + virTristateBool trustGuestRxFilters; virTristateBool isolatedPort; =20 int plugtype; /* virNetworkPortPlugType */ @@ -71,7 +71,7 @@ struct _virNetworkPortDef { struct { virPCIDeviceAddress addr; /* PCI Address of device */ int driver; /* virNetworkForwardDriverNameType */ - int managed; + virTristateBool managed; } hostdevpci; } plug; }; diff --git a/src/cpu/cpu_x86.c b/src/cpu/cpu_x86.c index f9a076dddf..9826ec6190 100644 --- a/src/cpu/cpu_x86.c +++ b/src/cpu/cpu_x86.c @@ -1603,8 +1603,8 @@ x86ModelParseFeatures(virCPUx86Model *model, =20 for (i =3D 0; i < n; i++) { g_autofree char *ftname =3D NULL; - g_autofree char *removed =3D NULL; virCPUx86Feature *feature; + virTristateBool rem; =20 if (!(ftname =3D virXMLPropString(nodes[i], "name"))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1620,21 +1620,14 @@ x86ModelParseFeatures(virCPUx86Model *model, return -1; } =20 - if ((removed =3D virXMLPropString(nodes[i], "removed"))) { - int rem; + if (virXMLPropTristateBool(nodes[i], "removed", + VIR_XML_PROP_NONE, + &rem) < 0) + return -1; =20 - if ((rem =3D virTristateBoolTypeFromString(removed)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid 'removed' attribute for feature = %s " - "in model %s"), - ftname, model->name); - return -1; - } - - if (rem =3D=3D VIR_TRISTATE_BOOL_YES) { - model->removedFeatures[nremoved++] =3D g_strdup(ftname); - continue; - } + if (rem =3D=3D VIR_TRISTATE_BOOL_YES) { + model->removedFeatures[nremoved++] =3D g_strdup(ftname); + continue; } =20 if (x86DataAdd(&model->data, &feature->data)) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index ea35948b01..461a818776 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -3758,7 +3758,6 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *cap= s, xmlXPathContextPtr ctxt, const char *typeStr) { - g_autofree char *migratability =3D NULL; xmlNodePtr hostCPUNode; g_autofree xmlNodePtr *nodes =3D NULL; VIR_XPATH_NODE_AUTORESTORE(ctxt) @@ -3766,6 +3765,7 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *cap= s, g_autofree char *xpath =3D g_strdup_printf("./hostCPU[@type=3D'%s']", = typeStr); size_t i; int n; + virTristateBool migratability; int val; =20 if (!(hostCPUNode =3D virXPathNode(xpath, ctxt))) { @@ -3781,13 +3781,12 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *c= aps, return -1; } =20 - if (!(migratability =3D virXMLPropString(hostCPUNode, "migratability")= ) || - (val =3D virTristateBoolTypeFromString(migratability)) <=3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("invalid migratability value for host CPU model")= ); + if (virXMLPropTristateBool(hostCPUNode, "migratability", + VIR_XML_PROP_REQUIRED, + &migratability) < 0) return -1; - } - hostCPU->migratability =3D val =3D=3D VIR_TRISTATE_BOOL_YES; + + virTristateBoolToBool(migratability, &hostCPU->migratability); =20 ctxt->node =3D hostCPUNode; =20 @@ -3798,7 +3797,6 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *cap= s, for (i =3D 0; i < n; i++) { qemuMonitorCPUProperty *prop =3D hostCPU->props + i; g_autofree char *type =3D NULL; - g_autofree char *migratable =3D NULL; =20 ctxt->node =3D nodes[i]; =20 @@ -3850,17 +3848,11 @@ virQEMUCapsLoadHostCPUModelInfo(virQEMUCapsAccel *c= aps, break; } =20 - if ((migratable =3D virXMLPropString(ctxt->node, "migratable")= )) { - if ((val =3D virTristateBoolTypeFromString(migratable)) <= =3D 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unknown migratable value for '%s' ho= st " - "CPU model property"), - prop->name); - return -1; - } + if (virXMLPropTristateBool(ctxt->node, "migratable", + VIR_XML_PROP_NONE, + &prop->migratable) < 0) + return -1; =20 - prop->migratable =3D val; - } } } =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index a8401bac30..aa8f6b8d05 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2829,19 +2829,11 @@ int qemuDomainObjPrivateXMLParseAllowReboot(xmlXPathContextPtr ctxt, virTristateBool *allowReboot) { - int val; - g_autofree char *valStr =3D NULL; + xmlNodePtr node =3D virXPathNode("./allowReboot", ctxt); =20 - if ((valStr =3D virXPathString("string(./allowReboot/@value)", ctxt)))= { - if ((val =3D virTristateBoolTypeFromString(valStr)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid allowReboot value '%s'"), valStr); - return -1; - } - *allowReboot =3D val; - } - - return 0; + return virXMLPropTristateBool(node, "value", + VIR_XML_PROP_NONE, + allowReboot); } =20 =20 --=20 2.34.1 From nobody Sun May 5 14:10:28 2024 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=1642772437; cv=none; d=zohomail.com; s=zohoarc; b=hv91aTSBkKn+7VARPm40Ul6mjCBEp18IQpyh09kqfF4GazHGzRPP3wJdfLdCSdEGA50jJ4IH+ayk5m9HzlzMpz5PC5YJ4dtLxEHJv3v+iJPgxR3PeEZfWj1mj7b5K5bDqtunz7JDp3jF3nVc95kAtOCAIKSFBMngZRW8NdiJuvo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642772437; 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=PXN65+5Y46uWnUYsmhEwYoDvle48xHEhKNY+Chm76Bk=; b=Pd2PVSJpxotnrMrZv+YhP/9QD95/lB8wAtZ18cHx1p2c8B0dPbL3dVLnK7R0DtjGGMEz2mDHfv2DMBVSIJVtJNtznYR1lacTJqbwIJLeoi/lyx7XcZDK82NPGE6fG1xSdub/p2GATt682l/fEYL0IWrsDHZSMi4P3f7Dbhz4xxU= 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 164277243710246.727841864747575; Fri, 21 Jan 2022 05:40:37 -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-347-4PCEUBMZMrOL7caqQQ83cg-1; Fri, 21 Jan 2022 08:40:34 -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 22D991091DAC; Fri, 21 Jan 2022 13:40:28 +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 CE43710A394F; Fri, 21 Jan 2022 13:40:27 +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 912091832DBD; Fri, 21 Jan 2022 13:40:27 +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 20LDSUE6011988 for ; Fri, 21 Jan 2022 08:28:30 -0500 Received: by smtp.corp.redhat.com (Postfix) id A8E1C108F850; Fri, 21 Jan 2022 13:28:30 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33B251090033 for ; Fri, 21 Jan 2022 13:28:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642772436; 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=PXN65+5Y46uWnUYsmhEwYoDvle48xHEhKNY+Chm76Bk=; b=MR76PgEyCZcLPSeOU28zyA9vm4GTGIWPinKxyCoV7Nm44MQhprkrTS0UDUP8yyr2utLN6w mg5dcRW0PC6Tuv1lle0Q2dBmKvehydNW/JThq1H0eIwwRRmdqk/lqB52fo7q3OKDf2aFpL I443cL1b2JqDTCXBOUpY/MArkv7xuFU= X-MC-Unique: 4PCEUBMZMrOL7caqQQ83cg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 07/12] conf: Convert virCPUDefParseXML() to virXMLProp*() Date: Fri, 21 Jan 2022 14:28:14 +0100 Message-Id: <233e9f2ae894b930addf62df289ab72bc6422f40.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: 1642772437910100003 Content-Type: text/plain; charset="utf-8" After previous cleanups, the virCPUDefParseXML() function uses a mixture of virXMLProp*() and the old virXMLPropString() + virXXXTypeFromString() patterns. Rework it so that virXMLProp*() is used. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/conf/cpu_conf.c | 24 ++++++++---------------- src/conf/cpu_conf.h | 2 +- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index 8e61a16919..da83e99371 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -407,17 +407,11 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, } =20 if (def->type =3D=3D VIR_CPU_TYPE_GUEST) { - g_autofree char *match =3D virXMLPropString(ctxt->node, "match"); - - if (match) { - def->match =3D virCPUMatchTypeFromString(match); - if (def->match < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Invalid match attribute for CPU " - "specification")); - return -1; - } - } + if (virXMLPropEnum(ctxt->node, "match", + virCPUMatchTypeFromString, + VIR_XML_PROP_NONE, + &def->match) < 0) + return -1; =20 if (virXMLPropEnum(ctxt->node, "check", virCPUCheckTypeFromString, VIR_XML_PROP_NONE, &def->check) < 0) @@ -450,12 +444,10 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, if ((counter_node =3D virXPathNode("./counter[@name=3D'tsc'])", ct= xt))) { tsc =3D g_new0(virHostCPUTscInfo, 1); =20 - if (virXPathULongLong("string(./counter[@name=3D'tsc']/@freque= ncy)", - ctxt, &tsc->frequency) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("Invalid TSC frequency")); + if (virXMLPropULongLong(counter_node, "frequency", 10, + VIR_XML_PROP_REQUIRED, + &tsc->frequency) < 0) return -1; - } =20 if (virXMLPropTristateBool(counter_node, "scaling", VIR_XML_PROP_NONE, diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index b0a81895be..2cda4ee1f4 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -122,7 +122,7 @@ struct _virCPUDef { int refs; int type; /* enum virCPUType */ int mode; /* enum virCPUMode */ - int match; /* enum virCPUMatch */ + virCPUMatch match; virCPUCheck check; virArch arch; char *model; --=20 2.34.1 From nobody Sun May 5 14:10:28 2024 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=1642772052; cv=none; d=zohomail.com; s=zohoarc; b=U4kv58gns8rDPCGzGqmvj+rA8GBw8HWo7RrKPCos0/XbH1jyPtZ2WTsHTt+Bt3e7SeHE9dOQwzvQRpm6NcIIq5L7I3kRXZJ6vs2MaBYMybMTvJNM6UlsLCjWa83Gfjytr3DKAX3cqu/hnxrX1oNjxpkjWWdZaYYvmIqevpnNT2I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642772052; 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=vgN3527r3WLj6Tyh0rh0CMDF2jq8j57jwO6/hhl9qpk=; b=imD4T6E79/f508ClJU0Cenw/75MvLZNcMv6lByig1AGDxe2KrP7fXmRh/ni2MaZC/sSEKN1tm1EAEOnaXU5WvAbj+mbfhuAEeJcziFmLhozpn7KTqprKRVAbBlIGq2uZ1iQ+ShPHvYulB3inlMIUr+XFYRmg2vRDpzvW6R2L4vI= 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 1642772052211693.9687399420583; Fri, 21 Jan 2022 05:34:12 -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-616-ffFzQkWnMPCtR9tzBAtGrQ-1; Fri, 21 Jan 2022 08:34:09 -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 AC83686A8C7; Fri, 21 Jan 2022 13:34:04 +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 7FDE8108F850; Fri, 21 Jan 2022 13:34:04 +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 3E9FA1832DC0; Fri, 21 Jan 2022 13:34:04 +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 20LDSVOm011993 for ; Fri, 21 Jan 2022 08:28:31 -0500 Received: by smtp.corp.redhat.com (Postfix) id 788521090033; Fri, 21 Jan 2022 13:28:31 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02E3E109004C for ; Fri, 21 Jan 2022 13:28:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642772051; 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=vgN3527r3WLj6Tyh0rh0CMDF2jq8j57jwO6/hhl9qpk=; b=DEoqfw7T47rRt4gKCusdo8Ux9JYR24/km8Gh8P+1b1ybWxRh2BQUOUJwxJkgo1F8Xs79C/ lwc8ge0iXjxX5A7HuO+SsoMhzVZm2UnmyDKJUlT2D2fM+oZfWYDAefwBHu/meuS4xJCCb2 lnNQrvQMdvp7bFq6YE/QbKabgorOiTA= X-MC-Unique: ffFzQkWnMPCtR9tzBAtGrQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 08/12] conf: Convert virDomainDefParseBootXML() to virXMLProp*() Date: Fri, 21 Jan 2022 14:28:15 +0100 Message-Id: <834a04b9a5488173cd2f2d0b01295831dc7844e6.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: 1642772053921100001 Content-Type: text/plain; charset="utf-8" After previous cleanups, the virDomainDefParseBootXML() function uses a mixture of virXMLProp*() and the old virXMLPropString() + virXXXTypeFromString() patterns. Rework it so that virXMLProp*() is used. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 61 +++++++++++++++++------------------------ src/conf/domain_conf.h | 4 +-- src/libxl/libxl_conf.c | 2 ++ src/libxl/xen_xl.c | 2 ++ src/libxl/xen_xm.c | 2 ++ src/qemu/qemu_process.c | 2 +- src/vz/vz_sdk.c | 4 ++- 7 files changed, 37 insertions(+), 40 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 281879b915..30f0a13e2a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16905,7 +16905,6 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, xmlNodePtr node; size_t i; int n; - g_autofree char *tmp =3D NULL; g_autofree xmlNodePtr *nodes =3D NULL; =20 /* analysis of the boot devices */ @@ -16913,20 +16912,13 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, return -1; =20 for (i =3D 0; i < n && i < VIR_DOMAIN_BOOT_LAST; i++) { - int val; - g_autofree char *dev =3D virXMLPropString(nodes[i], "dev"); - if (!dev) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("missing boot device")); + if (virXMLPropEnum(nodes[i], "dev", + virDomainBootTypeFromString, + VIR_XML_PROP_REQUIRED, + &def->os.bootDevs[def->os.nBootDevs]) < 0) return -1; - } - if ((val =3D virDomainBootTypeFromString(dev)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown boot device '%s'"), - dev); - return -1; - } - def->os.bootDevs[def->os.nBootDevs++] =3D val; + + def->os.nBootDevs++; } =20 if ((node =3D virXPathNode("./os/bootmenu[1]", ctxt))) { @@ -16940,36 +16932,33 @@ virDomainDefParseBootXML(xmlXPathContextPtr ctxt, def->os.bootmenu =3D VIR_TRISTATE_BOOL_NO; } =20 - tmp =3D virXMLPropString(node, "timeout"); - if (tmp && def->os.bootmenu =3D=3D VIR_TRISTATE_BOOL_YES) { - if (virStrToLong_uip(tmp, NULL, 0, &def->os.bm_timeout) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("invalid value for boot menu timeout")); + if (def->os.bootmenu =3D=3D VIR_TRISTATE_BOOL_YES) { + int rv; + + if ((rv =3D virXMLPropUInt(node, "timeout", 10, + VIR_XML_PROP_NONE, + &def->os.bm_timeout)) < 0) { return -1; + } else if (rv > 0) { + def->os.bm_timeout_set =3D true; } - def->os.bm_timeout_set =3D true; } - VIR_FREE(tmp); } =20 if ((node =3D virXPathNode("./os/bios[1]", ctxt))) { - tmp =3D virXMLPropString(node, "useserial"); - if (tmp) { - bool state =3D false; - ignore_value(virStringParseYesNo(tmp, &state)); - def->os.bios.useserial =3D virTristateBoolFromBool(state); - VIR_FREE(tmp); + int rv; + + if (virXMLPropTristateBool(node, "useserial", + VIR_XML_PROP_NONE, + &def->os.bios.useserial) < 0) { + def->os.bios.useserial =3D VIR_TRISTATE_BOOL_NO; } =20 - tmp =3D virXMLPropString(node, "rebootTimeout"); - if (tmp) { - /* that was really just for the check if it is there */ - - if (virStrToLong_i(tmp, NULL, 0, &def->os.bios.rt_delay) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("invalid value for rebootTimeout")); - return -1; - } + if ((rv =3D virXMLPropInt(node, "rebootTimeout", 10, + VIR_XML_PROP_NONE, + &def->os.bios.rt_delay, 0)) < 0) { + return -1; + } else if (rv > 0) { def->os.bios.rt_set =3D true; } } diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index c2c263dfab..584e15b6c7 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2195,7 +2195,7 @@ typedef enum { VIR_ENUM_DECL(virDomainLockFailure); =20 struct _virDomainBIOSDef { - int useserial; /* enum virTristateBool */ + virTristateBool useserial; /* reboot-timeout parameters */ bool rt_set; int rt_delay; @@ -2324,7 +2324,7 @@ struct _virDomainOSDef { virArch arch; char *machine; size_t nBootDevs; - int bootDevs[VIR_DOMAIN_BOOT_LAST]; + virDomainBootOrder bootDevs[VIR_DOMAIN_BOOT_LAST]; virTristateBool bootmenu; unsigned int bm_timeout; bool bm_timeout_set; diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c index 1ac6253ad7..561171126c 100644 --- a/src/libxl/libxl_conf.c +++ b/src/libxl/libxl_conf.c @@ -609,6 +609,8 @@ libxlMakeDomBuildInfo(virDomainDef *def, case VIR_DOMAIN_BOOT_NET: bootorder[i] =3D 'n'; break; + case VIR_DOMAIN_BOOT_LAST: + break; } } if (def->os.nBootDevs =3D=3D 0) { diff --git a/src/libxl/xen_xl.c b/src/libxl/xen_xl.c index 799fe05cbd..87194ccbd1 100644 --- a/src/libxl/xen_xl.c +++ b/src/libxl/xen_xl.c @@ -1153,6 +1153,8 @@ xenFormatXLOS(virConf *conf, virDomainDef *def) default: boot[i] =3D 'c'; break; + case VIR_DOMAIN_BOOT_LAST: + break; } } =20 diff --git a/src/libxl/xen_xm.c b/src/libxl/xen_xm.c index 2e636d874e..a962da9cad 100644 --- a/src/libxl/xen_xm.c +++ b/src/libxl/xen_xm.c @@ -457,6 +457,8 @@ xenFormatXMOS(virConf *conf, virDomainDef *def) default: boot[i] =3D 'c'; break; + case VIR_DOMAIN_BOOT_LAST: + break; } } =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7ff4dc1835..336f0bab2e 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -6183,7 +6183,7 @@ qemuProcessPrepareDeviceBootorder(virDomainDef *def) return; =20 for (i =3D 0; i < def->os.nBootDevs; i++) { - switch ((virDomainBootOrder) def->os.bootDevs[i]) { + switch (def->os.bootDevs[i]) { case VIR_DOMAIN_BOOT_CDROM: bootCD =3D i + 1; break; diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index 94c6cd5c7a..ccfd3e9d55 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -3799,7 +3799,7 @@ prlsdkSetBootOrderVm(PRL_HANDLE sdkdom, virDomainDef = *def) for (i =3D 0; i < def->os.nBootDevs; ++i) { virType =3D def->os.bootDevs[i]; =20 - switch ((int)virType) { + switch (virType) { case VIR_DOMAIN_BOOT_CDROM: sdkType =3D PDE_OPTICAL_DISK; break; @@ -3809,6 +3809,8 @@ prlsdkSetBootOrderVm(PRL_HANDLE sdkdom, virDomainDef = *def) case VIR_DOMAIN_BOOT_NET: sdkType =3D PDE_GENERIC_NETWORK_ADAPTER; break; + case VIR_DOMAIN_BOOT_FLOPPY: + case VIR_DOMAIN_BOOT_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Unsupported boot device type: '%s'"), --=20 2.34.1 From nobody Sun May 5 14:10:28 2024 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=1642772057; cv=none; d=zohomail.com; s=zohoarc; b=lOwgNOHKxyzykvtDsuvmK/pDl9t8roYtJ45TfP0hgPkynTsbF34aA6X4G0BvO8N9Mgh9V3qDKkGLnKdp+Eo4WFdt+y2kxmeYQgDBLOevg3G/IcctOe4fNYm2ap1RQ1t52QavC6xqpKk7AZfL/W43GyPQkYJo/MLe1otKs6BXyNA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642772057; 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=mGpKBVB432VsoI2ExJBowALi44YLhrId2F9HvRD0kpk=; b=dofy+I2mWfxxd+D5pBYX1WT3TRO9+su5bidmwTVP32syGKifb2IKdC7cWBoAc0kWYx+jIzxIpi42Bpdi2Sk9k1we5TeciR+qpDbPKDrK0ah6lEU5PJp64KKBjpJNdTdKG9EBJGjLdNy6JCMG7PkVdqir+mJe0acVJaWkrqGZ178= 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 1642772057126950.6368554926172; Fri, 21 Jan 2022 05:34:17 -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-643-YAbwyDAUOi6g1h7xIfsd6g-1; Fri, 21 Jan 2022 08:34:14 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 128B41091DBB; Fri, 21 Jan 2022 13:34: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 E0C7A7B6C7; Fri, 21 Jan 2022 13:34:08 +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 A700D4A707; Fri, 21 Jan 2022 13:34:08 +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 20LDSWgg011998 for ; Fri, 21 Jan 2022 08:28:32 -0500 Received: by smtp.corp.redhat.com (Postfix) id 4955C109004C; Fri, 21 Jan 2022 13:28:32 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id C71D41090033 for ; Fri, 21 Jan 2022 13:28:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642772056; 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=mGpKBVB432VsoI2ExJBowALi44YLhrId2F9HvRD0kpk=; b=Kt2/uC3MezCQaG3hPV2I7LvTP5L6cOcxgK/zxVGjm0TFk8Shjl2SlqT2uUmKFvW/GOM/jo 9wMlY3jEXNUdgUxCJnwmdkw8BstvFU3g9WN+GdlaORTeOsZPLtfKTIMX40YnLz0AmqP11R WaZKklj5uSDm4SqyR0iAQMO6xHEoY8w= X-MC-Unique: YAbwyDAUOi6g1h7xIfsd6g-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 09/12] conf: Convert virDomainFSDefParseXML() to virXMLProp*() Date: Fri, 21 Jan 2022 14:28:16 +0100 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.16 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: 1642772059020100001 Content-Type: text/plain; charset="utf-8" After previous cleanups, the virDomainFSDefParseXML() function uses a mixture of virXMLProp*() and the old virXMLPropString() + virXXXTypeFromString() patterns. Rework it so that virXMLProp*() is used. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/bhyve/bhyve_command.c | 2 +- src/conf/domain_conf.c | 127 +++++++++++++-------------------- src/conf/domain_conf.h | 10 +-- src/lxc/lxc_container.c | 3 + src/qemu/qemu_domain_address.c | 2 +- 5 files changed, 60 insertions(+), 84 deletions(-) diff --git a/src/bhyve/bhyve_command.c b/src/bhyve/bhyve_command.c index 3368d20a04..af8ec30fe7 100644 --- a/src/bhyve/bhyve_command.c +++ b/src/bhyve/bhyve_command.c @@ -577,7 +577,7 @@ bhyveBuildFSArgStr(const virDomainDef *def G_GNUC_UNUSE= D, { g_auto(virBuffer) params =3D VIR_BUFFER_INITIALIZER; =20 - switch ((virDomainFSType) fs->type) { + switch (fs->type) { case VIR_DOMAIN_FS_TYPE_MOUNT: break; case VIR_DOMAIN_FS_TYPE_BLOCK: diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 30f0a13e2a..f4b05b1c21 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9759,86 +9759,66 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, virDomainFSDef *def; xmlNodePtr driver_node =3D NULL; xmlNodePtr source_node =3D NULL; - g_autofree char *type =3D NULL; g_autofree char *source =3D NULL; g_autofree char *target =3D NULL; g_autofree char *format =3D NULL; - g_autofree char *accessmode =3D NULL; g_autofree char *usage =3D NULL; g_autofree char *units =3D NULL; - g_autofree char *model =3D NULL; - g_autofree char *multidevs =3D NULL; - g_autofree char *fmode =3D NULL; - g_autofree char *dmode =3D NULL; g_autofree char *sock =3D NULL; + int rv; =20 ctxt->node =3D node; =20 if (!(def =3D virDomainFSDefNew(xmlopt))) return NULL; =20 - type =3D virXMLPropString(node, "type"); - if (type) { - if ((def->type =3D virDomainFSTypeFromString(type)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown filesystem type '%s'"), type); - goto error; - } - } else { - def->type =3D VIR_DOMAIN_FS_TYPE_MOUNT; - } + if (virXMLPropEnum(node, "type", + virDomainFSTypeFromString, + VIR_XML_PROP_NONE, + &def->type) < 0) + goto error; =20 - accessmode =3D virXMLPropString(node, "accessmode"); - if (accessmode) { - if ((def->accessmode =3D virDomainFSAccessModeTypeFromString(acces= smode)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown accessmode '%s'"), accessmode); - goto error; - } - } else { - def->accessmode =3D VIR_DOMAIN_FS_ACCESSMODE_DEFAULT; - } + if (virXMLPropEnum(node, "accessmode", + virDomainFSAccessModeTypeFromString, + VIR_XML_PROP_NONE, + &def->accessmode) < 0) + goto error; =20 - fmode =3D virXMLPropString(node, "fmode"); - if (fmode) { - if ((virStrToLong_uip(fmode, NULL, 8, &def->fmode) < 0) || - (def->fmode > 0777)) { + if ((rv =3D virXMLPropUInt(node, "fmode", 8, + VIR_XML_PROP_NONE, + &def->fmode)) < 0) { + goto error; + } else if (rv > 0) { + if (def->fmode > 0777) { virReportError(VIR_ERR_XML_ERROR, - _("invalid fmode: '%s'"), fmode); + _("invalid fmode: '0%o'"), def->fmode); goto error; } } =20 - dmode =3D virXMLPropString(node, "dmode"); - if (dmode) { - if ((virStrToLong_uip(dmode, NULL, 8, &def->dmode) < 0) || - (def->dmode > 0777)) { + if ((rv =3D virXMLPropUInt(node, "dmode", 8, + VIR_XML_PROP_NONE, + &def->dmode)) < 0) { + goto error; + } else if (rv > 0) { + if (def->dmode > 0777) { virReportError(VIR_ERR_XML_ERROR, - _("invalid dmode: '%s'"), dmode); + _("invalid dmode: '0%o'"), def->dmode); goto error; } } =20 - model =3D virXMLPropString(node, "model"); - if (model) { - if ((def->model =3D virDomainFSModelTypeFromString(model)) < 0 || - def->model =3D=3D VIR_DOMAIN_FS_MODEL_DEFAULT) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown model '%s'"), model); - goto error; - } - } + if (virXMLPropEnum(node, "model", + virDomainFSModelTypeFromString, + VIR_XML_PROP_NONZERO, + &def->model) < 0) + goto error; =20 - multidevs =3D virXMLPropString(node, "multidevs"); - if (multidevs) { - if ((def->multidevs =3D virDomainFSMultidevsTypeFromString(multide= vs)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown multidevs '%s'"), multidevs); - goto error; - } - } else { - def->multidevs =3D VIR_DOMAIN_FS_MULTIDEVS_DEFAULT; - } + if (virXMLPropEnum(node, "multidevs", + virDomainFSMultidevsTypeFromString, + VIR_XML_PROP_NONE, + &def->multidevs) < 0) + goto error; =20 if (virParseScaledValue("./space_hard_limit[1]", NULL, ctxt, &def->space_hard_limit, @@ -9901,11 +9881,10 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, if (def->fsdriver =3D=3D VIR_DOMAIN_FS_DRIVER_TYPE_VIRTIOFS) { g_autofree char *queue_size =3D virXPathString("string(./driver/@q= ueue)", ctxt); g_autofree char *binary =3D virXPathString("string(./binary/@path)= ", ctxt); - g_autofree char *cache =3D virXPathString("string(./binary/cache/@= mode)", ctxt); - g_autofree char *sandbox =3D virXPathString("string(./binary/sandb= ox/@mode)", ctxt); xmlNodePtr binary_node =3D virXPathNode("./binary", ctxt); xmlNodePtr binary_lock_node =3D virXPathNode("./binary/lock", ctxt= ); - int val; + xmlNodePtr binary_cache_node =3D virXPathNode("./binary/cache", ct= xt); + xmlNodePtr binary_sandbox_node =3D virXPathNode("./binary/sandbox"= , ctxt); =20 if (queue_size && virStrToLong_ull(queue_size, NULL, 10, &def->que= ue_size) < 0) { virReportError(VIR_ERR_XML_ERROR, @@ -9932,26 +9911,17 @@ virDomainFSDefParseXML(virDomainXMLOption *xmlopt, &def->flock) < 0) goto error; =20 - if (cache) { - if ((val =3D virDomainFSCacheModeTypeFromString(cache)) <=3D 0= ) { - virReportError(VIR_ERR_XML_ERROR, - _("cannot parse cache mode '%s' for virtiof= s"), - cache); - goto error; - } - def->cache =3D val; - } - - if (sandbox) { - if ((val =3D virDomainFSSandboxModeTypeFromString(sandbox)) <= =3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("cannot parse sandbox mode '%s' for virti= ofs"), - sandbox); - goto error; - } - def->sandbox =3D val; - } + if (virXMLPropEnum(binary_cache_node, "mode", + virDomainFSCacheModeTypeFromString, + VIR_XML_PROP_NONZERO, + &def->cache) < 0) + goto error; =20 + if (virXMLPropEnum(binary_sandbox_node, "mode", + virDomainFSSandboxModeTypeFromString, + VIR_XML_PROP_NONZERO, + &def->sandbox) < 0) + goto error; } =20 if (source =3D=3D NULL && def->type !=3D VIR_DOMAIN_FS_TYPE_RAM @@ -24188,6 +24158,9 @@ virDomainFSDefFormat(virBuffer *buf, virBufferEscapeString(buf, " volume=3D'%s'", def->src->srcpool->vo= lume); virBufferAddLit(buf, "/>\n"); break; + + case VIR_DOMAIN_FS_TYPE_LAST: + break; } =20 virBufferEscapeString(buf, "\n", diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 584e15b6c7..bbb2f463e2 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -787,7 +787,7 @@ struct _virDomainControllerDef { =20 /* Types of disk backends */ typedef enum { - VIR_DOMAIN_FS_TYPE_MOUNT, /* Mounts (binds) a host dir on a guest dir = */ + VIR_DOMAIN_FS_TYPE_MOUNT =3D 0, /* Mounts (binds) a host dir on a gues= t dir */ VIR_DOMAIN_FS_TYPE_BLOCK, /* Mounts a host block dev on a guest dir */ VIR_DOMAIN_FS_TYPE_FILE, /* Loopback mounts a host file on a guest di= r */ VIR_DOMAIN_FS_TYPE_TEMPLATE, /* Expands a OS template to a guest dir */ @@ -867,15 +867,15 @@ typedef enum { } virDomainFSSandboxMode; =20 struct _virDomainFSDef { - int type; + virDomainFSType type; virDomainFSDriverType fsdriver; - int accessmode; /* enum virDomainFSAccessMode */ + virDomainFSAccessMode accessmode; int format; /* virStorageFileFormat */ virDomainFSWrpolicy wrpolicy; - int model; /* virDomainFSModel */ + virDomainFSModel model; unsigned int fmode; unsigned int dmode; - int multidevs; /* virDomainFSMultidevs */ + virDomainFSMultidevs multidevs; unsigned long long usage; /* in bytes */ virStorageSource *src; char *sock; diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index 3f38c55fc6..d5410e9fa6 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -1447,6 +1447,9 @@ static int lxcContainerMountFS(virDomainFSDef *fs, _("Unexpected filesystem type %s"), virDomainFSTypeToString(fs->type)); return -1; + case VIR_DOMAIN_FS_TYPE_TEMPLATE: + case VIR_DOMAIN_FS_TYPE_VOLUME: + case VIR_DOMAIN_FS_TYPE_LAST: default: virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("Cannot mount filesystem type %s"), diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c index 18fc34d049..3e6eed6ec9 100644 --- a/src/qemu/qemu_domain_address.c +++ b/src/qemu/qemu_domain_address.c @@ -705,7 +705,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDevic= eDef *dev, case VIR_DOMAIN_FS_DRIVER_TYPE_PATH: case VIR_DOMAIN_FS_DRIVER_TYPE_HANDLE: /* these drivers are handled by virtio-9p-pci */ - switch ((virDomainFSModel) dev->data.fs->model) { + switch (dev->data.fs->model) { case VIR_DOMAIN_FS_MODEL_VIRTIO_TRANSITIONAL: /* Transitional devices only work in conventional PCI slot= s */ return pciFlags; --=20 2.34.1 From nobody Sun May 5 14:10:28 2024 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 Reviewed-by: J=C3=A1n Tomko --- 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 From nobody Sun May 5 14:10:28 2024 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=1642772440; cv=none; d=zohomail.com; s=zohoarc; b=LLs9Zo7CVBEBKCq7ux1YYSoCYpZqzdrif4w3nWeUwIL7Co+FHYYk06kxiQmNGDXTxCATWu7OHcd+mRjZmWnd45n6glwnFB5gFAIUl9MlI5RC3xv7zgqVAEwROJ++AWqNpF9leYq2rqYKYDBYIi0FrV0XaHvC2xQ2yNgg1xiBVbg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642772440; 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=FpDqJHhxxGyZD52CK+Kd2xOqcZLqAtTuFq2eZ+MR0V0=; b=LUQ4kbVLHU5E3Z5DOTR97pgq/FaFdOycfdPEZyMc3vz5aaIuT8bwm+2qMp6sBVN2JYuX9C6PFDsSSj6zm2qddjifHMRSi+KOhgYM38Hx/cNOVN9xn/3ZNue7VsZEtAnW1YrXbIoO1OCTDET8RA1KndJumvqujPZXJuobMJEFRcM= 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 1642772440808182.59850684456046; Fri, 21 Jan 2022 05:40:40 -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-116-YG51tNERPlmu9rFJr-WbEw-1; Fri, 21 Jan 2022 08:40:36 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D71BA8519E0; Fri, 21 Jan 2022 13:40:30 +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 AB5D47ED86; Fri, 21 Jan 2022 13:40:30 +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 6FAEB1832DC0; Fri, 21 Jan 2022 13:40:30 +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 20LDSXeW012011 for ; Fri, 21 Jan 2022 08:28:33 -0500 Received: by smtp.corp.redhat.com (Postfix) id DEA8F10A401C; 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 6842810A3BDB for ; Fri, 21 Jan 2022 13:28:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642772439; 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=FpDqJHhxxGyZD52CK+Kd2xOqcZLqAtTuFq2eZ+MR0V0=; b=TNq1rAT+NuqWimu/EjuSDb115nEo04ii7KmBSx9wAZU9udh8Z4cVpq2uOcQhV7Ue32Zsxh xVOWJLATPP3UMFO+mmxY5CylLm+nfiuSVn6y6pwV9oMC6/k4fP8PsqUDNvB2NCIv6Dw+ZH DV4QVx5o9P0MOpINsJUecI2QnqAkBDc= X-MC-Unique: YG51tNERPlmu9rFJr-WbEw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 11/12] conf: Convert virNetworkPortDefParseXML() to virXMLProp*() Date: Fri, 21 Jan 2022 14:28:18 +0100 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.12 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: 1642772442579100001 Content-Type: text/plain; charset="utf-8" After previous cleanups, the virNetworkPortDefParseXML() function uses a mixture of virXMLProp*() and the old virXMLPropString() + virXXXTypeFromString() patterns. Rework it so that virXMLProp*() is used. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/conf/virnetworkportdef.c | 20 +++++++++----------- src/conf/virnetworkportdef.h | 2 +- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/conf/virnetworkportdef.c b/src/conf/virnetworkportdef.c index 1d75436085..fcd9e55a55 100644 --- a/src/conf/virnetworkportdef.c +++ b/src/conf/virnetworkportdef.c @@ -92,7 +92,6 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) g_autofree char *mac =3D NULL; g_autofree char *macmgr =3D NULL; g_autofree char *mode =3D NULL; - g_autofree char *plugtype =3D NULL; g_autofree char *driver =3D NULL; =20 def =3D g_new0(virNetworkPortDef, 1); @@ -176,13 +175,12 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) return NULL; =20 plugNode =3D virXPathNode("./plug", ctxt); - plugtype =3D virXPathString("string(./plug/@type)", ctxt); =20 - if (plugtype && - (def->plugtype =3D virNetworkPortPlugTypeFromString(plugtype)) < 0= ) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid network port plug type '%s'"), plugtype); - } + if (virXMLPropEnum(plugNode, "type", + virNetworkPortPlugTypeFromString, + VIR_XML_PROP_NONE, + &def->plugtype) < 0) + return NULL; =20 switch (def->plugtype) { case VIR_NETWORK_PORT_PLUG_TYPE_NONE: @@ -190,12 +188,12 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) =20 case VIR_NETWORK_PORT_PLUG_TYPE_NETWORK: case VIR_NETWORK_PORT_PLUG_TYPE_BRIDGE: - if (!(def->plug.bridge.brname =3D virXPathString("string(./plug/@b= ridge)", ctxt))) { + if (!(def->plug.bridge.brname =3D virXMLPropString(plugNode, "brid= ge"))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing network port bridge name")); return NULL; } - macmgr =3D virXPathString("string(./plug/@macTableManager)", ctxt); + macmgr =3D virXMLPropString(plugNode, "macTableManager"); if (macmgr && (def->plug.bridge.macTableManager =3D virNetworkBridgeMACTableManagerTypeFromString(macmgr)) <=3D 0= ) { @@ -207,12 +205,12 @@ virNetworkPortDefParseXML(xmlXPathContextPtr ctxt) break; =20 case VIR_NETWORK_PORT_PLUG_TYPE_DIRECT: - if (!(def->plug.direct.linkdev =3D virXPathString("string(./plug/@= dev)", ctxt))) { + if (!(def->plug.direct.linkdev =3D virXMLPropString(plugNode, "dev= "))) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Missing network port link device name")); return NULL; } - mode =3D virXPathString("string(./plug/@mode)", ctxt); + mode =3D virXMLPropString(plugNode, "mode"); if (mode && (def->plug.direct.mode =3D virNetDevMacVLanModeTypeFromString(mode)) < 0) { diff --git a/src/conf/virnetworkportdef.h b/src/conf/virnetworkportdef.h index c6474c4ad8..ee13f8a084 100644 --- a/src/conf/virnetworkportdef.h +++ b/src/conf/virnetworkportdef.h @@ -58,7 +58,7 @@ struct _virNetworkPortDef { virTristateBool trustGuestRxFilters; virTristateBool isolatedPort; =20 - int plugtype; /* virNetworkPortPlugType */ + virNetworkPortPlugType plugtype; union { struct { char *brname; --=20 2.34.1 From nobody Sun May 5 14:10:28 2024 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=1642771992; cv=none; d=zohomail.com; s=zohoarc; b=dFjNfiDSv6SW3GKXE4yZXKFqU/KfCGNhFk8qfmMKcH/5FjYyE/lSW1oUj5ka/7JlHitTUxl1qL1ebxk1RdsC6sQCFZXol3/bPOdLH1poXUpQ5eJdJRmz6Qp5QaVP2Hp5HZCHY6UWr3Fy+LmXcL/9qJhFnEycq4PPyoWA+jw/T94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642771992; 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=NHscJV2RkAnT/lS/yHjr4tOwVvkJTliYFwbyWPJ1KR0=; b=ek9Kuw2WySldu8iyE0DrJr5Qya6r+xp0FK9d0p4U7Kvibq6HoW4Jcmnt4GY0nKPytWPUo+sF2YBO6cvGMbMW8GSolkQQcZIg8+5YVQhRbRxIWb6oVkwIXeFY3wn4zAGvdtnbM22Z/sqgQl1T7Vi3RFesnl1IDyReq3lgaCnJj+c= 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 1642771992217276.5150398107471; Fri, 21 Jan 2022 05:33:12 -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-627-SZODWiqDNyKJrVmbMnqlCA-1; Fri, 21 Jan 2022 08:33:07 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B75978144E2; Fri, 21 Jan 2022 13:32:58 +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 960917E11E; Fri, 21 Jan 2022 13:32:58 +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 5F14F4A7CA; Fri, 21 Jan 2022 13:32:58 +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 20LDSYCq012024 for ; Fri, 21 Jan 2022 08:28:34 -0500 Received: by smtp.corp.redhat.com (Postfix) id ADFD3108F850; Fri, 21 Jan 2022 13:28:34 +0000 (UTC) Received: from maggie.redhat.com (unknown [10.43.2.56]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38C1610A4023 for ; Fri, 21 Jan 2022 13:28:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642771990; 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=NHscJV2RkAnT/lS/yHjr4tOwVvkJTliYFwbyWPJ1KR0=; b=XH6DcX+dqYper393/1kMBNfA/hXjj30vMsyygDelKn1ZzxLw43rL27mJN50A6xJi9odROm GnLiGQY5NIgxIbAeGgS5wHNjJ3ZoxyHbWViCjDgwU1oAHAitD7dtB9q19/yBujJ40D8uPC 0gN6hR9IuhWt2/X7ChseMAiuBkerT0g= X-MC-Unique: SZODWiqDNyKJrVmbMnqlCA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 12/12] conf: Convert virDomainHostdevDefParseXMLSubsys() to virXMLProp*() Date: Fri, 21 Jan 2022 14:28:19 +0100 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.12 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: 1642771994233100001 Content-Type: text/plain; charset="utf-8" After previous cleanups, the virDomainHostdevDefParseXMLSubsys() function uses a mixture of virXMLProp*() and the old virXMLPropString() + virXXXTypeFromString() patterns. Rework it so that virXMLProp*() is used. Signed-off-by: Michal Privoznik Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 60 ++++++++++++----------------------- src/conf/domain_conf.h | 26 +++++++-------- src/qemu/qemu_command.c | 4 +-- src/qemu/qemu_hostdev.c | 4 +-- src/qemu/qemu_hotplug.c | 3 +- src/qemu/qemu_validate.c | 2 +- src/security/virt-aa-helper.c | 2 +- 7 files changed, 42 insertions(+), 59 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a25beaee3e..f97bd7bf22 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7293,14 +7293,12 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, virDomainXMLOption *xmlopt) { xmlNodePtr sourcenode; - int backend; + xmlNodePtr driver_node =3D NULL; virDomainHostdevSubsysPCI *pcisrc =3D &def->source.subsys.u.pci; virDomainHostdevSubsysSCSI *scsisrc =3D &def->source.subsys.u.scsi; virDomainHostdevSubsysSCSIVHost *scsihostsrc =3D &def->source.subsys.u= .scsi_host; virDomainHostdevSubsysMediatedDev *mdevsrc =3D &def->source.subsys.u.m= dev; virTristateBool managed; - g_autofree char *sgio =3D NULL; - g_autofree char *backendStr =3D NULL; g_autofree char *model =3D NULL; int rv; =20 @@ -7313,7 +7311,6 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, VIR_XML_PROP_NONE, &managed)); virTristateBoolToBool(managed, &def->managed); =20 - sgio =3D virXMLPropString(node, "sgio"); model =3D virXMLPropString(node, "model"); =20 /* @type is passed in from the caller rather than read from the @@ -7352,18 +7349,17 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, return -1; } =20 - if (sgio) { + if ((rv =3D virXMLPropEnum(node, "sgio", + virDomainDeviceSGIOTypeFromString, + VIR_XML_PROP_NONZERO, + &scsisrc->sgio)) < 0) { + return -1; + } else if (rv > 0) { if (def->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SC= SI) { virReportError(VIR_ERR_XML_ERROR, "%s", _("sgio is only supported for scsi host device"= )); return -1; } - - if ((scsisrc->sgio =3D virDomainDeviceSGIOTypeFromString(sgio)) <= =3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown sgio mode '%s'"), sgio); - return -1; - } } =20 if ((rv =3D virXMLPropTristateBool(node, "rawio", @@ -7389,27 +7385,17 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, } =20 if (def->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI= _HOST) { - if (model && - ((scsihostsrc->model =3D virDomainHostdevSubsysSCSIVHostModelT= ypeFromString(model)) < 0)) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown hostdev model '%s'"), - model); + if (virXMLPropEnum(node, "model", + virDomainHostdevSubsysSCSIVHostModelTypeFromStr= ing, + VIR_XML_PROP_NONE, + &scsihostsrc->model) < 0) return -1; - } } else if (def->source.subsys.type =3D=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TY= PE_MDEV) { - if (!model) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Missing 'model' attribute in mediated device= 's " - " element")); + if (virXMLPropEnum(node, "model", + virMediatedDeviceModelTypeFromString, + VIR_XML_PROP_REQUIRED, + &mdevsrc->model) < 0) return -1; - } - - if ((mdevsrc->model =3D virMediatedDeviceModelTypeFromString(model= )) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown hostdev model '%s'"), - model); - return -1; - } =20 if (virXMLPropTristateSwitch(node, "display", VIR_XML_PROP_NONE, @@ -7427,16 +7413,12 @@ virDomainHostdevDefParseXMLSubsys(xmlNodePtr node, if (virDomainHostdevSubsysPCIDefParseXML(sourcenode, ctxt, def, fl= ags) < 0) return -1; =20 - backend =3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT; - if ((backendStr =3D virXPathString("string(./driver/@name)", ctxt)= ) && - (((backend =3D virDomainHostdevSubsysPCIBackendTypeFromString(= backendStr)) < 0) || - backend =3D=3D VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown PCI device " - "has been specified"), backendStr); + driver_node =3D virXPathNode("./driver", ctxt); + if (virXMLPropEnum(driver_node, "name", + virDomainHostdevSubsysPCIBackendTypeFromString, + VIR_XML_PROP_NONZERO, + &pcisrc->backend) < 0) return -1; - } - pcisrc->backend =3D backend; =20 break; =20 @@ -30564,7 +30546,7 @@ virDomainNetDefActualToNetworkPort(virDomainDef *do= m, } port->plug.hostdevpci.managed =3D virTristateBoolFromBool(actual->= data.hostdev.def.managed); port->plug.hostdevpci.addr =3D actual->data.hostdev.def.source.sub= sys.u.pci.addr; - switch ((virDomainHostdevSubsysPCIBackendType)actual->data.hostdev= .def.source.subsys.u.pci.backend) { + switch (actual->data.hostdev.def.source.subsys.u.pci.backend) { case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT: port->plug.hostdevpci.driver =3D VIR_NETWORK_FORWARD_DRIVER_NA= ME_DEFAULT; break; diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 8a4d7b6f99..3e63d2513b 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -214,7 +214,7 @@ typedef enum { =20 /* the backend driver used for PCI hostdev devices */ typedef enum { - VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT, /* detect automatically, prefe= r VFIO */ + VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT =3D 0, /* detect automatically,= prefer VFIO */ VIR_DOMAIN_HOSTDEV_PCI_BACKEND_KVM, /* force legacy kvm style */ VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO, /* force vfio */ VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN, /* force legacy xen style, use = pciback */ @@ -245,7 +245,7 @@ struct _virDomainHostdevSubsysUSB { =20 struct _virDomainHostdevSubsysPCI { virPCIDeviceAddress addr; /* host address */ - int backend; /* enum virDomainHostdevSubsysPCIBackendType */ + virDomainHostdevSubsysPCIBackendType backend; }; =20 struct _virDomainHostdevSubsysSCSIHost { @@ -260,9 +260,17 @@ struct _virDomainHostdevSubsysSCSIiSCSI { virStorageSource *src; }; =20 +typedef enum { + VIR_DOMAIN_DEVICE_SGIO_DEFAULT =3D 0, + VIR_DOMAIN_DEVICE_SGIO_FILTERED, + VIR_DOMAIN_DEVICE_SGIO_UNFILTERED, + + VIR_DOMAIN_DEVICE_SGIO_LAST +} virDomainDeviceSGIO; + struct _virDomainHostdevSubsysSCSI { int protocol; /* enum virDomainHostdevSCSIProtocolType */ - int sgio; /* enum virDomainDeviceSGIO */ + virDomainDeviceSGIO sgio; virTristateBool rawio; union { virDomainHostdevSubsysSCSIHost host; @@ -271,7 +279,7 @@ struct _virDomainHostdevSubsysSCSI { }; =20 struct _virDomainHostdevSubsysMediatedDev { - int model; /* enum virMediatedDeviceModelType= */ + virMediatedDeviceModelType model; virTristateSwitch display; char uuidstr[VIR_UUID_STRING_BUFLEN]; /* mediated device's uuid stri= ng */ virTristateSwitch ramfb; @@ -300,7 +308,7 @@ VIR_ENUM_DECL(virDomainHostdevSubsysSCSIVHostModel); struct _virDomainHostdevSubsysSCSIVHost { int protocol; /* enum virDomainHostdevSubsysSCSIHostProtocolType */ char *wwpn; - int model; /* enum virDomainHostdevSubsysSCSIVHostModelType */ + virDomainHostdevSubsysSCSIVHostModelType model; }; =20 struct _virDomainHostdevSubsys { @@ -449,14 +457,6 @@ typedef enum { VIR_DOMAIN_DISK_IO_LAST } virDomainDiskIo; =20 -typedef enum { - VIR_DOMAIN_DEVICE_SGIO_DEFAULT =3D 0, - VIR_DOMAIN_DEVICE_SGIO_FILTERED, - VIR_DOMAIN_DEVICE_SGIO_UNFILTERED, - - VIR_DOMAIN_DEVICE_SGIO_LAST -} virDomainDeviceSGIO; - typedef enum { VIR_DOMAIN_DISK_DISCARD_DEFAULT =3D 0, VIR_DOMAIN_DISK_DISCARD_UNMAP, diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 99ac44d7f1..f5d7cd2c1b 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -4967,7 +4967,7 @@ qemuBuildPCIHostdevDevProps(const virDomainDef *def, const char *failover_pair_id =3D NULL; =20 /* caller has to assign proper passthrough backend type */ - switch ((virDomainHostdevSubsysPCIBackendType) pcisrc->backend) { + switch (pcisrc->backend) { case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO: break; =20 @@ -5480,7 +5480,7 @@ qemuBuildHostdevCommandLine(virCommand *cmd, =20 /* MDEV */ case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: - switch ((virMediatedDeviceModelType) mdevsrc->model) { + switch (mdevsrc->model) { case VIR_MDEV_MODEL_TYPE_VFIO_PCI: case VIR_MDEV_MODEL_TYPE_VFIO_CCW: case VIR_MDEV_MODEL_TYPE_VFIO_AP: diff --git a/src/qemu/qemu_hostdev.c b/src/qemu/qemu_hostdev.c index dfe657c51e..8af22bdd58 100644 --- a/src/qemu/qemu_hostdev.c +++ b/src/qemu/qemu_hostdev.c @@ -169,14 +169,14 @@ qemuHostdevPreparePCIDevicesCheckSupport(virDomainHos= tdevDef **hostdevs, /* assign defaults for hostdev passthrough */ for (i =3D 0; i < nhostdevs; i++) { virDomainHostdevDef *hostdev =3D hostdevs[i]; - int *backend =3D &hostdev->source.subsys.u.pci.backend; + virDomainHostdevSubsysPCIBackendType *backend =3D &hostdev->source= .subsys.u.pci.backend; =20 if (hostdev->mode !=3D VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) continue; if (hostdev->source.subsys.type !=3D VIR_DOMAIN_HOSTDEV_SUBSYS_TYP= E_PCI) continue; =20 - switch ((virDomainHostdevSubsysPCIBackendType)*backend) { + switch (*backend) { case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT: if (supportsPassthroughVFIO && virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) { diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index f3ec24635d..22acbd0852 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -1622,7 +1622,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriver *driver, /* this could have been changed by qemuHostdevPreparePCIDevices */ backend =3D hostdev->source.subsys.u.pci.backend; =20 - switch ((virDomainHostdevSubsysPCIBackendType)backend) { + switch (backend) { case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO: if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_VFIO_PCI)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -2814,6 +2814,7 @@ qemuDomainAttachMediatedDevice(virQEMUDriver *driver, if (qemuDomainEnsureVirtioAddress(&releaseaddr, vm, &dev) < 0) return -1; } break; + case VIR_MDEV_MODEL_TYPE_VFIO_AP: case VIR_MDEV_MODEL_TYPE_LAST: break; } diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 7eaad3614e..0a879f0115 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2357,7 +2357,7 @@ qemuValidateDomainMdevDef(const virDomainHostdevDef *= hostdev, const virDomainHostdevSubsysMediatedDev *mdevsrc; =20 mdevsrc =3D &hostdev->source.subsys.u.mdev; - switch ((virMediatedDeviceModelType) mdevsrc->model) { + switch (mdevsrc->model) { case VIR_MDEV_MODEL_TYPE_VFIO_PCI: return qemuValidateDomainMdevDefVFIOPCI(hostdev, def, qemuCaps); case VIR_MDEV_MODEL_TYPE_VFIO_AP: diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c index 28717b7e38..1f1cce8b3d 100644 --- a/src/security/virt-aa-helper.c +++ b/src/security/virt-aa-helper.c @@ -1070,7 +1070,7 @@ get_files(vahControl * ctl) =20 case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV: { virDomainHostdevSubsysMediatedDev *mdevsrc =3D &dev->sourc= e.subsys.u.mdev; - switch ((virMediatedDeviceModelType) mdevsrc->model) { + switch (mdevsrc->model) { case VIR_MDEV_MODEL_TYPE_VFIO_PCI: case VIR_MDEV_MODEL_TYPE_VFIO_AP: case VIR_MDEV_MODEL_TYPE_VFIO_CCW: --=20 2.34.1