1#! /bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or https://opensource.org/licenses/CDDL-1.0.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright (c) 2018 by Nutanix. All rights reserved.
25#
26
27. $STF_SUITE/include/libtest.shlib
28
29#
30# DESCRIPTION:
31# Copy a large number of files between 2 directories
32# within a zfs filesystem works without errors.
33# This make sure zap upgrading and expanding works.
34#
35# STRATEGY:
36#
37# 1. Create NR_FILES files in directory src
38# 2. Check the number of files is correct
39# 3. Copy files from src to dst in readdir order
40# 4. Check the number of files is correct
41#
42
43verify_runnable "global"
44
45function cleanup
46{
47	rm -rf $TESTDIR/src $TESTDIR/dst
48}
49
50log_assert "Copy a large number of files between 2 directories" \
51	"within a zfs filesystem works without errors"
52
53log_onexit cleanup
54
55NR_FILES=60000
56BATCH=1000
57
58log_must mkdir $TESTDIR/src $TESTDIR/dst
59
60WD=$PWD
61cd $TESTDIR/src
62# create NR_FILES in BATCH at a time to prevent overflowing argument buffer
63for i in $(seq $(($NR_FILES/$BATCH))); do touch $(seq $((($i-1)*$BATCH+1)) $(($i*$BATCH))); done
64cd $WD
65
66log_must test $NR_FILES -eq $(ls -U $TESTDIR/src | wc -l)
67
68# copy files from src to dst, use cp_files to make sure we copy in readdir order
69log_must cp_files $TESTDIR/src $TESTDIR/dst
70
71log_must test $NR_FILES -eq $(ls -U $TESTDIR/dst | wc -l)
72
73log_pass
74