Skip to content

Commit 40efb42

Browse files
authored
fix: add support for memoryBacking source type configuration (ansible-collections#228) (ansible-collections#230)
- Introduced a new 'source' parameter in the memoryBacking configuration to allow specifying the type of memory backing (anonymous, file, memfd).
1 parent 2fe619f commit 40efb42

File tree

4 files changed

+49
-0
lines changed

4 files changed

+49
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
minor_changes:
2+
- virt_install - added support for memoryBacking source type configuration, including memfd for shared memory (https://github.com/ansible-collections/community.libvirt/issues/228).

plugins/doc_fragments/virt_install.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,17 @@ class ModuleDocFragment(object):
7070
type: bool
7171
description:
7272
- Memory pages will be locked in host's memory and will not be swapped out.
73+
source:
74+
type: dict
75+
description:
76+
- Configure the source of memory backing.
77+
version_added: '2.1.0'
78+
suboptions:
79+
type:
80+
type: str
81+
choices: [ anonymous, file, memfd ]
82+
description:
83+
- The type of memory backing source.
7384
access:
7485
type: dict
7586
description:

plugins/module_utils/virt_install.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ def _build_basic_options(self):
273273
'hugepage_specs': ('hugepages.page', {
274274
'page_size': ('size', None),
275275
}),
276+
'source': ('source', None),
276277
}
277278
self._add_parameter('--memorybacking',
278279
dict_value=self.params['memorybacking'],
@@ -893,6 +894,14 @@ def get_memorybacking_args():
893894
),
894895
nosharepages=dict(type='bool'),
895896
locked=dict(type='bool'),
897+
source=dict(
898+
type='dict',
899+
options=dict(
900+
type=dict(
901+
type='str',
902+
choices=['anonymous', 'file', 'memfd']),
903+
),
904+
),
896905
access=dict(
897906
type='dict',
898907
options=dict(

tests/unit/module_utils/test_virt_install.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,33 @@ def test_memorybacking_options(self):
890890
self.assertIn('hugepages.page0.size=2048', memorybacking_cmdline)
891891
self.assertIn('hugepages.page0.nodeset=0-1', memorybacking_cmdline)
892892

893+
def test_memorybacking_with_memfd_source(self):
894+
"""Test memorybacking parameter with memfd source"""
895+
self.mock_module.params = {
896+
'name': 'test-vm',
897+
'memory': 4096,
898+
'memorybacking': {
899+
'source': {
900+
'type': 'memfd'
901+
},
902+
'access': {
903+
'mode': 'shared'
904+
}
905+
}
906+
}
907+
self.virt_install = VirtInstallTool(self.mock_module)
908+
self.virt_install._build_command()
909+
910+
try:
911+
idx = self.virt_install.command_argv.index('--memorybacking')
912+
memorybacking_cmdline = self.virt_install.command_argv[idx + 1]
913+
except (ValueError, IndexError):
914+
memorybacking_cmdline = None
915+
916+
self.assertIsNotNone(memorybacking_cmdline)
917+
self.assertIn('source.type=memfd', memorybacking_cmdline)
918+
self.assertIn('access.mode=shared', memorybacking_cmdline)
919+
893920
def test_vcpus_configuration(self):
894921
"""Test vcpus parameter with options"""
895922
self.mock_module.params = {

0 commit comments

Comments
 (0)