1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
|
#-
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2022 The FreeBSD Foundation
#
# This software was developed by Mark Johnston under sponsorship from
# the FreeBSD Foundation.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
MAKEFS="makefs -t zfs -o nowarn=true"
ZFS_POOL_NAME="makefstest$$"
TEST_ZFS_POOL_NAME="$TMPDIR/poolname"
. "$(dirname "$0")/makefs_tests_common.sh"
common_cleanup()
{
local pool md
# Try to force a TXG, this can help catch bugs by triggering a panic.
sync
pool=$(cat $TEST_ZFS_POOL_NAME)
if zpool list "$pool" >/dev/null; then
zpool destroy "$pool"
fi
md=$(cat $TEST_MD_DEVICE_FILE)
if [ -c /dev/"$md" ]; then
mdconfig -d -u "$md"
fi
}
import_image()
{
atf_check -e empty -o save:$TEST_MD_DEVICE_FILE -s exit:0 \
mdconfig -a -f $TEST_IMAGE
atf_check zpool import -R $TEST_MOUNT_DIR $ZFS_POOL_NAME
echo "$ZFS_POOL_NAME" > $TEST_ZFS_POOL_NAME
}
#
# Test autoexpansion of the vdev.
#
# The pool is initially 10GB, so we get 10GB minus one metaslab's worth of
# usable space for data. Then the pool is expanded to 50GB, and the amount of
# usable space is 50GB minus one metaslab.
#
atf_test_case autoexpand cleanup
autoexpand_body()
{
local mssize poolsize poolsize1 newpoolsize
create_test_inputs
mssize=$((128 * 1024 * 1024))
poolsize=$((10 * 1024 * 1024 * 1024))
atf_check $MAKEFS -s $poolsize -o mssize=$mssize -o rootpath=/ \
-o poolname=$ZFS_POOL_NAME \
$TEST_IMAGE $TEST_INPUTS_DIR
newpoolsize=$((50 * 1024 * 1024 * 1024))
truncate -s $newpoolsize $TEST_IMAGE
import_image
check_image_contents
poolsize1=$(zpool list -Hp -o size $ZFS_POOL_NAME)
atf_check [ $((poolsize1 + $mssize)) -eq $poolsize ]
atf_check zpool online -e $ZFS_POOL_NAME /dev/$(cat $TEST_MD_DEVICE_FILE)
check_image_contents
poolsize1=$(zpool list -Hp -o size $ZFS_POOL_NAME)
atf_check [ $((poolsize1 + $mssize)) -eq $newpoolsize ]
}
autoexpand_cleanup()
{
common_cleanup
}
#
# Test with some default layout defined by the common code.
#
atf_test_case basic cleanup
basic_body()
{
create_test_inputs
atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
check_image_contents
}
basic_cleanup()
{
common_cleanup
}
atf_test_case dataset_removal cleanup
dataset_removal_body()
{
create_test_dirs
cd $TEST_INPUTS_DIR
mkdir dir
cd -
atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
-o fs=${ZFS_POOL_NAME}/dir \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
check_image_contents
atf_check zfs destroy ${ZFS_POOL_NAME}/dir
}
dataset_removal_cleanup()
{
common_cleanup
}
#
# Make sure that we can create and remove an empty directory.
#
atf_test_case empty_dir cleanup
empty_dir_body()
{
create_test_dirs
cd $TEST_INPUTS_DIR
mkdir dir
cd -
atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
check_image_contents
atf_check rmdir ${TEST_MOUNT_DIR}/dir
}
empty_dir_cleanup()
{
common_cleanup
}
atf_test_case empty_fs cleanup
empty_fs_body()
{
create_test_dirs
atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
check_image_contents
}
empty_fs_cleanup()
{
common_cleanup
}
atf_test_case file_sizes cleanup
file_sizes_body()
{
local i
create_test_dirs
cd $TEST_INPUTS_DIR
i=1
while [ $i -lt $((1 << 20)) ]; do
truncate -s $i ${i}.1
truncate -s $(($i - 1)) ${i}.2
truncate -s $(($i + 1)) ${i}.3
i=$(($i << 1))
done
cd -
# XXXMJ this creates sparse files, make sure makefs doesn't
# preserve the sparseness.
# XXXMJ need to test with larger files (at least 128MB for L2 indirs)
atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
check_image_contents
}
file_sizes_cleanup()
{
common_cleanup
}
atf_test_case hard_links cleanup
hard_links_body()
{
local f
create_test_dirs
cd $TEST_INPUTS_DIR
mkdir dir
echo "hello" > 1
ln 1 2
ln 1 dir/1
echo "goodbye" > dir/a
ln dir/a dir/b
ln dir/a a
cd -
atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
check_image_contents
stat -f '%i' ${TEST_MOUNT_DIR}/1 > ./ino
stat -f '%l' ${TEST_MOUNT_DIR}/1 > ./nlink
for f in 1 2 dir/1; do
atf_check -o file:./nlink -e empty -s exit:0 \
stat -f '%l' ${TEST_MOUNT_DIR}/${f}
atf_check -o file:./ino -e empty -s exit:0 \
stat -f '%i' ${TEST_MOUNT_DIR}/${f}
atf_check cmp -s ${TEST_INPUTS_DIR}/1 ${TEST_MOUNT_DIR}/${f}
done
stat -f '%i' ${TEST_MOUNT_DIR}/dir/a > ./ino
stat -f '%l' ${TEST_MOUNT_DIR}/dir/a > ./nlink
for f in dir/a dir/b a; do
atf_check -o file:./nlink -e empty -s exit:0 \
stat -f '%l' ${TEST_MOUNT_DIR}/${f}
atf_check -o file:./ino -e empty -s exit:0 \
stat -f '%i' ${TEST_MOUNT_DIR}/${f}
atf_check cmp -s ${TEST_INPUTS_DIR}/dir/a ${TEST_MOUNT_DIR}/${f}
done
}
hard_links_cleanup()
{
common_cleanup
}
# Allocate enough dnodes from an object set that the meta dnode needs to use
# indirect blocks.
atf_test_case indirect_dnode_array cleanup
indirect_dnode_array_body()
{
local count i
# How many dnodes do we need to allocate? Well, the data block size
# for meta dnodes is always 16KB, so with a dnode size of 512B we get
# 32 dnodes per direct block. The maximum indirect block size is 128KB
# and that can fit 1024 block pointers, so we need at least 32 * 1024
# files to force the use of two levels of indirection.
#
# Unfortunately that number of files makes the test run quite slowly,
# so we settle for a single indirect block for now...
count=$(jot -r 1 32 1024)
create_test_dirs
cd $TEST_INPUTS_DIR
for i in $(seq 1 $count); do
touch $i
done
cd -
atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
check_image_contents
}
indirect_dnode_array_cleanup()
{
common_cleanup
}
#
# Create some files with long names, so as to test fat ZAP handling.
#
atf_test_case long_file_name cleanup
long_file_name_body()
{
local dir i
create_test_dirs
cd $TEST_INPUTS_DIR
# micro ZAP keys can be at most 50 bytes.
for i in $(seq 1 60); do
touch $(jot -s '' $i 1 1)
done
dir=$(jot -s '' 61 1 1)
mkdir $dir
for i in $(seq 1 60); do
touch ${dir}/$(jot -s '' $i 1 1)
done
cd -
atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
check_image_contents
# Add a directory entry in the hope that OpenZFS might catch a bug
# in makefs' fat ZAP encoding.
touch ${TEST_MOUNT_DIR}/foo
}
long_file_name_cleanup()
{
common_cleanup
}
#
# Exercise handling of multiple datasets.
#
atf_test_case multi_dataset_1 cleanup
multi_dataset_1_body()
{
create_test_dirs
cd $TEST_INPUTS_DIR
mkdir dir1
echo a > dir1/a
mkdir dir2
echo b > dir2/b
cd -
atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
-o fs=${ZFS_POOL_NAME}/dir1 -o fs=${ZFS_POOL_NAME}/dir2 \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
check_image_contents
# Make sure that we have three datasets with the expected mount points.
atf_check -o inline:${ZFS_POOL_NAME}\\n -e empty -s exit:0 \
zfs list -H -o name ${ZFS_POOL_NAME}
atf_check -o inline:${TEST_MOUNT_DIR}\\n -e empty -s exit:0 \
zfs list -H -o mountpoint ${ZFS_POOL_NAME}
atf_check -o inline:${ZFS_POOL_NAME}/dir1\\n -e empty -s exit:0 \
zfs list -H -o name ${ZFS_POOL_NAME}/dir1
atf_check -o inline:${TEST_MOUNT_DIR}/dir1\\n -e empty -s exit:0 \
zfs list -H -o mountpoint ${ZFS_POOL_NAME}/dir1
atf_check -o inline:${ZFS_POOL_NAME}/dir2\\n -e empty -s exit:0 \
zfs list -H -o name ${ZFS_POOL_NAME}/dir2
atf_check -o inline:${TEST_MOUNT_DIR}/dir2\\n -e empty -s exit:0 \
zfs list -H -o mountpoint ${ZFS_POOL_NAME}/dir2
}
multi_dataset_1_cleanup()
{
common_cleanup
}
#
# Create a pool with two datasets, where the root dataset is mounted below
# the child dataset.
#
atf_test_case multi_dataset_2 cleanup
multi_dataset_2_body()
{
create_test_dirs
cd $TEST_INPUTS_DIR
mkdir dir1
echo a > dir1/a
mkdir dir2
echo b > dir2/b
cd -
atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
-o fs=${ZFS_POOL_NAME}/dir1\;mountpoint=/ \
-o fs=${ZFS_POOL_NAME}\;mountpoint=/dir1 \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
check_image_contents
}
multi_dataset_2_cleanup()
{
common_cleanup
}
#
# Create a dataset with a non-existent mount point.
#
atf_test_case multi_dataset_3 cleanup
multi_dataset_3_body()
{
create_test_dirs
cd $TEST_INPUTS_DIR
mkdir dir1
echo a > dir1/a
cd -
atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
-o fs=${ZFS_POOL_NAME}/dir1 \
-o fs=${ZFS_POOL_NAME}/dir2 \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
atf_check -o inline:${TEST_MOUNT_DIR}/dir2\\n -e empty -s exit:0 \
zfs list -H -o mountpoint ${ZFS_POOL_NAME}/dir2
# Mounting dir2 should have created a directory called dir2. Go
# back and create it in the staging tree before comparing.
atf_check mkdir ${TEST_INPUTS_DIR}/dir2
check_image_contents
}
multi_dataset_3_cleanup()
{
common_cleanup
}
#
# Create an unmounted dataset.
#
atf_test_case multi_dataset_4 cleanup
multi_dataset_4_body()
{
create_test_dirs
cd $TEST_INPUTS_DIR
mkdir dir1
echo a > dir1/a
cd -
atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
-o fs=${ZFS_POOL_NAME}/dir1\;canmount=noauto\;mountpoint=none \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
atf_check -o inline:none\\n -e empty -s exit:0 \
zfs list -H -o mountpoint ${ZFS_POOL_NAME}/dir1
check_image_contents
atf_check zfs set mountpoint=/dir1 ${ZFS_POOL_NAME}/dir1
atf_check zfs mount ${ZFS_POOL_NAME}/dir1
atf_check -o inline:${TEST_MOUNT_DIR}/dir1\\n -e empty -s exit:0 \
zfs list -H -o mountpoint ${ZFS_POOL_NAME}/dir1
# dir1/a should be part of the root dataset, not dir1.
atf_check -s not-exit:0 -e not-empty stat ${TEST_MOUNT_DIR}dir1/a
}
multi_dataset_4_cleanup()
{
common_cleanup
}
#
# Validate handling of multiple staging directories.
#
atf_test_case multi_staging_1 cleanup
multi_staging_1_body()
{
local tmpdir
create_test_dirs
cd $TEST_INPUTS_DIR
mkdir dir1
echo a > a
echo a > dir1/a
echo z > z
cd -
tmpdir=$(mktemp -d)
cd $tmpdir
mkdir dir2 dir2/dir3
echo b > dir2/b
echo c > dir2/dir3/c
ln -s dir2/dir3c s
cd -
atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
$TEST_IMAGE ${TEST_INPUTS_DIR} $tmpdir
import_image
check_image_contents -d $tmpdir
}
multi_staging_1_cleanup()
{
common_cleanup
}
atf_test_case multi_staging_2 cleanup
multi_staging_2_body()
{
local tmpdir
create_test_dirs
cd $TEST_INPUTS_DIR
mkdir dir
echo a > dir/foo
echo b > dir/bar
cd -
tmpdir=$(mktemp -d)
cd $tmpdir
mkdir dir
echo c > dir/baz
cd -
atf_check $MAKEFS -s 1g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
$TEST_IMAGE ${TEST_INPUTS_DIR} $tmpdir
import_image
# check_image_contents can't easily handle merged directories, so
# just check that the merged directory contains the files we expect.
atf_check -o not-empty stat ${TEST_MOUNT_DIR}/dir/foo
atf_check -o not-empty stat ${TEST_MOUNT_DIR}/dir/bar
atf_check -o not-empty stat ${TEST_MOUNT_DIR}/dir/baz
if [ "$(ls ${TEST_MOUNT_DIR}/dir | wc -l)" -ne 3 ]; then
atf_fail "Expected 3 files in ${TEST_MOUNT_DIR}/dir"
fi
}
multi_staging_2_cleanup()
{
common_cleanup
}
#
# Rudimentary test to verify that two ZFS images created using the same
# parameters and input hierarchy are byte-identical. In particular, makefs(1)
# does not preserve file access times.
#
atf_test_case reproducible cleanup
reproducible_body()
{
create_test_inputs
atf_check $MAKEFS -s 512m -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
${TEST_IMAGE}.1 $TEST_INPUTS_DIR
atf_check $MAKEFS -s 512m -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
${TEST_IMAGE}.2 $TEST_INPUTS_DIR
# XXX-MJ cmp(1) is really slow
atf_check cmp ${TEST_IMAGE}.1 ${TEST_IMAGE}.2
}
reproducible_cleanup()
{
}
#
# Verify that we can take a snapshot of a generated dataset.
#
atf_test_case snapshot cleanup
snapshot_body()
{
create_test_dirs
cd $TEST_INPUTS_DIR
mkdir dir
echo "hello" > dir/hello
echo "goodbye" > goodbye
cd -
atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
atf_check zfs snapshot ${ZFS_POOL_NAME}@1
}
snapshot_cleanup()
{
common_cleanup
}
#
# Check handling of symbolic links.
#
atf_test_case soft_links cleanup
soft_links_body()
{
create_test_dirs
cd $TEST_INPUTS_DIR
mkdir dir
ln -s a a
ln -s dir/../a a
ln -s dir/b b
echo 'c' > dir
ln -s dir/c c
# XXX-MJ overflows bonus buffer ln -s $(jot -s '' 320 1 1) 1
cd -
atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
check_image_contents
}
soft_links_cleanup()
{
common_cleanup
}
#
# Verify that we can set properties on the root dataset.
#
atf_test_case root_props cleanup
root_props_body()
{
create_test_inputs
atf_check $MAKEFS -s 10g -o rootpath=/ -o poolname=$ZFS_POOL_NAME \
-o fs=${ZFS_POOL_NAME}\;atime=off\;setuid=off \
$TEST_IMAGE $TEST_INPUTS_DIR
import_image
check_image_contents
atf_check -o inline:off\\n -e empty -s exit:0 \
zfs get -H -o value atime $ZFS_POOL_NAME
atf_check -o inline:local\\n -e empty -s exit:0 \
zfs get -H -o source atime $ZFS_POOL_NAME
atf_check -o inline:off\\n -e empty -s exit:0 \
zfs get -H -o value setuid $ZFS_POOL_NAME
atf_check -o inline:local\\n -e empty -s exit:0 \
zfs get -H -o source setuid $ZFS_POOL_NAME
}
root_props_cleanup()
{
common_cleanup
}
atf_init_test_cases()
{
atf_add_test_case autoexpand
atf_add_test_case basic
atf_add_test_case dataset_removal
atf_add_test_case empty_dir
atf_add_test_case empty_fs
atf_add_test_case file_sizes
atf_add_test_case hard_links
atf_add_test_case indirect_dnode_array
atf_add_test_case long_file_name
atf_add_test_case multi_dataset_1
atf_add_test_case multi_dataset_2
atf_add_test_case multi_dataset_3
atf_add_test_case multi_dataset_4
atf_add_test_case multi_staging_1
atf_add_test_case multi_staging_2
atf_add_test_case reproducible
atf_add_test_case snapshot
atf_add_test_case soft_links
atf_add_test_case root_props
# XXXMJ tests:
# - test with different ashifts (at least, 9 and 12), different image sizes
# - create datasets in imported pool
}
|