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 */