Repository navigation
Expand file tree
/
Copy pathsadfscheck
More file actions
executable file
·336 lines (311 loc) · 10.9 KB
/
Copy pathsadfscheck
File metadata and controls
executable file
·336 lines (311 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#!/bin/sh -eu
# sadfscheck (part of ossobv/vcutil) // wdoekes/2021,2024-2025 // Public Domain
#
# Checks nvme and zfs configurations for suboptimal/non-osso configuration.
#
sector_list() {
local dev phys log
lsblk --tree -o NAME,PHY-SEC,LOG-SEC |
sed -e '1d;/^[^A-Za-z0-9]/d' |
while read dev phys log; do
if test "$log" = 4096 && test "$log" -gt "$phys"; then
# If logical is 4096 and the physical size is smaller, then ignore.
# This has no performance drawback.
:
elif test "$phys" != "$log"; then
echo "/dev/$dev: sector size mismatch:\
$log logical, $phys physical" >&2
fi
done
}
nvme_list() {
local devs
devs=$(nvme list 2>/dev/null | awk '/^\/dev\//{print $1}')
test -z "$devs" && echo "info: no nvme devices found" >&2
echo $devs
}
nvme_check_best_sector() {
local dev status=true
for dev in $(nvme_list); do
nvme id-ns "$dev" | parse_nvme_id_ns_best_lba "$dev" || status=false
done
$status
}
parse_nvme_id_ns_best_lba() {
local dev
dev=$1
# flbas : 0x1
# lbaf 0 : ms:0 lbads:9 rp:0x2
# lbaf 1 : ms:0 lbads:12 rp:0 (in use)
awk -v dev=$dev -F '[[:blank:]]*:[[:blank:]]*' '
# mawk does int("0x1") is 1, while gawk says it is 0.
function myint(s) {
if (s !~ /^0x/) { return int(s); }
sub(/^0[xX]/, "", s); s = tolower(s); v = 0
for (i = 1; i <= length(s); i++) {
c = index("0123456789abcdef", substr(s, i, 1)) - 1
if (c < 0) return -1 # bad digit
v = v * 16 + c
}
return v
}
BEGIN { inuse_lbaf = -1; idx = -1; inuse = -1; best = -1 }
$1 == "flbas" { inuse_lbaf = myint($2) % 16 }
/^lbaf[[:blank:]]/ {
lbaf = myint(substr($1, 5)); lbads = myint($4); prio = myint($5)
idx += 1; a_lbaf[idx] = lbaf; a_lbads[idx] = lbads
if (lbaf == inuse_lbaf) inuse = idx
# We want lbads to be 12+ (4096+) and then we take the first
# one with the lowest prio.
if (lbads >= 12 && (best == -1 || prio < lowest_prio || (\
prio == lowest_prio && inuse == idx))) {
best = idx; lowest_prio = prio
}
}
END {
ret = 1;
# printf("%s: inuse=%d (%d) best=%d (%s) lowest_prio=%d\n",
# dev, inuse, 2 ^ a_lbads[inuse], best, 2 ^ a_lbads[inuse],
# lowest_prio);
if (inuse == -1) {
printf "%s: could not determine current LBA format\n", dev;
} else if (inuse != best) {
printf "%s: does not have the best format/sector size\n", dev
} else if (a_lbads[inuse] < 12) {
printf "%s: has poor sector size\n", dev
} else {
ret = 0
}
exit ret
}
'
}
dev_sector_size() {
local dev="$1"
if ! test -b "$dev" && test -b /dev/disk/by-id/${dev#/dev/}; then
# Old ZFS 0.7.5 links to wrong device. Quick hack to fix.
dev=/dev/disk/by-id/${dev#/dev/}
fi
local dev="$(realpath "$dev")"
if test "${dev#/dev/nvme}" != "$dev"; then
local sector_size=$(nvme id-ns -H "$dev" | sed -e '
/^LBA Format/!d;/(in use)/!d
s/.*Data Size:[[:blank:]]*\([0-9]\+\)[[:blank:]]\+bytes.*/\1/')
test -z "$sector_size" && echo "error: No sector size for $1" >&2
echo $sector_size
else
local size=
local assume_4096=
smartctl -i "$dev" | while read -r line; do
case "$line" in
'Rotation Rate:'*)
# Rotation Rate: Solid State Device
test -z "$assume_4096" &&
test "${line%Solid State Device}" != "$line" &&
assume_4096=1 || assume_4096=0;;
'Sector Size:'*)
# Sector Size: 512 bytes logical/physical
size=${line#*:}; size=${size% bytes*}; size=$((size + 0));;
'Sector Sizes:'*)
# Sector Sizes: 512 bytes logical, 4096 bytes physical
size=${line#*: *logical, }; size=${size% bytes*}
assume_4096=0;;
'Logical block size:'*)
size=${line#*:}; size=${size% bytes*}; size=$((size + 0));;
'')
if test -n "$size"; then
if test ${assume_4096:-0} -eq 1; then
echo 4096 # not 512.. probably, maybe even 8192
else
echo $size
fi
break
fi
esac
done
fi
}
dev_sector_shift() {
local sector_size="$(dev_sector_size "$1")"
case $sector_size in
512)
echo 9
;;
4096)
echo 12
;;
8192)
echo 13
;;
*)
echo "unknown-${sector_size}-for-$1" >&2
echo 12
;;
esac
}
_zdb_output=
zdb_output() {
# zdb lists cached info. Sometimes pools are imported with
# cachefile=none or cachefile=/else/where. zdb will not list those.
# So, instead we use -eC to read their "non-imported" values.
# (And because this is slow (not cached), we cache the output for
# ourselves.)
# Note that the zdb -C output is just slightly different from the
# regular zdb output.
if test -z "$_zdb_output"; then
_zdb_output=$(\
zdb
eval $(zpool list -Honame,cachefile | sed -e '
/[[:blank:]]-$/d
s/^\([^[:blank:]]*\)[[:blank:]].*/zdb -eC \1;/')
)
fi
echo "$_zdb_output"
}
zpool_check_ashift() {
local output
output=$(zdb_output | while read line; do
local pool
local ashift
local path
local actual_ashift
case "$line" in
name:*)
pool=${line##* }; pool=${pool%\'}; pool=${pool#\'};;
ashift:*)
ashift=${line##* };;
path:*)
path=${line##* }; path=${path%\'}; path=${path#\'};;
features_for_read:)
local dev_ashift=$(dev_sector_shift $path)
if test $ashift -lt $dev_ashift; then
echo "$pool: ashift $ashift on zpool lower\
than disk ashift $dev_ashift"
elif test $ashift -lt 12; then
echo "$pool: unexpected ashift $ashift below 12"
fi
esac
done | uniq)
if test -n "$output"; then
printf '%s\n' "$output"
false
fi
}
zpool_check_autotrim() {
local output name autotrim
output=$(zpool list -Honame,autotrim | LC_ALL=C sort |
while read name autotrim; do
if test "$autotrim" != on; then
echo "$name: autotrim is not on (it is '$autotrim')" >&2
fi
done)
if test -n "$output"; then
printf '%s\n' "$output"
false
fi
}
zfs_check_compression() {
local output name compression
output=$(zpool list -Honame | LC_ALL=C sort | while read name; do
# We check the main pools only. Children filesystems can have different
# settings.
compression=$(zfs get -Hovalue compression "$name")
if test "$compression" != lz4 && test "$compression" != on; then
echo "$name: compression is not lz4 (it is '$compression')" >&2
fi
done)
if test -n "$output"; then
printf '%s\n' "$output"
false
fi
}
zfs_check_primarycache() {
local output name primarycache
output=$(zpool list -Honame | LC_ALL=C sort | while read name; do
# We check the main pools only. Children filesystems can have different
# settings.
primarycache=$(zfs get -Hovalue primarycache "$name")
if test "$primarycache" != all; then
echo "$name: primarycache is not all (it is '$primarycache')" >&2
fi
done)
if test -n "$output"; then
printf '%s\n' "$output"
false
fi
}
zpool_check_stripe() {
local output status=true pool type1= type2=
output=$(zdb_output | while read line; do
if test "${line#name:}" != "$line"; then
pool=${line##* }; pool=${pool%\'}; pool=${pool#\'}
type1=
type2=
elif test -z "$type1" && test "${line#type:}" != "$line"; then
type1=${line##* }; type1=${type1%\'}; type1=${type1#\'}
elif test -z "$type2" && test "${line#type:}" != "$line"; then
type2=${line##* }; type2=${type2%\'}; type2=${type2#\'}
if test "$type2" != "mirror" && test "$type2" != "raidz"; then
echo "$pool: unexpected non-mirror/non-raidz,\
striping/single intentional? (hardware raid?)"
fi
fi
done)
if test -n "$output"; then
printf '%s\n' "$output"
status=false
fi
local zdb_names zpool_names
zdb_names=$(zdb_output | sed -ne "s/^[[:blank:]]\+name: '\([^']*\)'/\1/p" |
LC_ALL=C sort) # '") vimsynfix
zpool_names=$(zpool list -Honame | LC_ALL=C sort)
if test "$zdb_names" != "$zpool_names"; then
echo "error: did not get info about all zpools ("$zdb_names"\
<> "$zpool_names")" >&2
status=false
fi
$status
}
zfs_check_arc() {
local status=true
local module_arc_min=$(sed -e \
'/^options zfs .*zfs_arc_min=/!d;s/.*zfs_arc_min=//;s/[^0-9].*//' \
/etc/modprobe.d/*.conf); module_arc_min=${module_arc_min:-0}
local module_arc_max=$(sed -e \
'/^options zfs .*zfs_arc_max=/!d;s/.*zfs_arc_max=//;s/[^0-9].*//' \
/etc/modprobe.d/*.conf); module_arc_max=${module_arc_max:-0}
local param_arc_min=$(cat /sys/module/zfs/parameters/zfs_arc_min)
local param_arc_max=$(cat /sys/module/zfs/parameters/zfs_arc_max)
local current_arc=$(awk '/^size/{print $3}' /proc/spl/kstat/zfs/arcstats)
test "$module_arc_min" -ne "$param_arc_min" &&
echo "zfs-kernel-module: running arc min ($param_arc_min) unequal\
to modprobe config ($module_arc_min)"
test "$module_arc_max" -ne "$param_arc_max" &&
echo "zfs-kernel-module: running arc min ($param_arc_max) unequal\
to modprobe config ($module_arc_max)"
local memory=$(free -m | awk '/^Mem:/{print $2}')
local maxpct=$(awk -v mem=$memory -v max=$module_arc_max \
'BEGIN{print int((max/1024/1024*100)/mem+0.5);exit}')
# Allow the current_arc to overflow max by 128MiB.
if test $((current_arc - 128*1024*1024)) -gt $module_arc_max; then
echo "zfs-kernel-module: current arc size ($current_arc)\
not below modprobe config ($module_arc_max)"
status=false
fi
if test $maxpct -lt 3 || test $maxpct -gt 85; then
echo "zfs-kernel-module: arc max modprobe config out of normal bounds\
($maxpct% is not between 3% and 85%)"
status=false
fi
$status
}
FAILS=0
sector_list || FAILS=$((FAILS+1))
nvme_check_best_sector || FAILS=$((FAILS+1))
zpool_check_ashift || FAILS=$((FAILS+1))
zpool_check_autotrim || FAILS=$((FAILS+1))
zpool_check_stripe || FAILS=$((FAILS+1))
zfs_check_arc || FAILS=$((FAILS+1))
zfs_check_compression || FAILS=$((FAILS+1))
zfs_check_primarycache || FAILS=$((FAILS+1))
test $FAILS -eq 0 # exit code