libvirt: add support for memory backing parameters

Add a libvirt config class for dealing with the XML elements
under the <memoryBacking> section of the guest schema.

Blueprint: virt-driver-large-pages
Change-Id: Icd89508671a8951bed480b901b2d12d44ebb7cab
This commit is contained in:
Daniel P. Berrange
2014-05-27 15:58:49 +01:00
parent c9a3b3f89c
commit b977c07e9d
2 changed files with 54 additions and 0 deletions

View File

@@ -1136,6 +1136,9 @@ class LibvirtConfigGuestTest(LibvirtConfigBaseTest):
obj.cputune.quota = 50000
obj.cputune.period = 25000
obj.membacking = config.LibvirtConfigGuestMemoryBacking()
obj.membacking.hugepages = True
obj.name = "demo"
obj.uuid = "b38a3f43-4be2-4046-897f-b67c2f5e0147"
obj.os_type = "linux"
@@ -1162,6 +1165,9 @@ class LibvirtConfigGuestTest(LibvirtConfigBaseTest):
<uuid>b38a3f43-4be2-4046-897f-b67c2f5e0147</uuid>
<name>demo</name>
<memory>104857600</memory>
<memoryBacking>
<hugepages/>
</memoryBacking>
<vcpu cpuset="0-1,3-5">2</vcpu>
<sysinfo type='smbios'>
<bios>
@@ -1785,6 +1791,28 @@ class LibvirtConfigGuestCPUTuneTest(LibvirtConfigBaseTest):
</cputune>""")
class LibvirtConfigGuestMemoryBackingTest(LibvirtConfigBaseTest):
def test_config_memory_backing_none(self):
obj = config.LibvirtConfigGuestMemoryBacking()
xml = obj.to_xml()
self.assertXmlEqual(xml, "<memoryBacking/>")
def test_config_memory_backing_all(self):
obj = config.LibvirtConfigGuestMemoryBacking()
obj.locked = True
obj.sharedpages = False
obj.hugepages = True
xml = obj.to_xml()
self.assertXmlEqual(xml, """
<memoryBacking>
<hugepages/>
<nosharedpages/>
<locked/>
</memoryBacking>""")
class LibvirtConfigGuestMetadataNovaTest(LibvirtConfigBaseTest):
def test_config_metadata(self):

View File

@@ -1307,6 +1307,29 @@ class LibvirtConfigGuestCPUTune(LibvirtConfigObject):
return root
class LibvirtConfigGuestMemoryBacking(LibvirtConfigObject):
def __init__(self, **kwargs):
super(LibvirtConfigGuestMemoryBacking, self).__init__(
root_name="memoryBacking", **kwargs)
self.hugepages = False
self.sharedpages = True
self.locked = False
def format_dom(self):
root = super(LibvirtConfigGuestMemoryBacking, self).format_dom()
if self.hugepages:
root.append(etree.Element("hugepages"))
if not self.sharedpages:
root.append(etree.Element("nosharedpages"))
if self.locked:
root.append(etree.Element("locked"))
return root
class LibvirtConfigGuest(LibvirtConfigObject):
def __init__(self, **kwargs):
@@ -1317,6 +1340,7 @@ class LibvirtConfigGuest(LibvirtConfigObject):
self.uuid = None
self.name = None
self.memory = 500 * units.Mi
self.membacking = None
self.vcpus = 1
self.cpuset = None
self.cpu = None
@@ -1342,6 +1366,8 @@ class LibvirtConfigGuest(LibvirtConfigObject):
root.append(self._text_node("uuid", self.uuid))
root.append(self._text_node("name", self.name))
root.append(self._text_node("memory", self.memory))
if self.membacking is not None:
root.append(self.membacking.format_dom())
if self.cpuset is not None:
vcpu = self._text_node("vcpu", self.vcpus)
vcpu.set("cpuset", hardware.format_cpu_spec(self.cpuset))