From nobody Mon Feb 9 05:40:45 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=1600885300; cv=none; d=zohomail.com; s=zohoarc; b=ChwjAwx6Lpux62mH/pSlUQKu7nadS6Lp2bfdOKMhMcy19UDY/wzTelIMX85i49OB+z8gTBCHWjnqI3NaF6PgrpF5H/TX5hu2Wdj3bwUDGQQfOTmDZcI8OZfpuoANeWlBPluBrta3I8ettycZeSDRH3DloPOckkwfz+obpERjry4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600885300; 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=hAoJvm92GNmTLUtRTY7A67GCxkxC7ZMKWi12nh7GO7c=; b=BiAVJytDFGOZLuOj9w/J+okmZwuQy/7MICRU4h6wssENJ4KU6RWAxaj6xQYcoDmx8jrBDLC1dC62dfEi+Q5y5+MRkj73CrBfbPhyet1HJmBdHedSV/30WygrAqvjVMLBbJQUAThxy/u9q5PlarWZXYTvKlAQvoswXeZ58or0cr4= 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 1600885300125127.58708505272762; Wed, 23 Sep 2020 11:21:40 -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-147-n57Y_dvANQaUEqN-NxNmNA-1; Wed, 23 Sep 2020 14:21:34 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 24E94186843C; Wed, 23 Sep 2020 18:21: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 F00CC5577D; Wed, 23 Sep 2020 18:21: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 BD66A8C7AE; Wed, 23 Sep 2020 18:21:27 +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 08NILIiT018956 for ; Wed, 23 Sep 2020 14:21:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id EC1245C1DC; Wed, 23 Sep 2020 18:21:18 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7428C5C1C7 for ; Wed, 23 Sep 2020 18:21:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600885298; 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=hAoJvm92GNmTLUtRTY7A67GCxkxC7ZMKWi12nh7GO7c=; b=QksyfHWdLXcV4AGhoNl4e3O+9CHka4jxOeEPHfNip0eZW3hGCyrTokNbAieaJh2WunAxnZ hZoINZjuUgNDG7us+yhc1iYvwQGW0+2ZINp0AIAHdhFLZ4Lo0Wh5EWQMMt/lFZLe6pyjpG V34TdCuGSrQ0VtNrDgteCNyERC3Bdbg= X-MC-Unique: n57Y_dvANQaUEqN-NxNmNA-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/6] conf: split out virDomainDefParseIDs Date: Wed, 23 Sep 2020 20:21:07 +0200 Message-Id: <96b68edbc2574cf7da41abbe8a3063579c523567.1600885173.git.jtomko@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.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Signed-off-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 139 +++++++++++++++++++++++------------------ 1 file changed, 79 insertions(+), 60 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 22c6ba3b0d..c208cb91a6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21011,6 +21011,83 @@ virDomainCachetuneDefParse(virDomainDefPtr def, } =20 =20 +static int +virDomainDefParseIDs(virDomainDefPtr def, + xmlXPathContextPtr ctxt, + unsigned int flags, + bool *uuid_generated) +{ + g_autofree xmlNodePtr *nodes =3D NULL; + g_autofree char *tmp =3D NULL; + long id =3D -1; + int n; + + if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) + if (virXPathLong("string(./@id)", ctxt, &id) < 0) + id =3D -1; + def->id =3D (int)id; + + /* Extract domain name */ + if (!(def->name =3D virXPathString("string(./name[1])", ctxt))) { + virReportError(VIR_ERR_NO_NAME, NULL); + goto error; + } + + /* Extract domain uuid. If both uuid and sysinfo/system/entry/uuid + * exist, they must match; and if only the latter exists, it can + * also serve as the uuid. */ + tmp =3D virXPathString("string(./uuid[1])", ctxt); + if (!tmp) { + if (virUUIDGenerate(def->uuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("Failed to generate UUID")); + goto error; + } + *uuid_generated =3D true; + } else { + if (virUUIDParse(tmp, def->uuid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("malformed uuid element")); + goto error; + } + VIR_FREE(tmp); + } + + /* Extract domain genid - a genid can either be provided or generated = */ + if ((n =3D virXPathNodeSet("./genid", ctxt, &nodes)) < 0) + goto error; + + if (n > 0) { + if (n !=3D 1) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("element 'genid' can only appear once")); + goto error; + } + def->genidRequested =3D true; + if (!(tmp =3D virXPathString("string(./genid)", ctxt))) { + if (virUUIDGenerate(def->genid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("Failed to generate genid")); + goto error; + } + def->genidGenerated =3D true; + } else { + if (virUUIDParse(tmp, def->genid) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("malformed genid element")); + goto error; + } + VIR_FREE(tmp); + } + } + VIR_FREE(nodes); + return 0; + + error: + return -1; +} + + static int virDomainDefParseCaps(virDomainDefPtr def, xmlXPathContextPtr ctxt, @@ -21220,7 +21297,6 @@ virDomainDefParseXML(xmlDocPtr xml, xmlNodePtr node =3D NULL; size_t i, j; int n; - long id =3D -1; virDomainDefPtr def; bool uuid_generated =3D false; bool usb_none =3D false; @@ -21244,69 +21320,12 @@ virDomainDefParseXML(xmlDocPtr xml, if (!(def =3D virDomainDefNew())) return NULL; =20 - if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) - if (virXPathLong("string(./@id)", ctxt, &id) < 0) - id =3D -1; - def->id =3D (int)id; + if (virDomainDefParseIDs(def, ctxt, flags, &uuid_generated) < 0) + goto error; =20 if (virDomainDefParseCaps(def, ctxt, xmlopt) < 0) goto error; =20 - /* Extract domain name */ - if (!(def->name =3D virXPathString("string(./name[1])", ctxt))) { - virReportError(VIR_ERR_NO_NAME, NULL); - goto error; - } - - /* Extract domain uuid. If both uuid and sysinfo/system/entry/uuid - * exist, they must match; and if only the latter exists, it can - * also serve as the uuid. */ - tmp =3D virXPathString("string(./uuid[1])", ctxt); - if (!tmp) { - if (virUUIDGenerate(def->uuid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("Failed to generate UUID")); - goto error; - } - uuid_generated =3D true; - } else { - if (virUUIDParse(tmp, def->uuid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("malformed uuid element")); - goto error; - } - VIR_FREE(tmp); - } - - /* Extract domain genid - a genid can either be provided or generated = */ - if ((n =3D virXPathNodeSet("./genid", ctxt, &nodes)) < 0) - goto error; - - if (n > 0) { - if (n !=3D 1) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("element 'genid' can only appear once")); - goto error; - } - def->genidRequested =3D true; - if (!(tmp =3D virXPathString("string(./genid)", ctxt))) { - if (virUUIDGenerate(def->genid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("Failed to generate genid")); - goto error; - } - def->genidGenerated =3D true; - } else { - if (virUUIDParse(tmp, def->genid) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("malformed genid element")); - goto error; - } - VIR_FREE(tmp); - } - } - VIR_FREE(nodes); - /* Extract short description of domain (title) */ def->title =3D virXPathString("string(./title[1])", ctxt); if (def->title && strchr(def->title, '\n')) { --=20 2.26.2