[LTP] [PATCH 1/4] libswap: add known swap supported fs check

Petr Vorel pvorel@suse.cz
Mon Jan 22 10:03:49 CET 2024


Hi Li, Cyril,

> This introduce an enhancement to the library's is_swap_supported
> function to check for filesystem compatibility before attempting
> to create and enable a swap file.  A list of supported filesystems
> is added (ext2, ext3, ext4, xfs, vfat, exfat, ntfs), and a check
> against this list is performed to ensure that the swap operations
> are only attempted on known compatible filesystems.

> If the make_swapfile function fails, the error handling is now
> more descriptive: it distinguishes between failures due to the
> filesystem not supporting swap files and other types of failures.
> Similarly, when attempting to enable the swap file with swapon,
> the patch ensures that clearer error messages are provided in
> cases where the operation is not supported by the filesystem.

> Signed-off-by: Li Wang <liwang@redhat.com>
> ---
>  libs/libltpswap/libswap.c | 33 ++++++++++++++++++++++++++-------
>  1 file changed, 26 insertions(+), 7 deletions(-)

> diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
> index 13610709e..623f2fb3c 100644
> --- a/libs/libltpswap/libswap.c
> +++ b/libs/libltpswap/libswap.c
> @@ -12,6 +12,17 @@
>  #include "libswap.h"
>  #include "lapi/syscalls.h"

> +static const char *const swap_supported_fs[] = {
> +	"ext2",
> +	"ext3",
> +	"ext4",
> +	"xfs",
> +	"vfat",
> +	"exfat",
> +	"ntfs",
> +	NULL
> +};
> +
>  /*
>   * Make a swap file
>   */
> @@ -40,23 +51,31 @@ int make_swapfile(const char *swapfile, int safe)
>   */
>  void is_swap_supported(const char *filename)
>  {
> +	int i, sw_support = 0;
>  	int fibmap = tst_fibmap(filename);
Just a note unrelated to this patchset. When testing on SLES kernel based on
5.3.18 we still get TCONF due missing FIBMAP ioctl support:

tst_test.c:1669: TINFO: === Testing on btrfs ===
tst_test.c:1118: TINFO: Formatting /dev/loop0 with btrfs opts='' extra opts=''
tst_test.c:1132: TINFO: Mounting /dev/loop0 to /tmp/LTP_swazaqF1L/mntpoint fstyp=btrfs flags=0
tst_ioctl.c:21: TINFO: FIBMAP ioctl is NOT supported: EINVAL (22)
libswap.c:45: TINFO: FS_NOCOW_FL attribute set on mntpoint/swapfile01

libswap.c:114: TCONF: Swapfile on btrfs not implemented

Am I wrong or could it be solved with FIEMAP (<linux/fiemap.h>)?
If yes, I wonder if we should fallback on btrfs when FIBMAP is missing

https://www.kernel.org/doc/Documentation/filesystems/fiemap.txt
https://unix.stackexchange.com/questions/623859/how-do-you-find-the-physical-offset-for-a-file-in-btrfs

Kind regards,
Petr


More information about the ltp mailing list