lib/commit: Add repository locking during transactions
Take a shared repo lock during a transaction to ensure that another process doesn't delete objects. Closes: #1343 Approved by: cgwalters
This commit is contained in:
parent
7d863ed9e4
commit
6d978893f1
|
|
@ -1304,6 +1304,8 @@ ostree_repo_scan_hardlinks (OstreeRepo *self,
|
||||||
*
|
*
|
||||||
* Multithreading: This function is *not* MT safe; only one transaction can be
|
* Multithreading: This function is *not* MT safe; only one transaction can be
|
||||||
* active at a time.
|
* active at a time.
|
||||||
|
*
|
||||||
|
* This function takes a shared lock on the @self repository.
|
||||||
*/
|
*/
|
||||||
gboolean
|
gboolean
|
||||||
ostree_repo_prepare_transaction (OstreeRepo *self,
|
ostree_repo_prepare_transaction (OstreeRepo *self,
|
||||||
|
|
@ -1316,6 +1318,11 @@ ostree_repo_prepare_transaction (OstreeRepo *self,
|
||||||
|
|
||||||
memset (&self->txn.stats, 0, sizeof (OstreeRepoTransactionStats));
|
memset (&self->txn.stats, 0, sizeof (OstreeRepoTransactionStats));
|
||||||
|
|
||||||
|
self->txn_locked = ostree_repo_lock_push (self, OSTREE_REPO_LOCK_SHARED,
|
||||||
|
cancellable, error);
|
||||||
|
if (!self->txn_locked)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
self->in_transaction = TRUE;
|
self->in_transaction = TRUE;
|
||||||
if (self->min_free_space_percent > 0)
|
if (self->min_free_space_percent > 0)
|
||||||
{
|
{
|
||||||
|
|
@ -1836,6 +1843,13 @@ ostree_repo_commit_transaction (OstreeRepo *self,
|
||||||
if (!ot_ensure_unlinked_at (self->repo_dir_fd, "transaction", 0))
|
if (!ot_ensure_unlinked_at (self->repo_dir_fd, "transaction", 0))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
if (self->txn_locked)
|
||||||
|
{
|
||||||
|
if (!ostree_repo_lock_pop (self, cancellable, error))
|
||||||
|
return FALSE;
|
||||||
|
self->txn_locked = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
if (out_stats)
|
if (out_stats)
|
||||||
*out_stats = self->txn.stats;
|
*out_stats = self->txn.stats;
|
||||||
|
|
||||||
|
|
@ -1876,6 +1890,13 @@ ostree_repo_abort_transaction (OstreeRepo *self,
|
||||||
|
|
||||||
self->in_transaction = FALSE;
|
self->in_transaction = FALSE;
|
||||||
|
|
||||||
|
if (self->txn_locked)
|
||||||
|
{
|
||||||
|
if (!ostree_repo_lock_pop (self, cancellable, error))
|
||||||
|
return FALSE;
|
||||||
|
self->txn_locked = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -122,6 +122,7 @@ struct OstreeRepo {
|
||||||
|
|
||||||
GMutex txn_lock;
|
GMutex txn_lock;
|
||||||
OstreeRepoTxn txn;
|
OstreeRepoTxn txn;
|
||||||
|
gboolean txn_locked;
|
||||||
|
|
||||||
GMutex cache_lock;
|
GMutex cache_lock;
|
||||||
guint dirmeta_cache_refcount;
|
guint dirmeta_cache_refcount;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue