2 # SPDX-License-Identifier: GPL-2.0-or-later
3 # Copyright (c) 2021 Oracle. All Rights Reserved.
7 # Check that we can upgrade a filesystem to support bigtime and that quota
8 # timers work properly after the upgrade. You need a quota-tools containing
9 # commit 16b60cb9e315ed for this test to run properly; v4.06 should do.
12 _begin_fstest auto quick bigtime quota
14 # Import common functions.
18 # real QA test starts here
20 _require_command "$XFS_ADMIN_PROG" "xfs_admin"
21 _require_command "$QUOTA_PROG" "quota"
23 _require_scratch_xfs_bigtime
24 _require_xfs_repair_upgrade bigtime
26 # The word 'projectname' was added to quota(8)'s synopsis shortly after
27 # y2038+ support was added for XFS, so we use that to decide if we're going
28 # to run this test at all.
29 $QUOTA_PROG --help 2>&1 | grep -q projectname || \
30 _notrun 'quota: bigtime support not detected'
32 date --date='Jan 1 00:00:00 UTC 2040' > /dev/null 2>&1 || \
33 _notrun "Userspace does not support dates past 2038."
35 # Format V5 filesystem without bigtime support and populate it
36 _scratch_mkfs -m crc=1,bigtime=0 >> $seqres.full
37 _qmount_option "usrquota"
38 _scratch_xfs_db -c 'version' -c 'sb 0' -c 'p' >> $seqres.full
39 _scratch_mount >> $seqres.full
41 # Force the block counters for uid 1 and 2 above zero
42 _pwrite_byte 0x61 0 64k $SCRATCH_MNT/a >> $seqres.full
43 _pwrite_byte 0x61 0 64k $SCRATCH_MNT/b >> $seqres.full
45 chown 1 $SCRATCH_MNT/a
46 chown 2 $SCRATCH_MNT/b
48 # Set quota limits on uid 1 before upgrading
49 $XFS_QUOTA_PROG -x -c 'limit -u bsoft=12k bhard=1m 1' $SCRATCH_MNT
51 # Make sure the grace period is at /some/ point in the future. We have to
52 # use bc because not all bashes can handle integer comparisons with 64-bit
54 repquota -upn $SCRATCH_MNT > $tmp.repquota
55 cat $tmp.repquota >> $seqres.full
56 grace="$(cat $tmp.repquota | grep '^#1' | awk '{print $6}')"
58 res="$(echo "${grace} > ${now}" | $BC_PROG)"
59 test $res -eq 1 || echo "Expected timer expiry (${grace}) to be after now (${now})."
63 # Now upgrade to bigtime support
64 _scratch_xfs_admin -O bigtime=1 2>> $seqres.full
65 _check_scratch_xfs_features BIGTIME
67 _scratch_xfs_db -c 'version' -c 'sb 0' -c 'p' >> $seqres.full
69 # Mount again, see if our quota timer survived
72 # Set a very generous grace period and quota limits on uid 2 after upgrading
73 $XFS_QUOTA_PROG -x -c 'timer -u -b -d 2147483647' $SCRATCH_MNT
74 $XFS_QUOTA_PROG -x -c 'limit -u bsoft=10000 bhard=150000 2' $SCRATCH_MNT
76 # Query the grace periods to see if they got set properly after the upgrade.
77 repquota -upn $SCRATCH_MNT > $tmp.repquota
78 cat $tmp.repquota >> $seqres.full
79 grace1="$(repquota -upn $SCRATCH_MNT | grep '^#1' | awk '{print $6}')"
80 grace2="$(repquota -upn $SCRATCH_MNT | grep '^#2' | awk '{print $6}')"
83 # Make sure that uid 1's expiration is in the future...
84 res1="$(echo "${grace} > ${now}" | $BC_PROG)"
85 test "${res1}" -eq 1 || echo "Expected uid 1 expiry (${grace1}) to be after now (${now})."
87 # ...and that uid 2's expiration is after uid 1's...
88 res2="$(echo "${grace2} > ${grace1}" | $BC_PROG)"
89 test "${res2}" -eq 1 || echo "Expected uid 2 expiry (${grace2}) to be after uid 1 (${grace1})."
91 # ...and that uid 2's expiration is after 2038 if right now is far enough
92 # past 1970 that our generous grace period would provide for that.
93 res3="$(echo "(${now} < 100) || (${grace2} > 2147483648)" | $BC_PROG)"
94 test "${res3}" -eq 1 || echo "Expected uid 2 expiry (${grace2}) to be after 2038."
98 # Query the grace periods to see if they survived a remount.
99 repquota -upn $SCRATCH_MNT > $tmp.repquota
100 cat $tmp.repquota >> $seqres.full
101 grace1="$(repquota -upn $SCRATCH_MNT | grep '^#1' | awk '{print $6}')"
102 grace2="$(repquota -upn $SCRATCH_MNT | grep '^#2' | awk '{print $6}')"
105 # Make sure that uid 1's expiration is in the future...
106 res1="$(echo "${grace} > ${now}" | $BC_PROG)"
107 test "${res1}" -eq 1 || echo "Expected uid 1 expiry (${grace1}) to be after now (${now})."
109 # ...and that uid 2's expiration is after uid 1's...
110 res2="$(echo "${grace2} > ${grace1}" | $BC_PROG)"
111 test "${res2}" -eq 1 || echo "Expected uid 2 expiry (${grace2}) to be after uid 1 (${grace1})."
113 # ...and that uid 2's expiration is after 2038 if right now is far enough
114 # past 1970 that our generous grace period would provide for that.
115 res3="$(echo "(${now} < 100) || (${grace2} > 2147483648)" | $BC_PROG)"
116 test "${res3}" -eq 1 || echo "Expected uid 2 expiry (${grace2}) to be after 2038."
118 # Now try setting uid 2's expiration to Feb 22 22:22:22 UTC 2222
119 new_expiry=$(date -d 'Feb 22 22:22:22 UTC 2222' +%s)
121 test $now -ge $new_expiry && \
122 echo "Now is after February 2222? Expect problems."
123 expiry_delta=$((new_expiry - now))
125 echo "setting expiration to $new_expiry - $now = $expiry_delta" >> $seqres.full
126 $XFS_QUOTA_PROG -x -c "timer -u $expiry_delta 2" -c 'report' $SCRATCH_MNT >> $seqres.full
128 # Did we get an expiration within 5s of the target range?
129 grace2="$(repquota -upn $SCRATCH_MNT | grep '^#2' | awk '{print $6}')"
130 echo "grace2 is $grace2" >> $seqres.full
131 _within_tolerance "grace2 expiry" $grace2 $new_expiry 5 -v
135 # ...and is it still within 5s after a remount?
136 grace2="$(repquota -upn $SCRATCH_MNT | grep '^#2' | awk '{print $6}')"
137 echo "grace2 is $grace2" >> $seqres.full
138 _within_tolerance "grace2 expiry after remount" $grace2 $new_expiry 5 -v