Received: by 10.223.164.221 with SMTP id h29csp4692100wrb; Thu, 19 Oct 2017 22:30:33 -0700 (PDT) X-Google-Smtp-Source: ABhQp+RGs39rSub4iB0E7lie0xAYeNzyw7whhw0ZaClP+iQyexHrSRULl+4ndPiAp5xpWZM7UUic X-Received: by 10.98.192.18 with SMTP id x18mr3809628pff.280.1508477433223; Thu, 19 Oct 2017 22:30:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508477433; cv=none; d=google.com; s=arc-20160816; b=Z1wBFOb5yk+EAV0m860Hzh1S7YQ8rOHDLzcCMh4gNi14F34tQgi2mfUYKq59piEqR4 plHbfnIf/eDMkE2fBFFY3cpshQz7tlz6yaokllcOjyDVjyWSj4ZK4Bp9xAX3Wf/UYi7/ izbr8/PDIdExFLidCLI8/td8hy2CM/j9Xf9j+NzZxJZ4DPutapEzxQsY/bdjxJfOE4bk Vyc3KBNoahHmw/4TJZ8G727a3OPs2MENRA/JWlNeiUHN391F87/nxDYrRJo9/054vYvq /XG/3kyqVyO6/8MpbdXcW1iWA3fJTNhLSfWi8tfRKb56RndvWbdh0qkwhjBH4O+nWAih LzpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=Jt55L0qGkYKwtHYtASv4jl2t2kA22uTXERnjLvXsrik=; b=Nh6iUDWBC84aWe/PEApmstd1tIFgISY2hsRZMOMqHESDwQDyEq/uTEdYT3Y2Y64lyA xCUby5cPW818oVUyUvxeEjZL0Opnv2Js7XF3kVkeBXAUWrGT2PGbhrLOJJSrSC9I51VC 3EW50S8x2YPg1jXAtYJNyFBz/0x0J63ebt8zERWlMnCq9JKLN64RciVDd4LO9XkPfQ88 59U9K1Kkol9xA9vLcGrEnidWAYWGJOFgyrpZRqQzziTTODVzxy+RX7sQOoeeX/dNOZ8M ErvB8E2M9ewciws9XahH/JhgRFQUwSi0LWY8e7qPkNeYBusXq8f6eiACjQeHupfpf81P g6IA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 33si141341plb.370.2017.10.19.22.30.18; Thu, 19 Oct 2017 22:30:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751352AbdJTF34 (ORCPT + 99 others); Fri, 20 Oct 2017 01:29:56 -0400 Received: from mga11.intel.com ([192.55.52.93]:56689 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750752AbdJTF3y (ORCPT ); Fri, 20 Oct 2017 01:29:54 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Oct 2017 22:29:53 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,405,1503385200"; d="scan'208";a="1233031143" Received: from theros.lm.intel.com ([10.232.112.77]) by fmsmga002.fm.intel.com with ESMTP; 19 Oct 2017 22:29:53 -0700 From: Ross Zwisler To: linux-kernel@vger.kernel.org, Josef Bacik , Eryu Guan , fstests@vger.kernel.org Cc: Ross Zwisler , Alasdair Kergon , Dan Williams , Dave Chinner , Jan Kara , Mike Snitzer , Shaohua Li , dm-devel@redhat.com, linux-nvdimm@lists.01.org, linux-raid@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, Christoph Hellwig Subject: [fstests PATCH] generic: add test for DAX MAP_SYNC support Date: Thu, 19 Oct 2017 23:29:43 -0600 Message-Id: <20171020052943.15104-1-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20171020052404.13762-1-ross.zwisler@linux.intel.com> References: <20171020052404.13762-1-ross.zwisler@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a test that exercises DAX's new MAP_SYNC flag. This test creates a file and writes to it via an mmap(), but never syncs via fsync/msync. This process is tracked via dm-log-writes, then replayed. If MAP_SYNC is working the dm-log-writes replay will show the test file with the same size that we wrote via the mmap() because each allocating page fault included an implicit metadata sync. If MAP_SYNC isn't working (which you can test by fiddling with the parameters to mmap()) the file will be smaller or missing entirely. Note that dm-log-writes doesn't track the data that we write via the mmap(), so we can't do any data integrity checking. We can only verify that the metadata writes for the page faults happened. Signed-off-by: Ross Zwisler --- For this test to run successfully you'll need both Jan's MAP_SYNC series: https://www.spinics.net/lists/linux-xfs/msg11852.html and my series adding DAX support to dm-log-writes: https://lists.01.org/pipermail/linux-nvdimm/2017-October/012972.html --- .gitignore | 1 + common/dmlogwrites | 1 - src/Makefile | 3 +- src/t_map_sync.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/466 | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ tests/generic/466.out | 3 ++ tests/generic/group | 1 + 7 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 src/t_map_sync.c create mode 100755 tests/generic/466 create mode 100644 tests/generic/466.out diff --git a/.gitignore b/.gitignore index 2014c08..9fc0695 100644 --- a/.gitignore +++ b/.gitignore @@ -119,6 +119,7 @@ /src/t_getcwd /src/t_holes /src/t_immutable +/src/t_map_sync /src/t_mmap_cow_race /src/t_mmap_dio /src/t_mmap_fallocate diff --git a/common/dmlogwrites b/common/dmlogwrites index 247c744..5b57df9 100644 --- a/common/dmlogwrites +++ b/common/dmlogwrites @@ -23,7 +23,6 @@ _require_log_writes() [ -z "$LOGWRITES_DEV" -o ! -b "$LOGWRITES_DEV" ] && \ _notrun "This test requires a valid \$LOGWRITES_DEV" - _exclude_scratch_mount_option dax _require_dm_target log-writes _require_test_program "log-writes/replay-log" } diff --git a/src/Makefile b/src/Makefile index 3eb25b1..af7e7e9 100644 --- a/src/Makefile +++ b/src/Makefile @@ -13,7 +13,8 @@ TARGETS = dirstress fill fill2 getpagesize holes lstat64 \ multi_open_unlink dmiperf unwritten_sync genhashnames t_holes \ t_mmap_writev t_truncate_cmtime dirhash_collide t_rename_overwrite \ holetest t_truncate_self t_mmap_dio af_unix t_mmap_stale_pmd \ - t_mmap_cow_race t_mmap_fallocate fsync-err t_mmap_write_ro + t_mmap_cow_race t_mmap_fallocate fsync-err t_mmap_write_ro \ + t_map_sync LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ preallo_rw_pattern_writer ftrunc trunc fs_perms testx looptest \ diff --git a/src/t_map_sync.c b/src/t_map_sync.c new file mode 100644 index 0000000..8190f3c --- /dev/null +++ b/src/t_map_sync.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define MiB(a) ((a)*1024*1024) + +/* + * These two defines were added to the kernel via commits entitled + * "mm: Define MAP_SYNC and VM_SYNC flags" and + * "mm: introduce MAP_SHARED_VALIDATE, a mechanism to safely define new mmap + * flags", respectively. + */ +#define MAP_SYNC 0x80000 +#define MAP_SHARED_VALIDATE 0x3 + +void err_exit(char *op) +{ + fprintf(stderr, "%s: %s\n", op, strerror(errno)); + exit(1); +} + +int main(int argc, char *argv[]) +{ + int page_size = getpagesize(); + int len = MiB(1); + int i, fd, err; + char *data; + + if (argc < 2) { + printf("Usage: %s \n", basename(argv[0])); + exit(0); + } + + fd = open(argv[1], O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); + if (fd < 0) + err_exit("fd"); + + ftruncate(fd, 0); + ftruncate(fd, len); + + data = mmap(NULL, len, PROT_READ|PROT_WRITE, + MAP_SHARED_VALIDATE|MAP_SYNC, fd, 0); + if (data == MAP_FAILED) + err_exit("mmap"); + + /* + * We intentionally don't sync 'fd' manually. If MAP_SYNC is working + * these allocating page faults will cause the filesystem to sync its + * metadata so that when we replay the dm-log-writes log the test file + * will be 1 MiB in size. + * + * dm-log-writes doesn't track the data that we write via the mmap(), + * so we can't check that, we can only verify that the metadata writes + * happened. + */ + for (i = 0; i < len; i+=page_size) + data[i] = 0xff; + + err = munmap(data, len); + if (err < 0) + err_exit("munmap"); + + err = close(fd); + if (err < 0) + err_exit("close"); + + return 0; +} diff --git a/tests/generic/466 b/tests/generic/466 new file mode 100755 index 0000000..f39e6dc --- /dev/null +++ b/tests/generic/466 @@ -0,0 +1,77 @@ +#! /bin/bash +# FS QA Test No. 466 +# +# Use md_log_writes to verify that MAP_SYNC actually syncs metadata during +# page faults. +# +#----------------------------------------------------------------------- +# Copyright (c) 2017 Intel Corporation. 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` +status=1 # failure is the default! +trap "_cleanup; exit \$status" 0 1 2 3 15 + +_cleanup() +{ + _log_writes_cleanup +} + +# get standard environment, filters and checks +. ./common/rc +. ./common/filter +. ./common/dmlogwrites + +# remove previous $seqres.full before test +rm -f $seqres.full + +# real QA test starts here +_supported_fs generic +_supported_os Linux +_require_log_writes +_require_scratch_dax +_require_test_program "t_map_sync" + +_log_writes_init +_log_writes_mkfs >> $seqres.full 2>&1 +_log_writes_mount -o dax + +src/t_map_sync $SCRATCH_MNT/test + +# Unmount the scratch dir and tear down the log writes target +_log_writes_mark last +_log_writes_unmount +_log_writes_remove +_check_scratch_fs + +# check pre umount +_log_writes_replay_log last +_scratch_mount + +# We should see $SCRATCH_MNT/test as 1MiB in size +du -sh $SCRATCH_MNT/test | _filter_scratch | _filter_spaces + +_scratch_unmount +_check_scratch_fs + +echo "Silence is golden" +status=0 +exit diff --git a/tests/generic/466.out b/tests/generic/466.out new file mode 100644 index 0000000..4c54d7a --- /dev/null +++ b/tests/generic/466.out @@ -0,0 +1,3 @@ +QA output created by 466 +1.0M SCRATCH_MNT/test +Silence is golden diff --git a/tests/generic/group b/tests/generic/group index fbe0a7f..65328c6 100644 --- a/tests/generic/group +++ b/tests/generic/group @@ -468,3 +468,4 @@ 463 auto quick clone dangerous 464 auto rw 465 auto rw quick aio +466 auto quick dax -- 2.9.5 From 1585253485120261773@xxx Mon Nov 27 20:45:33 +0000 2017 X-GM-THRID: 1585253485120261773 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread