2016-05-13 20:50:56

by Anna Schumaker

[permalink] [raw]
Subject: [PATCH 0/5] Add copy_file_range() tests

These tests exercise the copy_file_range() system call, and check copying
data to both a new file and overwriting data inside an existing file. The
first patch adds the copy_file_range() utility for using the systemcall, and
is heavily based on src/cloner.c. The remaining patches add my tests.

Thanks,
Anna

Anna Schumaker (5):
src/copy_file_range: Add a program for testing vfs_copy_file_range()
generic/343: Add copy to new file test
generic/344: Add small copies to new file test
generic/345: Add copy test that overwrites data
generic/346: Add a copy test for overwriting small amounts of data

.gitignore | 1 +
common/rc | 7 ++
src/Makefile | 3 +-
src/copy_file_range.c | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++
tests/generic/343 | 96 +++++++++++++++++++++++++
tests/generic/343.out | 17 +++++
tests/generic/344 | 86 +++++++++++++++++++++++
tests/generic/344.out | 13 ++++
tests/generic/345 | 107 ++++++++++++++++++++++++++++
tests/generic/345.out | 17 +++++
tests/generic/346 | 94 +++++++++++++++++++++++++
tests/generic/346.out | 17 +++++
tests/generic/group | 4 ++
13 files changed, 650 insertions(+), 1 deletion(-)
create mode 100644 src/copy_file_range.c
create mode 100644 tests/generic/343
create mode 100644 tests/generic/343.out
create mode 100644 tests/generic/344
create mode 100644 tests/generic/344.out
create mode 100644 tests/generic/345
create mode 100644 tests/generic/345.out
create mode 100644 tests/generic/346
create mode 100644 tests/generic/346.out

--
2.8.2



2016-05-13 20:50:58

by Anna Schumaker

[permalink] [raw]
Subject: [PATCH 2/5] generic/343: Add copy to new file test

This test copies data from various points in a source file to a new
file. This is useful for testing the basics of copy_file_range().

Signed-off-by: Anna Schumaker <[email protected]>
---
tests/generic/343 | 96 +++++++++++++++++++++++++++++++++++++++++++++++++++
tests/generic/343.out | 17 +++++++++
tests/generic/group | 1 +
3 files changed, 114 insertions(+)
create mode 100644 tests/generic/343
create mode 100644 tests/generic/343.out

