From patchwork Thu Oct 4 06:26:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 978666 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nrzYibzs"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Qjb52zgTz9s55 for ; Thu, 4 Oct 2018 16:26:41 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id A2E5A3E76B4 for ; Thu, 4 Oct 2018 08:26:38 +0200 (CEST) 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 [IPv6:2001:4b78:1:20::2]) by picard.linux.it (Postfix) with ESMTP id 331E73E714E for ; Thu, 4 Oct 2018 08:26:34 +0200 (CEST) Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id B1EF1600069 for ; Thu, 4 Oct 2018 08:26:33 +0200 (CEST) Received: by mail-wm1-x341.google.com with SMTP id e187-v6so233842wmf.0 for ; Wed, 03 Oct 2018 23:26:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VklIHkoZXk4CZxyaaGizzmMiENpn27JP7ULYyAEIY2A=; b=nrzYibzsAfuvrTcw63mD5CCUVDpJgpUWak3dF6hDMNaPCdYJhV9NbiOYBgkGfzNDej i9bL77MGxAXgkvQA7D0u8wLhxxaurOVK2s2pDVX12tJvo23O8h0ZaB9OO2e0bNnB/bEP KmQA8pzB35l4r+CrH2GnJQ7yz++41qBtVrbvTco4VqUsm+wU0X8LCSLkhOuoiquQsYGs HF4gTYSvyFcZJ0Mo0BxTZT2fnA1fsgwP7auKEmcBNCp4zhWKFFpXkvFWUA9A018enuiB 9koVMOPQmS89H/Pxc3nQmBwhL/+ishH9ZvMsYt4S0Bhhl9ZWHwY2gUynD8sA6jmbn94S aawQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VklIHkoZXk4CZxyaaGizzmMiENpn27JP7ULYyAEIY2A=; b=PH8rLtdp4/bYzXi5uu1cAkLCS2jPbYAhvrf+t6FNOdhVXS0MI1NfetKomflMinSED1 61L4Fk2E79OR8GK0SHQXCCj30bsL4XyJUGgCKoP5pEptEJtvOnwx9D9G1r2K3Fa++gdd D0I56j82pce8+5vjCUccxCX6H2RUimb6mR/XM4pQmlfkRYAY4utwD47yl79OotR5ZgKq t7HoRGT+0juyQissM5Vfly6JfjBVQ2MI9/knRn2FPDq+to62u8TO2tz5b4iFkgNNvG7v 5tqcn/HhFFxGiNV/ZkA5MDrUZbhfnHBjl6mfn7kp8w89LY0P+AwjjtS1e3PqTqzlETgT Z2ZA== X-Gm-Message-State: ABuFfoiHoIHJu6331zFg4C7CzJUknfNrfHkK6sG5iYGfG8A8VSjTY1DB ZQavIe3NkdQiSs8w1Nucedg= X-Google-Smtp-Source: ACcGV62lMOoz72Z4rXt0x5f+D1CU6b5MB+CI5gyLFY88IkxJQQEtUHi/Xjrcw46Get7leLKzYkAdyw== X-Received: by 2002:a1c:e5cf:: with SMTP id c198-v6mr3570816wmh.113.1538634393161; Wed, 03 Oct 2018 23:26:33 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 77-v6sm7752713wmv.6.2018.10.03.23.26.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 23:26:32 -0700 (PDT) From: Amir Goldstein To: Cyril Hrubis Date: Thu, 4 Oct 2018 09:26:20 +0300 Message-Id: <20181004062624.27295-2-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181004062624.27295-1-amir73il@gmail.com> References: <20181004062624.27295-1-amir73il@gmail.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Cc: linux-unionfs@vger.kernel.org, ltp@lists.linux.it, Miklos Szeredi Subject: [LTP] [PATCH v2 1/5] syscalls/readahead01: Convert to newlib X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" * Use SPDX-License-Identifier Signed-off-by: Amir Goldstein Acked-by: Jan Stancek --- .../kernel/syscalls/readahead/readahead01.c | 119 +++++------------- 1 file changed, 34 insertions(+), 85 deletions(-) diff --git a/testcases/kernel/syscalls/readahead/readahead01.c b/testcases/kernel/syscalls/readahead/readahead01.c index f35019488..682b524b3 100644 --- a/testcases/kernel/syscalls/readahead/readahead01.c +++ b/testcases/kernel/syscalls/readahead/readahead01.c @@ -1,25 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2012 Linux Test Project, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Further, this software is distributed without any warranty that it - * is free of the rightful claim of any third person regarding - * infringement or the like. Any license provided herein, whether - * implied or otherwise, applies only to this software file. Patent - * licenses, if any, provided herein do not apply to combinations of - * this program with other software, or any other product whatsoever. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. */ /* @@ -36,47 +17,36 @@ #include #include #include "config.h" -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" #include "lapi/syscalls.h" -char *TCID = "readahead01"; -int TST_TOTAL = 1; - -option_t options[] = { - {NULL, NULL, NULL} -}; - #if defined(__NR_readahead) -static void setup(void); -static void cleanup(void); - static int check_ret(long expected_ret) { - if (expected_ret == TEST_RETURN) { - tst_resm(TPASS, "expected ret success - " - "returned value = %ld", TEST_RETURN); + if (expected_ret == TST_RET) { + tst_res(TPASS, "expected ret success - " + "returned value = %ld", TST_RET); return 0; } - tst_resm(TFAIL, "unexpected failure - " - "returned value = %ld, expected: %ld", - TEST_RETURN, expected_ret); + tst_res(TFAIL, "unexpected failure - " + "returned value = %ld, expected: %ld", + TST_RET, expected_ret); return 1; } static int check_errno(long expected_errno) { - if (TEST_ERRNO == expected_errno) { - tst_resm(TPASS | TTERRNO, "expected failure"); + if (TST_ERR == expected_errno) { + tst_res(TPASS | TTERRNO, "expected failure"); return 0; } - if (TEST_ERRNO == 0) - tst_resm(TFAIL, "call succeeded unexpectedly"); + if (TST_ERR == 0) + tst_res(TFAIL, "call succeeded unexpectedly"); else - tst_resm(TFAIL | TTERRNO, "unexpected failure - " - "expected = %ld : %s, actual", - expected_errno, strerror(expected_errno)); + tst_res(TFAIL | TTERRNO, "unexpected failure - " + "expected = %ld : %s, actual", + expected_errno, strerror(expected_errno)); return 1; } @@ -85,19 +55,17 @@ static void test_bad_fd(void) char tempname[PATH_MAX] = "readahead01_XXXXXX"; int fd; - tst_resm(TINFO, "test_bad_fd -1"); + tst_res(TINFO, "test_bad_fd -1"); TEST(readahead(-1, 0, getpagesize())); check_ret(-1); check_errno(EBADF); - tst_resm(TINFO, "test_bad_fd O_WRONLY"); + tst_res(TINFO, "test_bad_fd O_WRONLY"); fd = mkstemp(tempname); if (fd == -1) - tst_resm(TBROK | TERRNO, "mkstemp failed"); + tst_res(TBROK | TERRNO, "mkstemp failed"); close(fd); - fd = open(tempname, O_WRONLY); - if (fd == -1) - tst_resm(TBROK | TERRNO, "Failed to open testfile"); + fd = SAFE_OPEN(tempname, O_WRONLY); TEST(readahead(fd, 0, getpagesize())); check_ret(-1); check_errno(EBADF); @@ -109,60 +77,41 @@ static void test_invalid_fd(void) { int fd[2]; - tst_resm(TINFO, "test_invalid_fd pipe"); - if (pipe(fd) < 0) - tst_resm(TBROK | TERRNO, "Failed to create pipe"); + tst_res(TINFO, "test_invalid_fd pipe"); + SAFE_PIPE(fd); TEST(readahead(fd[0], 0, getpagesize())); check_ret(-1); check_errno(EINVAL); close(fd[0]); close(fd[1]); - tst_resm(TINFO, "test_invalid_fd socket"); - fd[0] = socket(AF_INET, SOCK_STREAM, 0); - if (fd[0] < 0) - tst_resm(TBROK | TERRNO, "Failed to create socket"); + tst_res(TINFO, "test_invalid_fd socket"); + fd[0] = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0); TEST(readahead(fd[0], 0, getpagesize())); check_ret(-1); check_errno(EINVAL); close(fd[0]); } -int main(int argc, char *argv[]) +void test_readahead(void) { - int lc; - - tst_parse_opts(argc, argv, options, NULL); - - setup(); - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - test_bad_fd(); - test_invalid_fd(); - } - cleanup(); - tst_exit(); + test_bad_fd(); + test_invalid_fd(); } static void setup(void) { - tst_require_root(); - tst_tmpdir(); - /* check if readahead syscall is supported */ - ltp_syscall(__NR_readahead, 0, 0, 0); - - TEST_PAUSE; + tst_syscall(__NR_readahead, 0, 0, 0); } -static void cleanup(void) -{ - tst_rmdir(); -} +static struct tst_test test = { + .needs_root = 1, + .needs_tmpdir = 1, + .setup = setup, + .test_all = test_readahead, +}; #else /* __NR_readahead */ -int main(void) -{ - tst_brkm(TCONF, NULL, "System doesn't support __NR_readahead"); -} + TST_TEST_TCONF("System doesn't support __NR_readahead"); #endif From patchwork Thu Oct 4 06:26:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 978667 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="uFdfLaJR"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Qjb94BX8z9s55 for ; Thu, 4 Oct 2018 16:26:45 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id F08673E7174 for ; Thu, 4 Oct 2018 08:26:42 +0200 (CEST) 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]) by picard.linux.it (Postfix) with ESMTP id 54DC83E7689 for ; Thu, 4 Oct 2018 08:26:36 +0200 (CEST) Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 60E01140174B for ; Thu, 4 Oct 2018 08:26:35 +0200 (CEST) Received: by mail-wr1-x444.google.com with SMTP id w5-v6so8543837wrt.2 for ; Wed, 03 Oct 2018 23:26:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=g2o3HnloOkAmBCKQzTWBqQev3i6knqbyNx/GQGmn5Pk=; b=uFdfLaJRkBHW9l3N244Zkj1/OMs0grMKyUZjK34u3GVg1d2ItmmsuWMuJBhjzRtNbF iBoA/q5h3uRPYHfNxLIdLuZM0tIWQ38eDvf8WsXBzhlRbjOWIPwwC2da8OPNtfl163jg 7fEy47ItE1Tejg7lEa8V1Fjt9luC/BQU+25pN185v8NeJHrINIO5rMSZHf19XT9HJhe1 tR0gbS1xyVxMOTNvtpl7eiLiCMIoWJ25NB5MzrTjTwVODv8/sPGI5jiHKhE6ZRgjZChn 90BInIYMVJs0HOqDtrmdsbARNPeEyFK062SDiqIIUsXuwYOETBWkkZ0hNJpJwaL/J17E mbCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=g2o3HnloOkAmBCKQzTWBqQev3i6knqbyNx/GQGmn5Pk=; b=EZ9N5YhrV5okwyhgMFnT8IQQJ3d5QJhMdjEDCLHLUukES9KzoCbU0dcatzjrMX6dmC F562Yk+1KzgnX4l2ZQ2f/2oFI3lyZpsaHE+wa9r93nuX189Ly2KpctvbvIbubuQyEKvR Y5+GHpuJBBBGddRSkbus3B1sZ5bM65TZzmgFr73HbU6Hkz1IqiUJoHJhcu/s11e4ddJk ySmYKRlqGX793Bk/CeYcUh0CrHm6uNbs19Qwhizx5xHe+LRzYXN+4ZuKlGF1e3Ew3WTQ UmTvIDJzcbFNrxCPlE5+jj6+Me1BPdhaXWET+lHgF4ECk0xYv/oKna7cR6iDxL9Fuy9w obSQ== X-Gm-Message-State: ABuFfog0jzrQk2g4LM331b7Rks0j/PErnOci6D6TVchGQcNMhEHmPdQH Pd4Ik4KY0h9CLaO0spF9zmg= X-Google-Smtp-Source: ACcGV623KuyfxAzE9m3NFdIMX5I98XwzXqmiVgsZsR8V30qQBYhw9fuxKmYuwI+WQxLAgvtEQBlByg== X-Received: by 2002:adf:f301:: with SMTP id i1-v6mr3492822wro.161.1538634394684; Wed, 03 Oct 2018 23:26:34 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 77-v6sm7752713wmv.6.2018.10.03.23.26.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 23:26:34 -0700 (PDT) From: Amir Goldstein To: Cyril Hrubis Date: Thu, 4 Oct 2018 09:26:21 +0300 Message-Id: <20181004062624.27295-3-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181004062624.27295-1-amir73il@gmail.com> References: <20181004062624.27295-1-amir73il@gmail.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-6.smtp.seeweb.it Cc: linux-unionfs@vger.kernel.org, ltp@lists.linux.it, Miklos Szeredi Subject: [LTP] [PATCH v2 2/5] syscalls/readahead02: Convert to newlib and cleanup X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" * Use SAFE macros * Use SPDX-License-Identifier * No need to cleanup test file from temp dir Signed-off-by: Amir Goldstein --- .../kernel/syscalls/readahead/readahead02.c | 248 +++++------------- 1 file changed, 72 insertions(+), 176 deletions(-) diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c index c9d92a6a4..c739d3ba2 100644 --- a/testcases/kernel/syscalls/readahead/readahead02.c +++ b/testcases/kernel/syscalls/readahead/readahead02.c @@ -1,25 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 /* * Copyright (C) 2012 Linux Test Project, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of version 2 of the GNU General Public - * License as published by the Free Software Foundation. - * - * This program is distributed in the hope that it would be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - * - * Further, this software is distributed without any warranty that it - * is free of the rightful claim of any third person regarding - * infringement or the like. Any license provided herein, whether - * implied or otherwise, applies only to this software file. Patent - * licenses, if any, provided herein do not apply to combinations of - * this program with other software, or any other product whatsoever. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - * 02110-1301, USA. */ /* @@ -43,86 +24,57 @@ #include #include #include "config.h" -#include "test.h" -#include "safe_macros.h" +#include "tst_test.h" #include "lapi/syscalls.h" -char *TCID = "readahead02"; -int TST_TOTAL = 1; - #if defined(__NR_readahead) static char testfile[PATH_MAX] = "testfile"; static const char drop_caches_fname[] = "/proc/sys/vm/drop_caches"; static const char meminfo_fname[] = "/proc/meminfo"; static size_t testfile_size = 64 * 1024 * 1024; -static int opt_fsize; static char *opt_fsizestr; static int pagesize; -static const char *fs_type; -static const char *device; -static int mount_flag; #define MNTPOINT "mntpoint" #define MIN_SANE_READAHEAD (4u * 1024u) -option_t options[] = { - {"s:", &opt_fsize, &opt_fsizestr}, +static const char mntpoint[] = MNTPOINT; + +static struct tst_option options[] = { + {"s:", &opt_fsizestr, "-s testfile size (default 64MB)"}, {NULL, NULL, NULL} }; -static void setup(void); -static void cleanup(void); - -static void help(void) -{ - printf(" -s x testfile size (default 64MB)\n"); -} - static int check_ret(long expected_ret) { - if (expected_ret == TEST_RETURN) { - tst_resm(TPASS, "expected ret success - " - "returned value = %ld", TEST_RETURN); + if (expected_ret == TST_RET) { + tst_res(TPASS, "expected ret success - " + "returned value = %ld", TST_RET); return 0; } - tst_resm(TFAIL | TTERRNO, "unexpected failure - " - "returned value = %ld, expected: %ld", - TEST_RETURN, expected_ret); + tst_res(TFAIL | TTERRNO, "unexpected failure - " + "returned value = %ld, expected: %ld", + TST_RET, expected_ret); return 1; } static int has_file(const char *fname, int required) { - int ret; struct stat buf; - ret = stat(fname, &buf); - if (ret == -1) { - if (errno == ENOENT) - if (required) - tst_brkm(TCONF, cleanup, "%s not available", - fname); - else - return 0; - else - tst_brkm(TBROK | TERRNO, cleanup, "stat %s", fname); + + if (stat(fname, &buf) == -1) { + if (errno != ENOENT) + tst_brk(TBROK | TERRNO, "stat %s", fname); + if (required) + tst_brk(TCONF, "%s not available", fname); + return 0; } return 1; } static void drop_caches(void) { - int ret; - FILE *f; - - f = fopen(drop_caches_fname, "w"); - if (f) { - ret = fprintf(f, "1"); - fclose(f); - if (ret < 1) - tst_brkm(TBROK, cleanup, "Failed to drop caches"); - } else { - tst_brkm(TBROK, cleanup, "Failed to open drop_caches"); - } + SAFE_FILE_PRINTF(drop_caches_fname, "1"); } static unsigned long parse_entry(const char *fname, const char *entry) @@ -161,32 +113,21 @@ static unsigned long get_cached_size(void) static void create_testfile(void) { - FILE *f; + int fd; char *tmp; size_t i; - tst_resm(TINFO, "creating test file of size: %zu", testfile_size); - tmp = SAFE_MALLOC(cleanup, pagesize); + tst_res(TINFO, "creating test file of size: %zu", testfile_size); + tmp = SAFE_MALLOC(pagesize); /* round to page size */ testfile_size = testfile_size & ~((long)pagesize - 1); - f = fopen(testfile, "w"); - if (!f) { - free(tmp); - tst_brkm(TBROK | TERRNO, cleanup, "Failed to create %s", - testfile); - } - + fd = SAFE_CREAT(testfile, 0644); for (i = 0; i < testfile_size; i += pagesize) - if (fwrite(tmp, pagesize, 1, f) < 1) { - free(tmp); - tst_brkm(TBROK, cleanup, "Failed to create %s", - testfile); - } - fflush(f); - fsync(fileno(f)); - fclose(f); + SAFE_WRITE(1, fd, tmp, pagesize); + SAFE_FSYNC(fd); + SAFE_CLOSE(fd); free(tmp); } @@ -215,13 +156,13 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize, off_t offset = 0; struct timeval now; - fd = SAFE_OPEN(cleanup, fname, O_RDONLY); + fd = SAFE_OPEN(fname, O_RDONLY); if (do_readahead) { cached_start = get_cached_size(); do { TEST(readahead(fd, offset, fsize - offset)); - if (TEST_RETURN != 0) { + if (TST_RET != 0) { check_ret(0); break; } @@ -232,7 +173,7 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize, if (*cached > cached_start) { max_ra_estimate = (1024 * (*cached - cached_start)); - tst_resm(TINFO, "max ra estimate: %lu", + tst_res(TINFO, "max ra estimate: %lu", max_ra_estimate); } max_ra_estimate = MAX(max_ra_estimate, @@ -242,27 +183,23 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize, i++; offset += max_ra_estimate; } while ((size_t)offset < fsize); - tst_resm(TINFO, "readahead calls made: %zu", i); + tst_res(TINFO, "readahead calls made: %zu", i); *cached = get_cached_size(); /* offset of file shouldn't change after readahead */ - offset = lseek(fd, 0, SEEK_CUR); - if (offset == (off_t) - 1) - tst_brkm(TBROK | TERRNO, cleanup, "lseek failed"); + offset = SAFE_LSEEK(fd, 0, SEEK_CUR); if (offset == 0) - tst_resm(TPASS, "offset is still at 0 as expected"); + tst_res(TPASS, "offset is still at 0 as expected"); else - tst_resm(TFAIL, "offset has changed to: %lu", offset); + tst_res(TFAIL, "offset has changed to: %lu", offset); } if (gettimeofday(&now, NULL) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "gettimeofday failed"); + tst_brk(TBROK | TERRNO, "gettimeofday failed"); time_start_usec = now.tv_sec * 1000000 + now.tv_usec; read_bytes_start = get_bytes_read(); - p = mmap(NULL, fsize, PROT_READ, MAP_SHARED | MAP_POPULATE, fd, 0); - if (p == MAP_FAILED) - tst_brkm(TBROK | TERRNO, cleanup, "mmap failed"); + p = SAFE_MMAP(NULL, fsize, PROT_READ, MAP_SHARED | MAP_POPULATE, fd, 0); /* for old kernels, where MAP_POPULATE doesn't work, touch each page */ tmp = 0; @@ -270,20 +207,20 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize, tmp = tmp ^ p[i]; /* prevent gcc from optimizing out loop above */ if (tmp != 0) - tst_brkm(TBROK, NULL, "This line should not be reached"); + tst_brk(TBROK, "This line should not be reached"); if (!do_readahead) *cached = get_cached_size(); - SAFE_MUNMAP(cleanup, p, fsize); + SAFE_MUNMAP(p, fsize); *read_bytes = get_bytes_read() - read_bytes_start; if (gettimeofday(&now, NULL) == -1) - tst_brkm(TBROK | TERRNO, cleanup, "gettimeofday failed"); + tst_brk(TBROK | TERRNO, "gettimeofday failed"); time_end_usec = now.tv_sec * 1000000 + now.tv_usec; *usec = time_end_usec - time_start_usec; - SAFE_CLOSE(cleanup, fd); + SAFE_CLOSE(fd); } static void test_readahead(void) @@ -302,7 +239,7 @@ static void test_readahead(void) cached_low = get_cached_size(); cached_max = cached_max - cached_low; - tst_resm(TINFO, "read_testfile(0)"); + tst_res(TINFO, "read_testfile(0)"); read_testfile(0, testfile, testfile_size, &read_bytes, &usec, &cached); if (cached > cached_low) cached = cached - cached_low; @@ -312,7 +249,7 @@ static void test_readahead(void) sync(); drop_caches(); cached_low = get_cached_size(); - tst_resm(TINFO, "read_testfile(1)"); + tst_res(TINFO, "read_testfile(1)"); read_testfile(1, testfile, testfile_size, &read_bytes_ra, &usec_ra, &cached_ra); if (cached_ra > cached_low) @@ -320,25 +257,25 @@ static void test_readahead(void) else cached_ra = 0; - tst_resm(TINFO, "read_testfile(0) took: %ld usec", usec); - tst_resm(TINFO, "read_testfile(1) took: %ld usec", usec_ra); + tst_res(TINFO, "read_testfile(0) took: %ld usec", usec); + tst_res(TINFO, "read_testfile(1) took: %ld usec", usec_ra); if (has_file(proc_io_fname, 0)) { - tst_resm(TINFO, "read_testfile(0) read: %ld bytes", read_bytes); - tst_resm(TINFO, "read_testfile(1) read: %ld bytes", - read_bytes_ra); + tst_res(TINFO, "read_testfile(0) read: %ld bytes", read_bytes); + tst_res(TINFO, "read_testfile(1) read: %ld bytes", + read_bytes_ra); /* actual number of read bytes depends on total RAM */ if (read_bytes_ra < read_bytes) - tst_resm(TPASS, "readahead saved some I/O"); + tst_res(TPASS, "readahead saved some I/O"); else - tst_resm(TFAIL, "readahead failed to save any I/O"); + tst_res(TFAIL, "readahead failed to save any I/O"); } else { - tst_resm(TCONF, "Your system doesn't have /proc/pid/io," - " unable to determine read bytes during test"); + tst_res(TCONF, "Your system doesn't have /proc/pid/io," + " unable to determine read bytes during test"); } - tst_resm(TINFO, "cache can hold at least: %ld kB", cached_max); - tst_resm(TINFO, "read_testfile(0) used cache: %ld kB", cached); - tst_resm(TINFO, "read_testfile(1) used cache: %ld kB", cached_ra); + tst_res(TINFO, "cache can hold at least: %ld kB", cached_max); + tst_res(TINFO, "read_testfile(0) used cache: %ld kB", cached); + tst_res(TINFO, "read_testfile(1) used cache: %ld kB", cached_ra); if (cached_max * 1024 >= testfile_size) { /* @@ -346,83 +283,42 @@ static void test_readahead(void) * for readahead should be at least testfile_size/2 */ if (cached_ra * 1024 > testfile_size / 2) - tst_resm(TPASS, "using cache as expected"); + tst_res(TPASS, "using cache as expected"); else - tst_resm(TWARN, "using less cache than expected"); + tst_res(TWARN, "using less cache than expected"); } else { - tst_resm(TCONF, "Page cache on your system is too small " - "to hold whole testfile."); + tst_res(TCONF, "Page cache on your system is too small " + "to hold whole testfile."); } } -int main(int argc, char *argv[]) -{ - int lc; - - tst_parse_opts(argc, argv, options, help); - - if (opt_fsize) - testfile_size = atoi(opt_fsizestr); - - setup(); - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - test_readahead(); - } - cleanup(); - tst_exit(); -} - static void setup(void) { - tst_require_root(); - tst_tmpdir(); - TEST_PAUSE; + if (opt_fsizestr) + testfile_size = SAFE_STRTOL(opt_fsizestr, 1, INT_MAX); has_file(drop_caches_fname, 1); has_file(meminfo_fname, 1); /* check if readahead is supported */ - ltp_syscall(__NR_readahead, 0, 0, 0); + tst_syscall(__NR_readahead, 0, 0, 0); pagesize = getpagesize(); - if (tst_fs_type(cleanup, ".") == TST_TMPFS_MAGIC) { - tst_resm(TINFO, "TMPFS detected, creating loop device"); - - fs_type = tst_dev_fs_type(); - device = tst_acquire_device(cleanup); - if (!device) { - tst_brkm(TCONF, cleanup, - "Failed to obtain block device"); - } - - tst_mkfs(cleanup, device, fs_type, NULL, NULL); - - SAFE_MKDIR(cleanup, MNTPOINT, 0755); - SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL); - mount_flag = 1; - - sprintf(testfile, MNTPOINT"/testfile"); - } + sprintf(testfile, "%s/testfile", mntpoint); create_testfile(); } -static void cleanup(void) -{ - unlink(testfile); - if (mount_flag && tst_umount(MNTPOINT) < 0) - tst_resm(TWARN | TERRNO, "umount device:%s failed", device); - - if (device) - tst_release_device(device); - - tst_rmdir(); -} +static struct tst_test test = { + .needs_root = 1, + .needs_tmpdir = 1, + .mount_device = 1, + .mntpoint = mntpoint, + .setup = setup, + .options = options, + .test_all = test_readahead, +}; #else /* __NR_readahead */ -int main(void) -{ - tst_brkm(TCONF, NULL, "System doesn't support __NR_readahead"); -} + TST_TEST_TCONF("System doesn't support __NR_readahead"); #endif From patchwork Thu Oct 4 06:26:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 978668 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="h6p0ZHLt"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42QjbF5BMGz9s55 for ; Thu, 4 Oct 2018 16:26:49 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 18C783E76AF for ; Thu, 4 Oct 2018 08:26:47 +0200 (CEST) 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 [IPv6:2001:4b78:1:20::2]) by picard.linux.it (Postfix) with ESMTP id 34BFD3E75A2 for ; Thu, 4 Oct 2018 08:26:37 +0200 (CEST) Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id A3611600069 for ; Thu, 4 Oct 2018 08:26:36 +0200 (CEST) Received: by mail-wr1-x443.google.com with SMTP id u12-v6so8506686wrr.4 for ; Wed, 03 Oct 2018 23:26:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tBnrR46P7R04B4QTghimKaRW4NbSjwPbTwKeOQjCMXI=; b=h6p0ZHLtPqqTCdyB/Xz8XdWlx+rHD7+3WExcZPY5rmiI38Vuly4YTvrSC18YCajfpG q0YCbDYltIokddBqlMD3et8uuRJArc4doiz+2L/MVq5lzVIoLTCn5wQpAp8TP+52/t6G 6m3ai8jLHdUENJB97q/Hyr4YgWx4ny+2lMdliN/ObxKvNviL92cDosoMm8Ks0/oMgiQY k7lGIk/j90l3wLJM/Tp6L9ejGIHZWyCSntso3+7b489Rj+ZjJW7BlrZ1FhsCwZyOc/6O JcaSNXggnTrm8k9x1AsmC+uFoqcTMdWzVG8JrcvIpU0ysIlKzD/1ecer/u8KXqeI9LTr IXXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tBnrR46P7R04B4QTghimKaRW4NbSjwPbTwKeOQjCMXI=; b=cHVpDsKnqyALRLvv4rNzinLL/xE1byqbdqRaPJgxm9L4ArhfdI4Y0GaYAY7hZyqWwF SXgDgrmNCxPs+ubFryoBX46r1mo67gal7aogijkXJlqtpj5aVS6Ur4TpXLUWw53GkfsP uOKyOE2uFAQ62Z15uzjxbNULzoBBAHlC81JwTacasNyX9raEQZackgJ3jpU7VxKeWR33 yUFtTwChCrVTWKsHPHInGI3KTgz/PoebHAE2JTrbrYpD9/VvzJUayotLCFLfZ7n5WNK4 29dICh2wskc/fq5nNxuOcrAsEjQN7fngi2JEln84govayvm1x1td/FXJ92SbmnWyYRXC HCpQ== X-Gm-Message-State: ABuFfojVyGU+Rk+aml5vGGTE8Zre6SedKgOPW6vyNnm9yF6JVk87WQYo erObxkcAi9J12Tbe3JRCOPk= X-Google-Smtp-Source: ACcGV61qzvCypGjI5ZMBNyKDU9iKWUwzfD9Fld6SNltRzLFNDAywsMnkyb9ehQuS3ZvFOQjtczvuig== X-Received: by 2002:adf:fb0e:: with SMTP id c14-v6mr3453740wrr.117.1538634396133; Wed, 03 Oct 2018 23:26:36 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 77-v6sm7752713wmv.6.2018.10.03.23.26.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 23:26:35 -0700 (PDT) From: Amir Goldstein To: Cyril Hrubis Date: Thu, 4 Oct 2018 09:26:22 +0300 Message-Id: <20181004062624.27295-4-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181004062624.27295-1-amir73il@gmail.com> References: <20181004062624.27295-1-amir73il@gmail.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Cc: linux-unionfs@vger.kernel.org, ltp@lists.linux.it, Miklos Szeredi Subject: [LTP] [PATCH v2 3/5] syscalls/readahead02: test readahead() on an overlayfs file X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Repeat the test case on an overlayfs file. The new test case is a regression test for kernel commit b833a3660394 ("ovl: add ovl_fadvise()") which fixes a regression of readahead() on an overlay file that was introduced by kernel commit 5b910bd615ba ("ovl: fix GPF in swapfile_activate of file from overlayfs over xfs"). Signed-off-by: Amir Goldstein --- .../kernel/syscalls/readahead/readahead02.c | 61 ++++++++++++++++--- 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c index c739d3ba2..158bfc955 100644 --- a/testcases/kernel/syscalls/readahead/readahead02.c +++ b/testcases/kernel/syscalls/readahead/readahead02.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -34,8 +35,14 @@ static const char meminfo_fname[] = "/proc/meminfo"; static size_t testfile_size = 64 * 1024 * 1024; static char *opt_fsizestr; static int pagesize; +static unsigned long cached_max; +static int ovl_mounted; #define MNTPOINT "mntpoint" +#define OVL_LOWER MNTPOINT"/lower" +#define OVL_UPPER MNTPOINT"/upper" +#define OVL_WORK MNTPOINT"/work" +#define OVL_MNT MNTPOINT"/ovl" #define MIN_SANE_READAHEAD (4u * 1024u) static const char mntpoint[] = MNTPOINT; @@ -111,12 +118,13 @@ static unsigned long get_cached_size(void) return parse_entry(meminfo_fname, entry); } -static void create_testfile(void) +static void create_testfile(int use_overlay) { int fd; char *tmp; size_t i; + sprintf(testfile, "%s/testfile", use_overlay ? OVL_MNT : MNTPOINT); tst_res(TINFO, "creating test file of size: %zu", testfile_size); tmp = SAFE_MALLOC(pagesize); @@ -223,21 +231,29 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize, SAFE_CLOSE(fd); } -static void test_readahead(void) +static void test_readahead(unsigned int use_overlay) { unsigned long read_bytes, read_bytes_ra; long usec, usec_ra; - unsigned long cached_max, cached_low, cached, cached_ra; + unsigned long cached_high, cached_low, cached, cached_ra; char proc_io_fname[128]; sprintf(proc_io_fname, "/proc/%u/io", getpid()); + if (use_overlay && !ovl_mounted) { + tst_res(TCONF, + "overlayfs is not configured in this kernel."); + return; + } + + create_testfile(use_overlay); + /* find out how much can cache hold if we read whole file */ read_testfile(0, testfile, testfile_size, &read_bytes, &usec, &cached); - cached_max = get_cached_size(); + cached_high = get_cached_size(); sync(); drop_caches(); cached_low = get_cached_size(); - cached_max = cached_max - cached_low; + cached_max = MAX(cached_max, cached_high - cached_low); tst_res(TINFO, "read_testfile(0)"); read_testfile(0, testfile, testfile_size, &read_bytes, &usec, &cached); @@ -292,6 +308,28 @@ static void test_readahead(void) } } +static void setup_overlay(void) +{ + int ret; + + /* Setup an overlay mount with lower dir and file */ + SAFE_MKDIR(OVL_LOWER, 0755); + SAFE_MKDIR(OVL_UPPER, 0755); + SAFE_MKDIR(OVL_WORK, 0755); + SAFE_MKDIR(OVL_MNT, 0755); + ret = mount("overlay", OVL_MNT, "overlay", 0, "lowerdir="OVL_LOWER + ",upperdir="OVL_UPPER",workdir="OVL_WORK); + if (ret < 0) { + if (errno == ENODEV) { + tst_res(TINFO, + "overlayfs is not configured in this kernel."); + return; + } + tst_brk(TBROK | TERRNO, "overlayfs mount failed"); + } + ovl_mounted = 1; +} + static void setup(void) { if (opt_fsizestr) @@ -305,8 +343,13 @@ static void setup(void) pagesize = getpagesize(); - sprintf(testfile, "%s/testfile", mntpoint); - create_testfile(); + setup_overlay(); +} + +static void cleanup(void) +{ + if (ovl_mounted) + SAFE_UMOUNT(OVL_MNT); } static struct tst_test test = { @@ -315,8 +358,10 @@ static struct tst_test test = { .mount_device = 1, .mntpoint = mntpoint, .setup = setup, + .cleanup = cleanup, .options = options, - .test_all = test_readahead, + .test = test_readahead, + .tcnt = 2, /* Repeat with overlayfs */ }; #else /* __NR_readahead */ From patchwork Thu Oct 4 06:26:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 978669 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EprN8AxO"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42QjbL4LZGz9s55 for ; Thu, 4 Oct 2018 16:26:54 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E7F2F3E7638 for ; Thu, 4 Oct 2018 08:26:51 +0200 (CEST) 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]) by picard.linux.it (Postfix) with ESMTP id 8A82F3E7637 for ; Thu, 4 Oct 2018 08:26:38 +0200 (CEST) Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id D7E951000D93 for ; Thu, 4 Oct 2018 08:26:37 +0200 (CEST) Received: by mail-wr1-x443.google.com with SMTP id 63-v6so8509695wra.11 for ; Wed, 03 Oct 2018 23:26:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=3FG79xdMKaPgwrCG1QW60HGjnyBGvMdqyDS5AjQBhms=; b=EprN8AxO7W0DJ06Zmentv6r+fUVIh4EWouLmkb408Q7zunDvWAaL56jVFLNE1AFyJ3 HlrSm9rc6X04xwqXBNGUEfWxVVNFjUMgr5kog6D51uAMYQHvGzesgbXm7RUQ5Cfu9Rd6 6qD0bO85UQPSxS57fIIjtJUf8q3AYDWD96jwGFfiZczPXYJaVw2suf3JYRodu/8Jm7Tz UV+i769X8E9TQXo83sqkN3CaXw1IAACpR8iB5yHFnGOaIke3OhnXPkCoHGA740f0QkKh B57Bz7x/fX53RaUAaV6b+7AfwtzJrgroZqrYViznh3bY4HGhyhN2RenzBJcL1s3TLNO+ MMwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=3FG79xdMKaPgwrCG1QW60HGjnyBGvMdqyDS5AjQBhms=; b=tywMVTRt41v5Rg0IFqaqe/yM0El/+l4DMbmGcCUVJ5jrLilTMldL2LrKUaMeEiNNDL tmluvitQgAu3cghczWf2f3uHJawPSj/Kzh7zVhQF+K3zihK3E9xFICiMC0eg5dGb0OeE gXXEnHWaITt6K6ciytIGBJAgy+etgm1FiUWzGFtn74rT0ikIqtwlfDBPFMOnTLu0sWU0 9XaMToMtfwSaAUfVHi1HQ7ViPKKcMkCzloaonueydBLJawRqmu4KIyoNneXsLBmu9MV2 STr4atPZRvCH2El8juDi1JZSvYipKNlyK5t1vIGIISbzeyUvUBFs1f7VNQZ6W8ZhquVk SdFA== X-Gm-Message-State: ABuFfoiwahl8/LX/wCNGc5WiZ8vSpbX4Mvkcb48N4Sy5C1qo7wP61hQp ZwAmIHbcQUfP44cobn4xEfI= X-Google-Smtp-Source: ACcGV61X74Ls0NDn31KjueJg9afgDZaorsb0sqVohLYx+wXC43b2+ScZQIJayome/Ejlc0B4dHT/MQ== X-Received: by 2002:a5d:450d:: with SMTP id s13-v6mr3532417wrq.82.1538634397358; Wed, 03 Oct 2018 23:26:37 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 77-v6sm7752713wmv.6.2018.10.03.23.26.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 23:26:36 -0700 (PDT) From: Amir Goldstein To: Cyril Hrubis Date: Thu, 4 Oct 2018 09:26:23 +0300 Message-Id: <20181004062624.27295-5-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181004062624.27295-1-amir73il@gmail.com> References: <20181004062624.27295-1-amir73il@gmail.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Cc: linux-unionfs@vger.kernel.org, ltp@lists.linux.it, Miklos Szeredi Subject: [LTP] [PATCH v2 4/5] syscalls/readahead02: test readahead using posix_fadvise() X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" The call to posix_fadvise(POSIX_FADV_WILLNEED) should have the same effect as the call to readahead() syscall. Repeat the test cases for local file and overlayfs file with posix_fadvise(). The new test case is a regression test for kernel commit b833a3660394 ("ovl: add ovl_fadvise()") which fixes a regression of fadvise() on an overlay file that was introduced by kernel commit 5b910bd615ba ("ovl: fix GPF in swapfile_activate of file from overlayfs over xfs"). Signed-off-by: Amir Goldstein --- .../kernel/syscalls/readahead/readahead02.c | 58 +++++++++++++++++-- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c index 158bfc955..ea73f8566 100644 --- a/testcases/kernel/syscalls/readahead/readahead02.c +++ b/testcases/kernel/syscalls/readahead/readahead02.c @@ -52,6 +52,46 @@ static struct tst_option options[] = { {NULL, NULL, NULL} }; +/* + * Check this system has fadvise64 syscall which is used in posix_fadvise. + * This is the only system configuration supported by the posix_fadvise tests, + * so use posix_fadvise in this test only with this system configuration. + */ +#ifdef __NR_fadvise64 +#define READAHEAD_WITH_FADVISE +#else +#if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS == 64) +#define READAHEAD_WITH_FADVISE +#endif +#endif + +static struct tcase { + const char *tname; + int use_overlay; + int use_fadvise; +} tcases[] = { + { "readahead on file", 0, 0 }, + { "readahead on overlayfs file", 1, 0 }, +#ifdef READAHEAD_WITH_FADVISE + { "POSIX_FADV_WILLNEED on file", 0, 1 }, + { "POSIX_FADV_WILLNEED on overlayfs file", 1, 1 }, +#endif +}; + +static int fadvise_willneed(int fd, off_t offset, size_t len) +{ + /* Should have the same effect as readahead() syscall */ + return posix_fadvise(fd, offset, len, POSIX_FADV_WILLNEED); +} + +static int libc_readahead(int fd, off_t offset, size_t len) +{ + return readahead(fd, offset, len); +} + +typedef int (*readahead_func_t)(int, off_t, size_t); +static readahead_func_t readahead_func = libc_readahead; + static int check_ret(long expected_ret) { if (expected_ret == TST_RET) { @@ -139,7 +179,6 @@ static void create_testfile(int use_overlay) free(tmp); } - /* read_testfile - mmap testfile and read every page. * This functions measures how many I/O and time it takes to fully * read contents of test file. @@ -169,7 +208,7 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize, if (do_readahead) { cached_start = get_cached_size(); do { - TEST(readahead(fd, offset, fsize - offset)); + TEST(readahead_func(fd, offset, fsize - offset)); if (TST_RET != 0) { check_ret(0); break; @@ -231,21 +270,28 @@ static void read_testfile(int do_readahead, const char *fname, size_t fsize, SAFE_CLOSE(fd); } -static void test_readahead(unsigned int use_overlay) +static void test_readahead(unsigned int n) { unsigned long read_bytes, read_bytes_ra; long usec, usec_ra; unsigned long cached_high, cached_low, cached, cached_ra; char proc_io_fname[128]; + struct tcase *tc = &tcases[n]; + + tst_res(TINFO, "Test #%d: %s", n, tc->tname); + sprintf(proc_io_fname, "/proc/%u/io", getpid()); - if (use_overlay && !ovl_mounted) { + if (tc->use_overlay && !ovl_mounted) { tst_res(TCONF, "overlayfs is not configured in this kernel."); return; } - create_testfile(use_overlay); + create_testfile(tc->use_overlay); + + /* Use either readahead() syscall or POSIX_FADV_WILLNEED */ + readahead_func = tc->use_fadvise ? fadvise_willneed : libc_readahead; /* find out how much can cache hold if we read whole file */ read_testfile(0, testfile, testfile_size, &read_bytes, &usec, &cached); @@ -361,7 +407,7 @@ static struct tst_test test = { .cleanup = cleanup, .options = options, .test = test_readahead, - .tcnt = 2, /* Repeat with overlayfs */ + .tcnt = ARRAY_SIZE(tcases), }; #else /* __NR_readahead */ From patchwork Thu Oct 4 06:26:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 978670 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="KvUXo4vo"; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42QjbQ1FF3z9s55 for ; Thu, 4 Oct 2018 16:26:58 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 857713E7686 for ; Thu, 4 Oct 2018 08:26:55 +0200 (CEST) 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]) by picard.linux.it (Postfix) with ESMTP id 9F6223E76A0 for ; Thu, 4 Oct 2018 08:26:39 +0200 (CEST) Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 13AA0600A9C for ; Thu, 4 Oct 2018 08:26:39 +0200 (CEST) Received: by mail-wr1-x442.google.com with SMTP id g15-v6so5902014wru.9 for ; Wed, 03 Oct 2018 23:26:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=z993t5qYihNdwfF5Vd0++tmGarjybDMmbH7/H4uBd+4=; b=KvUXo4vo95g0DE14QEjV1mK9jgS9RhYA7gwHmwp9bigEZX1hJM2TCtTncLPCObPe4d 1Sh+GZfiyebFl3crQaP67utC53LABfXuYrkyCA23xMUmcqKaOfGfk3QJsL5na2E0tUru XE2huR/Zl5SA+SmxYqW3H9tCOmAFV/47Q2X+nFh5xNKqy2oqabsGJtdx+RK170k8FBQH RECTEAkVeHfRmCoYi1t6i6ZJL1FnsxFXirZ/o27XKEq9xoan3dMRNN6L/uu17FaN7An1 c7Kjcdhxz7CSEgBBc1Rid9R9qfKl6TiDjnOPyMY29lEbdmlCOu42/qQkyZI97jjaJEhe /nuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=z993t5qYihNdwfF5Vd0++tmGarjybDMmbH7/H4uBd+4=; b=Lhm/LIxiXjiwvt2ZsCWI2wmFDq5aNC6kVWaU9AcXURMmt7fUTCVYmX/NVjGaZa6pEJ /eCFbDitEi3JIVwWbjT/0b3A1FrG5XYUfpRfHQK/GLxPhxuZssxrkSuIAwH2YM12rdz8 AZ2unamtk1YQAzhNT4nrxDYOVQIxEIhxedNXXEv7mWu0WtAEV0inQI2xLg5BysR2I3ta Rnj8Pm6hr/8XctykOhcnphN5QVBv4XnNKrtJUsLvZchVh4JgVhZ1le99NPAZLvDPr59a k5Puz93nC7q7lI0PT3gk99Hsi950O7W8aho/x4PPd4JNLh3QIC5t0b92irSAKei9pWMr xhQw== X-Gm-Message-State: ABuFfohwsQGy6aRkd9RLYTFURF0I+FFjoCw7yka/lT7vrr90Vh7dQNWn L06vRn+L2FWbTA6Ez1fH3Df96nVO X-Google-Smtp-Source: ACcGV61eiBGXkvknSCmtNqpvCiDcJVpTZ0Qr2JWsR54brUe1VKEjU8kIjQ1e5lBXjouKVsQONp3CiQ== X-Received: by 2002:adf:93e6:: with SMTP id 93-v6mr3569252wrp.81.1538634398675; Wed, 03 Oct 2018 23:26:38 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id 77-v6sm7752713wmv.6.2018.10.03.23.26.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Oct 2018 23:26:38 -0700 (PDT) From: Amir Goldstein To: Cyril Hrubis Date: Thu, 4 Oct 2018 09:26:24 +0300 Message-Id: <20181004062624.27295-6-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181004062624.27295-1-amir73il@gmail.com> References: <20181004062624.27295-1-amir73il@gmail.com> X-Virus-Scanned: clamav-milter 0.99.2 at in-5.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-5.smtp.seeweb.it Cc: linux-unionfs@vger.kernel.org, ltp@lists.linux.it, Miklos Szeredi Subject: [LTP] [PATCH v2 5/5] syscalls/readahead02: fail test if readahead did not use any cache X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" The heuristic of failing the test only if not saving any io has false negatives with overlayfs readahead() bug, but readahead() with overlayfs always warns on "using less cache then expected", when actually, it is using no cache at all. Add another condition to fail the test if readahead did not use any cache at all, which always detected the overlayfs bug. Signed-off-by: Amir Goldstein Acked-by: Jan Stancek --- testcases/kernel/syscalls/readahead/readahead02.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c index ea73f8566..918a694c1 100644 --- a/testcases/kernel/syscalls/readahead/readahead02.c +++ b/testcases/kernel/syscalls/readahead/readahead02.c @@ -346,6 +346,8 @@ static void test_readahead(unsigned int n) */ if (cached_ra * 1024 > testfile_size / 2) tst_res(TPASS, "using cache as expected"); + else if (!cached_ra) + tst_res(TFAIL, "readahead failed to use any cache"); else tst_res(TWARN, "using less cache than expected"); } else {