summaryrefslogtreecommitdiff
path: root/libpod/lock
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/lock')
-rw-r--r--libpod/lock/lock.go11
-rw-r--r--libpod/lock/shm/shm_lock.go8
-rw-r--r--libpod/lock/shm_lock_manager_linux.go12
3 files changed, 22 insertions, 9 deletions
diff --git a/libpod/lock/lock.go b/libpod/lock/lock.go
index 5258c641f..73c1fdcf7 100644
--- a/libpod/lock/lock.go
+++ b/libpod/lock/lock.go
@@ -41,11 +41,14 @@ type Locker interface {
// Lock locks the lock.
// This call MUST block until it successfully acquires the lock or
// encounters a fatal error.
- Lock() error
+ // All errors must be handled internally, as they are not returned. For
+ // the most part, panicking should be appropriate.
+ Lock()
// Unlock unlocks the lock.
- // A call to Unlock() on a lock that is already unlocked lock MUST
- // error.
- Unlock() error
+ // All errors must be handled internally, as they are not returned. For
+ // the most part, panicking should be appropriate.
+ // This includes unlocking locks which are already unlocked.
+ Unlock()
// Free deallocates the underlying lock, allowing its reuse by other
// pods and containers.
// The lock MUST still be usable after a Free() - some libpod instances
diff --git a/libpod/lock/shm/shm_lock.go b/libpod/lock/shm/shm_lock.go
index 16d7f2008..3372a8c71 100644
--- a/libpod/lock/shm/shm_lock.go
+++ b/libpod/lock/shm/shm_lock.go
@@ -12,9 +12,13 @@ import (
"unsafe"
"github.com/pkg/errors"
+ "github.com/sirupsen/logrus"
)
-const (
+var (
+ // BitmapSize is the size of the bitmap used when managing SHM locks.
+ // an SHM lock manager's max locks will be rounded up to a multiple of
+ // this number.
BitmapSize uint32 = uint32(C.bitmap_size_c)
)
@@ -51,6 +55,8 @@ func CreateSHMLock(path string, numLocks uint32) (*SHMLocks, error) {
locks.maxLocks = uint32(lockStruct.num_locks)
locks.valid = true
+ logrus.Debugf("Initialized SHM lock manager at path %s", path)
+
return locks, nil
}
diff --git a/libpod/lock/shm_lock_manager_linux.go b/libpod/lock/shm_lock_manager_linux.go
index 974431a13..2c0ea611a 100644
--- a/libpod/lock/shm_lock_manager_linux.go
+++ b/libpod/lock/shm_lock_manager_linux.go
@@ -73,13 +73,17 @@ func (l *SHMLock) ID() uint32 {
}
// Lock acquires the lock.
-func (l *SHMLock) Lock() error {
- return l.manager.locks.LockSemaphore(l.lockID)
+func (l *SHMLock) Lock() {
+ if err := l.manager.locks.LockSemaphore(l.lockID); err != nil {
+ panic(err.Error())
+ }
}
// Unlock releases the lock.
-func (l *SHMLock) Unlock() error {
- return l.manager.locks.UnlockSemaphore(l.lockID)
+func (l *SHMLock) Unlock() {
+ if err := l.manager.locks.UnlockSemaphore(l.lockID); err != nil {
+ panic(err.Error())
+ }
}
// Free releases the lock, allowing it to be reused.