diff --git a/tests/generic/343 b/tests/generic/343
new file mode 100644
index 0000000..948b758
--- /dev/null
+++ b/tests/generic/343
@@ -0,0 +1,96 @@
+#!/bin/bash
+# FS QA Test No. 343
+#
+# Tests vfs_copy_file_range():
+# - Copy a file
+# - Copy beginning of original to new file
+# - Copy middle of original to a new file
+# - Copy end of original to new file
+#-----------------------------------------------------------------------
+# Copyright (c) 2016 Netapp, Inc. 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 -rf $tmp.*
+}
+
+# get standard environment
+. common/rc
+. common/filter
+
+# real QA test starts here
+_supported_os Linux
+
+_require_copy_file_range
+_require_test
+
+testdir=$TEST_DIR/test-$seq
+rm -rf $testdir
+mkdir $testdir
+
+_checksum_files()
+{
+ for f in $*; do
+ md5sum $testdir/$f | _filter_test_dir
+ done
+}
+
+rm -f $seqres.full
+
+echo "Create the original file and then copy"
+$XFS_IO_PROG -f -c 'pwrite -S 0x61 0 1000' $testdir/file >> $seqres.full 2>&1
+$XFS_IO_PROG -f -c 'pwrite -S 0x62 1000 1000' $testdir/file >> $seqres.full 2>&1
+$XFS_IO_PROG -f -c 'pwrite -S 0x63 2000 1000' $testdir/file >> $seqres.full 2>&1
+$XFS_IO_PROG -f -c 'pwrite -S 0x64 3000 1000' $testdir/file >> $seqres.full 2>&1
+$XFS_IO_PROG -f -c 'pwrite -S 0x65 4000 1000' $testdir/file >> $seqres.full 2>&1
+$COPY_FILE_RANGE_PROG $testdir/file $testdir/copy
+cmp $testdir/file $testdir/copy
+echo "Original md5sums:"
+_checksum_files file copy
+
+echo "Copy beginning of original file"
+$COPY_FILE_RANGE_PROG -l 1000 $testdir/file $testdir/beginning
+cmp -n 1000 $testdir/file $testdir/beginning
+echo "md5sums after copying beginning:"
+_checksum_files file beginning
+
+echo "Copy middle of original file"
+$COPY_FILE_RANGE_PROG -s 1000 -l 3000 $testdir/file $testdir/middle
+cmp -n 3000 $testdir/file $testdir/middle 1000
+echo "md5sums after copying middle:"
+_checksum_files file middle
+
+echo "Copy end of original file"
+$COPY_FILE_RANGE_PROG -s 4000 -l 1000 $testdir/file $testdir/end
+cmp -n 1000 $testdir/file $testdir/end 4000
+echo "md5sums after copying end:"
+_checksum_files file end
+
+#success, all done
+status=0
+exit
diff --git a/tests/generic/343.out b/tests/generic/343.out
new file mode 100644
index 0000000..f9b54aa
--- /dev/null
+++ b/tests/generic/343.out
@@ -0,0 +1,17 @@
+QA output created by 343
+Create the original file and then copy
+Original md5sums:
+e11fbace556cba26bf0076e74cab90a3 TEST_DIR/test-343/file
+e11fbace556cba26bf0076e74cab90a3 TEST_DIR/test-343/copy
+Copy beginning of original file
+md5sums after copying beginning:
+e11fbace556cba26bf0076e74cab90a3 TEST_DIR/test-343/file
+cabe45dcc9ae5b66ba86600cca6b8ba8 TEST_DIR/test-343/beginning
+Copy middle of original file
+md5sums after copying middle:
+e11fbace556cba26bf0076e74cab90a3 TEST_DIR/test-343/file
+4197de9da5badfc302715486b82bcdf1 TEST_DIR/test-343/middle
+Copy end of original file
+md5sums after copying end:
+e11fbace556cba26bf0076e74cab90a3 TEST_DIR/test-343/file
+e68d4a150c4e42f4f9ea3ffe4c9cf4ed TEST_DIR/test-343/end
diff --git a/tests/generic/group b/tests/generic/group
index ef1a423..d5e5242 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -345,3 +345,4 @@
340 auto
341 auto quick metadata
342 auto quick metadata
+343 auto quick copy
--
2.8.2


2016-05-13 20:50:57

by Anna Schumaker

[permalink] [raw]
Subject: [PATCH 1/5] src/copy_file_range: Add a program for testing vfs_copy_file_range()

This will be used by the various copy tests to call the Linux
copy_file_range() system call. I used src/cloner.c as a reference while
writing this tool.

Signed-off-by: Anna Schumaker <[email protected]>
---
.gitignore | 1 +
common/rc | 7 ++
src/Makefile | 3 +-
src/copy_file_range.c | 189 ++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 199 insertions(+), 1 deletion(-)
create mode 100644 src/copy_file_range.c

diff --git a/.gitignore b/.gitignore
index f9ea1fa..07cb94b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,6 +38,7 @@
/src/bstat
/src/bulkstat_unlink_test
/src/bulkstat_unlink_test_modified
+/src/copy_file_range
/src/dbtest
/src/devzero
/src/dirperf
diff --git a/common/rc b/common/rc
index 8bec836..735ff7a 100644
--- a/common/rc
+++ b/common/rc
@@ -2909,6 +2909,13 @@ _require_cloner()
_notrun "cloner binary not present at $CLONER_PROG"
}

