lib/commit: Fix min-free-space accounting for duplicate content objects
authorJonathan Lebon <jlebon@redhat.com>
Thu, 23 Jul 2026 02:09:15 +0000 (22:09 -0400)
committerJonathan Lebon <jonathan@jlebon.com>
Thu, 23 Jul 2026 15:54:39 +0000 (11:54 -0400)
commit16e537cb8a9b69d8f254dfbf4abf4f0358251f56
tree9ce61bb2763228a050553176e9377200126f198b
parent974b5184cbd4b83e0423452acbb61b86d19ee160
lib/commit: Fix min-free-space accounting for duplicate content objects

First, in the _ostree_repo_bare_content_commit(), we never actually
checked whether the file was already present in the repo before linking
it in place. Do this so that we can no-op up front.

Second, and the actual bug this patch is fixing: the min-free-space
accounting in write_content_object() and
_ostree_repo_bare_content_commit() optimistically reserves space from
the running `txn.max_blocks` counter _before_ knowing whether we'll
actually no-op or not based on the object already existing.

Over many duplicate writes within a single transaction, the counter
diverges from the actual free space and eventually hits zero, causing a
spurious "min-free-space would be exceeded" error even with plenty of
disk space available.

This may be the source of the CI issue FCOS is hitting in
https://github.com/coreos/fedora-coreos-config/pull/4265 due to the
bootc SELinux relabeling done since
https://github.com/bootc-dev/bootc/pull/2088.

This patch saves the number of blocks reserved and credits them back in
both code paths when a duplicate object is detected.

This was heavily AI-guided, finding the bug, and then doing red-green
testing towards the fix.

Assisted-by: AI
src/libostree/ostree-repo-commit.c
tests/test-repo.c