public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH 1/4] libswap: add known swap supported fs check
@ 2024-01-22  7:29 Li Wang
  2024-01-22  7:29 ` [LTP] [PATCH 2/4] swapon01: Test on all filesystems Li Wang
                   ` (4 more replies)
  0 siblings, 5 replies; 26+ messages in thread
From: Li Wang @ 2024-01-22  7:29 UTC (permalink / raw)
  To: ltp

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);
 	long fs_type = tst_fs_type(filename);
 	const char *fstype = tst_fs_type_name(fs_type);
 
-	int ret = make_swapfile(filename, 1);
-	if (ret != 0) {
-		if (fibmap == 1)
-			tst_brk(TCONF, "mkswap on %s not supported", fstype);
-		else
-			tst_brk(TFAIL, "mkswap on %s failed", fstype);
+	for (i = 0; swap_supported_fs[i]; i++) {
+		if (!strcmp(fstype, swap_supported_fs[i])) {
+			sw_support = 1;
+			break;
+		}
 	}
 
+       int ret = make_swapfile(filename, 1);
+       if (ret != 0) {
+               if (fibmap == 1 && sw_support == 0)
+                       tst_brk(TCONF, "mkswap on %s not supported", fstype);
+               else
+                       tst_brk(TFAIL, "mkswap on %s failed", fstype);
+       }
+
 	TEST(tst_syscall(__NR_swapon, filename, 0));
 	if (TST_RET == -1) {
 		if (errno == EPERM)
 			tst_brk(TCONF, "Permission denied for swapon()");
-		else if (fibmap == 1 && errno == EINVAL)
+		else if (fibmap == 1 && errno == EINVAL && sw_support == 0)
 			tst_brk(TCONF, "Swapfile on %s not implemented", fstype);
 		else
 			tst_brk(TFAIL | TTERRNO, "swapon() on %s failed", fstype);
-- 
2.40.1


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

^ permalink raw reply related	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2024-01-23 15:45 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-22  7:29 [LTP] [PATCH 1/4] libswap: add known swap supported fs check Li Wang
2024-01-22  7:29 ` [LTP] [PATCH 2/4] swapon01: Test on all filesystems Li Wang
2024-01-22  7:29 ` [LTP] [PATCH 3/4] swapon01: Improving test with memory limits and swap reporting Li Wang
2024-01-22  9:08   ` Petr Vorel
2024-01-22  7:29 ` [LTP] [PATCH 4/4] libswap: add Btrfs noCOW attribute setting for swap files Li Wang
2024-01-22  8:40   ` Petr Vorel
2024-01-22  8:47     ` Petr Vorel
2024-01-22  9:20       ` Li Wang
2024-01-22  9:04     ` Li Wang
2024-01-22  9:03 ` [LTP] [PATCH 1/4] libswap: add known swap supported fs check Petr Vorel
2024-01-22  9:12   ` Li Wang
2024-01-22 10:57     ` Petr Vorel
2024-01-22  9:41   ` Petr Vorel
2024-01-22 10:22     ` Li Wang
2024-01-22  9:13 ` Petr Vorel
2024-01-22  9:32   ` Li Wang
2024-01-22 11:03     ` Petr Vorel
2024-01-22 14:23       ` Li Wang
2024-01-22 20:23         ` Petr Vorel
2024-01-23  5:55           ` Li Wang
2024-01-23  7:30             ` Li Wang
2024-01-23  7:48               ` Petr Vorel
2024-01-23 12:04                 ` Li Wang
2024-01-23 12:31                   ` Petr Vorel
2024-01-23 13:10                     ` Li Wang
2024-01-23 15:45                       ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox