From nobody Mon Feb 9 22:18:52 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1619188786; cv=none; d=zohomail.com; s=zohoarc; b=LtwTcQtd7MGIN/BLF4USjvxulfYVVZfyai/f7aeEwVaBBxesb4+ty64W8rrVc0HBA5VxYrrfvZD+Rt/h98NkobLB5SojDohCJCtdEYIg+xzmECx5WTmLJyfTap8yeOGsZiclJy8RFI0p/LP/6OUZttF6OCHtujVCaqc78bWj7X8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619188786; h=Content-Type:Content-Transfer-Encoding:Cc: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=04NXF6dUCS3ZE8FvO+1Fa8GozuHD+3JKIbXEpM+UBdw=; b=gExw2HEYnzSDE3UghXarjxiKdFGRdBQR7WEyVm8mEEZ1DEcm0aVTDiYlf44obXTlBmEcH5REUM25MFBJ1vns97KoBZvX6Yt9mVGGLJAS1x0A+m32tx2ClM/LVYOSWUQNqPFyr6WIbpuUVU8NB+B81YOm3iJVO01osH8AQGhwRn0= 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) header.from= 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 1619188786374362.7796867991274; Fri, 23 Apr 2021 07:39:46 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-514-hemacHZqMrm6a9gXKfyiDQ-1; Fri, 23 Apr 2021 10:39:42 -0400 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 C711A1927807; Fri, 23 Apr 2021 14:39:37 +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 A16AB5C233; Fri, 23 Apr 2021 14:39:37 +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 6BFF644A5E; Fri, 23 Apr 2021 14:39:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13NEdXa9029233 for ; Fri, 23 Apr 2021 10:39:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5125E1349A; Fri, 23 Apr 2021 14:39:33 +0000 (UTC) Received: from work.redhat.com (ovpn-115-30.ams2.redhat.com [10.36.115.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 30FF360BD8; Fri, 23 Apr 2021 14:39:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619188785; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=04NXF6dUCS3ZE8FvO+1Fa8GozuHD+3JKIbXEpM+UBdw=; b=JZJkMEAX/LojtgRvWgkFy0amUFxZRLNfXTK169VdKRzyqielIT94bAwQ0PdsZmGmL4mBuH JtHShFs6B0SaTQEBUsBFqPDsHR95s9cX4wMYgATnZGaWIoF7FTj8tlapxK4cIx4HOzHDhN nKfulygXQjkEUAaDP2ngSdM/lYHz2Rw= X-MC-Unique: hemacHZqMrm6a9gXKfyiDQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 04/11] virDomainControllerDefParseXML: Use virXMLProp* Date: Fri, 23 Apr 2021 16:39:15 +0200 Message-Id: <20210423143922.298608-5-twiederh@redhat.com> In-Reply-To: <20210423143922.298608-1-twiederh@redhat.com> References: <20210423143922.298608-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?J=C3=A1n=20Tomko?= , Tim Wiederhake 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: Tim Wiederhake Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 275 +++++++++++++++-------------------------- 1 file changed, 101 insertions(+), 174 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 33e79b20e6..46b3f03d99 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9491,7 +9491,7 @@ virDomainControllerDefParseXML(virDomainXMLOption *xm= lopt, unsigned int flags) { g_autoptr(virDomainControllerDef) def =3D NULL; - int type =3D 0; + virDomainControllerType type =3D 0; xmlNodePtr cur =3D NULL; bool processedModel =3D false; bool processedTarget =3D false; @@ -9499,33 +9499,14 @@ virDomainControllerDefParseXML(virDomainXMLOption *= xmlopt, int ports =3D -1; VIR_XPATH_NODE_AUTORESTORE(ctxt) int rc; - g_autofree char *typeStr =3D NULL; g_autofree char *idx =3D NULL; g_autofree char *model =3D NULL; - g_autofree char *queues =3D NULL; - g_autofree char *cmd_per_lun =3D NULL; - g_autofree char *max_sectors =3D NULL; - g_autofree char *modelName =3D NULL; - g_autofree char *chassisNr =3D NULL; - g_autofree char *chassis =3D NULL; - g_autofree char *port =3D NULL; - g_autofree char *busNr =3D NULL; - g_autofree char *targetIndex =3D NULL; - g_autofree char *hotplug =3D NULL; - g_autofree char *ioeventfd =3D NULL; - g_autofree char *portsStr =3D NULL; - g_autofree char *iothread =3D NULL; =20 ctxt->node =3D node; =20 - typeStr =3D virXMLPropString(node, "type"); - if (typeStr) { - if ((type =3D virDomainControllerTypeFromString(typeStr)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown controller type '%s'"), typeStr); - return NULL; - } - } + if (virXMLPropEnum(node, "type", virDomainControllerTypeFromString, + VIR_XML_PROP_NONE, &type) < 0) + return NULL; =20 if (!(def =3D virDomainControllerDefNew(type))) return NULL; @@ -9555,11 +9536,26 @@ virDomainControllerDefParseXML(virDomainXMLOption *= xmlopt, while (cur !=3D NULL) { if (cur->type =3D=3D XML_ELEMENT_NODE) { if (virXMLNodeNameEqual(cur, "driver")) { - queues =3D virXMLPropString(cur, "queues"); - cmd_per_lun =3D virXMLPropString(cur, "cmd_per_lun"); - max_sectors =3D virXMLPropString(cur, "max_sectors"); - ioeventfd =3D virXMLPropString(cur, "ioeventfd"); - iothread =3D virXMLPropString(cur, "iothread"); + if (virXMLPropUInt(cur, "queues", 10, VIR_XML_PROP_NONE, + &def->queues) < 0) + return NULL; + + if (virXMLPropUInt(cur, "cmd_per_lun", 10, VIR_XML_PROP_NO= NE, + &def->cmd_per_lun) < 0) + return NULL; + + if (virXMLPropUInt(cur, "max_sectors", 10, VIR_XML_PROP_NO= NE, + &def->max_sectors) < 0) + return NULL; + + if (virXMLPropTristateSwitch(cur, "ioeventfd", + VIR_XML_PROP_NONE, + &def->ioeventfd) < 0) + return NULL; + + if (virXMLPropUInt(cur, "iothread", 10, VIR_XML_PROP_NONE, + &def->iothread) < 0) + return NULL; =20 if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) return NULL; @@ -9570,7 +9566,15 @@ virDomainControllerDefParseXML(virDomainXMLOption *x= mlopt, "controller definition not allowed")); return NULL; } - modelName =3D virXMLPropString(cur, "name"); + + if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { + if (virXMLPropEnum(cur, "name", + virDomainControllerPCIModelNameType= FromString, + VIR_XML_PROP_NONE, + &def->opts.pciopts.modelName) < 0) + return NULL; + } + processedModel =3D true; } else if (virXMLNodeNameEqual(cur, "target")) { if (processedTarget) { @@ -9579,12 +9583,39 @@ virDomainControllerDefParseXML(virDomainXMLOption *= xmlopt, "controller definition not allowed")); return NULL; } - chassisNr =3D virXMLPropString(cur, "chassisNr"); - chassis =3D virXMLPropString(cur, "chassis"); - port =3D virXMLPropString(cur, "port"); - busNr =3D virXMLPropString(cur, "busNr"); - hotplug =3D virXMLPropString(cur, "hotplug"); - targetIndex =3D virXMLPropString(cur, "index"); + if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_PCI) { + if (virXMLPropInt(cur, "chassisNr", 0, VIR_XML_PROP_NO= NE, + &def->opts.pciopts.chassisNr) < 0) + return NULL; + + if (virXMLPropInt(cur, "chassis", 0, VIR_XML_PROP_NONE, + &def->opts.pciopts.chassis) < 0) + return NULL; + + if (virXMLPropInt(cur, "port", 0, VIR_XML_PROP_NONE, + &def->opts.pciopts.port) < 0) + return NULL; + + if (virXMLPropInt(cur, "busNr", 0, VIR_XML_PROP_NONE, + &def->opts.pciopts.busNr) < 0) + return NULL; + + if (virXMLPropTristateSwitch(cur, "hotplug", + VIR_XML_PROP_NONE, + &def->opts.pciopts.hotplu= g) < 0) + return NULL; + + if ((rc =3D virXMLPropInt(cur, "index", 0, VIR_XML_PRO= P_NONE, + &def->opts.pciopts.targetIndex)) < 0) + return NULL; + + if ((rc =3D=3D 1) && def->opts.pciopts.targetIndex =3D= =3D -1) { + virReportError(VIR_ERR_XML_ERROR, + _("Invalid target index '%i' in PCI= controller"), + def->opts.pciopts.targetIndex); + } + } + processedTarget =3D true; } } @@ -9601,42 +9632,6 @@ virDomainControllerDefParseXML(virDomainXMLOption *x= mlopt, return NULL; } =20 - if (queues && virStrToLong_ui(queues, NULL, 10, &def->queues) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Malformed 'queues' value '%s'"), queues); - return NULL; - } - - if (cmd_per_lun && virStrToLong_ui(cmd_per_lun, NULL, 10, &def->cmd_pe= r_lun) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Malformed 'cmd_per_lun' value '%s'"), cmd_per_lu= n); - return NULL; - } - - if (max_sectors && virStrToLong_ui(max_sectors, NULL, 10, &def->max_se= ctors) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Malformed 'max_sectors' value %s"), max_sectors); - return NULL; - } - - if (ioeventfd) { - int value; - if ((value =3D virTristateSwitchTypeFromString(ioeventfd)) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Malformed 'ioeventfd' value %s"), ioeventfd); - return NULL; - } - def->ioeventfd =3D value; - } - - if (iothread) { - if (virStrToLong_uip(iothread, NULL, 10, &def->iothread) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid 'iothread' value '%s'"), iothread); - return NULL; - } - } - if (def->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_USB && def->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) { VIR_DEBUG("Ignoring device address for none model usb controller"); @@ -9645,30 +9640,28 @@ virDomainControllerDefParseXML(virDomainXMLOption *= xmlopt, return NULL; } =20 - portsStr =3D virXMLPropString(node, "ports"); - if (portsStr) { - int r =3D virStrToLong_i(portsStr, NULL, 10, &ports); - if (r !=3D 0 || ports < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid ports: %s"), portsStr); - return NULL; - } + if ((rc =3D virXMLPropInt(node, "ports", 10, VIR_XML_PROP_NONE, &ports= )) < 0) + return NULL; + if ((rc =3D=3D 1) && ports < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid ports: %i"), ports); + return NULL; } =20 switch (def->type) { case VIR_DOMAIN_CONTROLLER_TYPE_VIRTIO_SERIAL: { - g_autofree char *vectors =3D virXMLPropString(node, "vectors"); + if ((rc =3D virXMLPropInt(node, "vectors", 10, VIR_XML_PROP_NONE, + &def->opts.vioserial.vectors)) < 0) + return NULL; =20 - def->opts.vioserial.ports =3D ports; - if (vectors) { - int r =3D virStrToLong_i(vectors, NULL, 10, - &def->opts.vioserial.vectors); - if (r !=3D 0 || def->opts.vioserial.vectors < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid vectors: %s"), vectors); - return NULL; - } + if ((rc =3D=3D 1) && def->opts.vioserial.vectors < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid vectors: %i"), + def->opts.vioserial.vectors); + return NULL; } + + def->opts.vioserial.ports =3D ports; break; } case VIR_DOMAIN_CONTROLLER_TYPE_USB: { @@ -9722,98 +9715,32 @@ virDomainControllerDefParseXML(virDomainXMLOption *= xmlopt, /* Other controller models don't require extra checks */ break; } - if (modelName) { - int value; - if ((value =3D virDomainControllerPCIModelNameTypeFromString(m= odelName)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown PCI controller model name '%s'"), - modelName); - return NULL; - } - def->opts.pciopts.modelName =3D value; - } - if (chassisNr) { - if (virStrToLong_i(chassisNr, NULL, 0, - &def->opts.pciopts.chassisNr) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid chassisNr '%s' in PCI controller= "), - chassisNr); - return NULL; - } - } - if (chassis) { - if (virStrToLong_i(chassis, NULL, 0, - &def->opts.pciopts.chassis) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid chassis '%s' in PCI controller"), - chassis); - return NULL; - } - } - if (port) { - if (virStrToLong_i(port, NULL, 0, - &def->opts.pciopts.port) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid port '%s' in PCI controller"), - port); - return NULL; - } - } - if (busNr) { - if (virStrToLong_i(busNr, NULL, 0, - &def->opts.pciopts.busNr) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid busNr '%s' in PCI controller"), - busNr); - return NULL; - } - } - if (targetIndex) { - if (virStrToLong_i(targetIndex, NULL, 0, - &def->opts.pciopts.targetIndex) < 0 || - def->opts.pciopts.targetIndex =3D=3D -1) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid target index '%s' in PCI control= ler"), - targetIndex); - return NULL; - } - } + if (numaNode >=3D 0) def->opts.pciopts.numaNode =3D numaNode; =20 - if (hotplug) { - int val =3D virTristateSwitchTypeFromString(hotplug); - - if (val <=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("PCI controller unrecognized hotplug sett= ing '%s'"), - hotplug); - return NULL; - } - def->opts.pciopts.hotplug =3D val; - } break; case VIR_DOMAIN_CONTROLLER_TYPE_XENBUS: { - g_autofree char *gntframes =3D virXMLPropString(node, "maxGrantFra= mes"); - g_autofree char *eventchannels =3D virXMLPropString(node, "maxEven= tChannels"); + if ((rc =3D virXMLPropInt(node, "maxGrantFrames", 10, VIR_XML_PROP= _NONE, + &def->opts.xenbusopts.maxGrantFrames)) < 0) + return NULL; =20 - if (gntframes) { - int r =3D virStrToLong_i(gntframes, NULL, 10, - &def->opts.xenbusopts.maxGrantFrames); - if (r !=3D 0 || def->opts.xenbusopts.maxGrantFrames < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid maxGrantFrames: %s"), gntframes); - return NULL; - } + if ((rc =3D=3D 1) && def->opts.xenbusopts.maxGrantFrames < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid maxGrantFrames: %i"), + def->opts.xenbusopts.maxGrantFrames); + return NULL; } - if (eventchannels) { - int r =3D virStrToLong_i(eventchannels, NULL, 10, - &def->opts.xenbusopts.maxEventChannels); - if (r !=3D 0 || def->opts.xenbusopts.maxEventChannels < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Invalid maxEventChannels: %s"), eventcha= nnels); - return NULL; - } + + if ((rc =3D virXMLPropInt(node, "maxEventChannels", 10, VIR_XML_PR= OP_NONE, + &def->opts.xenbusopts.maxEventChannels)) <= 0) + return NULL; + + if ((rc =3D=3D 1) && def->opts.xenbusopts.maxEventChannels < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Invalid maxEventChannels: %i"), + def->opts.xenbusopts.maxEventChannels); + return NULL; } break; } --=20 2.26.3