+_require_copy_file_range()
+{
+ COPY_FILE_RANGE_PROG=$here/src/copy_file_range
+ [ -x $COPY_FILE_RANGE_PROG ] || \
+ _notrun "copy file range binary not present at $COPY_FILE_RANGE_PROG"
+}
+
_require_atime()
{
if [ "$FSTYP" == "nfs" ]; then
diff --git a/src/Makefile b/src/Makefile
index 1bf318b..b1b5766 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -20,7 +20,8 @@ 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 test-nextquota punch-alternating
+ renameat2 t_getcwd e4compact test-nextquota punch-alternating \
+ copy_file_range

SUBDIRS =

diff --git a/src/copy_file_range.c b/src/copy_file_range.c
new file mode 100644
index 0000000..067de26
--- /dev/null
+++ b/src/copy_file_range.c
@@ -0,0 +1,189 @@
+/*
+ * Tiny program to perform file range copies using the Linux system call.
+ *
+ * Copyright (c) 2016 Netapp, Inc. 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will 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 to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+#include <errno.h>
+#include <fcntl.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+static void
+usage(char *name, const char *msg)
+{
+ printf("Fatal: %s\n"
+ "Usage:\n"
+ "%s [options] <src_file> <dest_file>\n"
+ "\tA full file copy is performed by default, "
+ "unless any of the following are specified:\n"
+ "\t-s <offset>: source file offset (default = 0)\n"
+ "\t-d <offset>: destination file offset (default = 0)\n"
+ "\t-l <length>: length of copy (default = 0)\n",
+ msg, name);
+ _exit(1);
+}
+
+static loff_t
+copy_file_range(int src_fd, loff_t *src_pos, int dst_fd, loff_t *dst_pos,
+ size_t len, unsigned int flags)
+{
+ loff_t ret;
+
+ do {
+ ret = syscall(__NR_copy_file_range, src_fd, src_pos,
+ dst_fd, dst_pos,
+ len, flags);
+ if (ret == -1)
+ return errno;
+ len -= ret;
+ } while (len > 0);
+
+ return 0;
+}
+
+static loff_t
+copy_file(int src_fd, int dst_fd, unsigned int flags)
+{
+ struct stat stat;
+ loff_t src_pos = 0;
+ loff_t dst_pos = 0;
+ size_t len;
+ loff_t ret;
+
+ ret = fstat(src_fd, &stat);
+ if (ret == -1) {
+ ret = errno;
+ printf("stat failed: %s\n", strerror(ret));
+ return ret;
+ }
+
+ len = stat.st_size;
+ ret = ftruncate(dst_fd, 0);
+ if (ret == -1) {
+ ret = errno;
+ printf("truncate failed: %s\n", strerror(ret));
+ return ret;
+ }
+
+ return copy_file_range(src_fd, &src_pos, dst_fd, &dst_pos, len, flags);
+}
+
+
+int
+main(int argc, char **argv)
+{
+ char *src_file, *dst_file;
+ bool full_file = true;
+ loff_t src_off = 0;
+ loff_t dst_off = 0;
+ int src_fd, dst_fd;
+ size_t len = 0;
+ int opt, ret;
+
+ while ((opt = getopt(argc, argv, "s:d:l:")) != -1) {
+ char *sval_end;
+ switch (opt) {
+ case 's':
+ errno = 0;
+ src_off = strtoull(optarg, &sval_end, 10);
+ if ((errno) || (*sval_end != '\0'))
+ usage(argv[0], "invalid source offset");
+ full_file = false;
+ break;
+ case 'd':
+ errno = 0;
+ dst_off = strtoull(optarg, &sval_end, 10);
+ if ((errno) || (*sval_end != '\0'))
+ usage(argv[0], "invalid destination offset");
+ full_file = false;
+ break;
+ case 'l':
+ errno = 0;
+ len = strtoul(optarg, &sval_end, 10);
+ if ((errno) || (*sval_end != '\0'))
+ usage(argv[0], "invalid length");
+ full_file = false;
+ break;
+ default:
+ usage(argv[0], "invalid argument");
+ }
+ }
+
+ /* should be exactly two args left */
+ if (optind != argc - 2)
+ usage(argv[0], "src_file and dst_file arguments are mandatory");
+
+ src_file = (char *)strdup(argv[optind++]);
+ if (src_file == NULL) {
+ ret = ENOMEM;
+ printf("no memory\n");
+ goto err_out;
+ }
+ dst_file = (char *)strdup(argv[optind++]);
+ if (dst_file == NULL) {
+ ret = ENOMEM;
+ printf("no memory\n");
+ goto err_src_free;
+ }
+
+ src_fd = open(src_file, O_RDONLY);
+ if (src_fd == -1) {
+ ret = errno;
+ printf("failed to open %s: %s\n", src_file, strerror(errno));
+ goto err_dst_free;
+ }
+ dst_fd = open(dst_file, O_CREAT | O_WRONLY, 0644);
+ if (dst_fd == -1) {
+ ret = errno;
+ printf("failed to open %s: %s\n", dst_file, strerror(errno));
+ goto err_src_close;
+ }
+
+ if (full_file) {
+ ret = copy_file(src_fd, dst_fd, 0);
+ } else {
+ ret = copy_file_range(src_fd, &src_off, dst_fd, &dst_off, len, 0);
+ }
+ if (ret != 0) {
+ printf("copy failed: %s\n", strerror(ret));
+ goto err_dst_close;
+ }
+
+ ret = 0;
+err_dst_close:
+ if (close(dst_fd)) {
+ ret |= errno;
+ printf("failed to close dst file: %s\n", strerror(errno));
+ }
+err_src_close:
+ if (close(src_fd)) {
+ ret |= errno;
+ printf("failed to close src file: %s\n", strerror(errno));
+ }
+err_dst_free:
+ free(dst_file);
+err_src_free:
+ free(src_file);
+err_out:
+ return ret;
+}
--
2.8.2


2016-05-13 20:50:59

by Anna Schumaker

[permalink] [raw]
Subject: [PATCH 4/5] generic/345: Add copy test that overwrites data

Using copy to overwrite data in the destination file is perfectly valid,
so let's make sure this case works as expected.

Signed-off-by: Anna Schumaker <[email protected]>
---
tests/generic/345 | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++
tests/generic/345.out | 17 ++++++++
tests/generic/group | 1 +
3 files changed, 125 insertions(+)
create mode 100644 tests/generic/345
create mode 100644 tests/generic/345.out

diff --git a/tests/generic/345 b/tests/generic/345
new file mode 100644
index 0000000..ba96e4a
--- /dev/null
+++ b/tests/generic/345
@@ -0,0 +1,107 @@
+#!/bin/bash
+# FS QA Test No. 345
+#
+# Tests vfs_copy_file_range():
+# - Copy a file
+# - Use copy to swap data at beginning and end
+# - Use copy to swap data in the middle
+# - Use copy to simultaneously overwrite and append to destination file
+#-----------------------------------------------------------------------
+# Copyright (c) 2016 Netapp, Inc. 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 -rf $tmp.*
+}
+
+# get standard environment
+. common/rc
+. common/filter
+
+# real QA test starts here
+_supported_os Linux
+
+_require_copy_file_range
+_require_test
+
+testdir=$TEST_DIR/test-$seq
+rm -rf $testdir
+mkdir $testdir
+
+_checksum_files()
+{
+ for f in file copy; do
+ md5sum $testdir/$f | _filter_test_dir
+ done
+}
+
+rm -f $seqres.full
+
+echo "Create the original file and then copy"
+$XFS_IO_PROG -f -c 'pwrite -S 0x61 0 1000' $testdir/file >> $seqres.full 2>&1
+$XFS_IO_PROG -f -c 'pwrite -S 0x62 1000 1000' $testdir/file >> $seqres.full 2>&1
+$XFS_IO_PROG -f -c 'pwrite -S 0x63 2000 1000' $testdir/file >> $seqres.full 2>&1
+$XFS_IO_PROG -f -c 'pwrite -S 0x64 3000 1000' $testdir/file >> $seqres.full 2>&1
+$XFS_IO_PROG -f -c 'pwrite -S 0x65 4000 1000' $testdir/file >> $seqres.full 2>&1
+$COPY_FILE_RANGE_PROG $testdir/file $testdir/copy
+cmp $testdir/file $testdir/copy
+echo "Original md5sums:"
+_checksum_files
+
+echo "Swap beginning and end of original file"
+$COPY_FILE_RANGE_PROG -s 4000 -l 1000 $testdir/file $testdir/copy
+$COPY_FILE_RANGE_PROG -d 4000 -l 1000 $testdir/file $testdir/copy
+cmp -n 1000 $testdir/file $testdir/copy 4000
+cmp -n 3000 $testdir/file $testdir/copy 1000 1000
+cmp -n 1000 $testdir/file $testdir/copy 0 4000
+echo "md5sums after swapping beginning and end:"
+_checksum_files
+
+echo "Swap middle parts of original file"
+$COPY_FILE_RANGE_PROG -s 1000 -d 3000 -l 1000 $testdir/file $testdir/copy
+$COPY_FILE_RANGE_PROG -s 3000 -d 1000 -l 1000 $testdir/file $testdir/copy
+cmp -n 1000 $testdir/file $testdir/copy 4000
+cmp -n 1000 $testdir/file $testdir/copy 3000 1000
+cmp -n 1000 $testdir/file $testdir/copy 2000 2000
+cmp -n 1000 $testdir/file $testdir/copy 1000 3000
+cmp -n 1000 $testdir/file $testdir/copy 0 4000
+echo "md5sums after swapping middle:"
+_checksum_files
+
+echo "Copy tail of original file onto copy"
+$COPY_FILE_RANGE_PROG -s 1000 -d 3000 -l 4000 $testdir/file $testdir/copy
+cmp -n 1000 $testdir/file $testdir/copy 4000
+cmp -n 1000 $testdir/file $testdir/copy 3000 1000
+cmp -n 1000 $testdir/file $testdir/copy 2000 2000
+cmp -n 4000 $testdir/file $testdir/copy 1000 3000
+echo "md5sums after copying tail:"
+_checksum_files
+
+#success, all done
+status=0
+exit
diff --git a/tests/generic/345.out b/tests/generic/345.out
new file mode 100644
index 0000000..0c0a505
--- /dev/null
+++ b/tests/generic/345.out
@@ -0,0 +1,17 @@
+QA output created by 345
+Create the original file and then copy
+Original md5sums:
+e11fbace556cba26bf0076e74cab90a3 TEST_DIR/test-345/file
+e11fbace556cba26bf0076e74cab90a3 TEST_DIR/test-345/copy
+Swap beginning and end of original file
+md5sums after swapping beginning and end:
+e11fbace556cba26bf0076e74cab90a3 TEST_DIR/test-345/file
+5f4e111811dd9a810143c9db9bec6d80 TEST_DIR/test-345/copy
+Swap middle parts of original file
+md5sums after swapping middle:
+e11fbace556cba26bf0076e74cab90a3 TEST_DIR/test-345/file
+8c81889a5a50b311197110bcf769a695 TEST_DIR/test-345/copy
+Copy tail of original file onto copy
+md5sums after copying tail:
+e11fbace556cba26bf0076e74cab90a3 TEST_DIR/test-345/file
+e5fbacd993eaa5e80ebc2b14b969887d TEST_DIR/test-345/copy
diff --git a/tests/generic/group b/tests/generic/group
index 323e42b..69696c7 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -347,3 +347,4 @@
342 auto quick metadata
343 auto quick copy
344 auto quick copy
+345 auto quick copy
--
2.8.2


