From patchwork Sun Jan 28 02:48:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1891829 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=iGu2cVdq; 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 4TMwqv0hRzz1yQ0 for ; Sun, 28 Jan 2024 13:49:14 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A8B963CE19A for ; Sun, 28 Jan 2024 03:49:10 +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 [IPv6:2001:4b78:1:20::4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id CF2E03CC7D6 for ; Sun, 28 Jan 2024 03:48:51 +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 3C7F31009BC0 for ; Sun, 28 Jan 2024 03:48:50 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706410129; 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=mAK70JhgLobKGoJHH89yJbPcF7j9DVont9XqbfvJ7ao=; b=iGu2cVdqmGXG5+xUqJpF2KuEYWstCG78z9T0JKGhJOfSmqnxy0uH+pAHRxpqprp3eQBJXg eZ6GqsP7/K3B4PhIyuEd9DnwtuoYgvHPQkfuxnta9ps1GrcBWf0xfqDVd6cAads3lm4W9q sNNmB1z7lJXebGciO3TYNDt40YzakI8= 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-586-4-hboCidMCG6lNkv1VUM2w-1; Sat, 27 Jan 2024 21:48:45 -0500 X-MC-Unique: 4-hboCidMCG6lNkv1VUM2w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 0E6F83C100B4; Sun, 28 Jan 2024 02:48:45 +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 CA08A1C060B1; Sun, 28 Jan 2024 02:48:43 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Sun, 28 Jan 2024 10:48:31 +0800 Message-Id: <20240128024838.2699248-2-liwang@redhat.com> In-Reply-To: <20240128024838.2699248-1-liwang@redhat.com> References: <20240128024838.2699248-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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 v5 1/8] 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 Tested-by: Petr Vorel Reviewed-by: Petr Vorel --- libs/libltpswap/libswap.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c index 13610709e..8c2ce6cd7 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 */ @@ -26,6 +37,7 @@ int make_swapfile(const char *swapfile, int safe) /* make the file swapfile */ const char *argv[2 + 1]; + argv[0] = "mkswap"; argv[1] = swapfile; argv[2] = NULL; @@ -40,13 +52,22 @@ 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); + for (i = 0; swap_supported_fs[i]; i++) { + if (strstr(fstype, swap_supported_fs[i])) { + sw_support = 1; + break; + } + } + int ret = make_swapfile(filename, 1); + if (ret != 0) { - if (fibmap == 1) + if (fibmap == 1 && sw_support == 0) tst_brk(TCONF, "mkswap on %s not supported", fstype); else tst_brk(TFAIL, "mkswap on %s failed", fstype); @@ -56,7 +77,7 @@ void is_swap_supported(const char *filename) 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 Sun Jan 28 02:48:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1891830 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=eC9Xuz90; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TMwr91pLnz1yQ0 for ; Sun, 28 Jan 2024 13:49:29 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4D72B3CE195 for ; Sun, 28 Jan 2024 03:49:27 +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 [IPv6:2001:4b78:1:20::4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 053003CC7D6 for ; Sun, 28 Jan 2024 03:48:52 +0100 (CET) Authentication-Results: in-4.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-4.smtp.seeweb.it (Postfix) with ESMTPS id 6CA101011BFF for ; Sun, 28 Jan 2024 03:48:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706410130; 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=VNJjhC/CjXE0oqb3ORKBJa/FU/7ibQIkkLDsk9BJIxY=; b=eC9Xuz90bkqMh1np8jcAw956Uq5+sgNU4dQF1nsrysJCXu0CaDBsvh134BD8KInA6Wc6jh Xh+R6HlCp0EKVn9wwHOvvv5eEsMdNQmhLvr2cKsycygwW8pjChdCjb5etVT5N0vikOzFER 59hf7JASkneMZm2Nyzhg1OZa/+xka8c= 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-481-77KiLYUjOrSbJ7EenGikRg-1; Sat, 27 Jan 2024 21:48:47 -0500 X-MC-Unique: 77KiLYUjOrSbJ7EenGikRg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 D0CD129AB3EC; Sun, 28 Jan 2024 02:48:46 +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 9E4431C060B1; Sun, 28 Jan 2024 02:48:45 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Sun, 28 Jan 2024 10:48:32 +0800 Message-Id: <20240128024838.2699248-3-liwang@redhat.com> In-Reply-To: <20240128024838.2699248-1-liwang@redhat.com> References: <20240128024838.2699248-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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 v5 2/8] 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 Tested-by: Petr Vorel Reviewed-by: Petr Vorel --- 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 }; From patchwork Sun Jan 28 02:48:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1891832 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=jOi6A9FO; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TMwrm6JH3z1yQ0 for ; Sun, 28 Jan 2024 13:50:00 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DA5F53CE5F2 for ; Sun, 28 Jan 2024 03:49:58 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 74F4C3CE19A for ; Sun, 28 Jan 2024 03:48:57 +0100 (CET) Authentication-Results: in-6.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-6.smtp.seeweb.it (Postfix) with ESMTPS id D22FF1400E1A for ; Sun, 28 Jan 2024 03:48:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706410133; 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=8e+5PnydiAjGtB6qXElWFCEHlHGnXso8cOSkA+m6ysk=; b=jOi6A9FOxFB1oO+tLNMLzPLo7qxXe/9C1uIs1/3CQotipSg73vU5gmI4bRtBa+tzfa2yuB HdtaehFb8QrAUA6XlUuieJDvPs7ksaMdZVkYqBbFcN1cRVROXhP7sdXdkcaarHwZpPNgRE mZO1ohvUr385qh+uDd8bqp6qpDZYnAM= 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-20-ZyXaPHcRMqq8lPCXoTwKyw-1; Sat, 27 Jan 2024 21:48:49 -0500 X-MC-Unique: ZyXaPHcRMqq8lPCXoTwKyw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 9F75A837224; Sun, 28 Jan 2024 02:48:48 +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 6CACC1C060B1; Sun, 28 Jan 2024 02:48:47 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Sun, 28 Jan 2024 10:48:33 +0800 Message-Id: <20240128024838.2699248-4-liwang@redhat.com> In-Reply-To: <20240128024838.2699248-1-liwang@redhat.com> References: <20240128024838.2699248-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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-6.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v5 3/8] swapon01: Improving test with memory limits and swap reporting 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 is target to create a more robust and controlled environment to test the swapon system call. By introducing memory limits through cgroups and filling memory with a known pattern, the test can better assess swapon behavior when the system experiences memory pressure. Additionally, the reporting of "SwapCached" memory before turning off the swap file provides a clearer understanding of the swap system's state in response to the test conditions. Signed-off-by: Li Wang Tested-by: Petr Vorel Reviewed-by: Petr Vorel --- testcases/kernel/syscalls/swapon/swapon01.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c index e1fe50459..a74a5171e 100644 --- a/testcases/kernel/syscalls/swapon/swapon01.c +++ b/testcases/kernel/syscalls/swapon/swapon01.c @@ -20,11 +20,15 @@ #define MNTPOINT "mntpoint" #define SWAP_FILE MNTPOINT"/swapfile01" +#define TESTMEM (1UL<<30) static void verify_swapon(void) { TST_EXP_PASS(tst_syscall(__NR_swapon, SWAP_FILE, 0)); + tst_pollute_memory(TESTMEM, 0x41); + tst_res(TINFO, "SwapCached: %ld Kb", SAFE_READ_MEMINFO("SwapCached:")); + if (TST_PASS && tst_syscall(__NR_swapoff, SWAP_FILE) != 0) { tst_brk(TBROK | TERRNO, "Failed to turn off swapfile, system reboot recommended"); @@ -35,6 +39,9 @@ static void setup(void) { is_swap_supported(SWAP_FILE); make_swapfile(SWAP_FILE, 0); + + SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid()); + SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM); } static struct tst_test test = { @@ -42,6 +49,7 @@ static struct tst_test test = { .mount_device = 1, .needs_root = 1, .all_filesystems = 1, + .needs_cgroup_ctrls = (const char *const []){ "memory", NULL }, .test_all = verify_swapon, .setup = setup }; From patchwork Sun Jan 28 02:48:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1891833 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=YvG4UXio; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TMws35Vgvz23fD for ; Sun, 28 Jan 2024 13:50:15 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CED573CCFE2 for ; Sun, 28 Jan 2024 03:50:13 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) (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 B7C0B3CE6C2 for ; Sun, 28 Jan 2024 03:48:56 +0100 (CET) Authentication-Results: in-5.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-5.smtp.seeweb.it (Postfix) with ESMTPS id BDCEB60094C for ; Sun, 28 Jan 2024 03:48:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706410134; 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=LEMCl16yw+0uNVzWsjE4r+ulLh1t1TrBaiIGsNFxshE=; b=YvG4UXionUxAvAFWbh8hD8VImqQH+mdd3GCYCrwoQmVFaKqyYA/1TlT2osTgxl3ENpc1oj lIDdKaRo4Q7DR1qZkgOy28ibJB7ZNKez4OKJZAfwO/LVpqkgSWXOD6APn7Z3PqcdAkPT/q 7Ljt14d2S7LndySt6Qyi4UWI0HR0Wl8= 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-614-SZbvF-KsOAOr6CGHfVWfyA-1; Sat, 27 Jan 2024 21:48:50 -0500 X-MC-Unique: SZbvF-KsOAOr6CGHfVWfyA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 6DFEA29AB3EB; Sun, 28 Jan 2024 02:48:50 +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 3B4391C060B1; Sun, 28 Jan 2024 02:48:48 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Sun, 28 Jan 2024 10:48:34 +0800 Message-Id: <20240128024838.2699248-5-liwang@redhat.com> In-Reply-To: <20240128024838.2699248-1-liwang@redhat.com> References: <20240128024838.2699248-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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-5.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-5.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v5 4/8] libswap: add function to prealloc contiguous file 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" The improve makes several key updates to the swap file handling in the libswap.c file: It incorporates support for the Btrfs filesystem, which is now recognized as a valid filesystem for swap files. A new function, set_nocow_attr, is added to apply the FS_NOCOW_FL flag to files on Btrfs filesystems. Introduces a new prealloc_contiguous_file function. This method preallocates a contiguous block of space for the swap file during its creation, rather than filling the file with data as was done previously. Modifications to the make_swapfile function are made to utilize prealloc_contiguous_file for creating the swap file, ensuring the file is created with contiguous space on the filesystem. Signed-off-by: Li Wang Tested-by: Petr Vorel Reviewed-by: Petr Vorel --- libs/libltpswap/libswap.c | 54 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c index 8c2ce6cd7..e606e3f03 100644 --- a/libs/libltpswap/libswap.c +++ b/libs/libltpswap/libswap.c @@ -4,6 +4,7 @@ * Author: Stanislav Kholmanskikh */ +#include #include #define TST_NO_DEFAULT_MAIN @@ -13,6 +14,7 @@ #include "lapi/syscalls.h" static const char *const swap_supported_fs[] = { + "btrfs", "ext2", "ext3", "ext4", @@ -23,6 +25,50 @@ static const char *const swap_supported_fs[] = { NULL }; +static void set_nocow_attr(const char *filename) +{ + int fd; + int attrs; + + tst_res(TINFO, "FS_NOCOW_FL attribute set on %s", filename); + + fd = SAFE_OPEN(filename, O_RDONLY); + + SAFE_IOCTL(fd, FS_IOC_GETFLAGS, &attrs); + + attrs |= FS_NOCOW_FL; + + SAFE_IOCTL(fd, FS_IOC_SETFLAGS, &attrs); + + SAFE_CLOSE(fd); +} + +static int prealloc_contiguous_file(const char *path, size_t bs, size_t bcount) +{ + int fd; + + fd = open(path, O_CREAT|O_WRONLY|O_TRUNC, 0600); + if (fd < 0) + return -1; + + /* Btrfs file need set 'nocow' attribute */ + if (tst_fs_type(path) == TST_BTRFS_MAGIC) + set_nocow_attr(path); + + if (tst_prealloc_size_fd(fd, bs, bcount)) { + close(fd); + unlink(path); + return -1; + } + + if (close(fd) < 0) { + unlink(path); + return -1; + } + + return 0; +} + /* * Make a swap file */ @@ -32,9 +78,15 @@ int make_swapfile(const char *swapfile, int safe) tst_brk(TBROK, "Insufficient disk space to create swap file"); /* create file */ - if (tst_fill_file(swapfile, 0, sysconf(_SC_PAGESIZE), 10) != 0) + if (prealloc_contiguous_file(swapfile, sysconf(_SC_PAGESIZE), 10) != 0) tst_brk(TBROK, "Failed to create swapfile"); + /* Full the file to make old xfs happy*/ + 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]; From patchwork Sun Jan 28 02:48:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1891831 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=gAECF4oI; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TMwrT3Ppfz1yQ0 for ; Sun, 28 Jan 2024 13:49:45 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 897013CE3B6 for ; Sun, 28 Jan 2024 03:49:43 +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 [IPv6:2001:4b78:1:20::4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 6DC7D3CCFE2 for ; Sun, 28 Jan 2024 03:48:56 +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 C5A391036E5B for ; Sun, 28 Jan 2024 03:48:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706410134; 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=HgP536nsY+EyzA6vAsIOoH/p8ASXIJFc5vTaT5YnoGo=; b=gAECF4oI+3HI24GW2uANgUbm7R7eJaIoNLjsOkBf9MQsNqk6LZ86Ai+HZsoosIXGe6YS7J WKOvIqCfXj+r9RPjHJwdOW+NNIQs7xK07RVhhtbqwMehIiBNPkw8ul9PnUXro+hFSzPOU3 kfRkw1oIT1wEhvFtyRiIXkAFF0E2AL4= 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-82-V6iUXkLiPsS4wQfkUMcyjA-1; Sat, 27 Jan 2024 21:48:52 -0500 X-MC-Unique: V6iUXkLiPsS4wQfkUMcyjA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 3BF8C185A781; Sun, 28 Jan 2024 02:48:52 +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 098D61C060B1; Sun, 28 Jan 2024 02:48:50 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Sun, 28 Jan 2024 10:48:35 +0800 Message-Id: <20240128024838.2699248-6-liwang@redhat.com> In-Reply-To: <20240128024838.2699248-1-liwang@redhat.com> References: <20240128024838.2699248-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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 v5 5/8] libswap: Introduce file contiguity 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 patch introduces a new function file_is_contiguous to the libltpswap library to determine if a swap file is stored in a contiguous block of disk space, which is a typical requirement for swap files in Linux. The function performs a series of checks using the fiemap structure to assess the contiguity of the file and logs the result. It is integrated into the is_swap_supported function to replace the previous tst_fibmap check, providing a more reliable method for verifying that a file suitable for swap is indeed contiguous. Signed-off-by: Li Wang Reviewed-by: Petr Vorel Tested-by: Petr Vorel --- libs/libltpswap/libswap.c | 70 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 5 deletions(-) diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c index e606e3f03..95d4f59b0 100644 --- a/libs/libltpswap/libswap.c +++ b/libs/libltpswap/libswap.c @@ -6,6 +6,8 @@ #include #include +#include +#include #define TST_NO_DEFAULT_MAIN @@ -69,6 +71,61 @@ static int prealloc_contiguous_file(const char *path, size_t bs, size_t bcount) return 0; } +static int file_is_contiguous(const char *filename) +{ + int fd, contiguous = 0; + struct fiemap *fiemap; + + if (tst_fibmap(filename) == 0) { + contiguous = 1; + goto out; + } + + if (tst_fs_type(filename) == TST_TMPFS_MAGIC) + goto out; + + fd = SAFE_OPEN(filename, O_RDONLY); + + fiemap = (struct fiemap *)SAFE_MALLOC(sizeof(struct fiemap) + sizeof(struct fiemap_extent)); + memset(fiemap, 0, sizeof(struct fiemap) + sizeof(struct fiemap_extent)); + + fiemap->fm_start = 0; + fiemap->fm_length = ~0; + fiemap->fm_flags = 0; + fiemap->fm_extent_count = 1; + + SAFE_IOCTL(fd, FS_IOC_FIEMAP, fiemap); + + /* + * fiemap->fm_mapped_extents != 1: + * This checks if the file does not have exactly one extent. If there are more + * or zero extents, the file is not stored in a single contiguous block. + * + * fiemap->fm_extents[0].fe_logical != 0: + * This checks if the first extent does not start at the logical offset 0 of + * the file. If it doesn't, it indicates that the file's first block of data + * is not at the beginning of the file, which implies non-contiguity. + * + * (fiemap->fm_extents[0].fe_flags & FIEMAP_EXTENT_LAST) != FIEMAP_EXTENT_LAST: + * This checks if the first extent does not have the FIEMAP_EXTENT_LAST flag set. + * If the flag isn't set, it means that this extent is not the last one, suggesting + * that there are more extents and the file is not contiguous. + */ + if (fiemap->fm_mapped_extents != 1 || + fiemap->fm_extents[0].fe_logical != 0 || + (fiemap->fm_extents[0].fe_flags & FIEMAP_EXTENT_LAST) != FIEMAP_EXTENT_LAST) { + + tst_res(TINFO, "File '%s' is not contiguous", filename); + contiguous = 0; + } + + SAFE_CLOSE(fd); + free(fiemap); + +out: + return contiguous; +} + /* * Make a swap file */ @@ -105,10 +162,15 @@ 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); + int ret = make_swapfile(filename, 1); + int fi_contiguous = file_is_contiguous(filename); long fs_type = tst_fs_type(filename); const char *fstype = tst_fs_type_name(fs_type); + if (fs_type == TST_BTRFS_MAGIC && + tst_kvercmp(5, 0, 0) < 0) + tst_brk(TCONF, "Swapfile on Btrfs (kernel < 5.0) not implemented"); + for (i = 0; swap_supported_fs[i]; i++) { if (strstr(fstype, swap_supported_fs[i])) { sw_support = 1; @@ -116,10 +178,8 @@ void is_swap_supported(const char *filename) } } - int ret = make_swapfile(filename, 1); - if (ret != 0) { - if (fibmap == 1 && sw_support == 0) + if (fi_contiguous == 0 && sw_support == 0) tst_brk(TCONF, "mkswap on %s not supported", fstype); else tst_brk(TFAIL, "mkswap on %s failed", fstype); @@ -129,7 +189,7 @@ void is_swap_supported(const char *filename) if (TST_RET == -1) { if (errno == EPERM) tst_brk(TCONF, "Permission denied for swapon()"); - else if (fibmap == 1 && errno == EINVAL && sw_support == 0) + else if (errno == EINVAL && fi_contiguous == 0 && sw_support == 0) tst_brk(TCONF, "Swapfile on %s not implemented", fstype); else tst_brk(TFAIL | TTERRNO, "swapon() on %s failed", fstype); From patchwork Sun Jan 28 02:48:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1891834 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=P9xr5YWM; 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 4TMwsT2wCzz23fD for ; Sun, 28 Jan 2024 13:50:37 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1F2263CE193 for ; Sun, 28 Jan 2024 03:50:35 +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 [IPv6:2001:4b78:1:20::4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 661CA3CE6C2 for ; Sun, 28 Jan 2024 03:48:58 +0100 (CET) Authentication-Results: in-4.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-4.smtp.seeweb.it (Postfix) with ESMTPS id A005B1036E5F for ; Sun, 28 Jan 2024 03:48:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706410136; 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=UuEHZOwarWNWJLs9BLL7IqH547YDp6AV/jHcW7pRiE4=; b=P9xr5YWMMZAz5RX1AqRzc9bLBfOcmC0CHnSmImOdJEpAMGgDRkNC4JlvF0aROROcDx+7Zd 6vXrqmtJIDLN9+jer4rUHM7LQRr9eK3jUHzQBxEbepnmvBfeMJb5ROGwO1954XJ1Ly69Ya 5+HeU11GeOVlAprhNnVg8InGwAMXR84= 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-387-Dwe9xIIMNVqdccH49cPqbQ-1; Sat, 27 Jan 2024 21:48:53 -0500 X-MC-Unique: Dwe9xIIMNVqdccH49cPqbQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 B52FB837224 for ; Sun, 28 Jan 2024 02:48:53 +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 CB71C1C060B1 for ; Sun, 28 Jan 2024 02:48:52 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Sun, 28 Jan 2024 10:48:36 +0800 Message-Id: <20240128024838.2699248-7-liwang@redhat.com> In-Reply-To: <20240128024838.2699248-1-liwang@redhat.com> References: <20240128024838.2699248-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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 v5 6/8] libswap: customize swapfile size 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" The key change is the modification of the make_swapfile function to accept an additional parameter blocks, specifying the number of blocks to allocate for the swap file. This change allows for more granular control over the size of swap files created during tests. Signed-off-by: Li Wang --- include/libswap.h | 2 +- libs/libltpswap/libswap.c | 23 +++++++++++++------ testcases/kernel/syscalls/swapoff/swapoff01.c | 5 +--- testcases/kernel/syscalls/swapon/swapon01.c | 2 +- testcases/kernel/syscalls/swapon/swapon02.c | 4 ++-- testcases/kernel/syscalls/swapon/swapon03.c | 4 ++-- 6 files changed, 23 insertions(+), 17 deletions(-) diff --git a/include/libswap.h b/include/libswap.h index d4b5301a5..e67d65756 100644 --- a/include/libswap.h +++ b/include/libswap.h @@ -14,7 +14,7 @@ /* * Make a swap file */ -int make_swapfile(const char *swapfile, int safe); +int make_swapfile(const char *swapfile, int blocks, int safe); /* * Check swapon/swapoff support status of filesystems or files diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c index 95d4f59b0..8aecad48d 100644 --- a/libs/libltpswap/libswap.c +++ b/libs/libltpswap/libswap.c @@ -4,6 +4,7 @@ * Author: Stanislav Kholmanskikh */ +#include #include #include #include @@ -129,19 +130,27 @@ out: /* * Make a swap file */ -int make_swapfile(const char *swapfile, int safe) +int make_swapfile(const char *swapfile, int blocks, int safe) { - if (!tst_fs_has_free(".", sysconf(_SC_PAGESIZE) * 10, TST_BYTES)) + struct statvfs fs_info; + unsigned long blk_size; + + if (statvfs(".", &fs_info) == -1) + return -1; + + blk_size = fs_info.f_bsize; + + if (!tst_fs_has_free(".", blk_size * blocks, TST_BYTES)) tst_brk(TBROK, "Insufficient disk space to create swap file"); /* create file */ - if (prealloc_contiguous_file(swapfile, sysconf(_SC_PAGESIZE), 10) != 0) + if (prealloc_contiguous_file(swapfile, blk_size, blocks) != 0) tst_brk(TBROK, "Failed to create swapfile"); - /* Full the file to make old xfs happy*/ + /* Fill the file if needed (specific to old xfs filesystems) */ 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"); + if (tst_fill_file(swapfile, 0, blk_size, blocks) != 0) + tst_brk(TBROK, "Failed to fill swapfile"); } /* make the file swapfile */ @@ -162,7 +171,7 @@ int make_swapfile(const char *swapfile, int safe) void is_swap_supported(const char *filename) { int i, sw_support = 0; - int ret = make_swapfile(filename, 1); + int ret = make_swapfile(filename, 10, 1); int fi_contiguous = file_is_contiguous(filename); long fs_type = tst_fs_type(filename); const char *fstype = tst_fs_type_name(fs_type); diff --git a/testcases/kernel/syscalls/swapoff/swapoff01.c b/testcases/kernel/syscalls/swapoff/swapoff01.c index b27eecdad..e3b445d05 100644 --- a/testcases/kernel/syscalls/swapoff/swapoff01.c +++ b/testcases/kernel/syscalls/swapoff/swapoff01.c @@ -44,11 +44,8 @@ static void setup(void) tst_brk(TBROK, "Insufficient disk space to create swap file"); - if (tst_fill_file("swapfile01", 0x00, 1024, 65536)) + if (make_swapfile("swapfile01", 65536, 1)) tst_brk(TBROK, "Failed to create file for swap"); - - if (system("mkswap swapfile01 > tmpfile 2>&1") != 0) - tst_brk(TBROK, "Failed to make swapfile"); } static struct tst_test test = { diff --git a/testcases/kernel/syscalls/swapon/swapon01.c b/testcases/kernel/syscalls/swapon/swapon01.c index a74a5171e..d406e4bd9 100644 --- a/testcases/kernel/syscalls/swapon/swapon01.c +++ b/testcases/kernel/syscalls/swapon/swapon01.c @@ -38,7 +38,7 @@ static void verify_swapon(void) static void setup(void) { is_swap_supported(SWAP_FILE); - make_swapfile(SWAP_FILE, 0); + make_swapfile(SWAP_FILE, 10, 0); SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid()); SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM); diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c index fceea77be..f5b0d6d56 100644 --- a/testcases/kernel/syscalls/swapon/swapon02.c +++ b/testcases/kernel/syscalls/swapon/swapon02.c @@ -44,8 +44,8 @@ static void setup(void) is_swap_supported("./tstswap"); SAFE_TOUCH("notswap", 0777, NULL); - make_swapfile("swapfile01", 0); - make_swapfile("alreadyused", 0); + make_swapfile("swapfile01", 10, 0); + make_swapfile("alreadyused", 10, 0); if (tst_syscall(__NR_swapon, "alreadyused", 0)) tst_res(TWARN | TERRNO, "swapon(alreadyused) failed"); diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c index dc633ebc6..e13009111 100644 --- a/testcases/kernel/syscalls/swapon/swapon03.c +++ b/testcases/kernel/syscalls/swapon/swapon03.c @@ -155,7 +155,7 @@ static int setup_swap(void) } /* Create the swapfile */ - make_swapfile(filename, 0); + make_swapfile(filename, 10, 0); /* turn on the swap file */ res = tst_syscall(__NR_swapon, filename, 0); @@ -178,7 +178,7 @@ static int setup_swap(void) /* Create all needed extra swapfiles for testing */ for (j = 0; j < testfiles; j++) - make_swapfile(swap_testfiles[j].filename, 0); + make_swapfile(swap_testfiles[j].filename, 10, 0); return 0; } From patchwork Sun Jan 28 02:48:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1891835 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=QAZcRuUA; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TMwsn020Gz23fD for ; Sun, 28 Jan 2024 13:50:52 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0A49E3CE19B for ; Sun, 28 Jan 2024 03:50:51 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id C8C2C3CE190 for ; Sun, 28 Jan 2024 03:48:58 +0100 (CET) Authentication-Results: in-6.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-6.smtp.seeweb.it (Postfix) with ESMTPS id 161CD1400E1A for ; Sun, 28 Jan 2024 03:48:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706410136; 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=Z3M6REz9GxQuJi5aonXtxeKpC8hGY/uZOTFqKiTvYdY=; b=QAZcRuUAdi+af7hXHN+kLd5r0hV/CphbtOlkBbYYG+xpRpSTim0CY1wPyFWy4hT3MqbSyV /gHBHdwPrrBEMwPczy2KpCrCnz9o1yrUCD/Vf7BYIG9+YOe9o80o5AxU3AJSlBb5nCjBwl xo2j5C3jqpuBxyQrbXVnrgti30ogYlg= 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-628-IPwpRFoyMOi1ozA4ic9TUw-1; Sat, 27 Jan 2024 21:48:55 -0500 X-MC-Unique: IPwpRFoyMOi1ozA4ic9TUw-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 3A6B583B82A for ; Sun, 28 Jan 2024 02:48:55 +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 508AD1C060B1 for ; Sun, 28 Jan 2024 02:48:54 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Sun, 28 Jan 2024 10:48:37 +0800 Message-Id: <20240128024838.2699248-8-liwang@redhat.com> In-Reply-To: <20240128024838.2699248-1-liwang@redhat.com> References: <20240128024838.2699248-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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-6.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v5 7/8] swapon/off: enable all_filesystem in swap test 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" Signed-off-by: Li Wang --- testcases/kernel/syscalls/swapoff/swapoff02.c | 11 ++++++----- testcases/kernel/syscalls/swapon/swapon02.c | 4 ++++ testcases/kernel/syscalls/swapon/swapon03.c | 4 ++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/testcases/kernel/syscalls/swapoff/swapoff02.c b/testcases/kernel/syscalls/swapoff/swapoff02.c index cd940b1e7..53060b320 100644 --- a/testcases/kernel/syscalls/swapoff/swapoff02.c +++ b/testcases/kernel/syscalls/swapoff/swapoff02.c @@ -18,6 +18,8 @@ #include "lapi/syscalls.h" #include "libswap.h" +#define MNTPOINT "mntpoint" + static int setup01(void); static void cleanup01(void); @@ -84,14 +86,13 @@ static void setup(void) is_swap_supported("./tstswap"); - if (!tst_fs_has_free(".", 1, TST_KB)) - tst_brk(TBROK, "Insufficient disk space to create swap file"); - - if (tst_fill_file("./swapfile01", 0x00, 1024, 1)) - tst_brk(TBROK, "Failed to create swapfile"); + if (make_swapfile("swapfile01", 10, 1)) + tst_brk(TBROK, "Failed to create file for swap"); } static struct tst_test test = { + .mntpoint = MNTPOINT, + .all_filesystems = 1, .needs_root = 1, .needs_tmpdir = 1, .test = verify_swapoff, diff --git a/testcases/kernel/syscalls/swapon/swapon02.c b/testcases/kernel/syscalls/swapon/swapon02.c index f5b0d6d56..acb789fc4 100644 --- a/testcases/kernel/syscalls/swapon/swapon02.c +++ b/testcases/kernel/syscalls/swapon/swapon02.c @@ -20,6 +20,8 @@ #include "lapi/syscalls.h" #include "libswap.h" +#define MNTPOINT "mntpoint" + static uid_t nobody_uid; static int do_swapoff; @@ -78,6 +80,8 @@ static void verify_swapon(unsigned int i) } static struct tst_test test = { + .mntpoint = MNTPOINT, + .all_filesystems = 1, .needs_root = 1, .needs_tmpdir = 1, .test = verify_swapon, diff --git a/testcases/kernel/syscalls/swapon/swapon03.c b/testcases/kernel/syscalls/swapon/swapon03.c index e13009111..249cb12c3 100644 --- a/testcases/kernel/syscalls/swapon/swapon03.c +++ b/testcases/kernel/syscalls/swapon/swapon03.c @@ -22,6 +22,8 @@ #include "swaponoff.h" #include "libswap.h" +#define MNTPOINT "mntpoint" + static int setup_swap(void); static int clean_swap(void); static int check_and_swapoff(const char *filename); @@ -265,6 +267,8 @@ static void cleanup(void) } static struct tst_test test = { + .mntpoint = MNTPOINT, + .all_filesystems = 1, .needs_root = 1, .needs_tmpdir = 1, .forks_child = 1, From patchwork Sun Jan 28 02:48:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1891836 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=SfvmCwIv; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TMwt43MXlz23fD for ; Sun, 28 Jan 2024 13:51:08 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 856BA3CFA3B for ; Sun, 28 Jan 2024 03:51:06 +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 9CDA33CE70B for ; Sun, 28 Jan 2024 03:49:01 +0100 (CET) Authentication-Results: in-4.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-4.smtp.seeweb.it (Postfix) with ESMTPS id 53C0B1000F26 for ; Sun, 28 Jan 2024 03:48:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706410138; 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=ldhElJT0G/3lc6jlpgrOHBx7SpfZOupzKY6bJNP8S4I=; b=SfvmCwIvuNNTCoVHuhMbWJgHSm6Xb171QnH3lca9ZJW6+ne5CIxDyspbSDVCvYd16v/9hb ZlLtpIZL0zY/1k71C2AyhObw89Hh7q4nPyI28bbfDruGhp2Xo1ApNkSoxcvuUiAN7w6c0A e9tRWhVzZ/DKnKSxJOU92TCbmwoIJW8= 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-637-MJrpJ9jvMGyejjcgkDlu1w-1; Sat, 27 Jan 2024 21:48:56 -0500 X-MC-Unique: MJrpJ9jvMGyejjcgkDlu1w-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 B372D827D85 for ; Sun, 28 Jan 2024 02:48:56 +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 C98D71C060B1 for ; Sun, 28 Jan 2024 02:48:55 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Sun, 28 Jan 2024 10:48:38 +0800 Message-Id: <20240128024838.2699248-9-liwang@redhat.com> In-Reply-To: <20240128024838.2699248-1-liwang@redhat.com> References: <20240128024838.2699248-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 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 v5 8/8] libswap: Refactor is_swap_supported function to return status 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 updates the is_swap_supported function in the libltpswap to return an integer status instead of void, allowing the function to communicate success or failure to the caller. It introduces checks and returns 0 on various failure conditions while logging the failure without aborting the test case. Signed-off-by: Li Wang Reviewed-by: Petr Vorel --- include/libswap.h | 2 +- libs/libltpswap/libswap.c | 28 ++++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/include/libswap.h b/include/libswap.h index e67d65756..1e09db031 100644 --- a/include/libswap.h +++ b/include/libswap.h @@ -20,5 +20,5 @@ int make_swapfile(const char *swapfile, int blocks, int safe); * Check swapon/swapoff support status of filesystems or files * we are testing on. */ -void is_swap_supported(const char *filename); +int is_swap_supported(const char *filename); #endif /* __LIBSWAP_H__ */ diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c index 8aecad48d..14b7d9e3a 100644 --- a/libs/libltpswap/libswap.c +++ b/libs/libltpswap/libswap.c @@ -168,7 +168,7 @@ int make_swapfile(const char *swapfile, int blocks, int safe) * Check swapon/swapoff support status of filesystems or files * we are testing on. */ -void is_swap_supported(const char *filename) +int is_swap_supported(const char *filename) { int i, sw_support = 0; int ret = make_swapfile(filename, 10, 1); @@ -188,23 +188,31 @@ void is_swap_supported(const char *filename) } if (ret != 0) { - if (fi_contiguous == 0 && sw_support == 0) + if (fi_contiguous == 0 && sw_support == 0) { tst_brk(TCONF, "mkswap on %s not supported", fstype); - else - tst_brk(TFAIL, "mkswap on %s failed", fstype); + } else { + tst_res(TFAIL, "mkswap on %s failed", fstype); + return 0; + } } TEST(tst_syscall(__NR_swapon, filename, 0)); if (TST_RET == -1) { - if (errno == EPERM) + if (errno == EPERM) { tst_brk(TCONF, "Permission denied for swapon()"); - else if (errno == EINVAL && fi_contiguous == 0 && sw_support == 0) + } else if (errno == EINVAL && fi_contiguous == 0 && sw_support == 0) { tst_brk(TCONF, "Swapfile on %s not implemented", fstype); - else - tst_brk(TFAIL | TTERRNO, "swapon() on %s failed", fstype); + } else { + tst_res(TFAIL | TTERRNO, "swapon() on %s failed", fstype); + return 0; + } } TEST(tst_syscall(__NR_swapoff, filename, 0)); - if (TST_RET == -1) - tst_brk(TFAIL | TTERRNO, "swapoff on %s failed", fstype); + if (TST_RET == -1) { + tst_res(TFAIL | TTERRNO, "swapoff on %s failed", fstype); + return 0; + } + + return (TST_RET == 0); }