From a861690d882b3f24b95e172956ae36fedece7737 Mon Sep 17 00:00:00 2001 From: "Christian S.J. Peron" Date: Thu, 8 Oct 2026 21:59:22 -0500 Subject: [PATCH] Change how we calculate the size of the image Instead of using actual allocated blocks use `logicalreferenced` for ZFS which gives us what we need. The issue is tha ZFS writes are async so when we go to check block allocation the images are still being written. Also compression can impact this block allocation too. --- src/shell/stage_commit.sh | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/shell/stage_commit.sh b/src/shell/stage_commit.sh index 1ebf87c..647c533 100644 --- a/src/shell/stage_commit.sh +++ b/src/shell/stage_commit.sh @@ -105,8 +105,21 @@ commit_image() lockf -k "${data_dir}/images/${image_name}.lock" \ tar -C "${src}" --no-xattrs -b 32 -cf - . | \ tar -b 32 -xpf - -C "${data_dir}/images/${image_name}.${instance}" - du -sk "${dest}" | awk '{ printf "%d bytes transferred\n", $1 * 1024 }' \ - > "${dest}/TOTALS" + # + # ZFS does not account for newly written blocks until the transaction + # group is synced, so sync the pool before asking for the logical + # (uncompressed) size of the image. + # + case $CBLOCK_FS in + zfs) + zpool sync "${nvol%%/*}" + bytes=$(zfs get -Hp -o value logicalreferenced "${nvol}") + ;; + ufs) + bytes=$(du -sk "${dest}" | awk '{ printf "%d", $1 * 1024 }') + ;; + esac + printf "%d bytes transferred\n" "${bytes}" > "${dest}/TOTALS" # NB: we need to do this atomically # if [ -h "${data_dir}/images/${image_name}:${build_tag}" ]; then