]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - tests/zfs-tests/tests/functional/cli_root/zpool_trim/zpool_trim_import_export.ksh
Vendor import of openzfs master @ 184df27eef0abdc7ab2105b21257f753834b936b
[FreeBSD/FreeBSD.git] / tests / zfs-tests / tests / functional / cli_root / zpool_trim / zpool_trim_import_export.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
17 #
18 # Copyright (c) 2019 by Tim Chase. All rights reserved.
19 # Copyright (c) 2019 Lawrence Livermore National Security, LLC.
20 #
21
22 . $STF_SUITE/include/libtest.shlib
23 . $STF_SUITE/tests/functional/cli_root/zpool_trim/zpool_trim.kshlib
24
25 #
26 # DESCRIPTION:
27 # Trimming automatically resumes across import/export.
28 #
29 # STRATEGY:
30 # 1. Create a one-disk pool.
31 # 2. Start trimming and verify that trimming is active.
32 # 3. Export the pool.
33 # 4. Import the pool.
34 # 5. Verify that trimming resumes and progress does not regress.
35 # 6. Suspend trimming.
36 # 7. Repeat steps 3-4.
37 # 8. Verify that progress does not regress but trimming is still suspended.
38 #
39
40 function cleanup
41 {
42         if poolexists $TESTPOOL; then
43                 destroy_pool $TESTPOOL
44         fi
45
46         if [[ -d "$TESTDIR" ]]; then
47                 rm -rf "$TESTDIR"
48         fi
49 }
50
51 LARGEFILE="$TESTDIR/largefile"
52
53 log_must mkdir "$TESTDIR"
54 log_must truncate -s 10G "$LARGEFILE"
55 log_must zpool create -f $TESTPOOL $LARGEFILE
56
57 log_must zpool trim -r 256M $TESTPOOL
58 sleep 2
59
60 progress="$(trim_progress $TESTPOOL $LARGEFILE)"
61 [[ -z "$progress" ]] && log_fail "Trimming did not start"
62
63 log_must zpool export $TESTPOOL
64 log_must zpool import -d $TESTDIR $TESTPOOL
65
66 new_progress="$(trim_progress $TESTPOOL $LARGEFILE)"
67 [[ -z "$new_progress" ]] && log_fail "Trimming did not restart after import"
68
69 [[ "$progress" -le "$new_progress" ]] || \
70     log_fail "Trimming lost progress after import"
71 log_mustnot eval "trim_prog_line $TESTPOOL $LARGEFILE | grep suspended"
72
73 log_must zpool trim -s $TESTPOOL $LARGEFILE
74 action_date="$(trim_prog_line $TESTPOOL $LARGEFILE | \
75     sed 's/.*ed at \(.*\)).*/\1/g')"
76 log_must zpool export $TESTPOOL
77 log_must zpool import -d $TESTDIR $TESTPOOL
78 new_action_date=$(trim_prog_line $TESTPOOL $LARGEFILE | \
79     sed 's/.*ed at \(.*\)).*/\1/g')
80 [[ "$action_date" != "$new_action_date" ]] && \
81     log_fail "Trimming action date did not persist across export/import"
82
83 [[ "$new_progress" -le "$(trim_progress $TESTPOOL $LARGEFILE)" ]] || \
84         log_fail "Trimming lost progress after import"
85
86 log_must eval "trim_prog_line $TESTPOOL $LARGEFILE | grep suspended"
87
88 log_pass "Trimming retains state as expected across export/import"