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: 5938221 Return-Path: X-Original-To: patchwork-linux-nvdimm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 243E19F380 for ; Wed, 4 Mar 2015 16:37:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 060B220123 for ; Wed, 4 Mar 2015 16:37:33 +0000 (UTC) Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D59C4200FF for ; Wed, 4 Mar 2015 16:37:30 +0000 (UTC) Received: from ml01.vlan14.01.org (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CBDF980D4B; Wed, 4 Mar 2015 08:37:30 -0800 (PST) X-Original-To: linux-nvdimm@ml01.01.org Delivered-To: linux-nvdimm@ml01.01.org Received: from mail-we0-f174.google.com (mail-we0-f174.google.com [74.125.82.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 53ECE80D4B for ; Wed, 4 Mar 2015 08:37:29 -0800 (PST) Received: by wevl61 with SMTP id l61so10579367wev.0 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=eygEYL/Y+kXs1wzGCwcuaRGlwJuogWAvYC07ogUzq2jl+upFJHzQoWuYGHr2IPih97 GvguCSH1TbzrK/nEfktVrK0msY+GQAHkgLDJI5uN81ve6RtOYATy6GLoE2G3pPGJdK/h dhIhwVgn54XQmPLTZho3HWCDjT5VRBEWSqnJ5Y69eKnfl5Rixy5p/oTMPHQILzBcjQ7Y kO6zxztpqe6S+KarwO0BedK/I36++/pV1XPD2V26N6GP71HT6UQPvql/0ZC/+2WTHHh+ Ju6ZZpE9X5jPxbKDS0wZ79gZv4AZVOu+yCruFJ0DVmSkFMzHDDn/YrBHr6E1HArgOETg TDKg== X-Gm-Message-State: ALoCoQnOnwUeQkUWYTs17kd7OrNIzm97eN993Qv35wXlsGbQ/Y3gO/fGjHlB6wfc/Fpbl/wlgAnY 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 References: <54F733BD.7060807@plexistor.com> In-Reply-To: <54F733BD.7060807@plexistor.com> Subject: [Linux-nvdimm] [PATCH 1/3] xfstests: generic/080 test that mmap-write updates c/mtime X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, 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