2016-05-13 20:50:59

by Anna Schumaker

[permalink] [raw]
Subject: [PATCH 3/5] generic/344: Add small copies to new file test

This test copies single bytes from a source file into various new files
just to make sure that we can handle very small copies.

Signed-off-by: Anna Schumaker <[email protected]>
---
tests/generic/344 | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++
tests/generic/344.out | 13 ++++++++
tests/generic/group | 1 +
3 files changed, 100 insertions(+)
create mode 100644 tests/generic/344
create mode 100644 tests/generic/344.out

diff --git a/tests/generic/344 b/tests/generic/344
new file mode 100644
index 0000000..4220293
--- /dev/null
+++ b/tests/generic/344
@@ -0,0 +1,86 @@
+#!/bin/bash
+# FS QA Test No. 344
+#
+# Tests vfs_copy_file_range():
+# - Copy a small file
+# - Small copies from various points in the original file
+#-----------------------------------------------------------------------
+# Copyright (c) 2016 Netapp, Inc. 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 -rf $tmp.*
+}
+
+# get standard environment
+. common/rc
+. common/filter
+
+# real QA test starts here
+_supported_os Linux
+
+_require_copy_file_range
+_require_test
+
+testdir=$TEST_DIR/test-$seq
+rm -rf $testdir
+mkdir $testdir
+
+_checksum_files()
+{
+ for f in $*; do
+ md5sum $testdir/$f | _filter_test_dir
+ done
+}
+
+rm -f $seqres.full
+
+echo "Create the original file and then copy"
+echo -n "abcde" > $testdir/file
+$COPY_FILE_RANGE_PROG $testdir/file $testdir/copy
+echo -n "abcde" | cmp $testdir/copy
+echo "Original md5sums:"
+_checksum_files file copy
+
+echo "Small copies from various points in the original file"
+$COPY_FILE_RANGE_PROG -s 0 -l 1 $testdir/file $testdir/a
+$COPY_FILE_RANGE_PROG -s 1 -l 1 $testdir/file $testdir/b
+$COPY_FILE_RANGE_PROG -s 2 -l 1 $testdir/file $testdir/c
+$COPY_FILE_RANGE_PROG -s 3 -l 1 $testdir/file $testdir/d
+$COPY_FILE_RANGE_PROG -s 4 -l 1 $testdir/file $testdir/e
+echo -n "a" | cmp $testdir/a
+echo -n "b" | cmp $testdir/b
+echo -n "c" | cmp $testdir/c
+echo -n "d" | cmp $testdir/d
+echo -n "e" | cmp $testdir/e
+echo "md5sums after small copies"
+_checksum_files file a b c d e
+
+#success, all done
+status=0
+exit
diff --git a/tests/generic/344.out b/tests/generic/344.out
new file mode 100644
index 0000000..152fb2c
--- /dev/null
+++ b/tests/generic/344.out
@@ -0,0 +1,13 @@
+QA output created by 344
+Create the original file and then copy
+Original md5sums:
+ab56b4d92b40713acc5af89985d4b786 TEST_DIR/test-344/file
+ab56b4d92b40713acc5af89985d4b786 TEST_DIR/test-344/copy
+Small copies from various points in the original file
+md5sums after small copies
+ab56b4d92b40713acc5af89985d4b786 TEST_DIR/test-344/file
+0cc175b9c0f1b6a831c399e269772661 TEST_DIR/test-344/a
+92eb5ffee6ae2fec3ad71c777531578f TEST_DIR/test-344/b
+4a8a08f09d37b73795649038408b5f33 TEST_DIR/test-344/c
+8277e0910d750195b448797616e091ad TEST_DIR/test-344/d
+e1671797c52e15f763380b45e841ec32 TEST_DIR/test-344/e
diff --git a/tests/generic/group b/tests/generic/group
index d5e5242..323e42b 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -346,3 +346,4 @@
341 auto quick metadata
342 auto quick metadata
343 auto quick copy
+344 auto quick copy
--
2.8.2


