From nobody Mon Feb 9 06:27:07 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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=1598559618; cv=none; d=zohomail.com; s=zohoarc; b=ehPywcRI4pd+m2IvxaZxx+yaSv5XdnnZOfPIg7cwK13Ge56nzUg6YUHXB2QDHpu1GrVRmZU4dX5bSUbHV5qsUx0R1v0sKLHkEyvRpPohMcfaObH6oqESSneAdUuNwZWHDVF6GuSoy+DObxZqjS6G/DrAvEykBFY5vW+r3XKypi0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1598559618; 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=D9226d0tXiUWZZEUNdx7iF1J7GmE0Smen5RB6xsoHh8=; b=I3ILPPPFDJQByCqaQi53mrpJ1Rglsv8UxWc3F0Nr3RR0u8WKHnL4vecW1IGyXG5oh5Hp+l0G/ZDMQVVsjcmF6Asdj5Vm5aoAfMKL6krJ8qLgIedVmTC3iMr7Qj0In7Gt8CGOeZNDApgvxr05V32CZWrh2IiKzMfORBFCnprCMPM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1598559618216434.89695147247846; Thu, 27 Aug 2020 13:20:18 -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-498-RWv6OsO9OdyqQIHV0PL1Fg-1; Thu, 27 Aug 2020 16:20:14 -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 93FE356BE8; Thu, 27 Aug 2020 20:20:08 +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 67C215C1C2; Thu, 27 Aug 2020 20:20:07 +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 AD82718408AB; Thu, 27 Aug 2020 20:20:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 07RKK1Gb029052 for ; Thu, 27 Aug 2020 16:20:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7F62119D7C; Thu, 27 Aug 2020 20:20:01 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.40.208.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id DFA1D19C71 for ; Thu, 27 Aug 2020 20:20:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1598559617; 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=D9226d0tXiUWZZEUNdx7iF1J7GmE0Smen5RB6xsoHh8=; b=dDfVnNKwJgjeMopBBL8yZy6ZM4jEjFfBw41bNgMcRRtRWRrZi4oo8oSoFHpTzr67vjvym4 x6z5uObBgMOD6a3T4JySRqQHyE2uU0qwXggJU+KbbYw077G3IyK7SNFaFjPM73juA+uv/P IOukRnkD+Oy1YY39fa2jE4UHE7Ts00E= X-MC-Unique: RWv6OsO9OdyqQIHV0PL1Fg-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 02/11] conf: split out virDomainDefParseMemory Date: Thu, 27 Aug 2020 22:19:44 +0200 Message-Id: <09d6b2350d5c9d80c21a916ed0c0e544c4a00d69.1598559571.git.jtomko@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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.002 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 | 209 ++++++++++++++++++++++------------------- 1 file changed, 114 insertions(+), 95 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 189f0ac71f..94def18f8a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -21101,6 +21101,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, @@ -21285,102 +21398,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