From patchwork Wed Oct 10 23:34:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 982146 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="E/+pHEAs"; 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 42Vr7R4ZcLz9s3l for ; Thu, 11 Oct 2018 10:35:31 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 231843E708F for ; Thu, 11 Oct 2018 01:35:29 +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 [217.194.8.6]) by picard.linux.it (Postfix) with ESMTP id 1D8173E70BB for ; Thu, 11 Oct 2018 01:34:57 +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-6.smtp.seeweb.it (Postfix) with ESMTPS id 93A36140054D for ; Thu, 11 Oct 2018 01:34:56 +0200 (CEST) Received: by mail-wr1-x443.google.com with SMTP id w5-v6so7564313wrt.2 for ; Wed, 10 Oct 2018 16:34:56 -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=bBO7rRPu5FDESQOq2udKjdxu0pAKbTF8JtLbmGTcg6I=; b=E/+pHEAsCWjf3rzu8J9ggag/1T8w08N9OUYzRsz6yoWMjePjsPGvZzstm+hV9sFeYD 16IH6UAYLDhcSvAZ5Tkz7IAyIPjezG2Kk11ueJGQ9iN9PUSEKHUlh0tVRbjxJpuUcrDM oXv00VjZXEMgDiZ6qYrRYyhY1vyoLNuv3A1KRjRQJyVoyW1o/SDkSckrsvtYVEHxNrA2 t1A2+w5sUrAn7JMloJmRQAFF3cIbVxCXxA/CnhWLyJCrx/I7xQe4mijSqX30smR8uM0l 9jzovhlU/GhRXTB5MnUv3SmtJ57Y7u26xy8NZBo3srYSJE4ymgRTUseoct8Lpl7odEK2 VWVQ== 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=bBO7rRPu5FDESQOq2udKjdxu0pAKbTF8JtLbmGTcg6I=; b=mP/5IJKqeKxbHTYFu6BzuMoQgdjTylbGTkPqqv3PQdj+255ZT/kLC1ipijlfvmQPYm Y2p22TvOto8xJhbNJSOSfAPPzV18+CBk39irCriPSHrY5BVUllsQ9ciUJ36o94y0yD2p or5jk+w6rXeivararOoaTiP9oAzOAvBVZuyaM4CvVdQWTEiYgtd6zUyGQylBpdBvNUUZ ZyQd94vZHITHwi73E3HOhxvSz2APnj0dnzn84zNRdcvCd7VIAhGD35nX3A0JGl4A/epN KA1yvrFA3fFB25sV0vK1CUjuiJqqAAj9lJspqaqjRmKiQhXHEn78zSUvzfjXsfz8I34j tldw== X-Gm-Message-State: ABuFfohEL+Lgdi8+Sb6a1+kXlj8gakPxNA8XIBDiiFzyJNm4T8vaua4u 0pGl7bd/FKqmpTIoLoyCHEg= X-Google-Smtp-Source: ACcGV621bCwaQPh4oVbwyIsDtU1bOkmQsQQ0rYGz8/mWkl+dAA4CS00AULMcxOJOqUu90KhLwEHMvA== X-Received: by 2002:adf:dc4a:: with SMTP id m10-v6mr24318999wrj.84.1539214496173; Wed, 10 Oct 2018 16:34:56 -0700 (PDT) Received: from localhost.localdomain ([141.226.14.107]) by smtp.gmail.com with ESMTPSA id h2-v6sm21768484wrs.34.2018.10.10.16.34.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 10 Oct 2018 16:34:55 -0700 (PDT) From: Amir Goldstein To: Cyril Hrubis Date: Thu, 11 Oct 2018 02:34:40 +0300 Message-Id: <20181010233441.5337-6-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181010233441.5337-1-amir73il@gmail.com> References: <20181010233441.5337-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 v3 5/6] 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 | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c index 56a8496ff..d5cc7677b 100644 --- a/testcases/kernel/syscalls/readahead/readahead02.c +++ b/testcases/kernel/syscalls/readahead/readahead02.c @@ -55,24 +55,49 @@ static struct tst_option options[] = { static struct tcase { const char *tname; int use_overlay; + int use_fadvise; } tcases[] = { - { "readahead on file", 0 }, - { "readahead on overlayfs file", 1 }, + { "readahead on file", 0, 0 }, + { "readahead on overlayfs file", 1, 0 }, + { "POSIX_FADV_WILLNEED on file", 0, 1 }, + { "POSIX_FADV_WILLNEED on overlayfs file", 1, 1 }, }; +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 readahead_supported = 1; +static int fadvise_supported = 1; static int check_ret(struct tcase *tc) { if (TST_RET == 0) return 0; - if (TST_ERR == EINVAL && - (!tc->use_overlay || !readahead_supported)) { + /* posix_fadvise returns error number (not in errno) */ + if (tc->use_fadvise && (TST_ERR = TST_RET) == EINVAL && + (!tc->use_overlay || !fadvise_supported)) { + fadvise_supported = 0; + tst_res(TCONF, "fadvise not supported on %s", + tst_device->fs_type); + } else if (TST_ERR == EINVAL && + (!tc->use_overlay || !readahead_supported)) { readahead_supported = 0; tst_res(TCONF, "readahead not supported on %s", tst_device->fs_type); } else { - tst_res(TFAIL | TTERRNO, "readahead failed on %s", + tst_res(TFAIL | TTERRNO, "%s failed on %s", + tc->use_fadvise ? "fadvise" : "readahead", tc->use_overlay ? "overlayfs" : tst_device->fs_type); } return 1; @@ -152,7 +177,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. @@ -182,7 +206,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) { SAFE_CLOSE(fd); return; @@ -264,6 +288,9 @@ static void test_readahead(unsigned int n) 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); cached_high = get_cached_size();