Skip to content

Commit

Permalink
cc_mounts: Fix swapfile not works on btrfs
Browse files Browse the repository at this point in the history
To make a swapfile works on btrfs
We need to create an empty file, add "no copy-on-write" attribute
before turn it into swapfile

Fixes GH-3713
LP: #1884127
  • Loading branch information
bin456789 committed Aug 14, 2023
1 parent e2ae755 commit 9771186
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cloudinit/config/cc_mounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,10 @@ def create_swap(fname, size, method):

fstype = util.get_mount_info(swap_dir)[1]

if fstype == "btrfs":
subp.subp(["truncate", "-s", "0", fname])
subp.subp(["chattr", "+C", fname])

if (
fstype == "xfs" and util.kernel_version() < (4, 18)
) or fstype == "btrfs":
Expand Down
2 changes: 2 additions & 0 deletions tests/unittests/config/test_cc_mounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ def test_swap_creation_method_btrfs(
cc_mounts.handle(None, self.cc, self.mock_cloud, [])
self.m_subp_subp.assert_has_calls(
[
mock.call(["truncate", "-s", "0", self.swap_path]),
mock.call(["chattr", "+C", self.swap_path]),
mock.call(
[
"dd",
Expand Down
1 change: 1 addition & 0 deletions tools/.github-cla-signers
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ bdrung
beantaxi
beezly
berolinux
bin456789
bipinbachhao
BirknerAlex
bmhughes
Expand Down

0 comments on commit 9771186

Please sign in to comment.