summaryrefslogtreecommitdiff
path: root/libpod/lock
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/lock')
-rw-r--r--libpod/lock/shm/shm_lock.c (renamed from libpod/lock/shm_lock.c)0
-rw-r--r--libpod/lock/shm/shm_lock.go (renamed from libpod/lock/shm_lock.go)7
-rw-r--r--libpod/lock/shm/shm_lock.h (renamed from libpod/lock/shm_lock.h)0
-rw-r--r--libpod/lock/shm/shm_lock_test.go (renamed from libpod/lock/shm_lock_test.go)2
-rw-r--r--libpod/lock/shm_lock_manager_linux.go (renamed from libpod/lock/shm_lock_manager.go)21
-rw-r--r--libpod/lock/shm_lock_manager_unsupported.go29
6 files changed, 48 insertions, 11 deletions
diff --git a/libpod/lock/shm_lock.c b/libpod/lock/shm/shm_lock.c
index 3fe41f63c..3fe41f63c 100644
--- a/libpod/lock/shm_lock.c
+++ b/libpod/lock/shm/shm_lock.c
diff --git a/libpod/lock/shm_lock.go b/libpod/lock/shm/shm_lock.go
index a8a969479..ff9b0ce2c 100644
--- a/libpod/lock/shm_lock.go
+++ b/libpod/lock/shm/shm_lock.go
@@ -1,4 +1,4 @@
-package lock
+package shm
// #cgo LDFLAGS: -lrt -lpthread
// #include "shm_lock.h"
@@ -72,6 +72,11 @@ func OpenSHMLock(numLocks uint32) (*SHMLocks, error) {
return locks, nil
}
+// GetMaxLocks returns the maximum number of locks in the SHM
+func (locks *SHMLocks) GetMaxLocks() uint32 {
+ return locks.maxLocks
+}
+
// Close closes an existing shared-memory segment.
// The segment will be rendered unusable after closing.
// WARNING: If you Close() while there are still locks locked, these locks may
diff --git a/libpod/lock/shm_lock.h b/libpod/lock/shm/shm_lock.h
index 18bea47e9..18bea47e9 100644
--- a/libpod/lock/shm_lock.h
+++ b/libpod/lock/shm/shm_lock.h
diff --git a/libpod/lock/shm_lock_test.go b/libpod/lock/shm/shm_lock_test.go
index 4903d3a50..bc22db835 100644
--- a/libpod/lock/shm_lock_test.go
+++ b/libpod/lock/shm/shm_lock_test.go
@@ -1,4 +1,4 @@
-package lock
+package shm
import (
"fmt"
diff --git a/libpod/lock/shm_lock_manager.go b/libpod/lock/shm_lock_manager_linux.go
index 1fc2b106e..b1e9df12d 100644
--- a/libpod/lock/shm_lock_manager.go
+++ b/libpod/lock/shm_lock_manager_linux.go
@@ -1,3 +1,5 @@
+// +build linux
+
package lock
import (
@@ -7,16 +9,17 @@ import (
"syscall"
"github.com/pkg/errors"
+ "github.com/projectatomic/libpod/libpod/lock/shm"
)
// SHMLockManager manages shared memory locks.
type SHMLockManager struct {
- locks *SHMLocks
+ locks *shm.SHMLocks
}
// NewSHMLockManager makes a new SHMLockManager with the given number of locks.
func NewSHMLockManager(numLocks uint32) (Manager, error) {
- locks, err := CreateSHMLock(numLocks)
+ locks, err := shm.CreateSHMLock(numLocks)
if err != nil {
return nil, err
}
@@ -29,8 +32,8 @@ func NewSHMLockManager(numLocks uint32) (Manager, error) {
// OpenSHMLockManager opens an existing SHMLockManager with the given number of
// locks.
-func OpenSHMLockManager(numLocks uint32) (LockManager, error) {
- locks, err := OpenSHMLock(numLocks)
+func OpenSHMLockManager(numLocks uint32) (Manager, error) {
+ locks, err := shm.OpenSHMLock(numLocks)
if err != nil {
return nil, err
}
@@ -59,20 +62,20 @@ func (m *SHMLockManager) AllocateLock() (Locker, error) {
func (m *SHMLockManager) RetrieveLock(id string) (Locker, error) {
intID, err := strconv.ParseInt(id, 16, 64)
if err != nil {
- return errors.Wrapf(err, "given ID %q is not a valid SHMLockManager ID - cannot be parsed as int", id)
+ return nil, errors.Wrapf(err, "given ID %q is not a valid SHMLockManager ID - cannot be parsed as int", id)
}
if intID < 0 {
- return errors.Wrapf(syscall.EINVAL, "given ID %q is not a valid SHMLockManager ID - must be positive", id)
+ return nil, errors.Wrapf(syscall.EINVAL, "given ID %q is not a valid SHMLockManager ID - must be positive", id)
}
if intID > math.MaxUint32 {
- return errors.Wrapf(syscall.EINVAL, "given ID %q is not a valid SHMLockManager ID - too large", id)
+ 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.maxLocks {
- return errors.Wrapf(syscall.EINVAL, "given ID %q is not a valid SHMLockManager ID - too large to fit", id)
+ 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)
}
lock := new(SHMLock)
diff --git a/libpod/lock/shm_lock_manager_unsupported.go b/libpod/lock/shm_lock_manager_unsupported.go
new file mode 100644
index 000000000..a1340fcd1
--- /dev/null
+++ b/libpod/lock/shm_lock_manager_unsupported.go
@@ -0,0 +1,29 @@
+// +build !linux
+
+package lock
+
+import "fmt"
+
+// SHMLockManager is a shared memory lock manager.
+// It is not supported on non-Unix platforms.
+type SHMLockManager struct{}
+
+// NewSHMLockManager is not supported on this platform
+func NewSHMLockManager(numLocks uint32) (Manager, error) {
+ return nil, fmt.Errorf("not supported")
+}
+
+// OpenSHMLockManager is not supported on this platform
+func OpenSHMLockManager(numLocks uint32) (Manager, error) {
+ return nil, fmt.Errorf("not supported")
+}
+
+// AllocateLock is not supported on this platform
+func (m *SHMLockManager) AllocateLock() (Locker, error) {
+ return nil, fmt.Errorf("not supported")
+}
+
+// RetrieveLock is not supported on this platform
+func (m *SHMLockManager) RetrieveLock(id string) (Locker, error) {
+ return nil, fmt.Errorf("not supported")
+}