cli: --memorybacking: Convert hugepages.page to a list

There can be more than 1 <memoryBacking><hugepages><page> element.
Adjust the cli options to match:

- hugepages.page[0-9]*.size
- hugepages.page[0-9]*.unit
- hugepages.page[0-9]*.nodeset
This commit is contained in:
Cole Robinson 2019-05-14 15:45:16 -04:00
parent 334d18ab93
commit 90f5b29789
5 changed files with 43 additions and 16 deletions

View File

@ -28,7 +28,8 @@
<nosharepages/>
<locked/>
<hugepages>
<page size="1" unit="G" nodeset="0-1"/>
<page size="12" unit="G" nodeset="0,1"/>
<page size="1234" unit="MB" nodeset="2"/>
</hugepages>
<access mode="shared"/>
<source type="anonymous"/>
@ -130,6 +131,7 @@
<sibling id="1" value="10"/>
</distances>
</cell>
<cell id="2" cpus="4" memory="256"/>
</numa>
</cpu>
<clock offset="utc">
@ -229,7 +231,8 @@
<nosharepages/>
<locked/>
<hugepages>
<page size="1" unit="G" nodeset="0-1"/>
<page size="12" unit="G" nodeset="0,1"/>
<page size="1234" unit="MB" nodeset="2"/>
</hugepages>
<access mode="shared"/>
<source type="anonymous"/>
@ -333,6 +336,7 @@
<sibling id="1" value="10"/>
</distances>
</cell>
<cell id="2" cpus="4" memory="256"/>
</numa>
</cpu>
<clock offset="utc">

View File

@ -443,6 +443,7 @@ c.add_compare("""--pxe
--cpu foobar,+x2apic,+x2apicagain,-distest,forbid=foo,forbid=bar,disable=distest2,optional=opttest,require=reqtest,match=strict,vendor=meee,\
cell.id=0,cell.cpus=1,2,3,cell.memory=1024,\
cell1.id=1,cell1.memory=256,cell1.cpus=5-8,\
numa.cell2.id=2,numa.cell2.memory=256,numa.cell2.cpus=4,\
cell0.distances.sibling0.id=0,cell0.distances.sibling0.value=10,\
cell0.distances.sibling1.id=1,cell0.distances.sibling1.value=21,\
cell1.distances.sibling0.id=0,cell1.distances.sibling0.value=21,\
@ -456,7 +457,7 @@ cache.mode=emulate,cache.level=3
--numatune 1-3,4,mode=strict
--memtune hard_limit=10,soft_limit=20,swap_hard_limit=30,min_guarantee=40
--blkiotune weight=100,device_path=/home/test/1.img,device_weight=200
--memorybacking size=1,unit='G',nodeset=0-1,nosharepages=yes,locked=yes,access_mode=shared,source_type=anonymous
--memorybacking size=1,unit='G',nodeset=0,1,nosharepages=yes,locked=yes,access_mode=shared,source_type=anonymous,hugepages.page.size=12,hugepages.page1.size=1234,hugepages.page1.unit=MB,hugepages.page1.nodeset=2
--features acpi=off,eoi=on,privnet=on,hyperv_synic=on,hyperv_reset=on,hyperv_spinlocks=on,hyperv_spinlocks_retries=5678,vmport=off,pmu=off,vmcoreinfo=on
--clock offset=utc,hpet_present=no,rtc_tickpolicy=merge,timer2.name=hypervclock,timer3.name=pit,timer1.present=yes,timer3.tickpolicy=delay,timer2.present=no
--sysinfo type=smbios,bios_vendor="Acme LLC",bios_version=1.2.3,bios_date=01/01/1970,bios_release=10.22

View File

@ -232,11 +232,14 @@ class XMLParseTest(unittest.TestCase):
check = self._make_checker(guest.memoryBacking)
check("hugepages", False, True)
check("page_size", None, 1)
check("page_unit", None, "G")
check("nosharepages", False, True)
check("locked", False, True)
page = guest.memoryBacking.pages.add_new()
check = self._make_checker(page)
check("size", None, 1)
check("unit", None, "G")
self._alter_compare(guest.get_xml(), outfile)
def testSeclabel(self):

View File

@ -1748,20 +1748,29 @@ class ParserMemoryBacking(VirtCLIParser):
cli_arg_name = "memorybacking"
guest_propname = "memoryBacking"
aliases = {
"hugepages.page.size": "size",
"hugepages.page.unit": "unit",
"hugepages.page.nodeset": "nodeset",
"hugepages.page[0-9]*.size": "size",
"hugepages.page[0-9]*.unit": "unit",
"hugepages.page[0-9]*.nodeset": "nodeset",
"access.mode": "access_mode",
"source.type": "source_type",
}
def page_find_inst_cb(self, *args, **kwargs):
cliarg = "page" # page[0-9]*
list_propname = "pages" # memoryBacking.pages
cb = self._make_find_inst_cb(cliarg, list_propname)
return cb(*args, **kwargs)
@classmethod
def _init_class(cls, **kwargs):
VirtCLIParser._init_class(**kwargs)
cls.add_arg("hugepages", "hugepages", is_onoff=True)
cls.add_arg("hugepages.page.size", "page_size")
cls.add_arg("hugepages.page.unit", "page_unit")
cls.add_arg("hugepages.page.nodeset", "page_nodeset", can_comma=True)
cls.add_arg("hugepages.page[0-9]*.size", "size",
find_inst_cb=cls.page_find_inst_cb)
cls.add_arg("hugepages.page[0-9]*.unit", "unit",
find_inst_cb=cls.page_find_inst_cb)
cls.add_arg("hugepages.page[0-9]*.nodeset", "nodeset", can_comma=True,
find_inst_cb=cls.page_find_inst_cb)
cls.add_arg("nosharepages", "nosharepages", is_onoff=True)
cls.add_arg("locked", "locked", is_onoff=True)

View File

@ -5,7 +5,18 @@
# This work is licensed under the GNU GPLv2 or later.
# See the COPYING file in the top-level directory.
from ..xmlbuilder import XMLBuilder, XMLProperty
from ..xmlbuilder import XMLBuilder, XMLChildProperty, XMLProperty
class _HugepagesPage(XMLBuilder):
"""
Class representing <memoryBacking><hugepages><page> elements
"""
XML_NAME = "page"
size = XMLProperty("./@size")
unit = XMLProperty("./@unit")
nodeset = XMLProperty("./@nodeset")
class DomainMemoryBacking(XMLBuilder):
@ -14,13 +25,12 @@ class DomainMemoryBacking(XMLBuilder):
"""
XML_NAME = "memoryBacking"
_XML_PROP_ORDER = ["hugepages", "nosharepages", "locked"]
_XML_PROP_ORDER = ["hugepages", "nosharepages", "locked", "pages"]
hugepages = XMLProperty("./hugepages", is_bool=True)
page_size = XMLProperty("./hugepages/page/@size")
page_unit = XMLProperty("./hugepages/page/@unit")
page_nodeset = XMLProperty("./hugepages/page/@nodeset")
nosharepages = XMLProperty("./nosharepages", is_bool=True)
locked = XMLProperty("./locked", is_bool=True)
access_mode = XMLProperty("./access/@mode")
source_type = XMLProperty("./source/@type")
pages = XMLChildProperty(_HugepagesPage, relative_xpath="./hugepages")