Skip to content

Commit

Permalink
repo: Make locking APIs public
Browse files Browse the repository at this point in the history
Doing anything even somewhat sophisticated requires this;
turns out our own `ostree prune` CLI wants this, e.g.
ostreedev#2337

Closes: ostreedev#2286
  • Loading branch information
cgwalters committed Apr 15, 2021
1 parent 36693f0 commit 24ca5ef
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 29 deletions.
2 changes: 2 additions & 0 deletions apidoc/ostree-sections.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ ostree_repo_get_min_free_space_bytes
ostree_repo_get_config
ostree_repo_get_dfd
ostree_repo_get_default_repo_finders
ostree_repo_lock_pop
ostree_repo_lock_push
ostree_repo_hash
ostree_repo_equal
ostree_repo_copy_config
Expand Down
2 changes: 2 additions & 0 deletions src/libostree/libostree-devel.sym
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ global:
ostree_repo_write_regfile;
ostree_content_writer_get_type;
ostree_content_writer_finish;
ostree_repo_lock_push;
ostree_repo_lock_pop;
} LIBOSTREE_2021.1;

/* Stub section for the stable release *after* this development one; don't
Expand Down
8 changes: 4 additions & 4 deletions src/libostree/ostree-repo-commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1684,8 +1684,8 @@ ostree_repo_prepare_transaction (OstreeRepo *self,

memset (&self->txn.stats, 0, sizeof (OstreeRepoTransactionStats));

self->txn_locked = _ostree_repo_lock_push (self, OSTREE_REPO_LOCK_SHARED,
cancellable, error);
self->txn_locked = ostree_repo_lock_push (self, OSTREE_REPO_LOCK_SHARED,
cancellable, error);
if (!self->txn_locked)
return FALSE;

Expand Down Expand Up @@ -2341,7 +2341,7 @@ ostree_repo_commit_transaction (OstreeRepo *self,

if (self->txn_locked)
{
if (!_ostree_repo_lock_pop (self, cancellable, error))
if (!ostree_repo_lock_pop (self, cancellable, error))
return FALSE;
self->txn_locked = FALSE;
}
Expand Down Expand Up @@ -2399,7 +2399,7 @@ ostree_repo_abort_transaction (OstreeRepo *self,

if (self->txn_locked)
{
if (!_ostree_repo_lock_pop (self, cancellable, error))
if (!ostree_repo_lock_pop (self, cancellable, error))
return FALSE;
self->txn_locked = FALSE;
}
Expand Down
16 changes: 0 additions & 16 deletions src/libostree/ostree-repo-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,22 +506,6 @@ _ostree_repo_maybe_regenerate_summary (OstreeRepo *self,
GCancellable *cancellable,
GError **error);

/* Locking APIs are currently private.
* See https://github.com/ostreedev/ostree/pull/1555
*/
typedef enum {
OSTREE_REPO_LOCK_SHARED,
OSTREE_REPO_LOCK_EXCLUSIVE
} OstreeRepoLockType;

gboolean _ostree_repo_lock_push (OstreeRepo *self,
OstreeRepoLockType lock_type,
GCancellable *cancellable,
GError **error);
gboolean _ostree_repo_lock_pop (OstreeRepo *self,
GCancellable *cancellable,
GError **error);

typedef OstreeRepo OstreeRepoAutoLock;

