From 220c4b136a64d5745537fcba6d736e13363e7944 Mon Sep 17 00:00:00 2001 From: Adi Date: Thu, 9 Jan 2025 16:26:37 +0000 Subject: [PATCH 1/2] 2x speed increase by using cmp instead of crc32 --- zfs-inplace-rebalancing.sh | 41 +++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/zfs-inplace-rebalancing.sh b/zfs-inplace-rebalancing.sh index 9c280df..b4d18c7 100755 --- a/zfs-inplace-rebalancing.sh +++ b/zfs-inplace-rebalancing.sh @@ -137,25 +137,19 @@ function rebalance() { # Linux # file attributes - original_checksum=$(lsattr "${file_path}") + original_perms=$(lsattr "${file_path}") # remove anything after the last space - original_checksum=${original_checksum% *} + original_perms=${original_perms% *} # file permissions, owner, group, size, modification time - original_checksum="${original_checksum} $(stat -c "%A %U %G %s %Y" "${file_path}")" - # file content - original_checksum="${original_checksum} $(cksum "${file_path}")" + original_perms="${original_perms} $(stat -c "%A %U %G %s %Y" "${file_path}")" # file attributes - copy_checksum=$(lsattr "${tmp_file_path}") + copy_perms=$(lsattr "${tmp_file_path}") # remove anything after the last space - copy_checksum=${copy_checksum% *} + copy_perms=${copy_perms% *} # file permissions, owner, group, size, modification time - copy_checksum="${copy_checksum} $(stat -c "%A %U %G %s %Y" "${tmp_file_path}")" - # file content - copy_checksum="${copy_checksum} $(cksum "${file_path}")" - # remove the temporary extension - copy_checksum=${copy_checksum%"${tmp_extension}"} + copy_perms="${copy_perms} $(stat -c "%A %U %G %s %Y" "${tmp_file_path}")" elif [[ "${OSName}" == "darwin"* ]] || [[ "${OSName}" == "freebsd"* ]]; then # Mac OS # FreeBSD @@ -163,25 +157,26 @@ function rebalance() { # note: no lsattr on Mac OS or FreeBSD # file permissions, owner, group size, modification time - original_checksum="$(stat -f "%Sp %Su %Sg %z %m" "${file_path}")" - # file content - original_checksum="${original_checksum} $(cksum "${file_path}")" + original_perms="$(stat -f "%Sp %Su %Sg %z %m" "${file_path}")" # file permissions, owner, group size, modification time - copy_checksum="$(stat -f "%Sp %Su %Sg %z %m" "${tmp_file_path}")" - # file content - copy_checksum="${copy_checksum} $(cksum "${file_path}")" - # remove the temporary extension - copy_checksum=${copy_checksum%"${tmp_extension}"} + copy_perms="$(stat -f "%Sp %Su %Sg %z %m" "${tmp_file_path}")" else echo "Unsupported OS type: $OSTYPE" exit 1 fi - if [[ "${original_checksum}" == "${copy_checksum}"* ]]; then - color_echo "${Green}" "Checksum OK" + if [[ "${original_perms}" == "${copy_perms}"* ]] && cmp -s "${file_path}" "${tmp_file_path}"; then + color_echo "${Green}" "Attribute and permission check OK" else - color_echo "${Red}" "Checksum FAILED: ${original_checksum} != ${copy_checksum}" + color_echo "${Red}" "Attribute and permission check FAILED: ${original_perms} != ${copy_perms}" + exit 1 + fi + + if cmp -s "${file_path}" "${tmp_file_path}"; then + color_echo "${Green}" "File content check OK" + else + color_echo "${Red}" "File content check FAILED" exit 1 fi fi From ceece0fedcdd52c8f3541b60c129053d96f82924 Mon Sep 17 00:00:00 2001 From: Adi Date: Sat, 18 Jan 2025 00:03:48 +0000 Subject: [PATCH 2/2] Remove redundant cmp check --- zfs-inplace-rebalancing.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zfs-inplace-rebalancing.sh b/zfs-inplace-rebalancing.sh index b4d18c7..43ae85d 100755 --- a/zfs-inplace-rebalancing.sh +++ b/zfs-inplace-rebalancing.sh @@ -166,7 +166,7 @@ function rebalance() { exit 1 fi - if [[ "${original_perms}" == "${copy_perms}"* ]] && cmp -s "${file_path}" "${tmp_file_path}"; then + if [[ "${original_perms}" == "${copy_perms}"* ]]; then color_echo "${Green}" "Attribute and permission check OK" else color_echo "${Red}" "Attribute and permission check FAILED: ${original_perms} != ${copy_perms}"