]>
Commit | Line | Data |
---|---|---|
b59b2297 | 1 | #!/bin/ksh -p |
2 | # | |
3 | # This file and its contents are supplied under the terms of the | |
4 | # Common Development and Distribution License ("CDDL"), version 1.0. | |
5 | # You may only use this file in accordance with the terms of version | |
6 | # 1.0 of the CDDL. | |
7 | # | |
8 | # A full copy of the text of the CDDL should have accompanied this | |
9 | # source. A copy of the CDDL is also available via the Internet at | |
10 | # http://www.illumos.org/license/CDDL. | |
11 | # | |
12 | ||
13 | # | |
14 | # Copyright 2017, loli10K <ezomori.nozomu@gmail.com>. All rights reserved. | |
15 | # | |
16 | ||
17 | . $STF_SUITE/include/libtest.shlib | |
18 | ||
19 | # | |
20 | # DESCRIPTION: | |
21 | # 'zfs diff -t' should display inode change time correctly. | |
22 | # | |
23 | # STRATEGY: | |
24 | # 1. Create a snapshot | |
25 | # 2. Create some files with a random delay and snapshot the filesystem again | |
26 | # 3. Verify 'zfs diff -t' correctly display timestamps | |
27 | # | |
28 | ||
29 | verify_runnable "both" | |
30 | ||
31 | function cleanup | |
32 | { | |
33 | for snap in $TESTSNAP1 $TESTSNAP2; do | |
34 | if snapexists "$snap"; then | |
35 | log_must zfs destroy "$snap" | |
36 | fi | |
37 | done | |
38 | find "$MNTPOINT" -type f -delete | |
39 | rm -f "$FILEDIFF" | |
40 | } | |
41 | ||
42 | # | |
43 | # Creates $count files in $fspath. Waits a random delay between each file. | |
44 | # | |
45 | function create_random # <fspath> <count> | |
46 | { | |
47 | fspath="$1" | |
48 | typeset -i count="$2" | |
49 | typeset -i i=0 | |
50 | ||
51 | while (( i < count )); do | |
52 | log_must touch "$fspath/file$i" | |
53 | sleep $(random 3) | |
54 | (( i = i + 1 )) | |
55 | done | |
56 | } | |
57 | ||
58 | log_assert "'zfs diff -t' should display inode change time correctly." | |
59 | log_onexit cleanup | |
60 | ||
61 | DATASET="$TESTPOOL/$TESTFS" | |
62 | TESTSNAP1="$DATASET@snap1" | |
63 | TESTSNAP2="$DATASET@snap2" | |
64 | MNTPOINT="$(get_prop mountpoint $DATASET)" | |
65 | FILEDIFF="$TESTDIR/zfs-diff.txt" | |
66 | FILENUM=5 | |
67 | ||
68 | # 1. Create a snapshot | |
69 | log_must zfs snapshot "$TESTSNAP1" | |
70 | ||
71 | # 2. Create some files with a random delay and snapshot the filesystem again | |
72 | create_random "$MNTPOINT" $FILENUM | |
73 | log_must zfs snapshot "$TESTSNAP2" | |
74 | ||
75 | # 3. Verify 'zfs diff -t' correctly display timestamps | |
76 | typeset -i count=0 | |
77 | log_must eval "zfs diff -t $TESTSNAP1 $TESTSNAP2 > $FILEDIFF" | |
fb0da71f | 78 | awk '{print substr($1,1,index($1,".")-1)" "$NF}' < "$FILEDIFF" | while read line |
b59b2297 | 79 | do |
80 | read ctime file <<< "$line" | |
81 | ||
82 | # If path from 'zfs diff' is not a file (could be xattr object) skip it | |
83 | if [[ ! -f "$file" ]]; then | |
84 | continue; | |
85 | fi | |
86 | ||
7839c4b5 MM |
87 | if is_freebsd; then |
88 | filetime="$(stat -f "%c" $file)" | |
89 | else | |
90 | filetime="$(stat -c '%Z' $file)" | |
91 | fi | |
b59b2297 | 92 | if [[ "$filetime" != "$ctime" ]]; then |
93 | log_fail "Unexpected ctime for file $file ($filetime != $ctime)" | |
94 | else | |
95 | log_note "Correct ctime read on $file: $ctime" | |
96 | fi | |
97 | ||
98 | (( i = i + 1 )) | |
99 | done | |
100 | if [[ $i != $FILENUM ]]; then | |
101 | log_fail "Wrong number of files verified ($i != $FILENUM)" | |
102 | fi | |
103 | ||
104 | log_pass "'zfs diff -t' displays inode change time correctly." |