-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathtest_uzfs.sh
More file actions
executable file
·1362 lines (1101 loc) · 36.1 KB
/
test_uzfs.sh
File metadata and controls
executable file
·1362 lines (1101 loc) · 36.1 KB
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
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Copyright © 2017-2019 The OpenEBS Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
if [ -z $SRC_PATH ]
then
SRC_PATH=`pwd`
fi
ZPOOL="$SRC_PATH/cmd/zpool/zpool"
ZFS="$SRC_PATH/cmd/zfs/zfs"
ZDB="$SRC_PATH/cmd/zdb/zdb"
## NOTE: It is assumed that cstor and libcstor will exist in same parent directory
ZREPL="$SRC_PATH/../libcstor/cmd/zrepl/zrepl"
GTEST_UZFS="$SRC_PATH/tests/cstor/gtest/test_uzfs"
GTEST_ZFS="$SRC_PATH/tests/cstor/gtest/test_zfs"
GTEST_ZREPL_PROT="$SRC_PATH/tests/cstor/gtest/test_zrepl_prot"
ZTEST="$SRC_PATH/cmd/ztest/ztest"
UZFS_TEST="$SRC_PATH/cmd/uzfs_test/uzfs_test"
UZFS_TEST_SYNC_SH="$SRC_PATH/cmd/uzfs_test/uzfs_test_sync.sh"
TMPDIR="/tmp"
VOLSIZE="20M"
UZFS_TEST_POOL="testp"
UZFS_TEST_VOL="ds0"
UZFS_REBUILD_VOL="ds1"
UZFS_REBUILD_VOL1="ds2"
UZFS_REBUILD_VOL2="ds3"
UZFS_TEST_VOLSIZE="20M"
UZFS_TEST_VOLSIZE_IN_NUM=20971520
ZREPL_PID="-1"
PROP_REPLICA_ID="io.openebs:zvol_replica_id"
source $UZFS_TEST_SYNC_SH
log_fail()
{
echo "failed => [$@]"
exit 1
}
log_note()
{
echo "executing => $@"
}
# Execute a positive test and exit if test fails
#
# $@ - command to execute
log_must()
{
local logfile status
logfile=`mktemp`
log_note $@ >> $logfile 2>&1
$@ >> $logfile 2>&1
status=$?
if [ $status -ne 0 ]; then
cat $logfile
rm $logfile
log_fail $@
fi
rm $logfile
}
log_must_not()
{
local logfile status
logfile=`mktemp`
log_note $@ >> $logfile 2>&1
$@ >> $logfile 2>&1
status=$?
if [ $status -eq 0 ]; then
cat $logfile > /dev/tty 2>&1
rm $logfile
log_fail $@
fi
rm $logfile
}
stop_zrepl()
{
if [ $ZREPL_PID -ne -1 ]; then
kill -SIGKILL $ZREPL_PID
ZREPL_PID=-1
fi
}
test_dup_zrepl()
{
# should block the duplicate zrepl start
$ZREPL &
pid=$!
sleep 2
blocked=`grep -c flock /proc/$pid/stack`
if [ $blocked -ne 1 ]; then
stop_zrepl
kill -SIGKILL $pid
echo "test failed, zrepl not blocked on flock"
exit 1;
fi
# kill the zrepl, the duplicate zrepl should take over
stop_zrepl
# wait for the other zrepl to take over
sleep 5
blocked=`grep -c flock /proc/$pid/stack`
if [ $blocked -ne 0 ]; then
kill -SIGKILL $pid
echo "test failed, zrepl not able to take over"
exit 1;
fi
ZREPL_PID=$pid
}
start_zrepl()
{
if [ $ZREPL_PID -eq -1 ]; then
$ZREPL &
ZREPL_PID=$!
sleep 5
test_dup_zrepl
else
echo "warning.. zrepl is already started"
fi
}
wait_for_pids()
{
for (( i = 1; i <= $#; i++ )) do
wait -n $@
status=$?
if [ $status -ne 0 ] && [ $status -ne 127 ]; then
exit 1
fi
done
}
create_disk()
{
for disk in "$@"; do
disk_name=$disk
rm $disk_name
log_must truncate -s 2G $disk_name
done
}
destroy_disk()
{
for disk in "$@"; do
disk_name=$disk
stat $disk_name >/dev/null && rm $disk_name
done
}
dump_data()
{
if [ $ZREPL_PID -ne -1 ]; then
kill -SIGHUP $ZREPL_PID
ret=$?
else
echo "warning.. zrepl was not started"
fi
# wait for some data to be dumped
sleep 3
return $ret
}
test_stats_len()
{
stats_len=`$ZFS stats | jq '.[] | length'`
test $stats_len = "$1" && return 0
return 1
}
run_zvol_targetip_tests()
{
local pool vol
pool=`echo $1| awk -F '/' '{print $1}'`
vol=`echo $1| awk -F '/' '{print $2}'`
pool_disk="$TMPDIR/test_targetip.img"
create_disk $pool_disk
log_must $ZPOOL create -f $pool -o cachefile="$TMPDIR/zpool_$pool.cache" \
$pool_disk
log_must $ZFS create -V $VOLSIZE -o io.openebs:targetip=127.0.0.1:6060 -o ${PROP_REPLICA_ID}=12345 $pool/$vol"_targetip_1"
log_must test_stats_len 1
log_must $ZFS create -V $VOLSIZE -o ${PROP_REPLICA_ID}=12345 $pool/$vol"_targetip_2"
log_must test_stats_len 1
log_must $ZFS set io.openebs:targetip= $pool/$vol"_targetip_1"
log_must test_stats_len 0
log_must $ZFS set io.openebs:targetip=127.0.0.1:6161 $pool/$vol"_targetip_2"
log_must test_stats_len 1
log_must $ZFS set io.openebs:targetip=127.0.0.1:6162 $pool/$vol"_targetip_1"
log_must test_stats_len 2
log_must_not $ZFS set io.openebs:targetip=127.0.0.1:5959 $pool/$vol"_targetip_1"
log_must test_stats_len 2
log_must $ZFS set io.openebs:targetip="" $pool/$vol"_targetip_1"
log_must test_stats_len 1
$ZFS create -V $VOLSIZE -o io.openebs:targetip=127.0.0.1:6161 -o ${PROP_REPLICA_ID}=12345 $pool/$vol"_targetip_3"
log_must test_stats_len 2
log_must export_pool $pool
log_must import_pool $pool
log_must test_stats_len 2
log_must destroy_pool $pool
destroy_disk $pool_disk
}
run_zvol_tests()
{
local src_pool
local src_vol
local dst_pool
local dst_vol
[[ $# -ne 2 ]] && return 1
src_pool=`echo $1| awk -F '/' '{print $1}'`
dst_pool=`echo $2| awk -F '/' '{print $1}'`
src_vol=`echo $1| awk -F '/' '{print $2}'`
dst_vol=`echo $2| awk -F '/' '{print $2}'`
[[ -z $src_pool || -z $dst_pool || -z $src_vol || -z $dst_vol ]] && return 1
if poolnotexists $src_pool || poolnotexists $dst_pool ; then
echo "pool does not exists"
return 1
fi
# test volume creation
log_must $ZFS create -V $VOLSIZE -o ${PROP_REPLICA_ID}=12345 $src_pool/$src_vol
log_must datasetexists $src_pool/$src_vol
log_must check_prop $src_pool/$src_vol type volume
log_must $ZFS create -V $VOLSIZE -o io.openebs:targetip=127.0.0.1:6060 -o io.openebs:zvol_workers=19 -o ${PROP_REPLICA_ID}=1234 $src_pool/$src_vol"_1"
# test volume properties
log_must $ZFS get all $src_pool/$src_vol > /dev/null
log_must $ZFS list $src_pool/$src_vol > /dev/null
log_must $ZFS set dedup=on $src_pool/$src_vol
log_must check_prop "$src_pool/$src_vol" dedup on
log_must $ZFS set compression=on $src_pool/$src_vol
log_must check_prop "$src_pool/$src_vol" compression on
log_must $ZFS set sync=standard $src_pool/$src_vol
log_must check_prop "$src_pool/$src_vol" sync standard
log_must check_prop "$src_pool/$src_vol" quorum off
log_must $ZFS set quorum=on $src_pool/$src_vol
log_must_not $ZFS set quorum=off $src_pool/$src_vol
log_must $ZFS set quorum=on $src_pool/$src_vol
log_must $ZFS set sync=disabled $src_pool/$src_vol
log_must check_prop "$src_pool/$src_vol" sync disabled
log_must $ZFS set sync=always $src_pool/$src_vol
log_must check_prop "$src_pool/$src_vol" sync always
log_must check_prop "$src_pool/$src_vol""_1" io.openebs:targetip 127.0.0.1:6060
log_must check_stats "$src_pool/$src_vol""_1" zvol_workers 19
# dump some data
#log_must dump_data
# test snapshot creation
log_must create_snapshot "$src_pool/$src_vol" "snap"
log_must snapexists "$src_pool/$src_vol@snap"
log_must check_prop "$src_pool/$src_vol@snap" type snapshot
# test zfs send/recv
log_note "zfs send/recv"
$ZFS send -vv "$src_pool/$src_vol@snap" | $ZFS recv "$dst_pool/$dst_vol"
# after zfs recv, dataset and snap should exist
log_must datasetexists $dst_pool/$dst_vol
log_must check_prop $dst_pool/$dst_vol type volume
log_must snapexists "$dst_pool/$dst_vol@snap"
log_must check_prop "$dst_pool/$dst_vol@snap" type snapshot
# should fail as it has children and -r is not passed
log_must_not $ZFS destroy $dst_pool/$dst_vol 2> /dev/null
log_must_not $ZFS destroy $src_pool/$src_vol 2> /dev/null
# test volume destroy
log_must $ZFS list -t all $dst_pool/$dst_vol > /dev/null
log_must $ZFS destroy -r $dst_pool/$dst_vol
log_must $ZFS list -t all $src_pool/$src_vol > /dev/null
log_must $ZFS destroy -r $src_pool/$src_vol
log_must $ZFS destroy -r $src_pool/$src_vol"_1"
# test snap destroy
log_must $ZFS create -s -V $VOLSIZE -o ${PROP_REPLICA_ID}=1234 $src_pool/$src_vol
log_must datasetexists $src_pool/$src_vol
log_must create_snapshot "$src_pool/$src_vol" "snap"
log_must snapexists "$src_pool/$src_vol@snap"
log_must check_prop "$src_pool/$src_vol@snap" type snapshot
log_must destroy_snapshot "$src_pool/$src_vol@snap"
log_must_not snapexists "$src_pool/$src_vol@snap"
return 0
}
run_pool_tests()
{
local src_pool
local src_vol
local dst_pool
local dst_vol
local log_disk
[[ $# -ne 2 ]] && return 1
src_pool=`echo $1| awk -F '/' '{print $1}'`
dst_pool=`echo $2| awk -F '/' '{print $1}'`
src_vol=`echo $1| awk -F '/' '{print $2}'`
dst_vol=`echo $2| awk -F '/' '{print $2}'`
[[ -z $src_pool || -z $dst_pool || -z $src_vol || -z $dst_vol ]] && return 1
if poolnotexists $src_pool || poolnotexists $dst_pool ; then
echo "pool does not exists"
return 1
fi
log_must cp $TMPDIR/zpool_$src_pool.cache $TMPDIR/$src_pool.cache
log_must cp $TMPDIR/zpool_$dst_pool.cache $TMPDIR/$dst_pool.cache
# test log addition/removal
log_disk="$TMPDIR/${src_pool}_disk.img"
create_disk $log_disk
log_must $ZPOOL add -f $src_pool log $log_disk
log_must $ZPOOL remove $src_pool $log_disk
log_must $ZPOOL add -f $dst_pool log $log_disk
log_must $ZPOOL remove $dst_pool $log_disk
destroy_disk $log_disk
# test pool export
log_must export_pool $src_pool
log_must export_pool $dst_pool
# should fail
#log_must check_state $src_pool "$TMPDIR/test_disk1.img" "online"
# test pool import
log_must $ZPOOL import -c "$TMPDIR/$src_pool.cache" $src_pool
log_must $ZPOOL import -c "$TMPDIR/$dst_pool.cache" $dst_pool
log_must rm "$TMPDIR/$src_pool.cache"
log_must rm "$TMPDIR/$dst_pool.cache"
log_must $ZPOOL set cachefile="$TMPDIR/zpool_$src_pool.cache" $src_pool
log_must $ZPOOL set cachefile="$TMPDIR/zpool_$dst_pool.cache" $dst_pool
cache=$($ZPOOL get -H -o value cachefile $src_pool)
if [ $cache != "$TMPDIR/zpool_$src_pool.cache" ]; then
log_fail "cachefile not set for $src_pool [$cache => $TMPDIR/zpool_$src_pool.cache]"
return 1
fi
cache=$($ZPOOL get -H -o value cachefile $dst_pool)
if [ $cache != "$TMPDIR/zpool_$dst_pool.cache" ]; then
log_fail "cachefile not set for $dst_pool [$cache => $TMPDIR/zpool_$dst_pool.cache]"
return 1
fi
# check pool status
log_must check_state $src_pool "online"
log_must check_state $dst_pool "online"
# check history
log_must check_history $src_pool "import -c $TMPDIR/$src_pool.cache $src_pool"
log_must check_history $src_pool "export $src_pool"
log_must check_history $src_pool "set cachefile=$TMPDIR/$src_pool.cache $src_pool"
log_must check_history $dst_pool "import -c $TMPDIR/$dst_pool.cache $dst_pool"
log_must check_history $dst_pool "export $dst_pool"
log_must check_history $dst_pool "set cachefile=$TMPDIR/$dst_pool.cache $dst_pool"
log_must $ZPOOL iostat -v $src_pool 1 5 > /dev/null
log_must $ZPOOL iostat -v $dst_pool 1 5 > /dev/null
return 0
}
#
# $1 Existing filesystem or volume name.
# $2 snapshot name. Default, $TESTSNAP
#
create_snapshot()
{
fs_vol=$1
snap=$2
test -z $fs_vol && log_fail "Filesystem or volume's name is undefined."
test -z $snap && log_fail "Snapshot's name is undefined."
if snapexists $fs_vol@$snap; then
return 1
fi
datasetexists $fs_vol || \
return 1
$ZFS snapshot $fs_vol@$snap
return $?
}
# delete the file system's snapshot
destroy_snapshot()
{
snap=$1
if ! snapexists $snap; then
return 1
fi
$ZFS destroy $snap
return $?
}
# $1 - snapshot name
snapexists()
{
$ZFS list -H -t snapshot "$1" > /dev/null 2>&1
return $?
}
# $1 - pool name
poolexists()
{
pool=$1
if [ -z $pool ]; then
echo "No pool name given."
return 1
fi
$ZPOOL get name "$pool" > /dev/null 2>&1
return $?
}
# $1 - pool name
poolnotexists()
{
pool=$1
if [ -z $pool ]; then
echo "No pool name given."
return 1
fi
if poolexists "$pool" ; then
return 1
else
return 0
fi
}
# $1 dataset name
datasetexists()
{
if [ $# -eq 0 ]; then
echo "No dataset name given."
return 1
fi
$ZFS get name $1 > /dev/null 2>&1 || return $?
return 0
}
# Destroy pool with the given parameters.
destroy_pool()
{
pool=$1
if [ -z $pool ]; then
echo "No pool name given."
return 1
fi
if poolexists "$pool" ; then
$ZPOOL destroy -f $pool
else
echo "Pool does not exist. ($pool)"
return 1
fi
return $?
}
# $1 - pool name
import_pool()
{
pool=$1
if [ -z $pool ]; then
echo "No pool name given."
return 1
fi
if poolexists "$pool" ; then
echo "Pool already imported. ($pool)"
return 1
else
log_must $ZPOOL import $pool -d $TMPDIR
fi
return $?
}
# $1 - pool name
export_pool()
{
pool=$1
if [ -z $pool ]; then
echo "No pool name given."
return 1
fi
if poolexists "$pool" ; then
$ZPOOL export $pool
else
echo "Pool does not exist. ($pool)"
return 1
fi
return $?
}
#
# Return 0 is pool matches expected state, 1 otherwise
check_state() # pool state{online,offline,degraded}
{
pool=$1
disk=$2
state=$3
test -z $pool \
&& log_fail "Arguments invalid or missing"
$ZPOOL get -H -o value health $pool \
| grep -i "$state" > /dev/null 2>&1
return $?
}
#
# Return 0 is history matches expected string
check_history()
{
pool=$1
match=$2
test -z $pool \
&& log_fail "Arguments invalid or missing"
$ZPOOL history -li $pool \
| grep -i "$match" > /dev/null 2>&1
return $?
}
check_stats()
{
type=$($ZFS stats | jq .stats[0].$2)
test $type = "$3" && return 0
return 1
}
check_prop()
{
type=$($ZFS get -pH -o value "$2" "$1")
test $type = "$3" && return 0
return 1
}
test_stripe_pool()
{
local src_pool dst_pool src_vol dst_vol
local src_pool_disk dst_pool_disk
local src_pool_spare_disk dst_pool_spare_disk
if [ $# -ne 2 ]; then
echo "missing src and dst pool"
exit 1
fi
src_pool=`echo $1| awk -F '/' '{print $1}'`
dst_pool=`echo $2| awk -F '/' '{print $1}'`
src_vol=`echo $1| awk -F '/' '{print $2}'`
dst_vol=`echo $2| awk -F '/' '{print $2}'`
src_pool_disk="$TMPDIR/test_stripe_s.img"
dst_pool_disk="$TMPDIR/test_stripe_d.img"
src_pool_spare_disk="$TMPDIR/test_stripe_spare_s.img"
dst_pool_spare_disk="$TMPDIR/test_stripe_spare_d.img"
# test pool creation
create_disk $src_pool_disk
create_disk $dst_pool_disk
log_must $ZPOOL create -f $src_pool -o cachefile="$TMPDIR/zpool_$src_pool.cache" \
$src_pool_disk
log_must $ZPOOL create -f $dst_pool -o cachefile="$TMPDIR/zpool_$dst_pool.cache" \
$dst_pool_disk
# test pool expansion
create_disk $src_pool_spare_disk
create_disk $dst_pool_spare_disk
# test clear pool
log_must $ZPOOL clear $src_pool
log_must $ZPOOL add -f $src_pool $src_pool_spare_disk
log_must $ZPOOL add -f $dst_pool $dst_pool_spare_disk
# test vdev remove
log_must_not $ZPOOL remove $src_pool $src_pool_spare_disk
log_must_not $ZPOOL remove $dst_pool $dst_pool_spare_disk
# read cachefile
log_must $ZDB -C -U "$TMPDIR/zpool_$src_pool.cache" $src_pool > /dev/null
log_must $ZDB -C -U "$TMPDIR/zpool_$dst_pool.cache" $dst_pool > /dev/null
# read disk labels
log_must $ZDB -l $src_pool_disk > /dev/null
log_must $ZDB -l $dst_pool_disk > /dev/null
# run test cases
log_must run_zvol_tests $src_pool/$src_vol $dst_pool/$dst_vol
log_must run_pool_tests $src_pool/$src_vol $dst_pool/$dst_vol
# test pool destroy
log_must destroy_pool $src_pool
log_must destroy_pool $dst_pool
destroy_disk $src_pool_disk
destroy_disk $dst_pool_disk
destroy_disk $src_pool_spare_disk
destroy_disk $dst_pool_spare_disk
return 0
}
test_mirror_pool()
{
local src_pool dst_pool src_vol dst_vol
local src_pool_disk_a src_pool_disk_b
local dst_pool_disk_a dst_pool_disk_b
local src_pool_spare_disk_a src_pool_spare_disk_b
local dst_pool_spare_disk_a dst_pool_spare_disk_b
if [ $# -ne 2 ]; then
echo "missing src and dst pool"
exit 1
fi
src_pool=`echo $1| awk -F '/' '{print $1}'`
dst_pool=`echo $2| awk -F '/' '{print $1}'`
src_vol=`echo $1| awk -F '/' '{print $2}'`
dst_vol=`echo $2| awk -F '/' '{print $2}'`
src_pool_disk_a="$TMPDIR/test_mirror_s_a.img"
src_pool_disk_b="$TMPDIR/test_mirror_s_b.img"
dst_pool_disk_a="$TMPDIR/test_mirror_d_a.img"
dst_pool_disk_b="$TMPDIR/test_mirror_d_b.img"
src_pool_spare_disk_a="$TMPDIR/test_mirror_spare_s_a.img"
src_pool_spare_disk_b="$TMPDIR/test_mirror_spare_s_b.img"
dst_pool_spare_disk_a="$TMPDIR/test_mirror_spare_d_a.img"
dst_pool_spare_disk_b="$TMPDIR/test_mirror_spare_d_b.img"
# test pool creation
create_disk $src_pool_disk_a $src_pool_disk_b
create_disk $dst_pool_disk_a $dst_pool_disk_b
# test pool creation
log_must $ZPOOL create -f $src_pool mirror \
-o cachefile="$TMPDIR/zpool_$src_pool.cache" \
$src_pool_disk_a $src_pool_disk_b
log_must $ZPOOL create -f $dst_pool mirror \
-o cachefile="$TMPDIR/zpool_$dst_pool.cache" \
$dst_pool_disk_a $dst_pool_disk_b
# test clear pool
log_must $ZPOOL clear $src_pool
# test pool expansion
create_disk $src_pool_spare_disk_a $src_pool_spare_disk_b
create_disk $dst_pool_spare_disk_a $dst_pool_spare_disk_b
log_must $ZPOOL add -f $src_pool $src_pool_spare_disk_a $src_pool_spare_disk_b
log_must $ZPOOL add -f $dst_pool $dst_pool_spare_disk_a $dst_pool_spare_disk_b
# test vdev remove
log_must_not $ZPOOL remove $src_pool $src_pool_spare_disk_a
log_must_not $ZPOOL remove $dst_pool $dst_pool_spare_disk_b
# read cachefile
log_must $ZDB -C -U "$TMPDIR/zpool_$src_pool.cache" $src_pool > /dev/null
log_must $ZDB -C -U "$TMPDIR/zpool_$dst_pool.cache" $dst_pool > /dev/null
# read disk labels
log_must $ZDB -l $src_pool_disk_a > /dev/null
log_must $ZDB -l $src_pool_disk_b > /dev/null
log_must $ZDB -l $dst_pool_disk_a > /dev/null
log_must $ZDB -l $dst_pool_disk_b > /dev/null
# run test cases
log_must run_zvol_tests $src_pool/$src_vol $dst_pool/$dst_vol
log_must run_pool_tests $src_pool/$src_vol $dst_pool/$dst_vol
# test pool destroy
log_must destroy_pool $src_pool
log_must destroy_pool $dst_pool
destroy_disk $src_pool_disk_a $src_pool_disk_b
destroy_disk $dst_pool_disk_a $dst_pool_disk_b
destroy_disk $src_pool_spare_disk_a $src_pool_spare_disk_b
destroy_disk $dst_pool_spare_disk_a $dst_pool_spare_disk_b
return 0
}
test_raidz_pool()
{
local src_pool dst_pool src_vol dst_vol
local src_pool_disk dst_pool_disk
local src_pool_spare_disk dst_pool_spare_disk
if [ $# -ne 2 ]; then
echo "missing src and dst pool"
exit 1
fi
src_pool=`echo $1| awk -F '/' '{print $1}'`
dst_pool=`echo $2| awk -F '/' '{print $1}'`
src_vol=`echo $1| awk -F '/' '{print $2}'`
dst_vol=`echo $2| awk -F '/' '{print $2}'`
for (( i = 1; i <= 4; i++ )) do
src_pool_disk[$i]="$TMPDIR/test_raidz_s_$i.img"
dst_pool_disk[$i]="$TMPDIR/test_raidz_d_$i.img"
src_pool_spare_disk[$i]="$TMPDIR/test_raidz_spare_s_$i.img"
dst_pool_spare_disk[$i]="$TMPDIR/test_raidz_spare_d_$i.img"
create_disk ${src_pool_disk[$i]} ${dst_pool_disk[$i]} \
${src_pool_spare_disk[$i]} ${dst_pool_spare_disk[$i]}
done
# test pool creation
log_must $ZPOOL create -f $src_pool raidz1 \
-o cachefile="$TMPDIR/zpool_$src_pool.cache" \
${src_pool_disk[1]} ${src_pool_disk[2]} ${src_pool_disk[3]} ${src_pool_disk[4]}
log_must $ZPOOL create -f $dst_pool raidz1 \
-o cachefile="$TMPDIR/zpool_$dst_pool.cache" \
${dst_pool_disk[1]} ${dst_pool_disk[2]} ${dst_pool_disk[3]} ${dst_pool_disk[4]}
# test pool expansion
log_must $ZPOOL add -f $src_pool \
${src_pool_spare_disk[1]} ${src_pool_spare_disk[2]} \
${src_pool_spare_disk[3]} ${src_pool_spare_disk[4]}
log_must $ZPOOL add -f $dst_pool \
${dst_pool_spare_disk[1]} ${dst_pool_spare_disk[2]} \
${dst_pool_spare_disk[3]} ${dst_pool_spare_disk[4]}
# test clear pool
log_must $ZPOOL clear $src_pool
# test vdev remove
log_must_not $ZPOOL remove $src_pool ${src_pool_spare_disk[2]}
log_must_not $ZPOOL remove $dst_pool ${dst_pool_spare_disk[3]}
# read cachefile
log_must $ZDB -C -U "$TMPDIR/zpool_$src_pool.cache" $src_pool > /dev/null
log_must $ZDB -C -U "$TMPDIR/zpool_$dst_pool.cache" $dst_pool > /dev/null
# read disk labels
for (( i = 1; i <= 4; i++ )) do
log_must $ZDB -l ${src_pool_disk[$i]} > /dev/null
log_must $ZDB -l ${dst_pool_disk[$i]} > /dev/null
done
# run test cases
log_must run_zvol_tests $src_pool/$src_vol $dst_pool/$dst_vol
log_must run_pool_tests $src_pool/$src_vol $dst_pool/$dst_vol
# test pool destroy
log_must destroy_pool $src_pool
log_must destroy_pool $dst_pool
for (( i = 1; i <= 4; i++ )) do
destroy_disk ${src_pool_disk[$i]} ${dst_pool_disk[$i]} \
${src_pool_spare_disk[$i]} ${dst_pool_spare_disk[$i]}
done
return 0
}
run_fio_test()
{
local fio_pool="fio_pool"
stop_zrepl
while [ 1 ]; do
netstat -apnt | grep -w 6060
if [ $? -ne 0 ]; then
break
else
sleep 5
fi
done
start_zrepl
[ -z "$FIO_SRCDIR" ] && log_fail "FIO_SRCDIR must be defined"
# Create backing store on disk device to test libaio backend
log_must truncate -s 100MB /tmp/disk;
if [ -e /dev/fake-dev ]; then
sudo losetup -d /dev/fake-dev;
sudo rm -f /dev/fake-dev;
fi
log_must sudo mknod /dev/fake-dev b 7 200;
log_must sudo chmod 666 /dev/fake-dev;
log_must sudo losetup /dev/fake-dev /tmp/disk;
log_must $ZPOOL create -f $fio_pool \
-o cachefile="$TMPDIR/zpool_$fio_pool.cache" "/tmp/disk"
log_must $ZFS create -sV $VOLSIZE -o volblocksize=4k -o io.openebs:targetip=127.0.0.1:6060 -o ${PROP_REPLICA_ID}=1234 $fio_pool/vol1
log_must $ZFS create -sV $VOLSIZE -o volblocksize=4k -o io.openebs:targetip=127.0.0.1:6060 -o ${PROP_REPLICA_ID}=1234 $fio_pool/vol2
cat >$TMPDIR/test.fio <<EOF
[global]
ioengine=replica.so
thread=1
group_reporting=1
direct=1
verify=md5
ramp_time=0
iodepth=128
rw=randrw
bs=4k
filesize=20m
fallocate=none
time_based=1
runtime=15
numjobs=1
[vol1]
filename=$fio_pool/vol1
[vol2]
filename=$fio_pool/vol2
EOF
# run the fio
echo "Running $FIO_SRCDIR/fio with lib path $SRC_PATH/lib/fio/.libs"
echo " and following configuration:"
cat $TMPDIR/test.fio
echo
LD_LIBRARY_PATH=$SRC_PATH/lib/fio/.libs $FIO_SRCDIR/fio $TMPDIR/test.fio
[ $? -eq 0 ] || log_fail "Fio test run failed"
sleep 5
# test pool destroy
# XXX Bug: we must destroy volumes before pool. If not then EBUSY
log_must $ZFS destroy -R $fio_pool/vol1
log_must $ZFS destroy -R $fio_pool/vol2
log_must destroy_pool $fio_pool
log_must rm $TMPDIR/test.fio
log_must sudo losetup -d /dev/fake-dev;
log_must sudo rm /dev/fake-dev;
log_must rm /tmp/disk;
return 0
}
#setup_uzfs_test log/nolog block_size vol_size sync pool_name \
# volume_name vdev_file log_file
setup_uzfs_test()
{
local block_size=$2
local vol_size=$3
local sync_prop=$4
local pool_name=$5
local volume_name=$6
local vdev_file=$7
local log_file
if [ $ZREPL_PID -eq -1 ]; then
echo "zrepl is not started..."
$ZREPL &
sleep 10
ZREPL_PID=$!
fi
export_pool $pool_name
if [ "$1" == "log" ]; then
if [ $# -ne 8 ]; then
echo "log file missing"
return 1
fi
log_file=$8
create_disk $TMPDIR/$vdev_file
create_disk $TMPDIR/$log_file
log_must $ZPOOL create -f $pool_name "$TMPDIR/$vdev_file" \
log "$TMPDIR/$log_file"
else
create_disk $TMPDIR/$vdev_file
log_must $ZPOOL create -f $pool_name "$TMPDIR/$vdev_file"
fi
log_must $ZFS create -V $vol_size -o ${PROP_REPLICA_ID}=1234 $pool_name/$volume_name -b $block_size
log_must $ZFS set sync=$sync_prop $pool_name/$volume_name
return 0
}
#cleanup_uzfs_test pool_name vdev_file log_file
cleanup_uzfs_test()
{
local pool_name vdev_file log_file
if [ $# -lt 2 ]; then
echo "missing pool name and disk name"
exit 1
fi
pool_name=$1
vdev_file=$2
if poolnotexists $pool_name ; then
log_must $ZPOOL import $pool_name -d $TMPDIR
fi
log_must $ZPOOL destroy $pool_name 2> /dev/null
log_must $ZPOOL labelclear -f $TMPDIR/$vdev_file 2> /dev/null
log_must dd if=/dev/zero of=$TMPDIR/$vdev_file bs=1M count=100
destroy_disk $TMPDIR/$vdev_file
if [ $# -eq 3 ]; then
log_file=$3
log_must $ZPOOL labelclear -f $TMPDIR/$log_file 2> /dev/null
log_must dd if=/dev/zero of=$TMPDIR/$log_file bs=1M count=100
destroy_disk $TMPDIR/$log_file
fi
}
run_zrepl_uzfs_test()
{
export_pool $UZFS_TEST_POOL
if [ "$1" == "log" ]; then
log_must setup_uzfs_test log $2 $UZFS_TEST_VOLSIZE $3 $UZFS_TEST_POOL \
$UZFS_TEST_VOL uzfs_zrepl_vdev1 uzfs_zrepl_log1
else
log_must setup_uzfs_test nolog $2 $UZFS_TEST_VOLSIZE $3 $UZFS_TEST_POOL $UZFS_TEST_VOL uzfs_zrepl_vdev1
fi
log_must $ZFS set io.openebs:targetip=127.0.0.1:6060 $UZFS_TEST_POOL/$UZFS_TEST_VOL
log_must export_pool $UZFS_TEST_POOL
log_must import_pool $UZFS_TEST_POOL
log_must $UZFS_TEST -T 4
sleep 5
if [ "$1" == "log" ]; then
cleanup_uzfs_test $UZFS_TEST_POOL uzfs_zrepl_vdev1 uzfs_zrepl_log1
else
cleanup_uzfs_test $UZFS_TEST_POOL uzfs_zrepl_vdev1
fi
return 0
}