OstreeRepoAutoLock * _ostree_repo_auto_lock_push (OstreeRepo *self,
Expand Down
20 changes: 11 additions & 9 deletions src/libostree/ostree-repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ pop_repo_lock (OstreeRepo *self,
return TRUE;
}

/*
/**
* ostree_repo_lock_push:
* @self: a #OstreeRepo
* @lock_type: the type of lock to acquire
Expand All @@ -470,9 +470,10 @@ pop_repo_lock (OstreeRepo *self,
* %TRUE is returned.
*
* Returns: %TRUE on success, otherwise %FALSE with @error set
* Since: 2021.2
*/
gboolean
_ostree_repo_lock_push (OstreeRepo *self,
ostree_repo_lock_push (OstreeRepo *self,
OstreeRepoLockType lock_type,
GCancellable *cancellable,
GError **error)
Expand Down Expand Up @@ -538,8 +539,8 @@ _ostree_repo_lock_push (OstreeRepo *self,
}
}

/*
* _ostree_repo_lock_pop:
/**
* ostree_repo_lock_pop:
* @self: a #OstreeRepo
* @cancellable: a #GCancellable
* @error: a #GError
Expand All @@ -560,11 +561,12 @@ _ostree_repo_lock_push (OstreeRepo *self,
* %TRUE is returned.
*
* Returns: %TRUE on success, otherwise %FALSE with @error set
* Since: 2021.2
*/
gboolean
_ostree_repo_lock_pop (OstreeRepo *self,
GCancellable *cancellable,
GError **error)
ostree_repo_lock_pop (OstreeRepo *self,
GCancellable *cancellable,
GError **error)
{
g_return_val_if_fail (self != NULL, FALSE);
g_return_val_if_fail (OSTREE_IS_REPO (self), FALSE);
Expand Down Expand Up @@ -655,7 +657,7 @@ _ostree_repo_auto_lock_push (OstreeRepo *self,
GCancellable *cancellable,
GError **error)
{
if (!_ostree_repo_lock_push (self, lock_type, cancellable, error))
if (!ostree_repo_lock_push (self, lock_type, cancellable, error))
return NULL;
return (OstreeRepoAutoLock *)self;
}
Expand All @@ -677,7 +679,7 @@ _ostree_repo_auto_lock_cleanup (OstreeRepoAutoLock *lock)
g_autoptr(GError) error = NULL;
int errsv = errno;

if (!_ostree_repo_lock_pop (repo, NULL, &error))
if (!ostree_repo_lock_pop (repo, NULL, &error))
g_critical ("Cleanup repo lock failed: %s", error->message);

errno = errsv;
Expand Down
25 changes: 25 additions & 0 deletions src/libostree/ostree-repo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1498,6 +1498,31 @@ gboolean ostree_repo_regenerate_summary (OstreeRepo *self,
GCancellable *cancellable,
GError **error);


/**
* OstreeRepoLockType:
* @OSTREE_REPO_LOCK_SHARED: A "read only" lock; multiple readers are allowed.
* @OSTREE_REPO_LOCK_EXCLUSIVE: A writable lock at most one writer can be active, and zero readers.
*
* Flags controlling repository locking.
*
* Since: 2021.2
*/
typedef enum {
OSTREE_REPO_LOCK_SHARED,
OSTREE_REPO_LOCK_EXCLUSIVE
} OstreeRepoLockType;

_OSTREE_PUBLIC
gboolean ostree_repo_lock_push (OstreeRepo *self,
OstreeRepoLockType lock_type,
GCancellable *cancellable,
GError **error);
_OSTREE_PUBLIC
gboolean ostree_repo_lock_pop (OstreeRepo *self,
GCancellable *cancellable,
GError **error);

/**
* OSTREE_REPO_METADATA_REF:
*
Expand Down
8 changes: 8 additions & 0 deletions tests/test-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,12 @@ w.write(inline_content.slice(10), null)
let actual_checksum = w.finish(null)
assertEquals(actual_checksum, networks_checksum)

// Basic locking API sanity test
repo.lock_push(OSTree.RepoLockType.SHARED, null);
repo.lock_push(OSTree.RepoLockType.SHARED, null);
repo.lock_pop(null);
repo.lock_pop(null);
repo.lock_push(OSTree.RepoLockType.EXCLUSIVE, null);
repo.lock_pop(null);

print("ok test-core");

0 comments on commit 24ca5ef

Please sign in to comment.