summaryrefslogtreecommitdiff
path: root/libpod/lock/shm_lock_manager_linux.go
diff options
context:
space:
mode:
authorMatthew Heon <matthew.heon@gmail.com>2018-08-10 13:46:07 -0400
committerMatthew Heon <matthew.heon@pm.me>2019-01-04 09:51:09 -0500
commite73484c176839b2f2adf3d07cc09222a7b75bf69 (patch)
treeca5226c7c3247901bb3732e207fdc929e3432343 /libpod/lock/shm_lock_manager_linux.go
parentf38fccb48c9acc2b7d55c1746c9e6dbde492cff5 (diff)
downloadpodman-e73484c176839b2f2adf3d07cc09222a7b75bf69.tar.gz
podman-e73484c176839b2f2adf3d07cc09222a7b75bf69.tar.bz2
podman-e73484c176839b2f2adf3d07cc09222a7b75bf69.zip
Move to POSIX mutexes for SHM locks
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Diffstat (limited to 'libpod/lock/shm_lock_manager_linux.go')
-rw-r--r--libpod/lock/shm_lock_manager_linux.go42
1 files changed, 9 insertions, 33 deletions
diff --git a/libpod/lock/shm_lock_manager_linux.go b/libpod/lock/shm_lock_manager_linux.go
index b1e9df12d..974431a13 100644
--- a/libpod/lock/shm_lock_manager_linux.go
+++ b/libpod/lock/shm_lock_manager_linux.go
@@ -3,13 +3,7 @@
package lock
import (
- "fmt"
- "math"
- "strconv"
- "syscall"
-
- "github.com/pkg/errors"
- "github.com/projectatomic/libpod/libpod/lock/shm"
+ "github.com/containers/libpod/libpod/lock/shm"
)
// SHMLockManager manages shared memory locks.
@@ -18,8 +12,8 @@ type SHMLockManager struct {
}
// NewSHMLockManager makes a new SHMLockManager with the given number of locks.
-func NewSHMLockManager(numLocks uint32) (Manager, error) {
- locks, err := shm.CreateSHMLock(numLocks)
+func NewSHMLockManager(path string, numLocks uint32) (Manager, error) {
+ locks, err := shm.CreateSHMLock(path, numLocks)
if err != nil {
return nil, err
}
@@ -32,8 +26,8 @@ func NewSHMLockManager(numLocks uint32) (Manager, error) {
// OpenSHMLockManager opens an existing SHMLockManager with the given number of
// locks.
-func OpenSHMLockManager(numLocks uint32) (Manager, error) {
- locks, err := shm.OpenSHMLock(numLocks)
+func OpenSHMLockManager(path string, numLocks uint32) (Manager, error) {
+ locks, err := shm.OpenSHMLock(path, numLocks)
if err != nil {
return nil, err
}
@@ -59,27 +53,9 @@ func (m *SHMLockManager) AllocateLock() (Locker, error) {
}
// RetrieveLock retrieves a lock from the manager given its ID.
-func (m *SHMLockManager) RetrieveLock(id string) (Locker, error) {
- intID, err := strconv.ParseInt(id, 16, 64)
- if err != nil {
- return nil, errors.Wrapf(err, "given ID %q is not a valid SHMLockManager ID - cannot be parsed as int", id)
- }
-
- if intID < 0 {
- return nil, errors.Wrapf(syscall.EINVAL, "given ID %q is not a valid SHMLockManager ID - must be positive", id)
- }
-
- if intID > math.MaxUint32 {
- return nil, errors.Wrapf(syscall.EINVAL, "given ID %q is not a valid SHMLockManager ID - too large", id)
- }
-
- var u32ID uint32 = uint32(intID)
- if u32ID >= m.locks.GetMaxLocks() {
- return nil, errors.Wrapf(syscall.EINVAL, "given ID %q is not a valid SHMLockManager ID - too large to fit", id)
- }
-
+func (m *SHMLockManager) RetrieveLock(id uint32) (Locker, error) {
lock := new(SHMLock)
- lock.lockID = u32ID
+ lock.lockID = id
lock.manager = m
return lock, nil
@@ -92,8 +68,8 @@ type SHMLock struct {
}
// ID returns the ID of the lock.
-func (l *SHMLock) ID() string {
- return fmt.Sprintf("%x", l.lockID)
+func (l *SHMLock) ID() uint32 {
+ return l.lockID
}
// Lock acquires the lock.