public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: Li Wang <liwang@redhat.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH] libswap: add Btrfs noCOW attribute setting for swap files
Date: Mon, 22 Jan 2024 08:13:37 +0100	[thread overview]
Message-ID: <20240122071337.GB65606@pevik> (raw)
In-Reply-To: <20240120082725.2550695-1-liwang@redhat.com>

Hi Li,

> The patch aims to ensure swap files on Btrfs filesystems are created
> with the appropriate FS_NOCOW_FL attribute, which is necessary to
> disable CoW (Copy-on-Write) for swap files, perthe btrfs(5) manual page.
> This change is gated behind a kernel version check to ensure compatibility
> with the system's capabilities.

> Signed-off-by: Li Wang <liwang@redhat.com>
> ---

> Notes:
>     Hi Petr,

>       I haven't gotten a chance to test this patch on any Btrfs platform,
>       but only compile successfully without error on my RHEL8/9(xfs).
>       Can you help test and guarantee it works for you?

I'm not able to apply this to the current master. I also got a bit confused by
number of patches for libswap / swapon01. Could you please resend all the
patches again (in a series)? Or push branch to your fork and point the location?
(whatever is easier to you)

Kind regards,
Petr

>  libs/libltpswap/libswap.c | 35 +++++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)

> diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
> index 5f9622aca..8b180f288 100644
> --- a/libs/libltpswap/libswap.c
> +++ b/libs/libltpswap/libswap.c
> @@ -4,6 +4,7 @@
>   * Author: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
>   */

> +#include <linux/fs.h>
>  #include <errno.h>

>  #define TST_NO_DEFAULT_MAIN
> @@ -23,11 +24,37 @@ static const char *const swap_supported_fs[] = {
>  	NULL
>  };

> +static void set_nocow_attr(const char *filename)
> +{
> +	int fd;
> +	int attrs;
> +
> +	fd = SAFE_OPEN(filename, O_RDONLY);
> +
> +	if (ioctl(fd, FS_IOC_GETFLAGS, &attrs) == -1) {
> +		tst_res(TFAIL | TERRNO, "Error getting attributes");
> +		close(fd);
> +		return;
> +	}
> +
> +	attrs |= FS_NOCOW_FL;
> +
> +	if (ioctl(fd, FS_IOC_SETFLAGS, &attrs) == -1)
> +		tst_res(TFAIL | TERRNO, "Error setting FS_NOCOW_FL attribute");
> +	else
> +		tst_res(TINFO, "FS_NOCOW_FL attribute set on %s\n", filename);
> +
> +	close(fd);
> +}
> +
>  /*
>   * Make a swap file
>   */
>  int make_swapfile(const char *swapfile, int safe)
>  {
> +	long fs_type = tst_fs_type(swapfile);
> +	const char *fstype = tst_fs_type_name(fs_type);
> +
>  	if (!tst_fs_has_free(".", sysconf(_SC_PAGESIZE) * 10, TST_BYTES))
>  		tst_brk(TBROK, "Insufficient disk space to create swap file");

> @@ -35,6 +62,14 @@ int make_swapfile(const char *swapfile, int safe)
>  	if (tst_fill_file(swapfile, 0, sysconf(_SC_PAGESIZE), 10) != 0)
>  		tst_brk(TBROK, "Failed to create swapfile");

> +	/* Btrfs file need set 'nocow' attribute */
> +	if (strcmp(fstype, "btrfs") == 0) {
> +		if (tst_kvercmp(5, 0, 0) > 0)
> +			set_nocow_attr(swapfile);
> +		else
> +			tst_brk(TCONF, "Swapfile on %s not implemented", fstype);
> +	}
> +
>  	/* make the file swapfile */
>  	const char *argv[2 + 1];
>  	argv[0] = "mkswap";

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2024-01-22  7:13 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-19 14:43 [LTP] [PATCH 1/1] swapon01: Test on all filesystems Petr Vorel
2024-01-19 15:06 ` Cyril Hrubis
2024-01-22  6:22   ` Petr Vorel
2024-01-22  7:39     ` Li Wang
2024-01-20  4:21 ` Li Wang
2024-01-20  4:34   ` [LTP] [PATCH 1/2] libswap: add known swap supported fs check Li Wang
2024-01-20  4:34     ` [LTP] [PATCH 2/2] swapon01: Test on all filesystems Li Wang
2024-01-20  6:40       ` [LTP] [PATCH] swapon01: Improving test with memory limits and swap reporting Li Wang
2024-01-20  6:52         ` Li Wang
2024-01-20  8:27       ` [LTP] [PATCH] libswap: add Btrfs noCOW attribute setting for swap files Li Wang
2024-01-22  7:13         ` Petr Vorel [this message]
2024-01-22  7:28           ` Li Wang
2024-01-22  6:26   ` [LTP] [PATCH 1/1] swapon01: Test on all filesystems Petr Vorel
2024-01-22  7:50     ` Li Wang
2024-01-22  8:24       ` Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240122071337.GB65606@pevik \
    --to=pvorel@suse.cz \
    --cc=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox