[LTP] [PATCH V3 4/5] libswap: add function to prealloc contiguous file

Li Wang liwang@redhat.com
Wed Jan 24 05:27:22 CET 2024


Hi Petr,

On Wed, Jan 24, 2024 at 1:40 AM Petr Vorel <pvorel@suse.cz> wrote:

> Hi Li,
>
> > Hi Petr,
>
> > On Tue, Jan 23, 2024 at 8:37 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> > > Hi Li,
>
> > > > Hi Li,
>
> > > > swapoff01 fails on TMPDIR on btrfs (regardless kernel version):
>
> > > FYI it works on Tumbleweed with 6.7 kernel. It's broken on some older
> SLES
> > > with 5.14 and all older kernels. I suppose with nocow (fixes I
> suggested
> > > previously) would work as expected (TPASS, or TCONF on kernel < 5.0).
>
>
> > You're right.
>
> > We have to guarantee the swapfile is a contiguous file whatever the FS
> type
> > is.
> > So here making use of make_swapfile() is a hard requirement.
> > And, I don't think the file first with 65536 blocks (in swapoff01) is not
> > necessary.
>
> Unfortunately this commit or the following (libswap: Introduce file
> contiguity
> check) breaks swapon01.c on older SLES (4.4 based kernel and older) on XFS:
>
> tst_ioctl.c:26: TINFO: FIBMAP ioctl is supported
> libswap.c:191: TFAIL: swapon() on xfs failed: EINVAL (22)
>
> The failure is in is_swap_supported().
>

Good catch.

After testing on my side, reproduced that easily with old XFS.
The reason is probably old XFS expects the swap file to be
initialized in a certain way.

So a simple fix is just to fill full of the file after preallocating space:

--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -140,6 +140,11 @@ int make_swapfile(const char *swapfile, int safe)
        if (prealloc_contiguous_file(swapfile, sysconf(_SC_PAGESIZE), 10)
!= 0)
                tst_brk(TBROK, "Failed to create swapfile");

+       if (tst_fs_type(swapfile) == TST_XFS_MAGIC) {
+               if (tst_fill_file(swapfile, 0, sysconf(_SC_PAGESIZE), 10)
!= 0)
+                       tst_brk(TBROK, "Failed to create swapfile");
+       }
+
        /* make the file swapfile */
        const char *argv[2 + 1];



-- 
Regards,
Li Wang


More information about the ltp mailing list