From patchwork Tue Jan 23 11: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: 1889673 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=jCYeZmJr; 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 4TK53D5vlTz23f0 for ; Tue, 23 Jan 2024 22:49:12 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D7B373CE217 for ; Tue, 23 Jan 2024 12:49:10 +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 [217.194.8.5]) (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 65F903CC758 for ; Tue, 23 Jan 2024 12:48:52 +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 C43A6601B3F for ; Tue, 23 Jan 2024 12:48:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706010530; 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=7JcF1vww/rTvQDEX3h1Q9l7H1iARRZard/ir+B9b1sY=; b=jCYeZmJrBb1wjHp5v/Pu42Nmlc+SQDbWJonoCrvS34FqL6KG5FkHnvLy3myMLEuvp8RTUB Mq1FqzjXj78wtaZ24NhsHan9nx4aUOXDM4mUzTqWx/WxcVqSOABdlWA04p3R3527pbWUg7 /ZIm+b96J50lCOyQjBVBhDuHBsr4GeM= 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-438-BCliw2vDN9S9Zuju5-8h9A-1; Tue, 23 Jan 2024 06:48:47 -0500 X-MC-Unique: BCliw2vDN9S9Zuju5-8h9A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 E2B5810651EF; Tue, 23 Jan 2024 11: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 6776451D5; Tue, 23 Jan 2024 11:48:45 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Tue, 23 Jan 2024 19:48:36 +0800 Message-Id: <20240123114840.2610533-2-liwang@redhat.com> In-Reply-To: <20240123114840.2610533-1-liwang@redhat.com> References: <20240123114840.2610533-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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 V3 1/5] 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 | 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 Tue Jan 23 11: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: 1889674 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=husDt2mH; 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 4TK53X5L7Qz23f0 for ; Tue, 23 Jan 2024 22:49:28 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4E51F3CE215 for ; Tue, 23 Jan 2024 12:49:26 +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 200D03CE213 for ; Tue, 23 Jan 2024 12:48:52 +0100 (CET) Authentication-Results: in-6.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-6.smtp.seeweb.it (Postfix) with ESMTPS id F00671400F9C for ; Tue, 23 Jan 2024 12:48:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706010530; 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=husDt2mHXurAPB1vHUJDWzdYnFaQVsdytvaiJeoG+VjobEBml4Zr5gylvWi0GDnL5l3udO aoASBUSbQflqbGKhsmbaH2aIrUAh1vdq0O22QcM+sYY6rj9ixqaFnZHC7iXW2dtw8X/Pyv 0XQz/SRNqzWVsCBJDFdxcRrNe39dX/c= 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-49-32oruQ_VNMqaoTvBm19-Cw-1; Tue, 23 Jan 2024 06:48:49 -0500 X-MC-Unique: 32oruQ_VNMqaoTvBm19-Cw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 0619585A59A; Tue, 23 Jan 2024 11:48:49 +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 7F1D351D5; Tue, 23 Jan 2024 11:48:47 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Tue, 23 Jan 2024 19:48:37 +0800 Message-Id: <20240123114840.2610533-3-liwang@redhat.com> In-Reply-To: <20240123114840.2610533-1-liwang@redhat.com> References: <20240123114840.2610533-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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 V3 2/5] 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 }; From patchwork Tue Jan 23 11: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: 1889675 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=fUKCiovS; 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 4TK53r6nRjz23f0 for ; Tue, 23 Jan 2024 22:49:44 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C573F3CE213 for ; Tue, 23 Jan 2024 12:49:42 +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 2B0783CE21D for ; Tue, 23 Jan 2024 12:48:55 +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 75A241400F81 for ; Tue, 23 Jan 2024 12:48:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706010532; 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=ldMb9g4osGuYl13i+2MdXQEX+MqHXW+dqt5cH8Wlar8=; b=fUKCiovSLFxYUbg7epkVkgw1zMxEYHXB85VukhY0v1XPICzw9IQcfTmtOKdb7A+cGe5x+v uCZgD5YB6njy6J48rEakivNgatldh99dUvsbyRZQ7aOVRx+XBgzmnn2e0ibetQjhSbnNmA 1pW3UFeLopWgW8jP6RKdT00Ulyl4hTw= 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-94-wsEq-XwtP46pc4JdQBXHiw-1; Tue, 23 Jan 2024 06:48:51 -0500 X-MC-Unique: wsEq-XwtP46pc4JdQBXHiw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 1CA2883BA89; Tue, 23 Jan 2024 11:48:51 +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 9565E51D5; Tue, 23 Jan 2024 11:48:49 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Tue, 23 Jan 2024 19:48:38 +0800 Message-Id: <20240123114840.2610533-4-liwang@redhat.com> In-Reply-To: <20240123114840.2610533-1-liwang@redhat.com> References: <20240123114840.2610533-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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 V3 3/5] 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 --- 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 Tue Jan 23 11:48:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1889676 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=dkM3On2C; 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 4TK5490JyMz23f0 for ; Tue, 23 Jan 2024 22:50:01 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1E4DC3CC791 for ; Tue, 23 Jan 2024 12:49:59 +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)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id D372F3CE213 for ; Tue, 23 Jan 2024 12:48:57 +0100 (CET) Authentication-Results: in-5.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-5.smtp.seeweb.it (Postfix) with ESMTPS id 59091600FBA for ; Tue, 23 Jan 2024 12:48:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706010534; 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=XJm7hR616bgL4oP2KvvsRKG/qxehq+IyMnQRzR8NOh4=; b=dkM3On2C3OZiW/ycc/GeCZlB6tbBdREkYUd0zSTnCQcvsmj/nINiVjvYy9JkWRA0GUFs3O pgdelAYxat+Jm3xTV3Irr5ouBKRqfb+4kxSuCvCDFy4YCuuQEm0dhoV0tklFka0p9nAjTs wSr5snrBLv5PRdJNLFNP+4+BaVWMcjA= 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-635-EnUiUgUqM7S5x0FAEn33ZA-1; Tue, 23 Jan 2024 06:48:53 -0500 X-MC-Unique: EnUiUgUqM7S5x0FAEn33ZA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 32DD0282D3C4; Tue, 23 Jan 2024 11: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 AC36851D5; Tue, 23 Jan 2024 11:48:51 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Tue, 23 Jan 2024 19:48:39 +0800 Message-Id: <20240123114840.2610533-5-liwang@redhat.com> In-Reply-To: <20240123114840.2610533-1-liwang@redhat.com> References: <20240123114840.2610533-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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 V3 4/5] 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 --- libs/libltpswap/libswap.c | 48 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c index 8c2ce6cd7..b253dbeec 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,7 +78,7 @@ 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"); /* make the file swapfile */ From patchwork Tue Jan 23 11:48:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 1889677 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=IG1s3YfN; 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 4TK54V2d7gz1yPg for ; Tue, 23 Jan 2024 22:50:18 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 00F203CEE80 for ; Tue, 23 Jan 2024 12:50:16 +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)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 516093CEE78 for ; Tue, 23 Jan 2024 12:49:01 +0100 (CET) Authentication-Results: in-2.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-2.smtp.seeweb.it (Postfix) with ESMTPS id 83705600653 for ; Tue, 23 Jan 2024 12:49:00 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1706010539; 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=LfJJlYSrcWE/qNTWfNYvmiLe03oI1oLwb0HH2kX6j4E=; b=IG1s3YfNrsGrRbfx0LminNMMh7tIwHb6rc5jQTH0xFThNYDeEiV113EvNjJ/t8z2us4jVG 2sWxVxrg0AETg2kmayPE6N7PW4BLNMT8YZzlSOrYMXgu7MOkw4oj5BSDr/Jm8KcM9Mx7v1 dXkQroFKwFRnOm3QkL9WGpFt5vSu+I8= 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-12-lc64sjx1NDe6aeNp_LYIaA-1; Tue, 23 Jan 2024 06:48:55 -0500 X-MC-Unique: lc64sjx1NDe6aeNp_LYIaA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 4955B1C0419B; Tue, 23 Jan 2024 11: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 C2E7551D5; Tue, 23 Jan 2024 11:48:53 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Tue, 23 Jan 2024 19:48:40 +0800 Message-Id: <20240123114840.2610533-6-liwang@redhat.com> In-Reply-To: <20240123114840.2610533-1-liwang@redhat.com> References: <20240123114840.2610533-1-liwang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 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 V3 5/5] 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 --- libs/libltpswap/libswap.c | 72 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 67 insertions(+), 5 deletions(-) diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c index b253dbeec..8382ea23c 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,63 @@ 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) { + contiguous = 0; + 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 */ @@ -99,10 +158,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; @@ -110,10 +174,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); @@ -123,7 +185,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);