lib/prune: Take exclusive repository lock

Add exclusive repository locking to all the pruning entry points. This
ensures that objects and deltas will not be removed while another
process is writing to the repository.

Closes: #1343
Approved by: cgwalters
This commit is contained in:
Dan Nicholson 2017-10-06 11:04:22 +00:00 committed by Atomic Bot
parent 6d978893f1
commit df7f33e498
1 changed files with 25 additions and 0 deletions

View File

@ -23,6 +23,7 @@
#include "ostree-core-private.h" #include "ostree-core-private.h"
#include "ostree-repo-private.h" #include "ostree-repo-private.h"
#include "ostree-autocleanups.h"
#include "otutil.h" #include "otutil.h"
typedef struct { typedef struct {
@ -160,12 +161,20 @@ _ostree_repo_prune_tmp (OstreeRepo *self,
* Prune static deltas, if COMMIT is specified then delete static delta files only * Prune static deltas, if COMMIT is specified then delete static delta files only
* targeting that commit; otherwise any static delta of non existing commits are * targeting that commit; otherwise any static delta of non existing commits are
* deleted. * deleted.
*
* This function takes an exclusive lock on the @self repository.
*/ */
gboolean gboolean
ostree_repo_prune_static_deltas (OstreeRepo *self, const char *commit, ostree_repo_prune_static_deltas (OstreeRepo *self, const char *commit,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
g_autoptr(OstreeRepoAutoLock) lock =
ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_EXCLUSIVE, cancellable,
error);
if (!lock)
return FALSE;
g_autoptr(GPtrArray) deltas = NULL; g_autoptr(GPtrArray) deltas = NULL;
if (!ostree_repo_list_static_delta_names (self, &deltas, if (!ostree_repo_list_static_delta_names (self, &deltas,
cancellable, error)) cancellable, error))
@ -286,6 +295,8 @@ repo_prune_internal (OstreeRepo *self,
* Use the %OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE to just determine * Use the %OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE to just determine
* statistics on objects that would be deleted, without actually * statistics on objects that would be deleted, without actually
* deleting them. * deleting them.
*
* This function takes an exclusive lock on the @self repository.
*/ */
gboolean gboolean
ostree_repo_prune (OstreeRepo *self, ostree_repo_prune (OstreeRepo *self,
@ -297,6 +308,12 @@ ostree_repo_prune (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
g_autoptr(OstreeRepoAutoLock) lock =
ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_EXCLUSIVE, cancellable,
error);
if (!lock)
return FALSE;
g_autoptr(GHashTable) objects = NULL; g_autoptr(GHashTable) objects = NULL;
gboolean refs_only = flags & OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY; gboolean refs_only = flags & OSTREE_REPO_PRUNE_FLAGS_REFS_ONLY;
@ -391,6 +408,8 @@ ostree_repo_prune (OstreeRepo *self,
* *
* The %OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE flag may be specified to just determine * The %OSTREE_REPO_PRUNE_FLAGS_NO_PRUNE flag may be specified to just determine
* statistics on objects that would be deleted, without actually deleting them. * statistics on objects that would be deleted, without actually deleting them.
*
* This function takes an exclusive lock on the @self repository.
*/ */
gboolean gboolean
ostree_repo_prune_from_reachable (OstreeRepo *self, ostree_repo_prune_from_reachable (OstreeRepo *self,
@ -401,6 +420,12 @@ ostree_repo_prune_from_reachable (OstreeRepo *self,
GCancellable *cancellable, GCancellable *cancellable,
GError **error) GError **error)
{ {
g_autoptr(OstreeRepoAutoLock) lock =
ostree_repo_auto_lock_push (self, OSTREE_REPO_LOCK_EXCLUSIVE, cancellable,
error);
if (!lock)
return FALSE;
g_autoptr(GHashTable) objects = NULL; g_autoptr(GHashTable) objects = NULL;
if (!ostree_repo_list_objects (self, OSTREE_REPO_LIST_OBJECTS_ALL | OSTREE_REPO_LIST_OBJECTS_NO_PARENTS, if (!ostree_repo_list_objects (self, OSTREE_REPO_LIST_OBJECTS_ALL | OSTREE_REPO_LIST_OBJECTS_NO_PARENTS,