2016-05-13 20:51:00

by Anna Schumaker

[permalink] [raw]
Subject: [PATCH 5/5] generic/346: Add a copy test for overwriting small amounts of data

This test is similar to 345, except that it copies one byte at a time to
make sure that this case works as expected.

Signed-off-by: Anna Schumaker <[email protected]>
---
tests/generic/346 | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++
tests/generic/346.out | 17 ++++++++++
tests/generic/group | 1 +
3 files changed, 112 insertions(+)
create mode 100644 tests/generic/346
create mode 100644 tests/generic/346.out

diff --git a/tests/generic/346 b/tests/generic/346
new file mode 100644
index 0000000..4154bd5
--- /dev/null
+++ b/tests/generic/346
@@ -0,0 +1,94 @@
+#!/bin/bash
+# FS QA Test No. 346
+#
+# Tests vfs_copy_file_range():
+# - Copy a small file
+# - Use copy to swap data at beginning and end
+# - Use copy to swap data in the middle
+# - Use copy to swap data in a small file
+#-----------------------------------------------------------------------
+# Copyright (c) 2016 Netapp, Inc. 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 -rf $tmp.*
+}
+
+# get standard environment
+. common/rc
+. common/filter
+
+# real QA test starts here
+_supported_os Linux
+
+_require_copy_file_range
+_require_test
+
+testdir=$TEST_DIR/test-$seq
+rm -rf $testdir
+mkdir $testdir
+
+_checksum_files()
+{
+ for f in file copy; do
+ md5sum $testdir/$f | _filter_test_dir
+ done
+}
+
+rm -f $seqres.full
+
+echo "Create the original file and then copy"
+echo -n "abcde" > $testdir/file
+$COPY_FILE_RANGE_PROG $testdir/file $testdir/copy
+cmp $testdir/file $testdir/copy
+echo "Original md5sums:"
+_checksum_files
+
+echo "Swap beginning and end of original file"
+$COPY_FILE_RANGE_PROG -s 0 -d 4 -l 1 $testdir/file $testdir/copy
+$COPY_FILE_RANGE_PROG -s 4 -d 0 -l 1 $testdir/file $testdir/copy
+echo -n "ebcda" | cmp $testdir/copy
+echo "md5sums after swapping beginning and end:"
+_checksum_files
+
+echo "Swap middle parts of original file"
+$COPY_FILE_RANGE_PROG -s 1 -d 3 -l 1 $testdir/file $testdir/copy
+$COPY_FILE_RANGE_PROG -s 3 -d 1 -l 1 $testdir/file $testdir/copy
+echo -n "edcba" | cmp $testdir/copy
+echo "md5sums after swapping middle:"
+_checksum_files
+
+echo "Copy tail of original file onto copy"
+$COPY_FILE_RANGE_PROG -s 1 -d 3 -l 4 $testdir/file $testdir/copy
+echo -n "edcbcde" | cmp $testdir/copy
+echo "md5sums after copying tail:"
+_checksum_files
+
+#success, all done
+status=0
+exit
diff --git a/tests/generic/346.out b/tests/generic/346.out
new file mode 100644
index 0000000..0d37b62
--- /dev/null
+++ b/tests/generic/346.out
@@ -0,0 +1,17 @@
+QA output created by 346
+Create the original file and then copy
+Original md5sums:
+ab56b4d92b40713acc5af89985d4b786 TEST_DIR/test-346/file
+ab56b4d92b40713acc5af89985d4b786 TEST_DIR/test-346/copy
+Swap beginning and end of original file
+md5sums after swapping beginning and end:
+ab56b4d92b40713acc5af89985d4b786 TEST_DIR/test-346/file
+32db1f6d06d15f7e38e1ab1c69da498a TEST_DIR/test-346/copy
+Swap middle parts of original file
+md5sums after swapping middle:
+ab56b4d92b40713acc5af89985d4b786 TEST_DIR/test-346/file
+295228f3d82d344bbcf2f0030519c2ea TEST_DIR/test-346/copy
+Copy tail of original file onto copy
+md5sums after copying tail:
+ab56b4d92b40713acc5af89985d4b786 TEST_DIR/test-346/file
+0c4aac952f72fa078e2f8419aca70b28 TEST_DIR/test-346/copy
diff --git a/tests/generic/group b/tests/generic/group
index 69696c7..8a8ba8d 100644
--- a/tests/generic/group
+++ b/tests/generic/group
@@ -348,3 +348,4 @@
343 auto quick copy
344 auto quick copy
345 auto quick copy
+346 auto quick copy
--
2.8.2


