diff options
author | Matthew Heon <matthew.heon@pm.me> | 2019-05-06 13:44:01 -0400 |
---|---|---|
committer | Matthew Heon <matthew.heon@pm.me> | 2019-05-06 14:17:54 -0400 |
commit | faae3a7065980a735ad60ab5f6d9e8421296dbf5 (patch) | |
tree | ca4e9dcdaaf1684fa446b3d4a48f686d1b86333a /libpod/lock/shm/shm_lock.go | |
parent | ff260f07e2be55c7fbda24b8727686fc55c650a6 (diff) | |
download | podman-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/shm/shm_lock.go')
-rw-r--r-- | libpod/lock/shm/shm_lock.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/libpod/lock/shm/shm_lock.go b/libpod/lock/shm/shm_lock.go index e70ea8743..c21e9a221 100644 --- a/libpod/lock/shm/shm_lock.go +++ b/libpod/lock/shm/shm_lock.go @@ -134,6 +134,23 @@ func (locks *SHMLocks) AllocateSemaphore() (uint32, error) { return uint32(retCode), nil } +// AllocateGivenSemaphore allocates the given semaphore from the shared-memory +// segment for use by a container or pod. +// If the semaphore is already in use or the index is invalid an error will be +// returned. +func (locks *SHMLocks) AllocateGivenSemaphore(sem uint32) error { + if !locks.valid { + return errors.Wrapf(syscall.EINVAL, "locks have already been closed") + } + + retCode := C.allocate_given_semaphore(locks.lockStruct, C.uint32_t(sem)) + if retCode < 0 { + return syscall.Errno(-1 * retCode) + } + + return nil +} + // DeallocateSemaphore frees a semaphore in a shared-memory segment so it can be // reallocated to another container or pod. // The given semaphore must be already allocated, or an error will be returned. |