From d686056254294fcabff472e71ebe486ec82e070e Mon Sep 17 00:00:00 2001 From: Umang Jain Date: Wed, 27 Jun 2018 02:40:15 +0530 Subject: [PATCH] lib/repo: Cleanup current boot's staging dir min-free-space-* checks are hit min-free-space-* act as a gating condition whether to we want hold onto caches in repo/tmp. If it is found that the free-disk space is going below this threshold, we flag it as an error and cleanup current boot's staging directory. Closes: #1602 Approved by: jlebon --- src/libostree/ostree-repo-commit.c | 9 +++++++-- src/libostree/ostree-repo-private.h | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libostree/ostree-repo-commit.c b/src/libostree/ostree-repo-commit.c index ce2f4deb..a3a6df44 100644 --- a/src/libostree/ostree-repo-commit.c +++ b/src/libostree/ostree-repo-commit.c @@ -522,6 +522,7 @@ _ostree_repo_bare_content_commit (OstreeRepo *self, const fsblkcnt_t object_blocks = (st_buf.st_size / self->txn.blocksize) + 1; if (object_blocks > self->txn.max_blocks) { + self->cleanup_stagedir = TRUE; g_mutex_unlock (&self->txn_lock); g_autofree char *formatted_required = g_format_size (st_buf.st_size); if (self->min_free_space_percent > 0) @@ -924,6 +925,7 @@ write_content_object (OstreeRepo *self, if (object_blocks > self->txn.max_blocks) { guint64 bytes_required = (guint64)object_blocks * self->txn.blocksize; + self->cleanup_stagedir = TRUE; g_mutex_unlock (&self->txn_lock); g_autofree char *formatted_required = g_format_size (bytes_required); if (self->min_free_space_percent > 0) @@ -1623,6 +1625,7 @@ ostree_repo_prepare_transaction (OstreeRepo *self, return FALSE; self->in_transaction = TRUE; + self->cleanup_stagedir = FALSE; if (self->min_free_space_percent >= 0 || self->min_free_space_mb >= 0) { struct statvfs stvfsbuf; @@ -1638,6 +1641,7 @@ ostree_repo_prepare_transaction (OstreeRepo *self, else { guint64 bytes_required = bfree * self->txn.blocksize; + self->cleanup_stagedir = TRUE; g_mutex_unlock (&self->txn_lock); g_autofree char *formatted_free = g_format_size (bytes_required); if (self->min_free_space_percent > 0) @@ -1783,9 +1787,10 @@ cleanup_txn_dir (OstreeRepo *self, /* If however this is the staging directory for the *current* * boot, then don't delete it now - we may end up reusing it, as - * is the point. + * is the point. Delete *only if* we have hit min-free-space* checks + * as we don't want to hold onto caches in that case. */ - if (g_str_has_prefix (path, self->stagedir_prefix)) + if (g_str_has_prefix (path, self->stagedir_prefix) && !self->cleanup_stagedir) return TRUE; /* Note early return */ /* But, crucially we can now clean up staging directories diff --git a/src/libostree/ostree-repo-private.h b/src/libostree/ostree-repo-private.h index 69f53921..0a447634 100644 --- a/src/libostree/ostree-repo-private.h +++ b/src/libostree/ostree-repo-private.h @@ -152,6 +152,7 @@ struct OstreeRepo { gid_t target_owner_gid; guint min_free_space_percent; /* See the min-free-space-percent config option */ guint64 min_free_space_mb; /* See the min-free-space-size config option */ + gboolean cleanup_stagedir; guint test_error_flags; /* OstreeRepoTestErrorFlags */