Skip to content

Commit

Permalink
lib/repo: Do free space math under lock in error path
Browse files Browse the repository at this point in the history
We were referencing the txn bits outside of the lock in the error
path. Generally shouldn't matter, but e.g. Rust wouldn't let us do this, and
race detector tooling will warn about it.

Closes: #1632
Approved by: jlebon
  • Loading branch information
cgwalters authored and rh-atomic-bot committed Jun 19, 2018
1 parent acab2c1 commit 5e9d382
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/libostree/ostree-repo-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,8 +896,9 @@ write_content_object (OstreeRepo *self,
const fsblkcnt_t object_blocks = (size / self->txn.blocksize) + 1;
if (object_blocks > self->txn.max_blocks)
{
guint64 bytes_required = (guint64)object_blocks * self->txn.blocksize;
g_mutex_unlock (&self->txn_lock);
g_autofree char *formatted_required = g_format_size ((guint64)object_blocks * self->txn.blocksize);
g_autofree char *formatted_required = g_format_size (bytes_required);
if (self->min_free_space_percent > 0)
return glnx_throw (error, "min-free-space-percent '%u%%' would be exceeded, %s more required",
self->min_free_space_percent, formatted_required);
Expand Down Expand Up @@ -1609,8 +1610,9 @@ ostree_repo_prepare_transaction (OstreeRepo *self,
self->txn.max_blocks = bfree - reserved_blocks;
else
{
guint64 bytes_required = bfree * self->txn.blocksize;
g_mutex_unlock (&self->txn_lock);
g_autofree char *formatted_free = g_format_size (bfree * self->txn.blocksize);
g_autofree char *formatted_free = g_format_size (bytes_required);
if (self->min_free_space_percent > 0)
return glnx_throw (error, "min-free-space-percent '%u%%' would be exceeded, %s available",
self->min_free_space_percent, formatted_free);
Expand Down

0 comments on commit 5e9d382

Please sign in to comment.