lib/repo: Cleanup current boot's staging dir min-free-space-* checks are hit
authorUmang Jain <umang@endlessm.com>
Tue, 26 Jun 2018 21:10:15 +0000 (02:40 +0530)
committerAtomic Bot <atomic-devel@projectatomic.io>
Wed, 27 Jun 2018 19:02:02 +0000 (19:02 +0000)
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
src/libostree/ostree-repo-private.h

index ce2f4deb56966b2424b2946a1fbad9f13db11bf6..a3a6df44222c2a2d7ea723eddd5a535610aed36e 100644 (file)
@@ -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
index 69f539216d4c2b0dac42c0a66a8c79a0534e923e..0a44763472189b52d79f81186a61a568c9412c21 100644 (file)
@@ -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 */