aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files
diff options
context:
space:
mode:
authorMatt Macy <mmacy@FreeBSD.org>2020-08-24 23:31:26 +0000
committerMatt Macy <mmacy@FreeBSD.org>2020-08-24 23:31:26 +0000
commiteda14cbc264d6969b02f2b1994cef11148e914f1 (patch)
tree54766ce51e901d5ec66cdce87973bb1e210588e1 /sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files
parent8d9b400f9d02116e528968fa4e7d3c479e326e2a (diff)
parent3b0ce0e28db46d0403929aba45c682285e1ac217 (diff)
downloadsrc-eda14cbc264d6969b02f2b1994cef11148e914f1.tar.gz
src-eda14cbc264d6969b02f2b1994cef11148e914f1.zip
Initial import from vendor-sys branch of openzfs
Notes
Notes: svn path=/head/; revision=364740
Diffstat (limited to 'sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files')
-rw-r--r--sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/.gitignore1
-rw-r--r--sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/Makefile.am13
-rwxr-xr-xsys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/cleanup.ksh34
-rw-r--r--sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/cp_files.c58
-rwxr-xr-xsys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/cp_files_001_pos.ksh74
-rwxr-xr-xsys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/setup.ksh35
6 files changed, 215 insertions, 0 deletions
diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/.gitignore b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/.gitignore
new file mode 100644
index 000000000000..eac05e155378
--- /dev/null
+++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/.gitignore
@@ -0,0 +1 @@
+/cp_files
diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/Makefile.am b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/Makefile.am
new file mode 100644
index 000000000000..06c31f5f3f92
--- /dev/null
+++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/Makefile.am
@@ -0,0 +1,13 @@
+include $(top_srcdir)/config/Rules.am
+
+pkgdatadir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cp_files
+
+dist_pkgdata_SCRIPTS = \
+ cp_files_001_pos.ksh \
+ cleanup.ksh \
+ setup.ksh
+
+pkgexecdir = $(datadir)/@PACKAGE@/zfs-tests/tests/functional/cp_files
+
+pkgexec_PROGRAMS = cp_files
+cp_files_SOURCES= cp_files.c
diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/cleanup.ksh b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/cleanup.ksh
new file mode 100755
index 000000000000..3166bd6ec16e
--- /dev/null
+++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/cleanup.ksh
@@ -0,0 +1,34 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+default_cleanup
diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/cp_files.c b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/cp_files.c
new file mode 100644
index 000000000000..9af64a112631
--- /dev/null
+++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/cp_files.c
@@ -0,0 +1,58 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <dirent.h>
+#include <errno.h>
+#include <string.h>
+
+int
+main(int argc, char *argv[])
+{
+ int tfd;
+ DIR *sdir;
+ struct dirent *dirent;
+
+ if (argc != 3) {
+ fprintf(stderr, "Usage: %s SRC DST\n", argv[0]);
+ exit(1);
+ }
+
+ sdir = opendir(argv[1]);
+ if (sdir == NULL) {
+ fprintf(stderr, "Failed to open %s: %s\n",
+ argv[1], strerror(errno));
+ exit(2);
+ }
+
+ tfd = open(argv[2], O_DIRECTORY);
+ if (tfd < 0) {
+ fprintf(stderr, "Failed to open %s: %s\n",
+ argv[2], strerror(errno));
+ closedir(sdir);
+ exit(3);
+ }
+
+ while ((dirent = readdir(sdir)) != NULL) {
+ if (dirent->d_name[0] == '.' &&
+ (dirent->d_name[1] == '.' || dirent->d_name[1] == '\0'))
+ continue;
+
+ int fd = openat(tfd, dirent->d_name, O_CREAT|O_WRONLY, 0666);
+ if (fd < 0) {
+ fprintf(stderr, "Failed to create %s/%s: %s\n",
+ argv[2], dirent->d_name, strerror(errno));
+ closedir(sdir);
+ close(tfd);
+ exit(4);
+ }
+ close(fd);
+ }
+
+ closedir(sdir);
+ close(tfd);
+
+ return (0);
+}
diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/cp_files_001_pos.ksh b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/cp_files_001_pos.ksh
new file mode 100755
index 000000000000..3e138cfc9f72
--- /dev/null
+++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/cp_files_001_pos.ksh
@@ -0,0 +1,74 @@
+#! /bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2018 by Nutanix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+#
+# DESCRIPTION:
+# Copy a large number of files between 2 directories
+# within a zfs filesystem works without errors.
+# This make sure zap upgrading and expanding works.
+#
+# STRATEGY:
+#
+# 1. Create NR_FILES files in directory src
+# 2. Check the number of files is correct
+# 3. Copy files from src to dst in readdir order
+# 4. Check the number of files is correct
+#
+
+verify_runnable "global"
+
+function cleanup
+{
+ rm -rf $TESTDIR/src $TESTDIR/dst
+}
+
+log_assert "Copy a large number of files between 2 directories" \
+ "within a zfs filesystem works without errors"
+
+log_onexit cleanup
+
+NR_FILES=60000
+BATCH=1000
+
+log_must mkdir $TESTDIR/src
+log_must mkdir $TESTDIR/dst
+
+WD=$(pwd)
+cd $TESTDIR/src
+# create NR_FILES in BATCH at a time to prevent overflowing argument buffer
+for i in $(seq $(($NR_FILES/$BATCH))); do touch $(seq $((($i-1)*$BATCH+1)) $(($i*$BATCH))); done
+cd $WD
+
+log_must test $NR_FILES -eq $(ls -U $TESTDIR/src | wc -l)
+
+# copy files from src to dst, use cp_files to make sure we copy in readdir order
+log_must $STF_SUITE/tests/functional/cp_files/cp_files $TESTDIR/src $TESTDIR/dst
+
+log_must test $NR_FILES -eq $(ls -U $TESTDIR/dst | wc -l)
+
+log_pass
diff --git a/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/setup.ksh b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/setup.ksh
new file mode 100755
index 000000000000..fc5cec3063a6
--- /dev/null
+++ b/sys/contrib/openzfs/tests/zfs-tests/tests/functional/cp_files/setup.ksh
@@ -0,0 +1,35 @@
+#!/bin/ksh -p
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+
+#
+# Copyright (c) 2013 by Delphix. All rights reserved.
+#
+
+. $STF_SUITE/include/libtest.shlib
+
+DISK=${DISKS%% *}
+default_setup $DISK