From nobody Thu May 2 21:45:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=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 Reviewed-by: Michal Privoznik --- 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 From nobody Thu May 2 21:45:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1600885293; cv=none; d=zohomail.com; s=zohoarc; b=PEwKD1LBl8Jb2qO9vfSaa9f0VVWNCTeQzBvGC8gpqjkx2ty4s46KYJeJIovqIRISHEwlHkAgp0EpCpvO0qiAU5jcUtKDfPYf5WaDGUKnu/tzy1H+giAo23k6slsfRkYh074UlEo831sTBBjFrV8SwGOY5Y3ALsTixUb0a7Q12Xg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600885293; 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=Ks5LMgTdar5ksyp59QcXSdu+T91kvrkj/L094jLyAj0=; b=hFZkv22+E0ETOeSV+sEmePnRzM9vtpLA1M8fX2oYPK5V8DgT1hfykg0bJWmm1UxlnX6hRLlA9QRVDVvWgRqJB16VyJVpstk0k39GDQvgWnu8/u/UMH5gflyIBwAjfWC207JzYCYWrSuEdjOytu7m/xZ6RurzvAD/1yO0sl2kpu8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1600885293067495.5923306487193; Wed, 23 Sep 2020 11:21:33 -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-152-R9-a_KHPMMqZcJgilEN1Zw-1; Wed, 23 Sep 2020 14:21:28 -0400 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 4B5BF1DE1B; Wed, 23 Sep 2020 18:21:23 +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 022925D990; Wed, 23 Sep 2020 18:21:23 +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 7DAAC183D044; Wed, 23 Sep 2020 18:21:22 +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 08NILJQB018961 for ; Wed, 23 Sep 2020 14:21:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id BC98A5C1DC; Wed, 23 Sep 2020 18:21:19 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 44C6F5C1C7 for ; Wed, 23 Sep 2020 18:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600885291; 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=Ks5LMgTdar5ksyp59QcXSdu+T91kvrkj/L094jLyAj0=; b=hPIO0i8iAIQADujWk+LtsYbHli3kxchJ4FbbxrAZ2Hu5HcVNloK5Xx0oJN5ObEBVXXsGz7 8rZfjsZH8WoICqwKTkhRMIfVZy4E4FlKaQZI6KQ912oFPaG20RPfri74RMGTSN7bmRfbJ9 HC7id/Gh7AtcrLXAptUf8bKbOAb//M4= X-MC-Unique: R9-a_KHPMMqZcJgilEN1Zw-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/6] conf: split out virDomainDefParseMemory Date: Wed, 23 Sep 2020 20:21:08 +0200 Message-Id: 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.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-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 Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 209 ++++++++++++++++++++++------------------- 1 file changed, 114 insertions(+), 95 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c208cb91a6..2d420458c6 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21160,6 +21160,119 @@ virDomainDefParseCaps(virDomainDefPtr def, } =20 =20 +static int +virDomainDefParseMemory(virDomainDefPtr def, + xmlXPathContextPtr ctxt) +{ + g_autofree xmlNodePtr *nodes =3D NULL; + g_autofree char *tmp =3D NULL; + xmlNodePtr node =3D NULL; + size_t i; + int n; + + /* Extract domain memory */ + if (virDomainParseMemory("./memory[1]", NULL, ctxt, + &def->mem.total_memory, false, true) < 0) + goto error; + + if (virDomainParseMemory("./currentMemory[1]", NULL, ctxt, + &def->mem.cur_balloon, false, true) < 0) + goto error; + + if (virDomainParseMemory("./maxMemory[1]", NULL, ctxt, + &def->mem.max_memory, false, false) < 0) + goto error; + + if (virXPathUInt("string(./maxMemory[1]/@slots)", ctxt, &def->mem.memo= ry_slots) =3D=3D -2) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Failed to parse memory slot count")); + goto error; + } + + /* 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); + goto error; + } + VIR_FREE(tmp); + + tmp =3D virXPathString("string(./memoryBacking/source/@type)", ctxt); + if (tmp) { + if ((def->mem.source =3D virDomainMemorySourceTypeFromString(tmp))= <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown memoryBacking/source/type '%s'"), tm= p); + goto error; + } + VIR_FREE(tmp); + } + + tmp =3D virXPathString("string(./memoryBacking/access/@mode)", ctxt); + if (tmp) { + if ((def->mem.access =3D virDomainMemoryAccessTypeFromString(tmp))= <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown memoryBacking/access/mode '%s'"), tm= p); + goto error; + } + VIR_FREE(tmp); + } + + tmp =3D virXPathString("string(./memoryBacking/allocation/@mode)", ctx= t); + if (tmp) { + if ((def->mem.allocation =3D virDomainMemoryAllocationTypeFromStri= ng(tmp)) <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown memoryBacking/allocation/mode '%s'")= , tmp); + goto error; + } + VIR_FREE(tmp); + } + + if (virXPathNode("./memoryBacking/hugepages", ctxt)) { + /* hugepages will be used */ + if ((n =3D virXPathNodeSet("./memoryBacking/hugepages/page", ctxt,= &nodes)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("cannot extract hugepages nodes")); + goto error; + } + + if (n) { + if (VIR_ALLOC_N(def->mem.hugepages, n) < 0) + goto error; + + for (i =3D 0; i < n; i++) { + if (virDomainHugepagesParseXML(nodes[i], ctxt, + &def->mem.hugepages[i]) < 0) + goto error; + def->mem.nhugepages++; + } + + VIR_FREE(nodes); + } else { + /* no hugepage pages */ + if (VIR_ALLOC(def->mem.hugepages) < 0) + goto error; + + def->mem.nhugepages =3D 1; + } + } + + if ((node =3D virXPathNode("./memoryBacking/nosharepages", ctxt))) + def->mem.nosharepages =3D true; + + if (virXPathBoolean("boolean(./memoryBacking/locked)", ctxt)) + def->mem.locked =3D true; + + if (virXPathBoolean("boolean(./memoryBacking/discard)", ctxt)) + def->mem.discard =3D VIR_TRISTATE_BOOL_YES; + + return 0; + + error: + return -1; +} + + static int virDomainMemorytuneDefParseMemory(xmlXPathContextPtr ctxt, xmlNodePtr node, @@ -21344,102 +21457,8 @@ virDomainDefParseXML(xmlDocPtr xml, goto error; } =20 - /* Extract domain memory */ - if (virDomainParseMemory("./memory[1]", NULL, ctxt, - &def->mem.total_memory, false, true) < 0) + if (virDomainDefParseMemory(def, ctxt) < 0) goto error; - - if (virDomainParseMemory("./currentMemory[1]", NULL, ctxt, - &def->mem.cur_balloon, false, true) < 0) - goto error; - - if (virDomainParseMemory("./maxMemory[1]", NULL, ctxt, - &def->mem.max_memory, false, false) < 0) - goto error; - - if (virXPathUInt("string(./maxMemory[1]/@slots)", ctxt, &def->mem.memo= ry_slots) =3D=3D -2) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Failed to parse memory slot count")); - goto error; - } - - /* 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); - goto error; - } - VIR_FREE(tmp); - - tmp =3D virXPathString("string(./memoryBacking/source/@type)", ctxt); - if (tmp) { - if ((def->mem.source =3D virDomainMemorySourceTypeFromString(tmp))= <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown memoryBacking/source/type '%s'"), tm= p); - goto error; - } - VIR_FREE(tmp); - } - - tmp =3D virXPathString("string(./memoryBacking/access/@mode)", ctxt); - if (tmp) { - if ((def->mem.access =3D virDomainMemoryAccessTypeFromString(tmp))= <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown memoryBacking/access/mode '%s'"), tm= p); - goto error; - } - VIR_FREE(tmp); - } - - tmp =3D virXPathString("string(./memoryBacking/allocation/@mode)", ctx= t); - if (tmp) { - if ((def->mem.allocation =3D virDomainMemoryAllocationTypeFromStri= ng(tmp)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown memoryBacking/allocation/mode '%s'")= , tmp); - goto error; - } - VIR_FREE(tmp); - } - - if (virXPathNode("./memoryBacking/hugepages", ctxt)) { - /* hugepages will be used */ - if ((n =3D virXPathNodeSet("./memoryBacking/hugepages/page", ctxt,= &nodes)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("cannot extract hugepages nodes")); - goto error; - } - - if (n) { - if (VIR_ALLOC_N(def->mem.hugepages, n) < 0) - goto error; - - for (i =3D 0; i < n; i++) { - if (virDomainHugepagesParseXML(nodes[i], ctxt, - &def->mem.hugepages[i]) < 0) - goto error; - def->mem.nhugepages++; - } - - VIR_FREE(nodes); - } else { - /* no hugepage pages */ - if (VIR_ALLOC(def->mem.hugepages) < 0) - goto error; - - def->mem.nhugepages =3D 1; - } - } - - if ((node =3D virXPathNode("./memoryBacking/nosharepages", ctxt))) - def->mem.nosharepages =3D true; - - if (virXPathBoolean("boolean(./memoryBacking/locked)", ctxt)) - def->mem.locked =3D true; - - if (virXPathBoolean("boolean(./memoryBacking/discard)", ctxt)) - def->mem.discard =3D VIR_TRISTATE_BOOL_YES; - /* Extract blkio cgroup tunables */ if (virXPathUInt("string(./blkiotune/weight)", ctxt, &def->blkio.weight) < 0) --=20 2.26.2 From nobody Thu May 2 21:45:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1600885293; cv=none; d=zohomail.com; s=zohoarc; b=kXIYclZOfdkfRzMUIUZdW7rhLXH9PvyqmcjZYSHa6e88ATKrSvWNZtn8CjuJXtQ1/VaJyn1DXexEToLOdiAoUCYHfhQa00r8COz//1BTj1FOQFLL51q2dDv13f/g2ZPpehgm3rev//d4aDGdBCZJm6KwCpKVzpHZ0KJ2QyDdJB8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600885293; 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=CCL5DgNodpQ4keVvLw0F8VIPhmapGLLwfQn8ZVY3vIs=; b=Czz1CMy9Ih+8HnCpDmbXT4tT4o0VKu8RKNBZ6ScMtX1LDJWorerPpu55XlVRXzzF3jnm0SrU75wUSgnpcf1o1FNh3vjlEE15/PGAzFw5SXeHYxRxF3NhlZxVMkJ8SjacIzI7IWO2PI65JNJe2Onwg+/D76k7MeeUSpsXLRBGq5c= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1600885293053698.8676177713322; Wed, 23 Sep 2020 11:21:33 -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-488-zJAhP_RbPoSfJINCoC97hg-1; Wed, 23 Sep 2020 14:21:29 -0400 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 C3C8C801001; Wed, 23 Sep 2020 18:21:23 +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 9FDBD78816; Wed, 23 Sep 2020 18:21:23 +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 4DF27183D044; Wed, 23 Sep 2020 18:21:23 +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 08NILK7k018969 for ; Wed, 23 Sep 2020 14:21:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8E18D5C1DC; Wed, 23 Sep 2020 18:21:20 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15A895C1C7 for ; Wed, 23 Sep 2020 18:21:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600885291; 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=CCL5DgNodpQ4keVvLw0F8VIPhmapGLLwfQn8ZVY3vIs=; b=ZHOk59ojnjo5VUYwxCBIkXgCC2UQOBd2fMgL3ZKKwip7S78YLYRrL/76Mx0bqEmw/saW9u V2YOApWboITA6rl+zuBbqXPs+WViR1bky+K/fkoZcaE3FW9G3oH3sQxlDcviK8pnUnEO8/ NYI6HtJn5HyTUTvFGXCWGN3aK8LIV3I= X-MC-Unique: zJAhP_RbPoSfJINCoC97hg-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 3/6] conf: introduce virDomainDefTunablesParse Date: Wed, 23 Sep 2020 20:21:09 +0200 Message-Id: <4c32063535f78edf19141ec0ae023c5142d0a1ed.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.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-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 Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 129 ++++++++++++++++++++++++----------------- 1 file changed, 75 insertions(+), 54 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 2d420458c6..c12cc1f216 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21401,64 +21401,16 @@ virDomainMemorytuneDefParse(virDomainDefPtr def, } =20 =20 -static virDomainDefPtr -virDomainDefParseXML(xmlDocPtr xml, - xmlXPathContextPtr ctxt, - virDomainXMLOptionPtr xmlopt, - unsigned int flags) +static int +virDomainDefTunablesParse(virDomainDefPtr def, + xmlXPathContextPtr ctxt, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) { - xmlNodePtr node =3D NULL; + g_autofree xmlNodePtr *nodes =3D NULL; size_t i, j; int n; - virDomainDefPtr def; - bool uuid_generated =3D false; - bool usb_none =3D false; - bool usb_other =3D false; - bool usb_master =3D false; - g_autofree xmlNodePtr *nodes =3D NULL; - g_autofree char *tmp =3D NULL; =20 - if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) { - g_autofree char *schema =3D NULL; - - schema =3D virFileFindResource("domain.rng", - abs_top_srcdir "/docs/schemas", - PKGDATADIR "/schemas"); - if (!schema) - return NULL; - if (virXMLValidateAgainstSchema(schema, xml) < 0) - return NULL; - } - - if (!(def =3D virDomainDefNew())) - return NULL; - - if (virDomainDefParseIDs(def, ctxt, flags, &uuid_generated) < 0) - goto error; - - if (virDomainDefParseCaps(def, ctxt, xmlopt) < 0) - goto error; - - /* Extract short description of domain (title) */ - def->title =3D virXPathString("string(./title[1])", ctxt); - if (def->title && strchr(def->title, '\n')) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("Domain title can't contain newlines")); - goto error; - } - - /* Extract documentation if present */ - def->description =3D virXPathString("string(./description[1])", ctxt); - - /* analysis of security label, done early even though we format it - * late, so devices can refer to this for defaults */ - if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL)) { - if (virSecurityLabelDefsParseXML(def, ctxt, xmlopt, flags) =3D=3D = -1) - goto error; - } - - if (virDomainDefParseMemory(def, ctxt) < 0) - goto error; /* Extract blkio cgroup tunables */ if (virXPathUInt("string(./blkiotune/weight)", ctxt, &def->blkio.weight) < 0) @@ -21687,6 +21639,75 @@ virDomainDefParseXML(xmlDocPtr xml, } VIR_FREE(nodes); =20 + return 0; + + error: + return -1; +} + + +static virDomainDefPtr +virDomainDefParseXML(xmlDocPtr xml, + xmlXPathContextPtr ctxt, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + xmlNodePtr node =3D NULL; + size_t i, j; + int n; + virDomainDefPtr def; + bool uuid_generated =3D false; + bool usb_none =3D false; + bool usb_other =3D false; + bool usb_master =3D false; + g_autofree xmlNodePtr *nodes =3D NULL; + g_autofree char *tmp =3D NULL; + + if (flags & VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA) { + g_autofree char *schema =3D NULL; + + schema =3D virFileFindResource("domain.rng", + abs_top_srcdir "/docs/schemas", + PKGDATADIR "/schemas"); + if (!schema) + return NULL; + if (virXMLValidateAgainstSchema(schema, xml) < 0) + return NULL; + } + + if (!(def =3D virDomainDefNew())) + return NULL; + + if (virDomainDefParseIDs(def, ctxt, flags, &uuid_generated) < 0) + goto error; + + if (virDomainDefParseCaps(def, ctxt, xmlopt) < 0) + goto error; + + /* Extract short description of domain (title) */ + def->title =3D virXPathString("string(./title[1])", ctxt); + if (def->title && strchr(def->title, '\n')) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("Domain title can't contain newlines")); + goto error; + } + + /* Extract documentation if present */ + def->description =3D virXPathString("string(./description[1])", ctxt); + + /* analysis of security label, done early even though we format it + * late, so devices can refer to this for defaults */ + if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_SECLABEL)) { + if (virSecurityLabelDefsParseXML(def, ctxt, xmlopt, flags) =3D=3D = -1) + goto error; + } + + if (virDomainDefParseMemory(def, ctxt) < 0) + goto error; + + if (virDomainDefTunablesParse(def, ctxt, xmlopt, flags) < 0) + goto error; + if (virCPUDefParseXML(ctxt, "./cpu[1]", VIR_CPU_TYPE_GUEST, &def->cpu)= < 0) goto error; =20 --=20 2.26.2 From nobody Thu May 2 21:45:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600885299; cv=none; d=zohomail.com; s=zohoarc; b=Uff12LiIXfk4YSEIxQGmxxvuH0xpLdhgh/gbpdMSJb/LE+pQFt4rjhrE9bwcoKbK7JPci8rhGajTEBvC3gctzA4fNJkOTPcPc/nU5Ow7+qYZdNNc8ArEx/V38aq7O2m8f8wAsChQOE36BbdZtoxteQbCGl5Y/0WJ4evD5jpl0ck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600885299; 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=UgKBlgLBUuysNmtgkhKMQ3ZOPdGwFI2KB5fksC88a1I=; b=LgNdxrZi69K/HSOf2/6/drZIb2CXAAwLn7lCb2teoHYZx14u+VL7mcQSiJvAYHcUyxLUe/WjFQoXMRUIyoBmKAZIeenOBgFOWYWn17ZAN/sTaSIlcgxrut+PoeVtwPcEE5WMYZUNWw36l3LOIQt15H+Hlvpu+4TO1nEYfJ7kS1Y= 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 1600885299760578.9463070891211; Wed, 23 Sep 2020 11:21:39 -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-237-H2yrOLd4OOemaeADN4DJKw-1; Wed, 23 Sep 2020 14:21:35 -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 4A90E109107C; Wed, 23 Sep 2020 18:21: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 294025C22B; Wed, 23 Sep 2020 18:21:28 +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 E8493183D04A; 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 08NILLt3018979 for ; Wed, 23 Sep 2020 14:21:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6010C5C1DC; Wed, 23 Sep 2020 18:21:21 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id DB34C5C1C7 for ; Wed, 23 Sep 2020 18:21:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600885297; 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=UgKBlgLBUuysNmtgkhKMQ3ZOPdGwFI2KB5fksC88a1I=; b=NXsVxm5ZRB7f/RO96MzAZBttWxYcT8ABPMiQeGcg9CqOMZMHvYyIegPLiSawo35cN18p+8 gM9GE7LC3EafsCKos0CDO0ZzebP+dVMxUVrRa5MU0VXoFLd101yOwTi16o6XLXddPaXLRH nVQcRGffIXRhZApz/T3fa/4snCtf7EQ= X-MC-Unique: H2yrOLd4OOemaeADN4DJKw-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 4/6] conf: introduce virDomainDefLifecycleParse Date: Wed, 23 Sep 2020 20:21:10 +0200 Message-Id: <31c8993cbdc913e5cde4e739234470e41f386f79.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.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: J=C3=A1n Tomko Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 86 ++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 36 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c12cc1f216..41dba831ce 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21646,6 +21646,55 @@ virDomainDefTunablesParse(virDomainDefPtr def, } =20 =20 +static int +virDomainDefLifecycleParse(virDomainDefPtr def, + xmlXPathContextPtr ctxt) +{ + if (virDomainEventActionParseXML(ctxt, "on_reboot", + "string(./on_reboot[1])", + &def->onReboot, + VIR_DOMAIN_LIFECYCLE_ACTION_RESTART, + virDomainLifecycleActionTypeFromStrin= g) < 0) + goto error; + + if (virDomainEventActionParseXML(ctxt, "on_poweroff", + "string(./on_poweroff[1])", + &def->onPoweroff, + VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY, + virDomainLifecycleActionTypeFromStrin= g) < 0) + goto error; + + if (virDomainEventActionParseXML(ctxt, "on_crash", + "string(./on_crash[1])", + &def->onCrash, + VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY, + virDomainLifecycleActionTypeFromStrin= g) < 0) + goto error; + + if (virDomainEventActionParseXML(ctxt, "on_lockfailure", + "string(./on_lockfailure[1])", + &def->onLockFailure, + VIR_DOMAIN_LOCK_FAILURE_DEFAULT, + virDomainLockFailureTypeFromString) <= 0) + goto error; + + if (virDomainPMStateParseXML(ctxt, + "string(./pm/suspend-to-mem/@enabled)", + &def->pm.s3) < 0) + goto error; + + if (virDomainPMStateParseXML(ctxt, + "string(./pm/suspend-to-disk/@enabled)", + &def->pm.s4) < 0) + goto error; + + return 0; + + error: + return -1; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlXPathContextPtr ctxt, @@ -21759,42 +21808,7 @@ virDomainDefParseXML(xmlDocPtr xml, if (virDomainFeaturesDefParse(def, ctxt) < 0) goto error; =20 - if (virDomainEventActionParseXML(ctxt, "on_reboot", - "string(./on_reboot[1])", - &def->onReboot, - VIR_DOMAIN_LIFECYCLE_ACTION_RESTART, - virDomainLifecycleActionTypeFromStrin= g) < 0) - goto error; - - if (virDomainEventActionParseXML(ctxt, "on_poweroff", - "string(./on_poweroff[1])", - &def->onPoweroff, - VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY, - virDomainLifecycleActionTypeFromStrin= g) < 0) - goto error; - - if (virDomainEventActionParseXML(ctxt, "on_crash", - "string(./on_crash[1])", - &def->onCrash, - VIR_DOMAIN_LIFECYCLE_ACTION_DESTROY, - virDomainLifecycleActionTypeFromStrin= g) < 0) - goto error; - - if (virDomainEventActionParseXML(ctxt, "on_lockfailure", - "string(./on_lockfailure[1])", - &def->onLockFailure, - VIR_DOMAIN_LOCK_FAILURE_DEFAULT, - virDomainLockFailureTypeFromString) <= 0) - goto error; - - if (virDomainPMStateParseXML(ctxt, - "string(./pm/suspend-to-mem/@enabled)", - &def->pm.s3) < 0) - goto error; - - if (virDomainPMStateParseXML(ctxt, - "string(./pm/suspend-to-disk/@enabled)", - &def->pm.s4) < 0) + if (virDomainDefLifecycleParse(def, ctxt) < 0) goto error; =20 if (virDomainPerfDefParseXML(def, ctxt) < 0) --=20 2.26.2 From nobody Thu May 2 21:45:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1600885327; cv=none; d=zohomail.com; s=zohoarc; b=UZW897udJX+Lgw5y1CN8KgZG5AaDoEqySb3IGVuGWMEPebUal2Nj8fuFfCY164Rpl2VxwmmGyijw4V45vSIrXIw/6ZePtbaUKjjXihyyXzuS5L1xqFeNod7ivoFzvVFl/GbQlk6yI2NlP6xV+x+oVED8VWU2LMxF7QGUNaIajm0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600885327; 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=VgpDKyzy9nAG1Ko5j54zR4xV2JooRu3ooKB2lkt5k1c=; b=F0gh3QVXCvRBC5E22zR6DM/AyTbBxdQO39HDR88VrcAnOFb7HSjGXWjQ5797EoCJ4h+ZrUTePRhveSHsOdmpBsiwMsgUwulr2N0SuVzD8VehqzbPTvR+H/H94L+t/7QBpkVVM/t2viQmIDzpXYIUpx2UStH0rPJKhIaloA5rWCY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.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 [63.128.21.124]) by mx.zohomail.com with SMTPS id 1600885327217502.8914068459609; Wed, 23 Sep 2020 11:22:07 -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-504-xpIgliMaOZaS5cXOL1Gslw-1; Wed, 23 Sep 2020 14:21:38 -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 14A7F1006713; Wed, 23 Sep 2020 18:21:31 +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 E2B2A19728; Wed, 23 Sep 2020 18:21: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 AAEE9183D04F; Wed, 23 Sep 2020 18:21:30 +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 08NILMUT018987 for ; Wed, 23 Sep 2020 14:21:22 -0400 Received: by smtp.corp.redhat.com (Postfix) id 31D0E5C22B; Wed, 23 Sep 2020 18:21:22 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id AD8515C1C7 for ; Wed, 23 Sep 2020 18:21:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600885326; 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=VgpDKyzy9nAG1Ko5j54zR4xV2JooRu3ooKB2lkt5k1c=; b=dww2poW54XB6BsgRDHIhzTLnWZ1jmzm4oNxzdQn6P5i6uz+dlv6gP2/HYPWZi2Ujy7dBlK OsTIJuiqoQIN2Aj57A+OxpEm1ZC7jlSF7c1qYEPQ+MV3wqd2c7u9ElRcnrnSQqTIfmgWAF P6LDZZU6jiSEoyNQXwMlXIUPLRQsHzY= X-MC-Unique: xpIgliMaOZaS5cXOL1Gslw-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 5/6] conf: introduce virDomainDefClockParse Date: Wed, 23 Sep 2020 20:21:11 +0200 Message-Id: <306c4cabe497ff9de7456becce03aa067f5b0efc.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.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-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 Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 185 +++++++++++++++++++++++------------------ 1 file changed, 102 insertions(+), 83 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 41dba831ce..ccfe32685c 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21695,6 +21695,107 @@ virDomainDefLifecycleParse(virDomainDefPtr def, } =20 =20 +static int +virDomainDefClockParse(virDomainDefPtr def, + xmlXPathContextPtr ctxt) +{ + size_t i; + int n; + g_autofree xmlNodePtr *nodes =3D NULL; + g_autofree char *tmp =3D NULL; + + if ((tmp =3D virXPathString("string(./clock/@offset)", ctxt)) && + (def->clock.offset =3D virDomainClockOffsetTypeFromString(tmp)) < = 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown clock offset '%s'"), tmp); + goto error; + } + VIR_FREE(tmp); + + switch (def->clock.offset) { + case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: + case VIR_DOMAIN_CLOCK_OFFSET_UTC: + tmp =3D virXPathString("string(./clock/@adjustment)", ctxt); + if (tmp) { + if (STREQ(tmp, "reset")) { + def->clock.data.utc_reset =3D true; + } else { + if (virStrToLong_ll(tmp, NULL, 10, + &def->clock.data.variable.adjustment) = < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("unknown clock adjustment '%s'"), + tmp); + goto error; + } + switch (def->clock.offset) { + case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: + def->clock.data.variable.basis =3D VIR_DOMAIN_CLOCK_BA= SIS_LOCALTIME; + break; + case VIR_DOMAIN_CLOCK_OFFSET_UTC: + def->clock.data.variable.basis =3D VIR_DOMAIN_CLOCK_BA= SIS_UTC; + break; + } + def->clock.offset =3D VIR_DOMAIN_CLOCK_OFFSET_VARIABLE; + } + VIR_FREE(tmp); + } else { + def->clock.data.utc_reset =3D false; + } + break; + + case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE: + if (virXPathLongLong("number(./clock/@adjustment)", ctxt, + &def->clock.data.variable.adjustment) < 0) + def->clock.data.variable.adjustment =3D 0; + if (virXPathLongLong("number(./clock/@adjustment0)", ctxt, + &def->clock.data.variable.adjustment0) < 0) + def->clock.data.variable.adjustment0 =3D 0; + tmp =3D virXPathString("string(./clock/@basis)", ctxt); + if (tmp) { + if ((def->clock.data.variable.basis =3D virDomainClockBasisTyp= eFromString(tmp)) < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown clock basis '%s'"), tmp); + goto error; + } + VIR_FREE(tmp); + } else { + def->clock.data.variable.basis =3D VIR_DOMAIN_CLOCK_BASIS_UTC; + } + break; + + case VIR_DOMAIN_CLOCK_OFFSET_TIMEZONE: + def->clock.data.timezone =3D virXPathString("string(./clock/@timez= one)", ctxt); + if (!def->clock.data.timezone) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing 'timezone' attribute for clock with = offset=3D'timezone'")); + goto error; + } + break; + } + + if ((n =3D virXPathNodeSet("./clock/timer", ctxt, &nodes)) < 0) + goto error; + + if (n && VIR_ALLOC_N(def->clock.timers, n) < 0) + goto error; + + for (i =3D 0; i < n; i++) { + virDomainTimerDefPtr timer =3D virDomainTimerDefParseXML(nodes[i], + ctxt); + if (!timer) + goto error; + + def->clock.timers[def->clock.ntimers++] =3D timer; + } + VIR_FREE(nodes); + + return 0; + + error: + return -1; +} + + static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, xmlXPathContextPtr ctxt, @@ -21814,90 +21915,8 @@ virDomainDefParseXML(xmlDocPtr xml, if (virDomainPerfDefParseXML(def, ctxt) < 0) goto error; =20 - if ((tmp =3D virXPathString("string(./clock/@offset)", ctxt)) && - (def->clock.offset =3D virDomainClockOffsetTypeFromString(tmp)) < = 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown clock offset '%s'"), tmp); + if (virDomainDefClockParse(def, ctxt) < 0) goto error; - } - VIR_FREE(tmp); - - switch (def->clock.offset) { - case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: - case VIR_DOMAIN_CLOCK_OFFSET_UTC: - tmp =3D virXPathString("string(./clock/@adjustment)", ctxt); - if (tmp) { - if (STREQ(tmp, "reset")) { - def->clock.data.utc_reset =3D true; - } else { - if (virStrToLong_ll(tmp, NULL, 10, - &def->clock.data.variable.adjustment) = < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown clock adjustment '%s'"), - tmp); - goto error; - } - switch (def->clock.offset) { - case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: - def->clock.data.variable.basis =3D VIR_DOMAIN_CLOCK_BA= SIS_LOCALTIME; - break; - case VIR_DOMAIN_CLOCK_OFFSET_UTC: - def->clock.data.variable.basis =3D VIR_DOMAIN_CLOCK_BA= SIS_UTC; - break; - } - def->clock.offset =3D VIR_DOMAIN_CLOCK_OFFSET_VARIABLE; - } - VIR_FREE(tmp); - } else { - def->clock.data.utc_reset =3D false; - } - break; - - case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE: - if (virXPathLongLong("number(./clock/@adjustment)", ctxt, - &def->clock.data.variable.adjustment) < 0) - def->clock.data.variable.adjustment =3D 0; - if (virXPathLongLong("number(./clock/@adjustment0)", ctxt, - &def->clock.data.variable.adjustment0) < 0) - def->clock.data.variable.adjustment0 =3D 0; - tmp =3D virXPathString("string(./clock/@basis)", ctxt); - if (tmp) { - if ((def->clock.data.variable.basis =3D virDomainClockBasisTyp= eFromString(tmp)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown clock basis '%s'"), tmp); - goto error; - } - VIR_FREE(tmp); - } else { - def->clock.data.variable.basis =3D VIR_DOMAIN_CLOCK_BASIS_UTC; - } - break; - - case VIR_DOMAIN_CLOCK_OFFSET_TIMEZONE: - def->clock.data.timezone =3D virXPathString("string(./clock/@timez= one)", ctxt); - if (!def->clock.data.timezone) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("missing 'timezone' attribute for clock with = offset=3D'timezone'")); - goto error; - } - break; - } - - if ((n =3D virXPathNodeSet("./clock/timer", ctxt, &nodes)) < 0) - goto error; - - if (n && VIR_ALLOC_N(def->clock.timers, n) < 0) - goto error; - - for (i =3D 0; i < n; i++) { - virDomainTimerDefPtr timer =3D virDomainTimerDefParseXML(nodes[i], - ctxt); - if (!timer) - goto error; - - def->clock.timers[def->clock.ntimers++] =3D timer; - } - VIR_FREE(nodes); =20 if (virDomainDefParseBootOptions(def, ctxt) < 0) goto error; --=20 2.26.2 From nobody Thu May 2 21:45:46 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600885299; cv=none; d=zohomail.com; s=zohoarc; b=kJ087vZG9cnrT/++9//aFqVjx01oglmce+jwEuVJn9DuXwxN2YJtBgMgMwCDcSrH9kjegcYWd+8UNDrVQtsWUkcOSCeQ3fFKr3Ya9WoQO37Jq3kdCvMg30KVVreF+Eqg3ug9dbwYDfOlNMeLarUYG/keVp245JhcANFcGe6qSVc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600885299; 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=weO2xGHWp0mGfxG0lb3GmlgqCQyayZ957d+lAJOQEaI=; b=fwo/iO0YnEBMrE8qUro+1jivX0ZJdKrdDl1o6LxCGOsLWAVaGlxjthzeS/C6CWD8x3RsjNY/XqC0qKH2W1LUMIGQgZyi+FYsK7BlBul0TtRujNho6tfzxEYkdLGf5t271WvFRcoqJOgtSicKUnQxlCm5sKh5M/rbX75240Nocko= 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 1600885299794113.39132410890534; Wed, 23 Sep 2020 11:21:39 -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-489-ubUD85G6ODC4bWyLsTixtA-1; Wed, 23 Sep 2020 14:21:36 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 23D2E81F00B; 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 034B173668; Wed, 23 Sep 2020 18:21:28 +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 C1EA38C7B9; 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 08NILQ49019013 for ; Wed, 23 Sep 2020 14:21:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 728495C22B; Wed, 23 Sep 2020 18:21:26 +0000 (UTC) Received: from hjs.redhat.com (unknown [10.43.2.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id EF3E85C26B for ; Wed, 23 Sep 2020 18:21:22 +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=weO2xGHWp0mGfxG0lb3GmlgqCQyayZ957d+lAJOQEaI=; b=ZMlvsAPfBPsg8CmhYAkBTknlARVgBGBsbgLbzDodjI2g+0R4W+bNotMLJKpr1ksg2NAjhJ wIG0YSLEnw0ZIomBD71Vh+50QwaHGoSKKVEOsudD70QuPDZJUl5Tc7CPwKRhiNK4DuK/hp U1GseieYF4hHnt7JbkafKpNFLFiYQ74= X-MC-Unique: ubUD85G6ODC4bWyLsTixtA-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 6/6] conf: introduce virDomainDefControllersParse Date: Wed, 23 Sep 2020 20:21:12 +0200 Message-Id: <18f4657c289468861690588bdba08701a872d9d4.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.13 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 Reviewed-by: Michal Privoznik --- src/conf/domain_conf.c | 122 +++++++++++++++++++++++------------------ 1 file changed, 70 insertions(+), 52 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ccfe32685c..680524ce08 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21795,6 +21795,75 @@ virDomainDefClockParse(virDomainDefPtr def, return -1; } =20 +static int +virDomainDefControllersParse(virDomainDefPtr def, + xmlXPathContextPtr ctxt, + virDomainXMLOptionPtr xmlopt, + unsigned int flags, + bool *usb_none) +{ + g_autofree xmlNodePtr *nodes =3D NULL; + bool usb_other =3D false; + bool usb_master =3D false; + size_t i; + int n; + + if ((n =3D virXPathNodeSet("./devices/controller", ctxt, &nodes)) < 0) + goto error; + + if (n && VIR_ALLOC_N(def->controllers, n) < 0) + goto error; + + for (i =3D 0; i < n; i++) { + virDomainControllerDefPtr controller =3D virDomainControllerDefPar= seXML(xmlopt, + = nodes[i], + = ctxt, + = flags); + + if (!controller) + goto error; + + /* sanitize handling of "none" usb controller */ + if (controller->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_USB) { + if (controller->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_N= ONE) { + if (usb_other || *usb_none) { + virDomainControllerDefFree(controller); + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("Can't add another USB controller: " + "USB is disabled for this domain")); + goto error; + } + *usb_none =3D true; + } else { + if (*usb_none) { + virDomainControllerDefFree(controller); + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("Can't add another USB controller: " + "USB is disabled for this domain")); + goto error; + } + usb_other =3D true; + } + + if (controller->info.mastertype =3D=3D VIR_DOMAIN_CONTROLLER_M= ASTER_NONE) + usb_master =3D true; + } + + virDomainControllerInsertPreAlloced(def, controller); + } + VIR_FREE(nodes); + + if (usb_other && !usb_master) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("No master USB controller specified")); + goto error; + } + + return 0; + + error: + return -1; +} =20 static virDomainDefPtr virDomainDefParseXML(xmlDocPtr xml, @@ -21808,8 +21877,6 @@ virDomainDefParseXML(xmlDocPtr xml, virDomainDefPtr def; bool uuid_generated =3D false; bool usb_none =3D false; - bool usb_other =3D false; - bool usb_master =3D false; g_autofree xmlNodePtr *nodes =3D NULL; g_autofree char *tmp =3D NULL; =20 @@ -21940,58 +22007,9 @@ virDomainDefParseXML(xmlDocPtr xml, } VIR_FREE(nodes); =20 - /* analysis of the controller devices */ - if ((n =3D virXPathNodeSet("./devices/controller", ctxt, &nodes)) < 0) + if (virDomainDefControllersParse(def, ctxt, xmlopt, flags, &usb_none) = < 0) goto error; =20 - if (n && VIR_ALLOC_N(def->controllers, n) < 0) - goto error; - - for (i =3D 0; i < n; i++) { - virDomainControllerDefPtr controller =3D virDomainControllerDefPar= seXML(xmlopt, - = nodes[i], - = ctxt, - = flags); - - if (!controller) - goto error; - - /* sanitize handling of "none" usb controller */ - if (controller->type =3D=3D VIR_DOMAIN_CONTROLLER_TYPE_USB) { - if (controller->model =3D=3D VIR_DOMAIN_CONTROLLER_MODEL_USB_N= ONE) { - if (usb_other || usb_none) { - virDomainControllerDefFree(controller); - virReportError(VIR_ERR_XML_DETAIL, "%s", - _("Can't add another USB controller: " - "USB is disabled for this domain")); - goto error; - } - usb_none =3D true; - } else { - if (usb_none) { - virDomainControllerDefFree(controller); - virReportError(VIR_ERR_XML_DETAIL, "%s", - _("Can't add another USB controller: " - "USB is disabled for this domain")); - goto error; - } - usb_other =3D true; - } - - if (controller->info.mastertype =3D=3D VIR_DOMAIN_CONTROLLER_M= ASTER_NONE) - usb_master =3D true; - } - - virDomainControllerInsertPreAlloced(def, controller); - } - VIR_FREE(nodes); - - if (usb_other && !usb_master) { - virReportError(VIR_ERR_XML_DETAIL, "%s", - _("No master USB controller specified")); - goto error; - } - /* analysis of the resource leases */ if ((n =3D virXPathNodeSet("./devices/lease", ctxt, &nodes)) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, --=20 2.26.2