Merge fix swap test on zfs file system

Swap on ZFS is *weird*. Getting it working needs some special casing, see e.g. https://askubuntu.com/questions/1198903/can-not-use-swap-file-on-zfs-files-with-holes

Currently, the swap regression test fails on my system (with /tmp in zfs):
```bash
tests/regression/apparmor ❯ ./swap.sh
Error: swap failed. Test 'SWAPON (unconfined)' was expected to 'pass'. Reason for failure 'FAIL: swapon /tmp/sdtest.872368-19048-kN4FN2/swapfile failed - Invalid argument'
Error: swap failed. Test 'SWAPOFF (unconfined)' was expected to 'pass'. Reason for failure 'FAIL: swapoff /tmp/sdtest.872368-19048-kN4FN2/swapfile failed - Invalid argument'
swapon: /tmp/sdtest.872368-19048-kN4FN2/swapfile: skipping - it appears to have holes.
Fatal Error (swap): Unexpected shell error. Run with -x to debug
```

However, just doing a file mount does make the test work on zfs, similar to how it is done with tmpfs. This means we don't need any special-casing for zfs beyond what is already there for working around (similar) tmpfs limitations.

Also, while researching this, it is possible a similar patch is needed for btrfs, but i currently don't have an easy way to test that.
This is non-breaking for anyone *not* using zfs, and it is currently broken with zfs anyways.

MR: https://gitlab.com/apparmor/apparmor/-/merge_requests/1462
Approved-by: Ryan Lee <rlee287@yahoo.com>
Approved-by: Georgia Garcia <georgia.garcia@canonical.com>
Merged-by: Georgia Garcia <georgia.garcia@canonical.com>
This commit is contained in:
Georgia Garcia 2024-12-13 20:06:56 +00:00
commit e8f1ac4791

View file

@ -31,8 +31,8 @@ swap_file=$tmpdir/swapfile
# check if we can run the test in tmpdir # check if we can run the test in tmpdir
fstype=$(stat -f --format '%T' "${tmpdir}") fstype=$(stat -f --format '%T' "${tmpdir}")
if [ "${fstype}" = "tmpfs" ] ; then if [ "${fstype}" = "tmpfs" ] || [ "${fstype}" = "zfs" ] ; then
# create a mountpoint not tmpfs # create a mountpoint not tmpfs or zfs
mount_file=$tmpdir/mountfile mount_file=$tmpdir/mountfile
mount_point=$tmpdir/mountpoint mount_point=$tmpdir/mountpoint
fstype="ext2" fstype="ext2"