Modify detect match to 3%

This will handle corner cases of RAID devices that are a little smaller
than expected (300GB -> 293GB), which were a little outside the 2%
range, while still being close enough.
This commit is contained in:
Joshua Boniface 2023-09-01 15:41:59 -04:00
parent 98337295b1
commit 0d32e27ea9
1 changed files with 8 additions and 10 deletions

View File

@ -228,17 +228,15 @@ seed_config() {
IFS=: read detect b_name b_size b_id <<<"${target_disk}" IFS=: read detect b_name b_size b_id <<<"${target_disk}"
# Get the lsscsi output (exclude NVMe) # Get the lsscsi output (exclude NVMe)
lsscsi_data_all="$( lsscsi -s -N )" lsscsi_data_all="$( lsscsi -s -N )"
# Get the available sizes, and match to within +/- 2% # Get the available sizes, and match to within +/- 3%
lsscsi_sizes=( $( awk '{ print $NF }' <<<"${lsscsi_data_all}" | sort | uniq ) ) lsscsi_sizes=( $( awk '{ print $NF }' <<<"${lsscsi_data_all}" | sort | uniq ) )
# For each size... # For each size...
for size in ${lsscsi_sizes[@]}; do for size in ${lsscsi_sizes[@]}; do
# Get whether we match +2% and -2% sizes to handle human -> real deltas # Get whether we match +3% and -3% sizes to handle human -> real deltas
# The break below is pretty safe. I can think of no two classes of disks # The break below is pretty safe. I can think of no two classes of disks
# where the difference is within 2% of each other. Even the common # where the difference is within 3% of each other. Even the common
# 120GB -> 128GB and 240GB -> 256GB size deltas are well outside of 2%, # 120GB -> 128GB and 240GB -> 256GB size deltas are well outside of 3%,
# so this should be safe in all cases. 1% would be narrower but has more # so this should be safe in all cases.
# chance of mis-identifying due to rounding, while 3% gets into more
# contentious differences, so 2% seems like the best option.
# We use Python for this due to BASH's problematic handling of floating- # We use Python for this due to BASH's problematic handling of floating-
# point numbers. # point numbers.
is_match="$( is_match="$(
@ -249,9 +247,9 @@ try:
t_size = float(sub(r'\D.','','${size}')) t_size = float(sub(r'\D.','','${size}'))
except ValueError: except ValueError:
exit(0) exit(0)
plustwopct = t_size * 1.02 plusthreepct = t_size * 1.03
minustwopct = t_size * 0.98 minusthreepct = t_size * 0.97
if b_size > minustwopct and b_size < plustwopct: if b_size > minusthreepct and b_size < plusthreepct:
print("match") print("match")
EOF EOF
)" )"