2016-05-16 23:21:36

by Dave Chinner

[permalink] [raw]
Subject: Re: [PATCH 1/5] src/copy_file_range: Add a program for testing vfs_copy_file_range()

On Fri, May 13, 2016 at 04:50:48PM -0400, Anna Schumaker wrote:
> This will be used by the various copy tests to call the Linux
> copy_file_range() system call. I used src/cloner.c as a reference while
> writing this tool.

Hmmm - I'd much prefer to see this added to xfs_io as it's a kernel
syscall that lots of filesystems will eventually implement. A
one-off binary for xfstests is fine for non-standard or deeply
filesysetm specific stuff, but if it's generic we try to put it into
xfs_io so that it's available to everyone writing scripts, not just
xfstests....

Cheers,

Dave.
--
Dave Chinner
[email protected]

2016-05-17 14:47:46

by Anna Schumaker

[permalink] [raw]
Subject: Re: [PATCH 1/5] src/copy_file_range: Add a program for testing vfs_copy_file_range()

On 05/16/2016 07:20 PM, Dave Chinner wrote:
> On Fri, May 13, 2016 at 04:50:48PM -0400, Anna Schumaker wrote:
>> This will be used by the various copy tests to call the Linux
>> copy_file_range() system call. I used src/cloner.c as a reference while
>> writing this tool.
>
> Hmmm - I'd much prefer to see this added to xfs_io as it's a kernel
> syscall that lots of filesystems will eventually implement. A
> one-off binary for xfstests is fine for non-standard or deeply
> filesysetm specific stuff, but if it's generic we try to put it into
> xfs_io so that it's available to everyone writing scripts, not just
> xfstests....

