Re: [PATCH 3/3] ext4: test for inline data + DAX corruption
On Mon, Sep 11, 2017 at 10:45:21PM -0600, Ross Zwisler wrote: > Add a regression test for the following kernel commit: > > ext4: prevent data corruption with inline data + DAX > > The test passes either if we don't encounter corruption, or if mounting > with DAX + inline data fails. The latter is the way that we prevent this > issue in the kernel. > > Signed-off-by: Ross ZwislerBesides the gitignore entry order issue and call the test program from $here/src/... issue, need another require rule: _require_ext4_mkfs_feature "inline_data" Otherwise this looks fine to me. Thanks, Eryu
Re: [PATCH 3/3] ext4: test for inline data + DAX corruption
On Mon, Sep 11, 2017 at 10:45:21PM -0600, Ross Zwisler wrote: > Add a regression test for the following kernel commit: > > ext4: prevent data corruption with inline data + DAX > > The test passes either if we don't encounter corruption, or if mounting > with DAX + inline data fails. The latter is the way that we prevent this > issue in the kernel. > > Signed-off-by: Ross Zwisler Besides the gitignore entry order issue and call the test program from $here/src/... issue, need another require rule: _require_ext4_mkfs_feature "inline_data" Otherwise this looks fine to me. Thanks, Eryu
[PATCH 3/3] ext4: test for inline data + DAX corruption
Add a regression test for the following kernel commit: ext4: prevent data corruption with inline data + DAX The test passes either if we don't encounter corruption, or if mounting with DAX + inline data fails. The latter is the way that we prevent this issue in the kernel. Signed-off-by: Ross Zwisler--- .gitignore | 1 + src/Makefile | 3 +- src/t_ext4_dax_inline_corruption.c | 70 +++ tests/ext4/031 | 84 ++ tests/ext4/031.out | 2 + tests/ext4/group | 1 + 6 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 src/t_ext4_dax_inline_corruption.c create mode 100755 tests/ext4/031 create mode 100644 tests/ext4/031.out diff --git a/.gitignore b/.gitignore index 4bdc5bf..37670e6 100644 --- a/.gitignore +++ b/.gitignore @@ -155,6 +155,7 @@ /src/t_mmap_cow_race /src/t_mmap_fallocate /src/t_ext4_dax_journal_corruption +/src/t_ext4_dax_inline_corruption # dmapi/ binaries /dmapi/src/common/cmd/read_invis diff --git a/src/Makefile b/src/Makefile index e6558e2..bcfae01 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_ext4_dax_journal_corruption + t_mmap_cow_race t_mmap_fallocate fsync-err t_ext4_dax_journal_corruption \ + t_ext4_dax_inline_corruption 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_ext4_dax_inline_corruption.c b/src/t_ext4_dax_inline_corruption.c new file mode 100644 index 000..4b7d893 --- /dev/null +++ b/src/t_ext4_dax_inline_corruption.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PAGE(a) ((a)*0x1000) +#define STRLEN 256 + +void err_exit(char *op) +{ + fprintf(stderr, "%s: %s\n", op, strerror(errno)); + exit(1); +} + +int main(int argc, char *argv[]) +{ + int fd, err, len = PAGE(1); + char *dax_data, *data; + char string[STRLEN]; + + if (argc < 2) { + printf("Usage: %s \n", basename(argv[0])); + exit(0); + } + + srand(time(NULL)); + snprintf(string, STRLEN, "random number %d\n", rand()); + + fd = open(argv[1], O_RDWR); + if (fd < 0) + err_exit("fd"); + + data = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + if (!data) + err_exit("mmap data"); + + /* this fallocate turns off inline data and turns on DAX */ + fallocate(fd, 0, 0, PAGE(2)); + + dax_data = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0); + if (!dax_data) + err_exit("mmap dax_data"); + + /* +* Write the data using the non-DAX mapping, and try and read it back +* using the DAX mapping. +*/ + strcpy(data, string); + if (strcmp(dax_data, string) != 0) + printf("Data miscompare\n"); + + err = munmap(dax_data, len); + if (err < 0) + err_exit("munmap dax_data"); + + err = munmap(data, len); + if (err < 0) + err_exit("munmap data"); + + err = close(fd); + if (err < 0) + err_exit("close"); + return 0; +} diff --git a/tests/ext4/031 b/tests/ext4/031 new file mode 100755 index 000..95a5c65 --- /dev/null +++ b/tests/ext4/031 @@ -0,0 +1,84 @@ +#! /bin/bash +# FS QA Test ext4/031 +# +# This is a regression test for kernel patch: +# ext4: prevent data corruption with inline data + DAX +# created by Ross Zwisler +# +#--- +# 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
[PATCH 3/3] ext4: test for inline data + DAX corruption
Add a regression test for the following kernel commit: ext4: prevent data corruption with inline data + DAX The test passes either if we don't encounter corruption, or if mounting with DAX + inline data fails. The latter is the way that we prevent this issue in the kernel. Signed-off-by: Ross Zwisler --- .gitignore | 1 + src/Makefile | 3 +- src/t_ext4_dax_inline_corruption.c | 70 +++ tests/ext4/031 | 84 ++ tests/ext4/031.out | 2 + tests/ext4/group | 1 + 6 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 src/t_ext4_dax_inline_corruption.c create mode 100755 tests/ext4/031 create mode 100644 tests/ext4/031.out diff --git a/.gitignore b/.gitignore index 4bdc5bf..37670e6 100644 --- a/.gitignore +++ b/.gitignore @@ -155,6 +155,7 @@ /src/t_mmap_cow_race /src/t_mmap_fallocate /src/t_ext4_dax_journal_corruption +/src/t_ext4_dax_inline_corruption # dmapi/ binaries /dmapi/src/common/cmd/read_invis diff --git a/src/Makefile b/src/Makefile index e6558e2..bcfae01 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_ext4_dax_journal_corruption + t_mmap_cow_race t_mmap_fallocate fsync-err t_ext4_dax_journal_corruption \ + t_ext4_dax_inline_corruption 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_ext4_dax_inline_corruption.c b/src/t_ext4_dax_inline_corruption.c new file mode 100644 index 000..4b7d893 --- /dev/null +++ b/src/t_ext4_dax_inline_corruption.c @@ -0,0 +1,70 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define PAGE(a) ((a)*0x1000) +#define STRLEN 256 + +void err_exit(char *op) +{ + fprintf(stderr, "%s: %s\n", op, strerror(errno)); + exit(1); +} + +int main(int argc, char *argv[]) +{ + int fd, err, len = PAGE(1); + char *dax_data, *data; + char string[STRLEN]; + + if (argc < 2) { + printf("Usage: %s \n", basename(argv[0])); + exit(0); + } + + srand(time(NULL)); + snprintf(string, STRLEN, "random number %d\n", rand()); + + fd = open(argv[1], O_RDWR); + if (fd < 0) + err_exit("fd"); + + data = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); + if (!data) + err_exit("mmap data"); + + /* this fallocate turns off inline data and turns on DAX */ + fallocate(fd, 0, 0, PAGE(2)); + + dax_data = mmap(NULL, len, PROT_READ, MAP_SHARED, fd, 0); + if (!dax_data) + err_exit("mmap dax_data"); + + /* +* Write the data using the non-DAX mapping, and try and read it back +* using the DAX mapping. +*/ + strcpy(data, string); + if (strcmp(dax_data, string) != 0) + printf("Data miscompare\n"); + + err = munmap(dax_data, len); + if (err < 0) + err_exit("munmap dax_data"); + + err = munmap(data, len); + if (err < 0) + err_exit("munmap data"); + + err = close(fd); + if (err < 0) + err_exit("close"); + return 0; +} diff --git a/tests/ext4/031 b/tests/ext4/031 new file mode 100755 index 000..95a5c65 --- /dev/null +++ b/tests/ext4/031 @@ -0,0 +1,84 @@ +#! /bin/bash +# FS QA Test ext4/031 +# +# This is a regression test for kernel patch: +# ext4: prevent data corruption with inline data + DAX +# created by Ross Zwisler +# +#--- +# 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` +tmp=/tmp/$$