summaryrefslogtreecommitdiff
path: root/libpod/lock/in_memory_locks.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@pm.me>2019-05-06 13:44:01 -0400
committerMatthew Heon <matthew.heon@pm.me>2019-05-06 14:17:54 -0400
commitfaae3a7065980a735ad60ab5f6d9e8421296dbf5 (patch)
treeca4e9dcdaaf1684fa446b3d4a48f686d1b86333a /libpod/lock/in_memory_locks.go
parentff260f07e2be55c7fbda24b8727686fc55c650a6 (diff)
downloadpodman-faae3a7065980a735ad60ab5f6d9e8421296dbf5.tar.gz
podman-faae3a7065980a735ad60ab5f6d9e8421296dbf5.tar.bz2
podman-faae3a7065980a735ad60ab5f6d9e8421296dbf5.zip
When refreshing after a reboot, force lock allocation
After a reboot, when we refresh Podman's state, we retrieved the lock from the fresh SHM instance, but we did not mark it as allocated to prevent it being handed out to other containers and pods. Provide a method for marking locks as in-use, and use it when we refresh Podman state after a reboot. Fixes #2900 Signed-off-by: Matthew Heon <matthew.heon@pm.me>
Diffstat (limited to 'libpod/lock/in_memory_locks.go')
-rw-r--r--libpod/lock/in_memory_locks.go16
1 files changed, 16 insertions, 0 deletions
diff --git a/libpod/lock/in_memory_locks.go b/libpod/lock/in_memory_locks.go
index 7c9605917..f3c842f89 100644
--- a/libpod/lock/in_memory_locks.go
+++ b/libpod/lock/in_memory_locks.go
@@ -90,6 +90,22 @@ func (m *InMemoryManager) RetrieveLock(id uint32) (Locker, error) {
return m.locks[id], nil
}
+// AllocateAndRetrieveLock allocates a lock with the given ID (if not already in
+// use) and returns it.
+func (m *InMemoryManager) AllocateAndRetrieveLock(id uint32) (Locker, error) {
+ if id >= m.numLocks {
+ return nil, errors.Errorf("given lock ID %d is too large - this manager only supports lock indexes up to %d", id, m.numLocks)
+ }
+
+ if m.locks[id].allocated {
+ return nil, errors.Errorf("given lock ID %d is already in use, cannot reallocate", id)
+ }
+
+ m.locks[id].allocated = true
+
+ return m.locks[id], nil
+}
+
// FreeAllLocks frees all locks.
// This function is DANGEROUS. Please read the full comment in locks.go before
// trying to use it.