From 6603706eec1c39d9d591c8ffa0ef7171b74d84d6 Mon Sep 17 00:00:00 2001 From: Eduardo Otubo Date: Thu, 23 Jan 2020 17:41:48 +0100 Subject: Do not use fallocate in swap file creation on xfs. (#70) When creating a swap file on an xfs filesystem, fallocate cannot be used. Doing so results in failure of swapon and a message like: swapon: swapfile has holes The solution here is to maintain a list (currently containing only XFS) of filesystems where fallocate cannot be used. The, on those fileystems use the slower but functional 'dd' method. Signed-off-by: Eduardo Otubo Co-authored-by: Adam Dobrawy Co-authored-by: Scott Moser Co-authored-by: Daniel Watkins LP: #1781781 --- tests/unittests/test_handler/test_handler_mounts.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/unittests') diff --git a/tests/unittests/test_handler/test_handler_mounts.py b/tests/unittests/test_handler/test_handler_mounts.py index 0fb160be..7bcefa0a 100644 --- a/tests/unittests/test_handler/test_handler_mounts.py +++ b/tests/unittests/test_handler/test_handler_mounts.py @@ -181,6 +181,18 @@ class TestFstabHandling(test_helpers.FilesystemMockingTestCase): return dev + def test_swap_integrity(self): + '''Ensure that the swap file is correctly created and can + swapon successfully. Fixing the corner case of: + kernel: swapon: swapfile has holes''' + + fstab = '/swap.img swap swap defaults 0 0\n' + + with open(cc_mounts.FSTAB_PATH, 'w') as fd: + fd.write(fstab) + cc = {'swap': ['filename: /swap.img', 'size: 512', 'maxsize: 512']} + cc_mounts.handle(None, cc, self.mock_cloud, self.mock_log, []) + def test_fstab_no_swap_device(self): '''Ensure that cloud-init adds a discovered swap partition to /etc/fstab.''' -- cgit v1.2.3