From patchwork Wed Mar 4 16:37:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boaz Harrosh X-Patchwork-Id: 5938231 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 86314BF440 for ; Wed, 4 Mar 2015 16:37:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7141E20114 for ; Wed, 4 Mar 2015 16:37:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 32B03200FF for ; Wed, 4 Mar 2015 16:37:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933030AbbCDQhb (ORCPT ); Wed, 4 Mar 2015 11:37:31 -0500 Received: from mail-wg0-f46.google.com ([74.125.82.46]:36708 "EHLO mail-wg0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932934AbbCDQh3 (ORCPT ); Wed, 4 Mar 2015 11:37:29 -0500 Received: by wghn12 with SMTP id n12so7680543wgh.3 for ; Wed, 04 Mar 2015 08:37:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=jnNkjNy0BubXPjoWTR0a4lUlgbpAFIrinjoguDSKcAw=; b=gmHRFBLB7Qr262IBV5ntZhlgt1Z80/G1n7O6LlkSRt20rn1f3dl3gg3YB/sRIIlomh zGZAS/KeBier6f1fy9Dy4aGUwj8nztm3TA9UnycMjcnVJ+C3vAmGB3y4SH/tHwm8GNuT l+FRAOR5XXRsj4OTkcMCtyEdQX4Mdb7ar6RLdQwM5unNtyNqoAAb2e2sI+TGGm6Q7jqp JzTKay7zh5AVsbPDUaIV38Av+qkoTbANJqh+X4VgRtSKENASwUaZX3AGCmXC7Ch3cB/x aTM/vLjhI3V72CEnKTZG6XANCyNsvPjKcZQ7lf9Mj4G8VQZyzC0EghY8m3hH2tgOciSG PiGQ== X-Gm-Message-State: ALoCoQnoihe3PM50YZJY+MUQsmvGBEsG4pSZyhzTslcmurIgQHi0fnxI3J3BqTVbDDKDlebuMslr X-Received: by 10.194.24.103 with SMTP id t7mr9543297wjf.15.1425487047518; Wed, 04 Mar 2015 08:37:27 -0800 (PST) Received: from [10.0.0.5] ([207.232.55.62]) by mx.google.com with ESMTPSA id dn1sm4355455wid.11.2015.03.04.08.37.25 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Mar 2015 08:37:26 -0800 (PST) Message-ID: <54F734C4.7080409@plexistor.com> Date: Wed, 04 Mar 2015 18:37:24 +0200 From: Boaz Harrosh User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Dave Chinner , Matthew Wilcox , Andrew Morton , "Kirill A. Shutemov" , Jan Kara , Hugh Dickins , Mel Gorman , linux-mm@kvack.org, linux-nvdimm , linux-fsdevel Subject: [PATCH 1/3] xfstests: generic/080 test that mmap-write updates c/mtime References: <54F733BD.7060807@plexistor.com> In-Reply-To: <54F733BD.7060807@plexistor.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Yigal Korman when using mmap() for file i/o, writing to the file should update it's c/mtime. Specifically if we first mmap-read from a page, then memap-write to the same page. This test was failing for the initial submission of DAX because pfn based mapping do not have an page_mkwrite called for them. The new Kernel patches that introduce pfn_mkwrite fixes this test. Signed-off-by: Yigal Korman Signed-off-by: Omer Zilberberg Signed-off-by: Boaz Harrosh --- .gitignore | 1 + src/Makefile | 2 +- src/mmap_mtime.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/080 | 53 ++++++++++++++++++++++ tests/generic/080.out | 4 ++ tests/generic/group | 1 + 6 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 src/mmap_mtime.c create mode 100644 tests/generic/080 create mode 100644 tests/generic/080.out diff --git a/.gitignore b/.gitignore index 41e1dc4..fd71526 100644 --- a/.gitignore +++ b/.gitignore @@ -119,6 +119,7 @@ /src/cloner /src/renameat2 /src/t_rename_overwrite +/src/mmap_mtime # dmapi/ binaries /dmapi/src/common/cmd/read_invis diff --git a/src/Makefile b/src/Makefile index fa5f0f4..0e48728 100644 --- a/src/Makefile +++ b/src/Makefile @@ -19,7 +19,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ bulkstat_unlink_test_modified t_dir_offset t_futimens t_immutable \ stale_handle pwrite_mmap_blocked t_dir_offset2 seek_sanity_test \ seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \ - renameat2 t_getcwd e4compact + renameat2 t_getcwd e4compact mmap_mtime SUBDIRS = diff --git a/src/mmap_mtime.c b/src/mmap_mtime.c new file mode 100644 index 0000000..9a83227 --- /dev/null +++ b/src/mmap_mtime.c @@ -0,0 +1,122 @@ +/* + * test to check that mtime is updated when writing to mmap + * + * Copyright (c) 2014 Plexistor Ltd. All rights reserved. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define EXIT_SUCCESS 0 +#define EXIT_ERROR 1 +#define EXIT_TEST_FAILED 2 + +#define PAGE_SIZE (getpagesize()) + +struct timespec get_mtime(int fd) +{ + struct stat st; + int ret; + + ret = fstat(fd, &st); + if (ret) { + perror("fstat"); + exit(EXIT_TEST_FAILED); + } + + /* + printf("%d mtime: %lld.%.9ld\n", fd, + (long long)st.st_mtim.tv_sec, st.st_mtim.tv_nsec); + */ + + return st.st_mtim; +} + +void print_usage (const char* progname) +{ + fprintf (stderr, "%s \n", progname); + exit(EXIT_ERROR); +} + +int main(int argc, char *argv[]) +{ + int ret = EXIT_SUCCESS; + loff_t size; + const char* filename; + int fd; + void *mapped_mem; + int i; + struct timespec before, after; + long tempc = 0; + uint64_t tempbuf[PAGE_SIZE/sizeof(uint64_t)]; // 4K buf + + if (argc < 2) + print_usage(argv[0]); + + filename = argv[1]; + size = PAGE_SIZE; + + fd = open(filename, O_CREAT | O_EXCL | O_RDWR, 0666); + if (fd < 0) { + fprintf(stderr, "%s: Cannot open `%s': %s\n", + argv[0], filename, strerror(errno)); + exit(EXIT_ERROR); + } + + // fill the file with random data in order to make sure we + // won't get fake "zero" pages from FS + if (write(fd, tempbuf, size) < 0) { + perror("write"); + close(fd); + exit(EXIT_ERROR); + } + + mapped_mem = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + if (mapped_mem == MAP_FAILED) { + perror("mmap"); + close(fd); + exit(EXIT_TEST_FAILED); + } + + printf("reading page..."); + for (i = 0; i < size/sizeof(char); i++) { + char *p = ((char*)mapped_mem) + i; + tempc += *p; + } + printf("done\n"); + + before = get_mtime(fd); + sleep(1); + + printf("writing something..."); + for (i = 0; i < size/sizeof(char); i++) { + char *p = ((char*)mapped_mem) + i; + *p = tempc + i; + } + printf("done\n"); + + after = get_mtime(fd); + + if ((before.tv_sec == after.tv_sec) && + (before.tv_nsec == after.tv_nsec)) { + printf("Failure. mtime was not updated.\n"); + ret = EXIT_TEST_FAILED; + } else { + // assuming no time travel/warp + printf("Success. mtime was updated as expected\n"); + } + + munmap(mapped_mem,0); + close(fd); + exit(ret); +} diff --git a/tests/generic/080 b/tests/generic/080 new file mode 100644 index 0000000..42e2a49 --- /dev/null +++ b/tests/generic/080 @@ -0,0 +1,53 @@ +#! /bin/bash +# FS QA Test No. 080 +# +# Verify that mtime is updated when writing to mmap-ed pages +# +#----------------------------------------------------------------------- +# Copyright (c) 2015 Yigal Korman (yigal@plexistor.com). All Rights Reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms 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. See the +# GNU General Public License for more details. +# +# 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 St, Fifth Floor, Boston, MA 02110-1301 USA +#----------------------------------------------------------------------- +# + +seq=`basename $0` +seqres=$RESULT_DIR/$seq +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + cd / + rm -f $tmp.* + rm -f $TEST_DIR/mmap_mtime_testfile +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter + +# real QA test starts here + +# Modify as appropriate. +_supported_fs generic +_supported_os IRIX Linux +_require_test + +$here/src/mmap_mtime $TEST_DIR/mmap_mtime_testfile +status=$? +exit diff --git a/tests/generic/080.out b/tests/generic/080.out new file mode 100644 index 0000000..118fd24 --- /dev/null +++ b/tests/generic/080.out @@ -0,0 +1,4 @@ +QA output created by 080 +reading page...done +writing something...done +Success. mtime was updated as expected diff --git a/tests/generic/group b/tests/generic/group index 11ce3e4..7ee5cdc 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -77,6 +77,7 @@ 076 metadata rw udf auto quick stress 077 acl attr auto enospc 079 acl attr ioctl metadata auto quick +080 auto quick 083 rw auto enospc stress 088 perms auto quick 089 metadata auto