]> git.proxmox.com Git - mirror_zfs-debian.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_sync/zpool_sync_001_pos.ksh
New upstream version 0.7.2
[mirror_zfs-debian.git] / tests / zfs-tests / tests / functional / cli_root / zpool_sync / zpool_sync_001_pos.ksh
1 #!/bin/ksh -p
2 #
3 # CDDL HEADER START
4 #
5 # This file and its contents are supplied under the terms of the
6 # Common Development and Distribution License ("CDDL"), version 1.0.
7 # You may only use this file in accordance with the terms of version
8 # 1.0 of the CDDL.
9 #
10 # A full copy of the text of the CDDL should have accompanied this
11 # source. A copy of the CDDL is also available via the Internet at
12 # http://www.illumos.org/license/CDDL.
13 #
14 # CDDL HEADER END
15 #
16 # Copyright (c) 2017 Datto Inc.
17 #
18
19 . $STF_SUITE/include/libtest.shlib
20
21 #
22 # DESCRIPTION:
23 # Verify 'zpool sync' can sync txgs to the pool(s) main vdevs.
24 #
25 # STRATEGY:
26 # 1. Create a pool
27 # 2. Use zdb to obtain current txg
28 # 3. Create a file in the pool if we're not using force sync
29 # 4. Use zpool sync to sync pool
30 # 5. Verify the new txg is now bigger than the saved one
31 #
32
33 verify_runnable "global"
34
35 function get_txg {
36 typeset -i txg=$(zdb -u $1 | sed -n 's/^.*txg = \(.*\)$/\1/p')
37 echo $txg
38 }
39
40 set -A args "sync $TESTPOOL" "sync -f $TESTPOOL" "sync" "sync -f"
41
42 log_assert "Verify 'zpool sync' can sync a pool"
43
44 typeset -i i=0
45 typeset -i orig_txg=0
46 typeset -i new_txg=0
47 while [[ $i -lt ${#args[*]} ]]; do
48 orig_txg=$(get_txg $TESTPOOL)
49 if ! [[ "${args[i]}" =~ "-f" ]]; then
50 log_must touch /$TESTPOOL/$i
51 fi
52 log_must zpool ${args[i]}
53 new_txg=$(get_txg $TESTPOOL)
54 if [[ $orig_txg -ge $new_txg ]]; then
55 log_fail "'zpool ${args[i]}' failed: txg $orig_txg >= $new_txg"
56 fi
57 ((i = i + 1))
58 done
59
60 # sync_pool is implemented using 'zpool sync' so let's test it as well
61
62 # make sure we can use sync_pool with force sync explicitly not used
63 orig_txg=$(get_txg $TESTPOOL)
64 log_must touch /$TESTPOOL/$i
65 log_must sync_pool $TESTPOOL false
66 new_txg=$(get_txg $TESTPOOL)
67 if [[ $orig_txg -ge $new_txg ]]; then
68 log_fail "'sync_pool $TESTPOOL false' failed: txg $orig_txg >= $new_txg"
69 fi
70
71 # make sure we can use sync_pool with force sync explicitly enabled
72 orig_txg=$(get_txg $TESTPOOL)
73 log_must sync_pool $TESTPOOL true
74 new_txg=$(get_txg $TESTPOOL)
75 if [[ $orig_txg -ge $new_txg ]]; then
76 log_fail "'sync_pool $TESTPOOL true' failed: txg $orig_txg >= $new_txg"
77 fi
78
79 # make sure we can use sync_pool with force sync implicitly not used
80 orig_txg=$(get_txg $TESTPOOL)
81 log_must touch /$TESTPOOL/$i
82 log_must sync_pool $TESTPOOL
83 new_txg=$(get_txg $TESTPOOL)
84 if [[ $orig_txg -ge $new_txg ]]; then
85 log_fail "'sync_pool $TESTPOOL' failed: txg $orig_txg >= $new_txg"
86 fi
87
88 log_pass "'zpool sync' syncs pool as expected."