@@ -119,6 +119,7 @@
/src/cloner
/src/renameat2
/src/t_rename_overwrite
+/src/mmap_mtime
# dmapi/ binaries
/dmapi/src/common/cmd/read_invis
@@ -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 =
new file mode 100644
@@ -0,0 +1,122 @@
+/*
+ * test to check that mtime is updated when writing to mmap
+ *
+ * Copyright (c) 2014 Plexistor Ltd. All rights reserved.
+*/
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <time.h>
+#include <sys/mman.h>
+#include <sys/signal.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <stdint.h>
+
+#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 <filename>\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);
+}
new file mode 100644
@@ -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
new file mode 100644
@@ -0,0 +1,4 @@
+QA output created by 080
+reading page...done
+writing something...done
+Success. mtime was updated as expected
@@ -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