Ah, that makes sense. Thanks for explaining the convention! I'll look into adding it to the xfs_io program instead. Should I send that patch to a different mailing list than [email protected]?

Thanks,
Anna

>
> Cheers,
>
> Dave.
>


2016-05-17 17:49:05

by Darrick J. Wong

[permalink] [raw]
Subject: Re: [PATCH 1/5] src/copy_file_range: Add a program for testing vfs_copy_file_range()

On Tue, May 17, 2016 at 10:47:42AM -0400, Anna Schumaker wrote:
> On 05/16/2016 07:20 PM, Dave Chinner wrote:
> > On Fri, May 13, 2016 at 04:50:48PM -0400, Anna Schumaker wrote:
> >> This will be used by the various copy tests to call the Linux
> >> copy_file_range() system call. I used src/cloner.c as a reference while
> >> writing this tool.
> >
> > Hmmm - I'd much prefer to see this added to xfs_io as it's a kernel
> > syscall that lots of filesystems will eventually implement. A
> > one-off binary for xfstests is fine for non-standard or deeply
> > filesysetm specific stuff, but if it's generic we try to put it into
> > xfs_io so that it's available to everyone writing scripts, not just
> > xfstests....
>
> Ah, that makes sense. Thanks for explaining the convention! I'll look into
> adding it to the xfs_io program instead. Should I send that patch to a
> different mailing list than [email protected]?

[email protected]. I recommend looking at io/reflink.c as a template.

FWIW I'd also appreciate c_f_r being wired up in xfs_io.

--D

>
> Thanks,
> Anna
>
> >
> > Cheers,
> >
> > Dave.
> >
>
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html

2016-05-17 17:52:21

by Anna Schumaker

[permalink] [raw]
Subject: Re: [PATCH 1/5] src/copy_file_range: Add a program for testing vfs_copy_file_range()

On 05/17/2016 01:48 PM, Darrick J. Wong wrote:
> On Tue, May 17, 2016 at 10:47:42AM -0400, Anna Schumaker wrote:
>> On 05/16/2016 07:20 PM, Dave Chinner wrote:
>>> On Fri, May 13, 2016 at 04:50:48PM -0400, Anna Schumaker wrote:
>>>> This will be used by the various copy tests to call the Linux
>>>> copy_file_range() system call. I used src/cloner.c as a reference while
>>>> writing this tool.
>>>
>>> Hmmm - I'd much prefer to see this added to xfs_io as it's a kernel
>>> syscall that lots of filesystems will eventually implement. A
>>> one-off binary for xfstests is fine for non-standard or deeply
>>> filesysetm specific stuff, but if it's generic we try to put it into
>>> xfs_io so that it's available to everyone writing scripts, not just
>>> xfstests....
>>
>> Ah, that makes sense. Thanks for explaining the convention! I'll look into
>> adding it to the xfs_io program instead. Should I send that patch to a
>> different mailing list than [email protected]?
>
> [email protected]. I recommend looking at io/reflink.c as a template.
>
> FWIW I'd also appreciate c_f_r being wired up in xfs_io.

I'm working on it right now! I just finished fighting autotolls to get it to recognize a new file defining the "copy_range" command. Hopefully porting everything over won't be too difficult from here.

Thanks for the suggestion to look at reflink!

Anna

>
> --D
>
>>
>> Thanks,
>> Anna
>>
>>>
>>> Cheers,
>>>
>>> Dave.
>>>
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe fstests" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
> --
> To unsubscribe from this list: send the line "unsubscribe linux-nfs" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>