xref: /illumos-gate/usr/src/test/zfs-tests/tests/functional/cli_root/zpool_sync/zpool_sync_001_pos.ksh (revision e82490700e19f1b8a2cef6102f4726144d281988)
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
33verify_runnable "global"
34
35function get_txg {
36	typeset -i txg=$(zdb -u $1 | sed -n 's/^[ 	][ 	]*txg = \(.*\)$/\1/p')
37	echo $txg
38}
39
40set -A args "sync $TESTPOOL" "sync -f $TESTPOOL" "sync" "sync -f"
41
42log_assert "Verify 'zpool sync' can sync a pool"
43
44typeset -i i=0
45typeset -i orig_txg=0
46typeset -i new_txg=0
47while [[ $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))
58done
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
63orig_txg=$(get_txg $TESTPOOL)
64log_must touch /$TESTPOOL/$i
65log_must sync_pool $TESTPOOL false
66new_txg=$(get_txg $TESTPOOL)
67if [[ $orig_txg -ge $new_txg ]]; then
68	log_fail "'sync_pool $TESTPOOL false' failed: txg $orig_txg >= $new_txg"
69fi
70
71# make sure we can use sync_pool with force sync explicitly enabled
72orig_txg=$(get_txg $TESTPOOL)
73log_must sync_pool $TESTPOOL true
74new_txg=$(get_txg $TESTPOOL)
75if [[ $orig_txg -ge $new_txg ]]; then
76	log_fail "'sync_pool $TESTPOOL true' failed: txg $orig_txg >= $new_txg"
77fi
78
79# make sure we can use sync_pool with force sync implicitly not used
80orig_txg=$(get_txg $TESTPOOL)
81log_must touch /$TESTPOOL/$i
82log_must sync_pool $TESTPOOL
83new_txg=$(get_txg $TESTPOOL)
84if [[ $orig_txg -ge $new_txg ]]; then
85	log_fail "'sync_pool $TESTPOOL' failed: txg $orig_txg >= $new_txg"
86fi
87
88log_pass "'zpool sync' syncs pool as expected."
89