From nobody Mon Feb 9 06:26:35 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1618587515; cv=none; d=zohomail.com; s=zohoarc; b=PXTEkI4/7oDLhUtaMOSxOdhQdJiW8/g9LNWuTIe7fOop+WhQzoxy0uMw6S+UXJYQqksWiIpEUtJ2igXENmf2KmKuSZYjy0dny+oLgys6BPt/RPB/8C6PdUFVL9BLG44bnc1Y9V1rdWPgaBkpn2H3SahQT+Xz41dXjtGiRVbNjQ4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1618587515; 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=NwQ4Wl4w+ow5+yRhlidYt8dNhTp5Ht45q9fhb5F+Vs0=; b=nl9eWfQcsPSz45ea6JRJJEaDuu+4Lo72IS31k4ox4CocPkuyqdHVRVoZZ+AYF7hmsmvUEqGUR8E4+ui1N20VcBayYRDHh3J55IMh4lspV4gGHozI67CK2gOA06iS0Kt/om0PmeVxhrZlLYmaSoQqdb+I7gyqiEeYDs7QBBDm2NM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1618587515141803.012101517119; Fri, 16 Apr 2021 08:38:35 -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-569-VAzJ7qgrOUqN9vKERqsQdw-1; Fri, 16 Apr 2021 11:38:31 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A9BEA1008065; Fri, 16 Apr 2021 15:38:25 +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 7F22319701; Fri, 16 Apr 2021 15:38: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 4A4E2180B654; Fri, 16 Apr 2021 15:38:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13GFYuFt009270 for ; Fri, 16 Apr 2021 11:34:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9B9221C4; Fri, 16 Apr 2021 15:34:56 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.33]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0BF8A5C3DF for ; Fri, 16 Apr 2021 15:34:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618587514; 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=NwQ4Wl4w+ow5+yRhlidYt8dNhTp5Ht45q9fhb5F+Vs0=; b=EtCPumO5C2HvLktz8sjPauJ+2PNogQdI/cmVH+r1B+gi2mmTem0epIJSfhH+3ae1gYVlAQ nzT32zjcqZPtMnmAyyKG8sYgsAukZF+13W9h+noeLfOmtpO53ggEqx2zIqe3RIOHB3Az9D lQ2Oz5VeZkQA6JkWutJoJhn2NJJAXAA= X-MC-Unique: VAzJ7qgrOUqN9vKERqsQdw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 07/25] conf: domain: Split out parsing of source data from XML parser Date: Fri, 16 Apr 2021 17:34:25 +0200 Message-Id: <9f2d0a7917f9c00d79f790d284fdd5b359cdea3a.1618587222.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" Extract all code related to parsing data which ends up in the 'src' member of a virDomainDiskDef. This allows to use the new function directly in virDomainDiskDefParseSource and removes the use of the VIR_DOMAIN_DEF_PARSE_DISK_SOURCE parser flag. Signed-off-by: Peter Krempa --- src/conf/domain_conf.c | 185 ++++++++++++++++++++++------------------- 1 file changed, 100 insertions(+), 85 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0eec4c9356..1793032301 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -9341,6 +9341,86 @@ virDomainDiskDefParsePrivateData(xmlXPathContextPtr = ctxt, } +static virStorageSource * +virDomainDiskDefParseSourceXML(virDomainXMLOption *xmlopt, + xmlNodePtr node, + xmlXPathContextPtr ctxt, + unsigned int flags) +{ + g_autoptr(virStorageSource) src =3D virStorageSourceNew(); + VIR_XPATH_NODE_AUTORESTORE(ctxt) + g_autofree char *type =3D NULL; + xmlNodePtr tmp; + + ctxt->node =3D node; + + src->type =3D VIR_STORAGE_TYPE_FILE; + + if ((type =3D virXMLPropString(node, "type")) && + (src->type =3D virStorageTypeFromString(type)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown disk type '%s'"), type); + return NULL; + } + + if ((tmp =3D virXPathNode("./source[1]", ctxt))) { + if (virDomainStorageSourceParse(tmp, ctxt, src, flags, xmlopt) < 0) + return NULL; + + if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) { + g_autofree char *sourceindex =3D NULL; + + if ((sourceindex =3D virXMLPropString(tmp, "index")) && + virStrToLong_uip(sourceindex, NULL, 10, &src->id) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("invalid disk index '%s'"), sourceindex); + return NULL; + } + } + } else { + /* Reset src->type in case when 'source' was not present */ + src->type =3D VIR_STORAGE_TYPE_FILE; + } + + if (virXPathNode("./readonly[1]", ctxt)) + src->readonly =3D true; + + if (virXPathNode("./shareable[1]", ctxt)) + src->shared =3D true; + + if ((tmp =3D virXPathNode("./auth", ctxt))) { + /* If we've already parsed and found an child, + * then generate an error to avoid ambiguity */ + if (src->auth) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("an definition already found for disk = source")); + return NULL; + } + + if (!(src->auth =3D virStorageAuthDefParse(tmp, ctxt))) + return NULL; + } + + if ((tmp =3D virXPathNode("./encryption", ctxt))) { + /* If we've already parsed and found an chil= d, + * then generate an error to avoid ambiguity */ + if (src->encryption) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("an definition already found for= disk source")); + return NULL; + } + + if (!(src->encryption =3D virStorageEncryptionParseNode(tmp, ctxt)= )) + return NULL; + } + + if (virDomainDiskBackingStoreParse(ctxt, src, flags, xmlopt) < 0) + return NULL; + + return g_steal_pointer(&src); +} + + static virDomainDiskDef * virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, xmlNodePtr node, @@ -9351,8 +9431,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, xmlNodePtr cur; VIR_XPATH_NODE_AUTORESTORE(ctxt) bool source =3D false; - g_autoptr(virStorageEncryption) encryption =3D NULL; - g_autoptr(virStorageAuthDef) authdef =3D NULL; g_autofree char *tmp =3D NULL; g_autofree char *snapshot =3D NULL; g_autofree char *rawio =3D NULL; @@ -9368,24 +9446,19 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, g_autofree char *product =3D NULL; g_autofree char *domain_name =3D NULL; g_autofree char *rotation_rate =3D NULL; + g_autoptr(virStorageSource) src =3D NULL; + + if (!(src =3D virDomainDiskDefParseSourceXML(xmlopt, node, ctxt, flags= ))) + return NULL; - if (!(def =3D virDomainDiskDefNew(xmlopt))) + if (!(def =3D virDomainDiskDefNewSource(xmlopt, &src))) return NULL; ctxt->node =3D node; /* defaults */ - def->src->type =3D VIR_STORAGE_TYPE_FILE; def->device =3D VIR_DOMAIN_DISK_DEVICE_DISK; - if ((tmp =3D virXMLPropString(node, "type")) && - (def->src->type =3D virStorageTypeFromString(tmp)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown disk type '%s'"), tmp); - return NULL; - } - VIR_FREE(tmp); - if ((tmp =3D virXMLPropString(node, "device")) && (def->device =3D virDomainDiskDeviceTypeFromString(tmp)) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -9412,9 +9485,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, continue; if (!source && virXMLNodeNameEqual(cur, "source")) { - if (virDomainStorageSourceParse(cur, ctxt, def->src, flags, xm= lopt) < 0) - return NULL; - source =3D true; if (virXMLPropEnum(cur, "startupPolicy", @@ -9423,13 +9493,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, &def->startupPolicy) < 0) return NULL; - if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) && - (tmp =3D virXMLPropString(cur, "index")) && - virStrToLong_uip(tmp, NULL, 10, &def->src->id) < 0) { - virReportError(VIR_ERR_XML_ERROR, _("invalid disk index '%= s'"), tmp); - return NULL; - } - VIR_FREE(tmp); } else if (!target && virXMLNodeNameEqual(cur, "target")) { target =3D virXMLPropString(cur, "dev"); @@ -9484,27 +9547,15 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, !(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) { if (virDomainDiskDefMirrorParse(def, cur, ctxt, flags, xmlopt)= < 0) return NULL; - } else if (!authdef && - virXMLNodeNameEqual(cur, "auth")) { - if (!(authdef =3D virStorageAuthDefParse(cur, ctxt))) - return NULL; + } else if (virXMLNodeNameEqual(cur, "auth")) { def->diskElementAuth =3D true; } else if (virXMLNodeNameEqual(cur, "iotune")) { if (virDomainDiskDefIotuneParse(def, ctxt) < 0) return NULL; - } else if (virXMLNodeNameEqual(cur, "readonly")) { - def->src->readonly =3D true; - } else if (virXMLNodeNameEqual(cur, "shareable")) { - def->src->shared =3D true; } else if (virXMLNodeNameEqual(cur, "transient")) { def->transient =3D true; - } else if (!encryption && - virXMLNodeNameEqual(cur, "encryption")) { - if (!(encryption =3D virStorageEncryptionParseNode(cur, ctxt))) - return NULL; - + } else if (virXMLNodeNameEqual(cur, "encryption")) { def->diskElementEnc =3D true; - } else if (!serial && virXMLNodeNameEqual(cur, "serial")) { if (!(serial =3D virXMLNodeContentString(cur))) @@ -9548,10 +9599,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, } } - /* Reset def->src->type in case when 'source' was not present */ - if (!source) - def->src->type =3D VIR_STORAGE_TYPE_FILE; - /* Only CDROM and Floppy devices are allowed missing source path * to indicate no media present. LUN is for raw access CD-ROMs * that are not attached to a physical device presently */ @@ -9676,40 +9723,12 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, } def->dst =3D g_steal_pointer(&target); - if (authdef) { - /* If we've already parsed and found an child, - * then generate an error to avoid ambiguity */ - if (def->src->auth) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("an definition already found for " - "disk source")); - return NULL; - } - - def->src->auth =3D g_steal_pointer(&authdef); - } - - if (encryption) { - /* If we've already parsed and found an = child, - * then generate an error to avoid ambiguity */ - if (def->src->encryption) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("an definition already found= for " - "disk source")); - return NULL; - } - - def->src->encryption =3D g_steal_pointer(&encryption); - } def->domain_name =3D g_steal_pointer(&domain_name); def->serial =3D g_steal_pointer(&serial); def->wwn =3D g_steal_pointer(&wwn); def->vendor =3D g_steal_pointer(&vendor); def->product =3D g_steal_pointer(&product); - if (virDomainDiskBackingStoreParse(ctxt, def->src, flags, xmlopt) < 0) - return NULL; - if (flags & VIR_DOMAIN_DEF_PARSE_STATUS && virDomainDiskDefParsePrivateData(ctxt, def, xmlopt) < 0) return NULL; @@ -9721,22 +9740,6 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, } -static virStorageSource * -virDomainDiskDefParseSourceXML(virDomainXMLOption *xmlopt, - xmlNodePtr node, - xmlXPathContextPtr ctxt, - unsigned int flags) -{ - g_autoptr(virDomainDiskDef) diskdef =3D NULL; - - if (!(diskdef =3D virDomainDiskDefParseXML(xmlopt, node, ctxt, - flags | VIR_DOMAIN_DEF_PARSE_= DISK_SOURCE))) - return NULL; - - return g_steal_pointer(&diskdef->src); -} - - /** * virDomainParseMemory: * @xpath: XPath to memory amount @@ -16484,11 +16487,23 @@ virDomainDiskDefParseSource(const char *xmlStr, { g_autoptr(xmlDoc) xml =3D NULL; g_autoptr(xmlXPathContext) ctxt =3D NULL; + g_autoptr(virStorageSource) src =3D NULL; if (!(xml =3D virXMLParseStringCtxtRoot(xmlStr, _("(disk_definition)")= , "disk", &ctxt))) return NULL; - return virDomainDiskDefParseSourceXML(xmlopt, ctxt->node, ctxt, flags); + if (!(src =3D virDomainDiskDefParseSourceXML(xmlopt, ctxt->node, ctxt,= flags))) + return NULL; + + if (virStorageSourceIsEmpty(src)) { + virReportError(VIR_ERR_NO_SOURCE, NULL); + return NULL; + } + + if (virDomainDiskDefParseValidateSource(src) < 0) + return NULL; + + return g_steal_pointer(&src); } --=20 2.30.2