summaryrefslogtreecommitdiff
path: root/libpod/lock/shm_lock_manager_linux.go
diff options
context:
space:
mode:
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.