repo: Make locking per-OstreeRepo

Previously each thread maintained its own lock file descriptor
regardless of whether the thread was using the same `OstreeRepo` as
another thread. This was very safe but it made certain multithreaded
procedures difficult. For example, if a main thread took an exclusive
lock and then spawned worker threads, it would deadlock if one of the
worker threads tried to acquire the lock.

This moves the file descriptor from thread local storage to the
`OstreeRepo` structure so that threads using the same `OstreeRepo` can
share the lock. A mutex guards against threads altering the lock state
concurrently.

Fixes: #2344
This commit is contained in:
Dan Nicholson committed 2021-06-05 09:15:32 -06:00
1 parent eb09207e1a
commit ccef9784d7
2 files changed
+68 -106

No files matched your search

+9
View File
@@ -104,6 +104,13 @@ typedef struct {
fsblkcnt_t max_blocks;
} OstreeRepoTxn;
typedef struct {
GMutex mutex; /* All other members should only be accessed with this held */
int fd; /* The open file or flock file descriptor */
guint shared; /* Number of shared locks curently held */
guint exclusive; /* Number of exclusive locks currently held */
} OstreeRepoLock;
typedef enum {
_OSTREE_FEATURE_NO,
_OSTREE_FEATURE_MAYBE,
@@ -159,6 +166,8 @@ struct OstreeRepo {
GWeakRef sysroot; /* Weak to avoid a circular ref; see also `is_system` */
char *remotes_config_dir;
OstreeRepoLock lock;
GMutex txn_lock;
OstreeRepoTxn txn;
gboolean txn_locked;