View | Details | Raw Unified | Return to bug 275965 | Differences between
and this patch

Collapse All | Expand All

(-)b/share/man/man5/periodic.conf.5 (+19 lines)
Lines 643-648 if you want to run a zfs trim daily. Link Here
643
.Pq Vt str
643
.Pq Vt str
644
A space separated list of names of zfs pools to trim.
644
A space separated list of names of zfs pools to trim.
645
If the list is empty or not set, all zfs pools are trimmed.
645
If the list is empty or not set, all zfs pools are trimmed.
646
.It Va daily_trim_zfs_default_threshold
647
.Pq Vt int
648
Number of days between a trim if no pool-specific threshold is set.
649
If not set, the default value is 14, corresponding to 2 weeks.
650
.It Va daily_trim_zfs_ Ns Ao Ar poolname Ac Ns Va _threshold
651
.Pq Vt int
652
The same as
653
.Va daily_trim_zfs_default_threshold
654
but specific to the pool
655
.Ao Ar poolname Ac Ns .
656
.It Va daily_trim_zfs_default_rate
657
.Pq Vt str
658
Controls the rate at which the TRIM operation progresses.
659
.It Va daily_trim_zfs_ Ns Ao Ar poolname Ac Ns Va _threshold
660
.Pq Vt int
661
The same as
662
.Va daily_trim_zfs_default_rate
663
but specific to the pool
664
.Ao Ar poolname Ac Ns .
646
.It Va daily_local
665
.It Va daily_local
647
.Pq Vt str
666
.Pq Vt str
648
Set to a list of extra scripts that should be run after all other
667
Set to a list of extra scripts that should be run after all other
(-)b/usr.sbin/periodic/etc/daily/801.trim-zfs (-11 / +61 lines)
Lines 4-17 Link Here
4
4
5
# If there is a global system configuration file, suck it in.
5
# If there is a global system configuration file, suck it in.
6
#
6
#
7
8
if [ -r /etc/defaults/periodic.conf ]
7
if [ -r /etc/defaults/periodic.conf ]
9
then
8
then
10
    . /etc/defaults/periodic.conf
9
    . /etc/defaults/periodic.conf
11
    source_periodic_confs
10
    source_periodic_confs
12
fi
11
fi
13
12
14
case "$daily_trim_zfs_enable" in
13
: ${daily_trim_zfs_default_threshold=14}
14
15
case "${daily_trim_zfs_enable}" in
15
    [Yy][Ee][Ss])
16
    [Yy][Ee][Ss])
16
	echo
17
	echo
17
	echo 'Trimming of zfs pools:'
18
	echo 'Trimming of zfs pools:'
Lines 34-53 case "$daily_trim_zfs_enable" in Link Here
34
		case ${_status} in
35
		case ${_status} in
35
		FAULTED)
36
		FAULTED)
36
			rc=3
37
			rc=3
37
			echo "Skipping faulted pool: ${pool}"
38
			echo "   skipping faulted pool '${pool}'"
38
			continue ;;
39
			continue
40
			;;
39
		UNAVAIL)
41
		UNAVAIL)
40
			rc=4
42
			rc=4
41
			echo "Skipping unavailable pool: ${pool}"
43
			echo "   skipping unavailable pool '${pool}'"
42
			continue ;;
44
			continue
45
			;;
43
		esac
46
		esac
44
47
45
		if ! zpool status "${pool}" | grep -q '(trimming)'; then
48
		if zpool status ${pool} | grep -q "trimming"; then
46
			echo "    starting trim of pool '${pool}'"
49
			echo "   trimming of pool '${pool}' already in progress, skipping"
47
			zpool trim ${daily_zfs_trim_flags} "${pool}"
50
			echo "      consult 'zpool status -t ${pool}' for the result"
48
		else
51
			continue
49
			echo "    trim of pool '${pool}' already in progress, skipping"
52
		fi
53
54
		# determine how many days shall be between trimming
55
		eval _pool_threshold=\${daily_trim_zfs_$(echo "${pool}" | tr ".:-" "_")_threshold:-${daily_trim_zfs_default_threshold}}
56
57
		_last_trim=$(zpool history ${pool} | \
58
		    sed -Ene 's/^([0-9.:-]{19}) zpool trim .*$/\1/p' | tail -1)
59
		if [ -z "${_last_trim}" ]; then
60
			# creation time of the pool if no trim was done
61
			_last_trim=$(zpool history ${pool} | \
62
			    sed -Ene '2s/^([0-9.:-]{19}) .*$/\1/p')
63
		fi
64
		if [ -z "${_last_trim}" ]; then
65
			rc=2
66
			echo "   skipping trimming of pool '${pool}':"
67
			echo "      can't get last trimming date"
68
			continue
69
		fi
70
71
		# Now minus last trim (both in seconds) converted to days
72
		_trim_diff=$(expr -e \( $(date +%s) - \
73
		    $(date -j -v -70M -f %F.%T ${_last_trim} +%s) \) / 60 / 60 / 24)
74
		if [ ${_trim_diff} -lt ${_pool_threshold} ]; then
75
			echo "   skipping trimming of pool '${pool}':"
76
			echo "      last trimming is ${_trim_diff} days ago, threshold is set to ${_pool_threshold} days"
77
			continue
50
		fi
78
		fi
79
80
		# determine the rate at which the TRIM operation is performed
81
		eval _trim_rate=\${daily_trim_zfs_$(echo "${pool}" | tr ".:-" "_")_rate:-${daily_trim_zfs_default_rate}}
82
		if [ -n "${_trim_rate}" ]; then
83
			_trim_flags="-r ${_trim_rate}"
84
		fi
85
86
		_status="$(zpool status ${pool} | grep scan:)"
87
		case "${_status}" in
88
			*"scrub in progress"*)
89
				echo "   scrubbing of pool '${pool}' is in progress, skipping"
90
				;;
91
			*"resilver in progress"*)
92
				echo "   resilvering of pool '${pool}' is in progress, skipping"
93
				;;
94
			*)
95
				echo "   starting TRIM of pool '${pool}'"
96
				echo "      consult 'zpool status -t ${pool}' for the result"
97
				zpool trim ${_trim_flags} ${pool}
98
				[ $rc -eq 0 ] && rc=1
99
				;;
100
		esac
51
	done
101
	done
52
	;;
102
	;;
53
103
(-)b/usr.sbin/periodic/periodic.conf (+4 lines)
Lines 183-188 daily_scrub_zfs_default_threshold="35" # days between scrubs Link Here
183
daily_trim_zfs_enable="NO"
183
daily_trim_zfs_enable="NO"
184
daily_trim_zfs_pools=""				# empty string selects all pools
184
daily_trim_zfs_pools=""				# empty string selects all pools
185
daily_trim_zfs_flags=""				# zpool-trim(8) flags
185
daily_trim_zfs_flags=""				# zpool-trim(8) flags
186
daily_trim_zfs_default_threshold="14"		# days between trim
187
#daily_trim_zfs_${poolname}_threshold="14"	# pool specific threshold
188
daily_trim_zfs_default_rate=""			# trim rate
189
#daily_trim_zfs_${poolname}_rate=""		# pool specific rate
186
190
187
# 999.local
191
# 999.local
188
daily_local="/etc/daily.local"				# Local scripts
192
daily_local="/etc/daily.local"				# Local scripts

Return to bug 275965