From patchwork Sat Jan 20 04:34:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1888732 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=VXHJYHnb; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TH3YQ6vyLz1yPJ for ; Sat, 20 Jan 2024 15:34:50 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BE1023CF29D for ; Sat, 20 Jan 2024 05:34:48 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 66D363CE2D9 for ; Sat, 20 Jan 2024 05:34:21 +0100 (CET) Authentication-Results: in-4.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=170.10.133.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=liwang@redhat.com; receiver=lists.linux.it) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 93DC41011BC9 for ; Sat, 20 Jan 2024 05:34:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705725259; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A/YN7mwSm6kGZn1HPdrh18451K7aV951VH9CNM86f5E=; b=VXHJYHnbCkXSRatkmKPN6d+UablL3YpIiXR+oZ/ttqLn08BzZ1tOXF2gaQD9R/bm5ro+H5 GtzmY6Y7A0U6QTuo6Lta+F+oeWscuwW5WFhIeJz0dQfM8BZpASF2hmkYu50Iob/ef8CWzK JJeVKAbSbFtEowDCo/u8rGzwmUgpXco= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-122-rfvU5qlFMuSooAJy8l7hIw-1; Fri, 19 Jan 2024 23:34:16 -0500 X-MC-Unique: rfvU5qlFMuSooAJy8l7hIw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5EF7983B82A for ; Sat, 20 Jan 2024 04:34:16 +0000 (UTC) Received: from liwang-workstation.lab.eng.nay.redhat.com (unknown [10.66.145.229]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7338B2026D66 for ; Sat, 20 Jan 2024 04:34:15 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Sat, 20 Jan 2024 12:34:11 +0800 Message-Id: <20240120043412.2544860-1-liwang@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-4.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-4.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH 1/2] libswap: add known swap supported fs check X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "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 --- 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 d014325e5..5f9622aca 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 */ @@ -39,23 +50,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); From patchwork Sat Jan 20 04:34:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1888731 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=e7bsGTXM; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TH3Y16D4Gz1yPJ for ; Sat, 20 Jan 2024 15:34:29 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 3454D3CE2C0 for ; Sat, 20 Jan 2024 05:34:25 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 5B7DD3CAC5F for ; Sat, 20 Jan 2024 05:34:22 +0100 (CET) Authentication-Results: in-2.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=redhat.com (client-ip=170.10.129.124; helo=us-smtp-delivery-124.mimecast.com; envelope-from=liwang@redhat.com; receiver=lists.linux.it) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 8CA0B602285 for ; Sat, 20 Jan 2024 05:34:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705725260; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+kcnyVGq3/mEUKD1xEMOBcBFJUr02ocyR5/8Pt3uZiQ=; b=e7bsGTXMcWSLJP2bD6v861i5UWeaMOP81CPON8l2KlwuNOhxsoxHM5/3BcJ5iTskLQoFsO gv0KhadoEQkeBOz/BEH9VvQVP5vkhaDwmPeqpTfUw3VSncl8sZoBy43RenJ4q6sjZSk7VM d5cystDgS18Ibm6bPuNyh/Djnm5ZCa8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-79-ZZbWBCxKPYKSSHszCn-LsA-1; Fri, 19 Jan 2024 23:34:18 -0500 X-MC-Unique: ZZbWBCxKPYKSSHszCn-LsA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4845A3C025BB; Sat, 20 Jan 2024 04:34:18 +0000 (UTC) Received: from liwang-workstation.lab.eng.nay.redhat.com (unknown [10.66.145.229]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F0CC62026D66; Sat, 20 Jan 2024 04:34:16 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Sat, 20 Jan 2024 12:34:12 +0800 Message-Id: <20240120043412.2544860-2-liwang@redhat.com> In-Reply-To: <20240120043412.2544860-1-liwang@redhat.com> References: <20240120043412.2544860-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-2.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-2.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH 2/2] swapon01: Test on all filesystems X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Petr Vorel Test on all filesystems to increase coverage. Skip filesystems which does not support swap (currently bcachefs, btrfs and tmpfs). Tested on 5.10, 6.6 and 6.7. Signed-off-by: Petr Vorel Signed-off-by: Li Wang --- testcases/kernel/syscalls/swapon/swapon01.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c index e59fb20a1..e1fe50459 100644 --- a/testcases/kernel/syscalls/swapon/swapon01.c +++ b/testcases/kernel/syscalls/swapon/swapon01.c @@ -8,6 +8,7 @@ * [Description] * * Checks that swapon() succeds with swapfile. + * Testing on all filesystems which support swap file. */ #include @@ -17,7 +18,8 @@ #include "lapi/syscalls.h" #include "libswap.h" -#define SWAP_FILE "swapfile01" +#define MNTPOINT "mntpoint" +#define SWAP_FILE MNTPOINT"/swapfile01" static void verify_swapon(void) { @@ -36,8 +38,10 @@ static void setup(void) } static struct tst_test test = { + .mntpoint = MNTPOINT, + .mount_device = 1, .needs_root = 1, - .needs_tmpdir = 1, + .all_filesystems = 1, .test_all = verify_swapon, .setup = setup };