Skip to content

Commit 35ee337

Browse files
Cryptominer937 zfs patch 1 (#107)
* A few Fixes for ZFS Systems Fixed syntax error: invalid arithmetic operator (error token is ".3T 17" Line 570 so rewrote the ZFSCHECK Caused by having 7.3T Free Space Actual output "hddpool zfs 7.8T 514G 7.3T 7% /hddpool" Line 270 Added ZFS as a option so we can display Disk Space. Tested on Debian 12, Ubuntu 24.04, and Proxmox 8.4.1 * Update yabs.sh switch to awk from bc * Revert 270
1 parent 0958b7f commit 35ee337

File tree

1 file changed

+91
-46
lines changed

1 file changed

+91
-46
lines changed

yabs.sh

Lines changed: 91 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -534,53 +534,98 @@ elif [[ -z "$SKIP_FIO" && "$AVAIL_SPACE" -lt 524288 && ("$ARCH" = "aarch64" || "
534534
elif [ -z "$SKIP_FIO" ]; then
535535
# Perform ZFS filesystem detection and determine if we have enough free space according to spa_asize_inflation
536536
ZFSCHECK="/sys/module/zfs/parameters/spa_asize_inflation"
537-
if [[ -f "$ZFSCHECK" ]];then
538-
mul_spa=$(( $(cat /sys/module/zfs/parameters/spa_asize_inflation) * 2 ))
539-
warning=0
540-
poss=()
541-
542-
for pathls in $(df -Th | awk '{print $7}' | tail -n +2)
543-
do
544-
if [[ "${PWD##"$pathls"}" != "$PWD" ]]; then
545-
poss+=("$pathls")
546-
fi
547-
done
548-
549-
long=""
550-
m=-1
551-
for x in "${poss[@]}"
552-
do
553-
if [ "${#x}" -gt "$m" ];then
554-
m=${#x}
555-
long=$x
556-
fi
557-
done
558-
559-
size_b=$(df -Th | grep -w "$long" | grep -i zfs | awk '{print $5}' | tail -c -2 | head -c 1)
560-
free_space=$(df -Th | grep -w "$long" | grep -i zfs | awk '{print $5}' | head -c -2)
561-
562-
if [[ $size_b == 'T' ]]; then
563-
free_space=$(awk "BEGIN {print int($free_space * 1024)}")
564-
size_b='G'
565-
fi
566-
567-
if [[ $(df -Th | grep -w "$long") == *"zfs"* ]];then
568-
569-
if [[ $size_b == 'G' ]]; then
570-
if ((free_space < mul_spa)); then
571-
warning=1
572-
fi
573-
else
574-
warning=1
575-
fi
576-
577-
fi
537+
if [[ -f "$ZFSCHECK" ]]; then
538+
# Calculate mul_spa, which is assumed to be an integer (e.g., 2 * 2 = 4)
539+
mul_spa=$(( $(cat /sys/module/zfs/parameters/spa_asize_inflation) * 2 ))
540+
warning=0
541+
poss=()
542+
543+
# Find relevant filesystem paths that are parent directories or the current directory itself
544+
for pathls in $(df -Th | awk '{print $7}' | tail -n +2)
545+
do
546+
# Check if PWD starts with (is a subdirectory of or same as) pathls
547+
if [[ "${PWD}" == "${pathls}"* ]]; then
548+
poss+=("$pathls")
549+
fi
550+
done
551+
552+
long=""
553+
m=-1 # Initialize max length to -1 to ensure the first valid path is picked
554+
# Select the longest matching path from the 'poss' array
555+
# This ensures we get the most specific mounted point for the current directory
556+
for x in "${poss[@]}"
557+
do
558+
if [ "${#x}" -gt "$m" ];then
559+
m=${#x}
560+
long=$x
561+
fi
562+
done
563+
564+
# Proceed only if a relevant ZFS path was found
565+
if [[ -n "$long" ]]; then
566+
# Get the 'Avail' space directly for the detected path and explicitly for ZFS type
567+
# The 'Avail' column is the 4th field in `df -Th` output
568+
# Example: '7.3T', '104G', '17G'
569+
avail_space_with_unit=$(df -Th | grep -w "$long" | awk '$2 == "zfs" {print $4; exit}')
570+
571+
# If a valid free space value was extracted
572+
if [[ -n "$avail_space_with_unit" ]]; then
573+
# Use awk to parse the numeric part and unit, then convert to Gigabytes (integer)
574+
# This handles units like T, G, M, K, or empty (assumed bytes) and rounds to nearest integer
575+
free_space_gb_int=$(echo "$avail_space_with_unit" | awk '
576+
{
577+
# Extract numeric part and unit
578+
numeric_part = $0;
579+
unit = "";
580+
# Use match to find the number and an optional unit at the end
581+
if (match($0, /([0-9.]+)([KMGTB]?)$/)) {
582+
numeric_part = substr($0, RSTART, RLENGTH - length(substr($0, RSTART + RLENGTH - 1, 1)));
583+
unit = substr($0, RSTART + RLENGTH - 1, 1);
584+
# If the last character was part of the number (e.g., "1.2"), unit should be empty
585+
if (unit ~ /[0-9.]/) {
586+
unit = "";
587+
}
588+
}
589+
590+
# Convert unit to uppercase for consistent logic
591+
unit = toupper(unit);
592+
593+
converted_value_gb = 0;
594+
if (unit == "T") {
595+
converted_value_gb = numeric_part * 1024;
596+
} else if (unit == "G") {
597+
converted_value_gb = numeric_part;
598+
} else if (unit == "M") {
599+
converted_value_gb = numeric_part / 1024;
600+
} else if (unit == "K") {
601+
converted_value_gb = numeric_part / (1024 * 1024);
602+
} else if (unit == "B" || unit == "") { # Assume bytes if unit is B or empty
603+
converted_value_gb = numeric_part / (1024 * 1024 * 1024);
604+
}
605+
606+
# Print rounded to nearest integer
607+
printf "%.0f\n", converted_value_gb;
608+
}')
609+
610+
# Now, perform the arithmetic comparison with the integer free_space_gb_int
611+
if ((free_space_gb_int < mul_spa)); then
612+
warning=1
613+
fi
614+
else
615+
# Handle case where avail_space_with_unit doesn't match expected format
616+
echo "Warning: Could not parse free space format for $long: '$avail_space_with_unit'"
617+
# Potentially set warning=1 here if unparseable space is critical
618+
fi
619+
else
620+
echo "Note: No relevant filesystem path detected for current directory ($PWD)."
621+
fi
622+
623+
# Display warning if conditions are met
624+
if [[ $warning -eq 1 ]];then
625+
echo -en "\nWarning! You are running YABS on a ZFS Filesystem and your disk space is too low for the fio test. Your test results will be inaccurate. You need at least $mul_spa GB free in order to complete this test accurately. For more information, please see https://github.com/masonr/yet-another-bench-script/issues/13\n"
626+
fi
627+
fi
578628

579-
if [[ $warning -eq 1 ]];then
580-
echo -en "\nWarning! You are running YABS on a ZFS Filesystem and your disk space is too low for the fio test. Your test results will be inaccurate. You need at least $mul_spa GB free in order to complete this test accurately. For more information, please see https://github.com/masonr/yet-another-bench-script/issues/13\n"
581-
fi
582-
fi
583-
584629
echo -en "\nPreparing system for disk tests..."
585630

586631
# create temp directory to store disk write/read test files

0 commit comments

Comments
 (0)