1#! /bin/ksh -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or https://opensource.org/licenses/CDDL-1.0.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23#
24# Copyright 2022 iXsystems, Inc.
25#
26
27. $STF_SUITE/include/libtest.shlib
28. $STF_SUITE/tests/functional/snapshot/snapshot.cfg
29
30#
31# DESCRIPTION:
32# Verify the functionality of snapshots_changed property
33#
34# STRATEGY:
35# 1. Create a pool
36# 2. Verify snapshots_changed property is NULL
37# 3. Create a filesystem
38# 4. Verify snapshots_changed property is NULL
39# 5. Create snapshots for all filesystems
40# 6. Verify snapshots_changed property shows correct time
41# 7. Unmount all filesystems
42# 8. Create a snapshot while unmounted
43# 9. Verify snapshots_changed
44# 10. Mount the filsystems
45# 11. Verify snapshots_changed
46# 12. Destroy the snapshots
47# 13. Verify snapshots_changed
48#
49
50function cleanup
51{
52	create_pool $TESTPOOL $DISKS
53}
54
55verify_runnable "both"
56
57log_assert "Verify snapshots_changed property"
58
59log_onexit cleanup
60
61snap_testpool="$TESTPOOL@v1"
62snap_testfsv1="$TESTPOOL/$TESTFS@v1"
63snap_testfsv2="$TESTPOOL/$TESTFS@v2"
64snapdir=".zfs/snapshot"
65
66# Create filesystems and check snapshots_changed is NULL
67create_pool $TESTPOOL $DISKS
68snap_changed_testpool=$(zfs get -H -o value -p snapshots_changed $TESTPOOL)
69log_must eval "[[ $snap_changed_testpool == - ]]"
70tpool_snapdir=$(get_prop mountpoint $TESTPOOL)/$snapdir
71log_must eval "[[ $(stat_mtime $tpool_snapdir) == 0 ]]"
72
73log_must zfs create $TESTPOOL/$TESTFS
74snap_changed_testfs=$(zfs get -H -o value -p snapshots_changed $TESTPOOL/$TESTFS)
75log_must eval "[[ $snap_changed_testfs == - ]]"
76tfs_snapdir=$(get_prop mountpoint $TESTPOOL/$TESTFS)/$snapdir
77log_must eval "[[ $(stat_mtime $tfs_snapdir) == 0 ]]"
78
79# Create snapshots for filesystems and check snapshots_changed reports correct time
80curr_time=$(date '+%s')
81log_must zfs snapshot $snap_testpool
82snap_changed_testpool=$(zfs get -H -o value -p snapshots_changed $TESTPOOL)
83log_must eval "[[ $snap_changed_testpool -ge $curr_time ]]"
84log_must eval "[[ $(stat_mtime $tpool_snapdir) ==  $snap_changed_testpool ]]"
85
86curr_time=$(date '+%s')
87log_must zfs snapshot $snap_testfsv1
88snap_changed_testfs=$(zfs get -H -o value -p snapshots_changed $TESTPOOL/$TESTFS)
89log_must eval "[[ $snap_changed_testfs -ge $curr_time ]]"
90log_must eval "[[ $(stat_mtime $tfs_snapdir) ==  $snap_changed_testfs ]]"
91
92# Unmount the filesystems and check snapshots_changed has correct value after unmount
93log_must zfs unmount $TESTPOOL/$TESTFS
94log_must eval "[[ $(zfs get -H -o value -p snapshots_changed $TESTPOOL/$TESTFS) == $snap_changed_testfs ]]"
95
96# Create snapshot while unmounted
97curr_time=$(date '+%s')
98log_must zfs snapshot $snap_testfsv2
99snap_changed_testfs=$(zfs get -H -o value -p snapshots_changed $TESTPOOL/$TESTFS)
100log_must eval "[[ $snap_changed_testfs -ge $curr_time ]]"
101
102log_must zfs unmount $TESTPOOL
103log_must eval "[[ $(zfs get -H -o value -p snapshots_changed $TESTPOOL) == $snap_changed_testpool ]]"
104
105# Mount back the filesystems and check snapshots_changed still has correct value
106log_must zfs mount $TESTPOOL
107log_must eval "[[ $(zfs get -H -o value -p snapshots_changed $TESTPOOL) == $snap_changed_testpool ]]"
108log_must eval "[[ $(stat_mtime $tpool_snapdir) ==  $snap_changed_testpool ]]"
109
110log_must zfs mount $TESTPOOL/$TESTFS
111log_must eval "[[ $(zfs get -H -o value -p snapshots_changed $TESTPOOL/$TESTFS) == $snap_changed_testfs ]]"
112log_must eval "[[ $(stat_mtime $tfs_snapdir) ==  $snap_changed_testfs ]]"
113
114# Destroy the snapshots and check snapshots_changed shows correct time
115curr_time=$(date '+%s')
116log_must zfs destroy $snap_testfsv1
117snap_changed_testfs=$(zfs get -H -o value -p snapshots_changed $TESTPOOL/$TESTFS)
118log_must eval "[[ $snap_changed_testfs -ge $curr_time ]]"
119log_must eval "[[ $(stat_mtime $tfs_snapdir) ==  $snap_changed_testfs ]]"
120
121curr_time=$(date '+%s')
122log_must zfs destroy $snap_testpool
123snap_changed_testpool=$(zfs get -H -o value -p snapshots_changed $TESTPOOL)
124log_must eval "[[ $snap_changed_testpool -ge $curr_time ]]"
125log_must eval "[[ $(stat_mtime $tpool_snapdir) ==  $snap_changed_testpool ]]"
126
127log_pass "snapshots_changed property behaves correctly"
128