Btrfs swapfile patch help

I thought this was the best place to discuss, instead of doing it on the bug report, I hope I wasn’t wrong.

As said on bugreport [1], I’m not a developer, it’s the first time I try to write a patch, unfortunately I don’t know how to do it.
Surely the code is not perfect, is there anyone who can help complete, revise and improve the code?

Mainly the changes are:

  1. If you choose btrfs, the code to detect the partition does not work, with the help of friends on Telegram I managed to improve the codide and now it perfectly detects Btrfs and ext4 [2].
  2. I create a nested subvolume (avoid mounting on /etc/fstab) [3] before activating the swap, to avoid carrying the swapfile if using snapshots, then I set the nocow [4] flag on the subvolume.
  3. I created ifs, if it reveals btrfs it points to the subvolume folder.

I tried the change in VM on Ubuntu 20.04, first with btrfs, then with ext4, the swpafile is created correctly on both installations


rootfstype=$(df -T /target | grep /target | awk ‘{print $2}’)


btrfs subvolume create /target/swap

[4] chattr + C /target/swap

For a complete view of the code:
patch: 25create_swapfile
patch: 45fstab_swapfile